]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shortlog: accept `--date`-related options
authorJeff King <peff@peff.net>
Mon, 24 Oct 2022 18:55:30 +0000 (14:55 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Oct 2022 21:48:05 +0000 (14:48 -0700)
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>
Documentation/git-shortlog.txt
builtin/shortlog.c
shortlog.h
t/t4201-shortlog.sh

index f64e77047b2f86f1645671fc46e9487f788c117a..9ed9d6a9e7d6745ed33cc4006d541699f237fe10 100644 (file)
@@ -47,6 +47,11 @@ OPTIONS
 
        Each pretty-printed commit will be rewrapped before it is shown.
 
+--date=<format>::
+       Show dates formatted according to the given date string. (See
+       the `--date` option 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:
index 7a1e1fe7c0ed6d97789c352d37e4870d6f2e2b04..53c379a51d0bd103428afe643a3780fdea8e0de5 100644 (file)
@@ -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 @@ parse_done:
        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;
index 3f7e9aabcaef4b1ff2e5a5122cbea8bc97a6b7d5..dc388dd459749392a70a9be8138d1d4c2f1b667e 100644 (file)
@@ -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),
index 3095b1b2ffee6047abb54d5fad4d6f1e6b07feaf..7547da539dbb641fca0a8ec67449db938a809573 100755 (executable)
@@ -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 &&