commit - b2c50a0a51e3a8e22fb1e9867cbf6bc7356acbd3
commit + 3e3a69f1a29c6322b5464dca5023d8766661d7bf
blob - d826f0a1b82911906aa324cfb67c46858b054fdc
blob + f267e721b6b581f74d68a80a860a0b837ada803a
--- got/got.c
+++ got/got.c
}
static const struct got_error *
-rebase_complete(struct got_worktree *worktree, struct got_reference *branch,
- struct got_reference *new_base_branch, struct got_reference *tmp_branch,
- struct got_repository *repo)
+rebase_complete(struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_reference *branch, struct got_reference *new_base_branch,
+ struct got_reference *tmp_branch, struct got_repository *repo)
{
printf("Switching work tree to %s\n", got_ref_get_name(branch));
- return got_worktree_rebase_complete(worktree,
+ return got_worktree_rebase_complete(worktree, fileindex,
new_base_branch, tmp_branch, branch, repo);
}
static const struct got_error *
rebase_commit(struct got_pathlist_head *merged_paths,
- struct got_worktree *worktree, struct got_reference *tmp_branch,
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_reference *tmp_branch,
struct got_object_id *commit_id, struct got_repository *repo)
{
const struct got_error *error;
return error;
error = got_worktree_rebase_commit(&new_commit_id, merged_paths,
- worktree, tmp_branch, commit, commit_id, repo);
+ worktree, fileindex, tmp_branch, commit, commit_id, repo);
if (error) {
if (error->code != GOT_ERR_COMMIT_NO_CHANGES)
goto done;
const struct got_error *error = NULL;
struct got_worktree *worktree = NULL;
struct got_repository *repo = NULL;
+ struct got_fileindex *fileindex = NULL;
char *cwd = NULL;
struct got_reference *branch = NULL;
struct got_reference *new_base_branch = NULL, *tmp_branch = NULL;
goto done;
}
error = got_worktree_rebase_continue(&resume_commit_id,
- &new_base_branch, &tmp_branch, &branch, worktree, repo);
+ &new_base_branch, &tmp_branch, &branch, &fileindex,
+ worktree, repo);
if (error)
goto done;
printf("Switching work tree to %s\n",
got_ref_get_symref_target(new_base_branch));
- error = got_worktree_rebase_abort(worktree, repo,
+ error = got_worktree_rebase_abort(worktree, fileindex, repo,
new_base_branch, update_progress, &did_something);
if (error)
goto done;
goto done;
}
error = got_worktree_rebase_continue(&resume_commit_id,
- &new_base_branch, &tmp_branch, &branch, worktree, repo);
+ &new_base_branch, &tmp_branch, &branch, &fileindex,
+ worktree, repo);
if (error)
goto done;
- error = rebase_commit(NULL, worktree, tmp_branch,
+ error = rebase_commit(NULL, worktree, fileindex, tmp_branch,
resume_commit_id, repo);
if (error)
goto done;
}
error = got_worktree_rebase_prepare(&new_base_branch,
- &tmp_branch, worktree, branch, repo);
+ &tmp_branch, &fileindex, worktree, branch, repo);
if (error)
goto done;
}
if (SIMPLEQ_EMPTY(&commits)) {
if (continue_rebase)
- error = rebase_complete(worktree, branch,
- new_base_branch, tmp_branch, repo);
+ error = rebase_complete(worktree, fileindex,
+ branch, new_base_branch, tmp_branch, repo);
else
error = got_error(GOT_ERR_EMPTY_REBASE);
goto done;
pid = qid;
error = got_worktree_rebase_merge_files(&merged_paths,
- worktree, parent_id, commit_id, repo, rebase_progress,
- &rebase_status, check_cancelled, NULL);
+ worktree, fileindex, parent_id, commit_id, repo,
+ rebase_progress, &rebase_status, check_cancelled, NULL);
if (error)
goto done;
break;
}
- error = rebase_commit(&merged_paths, worktree, tmp_branch,
- commit_id, repo);
+ error = rebase_commit(&merged_paths, worktree, fileindex,
+ tmp_branch, commit_id, repo);
got_worktree_rebase_pathlist_free(&merged_paths);
if (error)
goto done;
}
if (rebase_status == GOT_STATUS_CONFLICT) {
- error = got_worktree_rebase_postpone(worktree);
+ error = got_worktree_rebase_postpone(worktree, fileindex);
if (error)
goto done;
error = got_error_msg(GOT_ERR_CONFLICTS,
"conflicts must be resolved before rebasing can continue");
} else
- error = rebase_complete(worktree, branch, new_base_branch,
- tmp_branch, repo);
+ error = rebase_complete(worktree, fileindex, branch,
+ new_base_branch, tmp_branch, repo);
done:
got_object_id_queue_free(&commits);
free(branch_head_commit_id);
static const struct got_error *
histedit_complete(struct got_worktree *worktree,
- struct got_reference *tmp_branch, struct got_reference *branch,
- struct got_repository *repo)
+ struct got_fileindex *fileindex, struct got_reference *tmp_branch,
+ struct got_reference *branch, struct got_repository *repo)
{
printf("Switching work tree to %s\n",
got_ref_get_symref_target(branch));
- return got_worktree_histedit_complete(worktree, tmp_branch, branch,
- repo);
+ return got_worktree_histedit_complete(worktree, fileindex, tmp_branch,
+ branch, repo);
}
static const struct got_error *
static const struct got_error *
histedit_commit(struct got_pathlist_head *merged_paths,
- struct got_worktree *worktree, struct got_reference *tmp_branch,
- struct got_histedit_list_entry *hle, struct got_repository *repo)
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_reference *tmp_branch, struct got_histedit_list_entry *hle,
+ struct got_repository *repo)
{
const struct got_error *err;
struct got_commit_object *commit;
return err;
err = got_worktree_histedit_commit(&new_commit_id, merged_paths,
- worktree, tmp_branch, commit, hle->commit_id, hle->logmsg, repo);
+ worktree, fileindex, tmp_branch, commit, hle->commit_id,
+ hle->logmsg, repo);
if (err) {
if (err->code != GOT_ERR_COMMIT_NO_CHANGES)
goto done;
{
const struct got_error *error = NULL;
struct got_worktree *worktree = NULL;
+ struct got_fileindex *fileindex = NULL;
struct got_repository *repo = NULL;
char *cwd = NULL;
struct got_reference *branch = NULL;
if (edit_in_progress && abort_edit) {
int did_something;
error = got_worktree_histedit_continue(&resume_commit_id,
- &tmp_branch, &branch, &base_commit_id, worktree, repo);
+ &tmp_branch, &branch, &base_commit_id, &fileindex,
+ worktree, repo);
if (error)
goto done;
printf("Switching work tree to %s\n",
got_ref_get_symref_target(branch));
- error = got_worktree_histedit_abort(worktree, repo,
+ error = got_worktree_histedit_abort(worktree, fileindex, repo,
branch, base_commit_id, update_progress, &did_something);
if (error)
goto done;
goto done;
error = got_worktree_histedit_continue(&resume_commit_id,
- &tmp_branch, &branch, &base_commit_id, worktree, repo);
+ &tmp_branch, &branch, &base_commit_id, &fileindex,
+ worktree, repo);
if (error)
goto done;
goto done;
error = got_worktree_histedit_prepare(&tmp_branch, &branch,
- &base_commit_id, worktree, repo);
+ &base_commit_id, &fileindex, worktree, repo);
if (error)
goto done;
repo);
} else {
error = histedit_commit(NULL, worktree,
- tmp_branch, hle, repo);
+ fileindex, tmp_branch, hle, repo);
}
if (error)
goto done;
pid = SIMPLEQ_FIRST(parent_ids);
error = got_worktree_histedit_merge_files(&merged_paths,
- worktree, pid->id, hle->commit_id, repo, rebase_progress,
- &rebase_status, check_cancelled, NULL);
+ worktree, fileindex, pid->id, hle->commit_id, repo,
+ rebase_progress, &rebase_status, check_cancelled, NULL);
if (error)
goto done;
got_object_commit_close(commit);
id_str);
free(id_str);
got_worktree_rebase_pathlist_free(&merged_paths);
- error = got_worktree_histedit_postpone(worktree);
+ error = got_worktree_histedit_postpone(worktree,
+ fileindex);
goto done;
}
continue;
}
- error = histedit_commit(&merged_paths, worktree, tmp_branch,
- hle, repo);
+ error = histedit_commit(&merged_paths, worktree, fileindex,
+ tmp_branch, hle, repo);
got_worktree_rebase_pathlist_free(&merged_paths);
if (error)
goto done;
}
if (rebase_status == GOT_STATUS_CONFLICT) {
- error = got_worktree_histedit_postpone(worktree);
+ error = got_worktree_histedit_postpone(worktree, fileindex);
if (error)
goto done;
error = got_error_msg(GOT_ERR_CONFLICTS,
"conflicts must be resolved before rebasing can continue");
} else
- error = histedit_complete(worktree, tmp_branch, branch, repo);
+ error = histedit_complete(worktree, fileindex, tmp_branch,
+ branch, repo);
done:
got_object_id_queue_free(&commits);
free(head_commit_id);
blob - 6e6d2f53d8d2d5dd4b9b32075806433ee2a4cb49
blob + e9f5a6c90d4b5185ce58d45c93a4c57a850306a3
--- include/got_worktree.h
+++ include/got_worktree.h
struct got_worktree;
struct got_commitable;
struct got_commit_object;
+struct got_fileindex;
/* status codes */
#define GOT_STATUS_NO_CHANGE ' '
* "got/worktree/rebase/" namespace. These references are used to
* keep track of rebase operation state and are used as input and/or
* output arguments with other rebase-related functions.
+ * The function also returns a pointer to a fileindex which must be
+ * passed back to other rebase-related functions.
*/
const struct got_error *got_worktree_rebase_prepare(struct got_reference **,
- struct got_reference **, struct got_worktree *, struct got_reference *,
- struct got_repository *);
+ struct got_reference **, struct got_fileindex **, struct got_worktree *,
+ struct got_reference *, struct got_repository *);
/*
* Continue an interrupted rebase operation.
* This function returns existing references created when rebase was prepared,
* and the ID of the commit currently being rebased. This should be called
* before either resuming or aborting a rebase operation.
+ * The function also returns a pointer to a fileindex which must be
+ * passed back to other rebase-related functions.
*/
const struct got_error *got_worktree_rebase_continue(struct got_object_id **,
struct got_reference **, struct got_reference **, struct got_reference **,
- struct got_worktree *, struct got_repository *);
+ struct got_fileindex **, struct got_worktree *, struct got_repository *);
/* Check whether a, potentially interrupted, rebase operation is in progress. */
const struct got_error *got_worktree_rebase_in_progress(int *,
* got_worktree_rebase_pathlist_free().
*/
const struct got_error *got_worktree_rebase_merge_files(
- struct got_pathlist_head *, struct got_worktree *,
+ struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
struct got_object_id *, struct got_object_id *, struct got_repository *,
got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
* crawl across the entire work tree to find paths to commit.
*/
const struct got_error *got_worktree_rebase_commit(struct got_object_id **,
- struct got_pathlist_head *, struct got_worktree *,
+ struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
struct got_reference *, struct got_commit_object *,
struct got_object_id *, struct got_repository *);
void got_worktree_rebase_pathlist_free(struct got_pathlist_head *);
/* Postpone the rebase operation. Should be called after a merge conflict. */
-const struct got_error *got_worktree_rebase_postpone(struct got_worktree *);
+const struct got_error *got_worktree_rebase_postpone(struct got_worktree *,
+ struct got_fileindex *);
/*
* Complete the current rebase operation. This should be called once all
* commits have been rebased successfully.
*/
const struct got_error *got_worktree_rebase_complete(struct got_worktree *,
- struct got_reference *, struct got_reference *, struct got_reference *,
- struct got_repository *);
+ struct got_fileindex *, struct got_reference *, struct got_reference *,
+ struct got_reference *, struct got_repository *);
/*
* Abort the current rebase operation.
* Report reverted files via the specified progress callback.
*/
const struct got_error *got_worktree_rebase_abort(struct got_worktree *,
- struct got_repository *, struct got_reference *,
+ struct got_fileindex *, struct got_repository *, struct got_reference *,
got_worktree_checkout_cb, void *);
/*
* functions.
*/
const struct got_error *got_worktree_histedit_prepare(struct got_reference **,
- struct got_reference **, struct got_object_id **, struct got_worktree *,
- struct got_repository *);
+ struct got_reference **, struct got_object_id **, struct got_fileindex **,
+ struct got_worktree *, struct got_repository *);
/*
* Continue an interrupted histedit operation.
*/
const struct got_error *got_worktree_histedit_continue(struct got_object_id **,
struct got_reference **, struct got_reference **, struct got_object_id **,
- struct got_worktree *, struct got_repository *);
+ struct got_fileindex **, struct got_worktree *, struct got_repository *);
/* Check whether a histedit operation is in progress. */
const struct got_error *got_worktree_histedit_in_progress(int *,
* got_worktree_rebase_pathlist_free().
*/
const struct got_error *got_worktree_histedit_merge_files(
- struct got_pathlist_head *, struct got_worktree *,
+ struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
struct got_object_id *, struct got_object_id *, struct got_repository *,
got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
* commit's original message.
*/
const struct got_error *got_worktree_histedit_commit(struct got_object_id **,
- struct got_pathlist_head *, struct got_worktree *,
+ struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
struct got_reference *, struct got_commit_object *,
struct got_object_id *, const char *, struct got_repository *);
struct got_object_id *, struct got_repository *);
/* Postpone the histedit operation. */
-const struct got_error *got_worktree_histedit_postpone(struct got_worktree *);
+const struct got_error *got_worktree_histedit_postpone(struct got_worktree *,
+ struct got_fileindex *);
/*
* Complete the current histedit operation. This should be called once all
* commits have been edited successfully.
*/
const struct got_error *got_worktree_histedit_complete(struct got_worktree *,
- struct got_reference *, struct got_reference *, struct got_repository *);
+ struct got_fileindex *, struct got_reference *, struct got_reference *,
+ struct got_repository *);
/*
* Abort the current histedit operation.
* Report reverted files via the specified progress callback.
*/
const struct got_error *got_worktree_histedit_abort(struct got_worktree *,
- struct got_repository *, struct got_reference *, struct got_object_id *,
- got_worktree_checkout_cb, void *);
+ struct got_fileindex *, struct got_repository *, struct got_reference *,
+ struct got_object_id *, got_worktree_checkout_cb, void *);
/* Get the path to this work tree's histedit command list file. */
const struct got_error *got_worktree_get_histedit_list_path(char **,
blob - e97e4a41f6e33058d7fa59cafff72d23268115a3
blob + a4aa679e50c2f3cd51a8cea50b51003ea9aecc08
--- lib/worktree.c
+++ lib/worktree.c
free(refname);
if (ref)
got_ref_close(ref);
+ return err;
+}
+
+static const struct got_error *
+get_fileindex_path(char **fileindex_path, struct got_worktree *worktree)
+{
+ const struct got_error *err = NULL;
+
+ if (asprintf(fileindex_path, "%s/%s/%s", worktree->root_path,
+ GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
+ err = got_error_from_errno("asprintf");
+ *fileindex_path = NULL;
+ }
return err;
}
+
static const struct got_error *
open_fileindex(struct got_fileindex **fileindex, char **fileindex_path,
struct got_worktree *worktree)
if (*fileindex == NULL)
return got_error_from_errno("got_fileindex_alloc");
- if (asprintf(fileindex_path, "%s/%s/%s", worktree->root_path,
- GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
- err = got_error_from_errno("asprintf");
- *fileindex_path = NULL;
+ err = get_fileindex_path(fileindex_path, worktree);
+ if (err)
goto done;
- }
index = fopen(*fileindex_path, "rb");
if (index == NULL) {
const struct got_error *
got_worktree_rebase_prepare(struct got_reference **new_base_branch_ref,
- struct got_reference **tmp_branch, struct got_worktree *worktree,
- struct got_reference *branch, struct got_repository *repo)
+ struct got_reference **tmp_branch, struct got_fileindex **fileindex,
+ struct got_worktree *worktree, struct got_reference *branch,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
char *tmp_branch_name = NULL, *new_base_branch_ref_name = NULL;
char *branch_ref_name = NULL;
- struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
struct check_rebase_ok_arg ok_arg;
struct got_reference *wt_branch = NULL, *branch_ref = NULL;
*new_base_branch_ref = NULL;
*tmp_branch = NULL;
+ *fileindex = NULL;
err = lock_worktree(worktree, LOCK_EX);
if (err)
return err;
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = open_fileindex(fileindex, &fileindex_path, worktree);
if (err)
goto done;
ok_arg.worktree = worktree;
ok_arg.repo = repo;
ok_arg.rebase_in_progress = 0;
- err = got_fileindex_for_each_entry_safe(fileindex, check_rebase_ok,
+ err = got_fileindex_for_each_entry_safe(*fileindex, check_rebase_ok,
&ok_arg);
if (err)
goto done;
goto done;
done:
free(fileindex_path);
- if (fileindex)
- got_fileindex_free(fileindex);
free(tmp_branch_name);
free(new_base_branch_ref_name);
free(branch_ref_name);
got_ref_close(*tmp_branch);
*tmp_branch = NULL;
}
+ if (*fileindex) {
+ got_fileindex_free(*fileindex);
+ *fileindex = NULL;
+ }
lock_worktree(worktree, LOCK_SH);
}
return err;
const struct got_error *
got_worktree_rebase_continue(struct got_object_id **commit_id,
struct got_reference **new_base_branch, struct got_reference **tmp_branch,
- struct got_reference **branch, struct got_worktree *worktree,
- struct got_repository *repo)
+ struct got_reference **branch, struct got_fileindex **fileindex,
+ struct got_worktree *worktree, struct got_repository *repo)
{
const struct got_error *err;
char *commit_ref_name = NULL, *new_base_branch_ref_name = NULL;
char *tmp_branch_name = NULL, *branch_ref_name = NULL;
struct got_reference *commit_ref = NULL, *branch_ref = NULL;
+ char *fileindex_path = NULL;
*commit_id = NULL;
+ *new_base_branch = NULL;
+ *tmp_branch = NULL;
+ *branch = NULL;
+ *fileindex = NULL;
+
+ err = lock_worktree(worktree, LOCK_EX);
+ if (err)
+ return err;
+ err = open_fileindex(fileindex, &fileindex_path, worktree);
+ if (err)
+ goto done;
+
err = get_rebase_tmp_ref_name(&tmp_branch_name, worktree);
if (err)
return err;
done:
free(commit_ref_name);
free(branch_ref_name);
+ free(fileindex_path);
if (commit_ref)
got_ref_close(commit_ref);
if (branch_ref)
got_ref_close(*branch);
*branch = NULL;
}
+ if (*fileindex) {
+ got_fileindex_free(*fileindex);
+ *fileindex = NULL;
+ }
+ lock_worktree(worktree, LOCK_SH);
}
return err;
}
static const struct got_error *
rebase_merge_files(struct got_pathlist_head *merged_paths,
const char *commit_ref_name, struct got_worktree *worktree,
- struct got_object_id *parent_commit_id, struct got_object_id *commit_id,
- struct got_repository *repo, got_worktree_checkout_cb progress_cb,
- void *progress_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg)
+ struct got_fileindex *fileindex, struct got_object_id *parent_commit_id,
+ struct got_object_id *commit_id, 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;
- struct got_fileindex *fileindex;
- char *fileindex_path;
struct got_reference *commit_ref = NULL;
struct collect_merged_paths_arg cmp_arg;
+ char *fileindex_path;
/* Work tree is locked/unlocked during rebase preparation/teardown. */
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = get_fileindex_path(&fileindex_path, worktree);
if (err)
return err;
err = merge_files(worktree, fileindex, fileindex_path,
parent_commit_id, commit_id, repo, collect_merged_paths,
&cmp_arg, cancel_cb, cancel_arg);
- got_fileindex_free(fileindex);
- free(fileindex_path);
if (commit_ref)
got_ref_close(commit_ref);
return err;
const struct got_error *
got_worktree_rebase_merge_files(struct got_pathlist_head *merged_paths,
- struct got_worktree *worktree, struct got_object_id *parent_commit_id,
- struct got_object_id *commit_id, struct got_repository *repo,
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_object_id *parent_commit_id, struct got_object_id *commit_id,
+ struct got_repository *repo,
got_worktree_checkout_cb progress_cb, void *progress_arg,
got_worktree_cancel_cb cancel_cb, void *cancel_arg)
{
goto done;
err = rebase_merge_files(merged_paths, commit_ref_name, worktree,
- parent_commit_id, commit_id, repo, progress_cb, progress_arg,
- cancel_cb, cancel_arg);
+ fileindex, parent_commit_id, commit_id, repo, progress_cb,
+ progress_arg, cancel_cb, cancel_arg);
done:
free(commit_ref_name);
return err;
const struct got_error *
got_worktree_histedit_merge_files(struct got_pathlist_head *merged_paths,
- struct got_worktree *worktree, struct got_object_id *parent_commit_id,
- struct got_object_id *commit_id, struct got_repository *repo,
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_object_id *parent_commit_id, struct got_object_id *commit_id,
+ struct got_repository *repo,
got_worktree_checkout_cb progress_cb, void *progress_arg,
got_worktree_cancel_cb cancel_cb, void *cancel_arg)
{
goto done;
err = rebase_merge_files(merged_paths, commit_ref_name, worktree,
- parent_commit_id, commit_id, repo, progress_cb, progress_arg,
- cancel_cb, cancel_arg);
+ fileindex, parent_commit_id, commit_id, repo, progress_cb,
+ progress_arg, cancel_cb, cancel_arg);
done:
free(commit_ref_name);
return err;
static const struct got_error *
rebase_commit(struct got_object_id **new_commit_id,
struct got_pathlist_head *merged_paths, struct got_reference *commit_ref,
- struct got_worktree *worktree, struct got_reference *tmp_branch,
- struct got_commit_object *orig_commit, const char *new_logmsg,
- struct got_repository *repo)
+ struct got_worktree *worktree, struct got_fileindex *fileindex,
+ struct got_reference *tmp_branch, struct got_commit_object *orig_commit,
+ const char *new_logmsg, struct got_repository *repo)
{
const struct got_error *err, *sync_err;
struct got_pathlist_head commitable_paths;
struct collect_commitables_arg cc_arg;
- struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
struct got_reference *head_ref = NULL;
struct got_object_id *head_commit_id = NULL;
/* Work tree is locked/unlocked during rebase preparation/teardown. */
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = get_fileindex_path(&fileindex_path, worktree);
if (err)
- goto done;
+ return err;
cc_arg.commitable_paths = &commitable_paths;
cc_arg.worktree = worktree;
if (sync_err && err == NULL)
err = sync_err;
done:
- if (fileindex)
- got_fileindex_free(fileindex);
free(fileindex_path);
free(head_commit_id);
if (head_ref)
const struct got_error *
got_worktree_rebase_commit(struct got_object_id **new_commit_id,
struct got_pathlist_head *merged_paths, struct got_worktree *worktree,
- struct got_reference *tmp_branch, struct got_commit_object *orig_commit,
+ struct got_fileindex *fileindex, struct got_reference *tmp_branch,
+ struct got_commit_object *orig_commit,
struct got_object_id *orig_commit_id, struct got_repository *repo)
{
const struct got_error *err;
}
err = rebase_commit(new_commit_id, merged_paths, commit_ref,
- worktree, tmp_branch, orig_commit, NULL, repo);
+ worktree, fileindex, tmp_branch, orig_commit, NULL, repo);
done:
if (commit_ref)
got_ref_close(commit_ref);
const struct got_error *
got_worktree_histedit_commit(struct got_object_id **new_commit_id,
struct got_pathlist_head *merged_paths, struct got_worktree *worktree,
- struct got_reference *tmp_branch, struct got_commit_object *orig_commit,
+ struct got_fileindex *fileindex, struct got_reference *tmp_branch,
+ struct got_commit_object *orig_commit,
struct got_object_id *orig_commit_id, const char *new_logmsg,
struct got_repository *repo)
{
}
err = rebase_commit(new_commit_id, merged_paths, commit_ref,
- worktree, tmp_branch, orig_commit, new_logmsg, repo);
+ worktree, fileindex, tmp_branch, orig_commit, new_logmsg, repo);
done:
if (commit_ref)
got_ref_close(commit_ref);
}
const struct got_error *
-got_worktree_rebase_postpone(struct got_worktree *worktree)
+got_worktree_rebase_postpone(struct got_worktree *worktree,
+ struct got_fileindex *fileindex)
{
+ if (fileindex)
+ got_fileindex_free(fileindex);
return lock_worktree(worktree, LOCK_SH);
}
const struct got_error *
got_worktree_rebase_complete(struct got_worktree *worktree,
- struct got_reference *new_base_branch, struct got_reference *tmp_branch,
- struct got_reference *rebased_branch,
+ struct got_fileindex *fileindex, struct got_reference *new_base_branch,
+ struct got_reference *tmp_branch, struct got_reference *rebased_branch,
struct got_repository *repo)
{
const struct got_error *err, *unlockerr;
err = delete_rebase_refs(worktree, repo);
done:
+ if (fileindex)
+ got_fileindex_free(fileindex);
free(new_head_commit_id);
unlockerr = lock_worktree(worktree, LOCK_SH);
if (unlockerr && err == NULL)
const struct got_error *
got_worktree_rebase_abort(struct got_worktree *worktree,
- struct got_repository *repo, struct got_reference *new_base_branch,
+ struct got_fileindex *fileindex, struct got_repository *repo,
+ struct got_reference *new_base_branch,
got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err, *unlockerr, *sync_err;
struct got_reference *resolved = NULL;
struct got_object_id *commit_id = NULL;
- struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
struct got_pathlist_head revertible_paths;
struct got_pathlist_entry *pe;
if (err)
goto done;
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = get_fileindex_path(&fileindex_path, worktree);
if (err)
goto done;
const struct got_error *
got_worktree_histedit_prepare(struct got_reference **tmp_branch,
struct got_reference **branch_ref, struct got_object_id **base_commit_id,
- struct got_worktree *worktree, struct got_repository *repo)
+ struct got_fileindex **fileindex, struct got_worktree *worktree,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
char *tmp_branch_name = NULL;
char *branch_ref_name = NULL;
char *base_commit_ref_name = NULL;
- struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
struct check_rebase_ok_arg ok_arg;
struct got_reference *wt_branch = NULL;
*tmp_branch = NULL;
*branch_ref = NULL;
*base_commit_id = NULL;
+ *fileindex = NULL;
err = lock_worktree(worktree, LOCK_EX);
if (err)
return err;
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = open_fileindex(fileindex, &fileindex_path, worktree);
if (err)
goto done;
ok_arg.worktree = worktree;
ok_arg.repo = repo;
ok_arg.rebase_in_progress = 0;
- err = got_fileindex_for_each_entry_safe(fileindex, check_rebase_ok,
+ err = got_fileindex_for_each_entry_safe(*fileindex, check_rebase_ok,
&ok_arg);
if (err)
goto done;
goto done;
done:
free(fileindex_path);
- if (fileindex)
- got_fileindex_free(fileindex);
free(tmp_branch_name);
free(branch_ref_name);
free(base_commit_ref_name);
*tmp_branch = NULL;
}
free(*base_commit_id);
+ if (*fileindex) {
+ got_fileindex_free(*fileindex);
+ *fileindex = NULL;
+ }
lock_worktree(worktree, LOCK_SH);
}
return err;
}
const struct got_error *
-got_worktree_histedit_postpone(struct got_worktree *worktree)
+got_worktree_histedit_postpone(struct got_worktree *worktree,
+ struct got_fileindex *fileindex)
{
+ if (fileindex)
+ got_fileindex_free(fileindex);
return lock_worktree(worktree, LOCK_SH);
}
const struct got_error *
got_worktree_histedit_continue(struct got_object_id **commit_id,
struct got_reference **tmp_branch, struct got_reference **branch_ref,
- struct got_object_id **base_commit_id,
+ struct got_object_id **base_commit_id, struct got_fileindex **fileindex,
struct got_worktree *worktree, struct got_repository *repo)
{
const struct got_error *err;
char *tmp_branch_name = NULL, *branch_ref_name = NULL;
struct got_reference *commit_ref = NULL;
struct got_reference *base_commit_ref = NULL;
+ char *fileindex_path = NULL;
*commit_id = NULL;
*tmp_branch = NULL;
*base_commit_id = NULL;
+ *fileindex = NULL;
+ err = lock_worktree(worktree, LOCK_EX);
+ if (err)
+ return err;
+
+ err = open_fileindex(fileindex, &fileindex_path, worktree);
+ if (err)
+ goto done;
+
err = get_histedit_tmp_ref_name(&tmp_branch_name, worktree);
if (err)
return err;
done:
free(commit_ref_name);
free(branch_ref_name);
+ free(fileindex_path);
if (commit_ref)
got_ref_close(commit_ref);
if (base_commit_ref)
got_ref_close(*tmp_branch);
*tmp_branch = NULL;
}
+ if (*fileindex) {
+ got_fileindex_free(*fileindex);
+ *fileindex = NULL;
+ }
+ lock_worktree(worktree, LOCK_EX);
}
return err;
}
const struct got_error *
got_worktree_histedit_abort(struct got_worktree *worktree,
- struct got_repository *repo, struct got_reference *branch,
- struct got_object_id *base_commit_id,
+ struct got_fileindex *fileindex, struct got_repository *repo,
+ struct got_reference *branch, struct got_object_id *base_commit_id,
got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err, *unlockerr, *sync_err;
struct got_reference *resolved = NULL;
- struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
struct got_pathlist_head revertible_paths;
struct got_pathlist_entry *pe;
if (err)
goto done;
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ err = get_fileindex_path(&fileindex_path, worktree);
if (err)
goto done;
done:
got_ref_close(resolved);
free(tree_id);
- if (fileindex)
- got_fileindex_free(fileindex);
free(fileindex_path);
TAILQ_FOREACH(pe, &revertible_paths, entry)
free((char *)pe->path);
const struct got_error *
got_worktree_histedit_complete(struct got_worktree *worktree,
- struct got_reference *tmp_branch, struct got_reference *edited_branch,
- struct got_repository *repo)
+ struct got_fileindex *fileindex, struct got_reference *tmp_branch,
+ struct got_reference *edited_branch, struct got_repository *repo)
{
const struct got_error *err, *unlockerr;
struct got_object_id *new_head_commit_id = NULL;
err = delete_histedit_refs(worktree, repo);
done:
+ if (fileindex)
+ got_fileindex_free(fileindex);
free(new_head_commit_id);
unlockerr = lock_worktree(worktree, LOCK_SH);
if (unlockerr && err == NULL)