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

Benjamin Pollack benjamin at bitquabit.com
Mon Nov 22 16:13:28 CST 2010


# 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
     return unixtime, offset
 
 def parsedate(date, formats=None, defaults=None):


More information about the Mercurial-devel mailing list