make struct got_commitable opaque to library users
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/got/got.c b/got/got.c
index 46b3ebb..3891b67 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2345,7 +2345,9 @@ collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_commitable *ct = pe->data;
- dprintf(fd, "# %c %s\n", ct->status, pe->path);
+ dprintf(fd, "# %c %s\n",
+ got_commitable_get_status(ct),
+ got_commitable_get_path(ct));
}
close(fd);
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 153a8c6..2c68c6d 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -15,6 +15,7 @@
*/
struct got_worktree;
+struct got_commitable;
/* status codes */
#define GOT_STATUS_NO_CHANGE ' '
@@ -30,20 +31,6 @@ struct got_worktree;
#define GOT_STATUS_OBSTRUCTED '~'
#define GOT_STATUS_REVERT 'R'
-/* XXX TODO make this opaque */
-struct got_commitable {
- char *path;
- char *in_repo_path;
- char *ondisk_path;
- unsigned char status;
- struct got_object_id *blob_id;
- struct got_object_id *base_blob_id;
- struct got_object_id *base_commit_id;
- mode_t mode;
- int flags;
-#define GOT_COMMITABLE_ADDED 0x01
-};
-
/*
* Attempt to initialize a new work tree on disk.
* The first argument is the path to a directory where the work tree
@@ -182,9 +169,10 @@ const struct got_error *got_worktree_revert(struct got_worktree *,
/*
* A callback function which is invoked when a commit message is requested.
- * Passes a list of modified paths being committed to, a pointer to the log
- * message that must be set by the callback and will be freed after committing,
- * and an argument passed through to the callback.
+ * Passes a pathlist with a struct got_commitable * in the data pointer of
+ * each element, a pointer to the log message that must be set by the
+ * callback and will be freed after committing, and an argument passed
+ * through to the callback.
*/
typedef const struct got_error *(*got_worktree_commit_msg_cb)(
struct got_pathlist_head *, char **, void *);
@@ -203,3 +191,9 @@ const struct got_error *got_worktree_commit(struct got_object_id **,
struct got_worktree *, const char *, const char *, const char *,
got_worktree_commit_msg_cb, void *,
got_worktree_status_cb, void *, struct got_repository *);
+
+/* Get the path of a commitable worktree item. */
+const char *got_commitable_get_path(struct got_commitable *);
+
+/* Get the status of a commitable worktree item. */
+unsigned int got_commitable_get_status(struct got_commitable *);
diff --git a/lib/got_lib_worktree.h b/lib/got_lib_worktree.h
index 222d5b8..84f3dc1 100644
--- a/lib/got_lib_worktree.h
+++ b/lib/got_lib_worktree.h
@@ -35,6 +35,19 @@ struct got_worktree {
int lockfd;
};
+struct got_commitable {
+ char *path;
+ char *in_repo_path;
+ char *ondisk_path;
+ unsigned char status;
+ struct got_object_id *blob_id;
+ struct got_object_id *base_blob_id;
+ struct got_object_id *base_commit_id;
+ mode_t mode;
+ int flags;
+#define GOT_COMMITABLE_ADDED 0x01
+};
+
#define GOT_WORKTREE_GOT_DIR ".got"
#define GOT_WORKTREE_FILE_INDEX "file-index"
#define GOT_WORKTREE_REPOSITORY "repository"
diff --git a/lib/worktree.c b/lib/worktree.c
index 8fe0105..813c260 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3045,3 +3045,15 @@ done:
}
return err;
}
+
+const char *
+got_commitable_get_path(struct got_commitable *ct)
+{
+ return ct->path;
+}
+
+unsigned int
+got_commitable_get_status(struct got_commitable *ct)
+{
+ return ct->status;
+}