git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: rybak.a.v@gmail.com
Cc: Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [RFC PATCH v2] Add 'human' date format
Date: Wed, 11 Jul 2018 14:23:47 -0700	[thread overview]
Message-ID: <CA+55aFx8-hni4WoDpc6jkNo03GJr1jVbRr5-Pz35X=yaq+hEqQ@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFym5aSudSHiVA=VmvoY=WFytUqficLQCE4Sd_urjwKqPw@mail.gmail.com>

[ Trying to come up with crazy special cases ]

On Wed, Jul 11, 2018 at 1:49 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> But it could be anything else invalid, of course. It could be MAX_INT
> or something like that.

That might be better. A timezone of -1 isn't actually a valid
timezone, but I guess you could create a commit by hand that had
"-0001" as the timezone.

You can't do that with something like MAX_INT, without fsck
complaining - since it has to be exactly four digits.

> The clearing of "human_tm" is done for a similar reason: the code does
>
>         hide.year = tm->tm_year == human_tm->tm_year;
>
> (and then later just checks "if (human_tm->tm_year)") knowing that a
> non-zero tm_year will only ever happen for human_tz (and that 1900 is
> not a valid git date, even though I guess in theory you could do it).

Actually, the 1900 should be safe, because 'timestamp_t' is unsigned.
So a valid timestamp really can't be before 1970.

Of course, you can probably try to mess with it by giving values that
don't actually fit, because sometimes we do convert mindlessly from
'timestamp_t' to 'time_t'. In particular, if you use the
"default-local" time, it will use that

  static struct tm *time_to_tm_local(timestamp_t time)
  {
        time_t t = time;
        return localtime(&t);
  }

and not check the range of the timestamp.

But other proper time stamp functions will actually do range checking
with "date_overflow()", so in general that whole assumption of "a real
git date cannot be in the year 1900" is valid.

              Linus

  reply	other threads:[~2018-07-11 21:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-07 19:38 [RFC PATCH] Add 'human' date format Linus Torvalds
2018-07-07 19:58 ` Linus Torvalds
2018-07-07 20:12   ` Linus Torvalds
2018-07-07 22:02 ` [RFC PATCH v2] " Linus Torvalds
2018-07-11 20:34   ` Andrei Rybak
2018-07-11 20:38     ` Andrei Rybak
2018-07-11 20:54       ` Junio C Hamano
2018-07-11 20:49     ` Linus Torvalds
2018-07-11 21:23       ` Linus Torvalds [this message]
2018-07-11 21:24   ` Ævar Arnfjörð Bjarmason
2018-07-11 21:49     ` Linus Torvalds
2018-07-24 21:49   ` Junio C Hamano
2018-07-24 22:58     ` Linus Torvalds
2018-11-27  4:10   ` Stephen P. Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+55aFx8-hni4WoDpc6jkNo03GJr1jVbRr5-Pz35X=yaq+hEqQ@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rybak.a.v@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).