changeset 32430:36d3559c69a6

revlog: tweak wording and logic for flags validation First, the logic around the if..elif..elif was subtly wrong and sub-optimal because all branches would be tested as long as the revlog was valid. This patch changes things so it behaves like a switch statement over the revlog version. While I was here, I also tweaked error strings to make them consistent and to read better.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 19 May 2017 20:10:50 -0700
parents 3ea1f1e71a0a
children d47b62368f3a
files mercurial/revlog.py tests/test-requires.t tests/test-revlog.t
diffstat 3 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Fri May 19 20:01:35 2017 -0700
+++ b/mercurial/revlog.py	Fri May 19 20:10:50 2017 -0700
@@ -328,15 +328,19 @@
         self._generaldelta = v & FLAG_GENERALDELTA
         flags = v & ~0xFFFF
         fmt = v & 0xFFFF
-        if fmt == REVLOGV0 and flags:
-            raise RevlogError(_("index %s unknown flags %#04x for format v0")
-                              % (self.indexfile, flags >> 16))
-        elif fmt == REVLOGV1 and flags & ~REVLOGV1_FLAGS:
-            raise RevlogError(_("index %s unknown flags %#04x for revlogng")
-                              % (self.indexfile, flags >> 16))
-        elif fmt > REVLOGV1:
-            raise RevlogError(_("index %s unknown format %d")
-                              % (self.indexfile, fmt))
+        if fmt == REVLOGV0:
+            if flags:
+                raise RevlogError(_('unknown flags (%#04x) in version %d '
+                                    'revlog %s') %
+                                  (flags >> 16, fmt, self.indexfile))
+        elif fmt == REVLOGV1:
+            if flags & ~REVLOGV1_FLAGS:
+                raise RevlogError(_('unknown flags (%#04x) in version %d '
+                                    'revlog %s') %
+                                  (flags >> 16, fmt, self.indexfile))
+        else:
+            raise RevlogError(_('unknown version (%d) in revlog %s') %
+                              (fmt, self.indexfile))
 
         self.storedeltachains = True
 
--- a/tests/test-requires.t	Fri May 19 20:01:35 2017 -0700
+++ b/tests/test-requires.t	Fri May 19 20:10:50 2017 -0700
@@ -5,7 +5,7 @@
   $ hg commit -m test
   $ rm .hg/requires
   $ hg tip
-  abort: index 00changelog.i unknown format 2!
+  abort: unknown version (2) in revlog 00changelog.i!
   [255]
   $ echo indoor-pool > .hg/requires
   $ hg tip
--- a/tests/test-revlog.t	Fri May 19 20:01:35 2017 -0700
+++ b/tests/test-revlog.t	Fri May 19 20:10:50 2017 -0700
@@ -7,7 +7,7 @@
   ...     fh.write('\x00\x01\x00\x00')
 
   $ hg log
-  abort: index 00changelog.i unknown flags 0x01 for format v0!
+  abort: unknown flags (0x01) in version 0 revlog 00changelog.i!
   [255]
 
 Unknown flags on revlog version 1 are rejected
@@ -16,7 +16,7 @@
   ...     fh.write('\x00\x04\x00\x01')
 
   $ hg log
-  abort: index 00changelog.i unknown flags 0x04 for revlogng!
+  abort: unknown flags (0x04) in version 1 revlog 00changelog.i!
   [255]
 
 Unknown version is rejected
@@ -25,7 +25,7 @@
   ...     fh.write('\x00\x00\x00\x02')
 
   $ hg log
-  abort: index 00changelog.i unknown format 2!
+  abort: unknown version (2) in revlog 00changelog.i!
   [255]
 
   $ cd ..