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

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 25, 2014, 1:23 a.m.
Message ID <ed84f46c12cf3ed3a8b9.1408929782@localhost.localdomain>
Download mbox | patch
Permalink /patch/5588/
State Superseded
Commit 98aafdf4cbf61410d817aceba5dda7b633ff15b3
Headers show

Comments

Mads Kiilerich - Aug. 25, 2014, 1:23 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1408929418 -7200
#      Mon Aug 25 03:16:58 2014 +0200
# Node ID ed84f46c12cf3ed3a8b9002cb867956a13536559
# Parent  5c37784b098f656208023290fb23836329b1e50b
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 = {}