Skip to content

Commit e323eaf

Browse files
committed
Merge branch 'pw/status-rebase-todo' into seen
The display of the rebase todo list in "git status" has been improved to correctly abbreviate object IDs for more commands and avoid misinterpreting refs as object IDs. * pw/status-rebase-todo: status: improve rebase todo list parsing sequencer: factor out parsing of todo commands
2 parents 3a1204d + 671451d commit e323eaf

4 files changed

Lines changed: 169 additions & 62 deletions

File tree

sequencer.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,27 @@ static int is_command(enum todo_command command, const char **bol)
26272627
return 0;
26282628
}
26292629

2630+
bool sequencer_parse_todo_command(const char **p, enum todo_command *cmd)
2631+
{
2632+
const char *s = *p;
2633+
2634+
for (int i = 0; i < TODO_COMMENT; i++)
2635+
if (is_command(i, p)) {
2636+
*cmd = i;
2637+
return true;
2638+
}
2639+
2640+
if (starts_with(s, comment_line_str)) {
2641+
*cmd = TODO_COMMENT;
2642+
return true;
2643+
} else if (s[0] == '\n' || (s[0] == '\r' && s[1] == '\n') || !s[0]) {
2644+
*cmd = TODO_COMMENT;
2645+
return true;
2646+
}
2647+
2648+
return false;
2649+
}
2650+
26302651
static int check_label_or_ref_arg(enum todo_command command, const char *arg)
26312652
{
26322653
switch (command) {
@@ -2716,30 +2737,24 @@ static int parse_insn_line(struct repository *r, struct replay_opts *opts,
27162737
{
27172738
struct object_id commit_oid;
27182739
char *end_of_object_name;
2719-
int i, saved, status, padding;
2740+
int saved, status, padding;
27202741

27212742
item->flags = 0;
27222743

27232744
/* left-trim */
27242745
bol += strspn(bol, " \t");
27252746

2726-
if (bol == eol || *bol == '\r' || starts_with_mem(bol, eol - bol, comment_line_str)) {
2727-
item->command = TODO_COMMENT;
2747+
if (!sequencer_parse_todo_command(&bol, &item->command))
2748+
return error(_("invalid command '%.*s'"),
2749+
(int)strcspn(bol, " \t\r\n"), bol);
2750+
2751+
if (item->command == TODO_COMMENT) {
27282752
item->commit = NULL;
27292753
item->arg_offset = bol - buf;
27302754
item->arg_len = eol - bol;
27312755
return 0;
27322756
}
27332757

2734-
for (i = 0; i < TODO_COMMENT; i++)
2735-
if (is_command(i, &bol)) {
2736-
item->command = i;
2737-
break;
2738-
}
2739-
if (i >= TODO_COMMENT)
2740-
return error(_("invalid command '%.*s'"),
2741-
(int)strcspn(bol, " \t\r\n"), bol);
2742-
27432758
/* Eat up extra spaces/ tabs before object name */
27442759
padding = strspn(bol, " \t");
27452760
bol += padding;

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ int read_author_script(const char *path, char **name, char **email, char **date,
265265
int write_basic_state(struct replay_opts *opts, const char *head_name,
266266
struct commit *onto, const struct object_id *orig_head);
267267
void sequencer_post_commit_cleanup(struct repository *r, int verbose);
268+
bool sequencer_parse_todo_command(const char **p, enum todo_command *cmd);
268269
int sequencer_get_last_command(struct repository* r,
269270
enum replay_action *action);
270271
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);

t/t7512-status-help.sh

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ test_expect_success 'status when splitting a commit' '
224224
COMMIT3=$(git rev-parse --short split_commit) &&
225225
test_commit four_split main.txt four &&
226226
COMMIT4=$(git rev-parse --short split_commit) &&
227-
FAKE_LINES="1 edit 2 3" &&
227+
FAKE_LINES="reword 1 edit 2 fixup_-C 3" &&
228228
export FAKE_LINES &&
229229
test_when_finished "git rebase --abort" &&
230230
ONTO=$(git rev-parse --short HEAD~3) &&
@@ -233,10 +233,10 @@ test_expect_success 'status when splitting a commit' '
233233
cat >expected <<EOF &&
234234
interactive rebase in progress; onto $ONTO
235235
Last commands done (2 commands done):
236-
pick $COMMIT2 # two_split
236+
reword $COMMIT2 # two_split
237237
edit $COMMIT3 # three_split
238238
Next command to do (1 remaining command):
239-
pick $COMMIT4 # four_split
239+
fixup -C $COMMIT4 # four_split
240240
(use "git rebase --edit-todo" to view and edit)
241241
You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
242242
(Once your working directory is clean, run "git rebase --continue")
@@ -297,7 +297,7 @@ test_expect_success 'prepare for several edits' '
297297

298298

299299
test_expect_success 'status: (continue first edit) second edit' '
300-
FAKE_LINES="edit 1 edit 2 3" &&
300+
FAKE_LINES="edit 1 edit 2 drop 3" &&
301301
export FAKE_LINES &&
302302
test_when_finished "git rebase --abort" &&
303303
COMMIT2=$(git rev-parse --short several_edits^^) &&
@@ -312,7 +312,7 @@ Last commands done (2 commands done):
312312
edit $COMMIT2 # two_edits
313313
edit $COMMIT3 # three_edits
314314
Next command to do (1 remaining command):
315-
pick $COMMIT4 # four_edits
315+
drop $COMMIT4 # four_edits
316316
(use "git rebase --edit-todo" to view and edit)
317317
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
318318
(use "git commit --amend" to amend the current commit)
@@ -327,7 +327,7 @@ EOF
327327

328328
test_expect_success 'status: (continue first edit) second edit and split' '
329329
git reset --hard several_edits &&
330-
FAKE_LINES="edit 1 edit 2 3" &&
330+
FAKE_LINES="edit 1 edit 2 squash 3" &&
331331
export FAKE_LINES &&
332332
test_when_finished "git rebase --abort" &&
333333
COMMIT2=$(git rev-parse --short several_edits^^) &&
@@ -343,7 +343,7 @@ Last commands done (2 commands done):
343343
edit $COMMIT2 # two_edits
344344
edit $COMMIT3 # three_edits
345345
Next command to do (1 remaining command):
346-
pick $COMMIT4 # four_edits
346+
squash $COMMIT4 # four_edits
347347
(use "git rebase --edit-todo" to view and edit)
348348
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
349349
(Once your working directory is clean, run "git rebase --continue")
@@ -362,7 +362,7 @@ EOF
362362

363363
test_expect_success 'status: (continue first edit) second edit and amend' '
364364
git reset --hard several_edits &&
365-
FAKE_LINES="edit 1 edit 2 3" &&
365+
FAKE_LINES="edit 1 edit 2 fixup 3" &&
366366
export FAKE_LINES &&
367367
test_when_finished "git rebase --abort" &&
368368
COMMIT2=$(git rev-parse --short several_edits^^) &&
@@ -378,7 +378,7 @@ Last commands done (2 commands done):
378378
edit $COMMIT2 # two_edits
379379
edit $COMMIT3 # three_edits
380380
Next command to do (1 remaining command):
381-
pick $COMMIT4 # four_edits
381+
fixup $COMMIT4 # four_edits
382382
(use "git rebase --edit-todo" to view and edit)
383383
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
384384
(use "git commit --amend" to amend the current commit)
@@ -393,7 +393,7 @@ EOF
393393

394394
test_expect_success 'status: (amend first edit) second edit' '
395395
git reset --hard several_edits &&
396-
FAKE_LINES="edit 1 edit 2 3" &&
396+
FAKE_LINES="edit 1 edit 2 fixup_-c 3" &&
397397
export FAKE_LINES &&
398398
test_when_finished "git rebase --abort" &&
399399
COMMIT2=$(git rev-parse --short several_edits^^) &&
@@ -409,7 +409,7 @@ Last commands done (2 commands done):
409409
edit $COMMIT2 # two_edits
410410
edit $COMMIT3 # three_edits
411411
Next command to do (1 remaining command):
412-
pick $COMMIT4 # four_edits
412+
fixup -c $COMMIT4 # four_edits
413413
(use "git rebase --edit-todo" to view and edit)
414414
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
415415
(use "git commit --amend" to amend the current commit)
@@ -460,14 +460,20 @@ EOF
460460

461461
test_expect_success 'status: (amend first edit) second edit and amend' '
462462
git reset --hard several_edits &&
463-
FAKE_LINES="edit 1 edit 2 3" &&
464-
export FAKE_LINES &&
465463
test_when_finished "git rebase --abort" &&
466464
COMMIT2=$(git rev-parse --short several_edits^^) &&
467465
COMMIT3=$(git rev-parse --short several_edits^) &&
468466
COMMIT4=$(git rev-parse --short several_edits) &&
469467
ONTO=$(git rev-parse --short HEAD~3) &&
470-
git rebase -i HEAD~3 &&
468+
cat >todo <<-EOF &&
469+
edit several_edits^^ # two_edits
470+
edit several_edits^ # three_edits
471+
merge $(git rev-parse main) $(git rev-parse several_edits)
472+
EOF
473+
(
474+
set_replace_editor todo &&
475+
git rebase -i HEAD~3
476+
) &&
471477
git commit --amend -m "c" &&
472478
git rebase --continue &&
473479
git commit --amend -m "d" &&
@@ -477,7 +483,7 @@ Last commands done (2 commands done):
477483
edit $COMMIT2 # two_edits
478484
edit $COMMIT3 # three_edits
479485
Next command to do (1 remaining command):
480-
pick $COMMIT4 # four_edits
486+
merge $(git rev-parse --short main) $COMMIT4
481487
(use "git rebase --edit-todo" to view and edit)
482488
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
483489
(use "git commit --amend" to amend the current commit)
@@ -525,14 +531,21 @@ EOF
525531

526532
test_expect_success 'status: (split first edit) second edit and split' '
527533
git reset --hard several_edits &&
528-
FAKE_LINES="edit 1 edit 2 3" &&
529-
export FAKE_LINES &&
530534
test_when_finished "git rebase --abort" &&
531535
COMMIT2=$(git rev-parse --short several_edits^^) &&
532536
COMMIT3=$(git rev-parse --short several_edits^) &&
533537
COMMIT4=$(git rev-parse --short several_edits) &&
538+
cat >todo <<-EOF &&
539+
edit several_edits^^ # two_edits
540+
edit several_edits^ # three_edits
541+
reset $(git rev-parse main)
542+
merge -C several_edits topic # title
543+
EOF
534544
ONTO=$(git rev-parse --short HEAD~3) &&
535-
git rebase -i HEAD~3 &&
545+
(
546+
set_replace_editor todo &&
547+
git rebase -i HEAD~3
548+
) &&
536549
git reset HEAD^ &&
537550
git add main.txt &&
538551
git commit --amend -m "f" &&
@@ -543,8 +556,9 @@ interactive rebase in progress; onto $ONTO
543556
Last commands done (2 commands done):
544557
edit $COMMIT2 # two_edits
545558
edit $COMMIT3 # three_edits
546-
Next command to do (1 remaining command):
547-
pick $COMMIT4 # four_edits
559+
Next commands to do (2 remaining commands):
560+
reset $(git rev-parse --short main)
561+
merge -C $COMMIT4 topic # title
548562
(use "git rebase --edit-todo" to view and edit)
549563
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
550564
(Once your working directory is clean, run "git rebase --continue")
@@ -563,14 +577,21 @@ EOF
563577

564578
test_expect_success 'status: (split first edit) second edit and amend' '
565579
git reset --hard several_edits &&
566-
FAKE_LINES="edit 1 edit 2 3" &&
567-
export FAKE_LINES &&
568580
test_when_finished "git rebase --abort" &&
581+
git branch cafe main &&
569582
COMMIT2=$(git rev-parse --short several_edits^^) &&
570583
COMMIT3=$(git rev-parse --short several_edits^) &&
571-
COMMIT4=$(git rev-parse --short several_edits) &&
584+
cat >todo <<-EOF &&
585+
edit several_edits^^ # two_edits
586+
edit several_edits^ # three_edits
587+
update-ref refs/heads/main
588+
reset cafe
589+
EOF
572590
ONTO=$(git rev-parse --short HEAD~3) &&
573-
git rebase -i HEAD~3 &&
591+
(
592+
set_replace_editor todo &&
593+
git rebase -i HEAD~3
594+
) &&
574595
git reset HEAD^ &&
575596
git add main.txt &&
576597
git commit --amend -m "g" &&
@@ -581,8 +602,9 @@ interactive rebase in progress; onto $ONTO
581602
Last commands done (2 commands done):
582603
edit $COMMIT2 # two_edits
583604
edit $COMMIT3 # three_edits
584-
Next command to do (1 remaining command):
585-
pick $COMMIT4 # four_edits
605+
Next commands to do (2 remaining commands):
606+
update-ref refs/heads/main
607+
reset cafe
586608
(use "git rebase --edit-todo" to view and edit)
587609
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
588610
(use "git commit --amend" to amend the current commit)

0 commit comments

Comments
 (0)