Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlog.py @ 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 | df448de7cf3b |
children | d47b62368f3a |
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