[PATCH STABLE] do not crash on or store negative timestamps (issue2513)

Adrian Buehlmann adrian at cadifra.com
Mon Nov 22 16:48:06 CST 2010


On 2010-11-22 23:13, Benjamin Pollack wrote:
> # HG changeset patch
> # User Benjamin Pollack <benjamin at bitquabit.com>
> # Date 1290463597 28800
> # Node ID 72557ca9f1d3405a88ffe83960da6d8fedbb7414
> # Parent  77aa74fe0e0b92945ec793e9e7af02fdda36ca7c
> do not crash on or store negative timestamps (issue2513)
> 
> Mercurial will now reject timestamps preceding the Unix epoch. When
> encountering them in existing repos, it will return January 1, 1970.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1031,6 +1031,8 @@ def datestr(date=None, format='%a %b %d 
>          minutes = abs(tz) // 60
>          format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
>          format = format.replace("%2", "%02d" % (minutes % 60))
> +    if t < 0:
> +        t = 0
>      s = time.strftime(format, time.gmtime(float(t) - tz))
>      return s

Doesn't t=0 still lead to negative arguments for time.gmtime() for
timezones to the west of Greenwich (e.g. U.S.)?

(assuming time.gmtime crashes on Windows for negative values [1])

> @@ -1072,6 +1074,8 @@ def strdate(string, format, defaults=[])
>          offset = unixtime - localunixtime
>      else:
>          unixtime = localunixtime + offset
> +    if unixtime < 0:
> +        raise ValueError
>      return unixtime, offset
>  
>  def parsedate(date, formats=None, defaults=None):

[1] http://msdn.microsoft.com/en-us/library/0z9czt0w(VS.80).aspx


More information about the Mercurial-devel mailing list