Rev 6282: (jelmer) Improve parsing of commit times in --commit-time argument for ``bzr in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Nov 21 01:26:52 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6282 [merge]
revision-id: pqm at pqm.ubuntu.com-20111121012651-prdfm12cb04wtdkm
parent: pqm at pqm.ubuntu.com-20111121003254-321qb4a08o2a3cji
parent: matt.giuca at gmail.com-20111121001858-fsnlj953eswlc8y2
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-11-21 01:26:51 +0000
message:
(jelmer) Improve parsing of commit times in --commit-time argument for ``bzr
commit``. (Matt Giuca)
modified:
bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
bzrlib/tests/test_timestamp.py test_timestamp.py-20070306153932-r3ejn242c20asagv-1
bzrlib/timestamp.py timestamp.py-20070306142322-ttbb9oulf3jotljd-1
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py 2011-09-02 07:38:52 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py 2011-11-20 01:50:38 +0000
@@ -704,6 +704,18 @@
self.assertStartsWith(
err, "bzr: ERROR: Could not parse --commit-time:")
+ def test_commit_time_missing_tz(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/hello.txt'])
+ tree.add('hello.txt')
+ out, err = self.run_bzr("commit -m hello "
+ "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
+ self.assertStartsWith(
+ err, "bzr: ERROR: Could not parse --commit-time:")
+ # Test that it is actually checking and does not simply crash with
+ # some other exception
+ self.assertContainsString(err, "missing a timezone offset")
+
def test_partial_commit_with_renames_in_tree(self):
# this test illustrates bug #140419
t = self.make_branch_and_tree('.')
=== modified file 'bzrlib/tests/test_timestamp.py'
--- a/bzrlib/tests/test_timestamp.py 2011-01-10 22:20:12 +0000
+++ b/bzrlib/tests/test_timestamp.py 2011-11-20 01:49:32 +0000
@@ -58,6 +58,45 @@
# offset of three minutes
self.assertEqual((1173193459, +3 * 60),
timestamp.parse_patch_date('2007-03-06 15:07:19 +0003'))
+ # No space between time and offset
+ self.assertEqual((1173193459, -5 * 3600),
+ timestamp.parse_patch_date('2007-03-06 10:04:19-0500'))
+ # Extra spacing
+ self.assertEqual((1173193459, -5 * 3600),
+ timestamp.parse_patch_date('2007-03-06 10:04:19 -0500'))
+
+ def test_parse_patch_date_bad(self):
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ 'NOT A TIME')
+ # Extra data at end
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 -0500x')
+ # Missing day
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03 10:04:19 -0500')
+ # Missing seconds
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04 -0500')
+ # Missing offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19')
+ # Missing plus or minus in offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 0500')
+ # Invalid hour in offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 +2400')
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 -2400')
+ # Invalid minute in offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 -0560')
+ # Too many digits in offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 79500')
+ # Minus sign in middle of offset
+ self.assertRaises(ValueError, timestamp.parse_patch_date,
+ '2007-03-06 10:04:19 +05-5')
class UnpackHighresDateTests(tests.TestCase):
=== modified file 'bzrlib/timestamp.py'
--- a/bzrlib/timestamp.py 2011-01-10 22:20:12 +0000
+++ b/bzrlib/timestamp.py 2011-11-20 01:50:38 +0000
@@ -16,6 +16,7 @@
import calendar
import time
+import re
from bzrlib import osutils
@@ -124,18 +125,30 @@
date_fmt='%Y-%m-%d %H:%M:%S')
+# Format for patch dates: %Y-%m-%d %H:%M:%S [+-]%H%M
+# Groups: 1 = %Y-%m-%d %H:%M:%S; 2 = [+-]%H; 3 = %M
+RE_PATCHDATE = re.compile("(\d+-\d+-\d+\s+\d+:\d+:\d+)\s*([+-]\d\d)(\d\d)$")
+RE_PATCHDATE_NOOFFSET = re.compile("\d+-\d+-\d+\s+\d+:\d+:\d+$")
+
def parse_patch_date(date_str):
"""Parse a patch-style date into a POSIX timestamp and offset.
Inverse of format_patch_date.
"""
- secs_str = date_str[:-6]
- offset_str = date_str[-5:]
- if len(offset_str) != 5:
- raise ValueError(
- "invalid timezone %r" % offset_str)
- offset_hours, offset_mins = offset_str[:3], offset_str[3:]
- offset = int(offset_hours) * 3600 + int(offset_mins) * 60
+ match = RE_PATCHDATE.match(date_str)
+ if match is None:
+ if RE_PATCHDATE_NOOFFSET.match(date_str) is not None:
+ raise ValueError("time data %r is missing a timezone offset"
+ % date_str)
+ else:
+ raise ValueError("time data %r does not match format " % date_str
+ + "'%Y-%m-%d %H:%M:%S %z'")
+ secs_str = match.group(1)
+ offset_hours, offset_mins = int(match.group(2)), int(match.group(3))
+ if abs(offset_hours) >= 24 or offset_mins >= 60:
+ raise ValueError("invalid timezone %r" %
+ (match.group(2) + match.group(3)))
+ offset = offset_hours * 3600 + offset_mins * 60
tm_time = time.strptime(secs_str, '%Y-%m-%d %H:%M:%S')
# adjust seconds according to offset before converting to POSIX
# timestamp, to avoid edge problems
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-11-18 14:37:41 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-11-21 00:18:58 +0000
@@ -50,6 +50,11 @@
* Support verifying signatures on remote repositories.
(Jelmer Vernooij, #889694)
+* Fixed parsing of the timestamp given to ``commit --commit-time``. Now
+ prohibits several invalid strings, reads the correct number of seconds,
+ and gives a better error message if the time zone offset is not given.
+ (Matt Giuca, #892657)
+
Documentation
*************
More information about the bazaar-commits
mailing list