Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 46713:bc2519513ae0
sidedata-exchange: add `wanted_sidedata` and `sidedata_computers` to repos
Each repo will advertise the sidedata categories it requires (categories being
unique and canonical), and have a set of "computers", functions to generate
sidedata from `(repo, revlog, rev, previous_sidedata)`, for a given category.
The set of computers can be a superset of the set of the wanted categories, but
not smaller: repos are expected to be coherent in their handling of sidedata.
Differential Revision: https://phab.mercurial-scm.org/D10028
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 19 Feb 2021 10:53:27 +0100 |
parents | a41565bef69f |
children | 6266d19556ad |
comparison
equal
deleted
inserted
replaced
46712:e8c11a2c96c0 | 46713:bc2519513ae0 |
---|---|
47 hook, | 47 hook, |
48 lock as lockmod, | 48 lock as lockmod, |
49 match as matchmod, | 49 match as matchmod, |
50 mergestate as mergestatemod, | 50 mergestate as mergestatemod, |
51 mergeutil, | 51 mergeutil, |
52 metadata as metadatamod, | |
52 namespaces, | 53 namespaces, |
53 narrowspec, | 54 narrowspec, |
54 obsolete, | 55 obsolete, |
55 pathutil, | 56 pathutil, |
56 phases, | 57 phases, |
271 | 272 |
272 if caps is None: | 273 if caps is None: |
273 caps = moderncaps.copy() | 274 caps = moderncaps.copy() |
274 self._repo = repo.filtered(b'served') | 275 self._repo = repo.filtered(b'served') |
275 self.ui = repo.ui | 276 self.ui = repo.ui |
277 | |
278 if repo._wanted_sidedata: | |
279 formatted = bundle2.format_remote_wanted_sidedata(repo) | |
280 caps.add(b'exp-wanted-sidedata=' + formatted) | |
281 | |
276 self._caps = repo._restrictcapabilities(caps) | 282 self._caps = repo._restrictcapabilities(caps) |
277 | 283 |
278 # Begin of _basepeer interface. | 284 # Begin of _basepeer interface. |
279 | 285 |
280 def url(self): | 286 def url(self): |
1392 self._extrafilterid = repoview.extrafilter(ui) | 1398 self._extrafilterid = repoview.extrafilter(ui) |
1393 | 1399 |
1394 self.filecopiesmode = None | 1400 self.filecopiesmode = None |
1395 if requirementsmod.COPIESSDC_REQUIREMENT in self.requirements: | 1401 if requirementsmod.COPIESSDC_REQUIREMENT in self.requirements: |
1396 self.filecopiesmode = b'changeset-sidedata' | 1402 self.filecopiesmode = b'changeset-sidedata' |
1403 | |
1404 self._wanted_sidedata = set() | |
1405 self._sidedata_computers = {} | |
1406 metadatamod.set_sidedata_spec_for_repo(self) | |
1397 | 1407 |
1398 def _getvfsward(self, origfunc): | 1408 def _getvfsward(self, origfunc): |
1399 """build a ward for self.vfs""" | 1409 """build a ward for self.vfs""" |
1400 rref = weakref.ref(self) | 1410 rref = weakref.ref(self) |
1401 | 1411 |
3330 fp.write(text) | 3340 fp.write(text) |
3331 finally: | 3341 finally: |
3332 fp.close() | 3342 fp.close() |
3333 return self.pathto(fp.name[len(self.root) + 1 :]) | 3343 return self.pathto(fp.name[len(self.root) + 1 :]) |
3334 | 3344 |
3345 def register_wanted_sidedata(self, category): | |
3346 self._wanted_sidedata.add(pycompat.bytestr(category)) | |
3347 | |
3348 def register_sidedata_computer(self, kind, category, keys, computer): | |
3349 if kind not in (b"changelog", b"manifest", b"filelog"): | |
3350 msg = _(b"unexpected revlog kind '%s'.") | |
3351 raise error.ProgrammingError(msg % kind) | |
3352 category = pycompat.bytestr(category) | |
3353 if category in self._sidedata_computers.get(kind, []): | |
3354 msg = _( | |
3355 b"cannot register a sidedata computer twice for category '%s'." | |
3356 ) | |
3357 raise error.ProgrammingError(msg % category) | |
3358 self._sidedata_computers.setdefault(kind, {}) | |
3359 self._sidedata_computers[kind][category] = (keys, computer) | |
3360 | |
3335 | 3361 |
3336 # used to avoid circular references so destructors work | 3362 # used to avoid circular references so destructors work |
3337 def aftertrans(files): | 3363 def aftertrans(files): |
3338 renamefiles = [tuple(t) for t in files] | 3364 renamefiles = [tuple(t) for t in files] |
3339 | 3365 |