changeset 47386:0d0fb091c49f

revlog: simplify "partial read" error message 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. Differential Revision: https://phab.mercurial-scm.org/D10784
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 27 May 2021 04:09:10 +0200
parents 9d9eb22b9b69
children 75e1104f23a2
files mercurial/revlog.py
diffstat 1 files changed, 12 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Thu May 27 03:41:02 2021 +0200
+++ b/mercurial/revlog.py	Thu May 27 04:09:10 2021 +0200
@@ -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