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

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

 



Paolo Bonzini <bonzini@xxxxxxx> 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);
--
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]