commit - 65596e15914f3e70494e33e84a842d7ce360c1e7
commit + 93a3027739b17cdd9bccd7bda53f581b919b87ea
blob - 4f7d23771ac7850de8807514c25be47cc3ceb7fc
blob + fec08d6e7aa2616d656e927be6b0417754d3c805
--- got/got.c
+++ got/got.c
if (error != NULL)
goto done;
- error = got_worktree_checkout_files(worktree, head_ref, repo,
+ error = got_worktree_checkout_files(worktree, repo,
checkout_progress, worktree_path, checkout_cancel, NULL);
if (error != NULL)
goto done;
blob - 806d598ff338396a2c65dc8d684657dde47f4316
blob + 06af45d140806cd9cccbab4aa32668e5689f53cf
--- include/got_worktree.h
+++ include/got_worktree.h
* The first argument is the path to a directory where the work tree
* will be created. The path itself must not yet exist, but the dirname(3)
* of the path must already exist.
- * The reference provided will be used as the new worktree's HEAD.
- * The third argument speficies the work tree's path prefix.
+ * The reference provided will be used to determine the new worktree's
+ * base commit. The third argument speficies the work tree's path prefix.
*/
const struct got_error *got_worktree_init(const char *, struct got_reference *,
const char *, struct got_repository *);
* Attempt to check out files into a work tree from its associated repository
* and path prefix, and update the work tree's file index accordingly.
* File content is obtained from blobs within the work tree's path prefix
- * inside the tree resolved via the provided reference.
+ * inside the tree corresponding to the work tree's base commit.
* The checkout progress callback will be invoked with the provided
* void * argument, and the path of each checked out file.
*/
const struct got_error *got_worktree_checkout_files(struct got_worktree *,
- struct got_reference *, struct got_repository *,
- got_worktree_checkout_cb progress, void *,
+ struct got_repository *, got_worktree_checkout_cb progress, void *,
got_worktree_cancel_cb, void *);
blob - f308aded447a9b1eb4bd3254941d0239b56abd64
blob + 75906a3d0c3bc85aceb9a38f7f965526ec15b9cc
--- lib/got_lib_worktree.h
+++ lib/got_lib_worktree.h
char *root_path;
char *repo_path;
char *path_prefix;
- char *base_commit;
+ char *base;
char *head_ref;
/*
blob - f44df5ba61c7b288ade196d3ade7a0617ebf9b68
blob + 673aed2f7eff4a8513878d5be8013592ce0d75a1
--- lib/worktree.c
+++ lib/worktree.c
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, GOT_WORKTREE_BASE);
if (err)
goto done;
free(worktree->root_path);
free(worktree->repo_path);
free(worktree->path_prefix);
- free(worktree->base_commit);
+ free(worktree->base);
free(worktree->head_ref);
if (worktree->lockfd != -1)
close(worktree->lockfd);
const struct got_error *
got_worktree_checkout_files(struct got_worktree *worktree,
- struct got_reference *head_ref, struct got_repository *repo,
- got_worktree_checkout_cb progress_cb, void *progress_arg,
- got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+ struct got_repository *repo, got_worktree_checkout_cb progress_cb,
+ 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_object *obj = NULL;
struct got_commit_object *commit = NULL;
struct got_tree_object *tree = NULL;
char *fileindex_path = NULL, *new_fileindex_path = NULL;
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();
if (err)
goto done;
- err = got_ref_resolve(&commit_id, repo, head_ref);
- if (err)
- goto done;
-
- err = got_object_open(&obj, repo, commit_id);
- if (err)
- goto done;
-
- if (obj->type != GOT_OBJ_TYPE_COMMIT) {
- err = got_error(GOT_ERR_OBJ_TYPE);
- goto done;
- }
-
- err = got_object_commit_open(&commit, repo, obj);
+ err = got_object_open_as_commit(&commit, repo, commit_id);
if (err)
goto done;
- got_object_close(obj);
- err = got_object_open(&obj, repo, commit->tree_id);
+ err = got_object_open_as_tree(&tree, repo, commit->tree_id);
if (err)
goto done;
- if (obj->type != GOT_OBJ_TYPE_TREE) {
- err = got_error(GOT_ERR_OBJ_TYPE);
- goto done;
- }
-
- err = got_object_tree_open(&tree, repo, obj);
- if (err)
- goto done;
-
err = tree_checkout(worktree, fileindex, tree, "/", repo,
progress_cb, progress_arg, cancel_cb, cancel_arg);
if (err)
got_object_tree_close(tree);
if (commit)
got_object_commit_close(commit);
- if (obj)
- got_object_close(obj);
free(commit_id);
if (new_fileindex_path)
unlink(new_fileindex_path);
blob - 5157cfdf337a5f2e01c27959ea8dc60b0516eda7
blob + 476ab3d1513ea3b719e817918075368ae0df1b1a
--- regress/worktree/worktree_test.c
+++ regress/worktree/worktree_test.c
if (err != NULL)
goto done;
- err = got_worktree_checkout_files(worktree, head_ref, repo,
- process_cb, NULL, NULL, NULL);
+ err = got_worktree_checkout_files(worktree, repo, process_cb, NULL,
+ NULL, NULL);
if (err != NULL)
goto done;