# HG changeset patch # User Pierre-Yves David # Date 2011-02-11 12:10:39 # Node ID 375ba42f3cda34a540a4a46f4c0a63893c3c2907 # Parent 117990768fe0a2ed80e5c90505e31ce92e6172a5 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 @@ -282,11 +282,17 @@ class queue(object): @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 @@ bad node in status 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