Skip to content

Commit 0df6211

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac52d94 commit 0df6211

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Documentation/pretty-formats.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ The placeholders are:
169169
'%at':: author date, UNIX timestamp
170170
'%ai':: author date, ISO 8601-like format
171171
'%aI':: author date, strict ISO 8601 format
172+
'%as':: author date, short format (`YYYY-MM-DD`)
172173
'%cn':: committer name
173174
'%cN':: committer name (respecting .mailmap, see
174175
linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -181,6 +182,7 @@ The placeholders are:
181182
'%ct':: committer date, UNIX timestamp
182183
'%ci':: committer date, ISO 8601-like format
183184
'%cI':: committer date, strict ISO 8601 format
185+
'%cs':: committer date, short format (`YYYY-MM-DD`)
184186
'%d':: ref names, like the --decorate option of linkgit:git-log[1]
185187
'%D':: ref names without the " (", ")" wrapping.
186188
'%S':: ref name given on the command line by which the commit was reached

pretty.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
731731
case 'I': /* date, ISO 8601 strict */
732732
strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT)));
733733
return placeholder_len;
734+
case 's':
735+
strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT)));
736+
return placeholder_len;
734737
}
735738

736739
skip:

t/t4205-log-pretty-formats.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ test_expect_success 'ISO and ISO-strict date formats display the same values' '
533533
test_cmp expected actual
534534
'
535535

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+
536542
# get new digests (with no abbreviations)
537543
test_expect_success 'set up log decoration tests' '
538544
head1=$(git rev-parse --verify HEAD~0) &&

0 commit comments

Comments
 (0)