Patchwork [1,of,4] local-clone: extract the closure copying caches

login
register
mail settings
Submitter Pierre-Yves David
Date May 25, 2017, 10:56 a.m.
Message ID <ee0b94add82334b4bae4.1495709770@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20896/
State Accepted
Headers show

Comments

Pierre-Yves David - May 25, 2017, 10:56 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1495706100 -7200
#      Thu May 25 11:55:00 2017 +0200
# Node ID ee0b94add82334b4bae4603837fbc0244502a03b
# Parent  548478efc46c6147e9c2781cf70477b3461b440d
# EXP-Topic clone-caches
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r ee0b94add823
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.
Yuya Nishihara - May 28, 2017, 1:51 p.m.
On Thu, 25 May 2017 12:56:10 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1495706100 -7200
> #      Thu May 25 11:55:00 2017 +0200
> # Node ID ee0b94add82334b4bae4603837fbc0244502a03b
> # Parent  548478efc46c6147e9c2781cf70477b3461b440d
> # EXP-Topic clone-caches
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r ee0b94add823
> local-clone: extract the closure copying caches

Looks good. Queued, thanks.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -409,6 +409,17 @@  def clonewithshare(ui, peeropts, sharepa
 
     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 @@  def clone(ui, peeropts, source, dest=Non
             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