[PATCH v3] Allow commit date before Unix epoch, clean fix for (issue2513)

Florent Gallaire fgallaire at gmail.com
Sat Apr 2 18:14:21 EDT 2016


> Nitpick: Since you don't use time.gmtime any more, clamping to the magic
> year-2038-value on OverflowError is... a little bit strange.

I agree it's not perfect, but it's a lot better than
t = time.gmtime(sys.maxint)
which is completely broken on 64 bits system (exception on the except clause)

1) I just fix issue 2513 the right way
2) it's simple
3) for backward compatibility, hg has never accepted more than signed
32 bits for dates

If you want to go further after my patch.... IMHO, it's the good first step.

Florent

> Perhaps, it would make more sense to clamp to the limits of
> datetime.datetime instead? Or explicitly check that t is within the
> bounds of
>
> datetime.datetime(1970, 1, 1) + datetime.timedelta(0x7fffffff)
> datetime.datetime(1970, 1, 1) + datetime.timedelta(-0x7fffffff)
>
> ?
>
> (see also c208dcd0f709, which introduced the original clamping for the
> time.gmtime call)
>
>>      return s
>>
>>  def shortdate(date=None):
>> @@ -1714,8 +1715,6 @@
>>      # to UTC+14
>>      if abs(when) > 0x7fffffff:
>>          raise Abort(_('date exceeds 32 bits: %d') % when)
>> -    if when < 0:
>> -        raise Abort(_('negative date value: %d') % when)
>>      if offset < -50400 or offset > 43200:
>>          raise Abort(_('impossible time zone offset: %d') % offset)
>>      return when, offset
>> diff -r ff0d3b6b287f -r a415db6cb545 tests/test-commit.t
>> --- a/tests/test-commit.t    Tue Mar 29 12:29:00 2016 -0500
>> +++ b/tests/test-commit.t    Sat Apr 02 20:26:22 2016 +0200
>> @@ -27,8 +27,8 @@
>>    $ hg commit -d '111111111111 0' -m commit-7
>>    abort: date exceeds 32 bits: 111111111111
>>    [255]
>> -  $ hg commit -d '-7654321 3600' -m commit-7
>> -  abort: negative date value: -7654321
>> +  $ hg commit -d '-111111111111 0' -m commit-7
>> +  abort: date exceeds 32 bits: -111111111111
>>    [255]
>>
>>  commit added file that has been deleted



-- 
FLOSS Engineer & Lawyer


More information about the Mercurial-devel mailing list