git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] revert: use getn_sha1() to simplify insn parsing

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Mar 29, 2012, 13:58 UTC
Message-ID
<1333029495-10034-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1333029495-10034-1-git-send-email-artagnon@gmail.com>

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@gmail.com>
---
 sequencer.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index a37846a..458cffb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -517,8 +517,7 @@ 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, padding;
+	int namelen, padding;
 
 	if (!prefixcmp(bol, "pick")) {
 		action = REPLAY_PICK;
@@ -535,12 +534,6 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
 		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);
-	*end_of_object_name = saved;
-
 	/*
 	 * Verify that the action matches up with the one in
 	 * opts; we don't support arbitrary instructions
@@ -552,8 +545,8 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
 		return NULL;
 	}
 
-	if (status < 0)
+	namelen = strcspn(bol, " \t\n");
+	if (getn_sha1(bol, namelen, commit_sha1))
 		return NULL;
 
 	return lookup_commit_reference(commit_sha1);
-- 
1.7.8.1.362.g5d6df.dirty
Previous: Jonathan NiederNext: Ramkumar Ramachandra
Message 7 of 11 in “Minor sequencer.c cleanups”
  1. 0/4 Minor sequencer.c cleanupsRamkumar Ramachandra, Mar 29, 2012
  2. 1/4 sha1_name: introduce getn_sha1() to take lengthRamkumar Ramachandra, Mar 29, 2012
  3. Jonathan NiederApr 3, 2012
  4. Matthieu MoyApr 4, 2012
  5. Ramkumar RamachandraApr 4, 2012
  6. Jonathan NiederApr 4, 2012
  7. 2/4 revert: use getn_sha1() to simplify insn parsingRamkumar Ramachandra, Mar 29, 2012
  8. 3/4 revert: simplify insn parsing logicRamkumar Ramachandra, Mar 29, 2012
  9. Junio C HamanoApr 2, 2012
  10. Ramkumar RamachandraApr 3, 2012
  11. 4/4 revert: report fine-grained errors from insn parserRamkumar Ramachandra, Mar 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.