Message ID | 58baccbaa8612adae55f776ce10806809861270c.1666320509.git.me@ttaylorr.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | shortlog: introduce `--group=<format>` | expand |
On Thu, Oct 20, 2022 at 11:11:29PM -0400, Taylor Blau wrote: > 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. > 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. > 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
On Fri, Oct 21, 2022 at 01:32:07AM -0400, Jeff King wrote: > On Thu, Oct 20, 2022 at 11:11:29PM -0400, Taylor Blau wrote: > > > 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: Thanks, both make sense. Thanks, Taylor
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].) + --group=<type>:: Group commits based on `<type>`. If no `--group` option is specified, the default is `author`. `<type>` is one of: 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..dc388dd459 100644 --- a/shortlog.h +++ b/shortlog.h @@ -2,6 +2,7 @@ #define SHORTLOG_H #include "string-list.h" +#include "date.h" struct commit; @@ -15,6 +16,7 @@ struct shortlog { int in2; int user_format; int abbrev; + struct date_mode date_mode; enum { SHORTLOG_GROUP_AUTHOR = (1 << 0), 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 +' + test_expect_success '--abbrev' ' sed s/SUBJECT/OBJID/ expect.template >expect && git shortlog --format="%h" --abbrev=35 HEAD >log &&