comparison mercurial/changegroup.py @ 39230:b518d495a560

repository: formalize interfaces for revision deltas and requests Now that we've sufficiently abstracted how revision deltas are produced in changegroup code, we can now start the process of formalizing that as part of the interfaces defined in the repository module. This commit essentially converts the revisiondelta and revisiondeltarequest classes into well-defined interfaces. This is not strictly necessary. But I want all types formalized by the storage interface to have interfaces. This makes it much easier to test for interface conformance and for implementing new storage backends. Because the interface is documented, comments and docstrings from changegroup.py have been dropped. Differential Revision: https://phab.mercurial-scm.org/D4225
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 09 Aug 2018 15:40:14 -0700
parents 2646b8d66b7b
children b41d023a412a
comparison
equal deleted inserted replaced
39229:2646b8d66b7b 39230:b518d495a560
34 revlog, 34 revlog,
35 util, 35 util,
36 ) 36 )
37 37
38 from .utils import ( 38 from .utils import (
39 interfaceutil,
39 stringutil, 40 stringutil,
40 ) 41 )
41 42
42 _CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s") 43 _CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s")
43 _CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s") 44 _CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s")
499 if len(d) < n: 500 if len(d) < n:
500 d += readexactly(self._fh, n - len(d)) 501 d += readexactly(self._fh, n - len(d))
501 return d 502 return d
502 return readexactly(self._fh, n) 503 return readexactly(self._fh, n)
503 504
505 @interfaceutil.implementer(repository.irevisiondeltarequest)
504 @attr.s(slots=True, frozen=True) 506 @attr.s(slots=True, frozen=True)
505 class revisiondeltarequest(object): 507 class revisiondeltarequest(object):
506 """Describes a request to construct a revision delta.
507
508 Instances are converted into ``revisiondelta`` later.
509 """
510 # Revision whose delta will be generated.
511 node = attr.ib() 508 node = attr.ib()
512
513 # Linknode value.
514 linknode = attr.ib() 509 linknode = attr.ib()
515
516 # Parent revisions to record in ``revisiondelta`` instance.
517 p1node = attr.ib() 510 p1node = attr.ib()
518 p2node = attr.ib() 511 p2node = attr.ib()
519
520 # Base revision that delta should be generated against. If nullid,
521 # the full revision data should be populated. If None, the delta
522 # may be generated against any base revision that is an ancestor of
523 # this revision. If any other value, the delta should be produced
524 # against that revision.
525 basenode = attr.ib() 512 basenode = attr.ib()
526
527 # Whether this should be marked as an ellipsis revision.
528 ellipsis = attr.ib(default=False) 513 ellipsis = attr.ib(default=False)
529 514
515 @interfaceutil.implementer(repository.irevisiondelta)
530 @attr.s(slots=True, frozen=True) 516 @attr.s(slots=True, frozen=True)
531 class revisiondelta(object): 517 class revisiondelta(object):
532 """Describes a delta entry in a changegroup.
533
534 Captured data is sufficient to serialize the delta into multiple
535 formats.
536
537 ``revision`` and ``delta`` are mutually exclusive.
538 """
539 # 20 byte node of this revision.
540 node = attr.ib() 518 node = attr.ib()
541 # 20 byte nodes of parent revisions.
542 p1node = attr.ib() 519 p1node = attr.ib()
543 p2node = attr.ib() 520 p2node = attr.ib()
544 # 20 byte node of node this delta is against.
545 basenode = attr.ib() 521 basenode = attr.ib()
546 # 20 byte node of changeset revision this delta is associated with.
547 linknode = attr.ib() 522 linknode = attr.ib()
548 # 2 bytes of flags to apply to revision data.
549 flags = attr.ib() 523 flags = attr.ib()
550 # Size of base revision this delta is against. May be None if
551 # basenode is nullid.
552 baserevisionsize = attr.ib() 524 baserevisionsize = attr.ib()
553 # Raw fulltext revision data.
554 revision = attr.ib() 525 revision = attr.ib()
555 # Delta between the basenode and node.
556 delta = attr.ib() 526 delta = attr.ib()
557 527
558 def _revisiondeltatochunks(delta, headerfn): 528 def _revisiondeltatochunks(delta, headerfn):
559 """Serialize a revisiondelta to changegroup chunks.""" 529 """Serialize a revisiondelta to changegroup chunks."""
560 530