Mercurial > public > mercurial-scm > hg-stable
diff mercurial/localrepo.py @ 17740:e6067bec18da
branchcache: fetch source branchcache during clone (issue3378)
Recomputing branch cache on clone may be expensive,
therefore if possible we fetch it along with the data.
- If the clone is performed by copying, we just copy branchcache file.
- If we localrepo.clone and streaming then we follow the procedure:
1. Fetch branchmap from the remote
2. Fetch the actual data.
3. Find the latest rev within branch heads (tip at the time of
branchmap fetch)
4. Update the cache for the revs in [remotetip+1, tip]
This way we ensure that the branchcache is correct even in case
of races with commits.
author | Tomasz Kleczek <tomasz.kleczek@fb.com> |
---|---|
date | Wed, 03 Oct 2012 13:19:53 -0700 |
parents | 1adba7ff4d26 |
children | c547e1acc37c |
line wrap: on
line diff
--- a/mercurial/localrepo.py Wed Oct 10 01:30:45 2012 +0200 +++ b/mercurial/localrepo.py Wed Oct 03 13:19:53 2012 -0700 @@ -2472,6 +2472,12 @@ def stream_in(self, remote, requirements): lock = self.lock() try: + # Save remote branchmap. We will use it later + # to speed up branchcache creation + rbranchmap = None + if remote.capable("branchmap"): + rbranchmap = remote.branchmap() + fp = remote.stream_out() l = fp.readline() try: @@ -2532,6 +2538,17 @@ self._applyrequirements(requirements) self._writerequirements() + if rbranchmap: + rbheads = [] + for bheads in rbranchmap.itervalues(): + rbheads.extend(bheads) + + self.branchcache = rbranchmap + if rbheads: + rtiprev = max((int(self.changelog.rev(node)) + for node in rbheads)) + self._writebranchcache(self.branchcache, + self[rtiprev].node(), rtiprev) self.invalidate() return len(self.heads()) + 1 finally: