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

Re: [PATCH v2] git-am: add option to extract email Message-Id: tag into commit log

From
AKAvi Kivity <avi@cloudius-systems.com>
Date
Jul 2, 2014, 14:44 UTC
Message-ID
<53B41AC4.5000308@cloudius-systems.com>
In-Reply-To
<53B414A4.2060909@gmail.com>
On 07/02/2014 05:18 PM, Fabian Ruch wrote:
Show 93 quoted lines
> Hi Avi,
>
> On 07/02/2014 10:51 AM, Avi Kivity wrote:
>> 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 <avi@cloudius-systems.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
>> index 9adce37..8a251a1 100644
>> --- a/Documentation/git-am.txt
>> +++ b/Documentation/git-am.txt
>> @@ -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.
>> diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
>> index cf11c8d..f1e1fed 100644
>> --- a/builtin/mailinfo.c
>> +++ b/builtin/mailinfo.c
>> @@ -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)
>> diff --git a/git-am.sh b/git-am.sh
>> index ee61a77..c0e7bdd 100755
>> --- a/git-am.sh
>> +++ b/git-am.sh
>> @@ -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 ;;
> 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.

I don't know, but some other booleans don't supply negations, for example --reject.

Show 10 quoted lines
>>   	--)
>>   		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.
Show 7 quoted 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.
Show 13 quoted lines
>
>>   	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
> Why 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.
Show 6 quoted lines
>
> 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.
Good idea.  Will post a v4 shortly.
Previous: Fabian RuchNext: Junio C Hamano
Message 5 of 7 in “git-am: add option to extract email Message-Id: tag into commit log”
  1. git-am: add option to extract email Message-Id: tag into commit logAvi Kivity, Jul 2, 2014
  2. Torsten BögershausenJul 2, 2014
  3. Avi KivityJul 2, 2014
  4. Fabian RuchJul 2, 2014
  5. Avi KivityJul 2, 2014
  6. Junio C HamanoJul 2, 2014
  7. Avi KivityJul 3, 2014

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.