{"thread":{"id":"12803","subject":"[PATCH] [RFC] add Message-ID field to log on git-am operation","startedAt":"2008-03-21T22:00:05Z","lastAt":"2008-03-24T06:43:27Z","messageCount":5,"participants":["Anton Gladkov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"72628","messageId":"1206136805-20115-1-git-send-email-agladkov@parallels.com","threadId":"12803","inReplyTo":null,"subject":"[PATCH] [RFC] add Message-ID field to log on git-am operation","fromName":"Anton Gladkov","fromEmail":"agladkov@parallels.com","sentAt":"2008-03-21T22:00:05Z","receivedAt":"2008-03-21T22:00:05Z","isPatch":true,"sender":{"key":"agladkov@parallels.com","avatar":null},"body":"o For what?\n E.g. you have tuned your post-script\n to send a notification on patches committed to\n the main branch. It is usefull when such\n notification sended as a reply on original message\n to follow already committed patches.\no How to use?\n Just 'git-am' your message.\n To whatch a message ID in logs use '%M' in pretty format or\n 'full' format.\n---\n builtin-commit-tree.c |    2 ++\n builtin-mailinfo.c    |    5 ++++-\n git-am.sh             |    3 ++-\n pretty.c              |   12 ++++++++++++\n 4 files changed, 20 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-commit-tree.c b/builtin-commit-tree.c\nindex 6610d18..b396ec4 100644\n--- a/builtin-commit-tree.c\n+++ b/builtin-commit-tree.c\n@@ -100,6 +100,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t/* Person/date information */\n \tstrbuf_addf(&buffer, \"author %s\\n\", git_author_info(IDENT_ERROR_ON_NO_NAME));\n \tstrbuf_addf(&buffer, \"committer %s\\n\", git_committer_info(IDENT_ERROR_ON_NO_NAME));\n+\tif (getenv(\"GIT_MESSAGE_ID\") != NULL)\n+\t\tstrbuf_addf(&buffer, \"message %s\\n\", getenv(\"GIT_MESSAGE_ID\"));\n \tif (!encoding_is_utf8)\n \t\tstrbuf_addf(&buffer, \"encoding %s\\n\", git_commit_encoding);\n \tstrbuf_addch(&buffer, '\\n');\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex 11f154b..f800d86 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -289,7 +289,7 @@ static void cleanup_space(char *buf)\n \n static void decode_header(char *it, unsigned itsize);\n static const char *header[MAX_HDR_PARSED] = {\n-\t\"From\",\"Subject\",\"Date\",\n+\t\"From\",\"Subject\",\"Date\",\"Message-ID\"\n };\n \n static int check_header(char *line, unsigned linesize, char **hdr_data, int overwrite)\n@@ -905,6 +905,9 @@ static void handle_info(void)\n \t\t\thandle_from(hdr);\n \t\t\tfprintf(fout, \"Author: %s\\n\", name);\n \t\t\tfprintf(fout, \"Email: %s\\n\", email);\n+\t\t} else if (!memcmp(header[i], \"Message-ID\", 10)) {\n+\t\t\tcleanup_space(hdr);\n+\t\t\tfprintf(fout, \"%s: %s\\n\", header[i], hdr);\n \t\t} else {\n \t\t\tcleanup_space(hdr);\n \t\t\tfprintf(fout, \"%s: %s\\n\", header[i], hdr);\ndiff --git a/git-am.sh b/git-am.sh\nindex ac5c388..ba22bf8 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -338,6 +338,7 @@ do\n \tGIT_AUTHOR_NAME=\"$(sed -n '/^Author/ s/Author: //p' \"$dotest/info\")\"\n \tGIT_AUTHOR_EMAIL=\"$(sed -n '/^Email/ s/Email: //p' \"$dotest/info\")\"\n \tGIT_AUTHOR_DATE=\"$(sed -n '/^Date/ s/Date: //p' \"$dotest/info\")\"\n+\tGIT_MESSAGE_ID=\"$(sed -n '/^Message-ID/ s/Message-ID: //p' \"$dotest/info\")\"\n \n \tif test -z \"$GIT_AUTHOR_EMAIL\"\n \tthen\n@@ -345,7 +346,7 @@ do\n \t\tstop_here $this\n \tfi\n \n-\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE\n+\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE GIT_MESSAGE_ID\n \n \tSUBJECT=\"$(sed -n '/^Subject/ s/Subject: //p' \"$dotest/info\")\"\n \tcase \"$keep_subject\" in -k)  SUBJECT=\"[PATCH] $SUBJECT\" ;; esac\ndiff --git a/pretty.c b/pretty.c\nindex 16bfb86..076718c 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -385,6 +385,7 @@ struct format_commit_context {\n \tstruct chunk subject;\n \tstruct chunk author;\n \tstruct chunk committer;\n+\tstruct chunk message;\n \tstruct chunk encoding;\n \tsize_t body_off;\n \n@@ -438,6 +439,9 @@ static void parse_commit_header(struct format_commit_context *context)\n \t\t} else if (!prefixcmp(msg + i, \"committer \")) {\n \t\t\tcontext->committer.off = i + 10;\n \t\t\tcontext->committer.len = eol - i - 10;\n+\t\t} else if (!prefixcmp(msg + i, \"message \")) {\n+\t\t\tcontext->message.off = i + 8;\n+\t\t\tcontext->message.len = eol - i - 8;\n \t\t} else if (!prefixcmp(msg + i, \"encoding \")) {\n \t\t\tcontext->encoding.off = i + 9;\n \t\t\tcontext->encoding.len = eol - i - 9;\n@@ -547,6 +551,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \tcase 'c':\t/* committer ... */\n \t\treturn format_person_part(sb, placeholder[1],\n \t\t                   msg + c->committer.off, c->committer.len);\n+\tcase 'M':\t/* message */\n+\t\tstrbuf_add(sb, msg + c->message.off, c->message.len);\n+\t\treturn 1;\n \tcase 'e':\t/* encoding */\n \t\tstrbuf_add(sb, msg + c->encoding.off, c->encoding.len);\n \t\treturn 1;\n@@ -627,6 +634,11 @@ static void pp_header(enum cmit_fmt fmt,\n \t\t\tstrbuf_grow(sb, linelen + 80);\n \t\t\tpp_user_info(\"Commit\", fmt, sb, line + 10, dmode, encoding);\n \t\t}\n+\t\tif (!memcmp(line, \"message \", 8) &&\n+\t\t    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {\n+\t\t\tstrbuf_grow(sb, linelen + 80);\n+\t\t\tpp_user_info(\"Message-ID\", fmt, sb, line + 8, dmode, encoding);\n+\t\t}\n \t}\n }\n \n-- \n1.5.5.rc0.22.ga384d.dirty\n"},{"id":"72698","messageId":"7v4payilkp.fsf@gitster.siamese.dyndns.org","threadId":"12803","inReplyTo":"1206136805-20115-1-git-send-email-agladkov@parallels.com","subject":"Re: [PATCH] [RFC] add Message-ID field to log on git-am operation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-22T19:51:34Z","receivedAt":"2008-03-22T19:51:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is a mixed bag.\n\nYour changes to mailinfo is fine, and I think it may make even more sense\nto also parse out In-Reply-To: and References: to capture the message\ncontext better.\n\nOn the other hand, I'd NAK changes to pretty.c and commit-tree.c; it is\nwrong to place that information in new commit object header.  The commit\nobject header is a place to store information common to all commit objects\n(authorship and committer) and the structural information that is required\nto correctly handle the commit objects (pointers to trees and commits, and\nencoding that tells what the message part is in if it is not in UTF-8).\n\nJust like workflows inspired by the kernel project use Signed-off-by: and\nAcked-by: information in the commit message part to keep track of the flow\nof patches, and some distro folks say \"Closes #nnn\" in their messages to\nclose their issue tracking system entries, your \"message\" is information\nonly useful to a particular workflow and convention, and belongs to the\ncommit log message body, not in the object header.\n\nWouldn't it work equally well to use applypatch-msg hook?  Use your\nupdated mailinfo to parse necessary information out of the incoming\nmessage, and add Message-ID: to the commit log messsage, perhaps at the\nend, in that hook?\n"},{"id":"72778","messageId":"20080323171621.GA3886@atn.sw.ru","threadId":"12803","inReplyTo":"7v4payilkp.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] [RFC] add Message-ID field to log on git-am operation","fromName":"Anton Gladkov","fromEmail":"agladkov@parallels.com","sentAt":"2008-03-23T17:16:21Z","receivedAt":"2008-03-23T17:16:21Z","isPatch":true,"sender":{"key":"agladkov@parallels.com","avatar":null},"body":"Junio!\nThank you for your response :)\n\nOn Sat, Mar 22, 2008 at 12:51:34PM -0700, Junio C Hamano wrote:\n> This is a mixed bag.\n> \n> Your changes to mailinfo is fine, and I think it may make even more sense\n> to also parse out In-Reply-To: and References: to capture the message\n> context better.\n\nI've found that all I need could be parsed by less changes in mailinfo.\nBy adding header fields I need to 'header' array :)\n\n> \n> On the other hand, I'd NAK changes to pretty.c and commit-tree.c; it is\n> wrong to place that information in new commit object header.  The commit\n> object header is a place to store information common to all commit objects\n> (authorship and committer) and the structural information that is required\n> to correctly handle the commit objects (pointers to trees and commits, and\n> encoding that tells what the message part is in if it is not in UTF-8).\n\nI see...\n\n> \n> Just like workflows inspired by the kernel project use Signed-off-by: and\n> Acked-by: information in the commit message part to keep track of the flow\n> of patches, and some distro folks say \"Closes #nnn\" in their messages to\n> close their issue tracking system entries, your \"message\" is information\n> only useful to a particular workflow and convention, and belongs to the\n> commit log message body, not in the object header.\n\nOk.\n\n> \n> Wouldn't it work equally well to use applypatch-msg hook?  Use your\n> updated mailinfo to parse necessary information out of the incoming\n> message, and add Message-ID: to the commit log messsage, perhaps at the\n> end, in that hook?\n\napplypatch-msg hook executed on message applying, after that there could be\nuseful to test applied patch, so it is not the place for notification sending.\n\n-- \nBest regards,\n\t\tanton\nmailto:agladkov@sw.ru\n"},{"id":"72791","messageId":"7v4pax70lz.fsf@gitster.siamese.dyndns.org","threadId":"12803","inReplyTo":"20080323171621.GA3886@atn.sw.ru","subject":"Re: [PATCH] [RFC] add Message-ID field to log on git-am operation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-23T18:32:08Z","receivedAt":"2008-03-23T18:32:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Anton Gladkov <agladkov@parallels.com> writes:\n\n> On Sat, Mar 22, 2008 at 12:51:34PM -0700, Junio C Hamano wrote:\n> ...\n>> Wouldn't it work equally well to use applypatch-msg hook?  Use your\n>> updated mailinfo to parse necessary information out of the incoming\n>> message, and add Message-ID: to the commit log messsage, perhaps at the\n>> end, in that hook?\n>\n> applypatch-msg hook executed on message applying, after that there could be\n> useful to test applied patch, so it is not the place for notification sending.\n\nAnd nobody suggested to send anything from the hook.\n\nAs I understood from your e-mail without proposed commit log message, your\nassumed workflow was:\n\n\treceive mail\n        \"git am\" it\n\ttest rewrite amend whatever you want to convince yourself that\n         the received patch was Ok\n        push the result out\n        pushed-into repository has a hook to send notification,\n         by picking up the Message-ID from the commit object\n\nThe only thing you need was that the message-id information is available\nsomewhere in the commit object.  I objected to your patch that puts it in\nthe commit object header and suggested it be placed in the commit log\nmessage.  You can implement such custom commit munging to add an extra\nMessage-ID: line inside the hook.  You do not have to send out e-mail nor\nanything from it.\n"},{"id":"72859","messageId":"20080324064327.GE22468@atn.sw.ru","threadId":"12803","inReplyTo":"7v4pax70lz.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] [RFC] add Message-ID field to log on git-am operation","fromName":"Anton Gladkov","fromEmail":"agladkov@parallels.com","sentAt":"2008-03-24T06:43:27Z","receivedAt":"2008-03-24T06:43:27Z","isPatch":true,"sender":{"key":"agladkov@parallels.com","avatar":null},"body":"On Sun, Mar 23, 2008 at 11:32:08AM -0700, Junio C Hamano wrote:\n> Anton Gladkov <agladkov@parallels.com> writes:\n> > ...\n> > applypatch-msg hook executed on message applying, after that there could be\n> > useful to test applied patch, so it is not the place for notification sending.\n> \n> And nobody suggested to send anything from the hook.\n> \n> As I understood from your e-mail without proposed commit log message, your\n> assumed workflow was:\n> \n> \treceive mail\n>         \"git am\" it\n> \ttest rewrite amend whatever you want to convince yourself that\n>          the received patch was Ok\n>         push the result out\n>         pushed-into repository has a hook to send notification,\n>          by picking up the Message-ID from the commit object\n\nThat is it.\n\n> \n> The only thing you need was that the message-id information is available\n> somewhere in the commit object.  I objected to your patch that puts it in\n> the commit object header and suggested it be placed in the commit log\n> message.  You can implement such custom commit munging to add an extra\n> Message-ID: line inside the hook.  You do not have to send out e-mail nor\n> anything from it.\n\nI've got your idea! Thank you :)\n\n-- \nBest regards,\n\t\tanton\nmailto:agladkov@sw.ru\n"}]}