Patchwork D1772: tests: port revlog index code to modern API

login
register
mail settings
Submitter phabricator
Date Dec. 27, 2017, 12:36 a.m.
Message ID <differential-rev-PHID-DREV-vzjezgosyhvwyqurqvnl-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26455/
State New
Headers show

Comments

phabricator - Dec. 27, 2017, 12:36 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  All revlog index parsers are now using our new type to
  represent index entries. We can now undo the custom type
  comparison code we implemented to see us through the transition.
  
  In addition, the code has been ported to use named attributes
  instead of field offsets.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/test-parseindex2.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-parseindex2.py b/tests/test-parseindex2.py
--- a/tests/test-parseindex2.py
+++ b/tests/test-parseindex2.py
@@ -13,10 +13,6 @@ 
     nullid,
     nullrev,
 )
-# no-check-code
-from mercurial.pure import (
-    parsers as pureparsers,
-)
 from mercurial import (
     policy,
 )
@@ -45,27 +41,32 @@ 
         cache = (0, data)
         while off <= l:
             e = struct.unpack(indexformatng, data[off:off + s])
-            nodemap[e[7]] = n
+            e = parsers.IndexV1Entry(*e)
+            nodemap[e.node] = n
             append(e)
             n += 1
-            if e[1] < 0:
+            if e.chunklength < 0:
                 break
-            off += e[1] + s
+            off += e.chunklength + s
     else:
         while off <= l:
             e = struct.unpack(indexformatng, data[off:off + s])
-            nodemap[e[7]] = n
+            e = parsers.IndexV1Entry(*e)
+            nodemap[e.node] = n
             append(e)
             n += 1
             off += s
 
-    e = list(index[0])
-    type = gettype(e[0])
-    e[0] = offset_type(0, type)
-    index[0] = tuple(e)
+    e = index[0]
+    type = gettype(e.offsetflags)
+
+    index[0] = parsers.IndexV1Entry(offset_type(0, type),
+                                    e.chunklength, e.rawlength,
+                                    e.baserev, e.linkrev,
+                                    e.p1rev, e.p2rev, e.node)
 
     # add the magic null revision at -1
-    index.append((0, 0, 0, -1, -1, -1, -1, nullid))
+    index.append(parsers.IndexV1Entry(0, 0, 0, -1, -1, -1, -1, nullid))
 
     return index, cache
 
@@ -169,21 +170,6 @@ 
     testversionfail(4, makehex(major, minor + 1, micro))
     testversionfail(5, "'foo'")
 
-def index_equal(a, b):
-    """Determine if 2 index objects are equal."""
-    # Normalize all entries to IndexV1Entry instances.
-    def normvalue(x):
-        if isinstance(x, pureparsers.IndexV1Entry):
-            return x
-
-        assert isinstance(x, tuple)
-        return pureparsers.IndexV1Entry(*x)
-
-    idxa = [map(normvalue, a[0])]
-    idxb = [map(normvalue, b[0])]
-
-    return (idxa, a[1]) == (idxb, b[1])
-
 def runtest() :
     # Only test the version-detection logic if it is present.
     try:
@@ -210,15 +196,15 @@ 
     py_res_2 = py_parseindex(data_non_inlined, False)
     c_res_2 = parse_index2(data_non_inlined, False)
 
-    if not index_equal(py_res_1, c_res_1):
+    if py_res_1 != c_res_1:
         print("Parse index result (with inlined data) differs!")
 
-    if not index_equal(py_res_2, c_res_2):
+    if py_res_2 != c_res_2:
         print("Parse index result (no inlined data) differs!")
 
     ix = parsers.parse_index2(data_inlined, True)[0]
     for i, r in enumerate(ix):
-        if r[7] == nullid:
+        if r.node == nullid:
             i = -1
         try:
             if ix[r[7]] != i: