Patchwork [4,of,6,v3] convert: Parse perforce changes when needed, not in the constructor

login
register
mail settings
Submitter David Soria Parra
Date Dec. 7, 2016, 9:51 p.m.
Message ID <e3c34b2fafd7ce1a78d2.1481147514@devbig415.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17873/
State Superseded
Headers show

Comments

David Soria Parra - Dec. 7, 2016, 9:51 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1481139471 28800
#      Wed Dec 07 11:37:51 2016 -0800
# Node ID e3c34b2fafd7ce1a78d23e35888a33ef10629fbf
# Parent  897be730ab884aa8f7373a34eeb6a288cc1dabc7
convert: Parse perforce changes when needed, not in the constructor

The perforce source is parsing all changes in the constructor and not deferring
it to when needed. This leads to the source parsing changes before the revmap
is available. Let's move the parsing to when we need it the first time.
Kostia Balytskyi - Dec. 7, 2016, 10:11 p.m.
On 12/7/16 9:51 PM, David Soria Parra wrote:
> # HG changeset patch

> # User David Soria Parra <davidsp@fb.com>

> # Date 1481139471 28800

> #      Wed Dec 07 11:37:51 2016 -0800

> # Node ID e3c34b2fafd7ce1a78d23e35888a33ef10629fbf

> # Parent  897be730ab884aa8f7373a34eeb6a288cc1dabc7

> convert: Parse perforce changes when needed, not in the constructor

>

> The perforce source is parsing all changes in the constructor and not deferring

> it to when needed. This leads to the source parsing changes before the revmap

> is available. Let's move the parsing to when we need it the first time.

>

> diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py

> --- a/hgext/convert/p4.py

> +++ b/hgext/convert/p4.py

> @@ -79,7 +79,6 @@

>           if revs and len(revs) > 1:

>               raise error.Abort(_("p4 source does not support specifying "

>                                  "multiple revisions"))

> -        self._parse(ui, path)

>   

>       def setrevmap(self, revmap):

>           self.revmap = revmap

> @@ -224,6 +223,8 @@

>               self.heads = [lastid]

>   

>       def getheads(self):

> +        if len(self.p4changes) == 0:

> +            self._parse(self.ui, self.path)

I think this could be implemented as a lazy property for less duplication.
>           return self.heads

>   

>       def getfile(self, name, rev):

> @@ -299,7 +300,11 @@

>           return self.changeset[rev]

>   

>       def gettags(self):

> +        if len(self.p4changes) == 0:

> +            self._parse(self.ui, self.path)

>           return self.tags

>   

>       def getchangedfiles(self, rev, i):

> +        if len(self.p4changes) == 0:

> +            self._parse(self.ui, self.path)

>           return sorted([x[0] for x in self.files[rev]])

> _______________________________________________

> Mercurial-devel mailing list

> Mercurial-devel@mercurial-scm.org

> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py
--- a/hgext/convert/p4.py
+++ b/hgext/convert/p4.py
@@ -79,7 +79,6 @@ 
         if revs and len(revs) > 1:
             raise error.Abort(_("p4 source does not support specifying "
                                "multiple revisions"))
-        self._parse(ui, path)
 
     def setrevmap(self, revmap):
         self.revmap = revmap
@@ -224,6 +223,8 @@ 
             self.heads = [lastid]
 
     def getheads(self):
+        if len(self.p4changes) == 0:
+            self._parse(self.ui, self.path)
         return self.heads
 
     def getfile(self, name, rev):
@@ -299,7 +300,11 @@ 
         return self.changeset[rev]
 
     def gettags(self):
+        if len(self.p4changes) == 0:
+            self._parse(self.ui, self.path)
         return self.tags
 
     def getchangedfiles(self, rev, i):
+        if len(self.p4changes) == 0:
+            self._parse(self.ui, self.path)
         return sorted([x[0] for x in self.files[rev]])