summaryrefslogtreecommitdiff
path: root/src/attr.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/attr.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/attr.c')
-rw-r--r--src/attr.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/attr.c b/src/attr.c
index 1a0f1f97f..08d7ee99d 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -191,11 +191,10 @@ int git_attr_foreach(
if (error < 0)
goto cleanup;
- error = callback(assign->name, assign->value, payload);
- if (error) {
- error = giterr_user_cancel();
+ error = GITERR_CALLBACK(
+ callback(assign->name, assign->value, payload) );
+ if (error)
goto cleanup;
- }
}
}
}
@@ -480,7 +479,6 @@ typedef struct {
const char *workdir;
git_index *index;
git_vector *files;
- git_error_state error;
} attr_walk_up_info;
int git_attr_cache__decide_sources(
@@ -524,7 +522,7 @@ static int push_one_attr(void *ref, git_buf *path)
info->repo, path->ptr, GIT_ATTR_FILE, src[i],
git_attr_file__parse_buffer, NULL, info->files);
- return giterr_capture(&info->error, error);
+ return error;
}
static int collect_attr_files(
@@ -570,8 +568,6 @@ static int collect_attr_files(
info.files = files;
error = git_path_walk_up(&dir, workdir, push_one_attr, &info);
- if (error == GIT_EUSER)
- error = giterr_restore(&info.error);
if (error < 0)
goto cleanup;