changeset 43040:ba4072c0a911

sidedata: test we can successfully write sidedata For now we just write them and rejoice on the lack of crashes. Differential Revision: https://phab.mercurial-scm.org/D6896
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 09 Sep 2019 21:38:29 +0200
parents 7902001aaf41
children 559ac8411f12
files mercurial/revlogutils/sidedata.py tests/test-sidedata.t tests/testlib/ext-sidedata.py
diffstat 3 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlogutils/sidedata.py	Fri Sep 27 16:40:07 2019 +0200
+++ b/mercurial/revlogutils/sidedata.py	Mon Sep 09 21:38:29 2019 +0200
@@ -38,6 +38,17 @@
 
 from .. import error
 
+## sidedata type constant
+# reserve a block for testing purposes.
+SD_TEST1 = 1
+SD_TEST2 = 2
+SD_TEST3 = 3
+SD_TEST4 = 4
+SD_TEST5 = 5
+SD_TEST6 = 6
+SD_TEST7 = 7
+
+# internal format constant
 SIDEDATA_HEADER = struct.Struct('>H')
 SIDEDATA_ENTRY = struct.Struct('>HL20s')
 
--- a/tests/test-sidedata.t	Fri Sep 27 16:40:07 2019 +0200
+++ b/tests/test-sidedata.t	Mon Sep 09 21:38:29 2019 +0200
@@ -2,6 +2,24 @@
 Test file dedicated to checking side-data related behavior
 ==========================================================
 
+Check data can be written/read from sidedata
+============================================
+
+  $ cat << EOF >> $HGRCPATH
+  > [extensions]
+  > testsidedata=$TESTDIR/testlib/ext-sidedata.py
+  > EOF
+
+  $ hg init test-sidedata --config format.use-side-data=yes
+  $ cd test-sidedata
+  $ echo aaa > a
+  $ hg add a
+  $ hg commit -m a --traceback
+  $ echo aaa > b
+  $ hg add b
+  $ hg commit -m b
+  $ echo xxx >> a
+  $ hg commit -m aa
 
 Check upgrade behavior
 ======================
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/testlib/ext-sidedata.py	Mon Sep 09 21:38:29 2019 +0200
@@ -0,0 +1,36 @@
+# ext-sidedata.py - small extension to test the sidedata logic
+#
+# Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net)
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+import hashlib
+import struct
+
+from mercurial import (
+    extensions,
+    revlog,
+)
+
+from mercurial.revlogutils import (
+    sidedata,
+)
+
+def wrapaddrevision(orig, self, text, transaction, link, p1, p2, *args,
+                    **kwargs):
+    if kwargs.get('sidedata') is None:
+        kwargs['sidedata'] = {}
+    sd = kwargs['sidedata']
+    ## let's store some arbitrary data just for testing
+    # text length
+    sd[sidedata.SD_TEST1] = struct.pack('>I', len(text))
+    # and sha2 hashes
+    sha256 = hashlib.sha256(text).digest()
+    sd[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
+    return orig(self, text, transaction, link, p1, p2, *args, **kwargs)
+
+def extsetup(ui):
+    extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision)