[PATCH 7/8] revert: use getn_sha1() to simplify insn parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To read the object name in the instruction sheet, we currently
manipulate the buffer to artificially introduce a NUL after the
supposed object name, and then use get_sha1() to read the object name
before restoring the buffer.  Get rid of this ugliness by using
getn_sha1(), a function introduced in the previous patch.

Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx>
---
 builtin/revert.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index 0954d22..187c317 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -750,8 +750,7 @@ static int parse_insn_line(char *bol, char *eol,
 			struct replay_insn_list *item, int lineno)
 {
 	unsigned char commit_sha1[20];
-	char *end_of_object_name;
-	int saved, status;
+	int namelen;
 
 	if (!prefixcmp(bol, "pick ") || !prefixcmp(bol, "pick\t")) {
 		item->action = REPLAY_PICK;
@@ -766,13 +765,8 @@ static int parse_insn_line(char *bol, char *eol,
 	/* Eat up extra spaces/ tabs before object name */
 	bol += strspn(bol, " \t");
 
-	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);
-	*end_of_object_name = saved;
-
-	if (status < 0)
+	namelen = strcspn(bol, " \t\n");
+	if (getn_sha1(bol, namelen, commit_sha1))
 		return parse_error(_("malformed object name"),
 				git_path(SEQ_TODO_FILE), lineno, bol);
 
-- 
1.7.8.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]