[PATCH] [RFC] add Message-ID field to log on git-am operation

Subsystems: the rest

STALE3731d

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] [RFC] add Message-ID field to log on git-am operation

From: Anton Gladkov <hidden>
Date: 2016-06-15 22:44:24

o For what?
 E.g. you have tuned your post-script
 to send a notification on patches committed to
 the main branch. It is usefull when such
 notification sended as a reply on original message
 to follow already committed patches.
o How to use?
 Just 'git-am' your message.
 To whatch a message ID in logs use '%M' in pretty format or
 'full' format.
---
 builtin-commit-tree.c |    2 ++
 builtin-mailinfo.c    |    5 ++++-
 git-am.sh             |    3 ++-
 pretty.c              |   12 ++++++++++++
 4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index 6610d18..b396ec4 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -100,6 +100,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 	/* Person/date information */
 	strbuf_addf(&buffer, "author %s\n", git_author_info(IDENT_ERROR_ON_NO_NAME));
 	strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
+	if (getenv("GIT_MESSAGE_ID") != NULL)
+		strbuf_addf(&buffer, "message %s\n", getenv("GIT_MESSAGE_ID"));
 	if (!encoding_is_utf8)
 		strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
 	strbuf_addch(&buffer, '\n');
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 11f154b..f800d86 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -289,7 +289,7 @@ static void cleanup_space(char *buf)
 
 static void decode_header(char *it, unsigned itsize);
 static const char *header[MAX_HDR_PARSED] = {
-	"From","Subject","Date",
+	"From","Subject","Date","Message-ID"
 };
 
 static int check_header(char *line, unsigned linesize, char **hdr_data, int overwrite)
@@ -905,6 +905,9 @@ static void handle_info(void)
 			handle_from(hdr);
 			fprintf(fout, "Author: %s\n", name);
 			fprintf(fout, "Email: %s\n", email);
+		} else if (!memcmp(header[i], "Message-ID", 10)) {
+			cleanup_space(hdr);
+			fprintf(fout, "%s: %s\n", header[i], hdr);
 		} else {
 			cleanup_space(hdr);
 			fprintf(fout, "%s: %s\n", header[i], hdr);
diff --git a/git-am.sh b/git-am.sh
index ac5c388..ba22bf8 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -338,6 +338,7 @@ do
 	GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
 	GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
 	GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
+	GIT_MESSAGE_ID="$(sed -n '/^Message-ID/ s/Message-ID: //p' "$dotest/info")"
 
 	if test -z "$GIT_AUTHOR_EMAIL"
 	then
@@ -345,7 +346,7 @@ do
 		stop_here $this
 	fi
 
-	export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
+	export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE GIT_MESSAGE_ID
 
 	SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
 	case "$keep_subject" in -k)  SUBJECT="[PATCH] $SUBJECT" ;; esac
diff --git a/pretty.c b/pretty.c
index 16bfb86..076718c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -385,6 +385,7 @@ struct format_commit_context {
 	struct chunk subject;
 	struct chunk author;
 	struct chunk committer;
+	struct chunk message;
 	struct chunk encoding;
 	size_t body_off;
 
@@ -438,6 +439,9 @@ static void parse_commit_header(struct format_commit_context *context)
 		} else if (!prefixcmp(msg + i, "committer ")) {
 			context->committer.off = i + 10;
 			context->committer.len = eol - i - 10;
+		} else if (!prefixcmp(msg + i, "message ")) {
+			context->message.off = i + 8;
+			context->message.len = eol - i - 8;
 		} else if (!prefixcmp(msg + i, "encoding ")) {
 			context->encoding.off = i + 9;
 			context->encoding.len = eol - i - 9;
@@ -547,6 +551,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 	case 'c':	/* committer ... */
 		return format_person_part(sb, placeholder[1],
 		                   msg + c->committer.off, c->committer.len);
+	case 'M':	/* message */
+		strbuf_add(sb, msg + c->message.off, c->message.len);
+		return 1;
 	case 'e':	/* encoding */
 		strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
 		return 1;
@@ -627,6 +634,11 @@ static void pp_header(enum cmit_fmt fmt,
 			strbuf_grow(sb, linelen + 80);
 			pp_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
 		}
+		if (!memcmp(line, "message ", 8) &&
+		    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
+			strbuf_grow(sb, linelen + 80);
+			pp_user_info("Message-ID", fmt, sb, line + 8, dmode, encoding);
+		}
 	}
 }
 
-- 
1.5.5.rc0.22.ga384d.dirty

Re: [PATCH] [RFC] add Message-ID field to log on git-am operation

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:24

This is a mixed bag.

Your changes to mailinfo is fine, and I think it may make even more sense
to also parse out In-Reply-To: and References: to capture the message
context better.

On the other hand, I'd NAK changes to pretty.c and commit-tree.c; it is
wrong to place that information in new commit object header.  The commit
object header is a place to store information common to all commit objects
(authorship and committer) and the structural information that is required
to correctly handle the commit objects (pointers to trees and commits, and
encoding that tells what the message part is in if it is not in UTF-8).

Just like workflows inspired by the kernel project use Signed-off-by: and
Acked-by: information in the commit message part to keep track of the flow
of patches, and some distro folks say "Closes #nnn" in their messages to
close their issue tracking system entries, your "message" is information
only useful to a particular workflow and convention, and belongs to the
commit log message body, not in the object header.

Wouldn't it work equally well to use applypatch-msg hook?  Use your
updated mailinfo to parse necessary information out of the incoming
message, and add Message-ID: to the commit log messsage, perhaps at the
end, in that hook?

Re: [PATCH] [RFC] add Message-ID field to log on git-am operation

From: Anton Gladkov <hidden>
Date: 2016-06-15 22:44:25

Junio!
Thank you for your response :)

On Sat, Mar 22, 2008 at 12:51:34PM -0700, Junio C Hamano wrote:
This is a mixed bag.

Your changes to mailinfo is fine, and I think it may make even more sense
to also parse out In-Reply-To: and References: to capture the message
context better.
I've found that all I need could be parsed by less changes in mailinfo.
By adding header fields I need to 'header' array :)
On the other hand, I'd NAK changes to pretty.c and commit-tree.c; it is
wrong to place that information in new commit object header.  The commit
object header is a place to store information common to all commit objects
(authorship and committer) and the structural information that is required
to correctly handle the commit objects (pointers to trees and commits, and
encoding that tells what the message part is in if it is not in UTF-8).
I see...
Just like workflows inspired by the kernel project use Signed-off-by: and
Acked-by: information in the commit message part to keep track of the flow
of patches, and some distro folks say "Closes #nnn" in their messages to
close their issue tracking system entries, your "message" is information
only useful to a particular workflow and convention, and belongs to the
commit log message body, not in the object header.
Ok.
Wouldn't it work equally well to use applypatch-msg hook?  Use your
updated mailinfo to parse necessary information out of the incoming
message, and add Message-ID: to the commit log messsage, perhaps at the
end, in that hook?
applypatch-msg hook executed on message applying, after that there could be
useful to test applied patch, so it is not the place for notification sending.

-- 
Best regards,
		anton
mailto:agladkov@sw.ru
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help