Patchwork D10784: revlog: simplify "partial read" error message

login
register
mail settings
Submitter phabricator
Date May 28, 2021, 10:58 p.m.
Message ID <differential-rev-PHID-DREV-zopl7ixr3zrvqfphn53n-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49105/
State Superseded
Headers show

Comments

phabricator - May 28, 2021, 10:58 p.m.
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




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

Patch

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