commit - 1251a9e5a52510aea3b03f1228de7404e6f95a3a
commit + 36a387004fc6fb4f302443e39bdffc01d1c1ed47
blob - 1b87fc95dffd00b52b5bb2ed84f14d17871152da
blob + c82e0bfd137ee751f13b1a609bfe0391b7593e5f
--- got/got.c
+++ got/got.c
struct got_object_id *head_commit_id = NULL;
struct got_commit_graph *graph = NULL;
- head_ref = got_worktree_get_head_ref(worktree);
- if (head_ref == NULL)
- return got_error_from_errno();
+ err = got_ref_open(&head_ref, repo,
+ got_worktree_get_head_ref_name(worktree));
+ if (err)
+ return err;
/* TODO: Check the reflog. The head ref may have been rebased. */
err = got_ref_resolve(&head_commit_id, repo, head_ref);
blob - 6986c3a84c17dafdf8fd94122de1c579ffde02e0
blob + 0261d1079837ceb9ddcff0869f8fce0735d7504b
--- include/got_worktree.h
+++ include/got_worktree.h
const char *got_worktree_get_head_ref_name(struct got_worktree *);
/*
- * Get the work tree's HEAD reference.
- * The caller must dispose of it with free(3).
- */
-struct got_reference *got_worktree_get_head_ref(struct got_worktree *);
-
-/*
* Get the current base commit ID of a worktree.
*/
struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
blob - 9bfa860c4d468a811b3903a7fb3b4bbeac96caa9
blob + 222d5b80f24c09ad6693cbb5d9bd53a6e62dac75
--- lib/got_lib_worktree.h
+++ lib/got_lib_worktree.h
char *repo_path;
char *path_prefix;
struct got_object_id *base_commit_id;
- struct got_reference *head_ref;
+ char *head_ref_name;
uuid_t uuid;
/*
blob - a4c605a756322f709713c648db7450a5fb552ae7
blob + 5b2aa32bae271bdfac6e8eaeeb67d203751b2ffb
--- lib/worktree.c
+++ lib/worktree.c
char *uuidstr = NULL;
char *path_lock = NULL;
char *base_commit_id_str = NULL;
- char *head_ref_str = NULL;
int version, fd = -1;
const char *errstr;
struct got_repository *repo = NULL;
if (err)
goto done;
- err = read_meta_file(&head_ref_str, path_got, GOT_WORKTREE_HEAD_REF);
- if (err)
- goto done;
-
- err = got_ref_open(&(*worktree)->head_ref, repo, head_ref_str);
+ err = read_meta_file(&(*worktree)->head_ref_name, path_got,
+ GOT_WORKTREE_HEAD_REF);
done:
if (repo)
got_repo_close(repo);
free(path_got);
free(path_lock);
- free(head_ref_str);
free(base_commit_id_str);
free(uuidstr);
free(formatstr);
free(worktree->repo_path);
free(worktree->path_prefix);
free(worktree->base_commit_id);
- if (worktree->head_ref)
- got_ref_close(worktree->head_ref);
+ free(worktree->head_ref_name);
if (worktree->lockfd != -1)
if (close(worktree->lockfd) != 0)
err = got_error_from_errno();
const char *
got_worktree_get_head_ref_name(struct got_worktree *worktree)
{
- return got_ref_get_name(worktree->head_ref);
+ return worktree->head_ref_name;
}
-struct got_reference *
-got_worktree_get_head_ref(struct got_worktree *worktree)
-{
- return got_ref_dup(worktree->head_ref);
-}
-
struct got_object_id *
got_worktree_get_base_commit_id(struct got_worktree *worktree)
{
struct got_pathlist_entry *pe;
char *relpath = NULL;
const char *head_ref_name = NULL;
+ struct got_reference *head_ref = NULL;
struct got_commit_object *head_commit = NULL;
struct got_object_id *head_commit_id = NULL;
struct got_reference *head_ref2 = NULL;
if (err)
goto done;
- /* XXX should re-read head ref here now that work tree is locked */
- err = got_ref_resolve(&head_commit_id, repo, worktree->head_ref);
+ err = got_ref_open(&head_ref, repo, worktree->head_ref_name);
if (err)
goto done;
+ err = got_ref_resolve(&head_commit_id, repo, head_ref);
+ if (err)
+ goto done;
cc_arg.commitable_paths = &commitable_paths;
cc_arg.worktree = worktree;
goto done;
}
/* Update branch head in repository. */
- err = got_ref_change_ref(worktree->head_ref, *new_commit_id);
+ err = got_ref_change_ref(head_ref, *new_commit_id);
if (err)
goto done;
- err = got_ref_write(worktree->head_ref, repo);
+ err = got_ref_write(head_ref, repo);
if (err)
goto done;
/* XXX race has ended here */
free(relpath);
free(head_commit_id);
free(head_commit_id2);
+ if (head_ref)
+ got_ref_close(head_ref);
if (head_ref2)
got_ref_close(head_ref2);
return err;