git-am: add option to extract email Message-Id: tag into commit log
PATCH v2 1/1 git-am: add option to extract email Message-Id: tag into commit log
Some workflows prefer to track exactly which email message was used to generate a commit. This can be used, for example, to generate an automated acknowledgement when a patch is committed as a response to the patch email, or as a reference to the thread which introduced the patch.
Support this by adding a --message-id option (abbreviated as -m) to git-am, which will then extract the message ID and append it to the email commit log.
---
v2: adjust to pass test suite (t5100)
Documentation/git-am.txt | 6 ++++++ builtin/mailinfo.c | 2 +- git-am.sh | 10 +++++++++- t/t5100/info0004 | 1 + t/t5100/info0005 | 1 + t/t5100/info0012 | 1 + 6 files changed, 19 insertions(+), 2 deletions(-)
Documentation/git-am.txt +6 -0
@@ -15,6 +15,7 @@ SYNOPSIS [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>] [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet] [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>] + [--message-id] [(<mbox> | <Maildir>)...] 'git am' (--continue | --skip | --abort)
@@ -121,6 +122,11 @@ default. You can use `--no-utf8` to override this. user to lie about the author date by using the same value as the committer date. +-m:: +--message-id:: + Extract the Message-Id: header from the e-mail and + append it to the commit message's tag stanza. + --skip:: Skip the current patch. This is only meaningful when restarting an aborted patch.
builtin/mailinfo.c +1 -1
@@ -278,7 +278,7 @@ static void cleanup_space(struct strbuf *sb)static void decode_header (struct strbuf *line);static const char *header[MAX_HDR_PARSED ] = { -"From" ,"Subject" ,"Date" , +"From" ,"Subject" ,"Date" ,"Message-Id" };static inline int cmp_header (const struct strbuf *line,const char *hdr)
git-am.sh +9 -1
@@ -39,6 +39,7 @@ committer-date-is-author-date lie about committer date ignore-date use current timestamp for author date rerere-autoupdate update the index with reused conflict resolution if possible S,gpg-sign? GPG-sign commits +m,message-id copy the Message-Id: header to the commit's tag stanza rebasing* (internal use for git-rebase)" . git-sh-setup
@@ -371,7 +372,7 @@ split_patches () { prec=4 dotest="$GIT_DIR/rebase-apply" sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort= -resolvemsg= resume= scissors= no_inbody_headers= +resolvemsg= resume= scissors= no_inbody_headers= message_id= git_apply_opt= committer_date_is_author_date= ignore_date=
@@ -442,6 +443,8 @@ it will be removed. Please do not use it anymore." gpg_sign_opt=-S ;; --gpg-sign=*) gpg_sign_opt="-S${1#--gpg-sign=}" ;; + -m|--message-id) + message_id=t ;; --) shift; break ;; *)
@@ -565,6 +568,7 @@ Use \"git am --abort\" to remove it.")" echo " $git_apply_opt" >"$dotest/apply-opt" echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" + echo "$message_id" > "$dotest/message-id" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" echo "$scissors" >"$dotest/scissors"
@@ -757,6 +761,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"." then cat "$dotest/msg-clean" fi + if test 't' == "$message_id" + then + grep ^Message-Id: "$dotest/info" || true + fi if test '' != "$ADD_SIGNOFF" then echo "$ADD_SIGNOFF"
t/t5100/info0004 +1 -0
@@ -2,4 +2,5 @@ Author: YOSHIFUJI Hideaki / 吉藤英明 Email: [email protected] Subject: GIT: Try all addresses for given remote name Date: Thu, 21 Jul 2005 09:10:36 -0400 (EDT) +Message-Id: <[email protected]>
t/t5100/info0005 +1 -0
@@ -2,4 +2,5 @@ Author: David Kågedal Email: [email protected] Subject: Fixed two bugs in git-cvsimport-script. Date: Mon, 15 Aug 2005 20:18:25 +0200 +Message-Id: <[email protected]>
t/t5100/info0012 +1 -0
@@ -2,4 +2,5 @@ Author: Dmitriy Blinov Email: [email protected] Subject: Изменён список пакетов необходимых для сборки Date: Wed, 12 Nov 2008 17:54:41 +0300 +Message-Id: <[email protected]>
Signature · 1 line
1.9.3
Quoted 37 lines
git-am.sh +5
-1@@ -39,6 +39,7 @@ committer-date-is-author-date lie about committer date ignore-date use current timestamp for author date rerere-autoupdate update the index with reused conflict resolution if possible S,gpg-sign? GPG-sign commits +m,message-id copy the Message-Id: header to the commit's tag stanza rebasing* (internal use for git-rebase)" . git-sh-setup@@ -371,7 +372,7 @@ split_patches () { prec=4 dotest="$GIT_DIR/rebase-apply" sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort= -resolvemsg= resume= scissors= no_inbody_headers= +resolvemsg= resume= scissors= no_inbody_headers= message_id= git_apply_opt= committer_date_is_author_date= ignore_date=@@ -442,6 +443,8 @@ it will be removed. Please do not use it anymore." gpg_sign_opt=-S ;; --gpg-sign=*) gpg_sign_opt="-S${1#--gpg-sign=}" ;; + -m|--message-id) + message_id=t ;; --) shift; break ;; *)@@ -565,6 +568,7 @@ Use \"git am --abort\" to remove it.")" echo " $git_apply_opt" >"$dotest/apply-opt" echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" + echo "$message_id" > "$dotest/message-id" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" echo "$scissors" >"$dotest/scissors"
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 764
Quoted 4 lines
git-am.sh +1
-0@@ -757,6 +761,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"." then cat "$dotest/msg-clean" fi + if test 't' == "$message_id"
The == is bash special, please use = instead
And the 't' can be written as t, so that the whole line looks like this:
if test t = "$message_id"
Quoted 9 lines · Torsten Bögershausen
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 764
Quoted 5 lines
git-am.sh +1
-0@@ -757,6 +761,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"." then cat "$dotest/msg-clean" fi + if test 't' == "$message_id"The == is bash special, please use = instead
And the 't' can be written as t, so that the whole line looks like this:
if test t = "$message_id"
Thanks. v3 posted with these changes.
Hi Avi,
Quoted 82 lines · Avi Kivity
Some workflows prefer to track exactly which email message was used to generate a commit. This can be used, for example, to generate an automated acknowledgement when a patch is committed as a response to the patch email, or as a reference to the thread which introduced the patch.
Support this by adding a --message-id option (abbreviated as -m) to git-am, which will then extract the message ID and append it to the email commit log.
Signed-off-by Avi Kivity <[email protected]>---
v2: adjust to pass test suite (t5100)
Documentation/git-am.txt | 6 ++++++ builtin/mailinfo.c | 2 +- git-am.sh | 10 +++++++++- t/t5100/info0004 | 1 + t/t5100/info0005 | 1 + t/t5100/info0012 | 1 + 6 files changed, 19 insertions(+), 2 deletions(-)Documentation/git-am.txt +6
-0@@ -15,6 +15,7 @@ SYNOPSIS [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>] [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet] [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>] + [--message-id] [(<mbox> | <Maildir>)...] 'git am' (--continue | --skip | --abort)@@ -121,6 +122,11 @@ default. You can use `--no-utf8` to override this. user to lie about the author date by using the same value as the committer date. +-m:: +--message-id:: + Extract the Message-Id: header from the e-mail and + append it to the commit message's tag stanza. + --skip:: Skip the current patch. This is only meaningful when restarting an aborted patch.builtin/mailinfo.c +1
-1@@ -278,7 +278,7 @@ static void cleanup_space(struct strbuf *sb)static void decode_header (struct strbuf *line);static const char *header[MAX_HDR_PARSED ] = { -"From" ,"Subject" ,"Date" , +"From" ,"Subject" ,"Date" ,"Message-Id" };static inline int cmp_header (const struct strbuf *line,const char *hdr)git-am.sh +2
-1@@ -39,6 +39,7 @@ committer-date-is-author-date lie about committer date ignore-date use current timestamp for author date rerere-autoupdate update the index with reused conflict resolution if possible S,gpg-sign? GPG-sign commits +m,message-id copy the Message-Id: header to the commit's tag stanza rebasing* (internal use for git-rebase)" . git-sh-setup@@ -371,7 +372,7 @@ split_patches () { prec=4 dotest="$GIT_DIR/rebase-apply" sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort= -resolvemsg= resume= scissors= no_inbody_headers= +resolvemsg= resume= scissors= no_inbody_headers= message_id= git_apply_opt= committer_date_is_author_date= ignore_date=
git-am.sh it will be removed. Please do not use it anymore." · line 447
Quoted 5 lines
git-am.sh +2
-0@@ -442,6 +443,8 @@ it will be removed. Please do not use it anymore." gpg_sign_opt=-S ;; --gpg-sign=*) gpg_sign_opt="-S${1#--gpg-sign=}" ;; + -m|--message-id) + message_id=t ;;
Doesn't the message-id line in OPTIONS_SPEC make the negated long option --no-message-id available as well? If that's the case, then the corresponding case arm is missing from here.
git-am.sh Use \"git am --abort\" to remove it.")" · line 571
Quoted 8 lines
git-am.sh +1
-0--) shift; break ;; *)@@ -565,6 +568,7 @@ Use \"git am --abort\" to remove it.")" echo " $git_apply_opt" >"$dotest/apply-opt" echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" + echo "$message_id" > "$dotest/message-id"
To match the local style conventions, the space character after the redirection operator should be removed.
Also, isn't the patch missing the bits where the state of message-id is read? Like so:
if test "$(cat "$dotest/message-id")" = t
then
message_id=t
figit-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 766
Quoted 10 lines
git-am.sh +3
-0echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" echo "$scissors" >"$dotest/scissors"@@ -757,6 +761,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"." then cat "$dotest/msg-clean" fi + if test 't' == "$message_id" + then + grep ^Message-Id: "$dotest/info" || true
Why is the true guard needed here? The exit status of grep seems to never be checked.
Although I cannot come up with an example where this would matter, you might want to consider using the grep wrapper sane_grep from git-sh-setup.sh instead. It resets the environment variable GREP_OPTIONS before calling grep so that no unexpected user options come into play.
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"."
Quoted 6 lines
git-am.sh +1
-0+ fi if test '' != "$ADD_SIGNOFF" then echo "$ADD_SIGNOFF"
Fabian
Quoted 85 lines · Fabian Ruch
Hi Avi,
Quoted 82 lines · Avi Kivity
Some workflows prefer to track exactly which email message was used to generate a commit. This can be used, for example, to generate an automated acknowledgement when a patch is committed as a response to the patch email, or as a reference to the thread which introduced the patch.
Support this by adding a --message-id option (abbreviated as -m) to git-am, which will then extract the message ID and append it to the email commit log.
Signed-off-by Avi Kivity <[email protected]>---
v2: adjust to pass test suite (t5100)
Documentation/git-am.txt | 6 ++++++ builtin/mailinfo.c | 2 +- git-am.sh | 10 +++++++++- t/t5100/info0004 | 1 + t/t5100/info0005 | 1 + t/t5100/info0012 | 1 + 6 files changed, 19 insertions(+), 2 deletions(-)Documentation/git-am.txt +6
-0@@ -15,6 +15,7 @@ SYNOPSIS [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>] [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet] [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>] + [--message-id] [(<mbox> | <Maildir>)...] 'git am' (--continue | --skip | --abort)@@ -121,6 +122,11 @@ default. You can use `--no-utf8` to override this. user to lie about the author date by using the same value as the committer date. +-m:: +--message-id:: + Extract the Message-Id: header from the e-mail and + append it to the commit message's tag stanza. + --skip:: Skip the current patch. This is only meaningful when restarting an aborted patch.builtin/mailinfo.c +1
-1@@ -278,7 +278,7 @@ static void cleanup_space(struct strbuf *sb)static void decode_header (struct strbuf *line);static const char *header[MAX_HDR_PARSED ] = { -"From" ,"Subject" ,"Date" , +"From" ,"Subject" ,"Date" ,"Message-Id" };static inline int cmp_header (const struct strbuf *line,const char *hdr)git-am.sh +2
-1@@ -39,6 +39,7 @@ committer-date-is-author-date lie about committer date ignore-date use current timestamp for author date rerere-autoupdate update the index with reused conflict resolution if possible S,gpg-sign? GPG-sign commits +m,message-id copy the Message-Id: header to the commit's tag stanza rebasing* (internal use for git-rebase)" . git-sh-setup@@ -371,7 +372,7 @@ split_patches () { prec=4 dotest="$GIT_DIR/rebase-apply" sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort= -resolvemsg= resume= scissors= no_inbody_headers= +resolvemsg= resume= scissors= no_inbody_headers= message_id= git_apply_opt= committer_date_is_author_date= ignore_date=@@ -442,6 +443,8 @@ it will be removed. Please do not use it anymore."
Quoted 8 lines
git-am.sh it will be removed. Please do not use it anymore." · line 447
Quoted 5 lines
git-am.sh +2
-0gpg_sign_opt=-S ;; --gpg-sign=*) gpg_sign_opt="-S${1#--gpg-sign=}" ;; + -m|--message-id) + message_id=t ;;Doesn't the message-id line in
OPTIONS_SPECmake the negated long option --no-message-id available as well? If that's the case, then the corresponding case arm is missing from here.
I don't know, but some other booleans don't supply negations, for example --reject.
Quoted 10 lines
git-am.sh Use \"git am --abort\" to remove it.")" · line 571
Quoted 8 lines
git-am.sh +1
-0--) shift; break ;; *)@@ -565,6 +568,7 @@ Use \"git am --abort\" to remove it.")" echo " $git_apply_opt" >"$dotest/apply-opt" echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" + echo "$message_id" > "$dotest/message-id"To match the local style conventions, the space character after the redirection operator should be removed.
Sure.
Quoted 7 lines
Also, isn't the patch missing the bits where the state of message-id is read? Like so:
if test "$(cat "$dotest/message-id")" = t then message_id=t fi
Good catch, I guess this fixes a restarted am.
Quoted 13 lines
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 766
Quoted 11 lines
git-am.sh +3
-0echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" echo "$scissors" >"$dotest/scissors"@@ -757,6 +761,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"." then cat "$dotest/msg-clean" fi + if test 't' == "$message_id" + then + grep ^Message-Id: "$dotest/info" || trueWhy is the true guard needed here? The exit status of grep seems to never be checked.
I usually code scripts with -e, but here it's unneeded.
Quoted 6 lines
Although I cannot come up with an example where this would matter, you might want to consider using the grep wrapper
sane_grepfromgit-sh-setup.shinstead. It resets the environment variableGREP_OPTIONSbefore calling grep so that no unexpected user options come into play.
Good idea. Will post a v4 shortly.
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 770
Quoted 7 lines · Avi Kivity
git-am.sh +4
-0+ if test 't' == "$message_id" + then + grep ^Message-Id: "$dotest/info" || true + fi if test '' != "$ADD_SIGNOFF" then echo "$ADD_SIGNOFF"
Seeing how existing code carefully makes sure that ADD_SIGNOFF has an empty line before it when and only when necessary to ensure that there is a blank after the existing log message, I would suspect that this patch that blindly inserts a line is doubly wrong. The output from "grep" may be appended without adding a blank when necessary, and appending of ADD_SIGNOFF may end up adding an extra blank after Message-Id. Am I reading the patch wrong?
Quoted 16 lines · Junio C Hamano
git-am.sh To restore the original branch and stop patching run \"\$cmdline --abort\"." · line 770
Quoted 7 lines · Avi Kivity
git-am.sh +4
-0+ if test 't' == "$message_id" + then + grep ^Message-Id: "$dotest/info" || true + fi if test '' != "$ADD_SIGNOFF" then echo "$ADD_SIGNOFF"Seeing how existing code carefully makes sure that
ADD_SIGNOFFhas an empty line before it when and only when necessary to ensure that there is a blank after the existing log message, I would suspect that this patch that blindly inserts a line is doubly wrong. The output from "grep" may be appended without adding a blank when necessary, and appending ofADD_SIGNOFFmay end up adding an extra blank after Message-Id. Am I reading the patch wrong?
Yes, you're right. Will have to redo the logic for deciding whether we already have a tag stanza or not.