use the new commit_worktree() helper function during rebase
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
diff --git a/lib/worktree.c b/lib/worktree.c
index fd6955d..01e747a 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3782,53 +3782,30 @@ done:
return err;
}
-static const struct got_error *
-bump_all_base_commit_ids(struct got_worktree *worktree,
- struct got_object_id *base_commit_id)
-{
- const struct got_error *err = NULL, *sync_err;
- struct got_fileindex *fileindex;
- char *fileindex_path;
- struct bump_base_commit_id_arg bbc_arg;
-
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
- if (err)
- return err;
-
- bbc_arg.base_commit_id = base_commit_id;
- bbc_arg.entry_name = NULL;
- bbc_arg.path = "";
- bbc_arg.path_len = 0;
- bbc_arg.progress_cb = NULL;
- bbc_arg.progress_arg = NULL;
- err = got_fileindex_for_each_entry_safe(fileindex,
- bump_base_commit_id, &bbc_arg);
-
- sync_err = sync_fileindex(fileindex, fileindex_path);
- if (sync_err && err == NULL)
- err = sync_err;
-
- got_fileindex_free(fileindex);
- free(fileindex_path);
- return err;
-}
-
const struct got_error *
got_worktree_rebase_commit(struct got_object_id **new_commit_id,
struct got_worktree *worktree, 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;
- char *commit_ref_name = NULL;
+ const struct got_error *err, *sync_err;
+ struct got_pathlist_head commitable_paths;
+ struct collect_commitables_arg cc_arg;
+ struct bump_base_commit_id_arg bbc_arg;
+ struct got_fileindex *fileindex = NULL;
+ char *fileindex_path = NULL, *commit_ref_name = NULL;
+ struct got_reference *head_ref = NULL;
+ struct got_object_id *head_commit_id = NULL;
struct got_reference *commit_ref = NULL;
struct got_object_id *commit_id = NULL;
+ TAILQ_INIT(&commitable_paths);
+
/* Work tree is locked/unlocked during rebase prepartion/teardown. */
err = get_rebase_commit_ref_name(&commit_ref_name, worktree);
if (err)
- goto done;
+ return err;
err = got_ref_open(&commit_ref, repo, commit_ref_name, 0);
if (err)
goto done;
@@ -3840,24 +3817,44 @@ got_worktree_rebase_commit(struct got_object_id **new_commit_id,
goto done;
}
- err = got_worktree_commit(new_commit_id, worktree, NULL,
- got_object_commit_get_author(orig_commit),
+ err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ if (err)
+ goto done;
+
+ cc_arg.commitable_paths = &commitable_paths;
+ cc_arg.worktree = worktree;
+ cc_arg.repo = repo;
+ err = worktree_status(worktree, "", fileindex, repo,
+ collect_commitables, &cc_arg, NULL, NULL);
+ if (err)
+ goto done;
+
+ if (TAILQ_EMPTY(&commitable_paths)) {
+ /* No-op change; commit will be elided. */
+ err = got_ref_delete(commit_ref, repo);
+ if (err)
+ goto done;
+ err = got_error(GOT_ERR_COMMIT_NO_CHANGES);
+ goto done;
+ }
+
+ err = got_ref_open(&head_ref, repo, worktree->head_ref_name, 0);
+ if (err)
+ goto done;
+
+ err = got_ref_resolve(&head_commit_id, repo, head_ref);
+ if (err)
+ goto done;
+
+ err = commit_worktree(new_commit_id, &commitable_paths, head_commit_id,
+ worktree, NULL, got_object_commit_get_author(orig_commit),
got_object_commit_get_committer(orig_commit),
collect_rebase_commit_msg, orig_commit,
rebase_status, NULL, repo);
- if (err) {
- if (err->code == GOT_ERR_COMMIT_NO_CHANGES) {
- /* No-op change; commit will be elided. */
- err = got_ref_delete(commit_ref, repo);
- if (err)
- goto done;
- err = got_error(GOT_ERR_COMMIT_NO_CHANGES);
- }
+ if (err)
goto done;
- }
- /* Prevent out-of-date errors during rebase of subsequent commits. */
- err = bump_all_base_commit_ids(worktree, *new_commit_id);
+ err = got_ref_change_ref(tmp_branch, *new_commit_id);
if (err)
goto done;
@@ -3865,11 +3862,33 @@ got_worktree_rebase_commit(struct got_object_id **new_commit_id,
if (err)
goto done;
- err = got_ref_change_ref(tmp_branch, *new_commit_id);
+ err = update_fileindex_after_commit(&commitable_paths,
+ *new_commit_id, fileindex, worktree);
+ if (err == NULL) {
+ /* Prevent out-of-date error when rebasing more commits. */
+ bbc_arg.base_commit_id = *new_commit_id;
+ bbc_arg.entry_name = NULL;
+ bbc_arg.path = "";
+ bbc_arg.path_len = 0;
+ bbc_arg.progress_cb = NULL;
+ bbc_arg.progress_arg = NULL;
+ err = got_fileindex_for_each_entry_safe(fileindex,
+ bump_base_commit_id, &bbc_arg);
+ }
+ sync_err = sync_fileindex(fileindex, fileindex_path);
+ if (sync_err && err == NULL)
+ err = sync_err;
+
done:
+ if (fileindex)
+ got_fileindex_free(fileindex);
+ free(fileindex_path);
free(commit_ref_name);
if (commit_ref)
got_ref_close(commit_ref);
+ free(head_commit_id);
+ if (head_ref)
+ got_ref_close(head_ref);
if (err) {
free(*new_commit_id);
*new_commit_id = NULL;