summaryrefslogtreecommitdiff
path: root/src/tag.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-06 15:07:57 -0800
committerRussell Belfer <rb@github.com>2013-12-11 10:57:49 -0800
commit25e0b1576d5f9e5248603f81d3198a65bfccf0ed (patch)
treedac0da29acfbd6478bed93bcab3557e2877dabaa /src/tag.c
parentfcd324c625d8be3f368c924d787e945e5812d8dd (diff)
downloadlibgit2-25e0b1576d5f9e5248603f81d3198a65bfccf0ed.tar.gz
Remove converting user error to GIT_EUSER
This changes the behavior of callbacks so that the callback error code is not converted into GIT_EUSER and instead we propagate the return value through to the caller. Instead of using the giterr_capture and giterr_restore functions, we now rely on all functions to pass back the return value from a callback. To avoid having a return value with no error message, the user can call the public giterr_set_str or some such function to set an error message. There is a new helper 'giterr_set_callback' that functions can invoke after making a callback which ensures that some error message was set in case the callback did not set one. In places where the sign of the callback return value is meaningful (e.g. positive to skip, negative to abort), only the negative values are returned back to the caller, obviously, since the other values allow for continuing the loop. The hardest parts of this were in the checkout code where positive return values were overloaded as meaningful values for checkout. I fixed this by adding an output parameter to many of the internal checkout functions and removing the overload. This added some code, but it is probably a better implementation. There is some funkiness in the network code where user provided callbacks could be returning a positive or a negative value and we want to rely on that to cancel the loop. There are still a couple places where an user error might get turned into GIT_EUSER there, I think, though none exercised by the tests.
Diffstat (limited to 'src/tag.c')
-rw-r--r--src/tag.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/tag.c b/src/tag.c
index 5d4e45e5d..adf2819d7 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -414,7 +414,6 @@ typedef struct {
git_repository *repo;
git_tag_foreach_cb cb;
void *cb_data;
- git_error_state error;
} tag_cb_data;
static int tags_cb(const char *ref, void *data)
@@ -427,16 +426,15 @@ static int tags_cb(const char *ref, void *data)
return 0; /* no tag */
if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) {
- if (d->cb(ref, &oid, d->cb_data))
- error = giterr_user_cancel();
+ error = d->cb(ref, &oid, d->cb_data);
+ giterr_set_callback(error, "git_tag_foreach");
}
- return giterr_capture(&d->error, error);
+ return error;
}
int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data)
{
- int error;
tag_cb_data data;
assert(repo && cb);
@@ -444,14 +442,8 @@ int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data)
data.cb = cb;
data.cb_data = cb_data;
data.repo = repo;
- memset(&data.error, 0, sizeof(data.error));
-
- error = git_reference_foreach_name(repo, &tags_cb, &data);
-
- if (error == GIT_EUSER)
- error = giterr_restore(&data.error);
- return error;
+ return git_reference_foreach_name(repo, &tags_cb, &data);
}
typedef struct {
@@ -470,8 +462,8 @@ static int tag_list_cb(const char *tag_name, git_oid *oid, void *data)
p_fnmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == 0)
{
char *matched = git__strdup(tag_name + GIT_REFS_TAGS_DIR_LEN);
- if (!matched)
- return -1;
+ GITERR_CHECK_ALLOC(matched);
+
return git_vector_insert(filter->taglist, matched);
}
@@ -494,19 +486,12 @@ int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_reposit
error = git_tag_foreach(repo, &tag_list_cb, (void *)&filter);
- /* the only case where callback will return an error is oom */
- if (error == GIT_EUSER) {
- giterr_set_oom();
- error = -1;
- }
-
- if (error < 0) {
+ if (error < 0)
git_vector_free(&taglist);
- return error;
- }
- tag_names->strings = (char **)taglist.contents;
- tag_names->count = taglist.length;
+ tag_names->strings =
+ (char **)git_vector_detach(&tag_names->count, NULL, &taglist);
+
return 0;
}