Patchwork [4,of,6,v2] convert: refactor subversion getchanges and caching

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 26, 2014, 8:04 p.m.
Message ID <9213de9f67fc9f8febec.1409083444@mk-desktop>
Download mbox | patch
Permalink /patch/5604/
State Accepted
Headers show

Comments

Mads Kiilerich - Aug. 26, 2014, 8:04 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1409083412 -7200
#      Tue Aug 26 22:03:32 2014 +0200
# Node ID 9213de9f67fc9f8febec8a7cb816ab50c952a79f
# Parent  89a3f792fdfa7d31abc218f327e70a92c6565240
convert: refactor subversion getchanges and caching

Patch

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -347,7 +347,7 @@  class svn_source(converter_source):
                              % self.module)
         self.last_changed = self.revnum(self.head)
 
-        self._changescache = None
+        self._changescache = (None, None)
 
         if os.path.exists(os.path.join(url, '.svn/entries')):
             self.wc = url
@@ -444,10 +444,7 @@  class svn_source(converter_source):
 
         return self.heads
 
-    def getchanges(self, rev):
-        if self._changescache and self._changescache[0] == rev:
-            return self._changescache[1]
-        self._changescache = None
+    def _getchanges(self, rev):
         (paths, parents) = self.paths[rev]
         if parents:
             files, self.removed, copies = self.expandpaths(rev, paths, parents)
@@ -463,15 +460,23 @@  class svn_source(converter_source):
 
         files.sort()
         files = zip(files, [rev] * len(files))
+        return (files, copies)
 
-        # caller caches the result, so free it here to release memory
-        del self.paths[rev]
+    def getchanges(self, rev):
+        # reuse cache from getchangedfiles
+        if self._changescache[0] == rev:
+            (files, copies) = self._changescache[1]
+        else:
+            (files, copies) = self._getchanges(rev)
+            # caller caches the result, so free it here to release memory
+            del self.paths[rev]
         return (files, copies)
 
     def getchangedfiles(self, rev, i):
-        changes = self.getchanges(rev)
-        self._changescache = (rev, changes)
-        return [f[0] for f in changes[0]]
+        # called from filemap - cache computed values for reuse in getchanges
+        (files, copies) = self._getchanges(rev)
+        self._changescache = (rev, (files, copies))
+        return [f[0] for f in files]
 
     def getcommit(self, rev):
         if rev not in self.commits: