Commit 26c1cb91 by Russell Belfer

One more rename/cleanup for callback err functions

parent f10d7a36
...@@ -193,7 +193,7 @@ int git_attr_foreach( ...@@ -193,7 +193,7 @@ int git_attr_foreach(
error = callback(assign->name, assign->value, payload); error = callback(assign->name, assign->value, payload);
if (error) { if (error) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
goto cleanup; goto cleanup;
} }
} }
......
...@@ -123,10 +123,13 @@ static int checkout_notify( ...@@ -123,10 +123,13 @@ static int checkout_notify(
path = delta->old_file.path; path = delta->old_file.path;
} }
return giterr_set_callback( {
data->opts.notify_cb( int error = data->opts.notify_cb(
why, path, baseline, target, workdir, data->opts.notify_payload), why, path, baseline, target, workdir, data->opts.notify_payload);
"git_checkout notification");
return giterr_set_after_callback_function(
error, "git_checkout notification");
}
} }
static bool checkout_is_workdir_modified( static bool checkout_is_workdir_modified(
......
...@@ -83,7 +83,8 @@ int giterr_set_regex(const regex_t *regex, int error_code); ...@@ -83,7 +83,8 @@ int giterr_set_regex(const regex_t *regex, int error_code);
* *
* @return This always returns the `error_code` parameter. * @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) { if (error_code) {
const git_error *e = giterr_last(); const git_error *e = giterr_last();
...@@ -95,9 +96,11 @@ GIT_INLINE(int) giterr_set_callback(int error_code, const char *action) ...@@ -95,9 +96,11 @@ GIT_INLINE(int) giterr_set_callback(int error_code, const char *action)
} }
#ifdef GIT_WIN32 #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 #else
#define GITERR_CALLBACK(code) giterr_set_callback((code), __func__) #define giterr_set_after_callback(code) \
giterr_set_after_callback_function((code), __func__)
#endif #endif
/** /**
......
...@@ -508,7 +508,7 @@ int git_config_backend_foreach_match( ...@@ -508,7 +508,7 @@ int git_config_backend_foreach_match(
/* abort iterator on non-zero return value */ /* abort iterator on non-zero return value */
if ((error = cb(entry, payload)) != 0) { if ((error = cb(entry, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
...@@ -536,7 +536,7 @@ int git_config_foreach_match( ...@@ -536,7 +536,7 @@ int git_config_foreach_match(
while (!(error = git_config_next(&entry, iter))) { while (!(error = git_config_next(&entry, iter))) {
if ((error = cb(entry, payload)) != 0) { if ((error = cb(entry, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
...@@ -799,7 +799,7 @@ int git_config_get_multivar_foreach( ...@@ -799,7 +799,7 @@ int git_config_get_multivar_foreach(
found = 1; found = 1;
if ((err = cb(entry, payload)) != 0) { if ((err = cb(entry, payload)) != 0) {
GITERR_CALLBACK(err); giterr_set_after_callback(err);
break; break;
} }
} }
......
...@@ -60,7 +60,11 @@ static int diff_insert_delta( ...@@ -60,7 +60,11 @@ static int diff_insert_delta(
if (error) { if (error) {
git__free(delta); 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( ...@@ -1389,7 +1393,7 @@ int git_diff__paired_foreach(
} }
if ((error = cb(h2i, i2w, payload)) != 0) { if ((error = cb(h2i, i2w, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -202,7 +202,7 @@ static int diff_patch_invoke_file_callback( ...@@ -202,7 +202,7 @@ static int diff_patch_invoke_file_callback(
if (!output->file_cb) if (!output->file_cb)
return 0; return 0;
return giterr_set_callback( return giterr_set_after_callback_function(
output->file_cb(patch->delta, progress, output->payload), output->file_cb(patch->delta, progress, output->payload),
"git_patch"); "git_patch");
} }
......
...@@ -398,7 +398,7 @@ int git_diff_print( ...@@ -398,7 +398,7 @@ int git_diff_print(
diff, print_file, print_hunk, print_line, &pi); diff, print_file, print_hunk, print_line, &pi);
if (error) /* make sure error message is set */ 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); git_buf_free(&buf);
...@@ -427,7 +427,7 @@ int git_patch_print( ...@@ -427,7 +427,7 @@ int git_patch_print(
diff_print_patch_line, &pi); diff_print_patch_line, &pi);
if (error) /* make sure error message is set */ 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); git_buf_free(&temp);
......
...@@ -271,7 +271,7 @@ int git_repository_fetchhead_foreach(git_repository *repo, ...@@ -271,7 +271,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
error = cb(ref_name, remote_url, &oid, is_merge, payload); error = cb(ref_name, remote_url, &oid, is_merge, payload);
if (error) { if (error) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
goto done; goto done;
} }
} }
......
...@@ -2117,7 +2117,7 @@ int git_index_add_all( ...@@ -2117,7 +2117,7 @@ int git_index_add_all(
if (error > 0) /* return > 0 means skip this one */ if (error > 0) /* return > 0 means skip this one */
continue; continue;
if (error < 0) { /* return < 0 means abort */ if (error < 0) { /* return < 0 means abort */
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
...@@ -2204,11 +2204,9 @@ static int index_apply_to_all( ...@@ -2204,11 +2204,9 @@ static int index_apply_to_all(
error = 0; error = 0;
continue; continue;
} }
if (error < 0) { /* return < 0 means abort */ if (error < 0) /* return < 0 means abort */
giterr_set_callback(error, "git_index_matched_path");
break; break;
} }
}
/* index manipulation may alter entry, so don't depend on it */ /* index manipulation may alter entry, so don't depend on it */
if ((error = git_buf_sets(&path, entry->path)) < 0) if ((error = git_buf_sets(&path, entry->path)) < 0)
...@@ -2252,8 +2250,13 @@ int git_index_remove_all( ...@@ -2252,8 +2250,13 @@ int git_index_remove_all(
git_index_matched_path_cb cb, git_index_matched_path_cb cb,
void *payload) void *payload)
{ {
return index_apply_to_all( int error = index_apply_to_all(
index, INDEX_ACTION_REMOVE, pathspec, cb, payload); 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( int git_index_update_all(
...@@ -2262,6 +2265,11 @@ int git_index_update_all( ...@@ -2262,6 +2265,11 @@ int git_index_update_all(
git_index_matched_path_cb cb, git_index_matched_path_cb cb,
void *payload) void *payload)
{ {
return index_apply_to_all( int error = index_apply_to_all(
index, INDEX_ACTION_UPDATE, pathspec, cb, payload); 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;
} }
...@@ -387,7 +387,7 @@ on_error: ...@@ -387,7 +387,7 @@ on_error:
static int do_progress_callback(git_indexer *idx, git_transfer_progress *stats) static int do_progress_callback(git_indexer *idx, git_transfer_progress *stats)
{ {
if (idx->progress_cb) if (idx->progress_cb)
return giterr_set_callback( return giterr_set_after_callback_function(
idx->progress_cb(stats, idx->progress_payload), idx->progress_cb(stats, idx->progress_payload),
"indexer progress"); "indexer progress");
return 0; return 0;
......
...@@ -288,7 +288,7 @@ int git_repository_mergehead_foreach( ...@@ -288,7 +288,7 @@ int git_repository_mergehead_foreach(
goto cleanup; goto cleanup;
if ((error = cb(&oid, payload)) != 0) { if ((error = cb(&oid, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
goto cleanup; goto cleanup;
} }
......
...@@ -584,7 +584,7 @@ int git_note_foreach( ...@@ -584,7 +584,7 @@ int git_note_foreach(
while (!(error = git_note_next(&note_id, &annotated_id, iter))) { while (!(error = git_note_next(&note_id, &annotated_id, iter))) {
if ((error = note_cb(&note_id, &annotated_id, payload)) != 0) { if ((error = note_cb(&note_id, &annotated_id, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -733,7 +733,7 @@ static int foreach_object_dir_cb(void *_state, git_buf *path) ...@@ -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) if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0)
return 0; return 0;
return giterr_set_callback( return giterr_set_after_callback_function(
state->cb(&oid, state->data), "git_odb_foreach"); state->cb(&oid, state->data), "git_odb_foreach");
} }
......
...@@ -234,7 +234,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, ...@@ -234,7 +234,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
pb->nr_objects, 0, pb->progress_cb_payload); pb->nr_objects, 0, pb->progress_cb_payload);
if (ret) if (ret)
return GITERR_CALLBACK(ret); return giterr_set_after_callback(ret);
} }
} }
......
...@@ -1088,10 +1088,8 @@ int git_pack_foreach_entry( ...@@ -1088,10 +1088,8 @@ int git_pack_foreach_entry(
} }
for (i = 0; i < p->num_objects; i++) for (i = 0; i < p->num_objects; i++)
if ((error = cb(p->oids[i], data)) != 0) { if ((error = cb(p->oids[i], data)) != 0)
GITERR_CALLBACK(error); return giterr_set_after_callback(error);
break;
}
return error; return error;
} }
......
...@@ -438,7 +438,7 @@ int git_path_walk_up( ...@@ -438,7 +438,7 @@ int git_path_walk_up(
iter.ptr[scan] = oldc; iter.ptr[scan] = oldc;
if (error) { if (error) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
...@@ -882,7 +882,7 @@ int git_path_direach( ...@@ -882,7 +882,7 @@ int git_path_direach(
git_buf_truncate(path, wd_len); /* restore path */ git_buf_truncate(path, wd_len); /* restore path */
if (error != 0) { if (error != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -661,7 +661,7 @@ int git_push_status_foreach(git_push *push, ...@@ -661,7 +661,7 @@ int git_push_status_foreach(git_push *push,
git_vector_foreach(&push->status, i, status) { git_vector_foreach(&push->status, i, status) {
int error = cb(status->ref, status->msg, data); int error = cb(status->ref, status->msg, data);
if (error) if (error)
return GITERR_CALLBACK(error); return giterr_set_after_callback(error);
} }
return 0; return 0;
......
...@@ -518,7 +518,7 @@ int git_reference_foreach( ...@@ -518,7 +518,7 @@ int git_reference_foreach(
while (!(error = git_reference_next(&ref, iter))) { while (!(error = git_reference_next(&ref, iter))) {
if ((error = callback(ref, payload)) != 0) { if ((error = callback(ref, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
...@@ -544,7 +544,7 @@ int git_reference_foreach_name( ...@@ -544,7 +544,7 @@ int git_reference_foreach_name(
while (!(error = git_reference_next_name(&refname, iter))) { while (!(error = git_reference_next_name(&refname, iter))) {
if ((error = callback(refname, payload)) != 0) { if ((error = callback(refname, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
...@@ -571,7 +571,7 @@ int git_reference_foreach_glob( ...@@ -571,7 +571,7 @@ int git_reference_foreach_glob(
while (!(error = git_reference_next_name(&refname, iter))) { while (!(error = git_reference_next_name(&refname, iter))) {
if ((error = callback(refname, payload)) != 0) { if ((error = callback(refname, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -1349,7 +1349,7 @@ static int rename_fetch_refspecs( ...@@ -1349,7 +1349,7 @@ static int rename_fetch_refspecs(
strcmp(git_buf_cstr(&base), spec->string)) { strcmp(git_buf_cstr(&base), spec->string)) {
if ((error = callback(spec->string, payload)) != 0) { if ((error = callback(spec->string, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
......
...@@ -588,7 +588,7 @@ int git_stash_foreach( ...@@ -588,7 +588,7 @@ int git_stash_foreach(
payload); payload);
if (error) { if (error) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -393,7 +393,7 @@ int git_status_foreach_ext( ...@@ -393,7 +393,7 @@ int git_status_foreach_ext(
status_entry->index_to_workdir->old_file.path; status_entry->index_to_workdir->old_file.path;
if ((error = cb(path, status_entry->status, payload)) != 0) { if ((error = cb(path, status_entry->status, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
} }
......
...@@ -169,7 +169,7 @@ int git_submodule_foreach( ...@@ -169,7 +169,7 @@ int git_submodule_foreach(
} }
if ((error = callback(sm, sm->name, payload)) != 0) { if ((error = callback(sm, sm->name, payload)) != 0) {
GITERR_CALLBACK(error); giterr_set_after_callback(error);
break; break;
} }
}); });
......
...@@ -426,8 +426,8 @@ static int tags_cb(const char *ref, void *data) ...@@ -426,8 +426,8 @@ static int tags_cb(const char *ref, void *data)
return 0; /* no tag */ return 0; /* no tag */
if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) { if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) {
error = d->cb(ref, &oid, d->cb_data); if ((error = d->cb(ref, &oid, d->cb_data)) != 0)
giterr_set_callback(error, "git_tag_foreach"); giterr_set_after_callback_function(error, "git_tag_foreach");
} }
return error; return error;
......
...@@ -883,9 +883,12 @@ static int tree_walk( ...@@ -883,9 +883,12 @@ static int tree_walk(
git_vector_foreach(&tree->entries, i, entry) { git_vector_foreach(&tree->entries, i, entry) {
if (preorder) { if (preorder) {
if ((error = callback(path->ptr, entry, payload)) < 0) error = callback(path->ptr, entry, payload);
return giterr_set_callback(error, "git_tree_walk"); if (error < 0) { /* negative value stops iteration */
if (error > 0) { giterr_set_after_callback_function(error, "git_tree_walk");
break;
}
if (error > 0) { /* positive value skips this entry */
error = 0; error = 0;
continue; continue;
} }
...@@ -916,8 +919,11 @@ static int tree_walk( ...@@ -916,8 +919,11 @@ static int tree_walk(
} }
if (!preorder) { if (!preorder) {
if ((error = callback(path->ptr, entry, payload)) < 0) error = callback(path->ptr, entry, payload);
return giterr_set_callback(error, "git_tree_walk"); if (error < 0) { /* negative value stops iteration */
giterr_set_after_callback_function(error, "git_tree_walk");
break;
}
error = 0; error = 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment