Commit 8656d6c4d5273b7a838b8d2b0b057891e50a2ece

Stefan Sperling 2019-05-20T16:31:38

make struct got_commitable opaque to library users

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;
+}