implement cancellation support for diff and status operations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/lib/worktree.c b/lib/worktree.c
index 1c52dfc..92720c5 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1122,7 +1122,7 @@ update_blob(struct got_worktree *worktree,
struct got_fileindex *fileindex, struct got_fileindex_entry *ie,
struct got_tree_entry *te, const char *path,
struct got_repository *repo, got_worktree_checkout_cb progress_cb,
- void *progress_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+ void *progress_arg)
{
const struct got_error *err = NULL;
struct got_blob_object *blob = NULL;
@@ -1218,8 +1218,7 @@ static const struct got_error *
delete_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
struct got_fileindex_entry *ie, const char *parent_path,
struct got_repository *repo,
- got_worktree_checkout_cb progress_cb, void *progress_arg,
- got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+ got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err = NULL;
unsigned char status;
@@ -1274,9 +1273,11 @@ diff_old_new(void *arg, struct got_fileindex_entry *ie,
{
struct diff_cb_arg *a = arg;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
return update_blob(a->worktree, a->fileindex, ie, te,
- ie->path, a->repo, a->progress_cb, a->progress_arg,
- a->cancel_cb, a->cancel_arg);
+ ie->path, a->repo, a->progress_cb, a->progress_arg);
}
static const struct got_error *
@@ -1284,9 +1285,11 @@ diff_old(void *arg, struct got_fileindex_entry *ie, const char *parent_path)
{
struct diff_cb_arg *a = arg;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
return delete_blob(a->worktree, a->fileindex, ie, parent_path,
- a->repo, a->progress_cb, a->progress_arg,
- a->cancel_cb, a->cancel_arg);
+ a->repo, a->progress_cb, a->progress_arg);
}
static const struct got_error *
@@ -1296,6 +1299,9 @@ diff_new(void *arg, struct got_tree_entry *te, const char *parent_path)
const struct got_error *err;
char *path;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
if (asprintf(&path, "%s%s%s", parent_path,
parent_path[0] ? "/" : "", te->name)
== -1)
@@ -1305,8 +1311,7 @@ diff_new(void *arg, struct got_tree_entry *te, const char *parent_path)
err = add_dir_on_disk(a->worktree, path);
else
err = update_blob(a->worktree, a->fileindex, NULL, te, path,
- a->repo, a->progress_cb, a->progress_arg,
- a->cancel_cb, a->cancel_arg);
+ a->repo, a->progress_cb, a->progress_arg);
free(path);
return err;
@@ -1594,6 +1599,9 @@ status_old_new(void *arg, struct got_fileindex_entry *ie,
struct diff_dir_cb_arg *a = arg;
char *abspath;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
if (got_path_cmp(parent_path, a->status_path) != 0 &&
!got_path_is_child(parent_path, a->status_path, a->status_path_len))
return NULL;
@@ -1621,6 +1629,9 @@ status_old(void *arg, struct got_fileindex_entry *ie, const char *parent_path)
struct got_object_id id;
unsigned char status;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
if (!got_path_is_child(parent_path, a->status_path, a->status_path_len))
return NULL;
@@ -1639,6 +1650,9 @@ status_new(void *arg, struct dirent *de, const char *parent_path)
struct diff_dir_cb_arg *a = arg;
char *path = NULL;
+ if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
+ return got_error(GOT_ERR_CANCELLED);
+
if (de->d_type == DT_DIR)
return NULL;