changeset 32493:3c8a71a8df11

local-clone: extract the listing of caches to copy Right now, the clone only copies the branchmap caches. There are multiple other valuable caches that we should copy and extensions might add their own. So we add a function to list the cache files to copy from the repository. The repository argument is unused but extensions will want it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 25 May 2017 11:59:07 +0200
parents 963de566de2f
children 53a67ba9fb44
files mercurial/hg.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Thu May 25 11:55:00 2017 +0200
+++ b/mercurial/hg.py	Thu May 25 11:59:07 2017 +0200
@@ -420,6 +420,14 @@
             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 @@
                 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