Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 32492:963de566de2f
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.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 25 May 2017 11:55:00 +0200 |
parents | 71e735bd8170 |
children | 3c8a71a8df11 |
comparison
equal
deleted
inserted
replaced
32491:f2116efd2c3a | 32492:963de566de2f |
---|---|
407 | 407 |
408 _postshareupdate(destrepo, update) | 408 _postshareupdate(destrepo, update) |
409 | 409 |
410 return srcpeer, peer(ui, peeropts, dest) | 410 return srcpeer, peer(ui, peeropts, dest) |
411 | 411 |
412 # Recomputing branch cache might be slow on big repos, | |
413 # so just copy it | |
414 def _copycache(srcrepo, dstcachedir, fname): | |
415 """copy a cache from srcrepo to destcachedir (if it exists)""" | |
416 srcbranchcache = srcrepo.vfs.join('cache/%s' % fname) | |
417 dstbranchcache = os.path.join(dstcachedir, fname) | |
418 if os.path.exists(srcbranchcache): | |
419 if not os.path.exists(dstcachedir): | |
420 os.mkdir(dstcachedir) | |
421 util.copyfile(srcbranchcache, dstbranchcache) | |
422 | |
412 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, | 423 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, |
413 update=True, stream=False, branch=None, shareopts=None): | 424 update=True, stream=False, branch=None, shareopts=None): |
414 """Make a copy of an existing repository. | 425 """Make a copy of an existing repository. |
415 | 426 |
416 Create a copy of an existing repository in a new directory. The | 427 Create a copy of an existing repository in a new directory. The |
564 srcbookmarks = srcrepo.vfs.join('bookmarks') | 575 srcbookmarks = srcrepo.vfs.join('bookmarks') |
565 dstbookmarks = os.path.join(destpath, 'bookmarks') | 576 dstbookmarks = os.path.join(destpath, 'bookmarks') |
566 if os.path.exists(srcbookmarks): | 577 if os.path.exists(srcbookmarks): |
567 util.copyfile(srcbookmarks, dstbookmarks) | 578 util.copyfile(srcbookmarks, dstbookmarks) |
568 | 579 |
569 # Recomputing branch cache might be slow on big repos, | |
570 # so just copy it | |
571 def copybranchcache(fname): | |
572 srcbranchcache = srcrepo.vfs.join('cache/%s' % fname) | |
573 dstbranchcache = os.path.join(dstcachedir, fname) | |
574 if os.path.exists(srcbranchcache): | |
575 if not os.path.exists(dstcachedir): | |
576 os.mkdir(dstcachedir) | |
577 util.copyfile(srcbranchcache, dstbranchcache) | |
578 | |
579 dstcachedir = os.path.join(destpath, 'cache') | 580 dstcachedir = os.path.join(destpath, 'cache') |
580 # In local clones we're copying all nodes, not just served | 581 # In local clones we're copying all nodes, not just served |
581 # ones. Therefore copy all branch caches over. | 582 # ones. Therefore copy all branch caches over. |
582 copybranchcache('branch2') | 583 _copycache(srcrepo, dstcachedir, 'branch2') |
583 for cachename in repoview.filtertable: | 584 for cachename in repoview.filtertable: |
584 copybranchcache('branch2-%s' % cachename) | 585 _copycache(srcrepo, dstcachedir, 'branch2-%s' % cachename) |
585 | 586 |
586 # we need to re-init the repo after manually copying the data | 587 # we need to re-init the repo after manually copying the data |
587 # into it | 588 # into it |
588 destpeer = peer(srcrepo, peeropts, dest) | 589 destpeer = peer(srcrepo, peeropts, dest) |
589 srcrepo.hook('outgoing', source='clone', | 590 srcrepo.hook('outgoing', source='clone', |