# HG changeset patch # User Pierre-Yves David # Date 2017-05-25 09:55:00 # Node ID 963de566de2f1d709c33c3c512cfa924544d132b # Parent f2116efd2c3abae0f99e2f610c2ff2feb237b628 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. 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