commit df6221c7df42758252c508006201c3f66e6ae831 from: Stefan Sperling date: Wed Jul 19 10:55:53 2023 UTC use a separate .cvg meta data directory for cvg(1) work trees This prevents mixing the use of got and cvg clients in the same work tree. Avoids confusion going forward while cvg differentiates itself further. tog(1) and gotadmin(1) remain compatible with both work tree formats. These tools only read work trees to locate the corresponding repository. commit - bff07ce328569d14e4638b7a32f4a92eb32ecc9e commit + df6221c7df42758252c508006201c3f66e6ae831 blob - 110ff29fdcc380ec042d16545ed9b818b713b3c7 blob + d5843bbce4cf6da211bc8e9a2c23bddcd868ba19 --- cvg/cvg.1 +++ cvg/cvg.1 @@ -1792,13 +1792,13 @@ supersedes any relevant settings in Git's .Pa config file. .Pp -.It Pa .got/got.conf +.It Pa .cvg/got.conf Worktree-specific configuration settings for .Nm . If present, a .Xr got.conf 5 configuration file in the -.Pa .got +.Pa .cvg meta-data directory of a work tree supersedes any relevant settings in the repository's .Xr got.conf 5 blob - 2ecf3b8dd41a4dc96f1546691ad57fa09b14470f blob + 395b21d6bf1ba81c76d54f3c0c75a094440ca583 --- cvg/cvg.c +++ cvg/cvg.c @@ -2304,11 +2304,12 @@ cmd_checkout(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_init(worktree_path, head_ref, path_prefix, repo); + error = got_worktree_init(worktree_path, head_ref, path_prefix, + GOT_WORKTREE_CVG_DIR, repo); if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST)) goto done; - error = got_worktree_open(&worktree, worktree_path); + error = got_worktree_open(&worktree, worktree_path, GOT_WORKTREE_CVG_DIR); if (error != NULL) goto done; @@ -2712,7 +2713,7 @@ cmd_update(int argc, char *argv[]) error = got_error_from_errno("getcwd"); goto done; } - error = got_worktree_open(&worktree, worktree_path); + error = got_worktree_open(&worktree, worktree_path, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "update", @@ -4037,7 +4038,7 @@ cmd_log(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; error = NULL; @@ -4544,7 +4545,7 @@ cmd_diff(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -5105,7 +5106,7 @@ cmd_blame(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -5496,7 +5497,7 @@ cmd_tree(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -5741,7 +5742,7 @@ cmd_status(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "status", cwd); @@ -6304,7 +6305,7 @@ cmd_tag(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -6503,7 +6504,7 @@ cmd_add(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "add", cwd); @@ -6668,7 +6669,7 @@ cmd_remove(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "remove", cwd); @@ -6937,7 +6938,7 @@ cmd_patch(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error != NULL) goto done; @@ -7381,7 +7382,7 @@ cmd_revert(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "revert", cwd); @@ -7865,7 +7866,7 @@ cmd_commit(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "commit", cwd); @@ -8361,7 +8362,7 @@ cmd_cherrypick(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (list_refs || remove_refs) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -8503,7 +8504,7 @@ cmd_backout(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (list_refs || remove_refs) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -8819,7 +8820,7 @@ cmd_cat(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) { @@ -9050,7 +9051,7 @@ cmd_info(int argc, char *argv[]) goto done; } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_CVG_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "info", cwd); blob - d762fe811564e7d6320b7826fb5a9680e3900517 blob + 11de03d9dc00687d501d46094c4ba5444e8c8cb6 --- got/got.c +++ got/got.c @@ -2412,7 +2412,7 @@ cmd_fetch(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -3107,11 +3107,13 @@ cmd_checkout(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_init(worktree_path, head_ref, path_prefix, repo); + error = got_worktree_init(worktree_path, head_ref, path_prefix, + GOT_WORKTREE_GOT_DIR, repo); if (error != NULL && !(error->code == GOT_ERR_ERRNO && errno == EEXIST)) goto done; - error = got_worktree_open(&worktree, worktree_path); + error = got_worktree_open(&worktree, worktree_path, + GOT_WORKTREE_GOT_DIR); if (error != NULL) goto done; @@ -3533,7 +3535,8 @@ cmd_update(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, worktree_path); + error = got_worktree_open(&worktree, worktree_path, + GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "update", @@ -4688,7 +4691,8 @@ cmd_log(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; error = NULL; @@ -5205,7 +5209,8 @@ cmd_diff(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -5777,7 +5782,8 @@ cmd_blame(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -6178,7 +6184,8 @@ cmd_tree(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -6433,7 +6440,8 @@ cmd_status(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "status", cwd); @@ -6696,7 +6704,8 @@ cmd_ref(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -7085,7 +7094,8 @@ cmd_branch(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -7747,7 +7757,8 @@ cmd_tag(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, + GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -7952,7 +7963,7 @@ cmd_add(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "add", cwd); @@ -8117,7 +8128,7 @@ cmd_remove(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "remove", cwd); @@ -8386,7 +8397,7 @@ cmd_patch(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error != NULL) goto done; @@ -8837,7 +8848,7 @@ cmd_revert(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "revert", cwd); @@ -9312,7 +9323,7 @@ cmd_commit(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "commit", cwd); @@ -9763,7 +9774,7 @@ cmd_send(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; else @@ -10304,7 +10315,7 @@ cmd_cherrypick(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (list_refs || remove_refs) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -10452,7 +10463,7 @@ cmd_backout(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (list_refs || remove_refs) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -11268,7 +11279,7 @@ cmd_rebase(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (list_backups || delete_backups) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -12657,7 +12668,7 @@ cmd_histedit(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (list_backups || delete_backups) { if (error->code != GOT_ERR_NOT_WORKTREE) @@ -13144,7 +13155,7 @@ cmd_integrate(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "integrate", @@ -13350,7 +13361,7 @@ cmd_merge(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, @@ -13708,7 +13719,7 @@ cmd_stage(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "stage", cwd); @@ -13836,7 +13847,7 @@ cmd_unstage(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "unstage", cwd); @@ -14129,7 +14140,7 @@ cmd_cat(int argc, char *argv[]) goto done; if (repo_path == NULL) { - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) { @@ -14374,7 +14385,7 @@ cmd_info(int argc, char *argv[]) goto done; } - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, GOT_WORKTREE_GOT_DIR); if (error) { if (error->code == GOT_ERR_NOT_WORKTREE) error = wrap_not_worktree_error(error, "info", cwd); blob - 9480ca036e0727eb650ea94c3379acdcb64a26b1 blob + ac13af4d643c13b2ba5b2cdc4285db4bb2b2789c --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -257,7 +257,7 @@ get_repo_path(char **repo_path) if (cwd == NULL) return got_error_from_errno("getcwd"); - err = got_worktree_open(&worktree, cwd); + err = got_worktree_open(&worktree, cwd, NULL); if (err) { if (err->code != GOT_ERR_NOT_WORKTREE) goto done; blob - 5b0b7259e6ff5fc0edf8711ac6780dd49315fe54 blob + 53e320eef8622a3384a31606d0cd2fe64d9ea60a --- include/got_worktree.h +++ include/got_worktree.h @@ -39,6 +39,10 @@ struct got_fileindex; #define GOT_STATUS_BASE_REF_ERR 'B' #define GOT_STATUS_CANNOT_UPDATE '#' +/* Also defined in got_lib_worktree.h in case got_worktree.h is not included. */ +#define GOT_WORKTREE_GOT_DIR ".got" +#define GOT_WORKTREE_CVG_DIR ".cvg" + /* * Attempt to initialize a new work tree on disk. * The first argument is the path to a directory where the work tree @@ -46,15 +50,21 @@ struct got_fileindex; * of the path must already exist. * The reference provided will be used to determine the new worktree's * base commit. The third argument speficies the work tree's path prefix. + * The fourth argument specifies the meta data directory to use, which + * should be either GOT_WORKTREE_GOT_DIR or GOT_WORKTREE_CVG_DIR. */ const struct got_error *got_worktree_init(const char *, struct got_reference *, - const char *, struct got_repository *); + const char *, const char *, struct got_repository *); /* - * Attempt to open a worktree at or above the specified path. + * Attempt to open a worktree at or above the specified path, using + * the specified meta data directory which should be either be NULL + * in which case a meta directory is auto-discovered, or be one of + * GOT_WORKTREE_GOT_DIR and GOT_WORKTREE_CVG_DIR. * The caller must dispose of it with got_worktree_close(). */ -const struct got_error *got_worktree_open(struct got_worktree **, const char *); +const struct got_error *got_worktree_open(struct got_worktree **, + const char *path, const char *meta_dir); /* Dispose of an open work tree. */ const struct got_error *got_worktree_close(struct got_worktree *); blob - 5d970a01a42033eb7fed3d588895e1ec8def46df blob + 44d2e9fa2efa721d3ada4822ca376499668d31aa --- lib/error.c +++ lib/error.c @@ -99,7 +99,7 @@ static const struct got_error got_errors[] = { { GOT_ERR_BAD_REF_DATA, "could not parse reference data" }, { GOT_ERR_TREE_DUP_ENTRY,"duplicate entry in tree object" }, { GOT_ERR_DIR_DUP_ENTRY,"duplicate entry in directory" }, - { GOT_ERR_NOT_WORKTREE, "no got work tree found" }, + { GOT_ERR_NOT_WORKTREE, "no work tree found" }, { GOT_ERR_UUID_VERSION, "bad uuid version" }, { GOT_ERR_UUID_INVALID, "uuid invalid" }, { GOT_ERR_UUID, "uuid error" }, blob - 6994c4024682259cc76c3a24d97361051a9b8ee5 blob + e989c6b7cd01f55aa6173b8bbf04441802b11fe6 --- lib/fileindex.c +++ lib/fileindex.c @@ -964,7 +964,9 @@ read_dirlist(struct got_pathlist_head *dirlist, DIR *d if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0 || (path[0] == '\0' && - strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) { + strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0) || + (path[0] == '\0' && + strcmp(de->d_name, GOT_WORKTREE_CVG_DIR) == 0)) { free(de); continue; } blob - ad838e489f8aceca0aa34848ae7cb128cb78dd53 blob + 8404383b2b9474368777c6f7dcb3a552605c907a --- lib/got_lib_worktree.h +++ lib/got_lib_worktree.h @@ -16,6 +16,7 @@ struct got_worktree { char *root_path; + const char *meta_dir; char *repo_path; int root_fd; char *path_prefix; @@ -57,7 +58,14 @@ struct got_commitable { #define GOT_COMMITABLE_ADDED 0x01 }; +/* Also defined in got_worktree.h */ +#ifndef GOT_WORKTREE_GOT_DIR #define GOT_WORKTREE_GOT_DIR ".got" +#endif +#ifndef GOT_WORKTREE_CVG_DIR +#define GOT_WORKTREE_CVG_DIR ".cvg" +#endif + #define GOT_WORKTREE_FILE_INDEX "file-index" #define GOT_WORKTREE_REPOSITORY "repository" #define GOT_WORKTREE_PATH_PREFIX "path-prefix" blob - 0057e61e6db15e140ea00a36f04722389b25a0ba blob + 5400e1336138a373e1307ff721ae4d68d5633075 --- lib/worktree.c +++ lib/worktree.c @@ -150,7 +150,7 @@ write_head_ref(const char *path_got, struct got_refere const struct got_error * got_worktree_init(const char *path, struct got_reference *head_ref, - const char *prefix, struct got_repository *repo) + const char *prefix, const char *meta_dir, struct got_repository *repo) { const struct got_error *err = NULL; struct got_object_id *commit_id = NULL; @@ -188,8 +188,8 @@ got_worktree_init(const char *path, struct got_referen goto done; } - /* Create .got directory (may already exist). */ - if (asprintf(&path_got, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) { + /* Create .got/.cvg directory (may already exist). */ + if (asprintf(&path_got, "%s/%s", path, meta_dir) == -1) { err = got_error_from_errno("asprintf"); goto done; } @@ -297,7 +297,7 @@ got_worktree_set_head_ref(struct got_worktree *worktre char *path_got = NULL, *head_ref_name = NULL; if (asprintf(&path_got, "%s/%s", worktree->root_path, - GOT_WORKTREE_GOT_DIR) == -1) { + worktree->meta_dir) == -1) { err = got_error_from_errno("asprintf"); path_got = NULL; goto done; @@ -338,7 +338,7 @@ got_worktree_set_base_commit_id(struct got_worktree *w char *path_got = NULL; if (asprintf(&path_got, "%s/%s", worktree->root_path, - GOT_WORKTREE_GOT_DIR) == -1) { + worktree->meta_dir) == -1) { err = got_error_from_errno("asprintf"); path_got = NULL; goto done; @@ -1202,7 +1202,8 @@ replace_existing_symlink(int *did_something, const cha static const struct got_error * is_bad_symlink_target(int *is_bad_symlink, const char *target_path, - size_t target_len, const char *ondisk_path, const char *wtroot_path) + size_t target_len, const char *ondisk_path, const char *wtroot_path, + const char *meta_dir) { const struct got_error *err = NULL; char canonpath[PATH_MAX]; @@ -1253,9 +1254,8 @@ is_bad_symlink_target(int *is_bad_symlink, const char return NULL; } - /* Do not allow symlinks pointing into the .got directory. */ - if (asprintf(&path_got, "%s/%s", wtroot_path, - GOT_WORKTREE_GOT_DIR) == -1) + /* Do not allow symlinks pointing into the meta directory. */ + if (asprintf(&path_got, "%s/%s", wtroot_path, meta_dir) == -1) return got_error_from_errno("asprintf"); if (got_path_is_child(canonpath, path_got, strlen(path_got))) *is_bad_symlink = 1; @@ -1312,7 +1312,7 @@ install_symlink(int *is_bad_symlink, struct got_worktr target_path[target_len] = '\0'; err = is_bad_symlink_target(is_bad_symlink, target_path, target_len, - ondisk_path, worktree->root_path); + ondisk_path, worktree->root_path, worktree->meta_dir); if (err) return err; @@ -2429,7 +2429,7 @@ got_worktree_get_histedit_script_path(char **path, struct got_worktree *worktree) { if (asprintf(path, "%s/%s/%s", worktree->root_path, - GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_HISTEDIT_SCRIPT) == -1) { + worktree->meta_dir, GOT_WORKTREE_HISTEDIT_SCRIPT) == -1) { *path = NULL; return got_error_from_errno("asprintf"); } @@ -2483,7 +2483,7 @@ get_fileindex_path(char **fileindex_path, struct got_w const struct got_error *err = NULL; if (asprintf(fileindex_path, "%s/%s/%s", worktree->root_path, - GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) { + worktree->meta_dir, GOT_WORKTREE_FILE_INDEX) == -1) { err = got_error_from_errno("asprintf"); *fileindex_path = NULL; } @@ -5586,7 +5586,8 @@ collect_commitables(void *arg, unsigned char status, goto done; } err = is_bad_symlink_target(&is_bad_symlink, target_path, - target_len, ct->ondisk_path, a->worktree->root_path); + target_len, ct->ondisk_path, a->worktree->root_path, + a->worktree->meta_dir); if (err) goto done; if (is_bad_symlink) { @@ -8946,7 +8947,8 @@ stage_path(void *arg, unsigned char status, } err = is_bad_symlink_target(&is_bad_symlink, target_path, target_len, ondisk_path, - a->worktree->root_path); + a->worktree->root_path, + a->worktree->meta_dir); if (err) break; if (is_bad_symlink) { blob - 1fd944cee5f298a85e2b478b512037f6a0a3ef25 blob + c3846b45dec95fcd923225f11b5f013d97fc39c0 --- lib/worktree_open.c +++ lib/worktree_open.c @@ -41,6 +41,10 @@ #include "got_lib_worktree.h" #include "got_lib_gotconfig.h" +#ifndef nitems +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif + static const struct got_error * read_meta_file(char **content, const char *path_got, const char *name) { @@ -106,10 +110,11 @@ done: } static const struct got_error * -open_worktree(struct got_worktree **worktree, const char *path) +open_worktree(struct got_worktree **worktree, const char *path, + const char *meta_dir) { const struct got_error *err = NULL; - char *path_got; + char *path_meta; char *formatstr = NULL; char *uuidstr = NULL; char *path_lock = NULL; @@ -122,13 +127,13 @@ open_worktree(struct got_worktree **worktree, const ch *worktree = NULL; - if (asprintf(&path_got, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) { + if (asprintf(&path_meta, "%s/%s", path, meta_dir) == -1) { err = got_error_from_errno("asprintf"); - path_got = NULL; + path_meta = NULL; goto done; } - if (asprintf(&path_lock, "%s/%s", path_got, GOT_WORKTREE_LOCK) == -1) { + if (asprintf(&path_lock, "%s/%s", path_meta, GOT_WORKTREE_LOCK) == -1) { err = got_error_from_errno("asprintf"); path_lock = NULL; goto done; @@ -141,7 +146,7 @@ open_worktree(struct got_worktree **worktree, const ch goto done; } - err = read_meta_file(&formatstr, path_got, GOT_WORKTREE_FORMAT); + err = read_meta_file(&formatstr, path_meta, GOT_WORKTREE_FORMAT); if (err) goto done; @@ -168,22 +173,23 @@ open_worktree(struct got_worktree **worktree, const ch err = got_error_from_errno2("realpath", path); goto done; } - err = read_meta_file(&(*worktree)->repo_path, path_got, + (*worktree)->meta_dir = meta_dir; + err = read_meta_file(&(*worktree)->repo_path, path_meta, GOT_WORKTREE_REPOSITORY); if (err) goto done; - err = read_meta_file(&(*worktree)->path_prefix, path_got, + err = read_meta_file(&(*worktree)->path_prefix, path_meta, GOT_WORKTREE_PATH_PREFIX); if (err) goto done; - err = read_meta_file(&base_commit_id_str, path_got, + err = read_meta_file(&base_commit_id_str, path_meta, GOT_WORKTREE_BASE_COMMIT); if (err) goto done; - err = read_meta_file(&uuidstr, path_got, GOT_WORKTREE_UUID); + err = read_meta_file(&uuidstr, path_meta, GOT_WORKTREE_UUID); if (err) goto done; uuid_from_string(uuidstr, &(*worktree)->uuid, &uuid_status); @@ -205,14 +211,14 @@ open_worktree(struct got_worktree **worktree, const ch if (err) goto done; - err = read_meta_file(&(*worktree)->head_ref_name, path_got, + err = read_meta_file(&(*worktree)->head_ref_name, path_meta, GOT_WORKTREE_HEAD_REF); if (err) goto done; if (asprintf(&(*worktree)->gotconfig_path, "%s/%s/%s", - (*worktree)->root_path, - GOT_WORKTREE_GOT_DIR, GOT_GOTCONFIG_FILENAME) == -1) { + (*worktree)->root_path, (*worktree)->meta_dir, + GOT_GOTCONFIG_FILENAME) == -1) { err = got_error_from_errno("asprintf"); goto done; } @@ -240,7 +246,7 @@ done: if (err == NULL) err = pack_err; } - free(path_got); + free(path_meta); free(path_lock); free(base_commit_id_str); free(uuidstr); @@ -258,10 +264,16 @@ done: } const struct got_error * -got_worktree_open(struct got_worktree **worktree, const char *path) +got_worktree_open(struct got_worktree **worktree, const char *path, + const char *meta_dir) { const struct got_error *err = NULL; char *worktree_path; + const char *meta_dirs[] = { + GOT_WORKTREE_GOT_DIR, + GOT_WORKTREE_CVG_DIR + }; + int i; worktree_path = strdup(path); if (worktree_path == NULL) @@ -270,7 +282,15 @@ got_worktree_open(struct got_worktree **worktree, cons for (;;) { char *parent_path; - err = open_worktree(worktree, worktree_path); + if (meta_dir == NULL) { + for (i = 0; i < nitems(meta_dirs); i++) { + err = open_worktree(worktree, worktree_path, + meta_dirs[i]); + if (err == NULL) + break; + } + } else + err = open_worktree(worktree, worktree_path, meta_dir); if (err && !(err->code == GOT_ERR_ERRNO && errno == ENOENT)) { free(worktree_path); return err; blob - 592e477643b13ce4e2a8ce6037f11ee4ba539cdf blob + c4c9f0b2ff7a958007c590e9b66a21cb9ad13a07 --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -71,7 +71,7 @@ test_diff_basic() { # 'got diff' in a repository without any arguments is an error (cd $testroot/repo && got diff 2> $testroot/stderr) - echo "got: no got work tree found" > $testroot/stderr.expected + echo "got: no work tree found" > $testroot/stderr.expected cmp -s $testroot/stderr.expected $testroot/stderr ret=$? if [ $ret -ne 0 ]; then @@ -1239,7 +1239,7 @@ test_diff_commits() { test_done "$testroot" "1" return 1 fi - echo "got: specified paths cannot be resolved: no got work tree found" \ + echo "got: specified paths cannot be resolved: no work tree found" \ > $testroot/stderr.expected cmp -s $testroot/stderr.expected $testroot/stderr ret=$? blob - 7bb059ecfaa26dc3c7b8d9f630f63c581d525b9b blob + 9479ad1b9a79971165d3eaf5e113e8d1b6ff0ff7 --- tog/tog.c +++ tog/tog.c @@ -4445,7 +4445,7 @@ cmd_log(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) @@ -5972,7 +5972,7 @@ cmd_diff(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) @@ -7088,7 +7088,7 @@ cmd_blame(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) @@ -8067,7 +8067,7 @@ cmd_tree(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) @@ -8948,7 +8948,7 @@ cmd_ref(int argc, char *argv[]) cwd = getcwd(NULL, 0); if (cwd == NULL) return got_error_from_errno("getcwd"); - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done; if (worktree) @@ -9779,7 +9779,7 @@ tog_log_with_path(int argc, char *argv[]) if (error != NULL) goto done; - error = got_worktree_open(&worktree, cwd); + error = got_worktree_open(&worktree, cwd, NULL); if (error && error->code != GOT_ERR_NOT_WORKTREE) goto done;