changeset 40392:595641bd8404

sqlitestore: support for storing revisions without their parents This commit kinda/sorta implements the equivalent of ellipsis nodes for the SQLite storage backend. Without implementing full blown ellipsis nodes (and the necessary support for them in the wire protocol), we instead teach the store to rewrite the p1 and p2 nodes to nullid when the incoming parent isn't in the local store. This allows servers to remain dumb and send the real parent and have the clients deal with the missing parent problem. This obviously isn't ideal because a benefit of ellipsis nodes is we can insert a fake parent to ellide missing changesets. But neither solution is ideal because it drops the original parent from storage. We could probably teach the SQLite store to retain the original parent and handle missing parents at read time. However, parent revisions are stored as integers and it isn't trivial to store an "empty" revision in the store yet, which would be necessary to represent the "missing" parent. The store is somewhat intelligent in trying to remove the missing parents metadata when the revision is re-added. But, revision numbers will be all messed up in that case, so I'm not sure it is worth it. At some point we'll likely want to remove the concept of revision numbers from the database and have the store invent them at index generation time. Or even better, we can do away with revision numbers from the file storage interface completely. We'll get there eventually... Differential Revision: https://phab.mercurial-scm.org/D5168
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 17 Oct 2018 17:32:15 +0200
parents abbd077965c0
children 229d23cdb203
files hgext/sqlitestore.py
diffstat 1 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/sqlitestore.py	Fri Oct 19 15:38:25 2018 +0200
+++ b/hgext/sqlitestore.py	Wed Oct 17 17:32:15 2018 +0200
@@ -110,6 +110,8 @@
 COMPRESSION_ZLIB = 3
 
 FLAG_CENSORED = 1
+FLAG_MISSING_P1 = 2
+FLAG_MISSING_P2 = 4
 
 CREATE_SCHEMA = [
     # Deltas are stored as content-indexed blobs.
@@ -535,6 +537,11 @@
                                      self._revisioncache, stoprids,
                                      zstddctx=self._dctx)
 
+        # Don't verify hashes if parent nodes were rewritten, as the hash
+        # wouldn't verify.
+        if self._revisions[node].flags & (FLAG_MISSING_P1 | FLAG_MISSING_P2):
+            _verifyhash = False
+
         if _verifyhash:
             self._checkhash(fulltext, node)
             self._revisioncache[node] = fulltext
@@ -618,10 +625,6 @@
 
     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:
@@ -633,6 +636,15 @@
             if wireflags & ~repository.REVISION_FLAG_CENSORED:
                 raise SQLiteStoreError('unhandled revision flag')
 
+            if maybemissingparents:
+                if p1 != nullid and not self.hasnode(p1):
+                    p1 = nullid
+                    storeflags |= FLAG_MISSING_P1
+
+                if p2 != nullid and not self.hasnode(p2):
+                    p2 = nullid
+                    storeflags |= FLAG_MISSING_P2
+
             baserev = self.rev(deltabase)
 
             # If base is censored, delta must be full replacement in a single
@@ -657,6 +669,29 @@
             nodes.append(node)
 
             if node in self._revisions:
+                # Possibly reset parents to make them proper.
+                entry = self._revisions[node]
+
+                if entry.flags & FLAG_MISSING_P1 and p1 != nullid:
+                    entry.p1node = p1
+                    entry.p1rev = self._nodetorev[p1]
+                    entry.flags &= ~FLAG_MISSING_P1
+
+                    self._db.execute(
+                        r'UPDATE fileindex SET p1rev=?, flags=? '
+                        r'WHERE id=?',
+                        (self._nodetorev[p1], entry.flags, entry.rid))
+
+                if entry.flags & FLAG_MISSING_P2 and p2 != nullid:
+                    entry.p2node = p2
+                    entry.p2rev = self._nodetorev[p2]
+                    entry.flags &= ~FLAG_MISSING_P2
+
+                    self._db.execute(
+                        r'UPDATE fileindex SET p2rev=?, flags=? '
+                        r'WHERE id=?',
+                        (self._nodetorev[p1], entry.flags, entry.rid))
+
                 continue
 
             if deltabase == nullid: