Subject: Re: [PATCH v2 7/8] shortlog: parse trailer idents

From: Junio C Hamano <[email-masked]>
Date: Sun, 27 Sep 2020 13:49:56 -0700

Jeff King <[email-masked]> writes:

> +Shortlog will attempt to parse each trailer value as a `name <email>`
> +identity. If successful, the mailmap is applied and the email is omitted
> +unless the `--email` option is specified. If the value cannot be parsed
> +as an identity, it will be taken literally and completely.

Makes sense.

> diff --git a/builtin/shortlog.c b/builtin/shortlog.c
> index e6f4faec7c..28133aec68 100644
> --- a/builtin/shortlog.c
> +++ b/builtin/shortlog.c
> @@ -228,6 +228,7 @@ static void insert_records_from_trailers(struct shortlog *log,
>  	struct trailer_iterator iter;
>  	const char *commit_buffer, *body;
>  	struct strset dups = STRSET_INIT;
> +	struct strbuf ident = STRBUF_INIT;
>  
>  	/*
>  	 * Using format_commit_message("%B") would be simpler here, but
> @@ -245,12 +246,17 @@ static void insert_records_from_trailers(struct shortlog *log,
>  		if (strcasecmp(iter.key.buf, log->trailer))
>  			continue;
>  
> +		strbuf_reset(&ident);
> +		if (!parse_ident(log, &ident, value))
> +			value = ident.buf;

And the implementation is quite straight-forward.

>  		if (strset_check_and_add(&dups, value))
>  			continue;
>  		insert_one_record(log, value, oneline);
>  	}
>  	trailer_iterator_release(&iter);
>  
> +	strbuf_release(&ident);
>  	strset_clear(&dups);
>  	unuse_commit_buffer(commit, commit_buffer);
>  }

Looking good.  Thanks.