commit 65596e15914f3e70494e33e84a842d7ce360c1e7 from: Stefan Sperling date: Mon Dec 24 18:59:50 2018 UTC store base commit in a dedicated meta file commit - 08d425ea092f7cc3bf70f4cbc3ed30ffc0b9772b commit + 65596e15914f3e70494e33e84a842d7ce360c1e7 blob - 5694eaebb55252cb517324287f062e32a9a29b19 blob + f308aded447a9b1eb4bd3254941d0239b56abd64 --- lib/got_lib_worktree.h +++ lib/got_lib_worktree.h @@ -39,6 +39,7 @@ struct got_worktree { #define GOT_WORKTREE_REPOSITORY "repository" #define GOT_WORKTREE_PATH_PREFIX "path-prefix" #define GOT_WORKTREE_HEAD "head" +#define GOT_WORKTREE_BASE "base" #define GOT_WORKTREE_LOCK "lock" #define GOT_WORKTREE_FORMAT "format" blob - c0c6adc686d7806615bf8af3fcbf5d9649aefe7c blob + f44df5ba61c7b288ade196d3ade7a0617ebf9b68 --- lib/worktree.c +++ lib/worktree.c @@ -155,11 +155,23 @@ got_worktree_init(const char *path, struct got_referen const char *prefix, struct got_repository *repo) { const struct got_error *err = NULL; + struct got_object_id *commit_id = NULL; + int obj_type; char *path_got = NULL; char *refstr = NULL; char *repo_path = NULL; char *formatstr = NULL; char *absprefix = NULL; + char *basestr = NULL; + + err = got_ref_resolve(&commit_id, repo, head_ref); + if (err) + return err; + err = got_object_get_type(&obj_type, repo, commit_id); + if (err) + return err; + if (obj_type != GOT_OBJ_TYPE_COMMIT) + return got_error(GOT_ERR_OBJ_TYPE); if (!got_path_is_absolute(prefix)) { if (asprintf(&absprefix, "/%s", prefix) == -1) @@ -199,6 +211,14 @@ got_worktree_init(const char *path, struct got_referen goto done; } err = create_meta_file(path_got, GOT_WORKTREE_HEAD, refstr); + if (err) + goto done; + + /* Record our base commit. */ + err = got_object_id_str(&basestr, commit_id); + if (err) + goto done; + err = create_meta_file(path_got, GOT_WORKTREE_BASE, basestr); if (err) goto done; @@ -228,11 +248,13 @@ got_worktree_init(const char *path, struct got_referen goto done; done: + free(commit_id); free(path_got); free(formatstr); free(refstr); free(repo_path); free(absprefix); + free(basestr); return err; } blob - f5e074fbbd708429bf097a89be6a2ad5af0605aa blob + 5157cfdf337a5f2e01c27959ea8dc60b0516eda7 --- regress/worktree/worktree_test.c +++ regress/worktree/worktree_test.c @@ -86,6 +86,8 @@ remove_worktree(const char *worktree_path) { if (!remove_meta_file(worktree_path, GOT_WORKTREE_HEAD)) return 0; + if (!remove_meta_file(worktree_path, GOT_WORKTREE_BASE)) + return 0; if (!remove_meta_file(worktree_path, GOT_WORKTREE_FILE_INDEX)) return 0; if (!remove_meta_file(worktree_path, GOT_WORKTREE_REPOSITORY)) @@ -172,6 +174,8 @@ worktree_init(const char *repo_path) /* Ensure required files were created. */ if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_HEAD)) goto done; + if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_BASE)) + goto done; if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_LOCK)) goto done; if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_FILE_INDEX)) @@ -273,6 +277,9 @@ worktree_init_exists(const char *repo_path) GOT_WORKTREE_HEAD)) goto done; if (!obstruct_meta_file_and_init(&ok, repo, worktree_path, + GOT_WORKTREE_BASE)) + goto done; + if (!obstruct_meta_file_and_init(&ok, repo, worktree_path, GOT_WORKTREE_LOCK)) goto done; if (!obstruct_meta_file_and_init(&ok, repo, worktree_path, @@ -292,9 +299,9 @@ done: if (repo) got_repo_close(repo); free(gotpath); - if (ok == 6) + if (ok == 7) remove_worktree(worktree_path); - return (ok == 6); + return (ok == 7); } static void