Commit Diff


commit - 0cb83759ff5e9ca28c397bb04edb8e0629eba4bd
commit + fdfa9bf28f9d53053ad4687f6cd06c86cfe31b33
blob - 9963b821c1f57a0322e8913d88df883c8de53679
blob + c985f53d8a15c95d1676fac487eee6262a70e492
--- include/got_worktree.h
+++ include/got_worktree.h
@@ -372,7 +372,13 @@ const struct got_error *got_worktree_histedit_abort(st
 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 *,
blob - e2d15ef7a6c7d7222b3bcc4ffe515453b008c1f9
blob + a88831b22abee7e7511276c0faba475a036c7c69
--- lib/worktree.c
+++ 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 g
 	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;
 	}