D4752: filelog: return correct size when content begins with metadata prefix

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Sep 26 18:29:54 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  An inline TODO tracked this. And we were reminded of it when
  recently implementing storage integration tests. Let's fix it so
  we don't have to port the buggy behavior to future storage backends.
  
  The new call to read() should be fast because the revision
  fulltext should be cached as part of calling renamed(). So the
  overhead here should be minimal.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/filelog.py
  mercurial/testing/storage.py
  tests/test-filelog.py.out

CHANGE DETAILS

diff --git a/tests/test-filelog.py.out b/tests/test-filelog.py.out
--- a/tests/test-filelog.py.out
+++ b/tests/test-filelog.py.out
@@ -1,2 +1 @@
-ERROR: FIXME: This is a known failure of filelog.size for data starting with \1\n
 OK.
diff --git a/mercurial/testing/storage.py b/mercurial/testing/storage.py
--- a/mercurial/testing/storage.py
+++ b/mercurial/testing/storage.py
@@ -859,9 +859,7 @@
             node0 = f.add(fulltext0, {}, tr, 0, nullid, nullid)
             node1 = f.add(fulltext1, meta1, tr, 1, nullid, nullid)
 
-        # TODO this is buggy.
-        self.assertEqual(f.size(0), len(fulltext0) + 4)
-
+        self.assertEqual(f.size(0), len(fulltext0))
         self.assertEqual(f.size(1), len(fulltext1))
 
         self.assertEqual(f.revision(node0), stored0)
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -144,8 +144,12 @@
         if self.iscensored(rev):
             return 0
 
-        # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
-        return self._revlog.size(rev)
+        size = self._revlog.size(rev)
+
+        if self.read(node).startswith(b'\x01\n'):
+            size -= 4
+
+        return size
 
     def cmp(self, node, text):
         """compare text with a given file revision



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


More information about the Mercurial-devel mailing list