commit - 2e8aa2402ee81767f9a2e99ac7f47494806adb61
commit + 577ec78f7e6f997c163d0aaa36ca04279d4196f7
blob - 0925d8494a96526e4f3ef494045fddcaf51827c3
blob + 82a6215be475814bc499728772aa2f36a334cdaf
--- include/got_worktree.h
+++ include/got_worktree.h
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
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
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;
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)
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
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);
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;
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;
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);
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);
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);
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) \