Merge branch 'pw/status-with-corrupt-sequencer-state'
The code to read state files used by the sequencer machinery for "git status" has been made more robust against a corrupt or stale state files. * pw/status-with-corrupt-sequencer-state: status: do not report errors in sequencer/todo sequencer: factor out todo command name parsing sequencer: always allow tab after command name
This commit is contained in:
43
sequencer.c
43
sequencer.c
@ -2079,6 +2079,18 @@ const char *todo_item_get_arg(struct todo_list *todo_list,
|
|||||||
return todo_list->buf.buf + item->arg_offset;
|
return todo_list->buf.buf + item->arg_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_command(enum todo_command command, const char **bol)
|
||||||
|
{
|
||||||
|
const char *str = todo_command_info[command].str;
|
||||||
|
const char nick = todo_command_info[command].c;
|
||||||
|
const char *p = *bol + 1;
|
||||||
|
|
||||||
|
return skip_prefix(*bol, str, bol) ||
|
||||||
|
((nick && **bol == nick) &&
|
||||||
|
(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) &&
|
||||||
|
(*bol = p));
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_insn_line(struct repository *r, struct todo_item *item,
|
static int parse_insn_line(struct repository *r, struct todo_item *item,
|
||||||
const char *buf, const char *bol, char *eol)
|
const char *buf, const char *bol, char *eol)
|
||||||
{
|
{
|
||||||
@ -2100,12 +2112,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < TODO_COMMENT; i++)
|
for (i = 0; i < TODO_COMMENT; i++)
|
||||||
if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
|
if (is_command(i, &bol)) {
|
||||||
item->command = i;
|
|
||||||
break;
|
|
||||||
} else if ((bol + 1 == eol || bol[1] == ' ') &&
|
|
||||||
*bol == todo_command_info[i].c) {
|
|
||||||
bol++;
|
|
||||||
item->command = i;
|
item->command = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2173,34 +2180,26 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
|
|||||||
|
|
||||||
int sequencer_get_last_command(struct repository *r, enum replay_action *action)
|
int sequencer_get_last_command(struct repository *r, enum replay_action *action)
|
||||||
{
|
{
|
||||||
struct todo_item item;
|
const char *todo_file, *bol;
|
||||||
char *eol;
|
|
||||||
const char *todo_file;
|
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int ret = -1;
|
int ret = 0;
|
||||||
|
|
||||||
todo_file = git_path_todo_file();
|
todo_file = git_path_todo_file();
|
||||||
if (strbuf_read_file(&buf, todo_file, 0) < 0) {
|
if (strbuf_read_file(&buf, todo_file, 0) < 0) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT || errno == ENOTDIR)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
return error_errno("unable to open '%s'", todo_file);
|
return error_errno("unable to open '%s'", todo_file);
|
||||||
}
|
}
|
||||||
eol = strchrnul(buf.buf, '\n');
|
bol = buf.buf + strspn(buf.buf, " \t\r\n");
|
||||||
if (buf.buf != eol && eol[-1] == '\r')
|
if (is_command(TODO_PICK, &bol) && (*bol == ' ' || *bol == '\t'))
|
||||||
eol--; /* strip Carriage Return */
|
|
||||||
if (parse_insn_line(r, &item, buf.buf, buf.buf, eol))
|
|
||||||
goto fail;
|
|
||||||
if (item.command == TODO_PICK)
|
|
||||||
*action = REPLAY_PICK;
|
*action = REPLAY_PICK;
|
||||||
else if (item.command == TODO_REVERT)
|
else if (is_command(TODO_REVERT, &bol) &&
|
||||||
|
(*bol == ' ' || *bol == '\t'))
|
||||||
*action = REPLAY_REVERT;
|
*action = REPLAY_REVERT;
|
||||||
else
|
else
|
||||||
goto fail;
|
ret = -1;
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -798,6 +798,22 @@ EOF
|
|||||||
test_i18ncmp expected actual
|
test_i18ncmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status shows cherry-pick with invalid oid' '
|
||||||
|
mkdir .git/sequencer &&
|
||||||
|
test_write_lines "pick invalid-oid" >.git/sequencer/todo &&
|
||||||
|
git status --untracked-files=no >actual 2>err &&
|
||||||
|
git cherry-pick --quit &&
|
||||||
|
test_must_be_empty err &&
|
||||||
|
test_i18ncmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status does not show error if .git/sequencer is a file' '
|
||||||
|
test_when_finished "rm .git/sequencer" &&
|
||||||
|
test_write_lines hello >.git/sequencer &&
|
||||||
|
git status --untracked-files=no 2>err &&
|
||||||
|
test_must_be_empty err
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'status showing detached at and from a tag' '
|
test_expect_success 'status showing detached at and from a tag' '
|
||||||
test_commit atag tagging &&
|
test_commit atag tagging &&
|
||||||
git checkout atag &&
|
git checkout atag &&
|
||||||
|
Reference in New Issue
Block a user