Mercurial > public > mercurial-scm > hg-stable
diff tests/simplestorerepo.py @ 39259:b41d023a412a
repository: establish API for emitting revision deltas
With our revision delta and revision delta request interfaces
defined, it is now time to define a method on storage interfaces
for using them.
So far, the only storage interface that is well-defined and used
is file storage. So that is the only interface we need to add a
method on.
We define an ``emitrevisiondeltas()`` method that takes an
iterable of ``irevisiondeltarequest``s and turns them into
``irevisiondelta`` instances.
changegroup._handlerevisiondeltarequest() and the looping logic
from changegroup.deltagroup() has effectively been moved to
revlog.emitrevisiondeltas().
Our filelog wrapper class proxies its emitrevisiondeltas() to
the internal revlog instance.
The simple store test extension used to verify sanity of storage
abstractions has also implemented emitrevisiondeltas() for
file storage and the test harness when run with this extension doesn't
seem to exhibit any regressions.
Rather than create a shared type to represent revision deltas,
each storage backend has its own type and the class name identifies
where the revision delta was derived from.
Differential Revision: https://phab.mercurial-scm.org/D4226
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 09 Aug 2018 16:02:14 -0700 |
parents | 404eab7ff33f |
children | 0a5b20c107a6 |
line wrap: on
line diff
--- a/tests/simplestorerepo.py Thu Aug 09 15:40:14 2018 -0700 +++ b/tests/simplestorerepo.py Thu Aug 09 16:02:14 2018 -0700 @@ -22,6 +22,7 @@ nullrev, ) from mercurial.thirdparty import ( + attr, cbor, ) from mercurial import ( @@ -60,6 +61,19 @@ if not isinstance(rev, int): raise ValueError('expected int') +@interfaceutil.implementer(repository.irevisiondelta) +@attr.s(slots=True, frozen=True) +class simplestorerevisiondelta(object): + node = attr.ib() + p1node = attr.ib() + p2node = attr.ib() + basenode = attr.ib() + linknode = attr.ib() + flags = attr.ib() + baserevisionsize = attr.ib() + revision = attr.ib() + delta = attr.ib() + @interfaceutil.implementer(repository.ifilestorage) class filestorage(object): """Implements storage for a tracked path. @@ -500,6 +514,54 @@ return mdiff.textdiff(self.revision(node1, raw=True), self.revision(node2, raw=True)) + def emitrevisiondeltas(self, requests): + for request in requests: + node = request.node + rev = self.rev(node) + + if request.basenode == nullid: + baserev = nullrev + elif request.basenode is not None: + baserev = self.rev(request.basenode) + else: + # This is a test extension and we can do simple things + # for choosing a delta parent. + baserev = self.deltaparent(rev) + + if baserev != nullrev and not self.candelta(baserev, rev): + baserev = nullrev + + revision = None + delta = None + baserevisionsize = None + + if self.iscensored(baserev) or self.iscensored(rev): + try: + revision = self.revision(node, raw=True) + except error.CensoredNodeError as e: + revision = e.tombstone + + if baserev != nullrev: + baserevisionsize = self.rawsize(baserev) + + elif baserev == nullrev: + revision = self.revision(node, raw=True) + else: + delta = self.revdiff(baserev, rev) + + extraflags = revlog.REVIDX_ELLIPSIS if request.ellipsis else 0 + + yield simplestorerevisiondelta( + node=node, + p1node=request.p1node, + p2node=request.p2node, + linknode=request.linknode, + basenode=self.node(baserev), + flags=self.flags(rev) | extraflags, + baserevisionsize=baserevisionsize, + revision=revision, + delta=delta) + def headrevs(self): # Assume all revisions are heads by default. revishead = {rev: True for rev in self._indexbyrev}