diff tests/simplestorerepo.py @ 37436:9d4f09bfe3ec

simplestore: correctly implement flag processors There were a couple of bugs around the implementation of flags processing with the simple store. After these changes, test-flagprocessor.t now passes! test-flagprocessor.t was also updated to include explicit test coverage that pushed data is as expected on the server. The test extension used by test-flagprocessor.t has been updated so it monkeypatches the object returned from repo.file() instead of monkeypatching filelog.filelog. This allows it to work with extensions that return custom types from repo.file(). The monkeypatching is rather hacky and probably is performance prohibitive for real repos. We should probably come up with a better mechanism for registering flag processors so monkeypatching isn't needed. Differential Revision: https://phab.mercurial-scm.org/D3116
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 04 Apr 2018 19:17:22 -0700
parents 06674aab2b4c
children a3202fa83aff
line wrap: on
line diff
--- a/tests/simplestorerepo.py	Wed Apr 04 17:40:09 2018 -0700
+++ b/tests/simplestorerepo.py	Wed Apr 04 19:17:22 2018 -0700
@@ -243,6 +243,10 @@
         if flags == 0:
             return text, True
 
+        if flags & ~revlog.REVIDX_KNOWN_FLAGS:
+            raise error.RevlogError(_("incompatible revision flag '%#x'") %
+                                    (flags & ~revlog.REVIDX_KNOWN_FLAGS))
+
         validatehash = True
         # Depending on the operation (read or write), the order might be
         # reversed due to non-commutative transforms.
@@ -405,15 +409,13 @@
         return 0, 0
 
     def add(self, text, meta, transaction, linkrev, p1, p2):
-        transaction.addbackup(self._indexpath)
-
         if meta or text.startswith(b'\1\n'):
             text = filelog.packmeta(meta, text)
 
         return self.addrevision(text, transaction, linkrev, p1, p2)
 
     def addrevision(self, text, transaction, linkrev, p1, p2, node=None,
-                    flags=0):
+                    flags=revlog.REVIDX_DEFAULT_FLAGS, cachedelta=None):
         validatenode(p1)
         validatenode(p2)
 
@@ -430,15 +432,21 @@
         if validatehash:
             self.checkhash(rawtext, node, p1=p1, p2=p2)
 
+        return self._addrawrevision(node, rawtext, transaction, linkrev, p1, p2,
+                                    flags)
+
+    def _addrawrevision(self, node, rawtext, transaction, link, p1, p2, flags):
+        transaction.addbackup(self._indexpath)
+
         path = b'/'.join([self._storepath, hex(node)])
 
-        self._svfs.write(path, text)
+        self._svfs.write(path, rawtext)
 
         self._indexdata.append({
             b'node': node,
             b'p1': p1,
             b'p2': p2,
-            b'linkrev': linkrev,
+            b'linkrev': link,
             b'flags': flags,
         })
 
@@ -457,6 +465,7 @@
 
         for node, p1, p2, linknode, deltabase, delta, flags in deltas:
             linkrev = linkmapper(linknode)
+            flags = flags or revlog.REVIDX_DEFAULT_FLAGS
 
             nodes.append(node)
 
@@ -469,7 +478,8 @@
             else:
                 text = mdiff.patch(self.revision(deltabase), delta)
 
-            self.addrevision(text, transaction, linkrev, p1, p2, flags)
+            self._addrawrevision(node, text, transaction, linkrev, p1, p2,
+                                 flags)
 
             if addrevisioncb:
                 addrevisioncb(self, node)