]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty: provide human date format
authorZheNing Hu <adlternative@gmail.com>
Sun, 25 Apr 2021 10:41:45 +0000 (10:41 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Apr 2021 07:09:32 +0000 (16:09 +0900)
Add the placeholders %ah and %ch to format author date and committer
date, like --date=human does, which provides more humanity date output.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/pretty-formats.txt
pretty.c
t/t4205-log-pretty-formats.sh

index 45133066e412201020a37eaae275857acb412204..cd697f508c53711d2f758a798e5300f7fc6d0f6d 100644 (file)
@@ -190,6 +190,8 @@ The placeholders are:
 '%ai':: author date, ISO 8601-like format
 '%aI':: author date, strict ISO 8601 format
 '%as':: author date, short format (`YYYY-MM-DD`)
+'%ah':: author date, human style (like the `--date=human` option of
+       linkgit:git-rev-list[1])
 '%cn':: committer name
 '%cN':: committer name (respecting .mailmap, see
        linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -206,6 +208,8 @@ The placeholders are:
 '%ci':: committer date, ISO 8601-like format
 '%cI':: committer date, strict ISO 8601 format
 '%cs':: committer date, short format (`YYYY-MM-DD`)
+'%ch':: committer date, human style(like the `--date=human` option of
+       linkgit:git-rev-list[1])
 '%d':: ref names, like the --decorate option of linkgit:git-log[1]
 '%D':: ref names without the " (", ")" wrapping.
 '%(describe[:options])':: human-readable name, like
index e5b33ba034bd600b343ea146b0c38f992d1b462e..b1ecd039cef29ecc77edd894c500dfadf49058c8 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -745,6 +745,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 'h':       /* date, human */
+               strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(HUMAN)));
+               return placeholder_len;
        case 's':
                strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT)));
                return placeholder_len;
index bcb558ef4d77910b6ca3f404868da4fd59d29526..8272d94ce6b464f7b5a7e3bba8c58037af5a2f16 100755 (executable)
@@ -538,6 +538,12 @@ test_expect_success '--date=short %ad%cd is the same as %as%cs' '
        test_cmp expected actual
 '
 
+test_expect_success '--date=human %ad%cd is the same as %ah%ch' '
+       git log --format=%ad%n%cd --date=human >expected &&
+       git log --format=%ah%n%ch >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) &&