pretty: provide human date format
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>
ZheNing Hu committed
Apr 25, 2021 at 10:41 UTC
b722d4560e9d566cb8c6cdccf08d649df146eb6b
3 files changed
+13
Documentation/pretty-formats.txt
+4
@@ -190,6 +190,8 @@ The placeholders are:
190
'%ai':: author date, ISO 8601-like format
191
'%aI':: author date, strict ISO 8601 format
192
'%as':: author date, short format (`YYYY-MM-DD`)
193
+'%ah':: author date, human style (like the `--date=human` option of
194
+ linkgit:git-rev-list[1])
195
'%cn':: committer name
196
'%cN':: committer name (respecting .mailmap, see
197
linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -206,6 +208,8 @@ The placeholders are:
208
'%ci':: committer date, ISO 8601-like format
209
'%cI':: committer date, strict ISO 8601 format
210
'%cs':: committer date, short format (`YYYY-MM-DD`)
211
+'%ch':: committer date, human style(like the `--date=human` option of
212
+ linkgit:git-rev-list[1])
213
'%d':: ref names, like the --decorate option of linkgit:git-log[1]
214
'%D':: ref names without the " (", ")" wrapping.
215
'%(describe[:options])':: human-readable name, like
pretty.c
+3
@@ -745,6 +745,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
745
case 'I': /* date, ISO 8601 strict */
746
strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT)));
747
return placeholder_len;
748
+ case 'h': /* date, human */
749
+ strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(HUMAN)));
750
+ return placeholder_len;
751
case 's':
752
strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT)));
753
return placeholder_len;
t/t4205-log-pretty-formats.sh
+6
@@ -538,6 +538,12 @@ test_expect_success '--date=short %ad%cd is the same as %as%cs' '
538
test_cmp expected actual
539
'
540
541
+test_expect_success '--date=human %ad%cd is the same as %ah%ch' '
542
+ git log --format=%ad%n%cd --date=human >expected &&
543
+ git log --format=%ah%n%ch >actual &&
544
+ test_cmp expected actual
545
+'
546
+
547
# get new digests (with no abbreviations)
548
test_expect_success 'set up log decoration tests' '
549
head1=$(git rev-parse --verify HEAD~0) &&