"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: Regress failures: regress, histedit
To:
Christian Weisgerber <naddy@mips.inka.de>
Cc:
gameoftrees@openbsd.org
Date:
Sat, 28 Aug 2021 17:48:43 +0200

Download raw body.

Thread
On Sat, Aug 28, 2021 at 04:49:56PM +0200, Christian Weisgerber wrote:
> Christian Weisgerber:
> 
> > It's about 00:30 here (UTC+2) and the rebase and histedit regression
> > tests are failing _right now_ for me with various differences like
> > this one:
> > 
> > - 2021-08-27 flan_hacker  committing more changes on newbranch
> > + 2021-08-28 flan_hacker  committing more changes on newbranch
> 
> After moving my time zone to Pacific/Kiritimati (UTC+14), I've been
> able to examine this in a more convenient time window.
> 
> The failures are in
>   rebase.sh:   test_rebase_basic()
>   histedit.sh: test_histedit_no_op()
> 
> rebase -l and histedit -l don't return the expected output.
> Both use the same code path in print_backup_ref().
> 
> The test specifically expects all times to be in UTC.
> 
> There are three timestamps involved in print_backup_ref().
> print_commit() outputs UTC.  However, get_commit_brief_str() prints
> the committer time using localtime_r().  Hmmm.

Yes, there is a mix of gmtime_r() and localtime_r().
This cannot be right.

My goal is to consistently output commit timestamps in UTC.
This differs from Git which displays local time by default, because
I believe it makes more sense to display UTC.
Nobody will care what their local clock said when someone else in
another timezone ran 'got commit'. Using UTC everywhere means people
on different continents can chat online and compare meaningful timestamps
while bisecting changes.

All time_t values stored in struct got_object_commit are already in UTC.
The commit object parser ensures this by adjusting the timestamp for
the timezone offset which was stored along with the timestamp.

When writing commits we always store a UTC timestamp, as obtained
from time(3), and a timezone offset of 0. Git will then show UTC
timestamps for commits generated by us. I've just verified again
that this behaviour does indeed already work as intended.

For display purposes we need a function which converts a time_t value
into a const char * date string without adjusting for anything,
ignoring the value of the TZ env var and such.
Which C library function would be the best one to use for this purpose?

Perhaps we should be setting TZ and calling tzset() from inside the
program to force libc to use UTC? Being required to do this would seem
wrong to me. But a brief look at the code of the gmtime_r() and related
functions seems to suggest that we should be doing this?