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:14 UTC
Message-ID
<Yz4BvCDIMWptDMKC@coredump.intra.peff.net>
In-Reply-To
<Yy6JxQz4ZxghQnG1.jacob@initialcommit.io>
On Fri, Sep 23, 2022 at 09:38:29PM -0700, Jacob Stopak wrote:
> Hmm I tried passing in --date=format:... to my patched shortlog command
> along with setting some date placeholder like "... %cd ..." in the code,
> but it's not picking up on the format. Do you know how the date format
> can be wedged into the format_commit_message(...) "format" argument?

It comes to the format code via the pretty_print_context. And we pick up the --date command via setup_revisions(), where it ends up in rev_info.date_mode.

In a normal git-log, I think that data gets shuffled across by show_log(). But shortlog has its own traversal.

I think something like this:
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7a1e1fe7c0..53c379a51d 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -211,7 +211,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 	ctx.fmt = CMIT_FMT_USERFORMAT;
 	ctx.abbrev = log->abbrev;
 	ctx.print_email_subject = 1;
-	ctx.date_mode.type = DATE_NORMAL;
+	ctx.date_mode = log->date_mode;
 	ctx.output_encoding = get_log_output_encoding();
 
 	if (!log->summary) {
@@ -407,6 +407,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 	log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
 	log.abbrev = rev.abbrev;
 	log.file = rev.diffopt.file;
+	log.date_mode = rev.date_mode;
 
 	if (!log.groups)
 		log.groups = SHORTLOG_GROUP_AUTHOR;
diff --git a/shortlog.h b/shortlog.h
index 3f7e9aabca..ef3a3dbc65 100644
--- a/shortlog.h
+++ b/shortlog.h
@@ -15,6 +15,7 @@ struct shortlog {
 	int in2;
 	int user_format;
 	int abbrev;
+	struct date_mode date_mode;
 
 	enum {
 		SHORTLOG_GROUP_AUTHOR = (1 << 0),

is enough. At least it allows:

  git shortlog --format='%ad %s' --date=format:%Y-%m

to work as you'd expect (but of course that's just the output for each
commit that we show, not the actual grouping).

> > Unfortunately there's no way to specify the format as part of the
> > placeholder. The for-each-ref formatter understands this, like:
> > 
> >   %(authordate:format:%Y-%m)
> >
> > I wouldn't be opposed to teaching the git-log formatter something
> > similar.
> 
> Oh that would solve my problem... Would it be a hefty effort to teach
> this to the git-log formatter?

Probably not a huge amount of work. But it puts us in a weird in-between
situation where we support _one_ of the more advanced ref-filter
placeholders, but not the others. And of course no code is shared.

That might be OK, as long as the syntax and semantics are identical to
what ref-filter can do. Then in the long run, if we eventually merge the
two implementations, there's no compatibility problem.

That said, I think it may just be easier to respect --date, as above.
It's not quite as flexible, but it's probably flexible enough.

-Peff
Previous: Jacob StopakNext: Taylor Blau
Message 9 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.