Mercurial > public > mercurial-scm > hg
comparison mercurial/branchmap.py @ 26460:79ef867538ea
branchmap: move branch cache code out of streamclone.py
This is low-level branch map and cache manipulation code. It deserves to
live next to similar code in branchmap.py. Moving it also paves the road
for multiple consumers, such as a bundle2 part handler that receives
branch mappings from a remote.
This is largely a mechanical move, with only variable names and
indentation being changed.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 03 Oct 2015 09:53:56 -0700 |
parents | 47f36e050c2e |
children | 56b2bcea2529 |
comparison
equal
deleted
inserted
replaced
26459:3b28ffde133a | 26460:79ef867538ea |
---|---|
114 partial.write(repo) | 114 partial.write(repo) |
115 | 115 |
116 assert partial.validfor(repo), filtername | 116 assert partial.validfor(repo), filtername |
117 repo._branchcaches[repo.filtername] = partial | 117 repo._branchcaches[repo.filtername] = partial |
118 | 118 |
119 def replacecache(repo, bm): | |
120 """Replace the branchmap cache for a repo with a branch mapping. | |
121 | |
122 This is likely only called during clone with a branch map from a remote. | |
123 """ | |
124 rbheads = [] | |
125 closed = [] | |
126 for bheads in bm.itervalues(): | |
127 rbheads.extend(bheads) | |
128 for h in bheads: | |
129 r = repo.changelog.rev(h) | |
130 b, c = repo.changelog.branchinfo(r) | |
131 if c: | |
132 closed.append(h) | |
133 | |
134 if rbheads: | |
135 rtiprev = max((int(repo.changelog.rev(node)) | |
136 for node in rbheads)) | |
137 cache = branchcache(bm, | |
138 repo[rtiprev].node(), | |
139 rtiprev, | |
140 closednodes=closed) | |
141 | |
142 # Try to stick it as low as possible | |
143 # filter above served are unlikely to be fetch from a clone | |
144 for candidate in ('base', 'immutable', 'served'): | |
145 rview = repo.filtered(candidate) | |
146 if cache.validfor(rview): | |
147 repo._branchcaches[candidate] = cache | |
148 cache.write(rview) | |
149 break | |
150 | |
119 class branchcache(dict): | 151 class branchcache(dict): |
120 """A dict like object that hold branches heads cache. | 152 """A dict like object that hold branches heads cache. |
121 | 153 |
122 This cache is used to avoid costly computations to determine all the | 154 This cache is used to avoid costly computations to determine all the |
123 branch heads of a repo. | 155 branch heads of a repo. |