Commit 26c1cb91beccb44425864bd233ed0e35f5801868

Russell Belfer 2013-12-09T09:44:03

One more rename/cleanup for callback err functions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
diff --git a/src/attr.c b/src/attr.c
index 553c071..e6e274e 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -193,7 +193,7 @@ int git_attr_foreach(
 
 				error = callback(assign->name, assign->value, payload);
 				if (error) {
-					GITERR_CALLBACK(error);
+					giterr_set_after_callback(error);
 					goto cleanup;
 				}
 			}
diff --git a/src/checkout.c b/src/checkout.c
index 4c64252..a292e3d 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -123,10 +123,13 @@ static int checkout_notify(
 		path = delta->old_file.path;
 	}
 
-	return giterr_set_callback(
-		data->opts.notify_cb(
-			why, path, baseline, target, workdir, data->opts.notify_payload),
-		"git_checkout notification");
+	{
+		int error = data->opts.notify_cb(
+			why, path, baseline, target, workdir, data->opts.notify_payload);
+
+		return giterr_set_after_callback_function(
+			error, "git_checkout notification");
+	}
 }
 
 static bool checkout_is_workdir_modified(
diff --git a/src/common.h b/src/common.h
index 71182bb..e315b59 100644
--- a/src/common.h
+++ b/src/common.h
@@ -83,7 +83,8 @@ int giterr_set_regex(const regex_t *regex, int error_code);
  *
  * @return This always returns the `error_code` parameter.
  */
-GIT_INLINE(int) giterr_set_callback(int error_code, const char *action)
+GIT_INLINE(int) giterr_set_after_callback_function(
+	int error_code, const char *action)
 {
 	if (error_code) {
 		const git_error *e = giterr_last();
@@ -95,9 +96,11 @@ GIT_INLINE(int) giterr_set_callback(int error_code, const char *action)
 }
 
 #ifdef GIT_WIN32
-#define GITERR_CALLBACK(code) giterr_set_callback((code), __FUNCTION__)
+#define giterr_set_after_callback(code) \
+	giterr_set_after_callback_function((code), __FUNCTION__)
 #else
-#define GITERR_CALLBACK(code) giterr_set_callback((code), __func__)
+#define giterr_set_after_callback(code) \
+	giterr_set_after_callback_function((code), __func__)
 #endif
 
 /**
diff --git a/src/config.c b/src/config.c
index 5477b04..056a6ae 100644
--- a/src/config.c
+++ b/src/config.c
@@ -508,7 +508,7 @@ int git_config_backend_foreach_match(
 
 		/* abort iterator on non-zero return value */
 		if ((error = cb(entry, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
@@ -536,7 +536,7 @@ int git_config_foreach_match(
 
 	while (!(error = git_config_next(&entry, iter))) {
 		if ((error = cb(entry, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
@@ -799,7 +799,7 @@ int git_config_get_multivar_foreach(
 		found = 1;
 
 		if ((err = cb(entry, payload)) != 0) {
-			GITERR_CALLBACK(err);
+			giterr_set_after_callback(err);
 			break;
 		}
 	}
diff --git a/src/diff.c b/src/diff.c
index b7657e4..83adc2a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -60,7 +60,11 @@ static int diff_insert_delta(
 
 		if (error) {
 			git__free(delta);
-			return (error > 0) ? 0 : giterr_set_callback(error, "git_diff");
+
+			if (error > 0)	/* positive value means to skip this delta */
+				return 0;
+			else			/* negative value means to cancel diff */
+				return giterr_set_after_callback_function(error, "git_diff");
 		}
 	}
 
@@ -1389,7 +1393,7 @@ int git_diff__paired_foreach(
 		}
 
 		if ((error = cb(h2i, i2w, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/diff_patch.c b/src/diff_patch.c
index 11f0247..9c2eb88 100644
--- a/src/diff_patch.c
+++ b/src/diff_patch.c
@@ -202,7 +202,7 @@ static int diff_patch_invoke_file_callback(
 	if (!output->file_cb)
 		return 0;
 
-	return giterr_set_callback(
+	return giterr_set_after_callback_function(
 		output->file_cb(patch->delta, progress, output->payload),
 		"git_patch");
 }
diff --git a/src/diff_print.c b/src/diff_print.c
index ff477e4..7a70e2b 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -398,7 +398,7 @@ int git_diff_print(
 			diff, print_file, print_hunk, print_line, &pi);
 
 		if (error) /* make sure error message is set */
-			giterr_set_callback(error, "git_diff_print");
+			giterr_set_after_callback_function(error, "git_diff_print");
 	}
 
 	git_buf_free(&buf);
@@ -427,7 +427,7 @@ int git_patch_print(
 			diff_print_patch_line, &pi);
 
 		if (error) /* make sure error message is set */
-			giterr_set_callback(error, "git_patch_print");
+			giterr_set_after_callback_function(error, "git_patch_print");
 	}
 
 	git_buf_free(&temp);
diff --git a/src/fetchhead.c b/src/fetchhead.c
index 2f217fa..4435454 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -271,7 +271,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
 
 		error = cb(ref_name, remote_url, &oid, is_merge, payload);
 		if (error) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			goto done;
 		}
 	}
diff --git a/src/index.c b/src/index.c
index 671bdfa..bb81f66 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2117,7 +2117,7 @@ int git_index_add_all(
 			if (error > 0) /* return > 0 means skip this one */
 				continue;
 			if (error < 0) { /* return < 0 means abort */
-				GITERR_CALLBACK(error);
+				giterr_set_after_callback(error);
 				break;
 			}
 		}
@@ -2204,10 +2204,8 @@ static int index_apply_to_all(
 				error = 0;
 				continue;
 			}
-			if (error < 0) { /* return < 0 means abort */
-				giterr_set_callback(error, "git_index_matched_path");
+			if (error < 0)   /* return < 0 means abort */
 				break;
-			}
 		}
 
 		/* index manipulation may alter entry, so don't depend on it */
@@ -2252,8 +2250,13 @@ int git_index_remove_all(
 	git_index_matched_path_cb cb,
 	void *payload)
 {
-	return index_apply_to_all(
+	int error = index_apply_to_all(
 		index, INDEX_ACTION_REMOVE, pathspec, cb, payload);
+
+	if (error) /* make sure error is set if callback stopped iteration */
+		giterr_set_after_callback(error);
+
+	return error;
 }
 
 int git_index_update_all(
@@ -2262,6 +2265,11 @@ int git_index_update_all(
 	git_index_matched_path_cb cb,
 	void *payload)
 {
-	return index_apply_to_all(
+	int error = index_apply_to_all(
 		index, INDEX_ACTION_UPDATE, pathspec, cb, payload);
+
+	if (error) /* make sure error is set if callback stopped iteration */
+		giterr_set_after_callback(error);
+
+	return error;
 }
diff --git a/src/indexer.c b/src/indexer.c
index 320845b..88897d0 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -387,7 +387,7 @@ on_error:
 static int do_progress_callback(git_indexer *idx, git_transfer_progress *stats)
 {
 	if (idx->progress_cb)
-		return giterr_set_callback(
+		return giterr_set_after_callback_function(
 			idx->progress_cb(stats, idx->progress_payload),
 			"indexer progress");
 	return 0;
diff --git a/src/merge.c b/src/merge.c
index f1778c9..5640be5 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -288,7 +288,7 @@ int git_repository_mergehead_foreach(
 			goto cleanup;
 
 		if ((error = cb(&oid, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			goto cleanup;
 		}
 
diff --git a/src/notes.c b/src/notes.c
index e0d5ad1..7959049 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -584,7 +584,7 @@ int git_note_foreach(
 
 	while (!(error = git_note_next(&note_id, &annotated_id, iter))) {
 		if ((error = note_cb(&note_id, &annotated_id, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 78cd792..fd4ffff 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -733,7 +733,7 @@ static int foreach_object_dir_cb(void *_state, git_buf *path)
 	if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0)
 		return 0;
 
-	return giterr_set_callback(
+	return giterr_set_after_callback_function(
 		state->cb(&oid, state->data), "git_odb_foreach");
 }
 
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 09b7248..7ce1b6c 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -234,7 +234,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
 				pb->nr_objects, 0, pb->progress_cb_payload);
 
 			if (ret)
-				return GITERR_CALLBACK(ret);
+				return giterr_set_after_callback(ret);
 		}
 	}
 
diff --git a/src/pack.c b/src/pack.c
index fd53ef4..23fcf35 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1088,10 +1088,8 @@ int git_pack_foreach_entry(
 	}
 
 	for (i = 0; i < p->num_objects; i++)
-		if ((error = cb(p->oids[i], data)) != 0) {
-			GITERR_CALLBACK(error);
-			break;
-		}
+		if ((error = cb(p->oids[i], data)) != 0)
+			return giterr_set_after_callback(error);
 
 	return error;
 }
diff --git a/src/path.c b/src/path.c
index 8c19e00..365bd6c 100644
--- a/src/path.c
+++ b/src/path.c
@@ -438,7 +438,7 @@ int git_path_walk_up(
 		iter.ptr[scan] = oldc;
 
 		if (error) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 
@@ -882,7 +882,7 @@ int git_path_direach(
 		git_buf_truncate(path, wd_len); /* restore path */
 
 		if (error != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/push.c b/src/push.c
index 8ebba15..adba880 100644
--- a/src/push.c
+++ b/src/push.c
@@ -661,7 +661,7 @@ int git_push_status_foreach(git_push *push,
 	git_vector_foreach(&push->status, i, status) {
 		int error = cb(status->ref, status->msg, data);
 		if (error)
-			return GITERR_CALLBACK(error);
+			return giterr_set_after_callback(error);
 	}
 
 	return 0;
diff --git a/src/refs.c b/src/refs.c
index 25037cc..4f3a557 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -518,7 +518,7 @@ int git_reference_foreach(
 
 	while (!(error = git_reference_next(&ref, iter))) {
 		if ((error = callback(ref, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
@@ -544,7 +544,7 @@ int git_reference_foreach_name(
 
 	while (!(error = git_reference_next_name(&refname, iter))) {
 		if ((error = callback(refname, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
@@ -571,7 +571,7 @@ int git_reference_foreach_glob(
 
 	while (!(error = git_reference_next_name(&refname, iter))) {
 		if ((error = callback(refname, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/remote.c b/src/remote.c
index d46364a..689de23 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1349,7 +1349,7 @@ static int rename_fetch_refspecs(
 			strcmp(git_buf_cstr(&base), spec->string)) {
 
 			if ((error = callback(spec->string, payload)) != 0) {
-				GITERR_CALLBACK(error);
+				giterr_set_after_callback(error);
 				break;
 			}
 
diff --git a/src/stash.c b/src/stash.c
index fb5bb2e..eae5696 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -588,7 +588,7 @@ int git_stash_foreach(
 			payload);
 
 		if (error) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/status.c b/src/status.c
index d4a4362..9bde8fb 100644
--- a/src/status.c
+++ b/src/status.c
@@ -393,7 +393,7 @@ int git_status_foreach_ext(
 			status_entry->index_to_workdir->old_file.path;
 
 		if ((error = cb(path, status_entry->status, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	}
diff --git a/src/submodule.c b/src/submodule.c
index 5298302..1c36d36 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -169,7 +169,7 @@ int git_submodule_foreach(
 		}
 
 		if ((error = callback(sm, sm->name, payload)) != 0) {
-			GITERR_CALLBACK(error);
+			giterr_set_after_callback(error);
 			break;
 		}
 	});
diff --git a/src/tag.c b/src/tag.c
index adf2819..be56b05 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -426,8 +426,8 @@ static int tags_cb(const char *ref, void *data)
 		return 0; /* no tag */
 
 	if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) {
-		error = d->cb(ref, &oid, d->cb_data);
-		giterr_set_callback(error, "git_tag_foreach");
+		if ((error = d->cb(ref, &oid, d->cb_data)) != 0)
+			giterr_set_after_callback_function(error, "git_tag_foreach");
 	}
 
 	return error;
diff --git a/src/tree.c b/src/tree.c
index 5f35ac3..4d77ff7 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -883,9 +883,12 @@ static int tree_walk(
 
 	git_vector_foreach(&tree->entries, i, entry) {
 		if (preorder) {
-			if ((error = callback(path->ptr, entry, payload)) < 0)
-				return giterr_set_callback(error, "git_tree_walk");
-			if (error > 0) {
+			error = callback(path->ptr, entry, payload);
+			if (error < 0) { /* negative value stops iteration */
+				giterr_set_after_callback_function(error, "git_tree_walk");
+				break;
+			}
+			if (error > 0) { /* positive value skips this entry */
 				error = 0;
 				continue;
 			}
@@ -916,8 +919,11 @@ static int tree_walk(
 		}
 
 		if (!preorder) {
-			if ((error = callback(path->ptr, entry, payload)) < 0)
-				return giterr_set_callback(error, "git_tree_walk");
+			error = callback(path->ptr, entry, payload);
+			if (error < 0) { /* negative value stops iteration */
+				giterr_set_after_callback_function(error, "git_tree_walk");
+				break;
+			}
 			error = 0;
 		}
 	}