changeset 32492:963de566de2f

local-clone: extract the closure copying caches Closures often get on the way. They are not much value in having that as a closure so I'm extracting it at the module level.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 25 May 2017 11:55:00 +0200
parents f2116efd2c3a
children 3c8a71a8df11
files mercurial/hg.py
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Thu May 25 19:38:00 2017 +0200
+++ b/mercurial/hg.py	Thu May 25 11:55:00 2017 +0200
@@ -409,6 +409,17 @@
 
     return srcpeer, peer(ui, peeropts, dest)
 
+# Recomputing branch cache might be slow on big repos,
+# so just copy it
+def _copycache(srcrepo, dstcachedir, fname):
+    """copy a cache from srcrepo to destcachedir (if it exists)"""
+    srcbranchcache = srcrepo.vfs.join('cache/%s' % fname)
+    dstbranchcache = os.path.join(dstcachedir, fname)
+    if os.path.exists(srcbranchcache):
+        if not os.path.exists(dstcachedir):
+            os.mkdir(dstcachedir)
+        util.copyfile(srcbranchcache, dstbranchcache)
+
 def clone(ui, peeropts, source, dest=None, pull=False, rev=None,
           update=True, stream=False, branch=None, shareopts=None):
     """Make a copy of an existing repository.
@@ -566,22 +577,12 @@
             if os.path.exists(srcbookmarks):
                 util.copyfile(srcbookmarks, dstbookmarks)
 
-            # Recomputing branch cache might be slow on big repos,
-            # so just copy it
-            def copybranchcache(fname):
-                srcbranchcache = srcrepo.vfs.join('cache/%s' % fname)
-                dstbranchcache = os.path.join(dstcachedir, fname)
-                if os.path.exists(srcbranchcache):
-                    if not os.path.exists(dstcachedir):
-                        os.mkdir(dstcachedir)
-                    util.copyfile(srcbranchcache, dstbranchcache)
-
             dstcachedir = os.path.join(destpath, 'cache')
             # In local clones we're copying all nodes, not just served
             # ones. Therefore copy all branch caches over.
-            copybranchcache('branch2')
+            _copycache(srcrepo, dstcachedir, 'branch2')
             for cachename in repoview.filtertable:
-                copybranchcache('branch2-%s' % cachename)
+                _copycache(srcrepo, dstcachedir, 'branch2-%s' % cachename)
 
             # we need to re-init the repo after manually copying the data
             # into it