Commit e620954619292de6ad76df32021946b9d6aa168c

Stefan Sperling 2019-08-22T11:12:24

untie cancel callback declaration from the work tree

diff --git a/got/got.c b/got/got.c
index 86376ee..1242a08 100644
--- a/got/got.c
+++ b/got/got.c
@@ -41,6 +41,7 @@
 #include "got_reference.h"
 #include "got_repository.h"
 #include "got_path.h"
+#include "got_cancel.h"
 #include "got_worktree.h"
 #include "got_diff.h"
 #include "got_commit_graph.h"
diff --git a/include/got_cancel.h b/include/got_cancel.h
new file mode 100644
index 0000000..feffaf3
--- /dev/null
+++ b/include/got_cancel.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * A callback function which is invoked at cancellation points.
+ * May return GOT_ERR_CANCELLED to abort the runing operation.
+ */
+typedef const struct got_error *(*got_cancel_cb)(void *);
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 1a7f2a2..1bd4eff 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -102,10 +102,6 @@ const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
 typedef const struct got_error *(*got_worktree_checkout_cb)(void *,
     unsigned char, const char *);
 
-/* A callback function which is invoked at cancellation points.
- * May return GOT_ERR_CANCELLED to abort the runing operation. */
-typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
-
 /*
  * Attempt to check out files into a work tree from its associated repository
  * and path prefix, and update the work tree's file index accordingly.
@@ -128,14 +124,14 @@ typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
  */
 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
     struct got_pathlist_head *, struct got_repository *,
-    got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
+    got_worktree_checkout_cb, void *, got_cancel_cb, void *);
 
 /* Merge the differences between two commits into a work tree. */
 const struct got_error *
 got_worktree_merge_files(struct got_worktree *,
     struct got_object_id *, struct got_object_id *,
     struct got_repository *, got_worktree_checkout_cb, void *,
-    got_worktree_cancel_cb, void *);
+    got_cancel_cb, void *);
 
 /* A callback function which is invoked to report a path's status. */
 typedef const struct got_error *(*got_worktree_status_cb)(void *,
@@ -149,7 +145,7 @@ typedef const struct got_error *(*got_worktree_status_cb)(void *,
  */
 const struct got_error *got_worktree_status(struct got_worktree *,
     struct got_pathlist_head *, struct got_repository *,
-    got_worktree_status_cb, void *, got_worktree_cancel_cb cancel_cb, void *);
+    got_worktree_status_cb, void *, got_cancel_cb cancel_cb, void *);
 
 /*
  * Try to resolve a user-provided path to an on-disk path in the work tree.
@@ -265,7 +261,7 @@ const struct got_error *got_worktree_rebase_in_progress(int *,
 const struct got_error *got_worktree_rebase_merge_files(
     struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
     struct got_object_id *, struct got_object_id *, struct got_repository *,
-    got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
+    got_worktree_checkout_cb, void *, got_cancel_cb, void *);
 
 /*
  * Commit changes merged by got_worktree_rebase_merge_files() to a temporary
@@ -338,7 +334,7 @@ const struct got_error *got_worktree_histedit_in_progress(int *,
 const struct got_error *got_worktree_histedit_merge_files(
     struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
     struct got_object_id *, struct got_object_id *, struct got_repository *,
-    got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
+    got_worktree_checkout_cb, void *, got_cancel_cb, void *);
 
 /*
  * Commit changes merged by got_worktree_histedit_merge_files() to a temporary
diff --git a/lib/repository.c b/lib/repository.c
index 2937089..6b47a6c 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -41,6 +41,7 @@
 #include "got_reference.h"
 #include "got_repository.h"
 #include "got_path.h"
+#include "got_cancel.h"
 #include "got_worktree.h"
 #include "got_object.h"
 
diff --git a/lib/worktree.c b/lib/worktree.c
index 715b19e..30b65e9 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -39,6 +39,7 @@
 #include "got_reference.h"
 #include "got_object.h"
 #include "got_path.h"
+#include "got_cancel.h"
 #include "got_worktree.h"
 #include "got_opentemp.h"
 #include "got_diff.h"
@@ -1386,7 +1387,7 @@ struct diff_cb_arg {
     struct got_repository *repo;
     got_worktree_checkout_cb progress_cb;
     void *progress_arg;
-    got_worktree_cancel_cb cancel_cb;
+    got_cancel_cb cancel_cb;
     void *cancel_arg;
 };
 
@@ -1782,7 +1783,7 @@ static const struct got_error *
 checkout_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
     const char *relpath, struct got_object_id *tree_id, const char *entry_name,
     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, got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL;
 	struct got_commit_object *commit = NULL;
@@ -1833,7 +1834,7 @@ const struct got_error *
 got_worktree_checkout_files(struct got_worktree *worktree,
     struct got_pathlist_head *paths, struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL, *sync_err, *unlockerr;
 	struct got_commit_object *commit = NULL;
@@ -1946,7 +1947,7 @@ struct merge_file_cb_arg {
     struct got_fileindex *fileindex;
     got_worktree_checkout_cb progress_cb;
     void *progress_arg;
-    got_worktree_cancel_cb cancel_cb;
+    got_cancel_cb cancel_cb;
     void *cancel_arg;
     struct got_object_id *commit_id2;
 };
@@ -2141,7 +2142,7 @@ merge_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
     const char *fileindex_path, struct got_object_id *commit_id1,
     struct got_object_id *commit_id2, struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL, *sync_err;
 	struct got_object_id *tree_id1 = NULL, *tree_id2 = NULL;
@@ -2191,7 +2192,7 @@ const struct got_error *
 got_worktree_merge_files(struct got_worktree *worktree,
     struct got_object_id *commit_id1, struct got_object_id *commit_id2,
     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, got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err, *unlockerr;
 	char *fileindex_path = NULL;
@@ -2233,7 +2234,7 @@ struct diff_dir_cb_arg {
     struct got_repository *repo;
     got_worktree_status_cb status_cb;
     void *status_arg;
-    got_worktree_cancel_cb cancel_cb;
+    got_cancel_cb cancel_cb;
     void *cancel_arg;
     /* A pathlist containing per-directory pathlists of ignore patterns. */
     struct got_pathlist_head ignores;
@@ -2521,7 +2522,7 @@ static const struct got_error *
 worktree_status(struct got_worktree *worktree, const char *path,
     struct got_fileindex *fileindex, struct got_repository *repo,
     got_worktree_status_cb status_cb, void *status_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL;
 	DIR *workdir = NULL;
@@ -2571,7 +2572,7 @@ const struct got_error *
 got_worktree_status(struct got_worktree *worktree,
     struct got_pathlist_head *paths, struct got_repository *repo,
     got_worktree_status_cb status_cb, void *status_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL;
 	char *fileindex_path = NULL;
@@ -4666,7 +4667,7 @@ rebase_merge_files(struct got_pathlist_head *merged_paths,
     struct got_fileindex *fileindex, struct got_object_id *parent_commit_id,
     struct got_object_id *commit_id, struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err;
 	struct got_reference *commit_ref = NULL;
@@ -4696,7 +4697,7 @@ got_worktree_rebase_merge_files(struct got_pathlist_head *merged_paths,
     struct got_object_id *parent_commit_id, struct got_object_id *commit_id,
     struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err;
 	char *commit_ref_name;
@@ -4723,7 +4724,7 @@ got_worktree_histedit_merge_files(struct got_pathlist_head *merged_paths,
     struct got_object_id *parent_commit_id, struct got_object_id *commit_id,
     struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg,
-    got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+    got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err;
 	char *commit_ref_name;
diff --git a/tog/tog.c b/tog/tog.c
index d1997e2..c92a4d0 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -50,6 +50,7 @@
 #include "got_blame.h"
 #include "got_privsep.h"
 #include "got_path.h"
+#include "got_cancel.h"
 #include "got_worktree.h"
 
 #ifndef MIN