Skip to content

Commit

Permalink
Merge branch 'js/rebase-count-fixes' into seen
Browse files Browse the repository at this point in the history
* js/rebase-count-fixes:
  rebase -r: fix the total number shown in the progress
  rebase --update-refs: fix loops
  • Loading branch information
gitster committed May 10, 2023
2 parents 3077684 + bb4da29 commit af8d571
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sequencer.c
Expand Up @@ -2695,7 +2695,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
char *p = buf, *next_p;
int i, res = 0, fixup_okay = file_exists(rebase_path_done());

todo_list->current = todo_list->nr = 0;
todo_list->current = todo_list->nr = todo_list->total_nr = 0;

for (i = 1; *p; i++, p = next_p) {
char *eol = strchrnul(p, '\n');
Expand All @@ -2714,7 +2714,8 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
item->arg_offset = p - buf;
item->arg_len = (int)(eol - p);
item->commit = NULL;
}
} else if (item->command == TODO_COMMENT)
todo_list->total_nr--;

if (fixup_okay)
; /* do nothing */
Expand Down Expand Up @@ -4299,7 +4300,7 @@ void todo_list_filter_update_refs(struct repository *r,
if (!is_null_oid(&rec->after))
continue;

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

Expand Down Expand Up @@ -4329,7 +4330,7 @@ void todo_list_filter_update_refs(struct repository *r,
* For each todo_item, check if its ref is in the update_refs list.
* If not, then add it as an un-updated ref.
*/
for (i = 0; i < todo_list->total_nr; i++) {
for (i = 0; i < todo_list->nr; i++) {
struct todo_item *item = &todo_list->items[i];
const char *arg = todo_list->buf.buf + item->arg_offset;
int j, found = 0;
Expand Down Expand Up @@ -6127,7 +6128,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
struct todo_list new_todo = TODO_LIST_INIT;
struct strbuf *buf = &todo_list->buf, buf2 = STRBUF_INIT;
struct object_id oid = onto->object.oid;
int res;
int new_total_nr, res;

repo_find_unique_abbrev_r(r, shortonto, &oid,
DEFAULT_ABBREV);
Expand Down Expand Up @@ -6155,6 +6156,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
return error(_("nothing to do"));
}

new_total_nr = todo_list->total_nr - count_commands(todo_list);
res = edit_todo_list(r, todo_list, &new_todo, shortrevisions,
shortonto, flags);
if (res == -1)
Expand All @@ -6177,11 +6179,13 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
return -1;
}

new_total_nr += count_commands(&new_todo);
new_todo.total_nr = new_total_nr;

/* Expand the commit IDs */
todo_list_to_strbuf(r, &new_todo, &buf2, -1, 0);
strbuf_swap(&new_todo.buf, &buf2);
strbuf_release(&buf2);
new_todo.total_nr -= new_todo.nr;
if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) < 0)
BUG("invalid todo list after expanding IDs:\n%s",
new_todo.buf.buf);
Expand Down
7 changes: 7 additions & 0 deletions t/t3430-rebase-merges.sh
Expand Up @@ -595,4 +595,11 @@ test_expect_success '--rebase-merges with message matched with onto label' '
EOF
'

test_expect_success 'progress shows the correct total' '
git checkout -b progress H &&
git rebase --rebase-merges --force-rebase --verbose A 2> err &&
grep "^Rebasing.*14.$" err >progress &&
test_line_count = 14 progress
'

test_done

0 comments on commit af8d571

Please sign in to comment.