[PATCH] mq: gracefully handle malformated status file
Pierre-Yves David
pierre-yves.david at logilab.fr
Mon Feb 28 04:51:45 CST 2011
I'm resending this small patch making mq more robust.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1297426239 -3600
# Branch stable
# Node ID 13ce20da49086647b98883aa0c239f85242bbe05
# Parent 02aa06a021a066cb360dc71097dedfa3ef123bb2
mq: gracefully handle malformated status file.
This patch prevent mq to crash when .hg/patches/status contains Malformed lines
(without ":"). Blank lines are ignored and other malformed lines issue a
warning.
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -269,11 +269,17 @@
@util.propertycache
def applied(self):
if os.path.exists(self.join(self.status_path)):
- def parse(l):
- n, name = l.split(':', 1)
- return statusentry(bin(n), name)
+ def parselines(lines):
+ for l in lines:
+ entry = l.split(':', 1)
+ if len(entry) > 1:
+ n, name= entry
+ yield statusentry(bin(n), name)
+ elif l.strip():
+ self.ui.warn(_('malformated mq status line: %s\n') % entry)
+ # else we ignore empty lines
lines = self.opener(self.status_path).read().splitlines()
- return [parse(l) for l in lines]
+ return list(parselines(lines))
return []
@util.propertycache
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -917,6 +917,25 @@
copy to copy
$ cd ..
+empty lines in status
+
+ $ hg init emptystatus
+ $ cd emptystatus
+ $ hg qinit
+ $ echo '\n\n' > .hg/patches/status
+ $ hg qser
+ $ cd ..
+
+bad line in status (without ":")
+
+ $ hg init badstatus
+ $ cd badstatus
+ $ hg qinit
+ $ echo 'babar has no colon in this line\n' > .hg/patches/status
+ $ hg qser
+ malformated mq status line: ['babar has no colon in this line']
+ $ cd ..
+
test file addition in slow path
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110228/6850bd99/attachment.pgp>
More information about the Mercurial-devel
mailing list