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

Nicolas Dumazet nicdumz at gmail.com
Tue Nov 23 01:11:11 UTC 2010


2010/11/23 Benjamin Pollack <benjamin at bitquabit.com>:
> # 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
>
> @@ -1072,6 +1074,8 @@ def strdate(string, format, defaults=[])
>         offset = unixtime - localunixtime
>     else:
>         unixtime = localunixtime + offset
> +    if unixtime < 0:
> +        raise ValueError

maybe an argument would be useful here?

>     return unixtime, offset
>
>  def parsedate(date, formats=None, defaults=None):
> _______________________________________________
> Mercurial mailing list
> Mercurial at selenic.com
> http://selenic.com/mailman/listinfo/mercurial
>



-- 
Nicolas Dumazet — NicDumZ



More information about the Mercurial mailing list