# HG changeset patch # User Gregory Szorc # Date 2018-09-26 21:41:15 # Node ID 1b183edbb68e24af2c1d98b8340d3d1a9f475d5a # Parent 5cb72229f0e9cd9233a568415f3622afe3d058ff repository: teach addgroup() to receive data with missing parents The way the narrow extension works today, the server rewrites outgoing changegroup data to lie about parents when the parents data is missing. It adds the ellipsis flag to the revision so it can be recorded as such in the revlog. In the new wire protocol, such rewriting does not occur on the server (at least not yet anyway). Instead, it is up to the client to recognize when it has received a revision without its parents. This means rewriting will be performed on the client. Furthermore, the mechanism for storing a shallow revision may differ from store to store. For example, the revlog store uses the ellipsis flag to denote a revision's parents have been rewritten. But a non-revlog store may wish to store things differently. And, some stores may not even support receiving shallow revision data! Therefore, it makes sense for the store itself to be making decisions about what to do when they receive revision data without their parents. This commit teaches the addgroup() bulk insert method to accept a boolean argument that indicates whether the incoming data may lack parent revisions. This flag can be set when receiving "shallow" data from a remote. The revlog implementation of this method has been taught to rewrite the missing parent(s) to nullid and to add the ellipsis flag to the revision when a missing parent is encountered. But it only does this if ellipsis flags are enabled on the repo and the incoming data is marked as possibly shallow. An error occurs otherwise. Differential Revision: https://phab.mercurial-scm.org/D5165 diff --git a/hgext/sqlitestore.py b/hgext/sqlitestore.py --- a/hgext/sqlitestore.py +++ b/hgext/sqlitestore.py @@ -615,7 +615,12 @@ class sqlitefilestore(object): self._revisioncache[node] = revisiondata return node - def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None): + def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None, + maybemissingparents=False): + if maybemissingparents: + raise error.Abort(_('SQLite storage does not support missing ' + 'parents write mode')) + nodes = [] for node, p1, p2, linknode, deltabase, delta, wireflags in deltas: diff --git a/mercurial/filelog.py b/mercurial/filelog.py --- a/mercurial/filelog.py +++ b/mercurial/filelog.py @@ -7,6 +7,7 @@ from __future__ import absolute_import +from .i18n import _ from .node import ( nullid, nullrev, @@ -104,9 +105,14 @@ class filelog(object): p1, p2, node=node, flags=flags, cachedelta=cachedelta) - def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None): + def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None, + maybemissingparents=False): + if maybemissingparents: + raise error.Abort(_('revlog storage does not support missing ' + 'parents write mode')) + return self._revlog.addgroup(deltas, linkmapper, transaction, - addrevisioncb=addrevisioncb) + addrevisioncb=addrevisioncb) def getstrippoint(self, minlink): return self._revlog.getstrippoint(minlink) diff --git a/mercurial/repository.py b/mercurial/repository.py --- a/mercurial/repository.py +++ b/mercurial/repository.py @@ -693,7 +693,8 @@ class ifilemutation(interfaceutil.Interf applying raw data from a peer repo. """ - def addgroup(deltas, linkmapper, transaction, addrevisioncb=None): + def addgroup(deltas, linkmapper, transaction, addrevisioncb=None, + maybemissingparents=False): """Process a series of deltas for storage. ``deltas`` is an iterable of 7-tuples of @@ -707,6 +708,11 @@ class ifilemutation(interfaceutil.Interf ``addrevisioncb`` should be called for each node as it is committed. + ``maybemissingparents`` is a bool indicating whether the incoming + data may reference parents/ancestor revisions that aren't present. + This flag is set when receiving data into a "shallow" store that + doesn't hold all history. + Returns a list of nodes that were processed. A node will be in the list even if it existed in the store previously. """ diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py --- a/tests/simplestorerepo.py +++ b/tests/simplestorerepo.py @@ -459,7 +459,12 @@ class filestorage(object): self._refreshindex() self._svfs.write(self._indexpath, cbor.dumps(self._indexdata)) - def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None): + def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None, + maybemissingparents=False): + if maybemissingparents: + raise error.Abort(_('simple store does not support missing parents ' + 'write mode')) + nodes = [] transaction.addbackup(self._indexpath)