shortlog: accept `--date`-related options

Prepare for a future patch which will introduce arbitrary pretty formats via the `--group` argument. To allow additional customizability (for example, to support something like `git shortlog -s --group='%aD' --date='format:%Y-%m' ...` (which groups commits by the datestring 'YYYY-mm' according to author date), we must store off the `--date` parsed from calling `parse_revision_opt()`. Note that this also affects custom output `--format` strings in `git shortlog`. Though this is a behavior change, this is arguably fixing a long-standing bug (ie., that `--format` strings are not affected by `--date` specifiers as they should be). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 24, 2022 at 14:55 UTC 251554c26931bec94e86d0e5740084d6116dd263
4 files changed +16 -1
Documentation/git-shortlog.txt
+5
@@ -47,6 +47,11 @@ OPTIONS
47
48 Each pretty-printed commit will be rewrapped before it is shown.
49
50 +--date=<format>::
51 + Show dates formatted according to the given date string. (See
52 + the `--date` option in the "Commit Formatting" section of
53 + linkgit:git-log[1]).
54 +
55 --group=<type>::
56 Group commits based on `<type>`. If no `--group` option is
57 specified, the default is `author`. `<type>` is one of:
builtin/shortlog.c
+2 -1
@@ -211,7 +211,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
211 ctx.fmt = CMIT_FMT_USERFORMAT;
212 ctx.abbrev = log->abbrev;
213 ctx.print_email_subject = 1;
214 - ctx.date_mode.type = DATE_NORMAL;
214 + ctx.date_mode = log->date_mode;
215 ctx.output_encoding = get_log_output_encoding();
216
217 if (!log->summary) {
@@ -407,6 +407,7 @@ parse_done:
407 log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
408 log.abbrev = rev.abbrev;
409 log.file = rev.diffopt.file;
410 + log.date_mode = rev.date_mode;
411
412 if (!log.groups)
413 log.groups = SHORTLOG_GROUP_AUTHOR;
shortlog.h
+2
@@ -2,6 +2,7 @@
2 #define SHORTLOG_H
3
4 #include "string-list.h"
5 +#include "date.h"
6
7 struct commit;
8
@@ -15,6 +16,7 @@ struct shortlog {
16 int in2;
17 int user_format;
18 int abbrev;
19 + struct date_mode date_mode;
20
21 enum {
22 SHORTLOG_GROUP_AUTHOR = (1 << 0),
t/t4201-shortlog.sh
+7
@@ -83,6 +83,13 @@ test_expect_success 'pretty format' '
83 test_cmp expect log.predictable
84 '
85
86 +test_expect_success 'pretty format (with --date)' '
87 + sed "s/SUBJECT/2005-04-07 OBJECT_NAME/" expect.template >expect &&
88 + git shortlog --format="%ad %H" --date=short HEAD >log &&
89 + fuzz log >log.predictable &&
90 + test_cmp expect log.predictable
91 +'
92 +
93 test_expect_success '--abbrev' '
94 sed s/SUBJECT/OBJID/ expect.template >expect &&
95 git shortlog --format="%h" --abbrev=35 HEAD >log &&