git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] [GSOC] pretty: provide human date format

From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 25, 2021, 10:41 UTC
Message-ID
<pull.939.v3.git.1619347306291.gitgitgadget@gmail.com>
In-Reply-To
<pull.939.v2.git.1619275340051.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>

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>
---
    [GSOC] pretty: provide human date format
    
    Reasons for making this patch: --date=human has no corresponding
    --pretty option.
    
    Although --date=human with --pretty="%(a|c)d" can achieve the same
    effect with --pretty="%(a|c)h", but it can be noticed that most time
    formats implement the corresponding option of --pretty, such as
    --date=iso8601 can be replaced by --pretty=%(a|c)i, so add
    --pretty=%(a|c)h seems to be a very reasonable thing.
    
    Change from v2: change %(a|c)h link to git-rev-list and change to more
    suitable test title.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/939
Range-diff vs v2:
 1:  1517708876b5 ! 1:  67c57d8f4a17 [GSOC] pretty: provide human date format
     @@ Documentation/pretty-formats.txt: 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:rev-list-options.txt[1])
     ++'%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])
     @@ Documentation/pretty-formats.txt: 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:rev-list-options.txt[1])
     ++'%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
     @@ t/t4205-log-pretty-formats.sh: test_expect_success 'short date' '
       	test_cmp expected actual
       '
       
     -+test_expect_success 'human date' '
     ++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
 Documentation/pretty-formats.txt | 4 ++++
 pretty.c                         | 3 +++
 t/t4205-log-pretty-formats.sh    | 6 ++++++
 3 files changed, 13 insertions(+)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 45133066e412..cd697f508c53 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -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
diff --git a/pretty.c b/pretty.c
index e5b33ba034bd..b1ecd039cef2 100644
--- 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;
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index cabdf7d57a00..10d511ba7307 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -539,6 +539,12 @@ test_expect_success 'short date' '
 	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) &&

base-commit: b0c09ab8796fb736efa432b8e817334f3e5ee75a
-- 
gitgitgadget
Previous: ZheNing HuNext: ZheNing Hu via GitGitGadget
Message 14 of 15 in “[GSOC] pretty: provide human date format”
  1. [GSOC] pretty: provide human date formatZheNing Hu via GitGitGadget, Apr 23, 2021
  2. Taylor BlauApr 23, 2021
  3. ZheNing HuApr 24, 2021
  4. Philip OakleyApr 23, 2021
  5. ZheNing HuApr 24, 2021
  6. [GSOC] pretty: provide human date formatZheNing Hu via GitGitGadget, Apr 24, 2021
  7. Philip OakleyApr 24, 2021
  8. 0/2 pretty tests: --date/format test improvementsÆvar Arnfjörð Bjarmason, Apr 25, 2021
  9. 1/2 pretty tests: simplify %aI/%cI date format testÆvar Arnfjörð Bjarmason, Apr 25, 2021
  10. Beat BolliApr 26, 2021
  11. Junio C HamanoApr 27, 2021
  12. 2/2 pretty tests: give --date/format tests a better descriptionÆvar Arnfjörð Bjarmason, Apr 25, 2021
  13. ZheNing HuApr 25, 2021
  14. [GSOC] pretty: provide human date formatZheNing Hu via GitGitGadget, Apr 25, 2021
  15. [GSOC] pretty: provide human date formatZheNing Hu via GitGitGadget, May 3, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.