summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/attr.c2
-rw-r--r--src/checkout.c11
-rw-r--r--src/common.h9
-rw-r--r--src/config.c6
-rw-r--r--src/diff.c8
-rw-r--r--src/diff_patch.c2
-rw-r--r--src/diff_print.c4
-rw-r--r--src/fetchhead.c2
-rw-r--r--src/index.c20
-rw-r--r--src/indexer.c2
-rw-r--r--src/merge.c2
-rw-r--r--src/notes.c2
-rw-r--r--src/odb_loose.c2
-rw-r--r--src/pack-objects.c2
-rw-r--r--src/pack.c6
-rw-r--r--src/path.c4
-rw-r--r--src/push.c2
-rw-r--r--src/refs.c6
-rw-r--r--src/remote.c2
-rw-r--r--src/stash.c2
-rw-r--r--src/status.c2
-rw-r--r--src/submodule.c2
-rw-r--r--src/tag.c4
-rw-r--r--src/tree.c16
24 files changed, 71 insertions, 49 deletions
diff --git a/src/attr.c b/src/attr.c
index 553c071be..e6e274e42 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 4c64252e4..a292e3d4c 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 71182bbb9..e315b5979 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 5477b04c8..056a6ae13 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 b7657e432..83adc2a8c 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 11f02478d..9c2eb885f 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 ff477e4c8..7a70e2b18 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 2f217fad1..4435454ef 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 671bdfa79..bb81f666e 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 320845bd9..88897d07d 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 f1778c950..5640be56b 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 e0d5ad19e..795904917 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 78cd792bd..fd4ffff1e 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 09b7248af..7ce1b6cb3 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 fd53ef49a..23fcf3530 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 8c19e004e..365bd6c00 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 8ebba15eb..adba880df 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 25037cc4f..4f3a557c6 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 d46364a81..689de230a 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 fb5bb2e55..eae56966c 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 d4a436283..9bde8fb57 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 5298302c7..1c36d3656 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 adf2819d7..be56b05ce 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 5f35ac3a8..4d77ff778 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;
}
}