changeset 22299:98aafdf4cbf6

convert: refactor hg getchanges and caching
author Mads Kiilerich <madski@unity3d.com>
date Tue, 26 Aug 2014 22:03:32 +0200
parents 4ba35d4298a0
children 35ab037de989
files hgext/convert/hg.py
diffstat 1 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Tue Aug 26 22:03:32 2014 +0200
+++ b/hgext/convert/hg.py	Tue Aug 26 22:03:32 2014 +0200
@@ -301,7 +301,7 @@
             raise NoRepo(_("%s is not a local Mercurial repository") % path)
         self.lastrev = None
         self.lastctx = None
-        self._changescache = None
+        self._changescache = None, None
         self.convertfp = None
         # Restrict converted revisions to startrev descendants
         startnode = ui.config('convert', 'hg.startrev')
@@ -360,22 +360,20 @@
         ctx = self.changectx(rev)
         parents = self.parents(ctx)
         if not parents:
-            files = sorted(ctx.manifest())
-            # getcopies() is not needed for roots, but it is a simple way to
-            # detect missing revlogs and abort on errors or populate
-            # self.ignored
-            self.getcopies(ctx, parents, files)
-            return [(f, rev) for f in files if f not in self.ignored], {}
-        if self._changescache and self._changescache[0] == rev:
-            m, a, r = self._changescache[1]
+            files = copyfiles = ctx.manifest()
         else:
-            m, a, r = self.repo.status(parents[0].node(), ctx.node())[:3]
-        # getcopies() detects missing revlogs early, run it before
-        # filtering the changes.
-        copies = self.getcopies(ctx, parents, m + a)
-        changes = [(name, rev) for name in m + a + r
-                   if name not in self.ignored]
-        return sorted(changes), copies
+            if self._changescache[0] == rev:
+                m, a, r = self._changescache[1]
+            else:
+                m, a, r = self.repo.status(parents[0].node(), ctx.node())[:3]
+            files = m + a + r
+            copyfiles = m + a
+        # getcopies() is also run for roots and before filtering so missing
+        # revlogs are detected early
+        copies = self.getcopies(ctx, parents, copyfiles)
+        changes = [(f, rev) for f in files if f not in self.ignored]
+        changes.sort()
+        return changes, copies
 
     def getcopies(self, ctx, parents, files):
         copies = {}