Skip to content

Commit

Permalink
revert: tolerate extra spaces, tabs in insn sheet
Browse files Browse the repository at this point in the history
Tolerate extra spaces and tabs as part of the the field separator in
'.git/sequencer/todo', for people with fat fingers.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ramkumar Ramachandra authored and Junio C Hamano committed Dec 15, 2011
1 parent 6bc1a23 commit 0db7696
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
18 changes: 12 additions & 6 deletions builtin/revert.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,18 +719,24 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
unsigned char commit_sha1[20];
enum replay_action action;
char *end_of_object_name;
int saved, status;
int saved, status, padding;

if (!prefixcmp(bol, "pick ")) {
if (!prefixcmp(bol, "pick")) {
action = CHERRY_PICK;
bol += strlen("pick ");
} else if (!prefixcmp(bol, "revert ")) {
bol += strlen("pick");
} else if (!prefixcmp(bol, "revert")) {
action = REVERT;
bol += strlen("revert ");
bol += strlen("revert");
} else
return NULL;

end_of_object_name = bol + strcspn(bol, " \n");
/* Eat up extra spaces/ tabs before object name */
padding = strspn(bol, " \t");
if (!padding)
return NULL;
bol += padding;

end_of_object_name = bol + strcspn(bol, " \t\n");
saved = *end_of_object_name;
*end_of_object_name = '\0';
status = get_sha1(bol, commit_sha1);
Expand Down
11 changes: 11 additions & 0 deletions t/t3510-cherry-pick-sequence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ test_expect_success 'malformed instruction sheet 3' '
test_must_fail git cherry-pick --continue
'

test_expect_success 'instruction sheet, fat-fingers version' '
pristine_detach initial &&
test_must_fail git cherry-pick base..anotherpick &&
echo "c" >foo &&
git add foo &&
git commit &&
sed "s/pick \([0-9a-f]*\)/pick \1 /" .git/sequencer/todo >new_sheet &&
cp new_sheet .git/sequencer/todo &&
git cherry-pick --continue
'

test_expect_success 'commit descriptions in insn sheet are optional' '
pristine_detach initial &&
test_must_fail git cherry-pick base..anotherpick &&
Expand Down

0 comments on commit 0db7696

Please sign in to comment.