]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty: provide short date format
authorRené Scharfe <l.s.r@web.de>
Wed, 20 Nov 2019 00:51:21 +0000 (16:51 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Nov 2019 04:33:36 +0000 (13:33 +0900)
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>
Documentation/pretty-formats.txt
pretty.c
t/t4205-log-pretty-formats.sh

index fdccfe5b039f9fb1f5ecce218f44e1cb42516b7e..34bbc39273d516627f460a0be66757c92e0d2ace 100644 (file)
@@ -169,6 +169,7 @@ The placeholders are:
 '%at':: author date, UNIX timestamp
 '%ai':: author date, ISO 8601-like format
 '%aI':: author date, strict ISO 8601 format
+'%as':: author date, short format (`YYYY-MM-DD`)
 '%cn':: committer name
 '%cN':: committer name (respecting .mailmap, see
        linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -181,6 +182,7 @@ The placeholders are:
 '%ct':: committer date, UNIX timestamp
 '%ci':: committer date, ISO 8601-like format
 '%cI':: committer date, strict ISO 8601 format
+'%cs':: committer date, short format (`YYYY-MM-DD`)
 '%d':: ref names, like the --decorate option of linkgit:git-log[1]
 '%D':: ref names without the " (", ")" wrapping.
 '%S':: ref name given on the command line by which the commit was reached
index da154affd4c6d48dcc0a00fb20a1616e2b094edd..61014cc25ac7eeff23fdae5c20de347e59be3fff 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -731,6 +731,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
        case 'I':       /* date, ISO 8601 strict */
                strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT)));
                return placeholder_len;
+       case 's':
+               strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT)));
+               return placeholder_len;
        }
 
 skip:
index 0335b428b1df345cb3a61c400bd8280f392fba8f..da9cacffea1c7806cdb51b3cd4dbd97ba0346336 100755 (executable)
@@ -533,6 +533,12 @@ test_expect_success 'ISO and ISO-strict date formats display the same values' '
        test_cmp expected actual
 '
 
+test_expect_success 'short date' '
+       git log --format=%ad%n%cd --date=short >expected &&
+       git log --format=%as%n%cs >actual &&
+       test_cmp expected actual
+'
+
 # get new digests (with no abbreviations)
 test_expect_success 'set up log decoration tests' '
        head1=$(git rev-parse --verify HEAD~0) &&