Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 39768:7b2b42fc377a
revlog: store flag processors per revlog
Previously, revlog flag processing would consult a global dict
when processing flags. This was simple. But it had the undesired
side-effect that any extension could load flag processors once
and those flag processors would be available to any revlog that was
subsequent loaded in the process. e.g. in hgweb, if the narrow
extension were loaded for repo A but not repo B, repo B would be
able to decode ellipsis flags even though it shouldn't be able to.
Making the flag processors dict per-revlog allows us to have per-revlog
controls over what flag processors are available, thus preserving
desired granular access to flag processors depending on the revlog's
needs.
If a flag processor is globally registered, it is still globally
available. So this commit should not meaningfully change behavior.
Differential Revision: https://phab.mercurial-scm.org/D4646
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 13 Sep 2018 15:48:53 -0700 |
parents | db088e133e91 |
children | ba0e0c6b7b61 |
comparison
equal
deleted
inserted
replaced
39767:db088e133e91 | 39768:7b2b42fc377a |
---|---|
412 self._maxdeltachainspan = -1 | 412 self._maxdeltachainspan = -1 |
413 self._withsparseread = False | 413 self._withsparseread = False |
414 self._sparserevlog = False | 414 self._sparserevlog = False |
415 self._srdensitythreshold = 0.50 | 415 self._srdensitythreshold = 0.50 |
416 self._srmingapsize = 262144 | 416 self._srmingapsize = 262144 |
417 | |
418 # Make copy of flag processors so each revlog instance can support | |
419 # custom flags. | |
420 self._flagprocessors = dict(_flagprocessors) | |
417 | 421 |
418 mmapindexthreshold = None | 422 mmapindexthreshold = None |
419 v = REVLOG_DEFAULT_VERSION | 423 v = REVLOG_DEFAULT_VERSION |
420 opts = getattr(opener, 'options', None) | 424 opts = getattr(opener, 'options', None) |
421 if opts is not None: | 425 if opts is not None: |
1705 # If a flagprocessor has been registered for a known flag, apply the | 1709 # If a flagprocessor has been registered for a known flag, apply the |
1706 # related operation transform and update result tuple. | 1710 # related operation transform and update result tuple. |
1707 if flag & flags: | 1711 if flag & flags: |
1708 vhash = True | 1712 vhash = True |
1709 | 1713 |
1710 if flag not in _flagprocessors: | 1714 if flag not in self._flagprocessors: |
1711 message = _("missing processor for flag '%#x'") % (flag) | 1715 message = _("missing processor for flag '%#x'") % (flag) |
1712 raise RevlogError(message) | 1716 raise RevlogError(message) |
1713 | 1717 |
1714 processor = _flagprocessors[flag] | 1718 processor = self._flagprocessors[flag] |
1715 if processor is not None: | 1719 if processor is not None: |
1716 readtransform, writetransform, rawtransform = processor | 1720 readtransform, writetransform, rawtransform = processor |
1717 | 1721 |
1718 if raw: | 1722 if raw: |
1719 vhash = rawtransform(self, text) | 1723 vhash = rawtransform(self, text) |