hgext/convert/common.py
branchstable
changeset 16105 ebaa0aa749e2
parent 15791 a814f8fcc65a
child 16106 d75aa756149b
--- 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