- Remove indentation where it is not needed.
- Swap the subset test branches to follow along logically and put the 'empty' case last.
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
# the ordering may be partial | # the ordering may be partial | ||||
subsettable = {None: 'visible', | subsettable = {None: 'visible', | ||||
'visible-hidden': 'visible', | 'visible-hidden': 'visible', | ||||
'visible': 'served', | 'visible': 'served', | ||||
'served': 'immutable', | 'served': 'immutable', | ||||
'immutable': 'base'} | 'immutable': 'base'} | ||||
def updatecache(repo): | def updatecache(repo): | ||||
"""Update the cache for the given filtered view on a repository""" | |||||
# This can trigger updates for the caches for subsets of the filtered | |||||
# view, e.g. when there is no cache for this filtered view or the cache | |||||
# is stale. | |||||
cl = repo.changelog | cl = repo.changelog | ||||
filtername = repo.filtername | filtername = repo.filtername | ||||
bcache = repo._branchcaches.get(filtername) | bcache = repo._branchcaches.get(filtername) | ||||
revs = [] | |||||
if bcache is None or not bcache.validfor(repo): | if bcache is None or not bcache.validfor(repo): | ||||
# cache object missing or cache object stale? Read from disk | |||||
bcache = branchcache.fromfile(repo) | bcache = branchcache.fromfile(repo) | ||||
revs = [] | |||||
if bcache is None: | if bcache is None: | ||||
# no (fresh) cache available anymore, perhaps we can re-use | |||||
# the cache for a subset, then extend that to add info on missing | |||||
# revisions. | |||||
subsetname = subsettable.get(filtername) | subsetname = subsettable.get(filtername) | ||||
if subsetname is None: | if subsetname is not None: | ||||
bcache = branchcache() | |||||
else: | |||||
subset = repo.filtered(subsetname) | subset = repo.filtered(subsetname) | ||||
bcache = subset.branchmap().copy() | bcache = subset.branchmap().copy() | ||||
extrarevs = subset.changelog.filteredrevs - cl.filteredrevs | extrarevs = subset.changelog.filteredrevs - cl.filteredrevs | ||||
revs.extend(r for r in extrarevs if r <= bcache.tiprev) | revs.extend(r for r in extrarevs if r <= bcache.tiprev) | ||||
else: | |||||
# nothing to fall back on, start empty. | |||||
bcache = branchcache() | |||||
revs.extend(cl.revs(start=bcache.tiprev + 1)) | revs.extend(cl.revs(start=bcache.tiprev + 1)) | ||||
if revs: | if revs: | ||||
bcache.update(repo, revs) | bcache.update(repo, revs) | ||||
assert bcache.validfor(repo), filtername | assert bcache.validfor(repo), filtername | ||||
repo._branchcaches[repo.filtername] = bcache | repo._branchcaches[repo.filtername] = bcache | ||||
def replacecache(repo, bm): | def replacecache(repo, bm): |