diff mbox series

[GSOC] pretty: provide human date format

Message ID pull.939.git.1619195245606.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series [GSOC] pretty: provide human date format | expand

Commit Message

ZheNing Hu April 23, 2021, 4:27 p.m. UTC
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.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/939

 Documentation/pretty-formats.txt | 2 ++
 pretty.c                         | 3 +++
 t/t4205-log-pretty-formats.sh    | 6 ++++++
 3 files changed, 11 insertions(+)


base-commit: b0c09ab8796fb736efa432b8e817334f3e5ee75a

Comments

Taylor Blau April 23, 2021, 8:21 p.m. UTC | #1
Hi ZheNing,

On Fri, Apr 23, 2021 at 04:27:25PM +0000, ZheNing Hu via GitGitGadget wrote:
> 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.

I don't see a reason why this shouldn't exist, and the patch that you
wrote below looks pretty good to me.

To refresh my memory on if you had missed any spots, I followed
0df621172d (pretty: provide short date format, 2019-11-19) as an
example. You did a fine job here, and I don't think this patch is
missing anything.

> 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.

Just to make sure I understand what you wrote: you're saying that the
pretty formats "%ah" and "%ch" that you propose here could be achieved
with --date=human and --pretty="%ad". Makes sense, but I agree that your
point about --date=iso8601 having a built-in pretty atom makes the case
for having "%ah" and "%ch".

> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/939
>
>  Documentation/pretty-formats.txt | 2 ++
>  pretty.c                         | 3 +++
>  t/t4205-log-pretty-formats.sh    | 6 ++++++
>  3 files changed, 11 insertions(+)
>
> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> index 45133066e412..9cdcdb8bb414 100644
> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -190,6 +190,7 @@ 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

There's no sorting here, so this place (at the bottom of the author-date
placeholders) seems just as good as any.

>  '%cn':: committer name
>  '%cN':: committer name (respecting .mailmap, see
>  	linkgit:git-shortlog[1] or linkgit:git-blame[1])
> @@ -206,6 +207,7 @@ 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

Likewise. The rest all looks good to me, too.

  Reviewed-by: Taylor Blau <me@ttaylorr.com>

Thanks,
Taylor
Philip Oakley April 23, 2021, 9:10 p.m. UTC | #2
On 23/04/2021 17:27, ZheNing Hu via GitGitGadget wrote:
> 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.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/939
>
>  Documentation/pretty-formats.txt | 2 ++
>  pretty.c                         | 3 +++
>  t/t4205-log-pretty-formats.sh    | 6 ++++++
>  3 files changed, 11 insertions(+)
>
> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> index 45133066e412..9cdcdb8bb414 100644
> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -190,6 +190,7 @@ 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

An example may be useful. There's no other mention of human date style
in the pretty-formats doc. Or a link to the definitive man page.

>  '%cn':: committer name
>  '%cN':: committer name (respecting .mailmap, see
>  	linkgit:git-shortlog[1] or linkgit:git-blame[1])
> @@ -206,6 +207,7 @@ 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
Likewise, an `(e.g. ????)` to unconfuse readers.
>  '%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..d4d75b0b350e 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 'human date' '
> +	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
--
Philip
ZheNing Hu April 24, 2021, 1:26 p.m. UTC | #3
Taylor Blau <me@ttaylorr.com> 于2021年4月24日周六 上午4:21写道:
>
> Hi ZheNing,
>
> On Fri, Apr 23, 2021 at 04:27:25PM +0000, ZheNing Hu via GitGitGadget wrote:
> > 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.
>
> I don't see a reason why this shouldn't exist, and the patch that you
> wrote below looks pretty good to me.
>
> To refresh my memory on if you had missed any spots, I followed
> 0df621172d (pretty: provide short date format, 2019-11-19) as an
> example. You did a fine job here, and I don't think this patch is
> missing anything.
>

Yes, I saw René Scharfe's (have --cc) patch and learned handle way from it.

> > 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.
>
> Just to make sure I understand what you wrote: you're saying that the
> pretty formats "%ah" and "%ch" that you propose here could be achieved
> with --date=human and --pretty="%ad". Makes sense, but I agree that your
> point about --date=iso8601 having a built-in pretty atom makes the case
> for having "%ah" and "%ch".
>

Yes, I tried to explain that "%(a|c)h" makes sense.

> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v1
> > Pull-Request: https://github.com/gitgitgadget/git/pull/939
> >
> >  Documentation/pretty-formats.txt | 2 ++
> >  pretty.c                         | 3 +++
> >  t/t4205-log-pretty-formats.sh    | 6 ++++++
> >  3 files changed, 11 insertions(+)
> >
> > diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> > index 45133066e412..9cdcdb8bb414 100644
> > --- a/Documentation/pretty-formats.txt
> > +++ b/Documentation/pretty-formats.txt
> > @@ -190,6 +190,7 @@ 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
>
> There's no sorting here, so this place (at the bottom of the author-date
> placeholders) seems just as good as any.
>
> >  '%cn':: committer name
> >  '%cN':: committer name (respecting .mailmap, see
> >       linkgit:git-shortlog[1] or linkgit:git-blame[1])
> > @@ -206,6 +207,7 @@ 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
>
> Likewise. The rest all looks good to me, too.
>
>   Reviewed-by: Taylor Blau <me@ttaylorr.com>
>
> Thanks,
> Taylor

Thanks!
--
ZheNing Hu
ZheNing Hu April 24, 2021, 1:33 p.m. UTC | #4
Philip Oakley <philipoakley@iee.email> 于2021年4月24日周六 上午5:10写道:
>
> On 23/04/2021 17:27, ZheNing Hu via GitGitGadget wrote:
> > 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.
> >
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-939%2Fadlternative%2Fpretty_human-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-939/adlternative/pretty_human-v1
> > Pull-Request: https://github.com/gitgitgadget/git/pull/939
> >
> >  Documentation/pretty-formats.txt | 2 ++
> >  pretty.c                         | 3 +++
> >  t/t4205-log-pretty-formats.sh    | 6 ++++++
> >  3 files changed, 11 insertions(+)
> >
> > diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> > index 45133066e412..9cdcdb8bb414 100644
> > --- a/Documentation/pretty-formats.txt
> > +++ b/Documentation/pretty-formats.txt
> > @@ -190,6 +190,7 @@ 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
>
> An example may be useful. There's no other mention of human date style
> in the pretty-formats doc. Or a link to the definitive man page.
>

Thanks for the suggestion. Note that the explanation here is relatively small,
and human style has many different situations, so I may just go to link it to
`rev-list-option.txt`, This is more convenient than showing multiple situations'
examples.

> >  '%cn':: committer name
> >  '%cN':: committer name (respecting .mailmap, see
> >       linkgit:git-shortlog[1] or linkgit:git-blame[1])
> > @@ -206,6 +207,7 @@ 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
> Likewise, an `(e.g. ????)` to unconfuse readers.
> >  '%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..d4d75b0b350e 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 'human date' '
> > +     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
> --
> Philip

Thanks!
--
ZheNing Hu
diff mbox series

Patch

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 45133066e412..9cdcdb8bb414 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -190,6 +190,7 @@  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
 '%cn':: committer name
 '%cN':: committer name (respecting .mailmap, see
 	linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -206,6 +207,7 @@  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
 '%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..d4d75b0b350e 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 'human date' '
+	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) &&