[PATCH 1 of 2] convert: turn splicemap into a simple dictionary

Patrick Mezard patrick at mezard.eu
Fri Feb 10 21:37:42 UTC 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1328909149 -3600
# Branch stable
# Node ID 37dd899d0f1d7e9e4b032da74b1aee9ee7a0385a
# Parent  20ad8f0512a2ea61a019a02c1ffd05a8f6e770f7
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.

diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -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
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -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]
diff --git a/tests/test-convert-splicemap.t b/tests/test-convert-splicemap.t
--- a/tests/test-convert-splicemap.t
+++ b/tests/test-convert-splicemap.t
@@ -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



More information about the Mercurial-devel mailing list