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

Re: [PATCH 2/2] patch-id: Add support for mbox format

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 19, 2010, 21:48 UTC
Message-ID
<7vy6gjp0zy.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1271666774-11619-2-git-send-email-bonzini@gnu.org>
Paolo Bonzini <bonzini@gnu.org> writes:
> This patch adds hunk parsing logic to git patch-id in order to detect an
> out of place "-" line and split the patch when it comes.  In addition,
> commit ids in the "From " lines are considered and printed in the output.

I don't know how this patch will affect the difficulty of enhancing it to handle MIME attachments later, but let's say we won't worry about it for now, because we do not even know if we want to do so at this moment.

I fixed up some style issues locally before applying, but please be careful next time.

 - One SP after a keyword used in syntactic constructs (e.g. "if (cond)",
   not "while(cond)"); your patches were fine wrt this;
 - No SP after a function (e.g. "memcpy(args...)", not "memcpy (args...)").

Also please be careful when calling get_sha1_hex(); an unsuccessful call to this function is allowed to clobber the buffer. In addition to the style fixes, I squashed something like this (not exactly this).

Thanks.
 builtin/patch-id.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 40af5c7..4785411 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -61,7 +61,8 @@ int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
 {
 	static char line[1000];
 	int patchlen = 0;
-	int before = -1, after = -1;
+	int before = -1, after = -1, found_next = 0;
+
 	while (fgets(line, sizeof(line), stdin) != NULL) {
 		char *p = line;
 		int len;
@@ -73,8 +74,10 @@ int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
 		else if (!memcmp(line, "From ", 5))
 			p += 5;
 
-		if (!get_sha1_hex(p, next_sha1))
+		if (!get_sha1_hex(p, next_sha1)) {
+			found_next = 1;
 			break;
+		}
 
 		/* Ignore commit comments */
 		if (!patchlen && memcmp(line, "diff ", 5))
@@ -117,6 +120,8 @@ int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx)
 		patchlen += len;
 		git_SHA1_Update(ctx, line, len);
 	}
+	if (!found_next)
+		hashclr(next_sha1);
 	return patchlen;
 }
 
@@ -128,8 +133,8 @@ static void generate_id_list(void)
 	int patchlen;
 
 	git_SHA1_Init(&ctx);
+	hashclr(sha1);
 	while (!feof(stdin)) {
-		memset(n, 0, 20);
 		patchlen = get_one_patchid(n, &ctx);
 		flush_current_id(patchlen, sha1, &ctx);
 		hashcpy(sha1, n);
Previous: Paolo BonziniNext: Paolo Bonzini
Message 9 of 11 in “patch-id: Add support for mbox format”
  1. patch-id: Add support for mbox formatPaolo Bonzini, Apr 16, 2010
  2. Junio C HamanoApr 16, 2010
  3. Paolo BonziniApr 16, 2010
  4. Junio C HamanoApr 16, 2010
  5. Paolo BonziniApr 16, 2010
  6. Junio C HamanoApr 17, 2010
  7. 1/2 patch-id: extract parsing one diff out of generate_id_listPaolo Bonzini, Apr 19, 2010
  8. 2/2 patch-id: Add support for mbox formatPaolo Bonzini, Apr 19, 2010
  9. Junio C HamanoApr 19, 2010
  10. Paolo BonziniApr 20, 2010
  11. Junio C HamanoApr 20, 2010

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.