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

Re: [RFC PATCH v2] shortlog: add group-by options for year and month

From
Jeff King <peff@peff.net>
Date
Oct 5, 2022, 22:26 UTC
Message-ID
<Yz4EsT8noIoygk9b@coredump.intra.peff.net>
In-Reply-To
<Yz36eFeGyQ3ha1pw@nand.local>
On Wed, Oct 05, 2022 at 05:43:20PM -0400, Taylor Blau wrote:
Show 9 quoted lines
> > Heh, I was about to make the exact same suggestion. The existing
> > "--group=author" could really just be "--group='%an <%ae>'" (or variants
> > depending on the "-e" flag).
> 
> This caught my attention, so I wanted to see how hard it would be to
> implement. It actually is quite straightforward, and gets us most of the
> way to being able to get the same functionality as in Jacob's patch
> (minus being able to do the for-each-ref-style sub-selectors, like
> `%(authordate:format=%Y-%m)`).
Yeah, your patch is about what I'd expect.

The date thing I think can be done with --date; I just sent a sketch in another part of the thread.

Show 16 quoted lines
> +static void insert_record_from_pretty(struct shortlog *log,
> +				      struct strset *dups,
> +				      struct commit *commit,
> +				      struct pretty_print_context *ctx,
> +				      const char *oneline)
> +{
> +	struct strbuf ident = STRBUF_INIT;
> +	size_t i;
> +
> +	for (i = 0; i < log->pretty.nr; i++) {
> +		if (i)
> +			strbuf_addch(&ident, ' ');
> +
> +		format_commit_message(commit, log->pretty.items[i].string,
> +				      &ident, ctx);
> +	}

So here you're allowing multiple pretty options. But really, once we allow the user an arbitrary format, is there any reason for them to do:

  git shortlog --group=%an --group=%ad
versus just:
  git shortlog --group='%an %ad'
?
Show 9 quoted lines
>  void shortlog_add_commit(struct shortlog *log, struct commit *commit)
>  {
>  	struct strbuf ident = STRBUF_INIT;
> @@ -243,6 +266,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
>  	if (log->groups & SHORTLOG_GROUP_TRAILER) {
>  		insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str);
>  	}
> +	if (log->groups & SHORTLOG_GROUP_PRETTY)
> +		insert_record_from_pretty(log, &dups, commit, &ctx, oneline_str);

I was puzzled at first that this was a bitwise check. But I forgot that we added support for --group options already, in 63d24fa0b0 (shortlog: allow multiple groups to be specified, 2020-09-27).

So a plan like:
  git shortlog --group=author --group=date

(as in the original patch in this thread) doesn't quite work, I think. Because the semantics for multiple --group lines are that the commit is credited individually to each ident. That's what lets you do:

  git shortlog -ns --group=author --group=trailer:co-authored-by

and credit authors and co-authors equally. So likewise, I think multiple group-format options don't really make sense (or at least, do not make sense to concatenate; you'd put each key in its own single format).

Show 10 quoted lines
> @@ -321,8 +346,10 @@ static int parse_group_option(const struct option *opt, const char *arg, int uns
>  	else if (skip_prefix(arg, "trailer:", &field)) {
>  		log->groups |= SHORTLOG_GROUP_TRAILER;
>  		string_list_append(&log->trailers, field);
> -	} else
> -		return error(_("unknown group type: %s"), arg);
> +	} else {
> +		log->groups |= SHORTLOG_GROUP_PRETTY;
> +		string_list_append(&log->pretty, arg);
> +	}

We probably want to insist that the format contains a "%" sign, and/or git it a keyword like "format:". Otherwise a typo like:

  git shortlog --format=autor

stops being an error we detect, and just returns nonsense results (every commit has the same ident).

I think you'd want to detect SHORTLOG_GROUP_PRETTY in the read_from_stdin() path, too. And probably just die() with "not supported", like we do for trailers.

> I think you could also do some cleanup on top, like replacing the
> SHORTLOG_GROUP_AUTHOR mode with adding either "%aN <%aE>" (or "%aN",
> without --email) as an entry in the `pretty` string_list.

Yeah, that would be a nice cleanup. I think might even be a good idea to explain the various options to the users in terms of "--author is equivalent to %aN <%aE>". It may help them understand how the tool works.

-Peff
Previous: Taylor BlauNext: Jacob Stopak
Message 11 of 16 in “shortlog: add group-by options for year and month”
  1. shortlog: add group-by options for year and monthJacob Stopak, Sep 22, 2022
  2. Martin ÅgrenSep 22, 2022
  3. shortlog: add group-by options for year and monthJacob Stopak, Sep 22, 2022
  4. Junio C HamanoSep 23, 2022
  5. Jacob StopakSep 23, 2022
  6. Jeff KingSep 23, 2022
  7. Junio C HamanoSep 23, 2022
  8. Jacob StopakSep 24, 2022
  9. Jeff KingOct 5, 2022
  10. Taylor BlauOct 5, 2022
  11. Jeff KingOct 5, 2022
  12. Jacob StopakOct 7, 2022
  13. Taylor BlauOct 7, 2022
  14. Jeff KingOct 11, 2022
  15. Taylor BlauOct 7, 2022
  16. Jeff KingOct 11, 2022

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.