Mercurial > public > mercurial-scm > hg
diff mercurial/localrepo.py @ 47083:81eb7091c494
sidedata: add a way of replacing an existing sidedata computer
This will be useful in a future patch to replace a sequential computer with
a parallel computer. We only allow for explicit replacement, to force the users
to think about overriding computers.
Differential Revision: https://phab.mercurial-scm.org/D10358
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 19 Apr 2021 11:22:21 +0200 |
parents | 223b47235d1c |
children | 3aab2330b7d3 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Thu Apr 08 16:30:10 2021 +0200 +++ b/mercurial/localrepo.py Mon Apr 19 11:22:21 2021 +0200 @@ -3370,16 +3370,25 @@ return self._wanted_sidedata.add(pycompat.bytestr(category)) - def register_sidedata_computer(self, kind, category, keys, computer, flags): + def register_sidedata_computer( + self, kind, category, keys, computer, flags, replace=False + ): if kind not in revlogconst.ALL_KINDS: msg = _(b"unexpected revlog kind '%s'.") raise error.ProgrammingError(msg % kind) category = pycompat.bytestr(category) - if category in self._sidedata_computers.get(kind, []): + already_registered = category in self._sidedata_computers.get(kind, []) + if already_registered and not replace: msg = _( b"cannot register a sidedata computer twice for category '%s'." ) raise error.ProgrammingError(msg % category) + if replace and not already_registered: + msg = _( + b"cannot replace a sidedata computer that isn't registered " + b"for category '%s'." + ) + raise error.ProgrammingError(msg % category) self._sidedata_computers.setdefault(kind, {}) self._sidedata_computers[kind][category] = (keys, computer, flags)