resolve: do not crash on empty mergestate
I managed to get an empty .hg/merge/state file by interrupting a merge
by pressing Control-C. This lead to this error:
TypeError: a2b_hex() argument 1 must be string or read-only buffer,
not None
since localnode is assigned None before the iteration over lines in
the mergestate begins.
--- a/mercurial/merge.py Wed Jun 23 16:54:12 2010 -1000
+++ b/mercurial/merge.py Sun Jun 27 23:12:05 2010 +0200
@@ -23,15 +23,13 @@
def _read(self):
self._state = {}
try:
- localnode = None
f = self._repo.opener("merge/state")
for i, l in enumerate(f):
if i == 0:
- localnode = l[:-1]
+ self._local = bin(l[:-1])
else:
bits = l[:-1].split("\0")
self._state[bits[0]] = bits[1:]
- self._local = bin(localnode)
except IOError, err:
if err.errno != errno.ENOENT:
raise
--- a/tests/test-resolve Wed Jun 23 16:54:12 2010 -1000
+++ b/tests/test-resolve Sun Jun 27 23:12:05 2010 +0200
@@ -25,3 +25,9 @@
echo % resolve -l, should be empty
hg resolve -l
+
+# test crashed merge with empty mergestate
+mkdir .hg/merge
+touch .hg/merge/state
+echo % resolve -l, should be empty
+hg resolve -l
--- a/tests/test-resolve.out Wed Jun 23 16:54:12 2010 -1000
+++ b/tests/test-resolve.out Sun Jun 27 23:12:05 2010 +0200
@@ -6,3 +6,4 @@
0 files updated, 0 files merged, 0 files removed, 1 files unresolved
use 'hg resolve' to retry unresolved file merges or 'hg update -C' to abandon
% resolve -l, should be empty
+% resolve -l, should be empty