git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
@ 2017-02-02 17:51 Hilco Wijbenga
  2017-02-03  4:19 ` G. Sylvie Davies
  2017-02-03  8:06 ` Duy Nguyen
  0 siblings, 2 replies; 6+ messages in thread
From: Hilco Wijbenga @ 2017-02-02 17:51 UTC (permalink / raw)
  To: Git Users

Hi all,

I'm trying to get the committer date printed in a custom fashion.
Using "%cI" gets me close:

$ git show --format="%cI | %an" master | head -n 1
2017-01-31T17:02:13-08:00 | Hilco Wijbenga

I would like to get rid of the "-08:00" bit at the end of the
timestamp. According to the "git show" manual I should be able to use
"%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.

$ git show --format="%<(19,trunc)cI | %an" master | head -n 1
cI | Hilco Wijbenga

Mmm, it seems to be recognized as a valid "something" but it's not
working as I had expected. :-) I tried several other versions of this
but no luck. Clearly, I'm misunderstanding the format description. How
do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?

Cheers,
Hilco

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
  2017-02-02 17:51 How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"? Hilco Wijbenga
@ 2017-02-03  4:19 ` G. Sylvie Davies
  2017-02-03  4:32   ` Hilco Wijbenga
  2017-02-03  8:06 ` Duy Nguyen
  1 sibling, 1 reply; 6+ messages in thread
From: G. Sylvie Davies @ 2017-02-03  4:19 UTC (permalink / raw)
  To: Hilco Wijbenga; +Cc: Git Users

On Thu, Feb 2, 2017 at 9:51 AM, Hilco Wijbenga <hilco.wijbenga@gmail.com> wrote:
> Hi all,
>
> I'm trying to get the committer date printed in a custom fashion.
> Using "%cI" gets me close:
>
> $ git show --format="%cI | %an" master | head -n 1
> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>
> I would like to get rid of the "-08:00" bit at the end of the
> timestamp. According to the "git show" manual I should be able to use
> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>
> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
> cI | Hilco Wijbenga
>
> Mmm, it seems to be recognized as a valid "something" but it's not
> working as I had expected. :-) I tried several other versions of this
> but no luck. Clearly, I'm misunderstanding the format description. How
> do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>

Will this work for you?

$ git show -s --pretty='%cd | %an' --date=format:%FT%R:%S
2017-02-02T10:01:36 | G. Sylvie Davies


I have no idea how portable this might be.  As "git help log" says:

         --date=format:...  feeds the format ...  to your system
strftime. Use --date=format:%c to show the date in your system
locale’s preferred format. See the strftime manual for a complete list
of format placeholders.



- Sylvie

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
  2017-02-03  4:19 ` G. Sylvie Davies
@ 2017-02-03  4:32   ` Hilco Wijbenga
  0 siblings, 0 replies; 6+ messages in thread
From: Hilco Wijbenga @ 2017-02-03  4:32 UTC (permalink / raw)
  To: G. Sylvie Davies; +Cc: Git Users

On 2 February 2017 at 20:19, G. Sylvie Davies <sylvie@bit-booster.com> wrote:
> On Thu, Feb 2, 2017 at 9:51 AM, Hilco Wijbenga <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I'm trying to get the committer date printed in a custom fashion.
>> Using "%cI" gets me close:
>>
>> $ git show --format="%cI | %an" master | head -n 1
>> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>>
>> I would like to get rid of the "-08:00" bit at the end of the
>> timestamp. According to the "git show" manual I should be able to use
>> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>>
>> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
>> cI | Hilco Wijbenga
>>
>> Mmm, it seems to be recognized as a valid "something" but it's not
>> working as I had expected. :-) I tried several other versions of this
>> but no luck. Clearly, I'm misunderstanding the format description. How
>> do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>>
>
> Will this work for you?
>
> $ git show -s --pretty='%cd | %an' --date=format:%FT%R:%S
> 2017-02-02T10:01:36 | G. Sylvie Davies

Ah, that does indeed do exactly what I want. Thank you.

> I have no idea how portable this might be.  As "git help log" says:
>
>          --date=format:...  feeds the format ...  to your system
> strftime. Use --date=format:%c to show the date in your system
> locale’s preferred format. See the strftime manual for a complete list
> of format placeholders.

It should be fine for my purposes.

Any idea why "%<(19,trunc)cl" doesn't work? (Your solution solves my
original problem perfectly but I'd like to understand how I'm
misreading the spec.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
  2017-02-02 17:51 How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"? Hilco Wijbenga
  2017-02-03  4:19 ` G. Sylvie Davies
@ 2017-02-03  8:06 ` Duy Nguyen
  2017-02-03 17:10   ` Hilco Wijbenga
  1 sibling, 1 reply; 6+ messages in thread
From: Duy Nguyen @ 2017-02-03  8:06 UTC (permalink / raw)
  To: Hilco Wijbenga; +Cc: Git Users

On Fri, Feb 3, 2017 at 12:51 AM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
> Hi all,
>
> I'm trying to get the committer date printed in a custom fashion.
> Using "%cI" gets me close:
>
> $ git show --format="%cI | %an" master | head -n 1
> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>
> I would like to get rid of the "-08:00" bit at the end of the
> timestamp. According to the "git show" manual I should be able to use
> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>
> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1

You're almost there. Just insert another '%' between "trunc)" and "cI".

> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?

You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)
-- 
Duy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
  2017-02-03  8:06 ` Duy Nguyen
@ 2017-02-03 17:10   ` Hilco Wijbenga
  2017-02-04 11:49     ` Duy Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: Hilco Wijbenga @ 2017-02-03 17:10 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Users

On 3 February 2017 at 00:06, Duy Nguyen <pclouds@gmail.com> wrote:
> On Fri, Feb 3, 2017 at 12:51 AM, Hilco Wijbenga
> <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I'm trying to get the committer date printed in a custom fashion.
>> Using "%cI" gets me close:
>>
>> $ git show --format="%cI | %an" master | head -n 1
>> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>>
>> I would like to get rid of the "-08:00" bit at the end of the
>> timestamp. According to the "git show" manual I should be able to use
>> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>>
>> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
>
> You're almost there. Just insert another '%' between "trunc)" and "cI".

Thank you so much! This has been bugging me. :-) Rereading "git help
show", I guess it's implied I should do this but it very much wasn't
clear to me (obviously). I guess I'm too used to the "%19.19s" type of
approach. Maybe there should be some examples?

>> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>
> You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)

Indeed, that's not very nice. I suppose I can understand the reason
for it but it mostly defeats the purpose of "trunc", doesn't it?
Luckily, Sylvie's solution does exactly what I want.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
  2017-02-03 17:10   ` Hilco Wijbenga
@ 2017-02-04 11:49     ` Duy Nguyen
  0 siblings, 0 replies; 6+ messages in thread
From: Duy Nguyen @ 2017-02-04 11:49 UTC (permalink / raw)
  To: Hilco Wijbenga; +Cc: Git Users

On Sat, Feb 4, 2017 at 12:10 AM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
>>> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>>
>> You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)
>
> Indeed, that's not very nice. I suppose I can understand the reason
> for it but it mostly defeats the purpose of "trunc", doesn't it?

It depends. When you truncate a commit subject line, you may want an
indicator that you're not seeing the whole line. For fixed fields like
dates when you expect every string to be truncated, then yes there's
not much point to show the ellipsis.
-- 
Duy

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-04 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-02 17:51 How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"? Hilco Wijbenga
2017-02-03  4:19 ` G. Sylvie Davies
2017-02-03  4:32   ` Hilco Wijbenga
2017-02-03  8:06 ` Duy Nguyen
2017-02-03 17:10   ` Hilco Wijbenga
2017-02-04 11:49     ` Duy Nguyen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).