revlog: always enable generaldelta on version 2 revlogs
This commit starts the process of diverging version 2 revlogs
from version 1 revlogs.
generaldelta is a useful feature and has been enabled by
default for ages. I can't think of a good reason why the
feature should be disabled. Yes, it is true changelogs
today don't have generaldelta enabled. But that's because
they don't have delta chains enabled, so generaldelta makes
no sense there.
This commit makes generaldelta always enabled on version 2
revlogs.
As part of this, one-off code in changelog.py mucking with
revlog.version had to be made conditional on the revlog
version, as we don't want to change revlog feature
flags on version 2 revlogs. The fact this code exists
is horrible and stems from revlog options being shared by
the opener. We probably want a better API here. But that can
wait for another patch.
Differential Revision: https://phab.mercurial-scm.org/D5561
--- a/mercurial/changelog.py Wed Jan 09 15:45:17 2019 -0800
+++ b/mercurial/changelog.py Wed Jan 09 17:41:36 2019 -0800
@@ -295,8 +295,9 @@
revlog.revlog.__init__(self, opener, indexfile, datafile=datafile,
checkambig=True, mmaplargeindex=True)
- if self._initempty:
- # changelogs don't benefit from generaldelta
+ if self._initempty and (self.version & 0xFFFF == revlog.REVLOGV1):
+ # changelogs don't benefit from generaldelta.
+
self.version &= ~revlog.FLAG_GENERALDELTA
self._generaldelta = False
--- a/mercurial/help/internals/revlogs.txt Wed Jan 09 15:45:17 2019 -0800
+++ b/mercurial/help/internals/revlogs.txt Wed Jan 09 17:41:36 2019 -0800
@@ -66,8 +66,6 @@
0
Store revision data inline.
-1
- Generaldelta encoding.
The following header values are common:
@@ -159,8 +157,10 @@
(In development. Format not finalized or stable.)
-Version 2 is currently identical to version 1. This will obviously
-change.
+Version 2 is identical to version 2 with the following differences.
+
+There is no dedicated *generaldelta* revlog format flag. Instead,
+the feature is implied enabled by default.
Delta Chains
============
--- a/mercurial/localrepo.py Wed Jan 09 15:45:17 2019 -0800
+++ b/mercurial/localrepo.py Wed Jan 09 17:41:36 2019 -0800
@@ -363,7 +363,7 @@
# Increment the sub-version when the revlog v2 format changes to lock out old
# clients.
-REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
+REVLOGV2_REQUIREMENT = 'exp-revlogv2.1'
# A repository with the sparserevlog feature will have delta chains that
# can spread over a larger span. Sparse reading cuts these large spans into
--- a/mercurial/revlog.py Wed Jan 09 15:45:17 2019 -0800
+++ b/mercurial/revlog.py Wed Jan 09 17:41:36 2019 -0800
@@ -387,8 +387,7 @@
opts = getattr(opener, 'options', {}) or {}
if 'revlogv2' in opts:
- # version 2 revlogs always use generaldelta.
- versionflags = REVLOGV2 | FLAG_GENERALDELTA | FLAG_INLINE_DATA
+ versionflags = REVLOGV2 | FLAG_INLINE_DATA
elif 'revlogv1' in opts:
versionflags = REVLOGV1 | FLAG_INLINE_DATA
if 'generaldelta' in opts:
@@ -451,25 +450,38 @@
raise
self.version = versionflags
- self._inline = versionflags & FLAG_INLINE_DATA
- self._generaldelta = versionflags & FLAG_GENERALDELTA
+
flags = versionflags & ~0xFFFF
fmt = versionflags & 0xFFFF
+
if fmt == REVLOGV0:
if flags:
raise error.RevlogError(_('unknown flags (%#04x) in version %d '
'revlog %s') %
(flags >> 16, fmt, self.indexfile))
+
+ self._inline = False
+ self._generaldelta = False
+
elif fmt == REVLOGV1:
if flags & ~REVLOGV1_FLAGS:
raise error.RevlogError(_('unknown flags (%#04x) in version %d '
'revlog %s') %
(flags >> 16, fmt, self.indexfile))
+
+ self._inline = versionflags & FLAG_INLINE_DATA
+ self._generaldelta = versionflags & FLAG_GENERALDELTA
+
elif fmt == REVLOGV2:
if flags & ~REVLOGV2_FLAGS:
raise error.RevlogError(_('unknown flags (%#04x) in version %d '
'revlog %s') %
(flags >> 16, fmt, self.indexfile))
+
+ self._inline = versionflags & FLAG_INLINE_DATA
+ # generaldelta implied by version 2 revlogs.
+ self._generaldelta = True
+
else:
raise error.RevlogError(_('unknown version (%d) in revlog %s') %
(fmt, self.indexfile))
--- a/mercurial/revlogutils/constants.py Wed Jan 09 15:45:17 2019 -0800
+++ b/mercurial/revlogutils/constants.py Wed Jan 09 17:41:36 2019 -0800
@@ -20,13 +20,15 @@
# Dummy value until file format is finalized.
# Reminder: change the bounds check in revlog.__init__ when this is changed.
REVLOGV2 = 0xDEAD
+# Shared across v1 and v2.
FLAG_INLINE_DATA = (1 << 16)
+# Only used by v1, implied by v2.
FLAG_GENERALDELTA = (1 << 17)
REVLOG_DEFAULT_FLAGS = FLAG_INLINE_DATA
REVLOG_DEFAULT_FORMAT = REVLOGV1
REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
REVLOGV1_FLAGS = FLAG_INLINE_DATA | FLAG_GENERALDELTA
-REVLOGV2_FLAGS = REVLOGV1_FLAGS
+REVLOGV2_FLAGS = FLAG_INLINE_DATA
# revlog index flags
--- a/tests/test-revlog-v2.t Wed Jan 09 15:45:17 2019 -0800
+++ b/tests/test-revlog-v2.t Wed Jan 09 17:41:36 2019 -0800
@@ -22,7 +22,7 @@
$ cd empty-repo
$ cat .hg/requires
dotencode
- exp-revlogv2.0
+ exp-revlogv2.1
fncache
sparserevlog
store
@@ -54,7 +54,7 @@
date: Thu Jan 01 00:00:00 1970 +0000
summary: initial
-Header written as expected (changelog always disables generaldelta)
+Header written as expected
$ f --hexdump --bytes 4 .hg/store/00changelog.i
.hg/store/00changelog.i:
@@ -62,4 +62,4 @@
$ f --hexdump --bytes 4 .hg/store/data/foo.i
.hg/store/data/foo.i:
- 0000: 00 03 de ad |....|
+ 0000: 00 01 de ad |....|