convert: better mapfile parsing errors (issue1581/1)
authorPatrick Mezard <pmezard@gmail.com>
Sat, 11 Apr 2009 21:15:27 +0200
changeset 8047 04c62275cbc7
parent 8046 f3ef8a352d83
child 8048 d22432bdcba1
convert: better mapfile parsing errors (issue1581/1)
hgext/convert/common.py
tests/test-convert-splicemap
tests/test-convert-splicemap.out
--- a/hgext/convert/common.py	Sat Apr 11 20:49:47 2009 +0200
+++ b/hgext/convert/common.py	Sat Apr 11 21:15:27 2009 +0200
@@ -333,8 +333,12 @@
             if err.errno != errno.ENOENT:
                 raise
             return
-        for line in fp:
-            key, value = strutil.rsplit(line[:-1], ' ', 1)
+        for i, line in enumerate(fp):
+            try:
+                key, value = strutil.rsplit(line[:-1], ' ', 1)
+            except ValueError:
+                raise util.Abort(_('syntax error in %s(%d): key/value pair expected')
+                                 % (self.path, i+1))
             if key not in self:
                 self.order.append(key)
             super(mapfile, self).__setitem__(key, value)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-convert-splicemap	Sat Apr 11 21:15:27 2009 +0200
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "convert=" >> $HGRCPATH
+echo 'hgext.graphlog =' >> $HGRCPATH
+
+glog()
+{
+    hg glog --template '#rev# "#desc|firstline#" files: #files#\n' "$@"
+}
+
+hg init repo1
+cd repo1
+echo a > a
+hg ci -Am adda
+echo b > b
+echo a >> a
+hg ci -Am addb
+PARENTID1=`hg id --debug -i`
+echo c > c
+hg ci -Am addc
+PARENTID2=`hg id --debug -i`
+cd ..
+
+hg init repo2
+cd repo2
+echo b > a
+echo d > d
+hg ci -Am addaandd
+CHILDID1=`hg id --debug -i`
+echo d >> d
+hg ci -Am changed
+CHILDID2=`hg id --debug -i`
+echo e > e
+hg ci -Am adde
+cd ..
+
+echo '% test invalid splicemap'
+cat > splicemap <<EOF
+$CHILDID2
+EOF
+hg convert --splicemap splicemap repo2 repo1
+
+echo '% splice repo2 on repo1'
+cat > splicemap <<EOF
+$CHILDID1 $PARENTID1
+$CHILDID2 $PARENTID2,$CHILDID1
+EOF
+hg clone repo1 target1
+hg convert --splicemap splicemap repo2 target1
+glog -R target1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-convert-splicemap.out	Sat Apr 11 21:15:27 2009 +0200
@@ -0,0 +1,31 @@
+adding a
+adding b
+adding c
+adding a
+adding d
+adding e
+% test invalid splicemap
+abort: syntax error in splicemap(1): key/value pair expected
+% splice repo2 on repo1
+updating working directory
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+scanning source...
+sorting...
+converting...
+2 addaandd
+spliced in ['6d4c2037ddc2cb2627ac3a244ecce35283268f8e'] as parents of 527cdedf31fbd5ea708aa14eeecf53d4676f38db
+1 changed
+spliced in ['e55c719b85b60e5102fac26110ba626e7cb6b7dc', '527cdedf31fbd5ea708aa14eeecf53d4676f38db'] as parents of e4ea00df91897da3079a10fab658c1eddba6617b
+0 adde
+o  5 "adde" files: e
+|
+o    4 "changed" files: d
+|\
+| o  3 "addaandd" files: a d
+| |
+@ |  2 "addc" files: c
+|/
+o  1 "addb" files: a b
+|
+o  0 "adda" files: a
+