convert: turn splicemap into a simple dictionary
Parsing the splicemap as a mapfile was a pain because map does not let us
override its parsing code and splicemap entries are not key/values. Besides we
had no need for mapfiles extra features. Just parse the splicemap and return a
dictionary.
--- a/hgext/convert/common.py Fri Feb 10 14:46:09 2012 +0100
+++ b/hgext/convert/common.py Fri Feb 10 22:25:49 2012 +0100
@@ -407,3 +407,25 @@
if self.fp:
self.fp.close()
self.fp = None
+
+def parsesplicemap(path):
+ """Parse a splicemap, return a child/parents dictionary."""
+ m = {}
+ try:
+ fp = open(path, 'r')
+ for i, line in enumerate(fp):
+ try:
+ child, parents = line.splitlines()[0].rstrip().rsplit(' ', 1)
+ parents = parents.replace(',', ' ').split()
+ except ValueError:
+ raise util.Abort(_('syntax error in %s(%d): child parent1'
+ '[,parent2] expected') % (path, i + 1))
+ pp = []
+ for p in parents:
+ if p not in pp:
+ pp.append(p)
+ m[child] = pp
+ except IOError, e:
+ if e.errno != errno.ENOENT:
+ raise
+ return m
--- a/hgext/convert/convcmd.py Fri Feb 10 14:46:09 2012 +0100
+++ b/hgext/convert/convcmd.py Fri Feb 10 22:25:49 2012 +0100
@@ -15,7 +15,7 @@
from gnuarch import gnuarch_source
from bzr import bzr_source
from p4 import p4_source
-import filemap
+import filemap, common
import os, shutil
from mercurial import hg, util, encoding
@@ -118,7 +118,7 @@
self.readauthormap(opts.get('authormap'))
self.authorfile = self.dest.authorfile()
- self.splicemap = mapfile(ui, opts.get('splicemap'))
+ self.splicemap = common.parsesplicemap(opts.get('splicemap'))
self.branchmap = mapfile(ui, opts.get('branchmap'))
def walktree(self, heads):
@@ -319,7 +319,7 @@
self.commitcache[prev].branch))
self.dest.setbranch(commit.branch, pbranches)
try:
- parents = self.splicemap[rev].replace(',', ' ').split()
+ parents = self.splicemap[rev]
self.ui.status(_('spliced in %s as parents of %s\n') %
(parents, rev))
parents = [self.map.get(p, p) for p in parents]
--- a/tests/test-convert-splicemap.t Fri Feb 10 14:46:09 2012 +0100
+++ b/tests/test-convert-splicemap.t Fri Feb 10 22:25:49 2012 +0100
@@ -43,7 +43,7 @@
> $CHILDID2
> EOF
$ hg convert --splicemap splicemap repo2 repo1
- abort: syntax error in splicemap(1): key/value pair expected
+ abort: syntax error in splicemap(1): child parent1[,parent2] expected
[255]
splice repo2 on repo1