D6896: sidedata: test we can successfully write sidedata

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Tue Oct 1 18:24:05 UTC 2019


Closed by commit rHGba4072c0a911: sidedata: test we can successfully write sidedata (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6896?vs=16654&id=16768

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6896/new/

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

AFFECTED FILES
  mercurial/revlogutils/sidedata.py
  tests/test-sidedata.t
  tests/testlib/ext-sidedata.py

CHANGE DETAILS

diff --git a/tests/testlib/ext-sidedata.py b/tests/testlib/ext-sidedata.py
new file mode 100644
--- /dev/null
+++ b/tests/testlib/ext-sidedata.py
@@ -0,0 +1,36 @@
+# ext-sidedata.py - small extension to test the sidedata logic
+#
+# Copyright 2019 Pierre-Yves David <pierre-yves.david at 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)
diff --git a/tests/test-sidedata.t b/tests/test-sidedata.t
--- a/tests/test-sidedata.t
+++ b/tests/test-sidedata.t
@@ -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
 ======================
diff --git a/mercurial/revlogutils/sidedata.py b/mercurial/revlogutils/sidedata.py
--- a/mercurial/revlogutils/sidedata.py
+++ b/mercurial/revlogutils/sidedata.py
@@ -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')
 



To: marmoute, durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list