store a parsed base commit ID in struct got_worktree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
diff --git a/lib/got_lib_worktree.h b/lib/got_lib_worktree.h
index 6eb1b51..5fa0ba1 100644
--- a/lib/got_lib_worktree.h
+++ b/lib/got_lib_worktree.h
@@ -18,7 +18,7 @@ struct got_worktree {
char *root_path;
char *repo_path;
char *path_prefix;
- char *base;
+ struct got_object_id *base_commit_id;
char *head_ref;
/*
diff --git a/lib/worktree.c b/lib/worktree.c
index 091974e..4656e2e 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -265,8 +265,10 @@ got_worktree_open(struct got_worktree **worktree, const char *path)
char *path_got;
char *formatstr = NULL;
char *path_lock = NULL;
+ char *base_commit_id_str = NULL;
int version, fd = -1;
const char *errstr;
+ struct got_repository *repo = NULL;
*worktree = NULL;
@@ -319,24 +321,37 @@ got_worktree_open(struct got_worktree **worktree, const char *path)
GOT_WORKTREE_REPOSITORY);
if (err)
goto done;
+
err = read_meta_file(&(*worktree)->path_prefix, path_got,
GOT_WORKTREE_PATH_PREFIX);
if (err)
goto done;
- err = read_meta_file(&(*worktree)->base, path_got,
+ err = read_meta_file(&base_commit_id_str, path_got,
GOT_WORKTREE_BASE_COMMIT);
if (err)
goto done;
+ err = got_repo_open(&repo, (*worktree)->repo_path);
+ if (err)
+ goto done;
+
+ err = got_object_resolve_id_str(&(*worktree)->base_commit_id, repo,
+ base_commit_id_str);
+ if (err)
+ goto done;
+
err = read_meta_file(&(*worktree)->head_ref, path_got,
GOT_WORKTREE_HEAD_REF);
if (err)
goto done;
done:
+ if (repo)
+ got_repo_close(repo);
free(path_got);
free(path_lock);
+ free(base_commit_id_str);
if (err) {
if (fd != -1)
close(fd);
@@ -355,7 +370,7 @@ got_worktree_close(struct got_worktree *worktree)
free(worktree->root_path);
free(worktree->repo_path);
free(worktree->path_prefix);
- free(worktree->base);
+ free(worktree->base_commit_id);
free(worktree->head_ref);
if (worktree->lockfd != -1)
close(worktree->lockfd);
@@ -612,7 +627,6 @@ got_worktree_checkout_files(struct got_worktree *worktree,
void *progress_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg)
{
const struct got_error *err = NULL, *unlockerr;
- struct got_object_id *commit_id = NULL;
struct got_commit_object *commit = NULL;
struct got_tree_object *tree = NULL;
char *fileindex_path = NULL, *new_fileindex_path = NULL;
@@ -623,10 +637,6 @@ got_worktree_checkout_files(struct got_worktree *worktree,
if (err)
return err;
- err = got_object_resolve_id_str(&commit_id, repo, worktree->base);
- if (err)
- goto done;
-
fileindex = got_fileindex_alloc();
if (fileindex == NULL) {
err = got_error_from_errno();
@@ -645,7 +655,8 @@ got_worktree_checkout_files(struct got_worktree *worktree,
if (err)
goto done;
- err = got_object_open_as_commit(&commit, repo, commit_id);
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
if (err)
goto done;
@@ -675,7 +686,6 @@ done:
got_object_tree_close(tree);
if (commit)
got_object_commit_close(commit);
- free(commit_id);
if (new_fileindex_path)
unlink(new_fileindex_path);
if (new_index)