commit - d3de4379508d0eb7de0cfc8b82f56b3178f10694
commit + af61c51081a680a79548682ea8ace02b70008932
blob - 3b09ad3990979150a08ba246a0bc52ef97216959
blob + c1247433b1ac2c401f58f4bcac68507d1d5c02f8
--- got/got.c
+++ got/got.c
}
static const struct got_error *
+collect_commits_to_rebase(struct got_object_id_queue *commits,
+ struct got_object_id *initial_commit_id,
+ struct got_object_id *iter_start_id, struct got_object_id *iter_stop_id,
+ const char *path_prefix, struct got_repository *repo)
+{
+ const struct got_error *err = NULL;
+ struct got_commit_graph *graph = NULL;
+ struct got_object_id *parent_id = NULL;
+ struct got_object_qid *qid;
+ struct got_object_id *commit_id = initial_commit_id;
+
+ err = got_commit_graph_open(&graph, initial_commit_id, "/", 1, repo);
+ if (err)
+ return err;
+
+ err = got_commit_graph_iter_start(graph, iter_start_id, repo);
+ if (err)
+ goto done;
+ while (got_object_id_cmp(commit_id, iter_stop_id) != 0) {
+ err = got_commit_graph_iter_next(&parent_id, graph);
+ if (err) {
+ if (err->code == GOT_ERR_ITER_COMPLETED) {
+ err = got_error_msg(GOT_ERR_ANCESTRY,
+ "ran out of commits to rebase before "
+ "youngest common ancestor commit has "
+ "been reached?!?");
+ goto done;
+ } else if (err->code != GOT_ERR_ITER_NEED_MORE)
+ goto done;
+ err = got_commit_graph_fetch_commits(graph, 1, repo);
+ if (err)
+ goto done;
+ } else {
+ err = rebase_check_path_prefix(parent_id, commit_id,
+ path_prefix, repo);
+ if (err)
+ goto done;
+
+ err = got_object_qid_alloc(&qid, commit_id);
+ if (err)
+ goto done;
+ SIMPLEQ_INSERT_HEAD(commits, qid, entry);
+ commit_id = parent_id;
+ }
+ }
+done:
+ got_commit_graph_close(graph);
+ return err;
+}
+
+static const struct got_error *
cmd_rebase(int argc, char *argv[])
{
const struct got_error *error = NULL;
struct got_object_id *commit_id = NULL, *parent_id = NULL;
struct got_object_id *resume_commit_id = NULL;
struct got_object_id *branch_head_commit_id = NULL, *yca_id = NULL;
- struct got_commit_graph *graph = NULL;
struct got_commit_object *commit = NULL;
int ch, rebase_in_progress = 0, abort_rebase = 0, continue_rebase = 0;
unsigned char rebase_status = GOT_STATUS_NO_CHANGE;
if (error)
goto done;
- error = got_commit_graph_open(&graph, commit_id, "/", 1, repo);
- if (error)
- goto done;
parent_ids = got_object_commit_get_parent_ids(commit);
pid = SIMPLEQ_FIRST(parent_ids);
- error = got_commit_graph_iter_start(graph, pid->id, repo);
+ error = collect_commits_to_rebase(&commits, commit_id, pid->id,
+ yca_id, got_worktree_get_path_prefix(worktree), repo);
got_object_commit_close(commit);
commit = NULL;
if (error)
goto done;
- while (got_object_id_cmp(commit_id, yca_id) != 0) {
- error = got_commit_graph_iter_next(&parent_id, graph);
- if (error) {
- if (error->code == GOT_ERR_ITER_COMPLETED) {
- error = got_error_msg(GOT_ERR_ANCESTRY,
- "ran out of commits to rebase before "
- "youngest common ancestor commit has "
- "been reached?!?");
- goto done;
- } else if (error->code != GOT_ERR_ITER_NEED_MORE)
- goto done;
- error = got_commit_graph_fetch_commits(graph, 1, repo);
- if (error)
- goto done;
- } else {
- error = rebase_check_path_prefix(parent_id, commit_id,
- got_worktree_get_path_prefix(worktree), repo);
- if (error)
- goto done;
- error = got_object_qid_alloc(&qid, commit_id);
- if (error)
- goto done;
- SIMPLEQ_INSERT_HEAD(&commits, qid, entry);
- commit_id = parent_id;
- }
- }
- got_commit_graph_close(graph);
- graph = NULL;
-
if (SIMPLEQ_EMPTY(&commits)) {
if (continue_rebase)
error = rebase_complete(worktree, branch,
free(branch_head_commit_id);
free(resume_commit_id);
free(yca_id);
- if (graph)
- got_commit_graph_close(graph);
if (commit)
got_object_commit_close(commit);
if (branch)