Commit Diff


commit - 2e8aa2402ee81767f9a2e99ac7f47494806adb61
commit + 577ec78f7e6f997c163d0aaa36ca04279d4196f7
blob - 0925d8494a96526e4f3ef494045fddcaf51827c3
blob + 82a6215be475814bc499728772aa2f36a334cdaf
--- include/got_worktree.h
+++ include/got_worktree.h
@@ -17,7 +17,7 @@
 struct got_worktree;
 
 const struct got_error *got_worktree_init(const char *, struct got_reference *,
-    struct got_repository *);
+    const char *, struct got_repository *);
 const struct got_error *got_worktree_open(struct got_worktree **, const char *);
 void got_worktree_close(struct got_worktree *);
 char *got_worktree_get_repo_path(struct got_worktree *);
blob - f49af4462fbbafaf62103a6217682cd77b3f9449
blob + 39417fca0a9443677e3ab37ff1dd7a3357ef0129
--- lib/got_worktree_priv.h
+++ lib/got_worktree_priv.h
@@ -17,11 +17,13 @@
 struct got_worktree {
 	char *path_worktree_root;
 	char *path_repo;
+	char *path_prefix;
 };
 
-#define GOT_WORKTREE_GOT_DIR	".got"
-#define GOT_WORKTREE_FILE_INDEX	"fileindex"
-#define GOT_WORKTREE_REPOSITORY	"repository"
-#define GOT_WORKTREE_FORMAT	"format"
+#define GOT_WORKTREE_GOT_DIR		".got"
+#define GOT_WORKTREE_FILE_INDEX		"fileindex"
+#define GOT_WORKTREE_REPOSITORY		"repository"
+#define GOT_WORKTREE_PATH_PREFIX	"path-prefix"
+#define GOT_WORKTREE_FORMAT		"format"
 
 #define GOT_WORKTREE_FORMAT_VERSION	1
blob - cf72425c625babfce4779a5d6ddba71bb5856ffb
blob + 0d7bf54d0023cc5b92eb8a181c1bd3d8ce5329b7
--- lib/worktree.c
+++ lib/worktree.c
@@ -78,7 +78,7 @@ done:
 
 const struct got_error *
 got_worktree_init(const char *path, struct got_reference *head_ref,
-    struct got_repository *repo)
+    const char *prefix, struct got_repository *repo)
 {
 	const struct got_error *err = NULL;
 	char *abspath = NULL;
@@ -88,6 +88,9 @@ got_worktree_init(const char *path, struct got_referen
 	char *path_repos = NULL;
 	char *formatstr = NULL;
 
+	if (!got_path_is_absolute(prefix))
+		return got_error(GOT_ERR_BAD_PATH);
+
 	if (got_path_is_absolute(path)) {
 		abspath = strdup(path);
 		if (abspath == NULL)
@@ -144,6 +147,11 @@ got_worktree_init(const char *path, struct got_referen
 	if (err)
 		goto done;
 
+	/* Store in-repository path prefix. */
+	err = create_meta_file(gotpath, GOT_WORKTREE_PATH_PREFIX, prefix);
+	if (err)
+		goto done;
+
 	/* Stamp work tree with format file. */
 	if (asprintf(&formatstr, "%d", GOT_WORKTREE_FORMAT_VERSION) == -1) {
 		err = got_error(GOT_ERR_NO_MEM);
blob - cad1391f834a5c431a11516c16e8d13cb8a1be97
blob + ec99a28c1c9c643626df9ed7c9de996380b31425
--- regress/worktree/worktree_test.c
+++ regress/worktree/worktree_test.c
@@ -83,6 +83,7 @@ remove_workdir(const char *worktree_path)
 	remove_meta_file(worktree_path, GOT_REF_HEAD);
 	remove_meta_file(worktree_path, GOT_WORKTREE_FILE_INDEX);
 	remove_meta_file(worktree_path, GOT_WORKTREE_REPOSITORY);
+	remove_meta_file(worktree_path, GOT_WORKTREE_PATH_PREFIX);
 	remove_meta_file(worktree_path, GOT_WORKTREE_FORMAT);
 	remove_got_dir(worktree_path);
 	rmdir(worktree_path);
@@ -125,7 +126,7 @@ worktree_init(const char *repo_path)
 	if (mkdtemp(worktree_path) == NULL)
 		goto done;
 
-	err = got_worktree_init(worktree_path, head_ref, repo);
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
 	if (err != NULL)
 		goto done;
 
@@ -136,6 +137,8 @@ worktree_init(const char *repo_path)
 		goto done;
 	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_REPOSITORY))
 		goto done;
+	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_PATH_PREFIX))
+		goto done;
 	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_FORMAT))
 		goto done;
 	ok = 1;
@@ -205,7 +208,7 @@ worktree_init_exists(const char *repo_path)
 
 	if (!obstruct_meta_file(&path, worktree_path, GOT_REF_HEAD))
 		goto done;
-	err = got_worktree_init(worktree_path, head_ref, repo);
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
 	if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST)
 		ok++;
 	unlink(path);
@@ -213,7 +216,7 @@ worktree_init_exists(const char *repo_path)
 
 	if (!obstruct_meta_file(&path, worktree_path, GOT_WORKTREE_FILE_INDEX))
 		goto done;
-	err = got_worktree_init(worktree_path, head_ref, repo);
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
 	if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST)
 		ok++;
 	unlink(path);
@@ -221,15 +224,23 @@ worktree_init_exists(const char *repo_path)
 
 	if (!obstruct_meta_file(&path, worktree_path, GOT_WORKTREE_REPOSITORY))
 		goto done;
-	err = got_worktree_init(worktree_path, head_ref, repo);
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
 	if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST)
 		ok++;
 	unlink(path);
 	free(path);
 
+	if (!obstruct_meta_file(&path, worktree_path, GOT_WORKTREE_PATH_PREFIX))
+		goto done;
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
+	if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST)
+		ok++;
+	unlink(path);
+	free(path);
+
 	if (!obstruct_meta_file(&path, worktree_path, GOT_WORKTREE_FORMAT))
 		goto done;
-	err = got_worktree_init(worktree_path, head_ref, repo);
+	err = got_worktree_init(worktree_path, head_ref, "/", repo);
 	if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST)
 		ok++;
 	unlink(path);
@@ -241,9 +252,9 @@ done:
 	if (repo)
 		got_repo_close(repo);
 	free(gotpath);
-	if (ok == 4)
+	if (ok == 5)
 		remove_workdir(worktree_path);
-	return (ok == 4);
+	return (ok == 5);
 }
 
 #define RUN_TEST(expr, name) \