Skip to content

Commit 251554c

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45c9f05 commit 251554c

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Documentation/git-shortlog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ OPTIONS
4747

4848
Each pretty-printed commit will be rewrapped before it is shown.
4949

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+
5055
--group=<type>::
5156
Group commits based on `<type>`. If no `--group` option is
5257
specified, the default is `author`. `<type>` is one of:

builtin/shortlog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
211211
ctx.fmt = CMIT_FMT_USERFORMAT;
212212
ctx.abbrev = log->abbrev;
213213
ctx.print_email_subject = 1;
214-
ctx.date_mode.type = DATE_NORMAL;
214+
ctx.date_mode = log->date_mode;
215215
ctx.output_encoding = get_log_output_encoding();
216216

217217
if (!log->summary) {
@@ -407,6 +407,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
407407
log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
408408
log.abbrev = rev.abbrev;
409409
log.file = rev.diffopt.file;
410+
log.date_mode = rev.date_mode;
410411

411412
if (!log.groups)
412413
log.groups = SHORTLOG_GROUP_AUTHOR;

shortlog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define SHORTLOG_H
33

44
#include "string-list.h"
5+
#include "date.h"
56

67
struct commit;
78

@@ -15,6 +16,7 @@ struct shortlog {
1516
int in2;
1617
int user_format;
1718
int abbrev;
19+
struct date_mode date_mode;
1820

1921
enum {
2022
SHORTLOG_GROUP_AUTHOR = (1 << 0),

t/t4201-shortlog.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ test_expect_success 'pretty format' '
8383
test_cmp expect log.predictable
8484
'
8585

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+
8693
test_expect_success '--abbrev' '
8794
sed s/SUBJECT/OBJID/ expect.template >expect &&
8895
git shortlog --format="%h" --abbrev=35 HEAD >log &&

0 commit comments

Comments
 (0)