Patchwork [2,of,4] local-clone: extract the listing of caches to copy

login
register
mail settings
Submitter Pierre-Yves David
Date May 25, 2017, 10:56 a.m.
Message ID <92bfcf826e4613c6d80a.1495709771@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20898/
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 1495706347 -7200
#      Thu May 25 11:59:07 2017 +0200
# Node ID 92bfcf826e4613c6d80afce8b6e3cad37539ca69
# Parent  ee0b94add82334b4bae4603837fbc0244502a03b
# 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 92bfcf826e46
local-clone: extract the listing of caches to copy

Right now, the clone only copy the branchmap caches. There are multiple other
valuable caches that we should copy and extension might adds their own. So we
add a function to list the cache files to copy from the repository. The
repository argument is unused but extension will want it.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -420,6 +420,14 @@  def _copycache(srcrepo, dstcachedir, fna
             os.mkdir(dstcachedir)
         util.copyfile(srcbranchcache, dstbranchcache)
 
+def _cachetocopy(srcrepo):
+    """return the list of cache file valuable to copy during a clone"""
+    # In local clones we're copying all nodes, not just served
+    # ones. Therefore copy all branch caches over.
+    cachefiles = ['branch2']
+    cachefiles.extend('branch2-%s' % f for f in repoview.filtertable)
+    return cachefiles
+
 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.
@@ -578,11 +586,8 @@  def clone(ui, peeropts, source, dest=Non
                 util.copyfile(srcbookmarks, dstbookmarks)
 
             dstcachedir = os.path.join(destpath, 'cache')
-            # In local clones we're copying all nodes, not just served
-            # ones. Therefore copy all branch caches over.
-            _copycache(srcrepo, dstcachedir, 'branch2')
-            for cachename in repoview.filtertable:
-                _copycache(srcrepo, dstcachedir, 'branch2-%s' % cachename)
+            for cache in _cachetocopy(srcrepo):
+                _copycache(srcrepo, dstcachedir, cache)
 
             # we need to re-init the repo after manually copying the data
             # into it