commit - 6ced41767b1ce3cd525b304d3adf2197b57bfaf6
commit + 07ed472d9d0779031a6bd3467c3f59d556cae175
blob - a0eaf352d837f1d8fc1afa69082b04e1a970c2fb
blob + 50dd2a7ba08f49bdc3fa18204bfeeb9e27015e89
--- lib/worktree.c
+++ lib/worktree.c
free(*tree_id);
*tree_id = NULL;
}
+ return err;
+}
+
+static const struct got_error *
+checkout_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
+ const char *relpath, struct got_object_id *tree_id, const char *entry_name,
+ 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;
+ struct got_commit_object *commit = NULL;
+ struct got_tree_object *tree = NULL;
+ struct got_fileindex_diff_tree_cb diff_cb;
+ struct diff_cb_arg arg;
+
+ err = ref_base_commit(worktree, repo);
+ if (err)
+ goto done;
+
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
+ if (err)
+ goto done;
+
+ err = got_object_open_as_tree(&tree, repo, tree_id);
+ if (err)
+ goto done;
+
+ if (entry_name &&
+ got_object_tree_find_entry(tree, entry_name) == NULL) {
+ err = got_error(GOT_ERR_NO_TREE_ENTRY);
+ goto done;
+ }
+
+ diff_cb.diff_old_new = diff_old_new;
+ diff_cb.diff_old = diff_old;
+ diff_cb.diff_new = diff_new;
+ arg.fileindex = fileindex;
+ arg.worktree = worktree;
+ arg.repo = repo;
+ arg.progress_cb = progress_cb;
+ arg.progress_arg = progress_arg;
+ arg.cancel_cb = cancel_cb;
+ arg.cancel_arg = cancel_arg;
+ err = got_fileindex_diff_tree(fileindex, tree, relpath,
+ entry_name, repo, &diff_cb, &arg);
+done:
+ if (tree)
+ got_object_tree_close(tree);
+ if (commit)
+ got_object_commit_close(commit);
return err;
}
struct got_tree_object *tree = NULL;
struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
- struct got_fileindex_diff_tree_cb diff_cb;
- struct diff_cb_arg arg;
char *relpath = NULL, *entry_name = NULL;
struct bump_base_commit_id_arg bbc_arg;
int entry_type;
* If the on-disk file index is incomplete we will try to complete it.
*/
err = open_fileindex(&fileindex, &fileindex_path, worktree);
- if (err)
- goto done;
-
- err = ref_base_commit(worktree, repo);
- if (err)
- goto done;
-
- err = got_object_open_as_commit(&commit, repo,
- worktree->base_commit_id);
- if (err)
- goto done;
-
- err = got_object_open_as_tree(&tree, repo, tree_id);
if (err)
goto done;
- if (entry_name &&
- got_object_tree_find_entry(tree, entry_name) == NULL) {
- err = got_error(GOT_ERR_NO_TREE_ENTRY);
- goto done;
- }
-
- diff_cb.diff_old_new = diff_old_new;
- diff_cb.diff_old = diff_old;
- diff_cb.diff_new = diff_new;
- arg.fileindex = fileindex;
- arg.worktree = worktree;
- arg.repo = repo;
- arg.progress_cb = progress_cb;
- arg.progress_arg = progress_arg;
- arg.cancel_cb = cancel_cb;
- arg.cancel_arg = cancel_arg;
- err = got_fileindex_diff_tree(fileindex, tree, relpath,
- entry_name, repo, &diff_cb, &arg);
+ err = checkout_files(worktree, fileindex, relpath, tree_id, entry_name,
+ repo, progress_cb, progress_arg, cancel_cb, cancel_arg);
if (err)
goto sync;