Patchwork D1771: revlog: pass index entry type into packentry() (API)

login
register
mail settings
Submitter phabricator
Date Dec. 27, 2017, 12:36 a.m.
Message ID <differential-rev-PHID-DREV-334qp4lt53uliger6s3b-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26460/
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
  packentry() currently accepts tuples. Let's pass in index entry types
  instead.
  
  The censor extension was calling into this low-level code. It has
  been refactored to use our new type and to look up fields in index
  entries by name instead of offset.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/censor.py
  mercurial/revlog.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -293,11 +293,12 @@ 
         return index, nodemap, None
 
     def packentry(self, entry, node, version, rev):
-        if gettype(entry[0]):
+        if gettype(entry.offsetflags):
             raise RevlogError(_('index entry flags need revlog version 1'))
-        e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
-              node(entry[5]), node(entry[6]), entry[7])
-        return indexformatv0_pack(*e2)
+        return indexformatv0_pack(entry.offsetflags, entry.chunklength,
+                                  entry.baserev, entry.linkrev,
+                                  node(entry.p1rev), node(entry.p2rev),
+                                  entry.node)
 
 # index ng:
 #  6 bytes: offset
@@ -329,7 +330,9 @@ 
         return index, getattr(index, 'nodemap', None), cache
 
     def packentry(self, entry, node, version, rev):
-        p = indexformatng_pack(*entry)
+        p = indexformatng_pack(entry.offsetflags, entry.chunklength,
+                               entry.rawlength, entry.baserev, entry.linkrev,
+                               entry.p1rev, entry.p2rev, entry.node)
         if rev == 0:
             p = versionformat_pack(version) + p[4:]
         return p
@@ -1990,8 +1993,8 @@ 
             l = len(data[1]) + len(data[0])
             base = chainbase = curr
 
-        e = (offset_type(offset, flags), l, textlen,
-             base, link, p1r, p2r, node)
+        e = parsers.IndexV1Entry(offset_type(offset, flags), l, textlen,
+                                 base, link, p1r, p2r, node)
         self.index.insert(-1, e)
         self.nodemap[node] = curr
 
diff --git a/hgext/censor.py b/hgext/censor.py
--- a/hgext/censor.py
+++ b/hgext/censor.py
@@ -34,12 +34,15 @@ 
     error,
     filelog,
     lock as lockmod,
+    policy,
     registrar,
     revlog,
     scmutil,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 cmdtable = {}
 command = registrar.command(cmdtable)
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -138,14 +141,20 @@ 
         The newdata argument, if given, is a tuple of three positive integers:
         (new compressed, new uncompressed, added flag bits).
         """
-        offlags, comp, uncomp, base, link, p1, p2, nodeid = flog.index[r]
-        flags = revlog.gettype(offlags)
+        idx = flog.index[r]
+        flags = revlog.gettype(idx.offsetflags)
+        comp = idx.chunklength
+        uncomp = idx.rawlength
+
         if newdata:
             comp, uncomp, nflags = newdata
             flags |= nflags
+
         offlags = revlog.offset_type(newoffs, flags)
-        e = (offlags, comp, uncomp, r, link, p1, p2, nodeid)
-        idxwrite.write(rio.packentry(e, None, flog.version, r))
+        entry = parsers.IndexV1Entry(offlags, comp, uncomp, r,
+                                     idx.linkrev, idx.p1rev, idx.p2rev,
+                                     idx.node)
+        idxwrite.write(rio.packentry(entry, None, flog.version, r))
         idxread.seek(rio.size, 1)
 
     def rewrite(r, offs, data, nflags=revlog.REVIDX_DEFAULT_FLAGS):