diff mercurial/utils/storageutil.py @ 47077:119790e1c67c

cg4: introduce protocol flag to signify the presence of sidedata We need a way of signaling whether the current revision has sidedata or not, and re-using the revision flags would waste potential revlog flags and mix two normally independent layers. In this change, we add a single byte at the start of the ch4 delta header to set potential protocol flags. We also reclaim the revlog flag for sidedata, since it is no longer used, in its place now lives the (also experimental) copytracing flag. When generating deltas, apply the `CG_FLAG_SIDEDATA` flag if there is sidedata. When applying the deltas, if said flag is present, the next chunk contains the sidedata. Differential Revision: https://phab.mercurial-scm.org/D10343
author Rapha?l Gom?s <rgomes@octobus.net>
date Sat, 10 Apr 2021 11:27:40 +0200
parents d55b71393907
children 223b47235d1c
line wrap: on
line diff
--- a/mercurial/utils/storageutil.py	Thu Apr 08 16:34:11 2021 +0200
+++ b/mercurial/utils/storageutil.py	Sat Apr 10 11:27:40 2021 +0200
@@ -28,6 +28,10 @@
 
 _nullhash = hashutil.sha1(sha1nodeconstants.nullid)
 
+# revision data contains extra metadata not part of the official digest
+# Only used in changegroup >= v4.
+CG_FLAG_SIDEDATA = 1
+
 
 def hashrevisionsha1(text, p1, p2):
     """Compute the SHA-1 for revision data and its parents.
@@ -486,7 +490,7 @@
 
                 available.add(rev)
 
-        sidedata = None
+        serialized_sidedata = None
         if sidedata_helpers:
             sidedata = store.sidedata(rev)
             sidedata = run_sidedata_helpers(
@@ -495,18 +499,26 @@
                 sidedata=sidedata,
                 rev=rev,
             )
-            sidedata = sidedatamod.serialize_sidedata(sidedata)
+            if sidedata:
+                serialized_sidedata = sidedatamod.serialize_sidedata(sidedata)
+
+        flags = flagsfn(rev) if flagsfn else 0
+        protocol_flags = 0
+        if serialized_sidedata:
+            # Advertise that sidedata exists to the other side
+            protocol_flags |= CG_FLAG_SIDEDATA
 
         yield resultcls(
             node=node,
             p1node=fnode(p1rev),
             p2node=fnode(p2rev),
             basenode=fnode(baserev),
-            flags=flagsfn(rev) if flagsfn else 0,
+            flags=flags,
             baserevisionsize=baserevisionsize,
             revision=revision,
             delta=delta,
-            sidedata=sidedata,
+            sidedata=serialized_sidedata,
+            protocol_flags=protocol_flags,
         )
 
         prevrev = rev