diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2016-11-15 14:36:33 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-11-15 14:36:33 +0100 |
commit | 060649e0f103ff37924140bb6584be9843f666e9 (patch) | |
tree | 57717b2214c27a67a6fffba2c9facf5d08220b85 | |
parent | 49656a5b6beff3b2e91ca1894bb3d72671bb4d8f (diff) | |
download | libgit2-cmn/cancellation.tar.gz |
Add minimal cancellation to diffcmn/cancellation
-rw-r--r-- | include/git2/errors.h | 2 | ||||
-rw-r--r-- | src/cancellation.h | 2 | ||||
-rw-r--r-- | src/diff_generate.c | 7 | ||||
-rw-r--r-- | tests/core/cancellation.c | 15 |
4 files changed, 25 insertions, 1 deletions
diff --git a/include/git2/errors.h b/include/git2/errors.h index e959ffd8a..6fce8ac65 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -50,6 +50,7 @@ typedef enum { GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */ GIT_EDIRECTORY = -23, /**< The operation is not valid for a directory */ GIT_EMERGECONFLICT = -24, /**< A merge conflict exists and cannot continue */ + GIT_ECANCELLED = -25, /**< The operation was canceled */ GIT_PASSTHROUGH = -30, /**< Internal only */ GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */ @@ -100,6 +101,7 @@ typedef enum { GITERR_REBASE, GITERR_FILESYSTEM, GITERR_PATCH, + GITERR_CANCELLATION, } git_error_t; /** diff --git a/src/cancellation.h b/src/cancellation.h index d447e00c6..fbb6fbc54 100644 --- a/src/cancellation.h +++ b/src/cancellation.h @@ -14,7 +14,7 @@ /** * Check whether there's an active cancellation that's been canceled. */ -GIT_INLINE(bool) git_cancellation__cancelled(void) +GIT_INLINE(bool) git_cancellation__canceled(void) { git_cancellation *c = GIT_GLOBAL->cancellation; diff --git a/src/diff_generate.c b/src/diff_generate.c index 06f9b19c7..4858c43c0 100644 --- a/src/diff_generate.c +++ b/src/diff_generate.c @@ -16,6 +16,7 @@ #include "index.h" #include "odb.h" #include "submodule.h" +#include "cancellation.h" #define DIFF_FLAG_IS_SET(DIFF,FLAG) \ (((DIFF)->base.opts.flags & (FLAG)) != 0) @@ -1212,6 +1213,12 @@ int git_diff__from_iterators( while (!error && (info.oitem || info.nitem)) { int cmp; + if (git_cancellation__canceled()) { + giterr_set(GITERR_CANCELLATION, "the operation was canceled"); + error = GIT_ECANCELLED; + goto cleanup; + } + /* report progress */ if (opts && opts->progress_cb) { if ((error = opts->progress_cb(&diff->base, diff --git a/tests/core/cancellation.c b/tests/core/cancellation.c index 7bc322cdb..be7a7b808 100644 --- a/tests/core/cancellation.c +++ b/tests/core/cancellation.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "array.h" +#include "cancellation.h" void test_core_cancellation__can_cancel(void) { @@ -115,3 +116,17 @@ void test_core_cancellation__trigger_failure(void) git_cancellation_free(c); } +void test_core_cancellation__detect_current(void) +{ + git_cancellation *c; + + cl_git_pass(git_cancellation_new(&c)); + cl_git_pass(git_cancellation_activate(c)); + + cl_assert_equal_i(0, git_cancellation__canceled()); + cl_git_pass(git_cancellation_request(c)); + cl_assert_equal_i(1, git_cancellation__canceled()); + + cl_git_pass(git_cancellation_deactivate()); +} + |