mq: gracefully handle malformated status file stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Fri, 11 Feb 2011 13:10:39 +0100
branchstable
changeset 13507 375ba42f3cda
parent 13506 117990768fe0
child 13508 0396ca8015be
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.
hgext/mq.py
tests/test-mq.t
--- a/hgext/mq.py	Thu Feb 24 00:47:49 2011 +0100
+++ b/hgext/mq.py	Fri Feb 11 13:10:39 2011 +0100
@@ -282,11 +282,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
--- a/tests/test-mq.t	Thu Feb 24 00:47:49 2011 +0100
+++ b/tests/test-mq.t	Fri Feb 11 13:10:39 2011 +0100
@@ -917,6 +917,25 @@
   copy to copy
   $ cd ..
 
+empty lines in status
+
+  $ hg init emptystatus
+  $ cd emptystatus
+  $ hg qinit
+  $ printf '\n\n' > .hg/patches/status
+  $ hg qser
+  $ cd ..
+
+bad line in status (without ":")
+
+  $ hg init badstatus
+  $ cd badstatus
+  $ hg qinit
+  $ printf '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