pretty: provide short date format
Add the placeholders %as and %cs to format author date and committer date, respectively, without the time part, like --date=short does, i.e. like YYYY-MM-DD. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Nov 19, 2019 at 16:51 UTC
0df621172d830adf36d4226b98f9cf4006d183a6
3 files changed
+11
Documentation/pretty-formats.txt
+2
@@ -169,6 +169,7 @@ The placeholders are:
169
'%at':: author date, UNIX timestamp
170
'%ai':: author date, ISO 8601-like format
171
'%aI':: author date, strict ISO 8601 format
172
+'%as':: author date, short format (`YYYY-MM-DD`)
173
'%cn':: committer name
174
'%cN':: committer name (respecting .mailmap, see
175
linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -181,6 +182,7 @@ The placeholders are:
182
'%ct':: committer date, UNIX timestamp
183
'%ci':: committer date, ISO 8601-like format
184
'%cI':: committer date, strict ISO 8601 format
185
+'%cs':: committer date, short format (`YYYY-MM-DD`)
186
'%d':: ref names, like the --decorate option of linkgit:git-log[1]
187
'%D':: ref names without the " (", ")" wrapping.
188
'%S':: ref name given on the command line by which the commit was reached
pretty.c
+3
@@ -731,6 +731,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
731
case 'I': /* date, ISO 8601 strict */
732
strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT)));
733
return placeholder_len;
734
+ case 's':
735
+ strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT)));
736
+ return placeholder_len;
737
}
738
739
skip:
t/t4205-log-pretty-formats.sh
+6
@@ -533,6 +533,12 @@ test_expect_success 'ISO and ISO-strict date formats display the same values' '
533
test_cmp expected actual
534
'
535
536
+test_expect_success 'short date' '
537
+ git log --format=%ad%n%cd --date=short >expected &&
538
+ git log --format=%as%n%cs >actual &&
539
+ test_cmp expected actual
540
+'
541
+
542
# get new digests (with no abbreviations)
543
test_expect_success 'set up log decoration tests' '
544
head1=$(git rev-parse --verify HEAD~0) &&