commit ad10f64ebeae9e8625205b8ef468ce58e03db95b from: Stefan Sperling via: Thomas Adam date: Wed Jul 19 20:02:02 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 - affd85fdd69bb67d27045196a798015ad4479e0d commit + ad10f64ebeae9e8625205b8ef468ce58e03db95b 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 - 95de495e64d65f7ef5087c0ae6d7afebcfafd007 blob + 713ac6213adf64d341195a912b6044a3298a0c80 --- cvg/cvg.c +++ cvg/cvg.c @@ -2302,11 +2302,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; @@ -2710,7 +2711,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", @@ -4035,7 +4036,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; @@ -4542,7 +4543,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 @@ -5103,7 +5104,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 @@ -5494,7 +5495,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 @@ -5739,7 +5740,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); @@ -6302,7 +6303,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 @@ -6501,7 +6502,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); @@ -6666,7 +6667,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); @@ -6935,7 +6936,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; @@ -7379,7 +7380,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); @@ -7863,7 +7864,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); @@ -8359,7 +8360,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) @@ -8501,7 +8502,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) @@ -8817,7 +8818,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) { @@ -9048,7 +9049,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 - 722e3f26795dd133e885ae9c4d0ddd32ae4ef4b8 blob + 0681017334f8726d46e09b4d07a0ff76ca7f5b98 --- got/got.c +++ got/got.c @@ -2411,7 +2411,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 @@ -3106,11 +3106,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; @@ -3532,7 +3534,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", @@ -4687,7 +4690,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; @@ -5204,7 +5208,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 @@ -5776,7 +5781,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 @@ -6177,7 +6183,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 @@ -6432,7 +6439,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); @@ -6695,7 +6703,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 @@ -7084,7 +7093,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 @@ -7746,7 +7756,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 @@ -7951,7 +7962,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); @@ -8116,7 +8127,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); @@ -8385,7 +8396,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; @@ -8836,7 +8847,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); @@ -9311,7 +9322,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); @@ -9762,7 +9773,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 @@ -10303,7 +10314,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) @@ -10451,7 +10462,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) @@ -11267,7 +11278,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) @@ -12656,7 +12667,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) @@ -13143,7 +13154,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", @@ -13349,7 +13360,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, @@ -13707,7 +13718,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); @@ -13835,7 +13846,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); @@ -14128,7 +14139,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) { @@ -14373,7 +14384,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 - afce9e2f9b1e5a863de3014628402fe232f36894 blob + d99d2c4bcdc53e7934088a9b34c228b51e84daf1 --- gotadmin/gotadmin.c +++ gotadmin/gotadmin.c @@ -256,7 +256,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 - 6a29089f0442bf1d89182fbe94b4324e943dfb94 blob + 633fbef71fbfd1a5c044f93fc954198b06d9fb18 --- lib/error.c +++ lib/error.c @@ -107,7 +107,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 - ea52f0b95b730a506409d1fee9c8f88c42b9ca11 blob + 1c024e5aeeb4acd603dceef48511e13ebd6a8389 --- lib/fileindex.c +++ lib/fileindex.c @@ -961,7 +961,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 - 5016750ce73d6b7a793df2a669389225f19ad9c0 blob + 7cfa2e83d5c136bc98a0f67c5afab910de51a462 --- lib/worktree.c +++ lib/worktree.c @@ -147,7 +147,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; @@ -185,8 +185,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; } @@ -294,7 +294,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; @@ -335,7 +335,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; @@ -1199,7 +1199,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]; @@ -1250,9 +1251,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; @@ -1309,7 +1309,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; @@ -2426,7 +2426,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"); } @@ -2480,7 +2480,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; } @@ -5583,7 +5583,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) { @@ -8943,7 +8944,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 - da26fa9ba9a5717c35d77d398c8661e5fa721527 blob + 5e907496b89f49a5b541e0d5556b7bff8d65f838 --- lib/worktree_open.c +++ lib/worktree_open.c @@ -40,6 +40,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) { @@ -105,10 +109,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; @@ -121,13 +126,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; @@ -140,7 +145,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; @@ -167,22 +172,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); @@ -204,14 +210,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; } @@ -239,7 +245,7 @@ done: if (err == NULL) err = pack_err; } - free(path_got); + free(path_meta); free(path_lock); free(base_commit_id_str); free(uuidstr); @@ -257,10 +263,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) @@ -269,7 +281,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 - 22c6366282c4b644e5f36a4e1ab4a639793c4c0b blob + abf8c21edb245a96720b8a92f3d1ea6fe1c6a36b --- tog/tog.c +++ tog/tog.c @@ -4449,7 +4449,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) @@ -5976,7 +5976,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) @@ -7092,7 +7092,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) @@ -8071,7 +8071,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) @@ -8952,7 +8952,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) @@ -9783,7 +9783,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;