# [BUG REPORT] Git log pretty date

13 messages from 2014-05-29 to 2014-06-03. Participants: Rodrigo Fernandes, Duy Nguyen, Dennis Kaarsemaker, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/36781

## Rodrigo Fernandes, 2014-05-29 10:29

Subject: [BUG REPORT] Git log pretty date
Message-ID: <CACJZPBtv-Cpb8_WZMz9Hsk9MrC86YGfbvREt6G=QKvMBjrqsEg@mail.gmail.com>
URL: https://gitlist.dev/e/CACJZPBtv-Cpb8_WZMz9Hsk9MrC86YGfbvREt6G%3DQKvMBjrqsEg%40mail.gmail.com

```
Hi,

I'm having some problems with the `git log` command.

Setup:
Happens in multiple versions, tested on 1.8.* and 2.*

The problem happens when I try to get a pretty log for a commit with a
wrong date.

Executing the command:
`git log --encoding=UTF-8 --date=raw --pretty=format:'%H,%P,%ad,%cd,%an,%s'`

I get an empty response on the date field, but since pretty has `%ad`
it should follow the --date and return the date even if wrong.

The problem happens in this repo:
`https://github.com/SamWM/jQuery-Plugins` on commit
`e9dddaf24c9de45d9b4efdf38eff7c30eb200f48`.

I posted it on SO too:
`http://stackoverflow.com/questions/23793188/find-date-for-not-dated-commit`

I think it is a bug probably on pretty since other raw formats show
the date as it should.

I tried to check the source code but have no idea where to start,
maybe if you point me on some direction I can take a look for my self.

Can you help?

Kind regards,
Rodrigo Fernandes

```

## Duy Nguyen, 2014-05-29 10:50

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <CACsJy8BREpVFKq3mW=Lwn+uNm1r40Xe8f4EyXLFN2yybZRT0oA@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8BREpVFKq3mW%3DLwn%2BuNm1r40Xe8f4EyXLFN2yybZRT0oA%40mail.gmail.com
In-Reply-To: <CACJZPBtv-Cpb8_WZMz9Hsk9MrC86YGfbvREt6G=QKvMBjrqsEg@mail.gmail.com>

```
On Thu, May 29, 2014 at 5:29 PM, Rodrigo Fernandes <rtfrodrigo@gmail.com> wrote:
> I get an empty response on the date field, but since pretty has `%ad`
> it should follow the --date and return the date even if wrong.
>
> ...
>
> I tried to check the source code but have no idea where to start,
> maybe if you point me on some direction I can take a look for my self.

pretty.c, format_commit_one() -> format_person_part() ->
show_ident_date() -> show_date(). The last one is in date.c
-- 
Duy

```

## Dennis Kaarsemaker, 2014-05-29 11:07

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <1401361654.26905.2.camel@spirit>
URL: https://gitlist.dev/e/1401361654.26905.2.camel%40spirit
In-Reply-To: <CACJZPBtv-Cpb8_WZMz9Hsk9MrC86YGfbvREt6G=QKvMBjrqsEg@mail.gmail.com>

```
On do, 2014-05-29 at 11:29 +0100, Rodrigo Fernandes wrote:
> 
> The problem happens when I try to get a pretty log for a commit with a
> wrong date.

The commit is:

===
$ git cat-file commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48
tree d63aeb159635cb231e191505a95a129a3b4a7b38
parent 9276202f1c0dcc360433df222c90f7874558f072
author SamWM <sam@webmonkeysolutions.com> 1288370243 --700
committer SamWM <sam@webmonkeysolutions.com> 1288370243 --700

Update version number, make text formatting and indentation consistent
with the rest of the code
====

Those dates are indeed wrong, I'm not surprised git refuses to parse
them.

-- 
Dennis Kaarsemaker
www.kaarsemaker.net

```

## Rodrigo Fernandes, 2014-05-29 12:24

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <CACJZPBvn4nX4aVGiiC1VAhHi7vPZJDBR8T5p13qaE6B+2Q9bUw@mail.gmail.com>
URL: https://gitlist.dev/e/CACJZPBvn4nX4aVGiiC1VAhHi7vPZJDBR8T5p13qaE6B%2B2Q9bUw%40mail.gmail.com
In-Reply-To: <1401361654.26905.2.camel@spirit>

```
Dennis I think that could be an improvement.

Duy, can you point me where is the date print from normal `git log` or
`git show` so I can compare?


On Thu, May 29, 2014 at 12:07 PM, Dennis Kaarsemaker
<dennis@kaarsemaker.net> wrote:
> On do, 2014-05-29 at 11:29 +0100, Rodrigo Fernandes wrote:
>>
>> The problem happens when I try to get a pretty log for a commit with a
>> wrong date.
>
> The commit is:
>
> ===
> $ git cat-file commit e9dddaf24c9de45d9b4efdf38eff7c30eb200f48
> tree d63aeb159635cb231e191505a95a129a3b4a7b38
> parent 9276202f1c0dcc360433df222c90f7874558f072
> author SamWM <sam@webmonkeysolutions.com> 1288370243 --700
> committer SamWM <sam@webmonkeysolutions.com> 1288370243 --700
>
> Update version number, make text formatting and indentation consistent
> with the rest of the code
> ====
>
> Those dates are indeed wrong, I'm not surprised git refuses to parse
> them.
>
> --
> Dennis Kaarsemaker
> www.kaarsemaker.net
>

```

## Duy Nguyen, 2014-05-29 12:52

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <CACsJy8CzMcaQ0q4bsUmR34fE+VunTFiW_oVmC-mKFORq89bsKQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8CzMcaQ0q4bsUmR34fE%2BVunTFiW_oVmC-mKFORq89bsKQ%40mail.gmail.com
In-Reply-To: <CACJZPBvn4nX4aVGiiC1VAhHi7vPZJDBR8T5p13qaE6B+2Q9bUw@mail.gmail.com>

```
On Thu, May 29, 2014 at 7:24 PM, Rodrigo Fernandes <rtfrodrigo@gmail.com> wrote:
> Duy, can you point me where is the date print from normal `git log` or
> `git show` so I can compare?

It's the same function, show_date() in date.c.
-- 
Duy

```

## Jeff King, 2014-05-29 16:16

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <20140529161628.GB3763@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140529161628.GB3763%40sigill.intra.peff.net
In-Reply-To: <CACsJy8BREpVFKq3mW=Lwn+uNm1r40Xe8f4EyXLFN2yybZRT0oA@mail.gmail.com>

```
On Thu, May 29, 2014 at 05:50:56PM +0700, Duy Nguyen wrote:

> On Thu, May 29, 2014 at 5:29 PM, Rodrigo Fernandes <rtfrodrigo@gmail.com> wrote:
> > I get an empty response on the date field, but since pretty has `%ad`
> > it should follow the --date and return the date even if wrong.
> >
> > ...
> >
> > I tried to check the source code but have no idea where to start,
> > maybe if you point me on some direction I can take a look for my self.
> 
> pretty.c, format_commit_one() -> format_person_part() ->
> show_ident_date() -> show_date(). The last one is in date.c

show_ident_date() recently learned to always print "Jan 1 1970" as a
sentinel for dates that cannot be parsed (or for --date=raw, "0 +0000").
But I do not think we hit that code path at all here.

It looks like split_ident_line notices the bogus date and returns NULL
for s.date_begin. Then format_person_part skips the placeholder, since
it knows we have nothing worth showing.

I think we probably want to do something like:

diff --git a/pretty.c b/pretty.c
index 3c43db5..7214a2c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -732,14 +732,6 @@ static size_t format_person_part(struct strbuf *sb, char part,
 		return placeholder_len;
 	}
 
-	if (!s.date_begin)
-		goto skip;
-
-	if (part == 't') {	/* date, UNIX timestamp */
-		strbuf_add(sb, s.date_begin, s.date_end - s.date_begin);
-		return placeholder_len;
-	}
-
 	switch (part) {
 	case 'd':	/* date */
 		strbuf_addstr(sb, show_ident_date(&s, dmode));
@@ -753,6 +745,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
 	case 'i':	/* date, ISO 8601 */
 		strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601));
 		return placeholder_len;
+	case 't':	/* date, UNIX timestamp */
+		strbuf_addstr(sb, show_ident_date(&s, DATE_RAW));
+		return placeholder_len;
 	}
 
 skip:

to at least make --format date output consistent with the rest of git
(and to make "%at" consistent with "%ad" and --date=raw). That still
doesn't address Rodrigo's concern, though (we would print "0 +0000").

For that, we would want on top:

  1. Teach split_ident_line to return _something_ for his malformed
     case.

  2. Teach show_ident_line to treat DATE_RAW to truly output raw
     content, even if it is malformed.

I am not sure whether those are a good idea or not. The current code
provides some level of sanitization, so that a parser of log output will
not get malformed cruft. And DATE_RAW may mean "show me what is in the
raw commit, even if it is broken". Or it may just mean "show me the date
in unix timestamp format, because that is easy to parse".

I'd argue that if somebody really wants the former, they should be using
"--pretty=raw", which will show the raw commit headers, without any
parsing or fixup at all.

-Peff

```

## Junio C Hamano, 2014-05-29 18:57

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <xmqq7g54begk.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq7g54begk.fsf%40gitster.dls.corp.google.com
In-Reply-To: <20140529161628.GB3763@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> ...
> to at least make --format date output consistent with the rest of git
> (and to make "%at" consistent with "%ad" and --date=raw). That still
> doesn't address Rodrigo's concern, though (we would print "0 +0000").
>
> For that, we would want on top:
>
>   1. Teach split_ident_line to return _something_ for his malformed
>      case.
>
>   2. Teach show_ident_line to treat DATE_RAW to truly output raw
>      content, even if it is malformed.
>
> I am not sure whether those are a good idea or not. The current code
> provides some level of sanitization, so that a parser of log output will
> not get malformed cruft. And DATE_RAW may mean "show me what is in the
> raw commit, even if it is broken". Or it may just mean "show me the date
> in unix timestamp format, because that is easy to parse".
>
> I'd argue that if somebody really wants the former, they should be using
> "--pretty=raw", which will show the raw commit headers, without any
> parsing or fixup at all.

I actually am not very much interested in deciding what to show for
a broken timestamp.  An empty string is just as good as any random
cruft.  I agree with you that it would be nice to have one escape
hatch to let the users see what garbage is recorded, if only for
diagnostic purposes, and DATE_RAW may be one good way to do so (but
I'd rather recommend "cat-file commit" for real diagnostics).

I would be more interested to see whatever broken tool that created
such a commit gets fixed.  Do we know where it came from?

```

## Jeff King, 2014-05-29 19:49

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <20140529194932.GA16665@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140529194932.GA16665%40sigill.intra.peff.net
In-Reply-To: <xmqq7g54begk.fsf@gitster.dls.corp.google.com>

```
On Thu, May 29, 2014 at 11:57:15AM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > ...
> > to at least make --format date output consistent with the rest of git
> > (and to make "%at" consistent with "%ad" and --date=raw). That still
> > doesn't address Rodrigo's concern, though (we would print "0 +0000").
> [...]
> 
> I actually am not very much interested in deciding what to show for
> a broken timestamp.  An empty string is just as good as any random
> cruft.

I was thinking specifically of the first part I quoted above. We are not
consistent between various methods of parsing/printing the date. That
may fall into the "if were doing it from scratch..." category, though;
it's possible that people currently using "--format=%ad" prefer and
expect the empty string to denote a bogus value. I'm OK with leaving it.

> I agree with you that it would be nice to have one escape
> hatch to let the users see what garbage is recorded, if only for
> diagnostic purposes, and DATE_RAW may be one good way to do so (but
> I'd rather recommend "cat-file commit" for real diagnostics).

Yeah, in case I wasn't clear, I don't actually like DATE_RAW as a way to
do that. I'd prefer "--pretty=raw" or "cat-file commit", which already
work.

> I would be more interested to see whatever broken tool that created
> such a commit gets fixed.  Do we know where it came from?

I don't think it has been said yet in the thread. Rodrigo?

-Peff

```

## Rodrigo Fernandes, 2014-05-29 19:57

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <CACJZPBs2_htD=zS1K3fOW+DZ323+2+iwupWuyNDArg2XF6Qx5g@mail.gmail.com>
URL: https://gitlist.dev/e/CACJZPBs2_htD%3DzS1K3fOW%2BDZ323%2B2%2BiwupWuyNDArg2XF6Qx5g%40mail.gmail.com
In-Reply-To: <20140529194932.GA16665@sigill.intra.peff.net>

```
Jeff,
I have no idea what was the tool. The repo is not mine. I found the
problem when I was doing some tests and the commit parsing was failing
on that repo.

Cumprimentos,
Rodrigo Fernandes


On Thu, May 29, 2014 at 8:49 PM, Jeff King <peff@peff.net> wrote:
> On Thu, May 29, 2014 at 11:57:15AM -0700, Junio C Hamano wrote:
>
>> Jeff King <peff@peff.net> writes:
>>
>> > ...
>> > to at least make --format date output consistent with the rest of git
>> > (and to make "%at" consistent with "%ad" and --date=raw). That still
>> > doesn't address Rodrigo's concern, though (we would print "0 +0000").
>> [...]
>>
>> I actually am not very much interested in deciding what to show for
>> a broken timestamp.  An empty string is just as good as any random
>> cruft.
>
> I was thinking specifically of the first part I quoted above. We are not
> consistent between various methods of parsing/printing the date. That
> may fall into the "if were doing it from scratch..." category, though;
> it's possible that people currently using "--format=%ad" prefer and
> expect the empty string to denote a bogus value. I'm OK with leaving it.
>
>> I agree with you that it would be nice to have one escape
>> hatch to let the users see what garbage is recorded, if only for
>> diagnostic purposes, and DATE_RAW may be one good way to do so (but
>> I'd rather recommend "cat-file commit" for real diagnostics).
>
> Yeah, in case I wasn't clear, I don't actually like DATE_RAW as a way to
> do that. I'd prefer "--pretty=raw" or "cat-file commit", which already
> work.
>
>> I would be more interested to see whatever broken tool that created
>> such a commit gets fixed.  Do we know where it came from?
>
> I don't think it has been said yet in the thread. Rodrigo?
>
> -Peff

```

## Rodrigo Fernandes, 2014-05-30 08:08

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <CACJZPBtJZ+gDvtHnRwi8JOO7rFAg=pPBvEQ=-FwKnp9Gr+FStw@mail.gmail.com>
URL: https://gitlist.dev/e/CACJZPBtJZ%2BgDvtHnRwi8JOO7rFAg%3DpPBvEQ%3D-FwKnp9Gr%2BFStw%40mail.gmail.com
In-Reply-To: <CACJZPBs2_htD=zS1K3fOW+DZ323+2+iwupWuyNDArg2XF6Qx5g@mail.gmail.com>

```
Jeff,
Do you have any idea how does github understand that is a bug and
fixes it automatically?
(I'm saying this because on Github the date is correct).
Cumprimentos,
Rodrigo Fernandes


On Thu, May 29, 2014 at 8:57 PM, Rodrigo Fernandes <rtfrodrigo@gmail.com> wrote:
> Jeff,
> I have no idea what was the tool. The repo is not mine. I found the
> problem when I was doing some tests and the commit parsing was failing
> on that repo.
>
> Cumprimentos,
> Rodrigo Fernandes
>
>
> On Thu, May 29, 2014 at 8:49 PM, Jeff King <peff@peff.net> wrote:
>> On Thu, May 29, 2014 at 11:57:15AM -0700, Junio C Hamano wrote:
>>
>>> Jeff King <peff@peff.net> writes:
>>>
>>> > ...
>>> > to at least make --format date output consistent with the rest of git
>>> > (and to make "%at" consistent with "%ad" and --date=raw). That still
>>> > doesn't address Rodrigo's concern, though (we would print "0 +0000").
>>> [...]
>>>
>>> I actually am not very much interested in deciding what to show for
>>> a broken timestamp.  An empty string is just as good as any random
>>> cruft.
>>
>> I was thinking specifically of the first part I quoted above. We are not
>> consistent between various methods of parsing/printing the date. That
>> may fall into the "if were doing it from scratch..." category, though;
>> it's possible that people currently using "--format=%ad" prefer and
>> expect the empty string to denote a bogus value. I'm OK with leaving it.
>>
>>> I agree with you that it would be nice to have one escape
>>> hatch to let the users see what garbage is recorded, if only for
>>> diagnostic purposes, and DATE_RAW may be one good way to do so (but
>>> I'd rather recommend "cat-file commit" for real diagnostics).
>>
>> Yeah, in case I wasn't clear, I don't actually like DATE_RAW as a way to
>> do that. I'd prefer "--pretty=raw" or "cat-file commit", which already
>> work.
>>
>>> I would be more interested to see whatever broken tool that created
>>> such a commit gets fixed.  Do we know where it came from?
>>
>> I don't think it has been said yet in the thread. Rodrigo?
>>
>> -Peff

```

## Jeff King, 2014-06-03 03:46

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <20140603034619.GA18176@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140603034619.GA18176%40sigill.intra.peff.net
In-Reply-To: <CACJZPBtJZ+gDvtHnRwi8JOO7rFAg=pPBvEQ=-FwKnp9Gr+FStw@mail.gmail.com>

```
On Fri, May 30, 2014 at 09:08:57AM +0100, Rodrigo Fernandes wrote:

> Do you have any idea how does github understand that is a bug and
> fixes it automatically?
> (I'm saying this because on Github the date is correct).

I looked into this. The dates you see on GitHub's web UI are actually
parsed by Rugged/libgit2. The libgit2 parser is slightly more forgiving
in this instance; if it sees a broken timezone, it will leave the
timestamp intact, and only omit the timezone. Whereas git says "no, it's
broken, and the timestamp cannot be trusted".

I think both are equally valid strategies, and I do not even think it is
a problem that they diverge between the two implementations. I'd be OK
with a patch to make git handle errors in each independently, assuming
it is not too invasive.

-Peff

```

## Dennis Kaarsemaker, 2014-06-03 06:23

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <20140603062301.GA22149@spirit>
URL: https://gitlist.dev/e/20140603062301.GA22149%40spirit
In-Reply-To: <20140603034619.GA18176@sigill.intra.peff.net>

```
On Mon, Jun 02, 2014 at 11:46:19PM -0400, Jeff King wrote:
> On Fri, May 30, 2014 at 09:08:57AM +0100, Rodrigo Fernandes wrote:
> 
> > Do you have any idea how does github understand that is a bug and
> > fixes it automatically?
> > (I'm saying this because on Github the date is correct).
> 
> I looked into this. The dates you see on GitHub's web UI are actually
> parsed by Rugged/libgit2. The libgit2 parser is slightly more forgiving
> in this instance; if it sees a broken timezone, it will leave the
> timestamp intact, and only omit the timezone. Whereas git says "no, it's
> broken, and the timestamp cannot be trusted".
> 
> I think both are equally valid strategies, and I do not even think it is
> a problem that they diverge between the two implementations. I'd be OK
> with a patch to make git handle errors in each independently, assuming
> it is not too invasive.

I think what libgit2 does is more wrong than what git does. It displays
the timestamp subtly wrong (off by 7 hours) instead of making it
completely clear that the timestamp is bogus.

-- 
Dennis Kaarsemaker <dennis@kaarsemaker.net>
http://twitter.com/seveas

```

## Jeff King, 2014-06-03 06:45

Subject: Re: [BUG REPORT] Git log pretty date
Message-ID: <20140603064526.GB26150@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140603064526.GB26150%40sigill.intra.peff.net
In-Reply-To: <20140603062301.GA22149@spirit>

```
On Tue, Jun 03, 2014 at 08:23:02AM +0200, Dennis Kaarsemaker wrote:

> On Mon, Jun 02, 2014 at 11:46:19PM -0400, Jeff King wrote:
> > On Fri, May 30, 2014 at 09:08:57AM +0100, Rodrigo Fernandes wrote:
> > 
> > > Do you have any idea how does github understand that is a bug and
> > > fixes it automatically?
> > > (I'm saying this because on Github the date is correct).
> > 
> > I looked into this. The dates you see on GitHub's web UI are actually
> > parsed by Rugged/libgit2. The libgit2 parser is slightly more forgiving
> > in this instance; if it sees a broken timezone, it will leave the
> > timestamp intact, and only omit the timezone. Whereas git says "no, it's
> > broken, and the timestamp cannot be trusted".
> > 
> > I think both are equally valid strategies, and I do not even think it is
> > a problem that they diverge between the two implementations. I'd be OK
> > with a patch to make git handle errors in each independently, assuming
> > it is not too invasive.
> 
> I think what libgit2 does is more wrong than what git does. It displays
> the timestamp subtly wrong (off by 7 hours) instead of making it
> completely clear that the timestamp is bogus.

I'm not sure what you mean. The timestamp is in UTC seconds-since-epoch,
and does not depend on the timezone. The timezone only indicates the
author's local time when the commit was made.

Whether the latter is relevant depends on the date format you are
showing (i.e., if you are showing it in the author's timezone, it
matters; for --date=local or --date=relative, it would not).

So I do not think libgit2 is at fault for parsing them separately; it
does not know how the result will be presented. What GitHub shows is
wrong, as it tries to put the timestamp into the author's timezone
(which it doesn't know). But in practice it turns out be more useful,
because we show relative dates for recent things (so "8 hours ago" is
actually accurate and does not care about the timestamp). For distant
things, time zone effects become less important (we show "Oct 29, 2010";
it may have actually been Oct 30 or Oct 28 in the author's zone, but
it's really not that important anymore).

Those comments are just on the two strategies. As far as
implementations, it looks like libgit2 somehow parses this commit as
+0700, which is odd. I'd expect it to fall back to +0000. I didn't dig
further.

-Peff

```
