# HG changeset patch # User Pierre-Yves David # Date 1297426239 -3600 # 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 -r 117990768fe0 -r 375ba42f3cda hgext/mq.py --- 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 diff -r 117990768fe0 -r 375ba42f3cda tests/test-mq.t --- 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