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

Re: [PATCH v2 1/6] shortlog: accept `--date`-related options

From
Jeff King <peff@peff.net>
Date
Oct 21, 2022, 05:32 UTC
Message-ID
<Y1Iu1x6dR6GwiA2Y@coredump.intra.peff.net>
In-Reply-To
<58baccbaa8612adae55f776ce10806809861270c.1666320509.git.me@ttaylorr.com>
On Thu, Oct 20, 2022 at 11:11:29PM -0400, Taylor Blau wrote:
Show 12 quoted lines
> diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt
> index f64e77047b..311c041c06 100644
> --- a/Documentation/git-shortlog.txt
> +++ b/Documentation/git-shortlog.txt
> @@ -47,6 +47,11 @@ OPTIONS
>  
>  	Each pretty-printed commit will be rewrapped before it is shown.
>  
> +--date=<format>::
> +	With a `--group=format:<format>`, show dates formatted
> +	according to the given date string. (See the `--date` options
> +	in the "COMMIT FORMATTING" section of linkgit:git-log[1].)

I like this much better than including the whole date-formats section. Two nits:

  - s/options/option/ ? I guess you could say there are "options" for
    formatting the date, but with "--date" it seems like you'd mean the
    singular option.
  - Because "Commit Formatting" is a subsection in git-log(1), the
    manual will format it with title caps, not all-caps.
Show 13 quoted lines
> 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) {

After the discussion in the last round of whether that funky caller in make_cover_letter() properly initialized the "struct shortlog", I wondered briefly if this would do the right thing for that caller. And it does, because DATE_NORMAL is intentionally set to "0" to allow for zero-initializing (which is what shortlog_init does).

Not that it matters in practice, because that caller will not group by nor format using a date, but I was curious if I had inadvertently introduced a gotcha for future callers. But it is good.

Show 14 quoted lines
> diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
> index 3095b1b2ff..7547da539d 100755
> --- a/t/t4201-shortlog.sh
> +++ b/t/t4201-shortlog.sh
> @@ -83,6 +83,13 @@ test_expect_success 'pretty format' '
>  	test_cmp expect log.predictable
>  '
>  
> +test_expect_success 'pretty format (with --date)' '
> +	sed "s/SUBJECT/2005-04-07 OBJECT_NAME/" expect.template >expect &&
> +	git shortlog --format="%ad %H" --date=short HEAD >log &&
> +	fuzz log >log.predictable &&
> +	test_cmp expect log.predictable
> +'

And this looks sensible. If you dropped "%H" then you wouldn't need to fuzz, and are still testing the interesting part. But just following the whole template/fuzz thing of the surrounding tests is reasonable.

-Peff
Previous: Taylor BlauNext: Taylor Blau
Message 38 of 72 in “shortlog: introduce `--group=<format>`”
  1. 0/7 shortlog: introduce `--group=<format>`Taylor Blau, Oct 11, 2022
  2. 1/7 Documentation: extract date-options.txtTaylor Blau, Oct 11, 2022
  3. Jeff KingOct 11, 2022
  4. Taylor BlauOct 11, 2022
  5. 2/7 shortlog: accept `--date`-related optionsTaylor Blau, Oct 11, 2022
  6. Jeff KingOct 11, 2022
  7. Taylor BlauOct 11, 2022
  8. 3/7 shortlog: extract `--group` fragment for translationTaylor Blau, Oct 11, 2022
  9. Ævar Arnfjörð BjarmasonOct 11, 2022
  10. Jeff KingOct 11, 2022
  11. 4/7 shortlog: support arbitrary commit format `--group`sTaylor Blau, Oct 11, 2022
  12. Jeff KingOct 11, 2022
  13. Taylor BlauOct 11, 2022
  14. Taylor BlauOct 11, 2022
  15. Jeff KingOct 11, 2022
  16. Jeff KingOct 11, 2022
  17. Taylor BlauOct 21, 2022
  18. Jeff KingOct 21, 2022
  19. Taylor BlauOct 21, 2022
  20. 5/7 shortlog: implement `--group=author` in terms of `--group=<format>`Taylor Blau, Oct 11, 2022
  21. Jeff KingOct 11, 2022
  22. Taylor BlauOct 11, 2022
  23. Jeff KingOct 11, 2022
  24. Taylor BlauOct 21, 2022
  25. Taylor BlauOct 21, 2022
  26. Jeff KingOct 21, 2022
  27. Taylor BlauOct 21, 2022
  28. Ævar Arnfjörð BjarmasonOct 11, 2022
  29. Ævar Arnfjörð BjarmasonOct 11, 2022
  30. 7/7 shortlog: implement `--group=trailer` in terms of `--group=<format>`Taylor Blau, Oct 11, 2022
  31. Jeff KingOct 11, 2022
  32. Jeff KingOct 11, 2022
  33. Taylor BlauOct 21, 2022
  34. 6/7 shortlog: implement `--group=committer` in terms of `--group=<format>`Taylor Blau, Oct 11, 2022
  35. Jeff KingOct 11, 2022
  36. 0/6 shortlog: introduce `--group=<format>`Taylor Blau, Oct 21, 2022
  37. 1/6 shortlog: accept `--date`-related optionsTaylor Blau, Oct 21, 2022
  38. Jeff KingOct 21, 2022
  39. Taylor BlauOct 21, 2022
  40. 2/6 shortlog: make trailer insertion a noop when appropriateTaylor Blau, Oct 21, 2022
  41. Jeff KingOct 21, 2022
  42. Taylor BlauOct 21, 2022
  43. 3/6 shortlog: extract `--group` fragment for translationTaylor Blau, Oct 21, 2022
  44. Jeff KingOct 21, 2022
  45. 4/6 shortlog: support arbitrary commit format `--group`sTaylor Blau, Oct 21, 2022
  46. Jeff KingOct 21, 2022
  47. Taylor BlauOct 21, 2022
  48. 5/6 shortlog: implement `--group=author` in terms of `--group=<format>`Taylor Blau, Oct 21, 2022
  49. Jeff KingOct 21, 2022
  50. 6/6 shortlog: implement `--group=committer` in terms of `--group=<format>`Taylor Blau, Oct 21, 2022
  51. Jeff KingOct 21, 2022
  52. Jeff KingOct 21, 2022
  53. 0/7 shortlog: introduce `--group=<format>`Taylor Blau, Oct 21, 2022
  54. 1/7 shortlog: accept `--date`-related optionsTaylor Blau, Oct 21, 2022
  55. 2/7 shortlog: make trailer insertion a noop when appropriateTaylor Blau, Oct 21, 2022
  56. 4/7 shortlog: support arbitrary commit format `--group`sTaylor Blau, Oct 21, 2022
  57. Jeff KingOct 22, 2022
  58. 5/7 shortlog: extract `shortlog_finish_setup()`Taylor Blau, Oct 21, 2022
  59. 6/7 shortlog: implement `--group=author` in terms of `--group=<format>`Taylor Blau, Oct 21, 2022
  60. 3/7 shortlog: extract `--group` fragment for translationTaylor Blau, Oct 21, 2022
  61. 7/7 shortlog: implement `--group=committer` in terms of `--group=<format>`Taylor Blau, Oct 21, 2022
  62. Jeff KingOct 22, 2022
  63. 0/7 shortlog: introduce `--group=<format>`Taylor Blau, Oct 24, 2022
  64. 7/7 shortlog: implement `--group=committer` in terms of `--group=<format>`Taylor Blau, Oct 24, 2022
  65. 5/7 shortlog: extract `shortlog_finish_setup()`Taylor Blau, Oct 24, 2022
  66. 4/7 shortlog: support arbitrary commit format `--group`sTaylor Blau, Oct 24, 2022
  67. 3/7 shortlog: extract `--group` fragment for translationTaylor Blau, Oct 24, 2022
  68. 1/7 shortlog: accept `--date`-related optionsTaylor Blau, Oct 24, 2022
  69. 6/7 shortlog: implement `--group=author` in terms of `--group=<format>`Taylor Blau, Oct 24, 2022
  70. 2/7 shortlog: make trailer insertion a noop when appropriateTaylor Blau, Oct 24, 2022
  71. Junio C HamanoOct 24, 2022
  72. Jeff KingOct 24, 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.