Patchwork [4,of,9,V2] revlog: fix _cache usage in revision()

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

Comments

Jun Wu - March 31, 2017, 4:45 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1490913248 25200
#      Thu Mar 30 15:34:08 2017 -0700
# Node ID 173d73e93cc25abdcac23fcd858a4e94d29e7461
# Parent  3fb26d049c52534835fd397ceb70b0f83068695a
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 173d73e93cc2
revlog: fix _cache usage in revision()

As documented at revlog.__init__, revlog._cache stores raw text.

The current read and write usage of "_cache" in revlog.revision lacks of
raw=True check.

This patch fixes that by adding check about raw, and storing rawtext
explicitly in _cache.

Note: it may slow down cache hit code path when raw=False and flags=0. That
performance issue will be fixed in a later patch.

test-revlog-raw now points us to a new problem.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1268,5 +1268,7 @@  class revlog(object):
         if self._cache:
             if self._cache[0] == node:
-                return self._cache[2]
+                # _cache only stores rawtext
+                if raw:
+                    return self._cache[2]
             cachedrev = self._cache[1]
 
@@ -1295,5 +1297,5 @@  class revlog(object):
             self.checkhash(text, node, rev=rev)
 
-        self._cache = (node, rev, text)
+        self._cache = (node, rev, rawtext)
         return text
 
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
@@ -1,1 +1,1 @@ 
-abort: rev 5: wrong text
+abort: crashed: integrity check failed on _testrevlog.i:11