Add minimal cancellation to diff
diff --git a/include/git2/errors.h b/include/git2/errors.h
index e959ffd..6fce8ac 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -50,6 +50,7 @@
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 @@
GITERR_REBASE,
GITERR_FILESYSTEM,
GITERR_PATCH,
+ GITERR_CANCELLATION,
} git_error_t;
/**
diff --git a/src/cancellation.h b/src/cancellation.h
index d447e00..fbb6fbc 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 06f9b19..4858c43 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 @@
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 7bc322c..be7a7b8 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 @@
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());
+}
+