provide a way for API users to override staged file content
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
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 9963b82..c985f53 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -372,7 +372,13 @@ const struct got_error *got_worktree_histedit_abort(struct got_worktree *,
const struct got_error *got_worktree_get_histedit_script_path(char **,
struct got_worktree *);
-/* Stage the specified paths for commit. */
+/*
+ * Stage the specified paths for commit.
+ * If the 'data' pointer of a pathlist element on the path list is NULL then
+ * stage the content of the entire file at this path. Otherwise, the 'data'
+ * pointer is expected to point at a const char * path of a file which
+ * contains alternative content to be staged instead.
+*/
const struct got_error *got_worktree_stage_paths(struct got_worktree *,
struct got_pathlist_head *, struct got_repository *,
got_worktree_status_cb, void *,
diff --git a/lib/worktree.c b/lib/worktree.c
index e2d15ef..a88831b 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4858,8 +4858,9 @@ done:
}
static const struct got_error *
-stage_path(const char *path, size_t path_len, struct got_worktree *worktree,
- struct got_fileindex *fileindex, struct got_repository *repo,
+stage_path(const char *path, size_t path_len, const char *path_content,
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_repository *repo,
got_worktree_status_cb status_cb, void *status_arg)
{
const struct got_error *err = NULL;
@@ -4886,8 +4887,8 @@ stage_path(const char *path, size_t path_len, struct got_worktree *worktree,
switch (status) {
case GOT_STATUS_ADD:
case GOT_STATUS_MODIFY:
- err = got_object_blob_create(&blob_id, ondisk_path,
- repo);
+ err = got_object_blob_create(&blob_id,
+ path_content ? path_content : ondisk_path, repo);
if (err)
goto done;
memcpy(ie->staged_blob_sha1, blob_id->sha1,
@@ -4940,8 +4941,8 @@ got_worktree_stage_paths(struct got_worktree *worktree,
if (err)
break;
}
- err = stage_path(pe->path, pe->path_len, worktree, fileindex,
- repo, status_cb, status_arg);
+ err = stage_path(pe->path, pe->path_len, (const char *)pe->data,
+ worktree, fileindex, repo, status_cb, status_arg);
if (err)
break;
}