Skip to content

Commit 37c2619

Browse files
committed
Merge branch 'ag/sequencer-todo-updates'
Reduce unnecessary reading of state variables back from the disk during sequencer operation. * ag/sequencer-todo-updates: sequencer: directly call pick_commits() from complete_action() rebase: fill `squash_onto' in get_replay_opts() sequencer: move the code writing total_nr on the disk to a new function sequencer: update `done_nr' when skipping commands in a todo list sequencer: update `total_nr' when adding an item to a todo list
2 parents 571fb96 + 393adf7 commit 37c2619

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

builtin/rebase.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
130130
parse_strategy_opts(&replay, strategy_buf.buf);
131131

132132
strbuf_release(&strategy_buf);
133+
134+
if (opts->squash_onto) {
135+
oidcpy(&replay.squash_onto, opts->squash_onto);
136+
replay.have_squash_onto = 1;
137+
}
138+
133139
return replay;
134140
}
135141

sequencer.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ void todo_list_release(struct todo_list *todo_list)
21302130
static struct todo_item *append_new_todo(struct todo_list *todo_list)
21312131
{
21322132
ALLOC_GROW(todo_list->items, todo_list->nr + 1, todo_list->alloc);
2133+
todo_list->total_nr++;
21332134
return todo_list->items + todo_list->nr++;
21342135
}
21352136

@@ -2401,6 +2402,16 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
24012402
sequencer_remove_state(&opts);
24022403
}
24032404

2405+
static void todo_list_write_total_nr(struct todo_list *todo_list)
2406+
{
2407+
FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
2408+
2409+
if (f) {
2410+
fprintf(f, "%d\n", todo_list->total_nr);
2411+
fclose(f);
2412+
}
2413+
}
2414+
24042415
static int read_populate_todo(struct repository *r,
24052416
struct todo_list *todo_list,
24062417
struct replay_opts *opts)
@@ -2446,7 +2457,6 @@ static int read_populate_todo(struct repository *r,
24462457

24472458
if (is_rebase_i(opts)) {
24482459
struct todo_list done = TODO_LIST_INIT;
2449-
FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
24502460

24512461
if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
24522462
!todo_list_parse_insn_buffer(r, done.buf.buf, &done))
@@ -2458,10 +2468,7 @@ static int read_populate_todo(struct repository *r,
24582468
+ count_commands(todo_list);
24592469
todo_list_release(&done);
24602470

2461-
if (f) {
2462-
fprintf(f, "%d\n", todo_list->total_nr);
2463-
fclose(f);
2464-
}
2471+
todo_list_write_total_nr(todo_list);
24652472
}
24662473

24672474
return 0;
@@ -5176,6 +5183,7 @@ static int skip_unnecessary_picks(struct repository *r,
51765183
MOVE_ARRAY(todo_list->items, todo_list->items + i, todo_list->nr - i);
51775184
todo_list->nr -= i;
51785185
todo_list->current = 0;
5186+
todo_list->done_nr += i;
51795187

51805188
if (is_fixup(peek_command(todo_list, 0)))
51815189
record_in_rewritten(base_oid, peek_command(todo_list, 0));
@@ -5255,15 +5263,21 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
52555263
return error_errno(_("could not write '%s'"), todo_file);
52565264
}
52575265

5258-
todo_list_release(&new_todo);
5266+
res = -1;
52595267

52605268
if (checkout_onto(r, opts, onto_name, &oid, orig_head))
5261-
return -1;
5269+
goto cleanup;
52625270

52635271
if (require_clean_work_tree(r, "rebase", "", 1, 1))
5264-
return -1;
5272+
goto cleanup;
52655273

5266-
return sequencer_continue(r, opts);
5274+
todo_list_write_total_nr(&new_todo);
5275+
res = pick_commits(r, &new_todo, opts);
5276+
5277+
cleanup:
5278+
todo_list_release(&new_todo);
5279+
5280+
return res;
52675281
}
52685282

52695283
struct subject2item_entry {

0 commit comments

Comments
 (0)