Skip to content

Commit cacc15e

Browse files
committed
Merge branch 'js/rebase-count-fixes'
A few bugs in the sequencer machinery that results in miscounting the steps have been corrected. * js/rebase-count-fixes: rebase -r: fix the total number shown in the progress rebase --update-refs: fix loops
2 parents dc3fd24 + 170eea9 commit cacc15e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

sequencer.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,6 @@ void todo_list_release(struct todo_list *todo_list)
24772477
static struct todo_item *append_new_todo(struct todo_list *todo_list)
24782478
{
24792479
ALLOC_GROW(todo_list->items, todo_list->nr + 1, todo_list->alloc);
2480-
todo_list->total_nr++;
24812480
return todo_list->items + todo_list->nr++;
24822481
}
24832482

@@ -2668,7 +2667,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
26682667
char *p = buf, *next_p;
26692668
int i, res = 0, fixup_okay = file_exists(rebase_path_done());
26702669

2671-
todo_list->current = todo_list->nr = 0;
2670+
todo_list->current = todo_list->nr = todo_list->total_nr = 0;
26722671

26732672
for (i = 1; *p; i++, p = next_p) {
26742673
char *eol = strchrnul(p, '\n');
@@ -2689,6 +2688,9 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
26892688
item->commit = NULL;
26902689
}
26912690

2691+
if (item->command != TODO_COMMENT)
2692+
todo_list->total_nr++;
2693+
26922694
if (fixup_okay)
26932695
; /* do nothing */
26942696
else if (is_fixup(item->command))
@@ -4270,7 +4272,7 @@ void todo_list_filter_update_refs(struct repository *r,
42704272
if (!is_null_oid(&rec->after))
42714273
continue;
42724274

4273-
for (j = 0; !found && j < todo_list->total_nr; j++) {
4275+
for (j = 0; !found && j < todo_list->nr; j++) {
42744276
struct todo_item *item = &todo_list->items[j];
42754277
const char *arg = todo_list->buf.buf + item->arg_offset;
42764278

@@ -4300,7 +4302,7 @@ void todo_list_filter_update_refs(struct repository *r,
43004302
* For each todo_item, check if its ref is in the update_refs list.
43014303
* If not, then add it as an un-updated ref.
43024304
*/
4303-
for (i = 0; i < todo_list->total_nr; i++) {
4305+
for (i = 0; i < todo_list->nr; i++) {
43044306
struct todo_item *item = &todo_list->items[i];
43054307
const char *arg = todo_list->buf.buf + item->arg_offset;
43064308
int j, found = 0;
@@ -6148,7 +6150,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
61486150
todo_list_to_strbuf(r, &new_todo, &buf2, -1, 0);
61496151
strbuf_swap(&new_todo.buf, &buf2);
61506152
strbuf_release(&buf2);
6151-
new_todo.total_nr -= new_todo.nr;
6153+
/* Nothing is done yet, and we're reparsing, so let's reset the count */
6154+
new_todo.total_nr = 0;
61526155
if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) < 0)
61536156
BUG("invalid todo list after expanding IDs:\n%s",
61546157
new_todo.buf.buf);

t/t3430-rebase-merges.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,12 @@ test_expect_success '--rebase-merges with message matched with onto label' '
578578
EOF
579579
'
580580

581+
test_expect_success 'progress shows the correct total' '
582+
git checkout -b progress H &&
583+
git rebase --rebase-merges --force-rebase --verbose A 2> err &&
584+
# Expecting "Rebasing (N/14)" here, no bogus total number
585+
grep "^Rebasing.*/14.$" err >progress &&
586+
test_line_count = 14 progress
587+
'
588+
581589
test_done

0 commit comments

Comments
 (0)