Patchwork [5,of,8,v4] convert: allow passing in a revmap

login
register
mail settings
Submitter David Soria Parra
Date Dec. 14, 2016, 9:46 a.m.
Message ID <4b9d267d2a05970d9320.1481708801@devbig415.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17894/
State Superseded
Headers show

Comments

David Soria Parra - Dec. 14, 2016, 9:46 a.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1481708757 28800
#      Wed Dec 14 01:45:57 2016 -0800
# Node ID 4b9d267d2a05970d9320b83f8bf29ec99f8ab40f
# Parent  92b0ad25b4aca99c74d3813ddae163324c1110a7
convert: allow passing in a revmap

Implement `common.setrevmap` which is used to pass in a file with existing
revision mappings. This functionality is used by `convertcmd.convert` if it
exists and allows implementors such as the p4 converter to make use of an
existing mapping.

We are using the revmap to abort scanning and the repository for more information
if we already have the revision. This means we are allowing incremental imports
in cases where a revmap is provided.

Patch

diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py
--- a/hgext/convert/p4.py
+++ b/hgext/convert/p4.py
@@ -55,6 +55,7 @@ 
 
         common.checktool('p4', abort=False)
 
+        self.revmap = {}
         self.p4changes = {}
         self.heads = []
         self.changeset = {}
@@ -77,6 +78,19 @@ 
                                "multiple revisions"))
         self._parse(ui, path)
 
+    def setrevmap(self, revmap):
+        """Sets the parsed revmap dictionary.
+
+        Revmap stores mappings from a source revision to a target revision.
+        It is set in convertcmd.convert and provided by the user as a file
+        on the commandline.
+
+        Revisions in the map are considered beeing present in the
+        repository and ignored during _parse(). This allows for incremental
+        imports if a revmap is provided.
+        """
+        self.revmap = revmap
+
     def _parse_view(self, path):
         "Read changes affecting the path"
         cmd = 'p4 -G changes -s submitted %s' % util.shellquote(path)
@@ -132,6 +146,10 @@ 
                 continue
             if self.revs and int(change) > int(self.revs[0]):
                 continue
+            if change in self.revmap:
+                # Ignore already present revisions, but set the parent pointer.
+                lastid = change
+                continue
 
             cmd = "p4 -G describe -s %s" % change
             stdout = util.popen(cmd, mode='rb')