##// END OF EJS Templates
branchcache: use an explicit class for the v2 version...
marmoute -
r52412:ec640dc9 default
parent child Browse files
Show More
@@ -4205,15 +4205,24 b' def perfbranchmap(ui, repo, *filternames'
4205 # add unfiltered
4205 # add unfiltered
4206 allfilters.append(None)
4206 allfilters.append(None)
4207
4207
4208 if util.safehasattr(branchmap.branchcache, 'fromfile'):
4208 old_branch_cache_from_file = None
4209 branchcacheread = None
4210 if util.safehasattr(branchmap, 'branch_cache_from_file'):
4211 old_branch_cache_from_file = branchmap.branch_cache_from_file
4212 branchmap.branch_cache_from_file = lambda *args: None
4213 elif util.safehasattr(branchmap.branchcache, 'fromfile'):
4209 branchcacheread = safeattrsetter(branchmap.branchcache, b'fromfile')
4214 branchcacheread = safeattrsetter(branchmap.branchcache, b'fromfile')
4210 branchcacheread.set(classmethod(lambda *args: None))
4215 branchcacheread.set(classmethod(lambda *args: None))
4211 else:
4216 else:
4212 # older versions
4217 # older versions
4213 branchcacheread = safeattrsetter(branchmap, b'read')
4218 branchcacheread = safeattrsetter(branchmap, b'read')
4214 branchcacheread.set(lambda *args: None)
4219 branchcacheread.set(lambda *args: None)
4215 branchcachewrite = safeattrsetter(branchmap.branchcache, b'write')
4220 if util.safehasattr(branchmap, '_LocalBranchCache'):
4216 branchcachewrite.set(lambda *args: None)
4221 branchcachewrite = safeattrsetter(branchmap._LocalBranchCache, b'write')
4222 branchcachewrite.set(lambda *args: None)
4223 else:
4224 branchcachewrite = safeattrsetter(branchmap.branchcache, b'write')
4225 branchcachewrite.set(lambda *args: None)
4217 try:
4226 try:
4218 for name in allfilters:
4227 for name in allfilters:
4219 printname = name
4228 printname = name
@@ -4221,7 +4230,10 b' def perfbranchmap(ui, repo, *filternames'
4221 printname = b'unfiltered'
4230 printname = b'unfiltered'
4222 timer(getbranchmap(name), title=printname)
4231 timer(getbranchmap(name), title=printname)
4223 finally:
4232 finally:
4224 branchcacheread.restore()
4233 if old_branch_cache_from_file is not None:
4234 branchmap.branch_cache_from_file = old_branch_cache_from_file
4235 if branchcacheread is not None:
4236 branchcacheread.restore()
4225 branchcachewrite.restore()
4237 branchcachewrite.restore()
4226 fm.end()
4238 fm.end()
4227
4239
@@ -4381,10 +4393,10 b' def perfbranchmapload(ui, repo, filter=b'
4381
4393
4382 repo.branchmap() # make sure we have a relevant, up to date branchmap
4394 repo.branchmap() # make sure we have a relevant, up to date branchmap
4383
4395
4384 try:
4396 fromfile = getattr(branchmap, 'branch_cache_from_file', None)
4385 fromfile = branchmap.branchcache.fromfile
4397 if fromfile is None:
4386 except AttributeError:
4398 fromfile = getattr(branchmap.branchcache, 'fromfile', None)
4387 # older versions
4399 if fromfile is None:
4388 fromfile = branchmap.read
4400 fromfile = branchmap.read
4389
4401
4390 currentfilter = filter
4402 currentfilter = filter
@@ -100,7 +100,7 b' class BranchMapCache:'
100 bcache = self._per_filter.get(filtername)
100 bcache = self._per_filter.get(filtername)
101 if bcache is None or not bcache.validfor(repo):
101 if bcache is None or not bcache.validfor(repo):
102 # cache object missing or cache object stale? Read from disk
102 # cache object missing or cache object stale? Read from disk
103 bcache = branchcache.fromfile(repo)
103 bcache = branch_cache_from_file(repo)
104
104
105 revs = []
105 revs = []
106 if bcache is None:
106 if bcache is None:
@@ -116,7 +116,7 b' class BranchMapCache:'
116 revs.extend(r for r in extrarevs if r <= bcache.tiprev)
116 revs.extend(r for r in extrarevs if r <= bcache.tiprev)
117 else:
117 else:
118 # nothing to fall back on, start empty.
118 # nothing to fall back on, start empty.
119 bcache = branchcache(repo)
119 bcache = new_branch_cache(repo)
120
120
121 revs.extend(cl.revs(start=bcache.tiprev + 1))
121 revs.extend(cl.revs(start=bcache.tiprev + 1))
122 if revs:
122 if revs:
@@ -147,7 +147,7 b' class BranchMapCache:'
147
147
148 if rbheads:
148 if rbheads:
149 rtiprev = max((int(clrev(node)) for node in rbheads))
149 rtiprev = max((int(clrev(node)) for node in rbheads))
150 cache = branchcache(
150 cache = new_branch_cache(
151 repo,
151 repo,
152 remotebranchmap,
152 remotebranchmap,
153 repo[rtiprev].node(),
153 repo[rtiprev].node(),
@@ -199,21 +199,6 b' class _BaseBranchCache:'
199
199
200 This cache is used to avoid costly computations to determine all the
200 This cache is used to avoid costly computations to determine all the
201 branch heads of a repo.
201 branch heads of a repo.
202
203 The cache is serialized on disk in the following format:
204
205 <tip hex node> <tip rev number> [optional filtered repo hex hash]
206 <branch head hex node> <open/closed state> <branch name>
207 <branch head hex node> <open/closed state> <branch name>
208 ...
209
210 The first line is used to check if the cache is still valid. If the
211 branch cache is for a filtered repo view, an optional third hash is
212 included that hashes the hashes of all filtered and obsolete revisions.
213
214 The open/closed state is represented by a single letter 'o' or 'c'.
215 This field can be used to avoid changelog reads when determining if a
216 branch head closes a branch or not.
217 """
202 """
218
203
219 def __init__(
204 def __init__(
@@ -420,10 +405,10 b' STATE_INHERITED = 2'
420 STATE_DIRTY = 3
405 STATE_DIRTY = 3
421
406
422
407
423 class branchcache(_BaseBranchCache):
408 class _LocalBranchCache(_BaseBranchCache):
424 """Branchmap info for a local repo or repoview"""
409 """base class of branch-map info for a local repo or repoview"""
425
410
426 _base_filename = b"branch2"
411 _base_filename = None
427
412
428 def __init__(
413 def __init__(
429 self,
414 self,
@@ -560,6 +545,7 b' class branchcache(_BaseBranchCache):'
560 def _filename(cls, repo):
545 def _filename(cls, repo):
561 """name of a branchcache file for a given repo or repoview"""
546 """name of a branchcache file for a given repo or repoview"""
562 filename = cls._base_filename
547 filename = cls._base_filename
548 assert filename is not None
563 if repo.filtername:
549 if repo.filtername:
564 filename = b'%s-%s' % (filename, repo.filtername)
550 filename = b'%s-%s' % (filename, repo.filtername)
565 return filename
551 return filename
@@ -741,6 +727,38 b' class branchcache(_BaseBranchCache):'
741 self.write(repo)
727 self.write(repo)
742
728
743
729
730 def branch_cache_from_file(repo) -> Optional[_LocalBranchCache]:
731 """Build a branch cache from on-disk data if possible"""
732 return BranchCacheV2.fromfile(repo)
733
734
735 def new_branch_cache(repo, *args, **kwargs):
736 """Build a new branch cache from argument"""
737 return BranchCacheV2(repo, *args, **kwargs)
738
739
740 class BranchCacheV2(_LocalBranchCache):
741 """a branch cache using version 2 of the format on disk
742
743 The cache is serialized on disk in the following format:
744
745 <tip hex node> <tip rev number> [optional filtered repo hex hash]
746 <branch head hex node> <open/closed state> <branch name>
747 <branch head hex node> <open/closed state> <branch name>
748 ...
749
750 The first line is used to check if the cache is still valid. If the
751 branch cache is for a filtered repo view, an optional third hash is
752 included that hashes the hashes of all filtered and obsolete revisions.
753
754 The open/closed state is represented by a single letter 'o' or 'c'.
755 This field can be used to avoid changelog reads when determining if a
756 branch head closes a branch or not.
757 """
758
759 _base_filename = b"branch2"
760
761
744 class remotebranchcache(_BaseBranchCache):
762 class remotebranchcache(_BaseBranchCache):
745 """Branchmap info for a remote connection, should not write locally"""
763 """Branchmap info for a remote connection, should not write locally"""
746
764
General Comments 0
You need to be logged in to leave comments. Login now