Patchwork [8,of,9,V2] revlog: make _addrevision only accept rawtext

login
register
mail settings
Submitter Jun Wu
Date March 31, 2017, 4:45 a.m.
Message ID <3a4dd24ccf078c477225.1490935517@x1c>
Download mbox | patch
Permalink /patch/19860/
State Accepted
Headers show

Comments

Jun Wu - March 31, 2017, 4:45 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1490924283 25200
#      Thu Mar 30 18:38:03 2017 -0700
# Node ID 3a4dd24ccf078c47722582f00872a88d33042ac3
# Parent  4bc37a3afb8b56b3d124188cc16ea8d83a0ba92d
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 3a4dd24ccf07
revlog: make _addrevision only accept rawtext

All 3 users of _addrevision use raw:

  - addrevision: passing rawtext to _addrevision
  - addgroup: passing rawtext and raw=True to _addrevision
  - clone: passing rawtext to _addrevision

There is no real user using _addrevision(raw=False). On the other hand,
_addrevision is low-level code dealing with raw revlog deltas and rawtexts.
It should not transform rawtext to non-raw text.

This patch removes the "raw" parameter from "_addrevision", and does some
rename and doc change to make it clear that "_addrevision" expects rawtext.

Archeology shows 2df983125d37 added "raw" flag to "_addrevision", follow-ups
e12c0fa1f65b and c1b7b2285522 seem to make the flag unnecessary.

test-revlog-raw.py no longer complains.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1578,17 +1578,17 @@  class revlog(object):
         return True
 
-    def _addrevision(self, node, text, transaction, link, p1, p2, flags,
-                     cachedelta, ifh, dfh, alwayscache=False, raw=False):
+    def _addrevision(self, node, rawtext, transaction, link, p1, p2, flags,
+                     cachedelta, ifh, dfh, alwayscache=False):
         """internal function to add revisions to the log
 
         see addrevision for argument descriptions.
+
+        note: "addrevision" takes non-raw text, "_addrevision" takes raw text.
+
         invariants:
-        - text is optional (can be None); if not set, cachedelta must be set.
+        - rawtext is optional (can be None); if not set, cachedelta must be set.
           if both are set, they must correspond to each other.
-        - raw is optional; if set to True, it indicates the revision data is to
-          be treated by _processflags() as raw. It is usually set by changegroup
-          generation and debug commands.
         """
-        btext = [text]
+        btext = [rawtext]
         def buildtext():
             if btext[0] is not None:
@@ -1608,9 +1608,9 @@  class revlog(object):
                 else:
                     fh = dfh
-                basetext = self.revision(self.node(baserev), _df=fh, raw=raw)
+                basetext = self.revision(self.node(baserev), _df=fh, raw=True)
                 btext[0] = mdiff.patch(basetext, delta)
 
             try:
-                res = self._processflags(btext[0], flags, 'read', raw=raw)
+                res = self._processflags(btext[0], flags, 'read', raw=True)
                 btext[0], validatehash = res
                 if validatehash:
@@ -1664,9 +1664,9 @@  class revlog(object):
         # full versions are inserted when the needed deltas
         # become comparable to the uncompressed text
-        if text is None:
+        if rawtext is None:
             textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]),
                                         cachedelta[1])
         else:
-            textlen = len(text)
+            textlen = len(rawtext)
 
         # should we try to build a delta?
@@ -1709,6 +1709,6 @@  class revlog(object):
             dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta
         else:
-            text = buildtext()
-            data = self.compress(text)
+            rawtext = buildtext()
+            data = self.compress(rawtext)
             l = len(data[1]) + len(data[0])
             base = chainbase = curr
@@ -1722,9 +1722,9 @@  class revlog(object):
         self._writeentry(transaction, ifh, dfh, entry, data, link, offset)
 
-        if alwayscache and text is None:
-            text = buildtext()
+        if alwayscache and rawtext is None:
+            rawtext = buildtext()
 
-        if type(text) == str: # only accept immutable objects
-            self._cache = (node, curr, text)
+        if type(rawtext) == str: # only accept immutable objects
+            self._cache = (node, curr, rawtext)
         self._chainbasecache[curr] = chainbase
         return node
@@ -1848,6 +1848,5 @@  class revlog(object):
                                           p1, p2, flags, (baserev, delta),
                                           ifh, dfh,
-                                          alwayscache=bool(addrevisioncb),
-                                          raw=True)
+                                          alwayscache=bool(addrevisioncb))
 
                 if addrevisioncb:
diff --git a/tests/test-revlog-raw.py.out b/tests/test-revlog-raw.py.out
--- a/tests/test-revlog-raw.py.out
+++ b/tests/test-revlog-raw.py.out
@@ -2,3 +2,3 @@  local test passed
 addgroupcopy test passed
 clone test passed
-abort: crashed: integrity check failed on _destrevlog.i:5
+lowlevelcopy test passed