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

Kostia Balytskyi kobalyts at outlook.com
Wed Dec 7 17:11:46 EST 2016



On 12/7/16 9:51 PM, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <davidsp at 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 at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list