comparison mercurial/utils/storageutil.py @ 46715:45f0d5297698

changegroupv4: add sidedata helpers These helpers carry the information and computers needed to rewrite sidedata when generating/applying patches. We will be making use of them soon. Differential Revision: https://phab.mercurial-scm.org/D10029
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 19 Feb 2021 11:15:42 +0100
parents e8c11a2c96c0
children d55b71393907
comparison
equal deleted inserted replaced
46714:f63299ee7e4d 46715:45f0d5297698
21 error, 21 error,
22 mdiff, 22 mdiff,
23 pycompat, 23 pycompat,
24 ) 24 )
25 from ..interfaces import repository 25 from ..interfaces import repository
26 from ..revlogutils import sidedata as sidedatamod
26 from ..utils import hashutil 27 from ..utils import hashutil
27 28
28 _nullhash = hashutil.sha1(nullid) 29 _nullhash = hashutil.sha1(nullid)
29 30
30 31
292 revdifffn=None, 293 revdifffn=None,
293 flagsfn=None, 294 flagsfn=None,
294 deltamode=repository.CG_DELTAMODE_STD, 295 deltamode=repository.CG_DELTAMODE_STD,
295 revisiondata=False, 296 revisiondata=False,
296 assumehaveparentrevisions=False, 297 assumehaveparentrevisions=False,
298 sidedata_helpers=None,
297 ): 299 ):
298 """Generic implementation of ifiledata.emitrevisions(). 300 """Generic implementation of ifiledata.emitrevisions().
299 301
300 Emitting revision data is subtly complex. This function attempts to 302 Emitting revision data is subtly complex. This function attempts to
301 encapsulate all the logic for doing so in a backend-agnostic way. 303 encapsulate all the logic for doing so in a backend-agnostic way.
354 Whether to send fulltext revisions instead of deltas, if allowed. 356 Whether to send fulltext revisions instead of deltas, if allowed.
355 357
356 ``nodesorder`` 358 ``nodesorder``
357 ``revisiondata`` 359 ``revisiondata``
358 ``assumehaveparentrevisions`` 360 ``assumehaveparentrevisions``
361 ``sidedata_helpers`` (optional)
362 If not None, means that sidedata should be included.
363 A dictionary of revlog type to tuples of `(repo, computers, removers)`:
364 * `repo` is used as an argument for computers
365 * `computers` is a list of `(category, (keys, computer)` that
366 compute the missing sidedata categories that were asked:
367 * `category` is the sidedata category
368 * `keys` are the sidedata keys to be affected
369 * `computer` is the function `(repo, store, rev, sidedata)` that
370 returns a new sidedata dict.
371 * `removers` will remove the keys corresponding to the categories
372 that are present, but not needed.
373 If both `computers` and `removers` are empty, sidedata are simply not
374 transformed.
375 Revlog types are `changelog`, `manifest` or `filelog`.
359 """ 376 """
360 377
361 fnode = store.node 378 fnode = store.node
362 frev = store.rev 379 frev = store.rev
363 380
467 store.rawdata(baserev), store.rawdata(rev) 484 store.rawdata(baserev), store.rawdata(rev)
468 ) 485 )
469 486
470 available.add(rev) 487 available.add(rev)
471 488
489 sidedata = None
490 if sidedata_helpers:
491 sidedata = store.sidedata(rev)
492 sidedata = run_sidedata_helpers(
493 store=store,
494 sidedata_helpers=sidedata_helpers,
495 sidedata=sidedata,
496 rev=rev,
497 )
498 sidedata = sidedatamod.serialize_sidedata(sidedata)
499
472 yield resultcls( 500 yield resultcls(
473 node=node, 501 node=node,
474 p1node=fnode(p1rev), 502 p1node=fnode(p1rev),
475 p2node=fnode(p2rev), 503 p2node=fnode(p2rev),
476 basenode=fnode(baserev), 504 basenode=fnode(baserev),
482 ) 510 )
483 511
484 prevrev = rev 512 prevrev = rev
485 513
486 514
515 def run_sidedata_helpers(store, sidedata_helpers, sidedata, rev):
516 """Returns the sidedata for the given revision after running through
517 the given helpers.
518 - `store`: the revlog this applies to (changelog, manifest, or filelog
519 instance)
520 - `sidedata_helpers`: see `storageutil.emitrevisions`
521 - `sidedata`: previous sidedata at the given rev, if any
522 - `rev`: affected rev of `store`
523 """
524 repo, sd_computers, sd_removers = sidedata_helpers
525 kind = store.revlog_kind
526 for _keys, sd_computer in sd_computers.get(kind, []):
527 sidedata = sd_computer(repo, store, rev, sidedata)
528 for keys, _computer in sd_removers.get(kind, []):
529 for key in keys:
530 sidedata.pop(key, None)
531 return sidedata
532
533
487 def deltaiscensored(delta, baserev, baselenfn): 534 def deltaiscensored(delta, baserev, baselenfn):
488 """Determine if a delta represents censored revision data. 535 """Determine if a delta represents censored revision data.
489 536
490 ``baserev`` is the base revision this delta is encoded against. 537 ``baserev`` is the base revision this delta is encoded against.
491 ``baselenfn`` is a callable receiving a revision number that resolves the 538 ``baselenfn`` is a callable receiving a revision number that resolves the