[PATCH 4/8] revert: separate out parse errors logically
From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:52:45
Subsystem:
the rest · Maintainer:
Linus Torvalds
Three kinds of errors can arise from parsing the instruction sheet:
1. Unrecognized action
2. Malformed object name
3. Object name does not refer to a valid commit
The next patch makes an attempt to make the parser report meaningful
errors by replacing the "return -1" with "return error(...)"
appropriately. For the first kind of error, it is insufficient to
check if the buffer beings with a "pick" or "revert", otherwise the
following insn sheet would be interpreted as having a malformed object
name:
pickle a1fe57~2
In reality, the issue is that "pickle" is an unrecognized instruction.
So, check that the buffer starts with ("pick " or "pick\t") and
("revert " or "revert\t").
Signed-off-by: Ramkumar Ramachandra <redacted>
---
builtin/revert.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 1841ffa..9a09471 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c@@ -736,22 +736,19 @@ static int parse_insn_line(char *bol, char *eol, struct replay_insn_list *item) { unsigned char commit_sha1[20]; char *end_of_object_name; - int saved, status, padding; + int saved, status; - if (!prefixcmp(bol, "pick")) { + if (!prefixcmp(bol, "pick ") || !prefixcmp(bol, "pick\t")) { item->action = REPLAY_PICK; - bol += strlen("pick"); - } else if (!prefixcmp(bol, "revert")) { + bol += strlen("pick "); + } else if (!prefixcmp(bol, "revert ") || !prefixcmp(bol, "revert\t")) { item->action = REPLAY_REVERT; - bol += strlen("revert"); + bol += strlen("revert "); } else return -1; /* Eat up extra spaces/ tabs before object name */ - padding = strspn(bol, " \t"); - if (!padding) - return -1; - bol += padding; + bol += strspn(bol, " \t"); end_of_object_name = bol + strcspn(bol, " \t\n"); saved = *end_of_object_name;
--
1.7.8.2