convert: parse perforce data on-demand
We are using read-only attributes that parse the perforce data on
demand. We are reading the data only once whenever an attribute is
requested and use it throughout the import process. This is equivalent
to the previous behavior, but we are avoiding reading from perforce when
we initialize the object, but instead run it during the actual import
process, when the first attribute is requested (usually getheads(), see
`convertcmd.convert`).
--- a/hgext/convert/p4.py Tue Dec 20 09:23:50 2016 -0800
+++ b/hgext/convert/p4.py Tue Dec 20 09:23:50 2016 -0800
@@ -56,13 +56,8 @@
common.checktool('p4', abort=False)
self.revmap = {}
- self.heads = []
- self.changeset = {}
- self.files = {}
- self.copies = {}
self.encoding = self.ui.config('convert', 'p4.encoding',
default=convcmd.orig_encoding)
- self.depotname = {} # mapping from local name to depot name
self.re_type = re.compile(
"([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)"
"(\+\w+)?$")
@@ -74,7 +69,6 @@
if revs and len(revs) > 1:
raise error.Abort(_("p4 source does not support specifying "
"multiple revisions"))
- self._parse_once(ui, path)
def setrevmap(self, revmap):
"""Sets the parsed revmap dictionary.
@@ -240,13 +234,29 @@
'depotname': depotname,
}
- def _parse_once(self, ui, path):
- d = self._parse(ui, path)
- self.changeset = d['changeset']
- self.heads = d['heads']
- self.files = d['files']
- self.copies = d['copies']
- self.depotname = d['depotname']
+ @util.propertycache
+ def _parse_once(self):
+ return self._parse(self.ui, self.path)
+
+ @util.propertycache
+ def copies(self):
+ return self._parse_once['copies']
+
+ @util.propertycache
+ def files(self):
+ return self._parse_once['files']
+
+ @util.propertycache
+ def changeset(self):
+ return self._parse_once['changeset']
+
+ @util.propertycache
+ def heads(self):
+ return self._parse_once['heads']
+
+ @util.propertycache
+ def depotname(self):
+ return self._parse_once['depotname']
def getheads(self):
return self.heads
--- a/tests/test-convert-p4-filetypes.t Tue Dec 20 09:23:50 2016 -0800
+++ b/tests/test-convert-p4-filetypes.t Tue Dec 20 09:23:50 2016 -0800
@@ -307,11 +307,11 @@
convert
$ hg convert -s p4 $DEPOTPATH dst
initializing destination dst repository
+ scanning source...
reading p4 views
collecting p4 changelists
1 initial
2 keywords
- scanning source...
sorting...
converting...
1 initial
--- a/tests/test-convert-p4.t Tue Dec 20 09:23:50 2016 -0800
+++ b/tests/test-convert-p4.t Tue Dec 20 09:23:50 2016 -0800
@@ -67,12 +67,12 @@
convert
$ hg convert -s p4 $DEPOTPATH dst
initializing destination dst repository
+ scanning source...
reading p4 views
collecting p4 changelists
1 initial
2 change a
3 change b/c
- scanning source...
sorting...
converting...
2 initial
@@ -98,13 +98,10 @@
convert again
$ hg convert -s p4 $DEPOTPATH dst
+ scanning source...
reading p4 views
collecting p4 changelists
- 1 initial
- 2 change a
- 3 change b/c
4 change a b/c
- scanning source...
sorting...
converting...
0 change a b/c
@@ -130,14 +127,10 @@
convert again
$ hg convert -s p4 $DEPOTPATH dst
+ scanning source...
reading p4 views
collecting p4 changelists
- 1 initial
- 2 change a
- 3 change b/c
- 4 change a b/c
5 add d e f
- scanning source...
sorting...
converting...
0 add d e f