[PATCH 2 of 7] revlog: make sure _cache only contain raw content

Jun Wu quark at fb.com
Tue Mar 28 03:49:03 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1490685282 25200
#      Tue Mar 28 00:14:42 2017 -0700
# Node ID 99cfe31d37df62b50e53a126f0eb31a1e352ac67
# Parent  1e84f9bd4385a8f95ac1ec15dee14c723071ab34
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 99cfe31d37df
revlog: make sure _cache only contain raw content

Previously, revlog._cache could cache both raw and non-raw content. That is
wrong, because _cache will be used directly for delta application. If the
non-raw content in _cache is used, it may corrupt delta application, or
return wrong content when deltas applied successfully but incorrectly, and a
flagprocessor says skip the hash check.

This patch changes _cache assignments to make sure only only raw contents
are assigned to it.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1284,11 +1284,11 @@ class revlog(object):
         text = mdiff.patches(text, bins)
 
-        text, validatehash = self._processflags(text, self.flags(rev), 'read',
-                                                raw=raw)
+        newtext, validatehash = self._processflags(text, self.flags(rev),
+                                                   'read', raw=raw)
         if validatehash:
-            self.checkhash(text, node, rev=rev)
+            self.checkhash(newtext, node, rev=rev)
 
         self._cache = (node, rev, text)
-        return text
+        return newtext
 
     def hash(self, text, p1, p2):
@@ -1715,5 +1715,6 @@ class revlog(object):
 
         if type(text) == str: # only accept immutable objects
-            self._cache = (node, curr, text)
+            if raw or not flags:
+                self._cache = (node, curr, text)
         self._chainbasecache[curr] = chainbase
         return node


More information about the Mercurial-devel mailing list