diff options
| author | Russell Belfer <rb@github.com> | 2013-12-03 16:45:39 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-12-11 10:57:49 -0800 |
| commit | 96869a4edb2872934e0e167a726ab240f4270fea (patch) | |
| tree | 2d770414acef2d1d45a609e004c0aa6fa56d06d7 /src/diff.c | |
| parent | 9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (diff) | |
| download | libgit2-96869a4edb2872934e0e167a726ab240f4270fea.tar.gz | |
Improve GIT_EUSER handling
This adds giterr_user_cancel to return GIT_EUSER and clear any
error message that is sitting around. As a result of using that
in places, we need to be more thorough with capturing errors that
happen inside a callback when used internally. To help with that,
this also adds giterr_capture and giterr_restore so that when we
internally use a foreach-type function that clears errors and
converts them to GIT_EUSER, it is easier to restore not just the
return value, but the actual error message text.
Diffstat (limited to 'src/diff.c')
| -rw-r--r-- | src/diff.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/diff.c b/src/diff.c index 53a8f4638..ad058af61 100644 --- a/src/diff.c +++ b/src/diff.c @@ -120,7 +120,7 @@ static int diff_delta__from_one( return -1; } - return notify_res < 0 ? GIT_EUSER : 0; + return notify_res < 0 ? giterr_user_cancel() : 0; } static int diff_delta__from_two( @@ -182,7 +182,7 @@ static int diff_delta__from_two( return -1; } - return notify_res < 0 ? GIT_EUSER : 0; + return notify_res < 0 ? giterr_user_cancel() : 0; } static git_diff_delta *diff_delta__last_for_item( @@ -1343,7 +1343,7 @@ int git_diff__paired_foreach( int (*cb)(git_diff_delta *h2i, git_diff_delta *i2w, void *payload), void *payload) { - int cmp; + int cmp, error = 0; git_diff_delta *h2i, *i2w; size_t i, j, i_max, j_max; int (*strcomp)(const char *, const char *) = git__strcmp; @@ -1399,18 +1399,17 @@ int git_diff__paired_foreach( strcomp(h2i->new_file.path, i2w->old_file.path); if (cmp < 0) { - if (cb(h2i, NULL, payload)) - return GIT_EUSER; - i++; + i++; i2w = NULL; } else if (cmp > 0) { - if (cb(NULL, i2w, payload)) - return GIT_EUSER; - j++; + j++; h2i = NULL; } else { - if (cb(h2i, i2w, payload)) - return GIT_EUSER; i++; j++; } + + if (cb(h2i, i2w, payload)) { + error = giterr_user_cancel(); + break; + } } /* restore case-insensitive delta sort */ @@ -1426,5 +1425,5 @@ int git_diff__paired_foreach( git_vector_sort(&idx2wd->deltas); } - return 0; + return error; } |
