Patchwork [5,of,6,v2] convert: refactor hg getchanges and caching

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 26, 2014, 8:04 p.m.
Message ID <9022fa68bb471e2b8fcc.1409083445@mk-desktop>
Download mbox | patch
Permalink /patch/5605/
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 9022fa68bb471e2b8fcc136f4e371aad45c81b0e
# Parent  9213de9f67fc9f8febec8a7cb816ab50c952a79f
convert: refactor hg getchanges and caching

Patch

diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -301,7 +301,7 @@  class mercurial_source(converter_source)
             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 @@  class mercurial_source(converter_source)
         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 = {}