changeset 46124:5b9bb4e9a3bf

share: properly copy cache files when cloning from a share If a is shared to b and b cloned to c, the old code would look directly under b/.hg for the cache directory and not use the cachevfs layer to pick the members from a/.hg/cache. Adjust variable names and comments to reflect that the function is used for more than just the branchmap cache. Differential Revision: https://phab.mercurial-scm.org/D9598
author Joerg Sonnenberger <joerg@bec.de>
date Mon, 14 Dec 2020 19:48:35 +0100
parents 1b5aeb928c8f
children ceaf1646f420
files mercurial/hg.py tests/test-share.t
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Mon Dec 14 18:19:58 2020 +0100
+++ b/mercurial/hg.py	Mon Dec 14 19:48:35 2020 +0100
@@ -594,16 +594,15 @@
     return srcpeer, peer(ui, peeropts, dest)
 
 
-# Recomputing branch cache might be slow on big repos,
-# so just copy it
+# Recomputing caches is often slow on big repos, so copy them.
 def _copycache(srcrepo, dstcachedir, fname):
     """copy a cache from srcrepo to destcachedir (if it exists)"""
-    srcbranchcache = srcrepo.vfs.join(b'cache/%s' % fname)
-    dstbranchcache = os.path.join(dstcachedir, fname)
-    if os.path.exists(srcbranchcache):
+    srcfname = srcrepo.cachevfs.join(fname)
+    dstfname = os.path.join(dstcachedir, fname)
+    if os.path.exists(srcfname):
         if not os.path.exists(dstcachedir):
             os.mkdir(dstcachedir)
-        util.copyfile(srcbranchcache, dstbranchcache)
+        util.copyfile(srcfname, dstfname)
 
 
 def clone(
--- a/tests/test-share.t	Mon Dec 14 18:19:58 2020 +0100
+++ b/tests/test-share.t	Mon Dec 14 19:48:35 2020 +0100
@@ -56,6 +56,17 @@
   rbc-revs-v1
   tags2-visible
 
+Cloning a shared repo should pick up the full cache dir on the other hand.
+
+  $ hg clone . ../repo2-clone
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ ls -1 ../repo2-clone/.hg/cache
+  branch2-served
+  rbc-names-v1
+  rbc-revs-v1
+  tags2-visible
+
 Some sed versions appends newline, some don't, and some just fails
 
   $ cat .hg/sharedpath; echo