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

REVISION SUMMARY
  We are about to reuse this message in more places and the current handling is
  pretty hard to read. So we eat two pie with one stone and clean up this.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -256,6 +256,10 @@
 # signed integer)
 _maxentrysize = 0x7FFFFFFF
 
+PARTIAL_READ_MSG = _(
+    b'partial read of revlog %s; expected %d bytes from offset %d, got %d'
+)
+
 
 class revlog(object):
     """
@@ -1709,34 +1713,17 @@
         if offset != realoffset or reallength != length:
             startoffset = offset - realoffset
             if len(d) - startoffset < length:
-                raise error.RevlogError(
-                    _(
-                        b'partial read of revlog %s; expected %d bytes from '
-                        b'offset %d, got %d'
-                    )
-                    % (
-                        self._indexfile if self._inline else self._datafile,
-                        length,
-                        offset,
-                        len(d) - startoffset,
-                    )
-                )
-
+                filename = self._indexfile if self._inline else self._datafile
+                got = len(d) - startoffset
+                m = PARTIAL_READ_MSG % (filename, length, offset, got)
+                raise error.RevlogError(m)
             return util.buffer(d, startoffset, length)
 
         if len(d) < length:
-            raise error.RevlogError(
-                _(
-                    b'partial read of revlog %s; expected %d bytes from offset 
'
-                    b'%d, got %d'
-                )
-                % (
-                    self._indexfile if self._inline else self._datafile,
-                    length,
-                    offset,
-                    len(d),
-                )
-            )
+            filename = self._indexfile if self._inline else self._datafile
+            got = len(d) - startoffset
+            m = PARTIAL_READ_MSG % (filename, length, offset, got)
+            raise error.RevlogError(m)
 
         return d
 



To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to