D5165: repository: teach addgroup() to receive data with missing parents

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Oct 19 17:02:29 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5165

AFFECTED FILES
  hgext/sqlitestore.py
  mercurial/filelog.py
  mercurial/repository.py
  tests/simplestorerepo.py

CHANGE DETAILS

diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py
--- a/tests/simplestorerepo.py
+++ b/tests/simplestorerepo.py
@@ -459,7 +459,12 @@
         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)
diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -693,7 +693,8 @@
         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 @@
 
         ``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/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 @@
                                     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/hgext/sqlitestore.py b/hgext/sqlitestore.py
--- a/hgext/sqlitestore.py
+++ b/hgext/sqlitestore.py
@@ -615,7 +615,12 @@
         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:



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list