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

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Sep 26 21:12:58 UTC 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG91d2233d3dec: filelog: return correct size when content begins with metadata prefix (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4752?vs=11407&id=11428

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