Patchwork [06,of,10] bundlerepo: use rev instead of node for iteration in revision()

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 16, 2013, 7:57 p.m.
Message ID <d99799fc4f359b6f756c.1358366250@mk-desktop>
Download mbox | patch
Permalink /patch/665/
State Accepted
Commit 95b8629fd2deda0c089895730e33f8b3ba03caf6
Headers show

Comments

Mads Kiilerich - Jan. 16, 2013, 7:57 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1358365301 -3600
# Node ID d99799fc4f359b6f756c1a147523b1eaf3cc084f
# Parent  c2b44c239c909a81fcc6bedc78125ac5c2f43aa8
bundlerepo: use rev instead of node for iteration in revision()

Avoids some lookups and avoids using rev while iterating.
tonfa - Jan. 16, 2013, 8:25 p.m.
On Wed, Jan 16, 2013 at 8:57 PM, Mads Kiilerich <mads@kiilerich.com> wrote:

> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1358365301 -3600
> # Node ID d99799fc4f359b6f756c1a147523b1eaf3cc084f
> # Parent  c2b44c239c909a81fcc6bedc78125ac5c2f43aa8
> bundlerepo: use rev instead of node for iteration in revision()
>
> Avoids some lookups and avoids using rev while iterating.
>
> diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
> --- a/mercurial/bundlerepo.py
> +++ b/mercurial/bundlerepo.py
> @@ -108,17 +108,16 @@
>
>          text = None
>          chain = []
> -        iter_node = node
> +        iterrev = rev
>          # reconstruct the revision if it is from a changegroup
> -        while rev in self.basemap:
> -            if self._cache and self._cache[0] == iter_node:
> +        while iterrev in self.basemap:
> +            if self._cache and self._cache[1] == iterrev:
>                  text = self._cache[2]
>                  break
> -            chain.append(rev)
> -            iter_node = self.basemap[rev]
> -            rev = self.rev(iter_node)
> +            chain.append(iterrev)
> +            iterrev = self.rev(self.basemap[rev])
>

self.basemap[iterrev] (it wasn't caught by any test?)


>          if text is None:
> -            text = revlog.revlog.revision(self, iter_node)
> +            text = revlog.revlog.revision(self, iterrev)
>
>          while chain:
>              delta = self._chunk(chain.pop())
> @@ -127,9 +126,9 @@
>          p1, p2 = self.parents(node)
>          if node != revlog.hash(text, p1, p2):
>              raise error.RevlogError(_("integrity check failed on %s:%d")
> -                                     % (self.datafile, self.rev(node)))
> +                                     % (self.datafile, rev))
>
> -        self._cache = (node, self.rev(node), text)
> +        self._cache = (node, rev, text)
>          return text
>
>      def addrevision(self, text, transaction, link, p1=None, p2=None,
> d=None):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -108,17 +108,16 @@ 
 
         text = None
         chain = []
-        iter_node = node
+        iterrev = rev
         # reconstruct the revision if it is from a changegroup
-        while rev in self.basemap:
-            if self._cache and self._cache[0] == iter_node:
+        while iterrev in self.basemap:
+            if self._cache and self._cache[1] == iterrev:
                 text = self._cache[2]
                 break
-            chain.append(rev)
-            iter_node = self.basemap[rev]
-            rev = self.rev(iter_node)
+            chain.append(iterrev)
+            iterrev = self.rev(self.basemap[rev])
         if text is None:
-            text = revlog.revlog.revision(self, iter_node)
+            text = revlog.revlog.revision(self, iterrev)
 
         while chain:
             delta = self._chunk(chain.pop())
@@ -127,9 +126,9 @@ 
         p1, p2 = self.parents(node)
         if node != revlog.hash(text, p1, p2):
             raise error.RevlogError(_("integrity check failed on %s:%d")
-                                     % (self.datafile, self.rev(node)))
+                                     % (self.datafile, rev))
 
-        self._cache = (node, self.rev(node), text)
+        self._cache = (node, rev, text)
         return text
 
     def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):