2009-04-26 03:13:08 +04:00
|
|
|
# revlog.py - storage back-end for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2009-04-26 03:24:49 +04:00
|
|
|
"""Storage back-end for Mercurial.
|
|
|
|
|
|
|
|
This provides efficient delta storage with O(1) retrieve and append
|
|
|
|
and O(changes) merge between branches.
|
|
|
|
"""
|
|
|
|
|
2015-12-13 10:22:18 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-06-20 19:41:46 +03:00
|
|
|
import binascii
|
2015-05-16 21:28:04 +03:00
|
|
|
import collections
|
2015-12-13 10:22:18 +03:00
|
|
|
import errno
|
2016-06-10 07:10:34 +03:00
|
|
|
import hashlib
|
2017-10-18 13:53:00 +03:00
|
|
|
import heapq
|
2015-12-18 04:16:02 +03:00
|
|
|
import os
|
2015-12-13 10:22:18 +03:00
|
|
|
import struct
|
|
|
|
import zlib
|
|
|
|
|
|
|
|
# import stuff from node for others to import from revlog
|
|
|
|
from .node import (
|
|
|
|
bin,
|
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
nullrev,
|
2016-08-19 12:26:04 +03:00
|
|
|
wdirhex,
|
2016-08-20 16:37:58 +03:00
|
|
|
wdirid,
|
2017-05-19 16:42:06 +03:00
|
|
|
wdirrev,
|
2015-12-13 10:22:18 +03:00
|
|
|
)
|
|
|
|
from .i18n import _
|
|
|
|
from . import (
|
|
|
|
ancestor,
|
|
|
|
error,
|
|
|
|
mdiff,
|
2016-08-13 06:23:56 +03:00
|
|
|
policy,
|
2017-03-22 00:39:49 +03:00
|
|
|
pycompat,
|
2015-12-13 10:22:18 +03:00
|
|
|
templatefilters,
|
|
|
|
util,
|
|
|
|
)
|
2005-05-08 04:11:36 +04:00
|
|
|
|
2016-08-13 06:23:56 +03:00
|
|
|
parsers = policy.importmod(r'parsers')
|
|
|
|
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
# Aliased for performance.
|
|
|
|
_zlibdecompress = zlib.decompress
|
2007-07-26 21:02:58 +04:00
|
|
|
|
2010-08-03 18:08:19 +04:00
|
|
|
# revlog header flags
|
2006-04-05 00:38:43 +04:00
|
|
|
REVLOGV0 = 0
|
2017-05-18 05:52:18 +03:00
|
|
|
REVLOGV1 = 1
|
2017-05-20 06:29:11 +03:00
|
|
|
# Dummy value until file format is finalized.
|
|
|
|
# Reminder: change the bounds check in revlog.__init__ when this is changed.
|
|
|
|
REVLOGV2 = 0xDEAD
|
2017-05-18 05:52:18 +03:00
|
|
|
FLAG_INLINE_DATA = (1 << 16)
|
|
|
|
FLAG_GENERALDELTA = (1 << 17)
|
|
|
|
REVLOG_DEFAULT_FLAGS = FLAG_INLINE_DATA
|
|
|
|
REVLOG_DEFAULT_FORMAT = REVLOGV1
|
2006-05-08 23:26:18 +04:00
|
|
|
REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
|
2017-05-18 05:52:18 +03:00
|
|
|
REVLOGV1_FLAGS = FLAG_INLINE_DATA | FLAG_GENERALDELTA
|
2017-05-20 06:29:11 +03:00
|
|
|
REVLOGV2_FLAGS = REVLOGV1_FLAGS
|
2010-08-03 18:08:19 +04:00
|
|
|
|
|
|
|
# revlog index flags
|
2015-01-12 22:01:52 +03:00
|
|
|
REVIDX_ISCENSORED = (1 << 15) # revision has censor metadata, must be verified
|
2017-01-17 22:25:02 +03:00
|
|
|
REVIDX_ELLIPSIS = (1 << 14) # revision hash does not match data (narrowhg)
|
|
|
|
REVIDX_EXTSTORED = (1 << 13) # revision data is stored externally
|
2015-01-12 22:01:52 +03:00
|
|
|
REVIDX_DEFAULT_FLAGS = 0
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
# stable order in which flags need to be processed and their processors applied
|
|
|
|
REVIDX_FLAGS_ORDER = [
|
|
|
|
REVIDX_ISCENSORED,
|
2017-01-17 22:25:02 +03:00
|
|
|
REVIDX_ELLIPSIS,
|
2017-01-05 20:16:51 +03:00
|
|
|
REVIDX_EXTSTORED,
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
]
|
|
|
|
REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER)
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2010-04-15 17:21:21 +04:00
|
|
|
# max size of revlog with inline data
|
|
|
|
_maxinline = 131072
|
2011-01-04 23:12:52 +03:00
|
|
|
_chunksize = 1048576
|
2010-04-14 01:58:38 +04:00
|
|
|
|
2009-01-12 07:48:28 +03:00
|
|
|
RevlogError = error.RevlogError
|
|
|
|
LookupError = error.LookupError
|
2014-09-04 00:34:29 +04:00
|
|
|
CensoredNodeError = error.CensoredNodeError
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
ProgrammingError = error.ProgrammingError
|
|
|
|
|
|
|
|
# Store flag processors (cf. 'addflagprocessor()' to register)
|
|
|
|
_flagprocessors = {
|
|
|
|
REVIDX_ISCENSORED: None,
|
|
|
|
}
|
|
|
|
|
|
|
|
def addflagprocessor(flag, processor):
|
|
|
|
"""Register a flag processor on a revision data flag.
|
|
|
|
|
|
|
|
Invariant:
|
|
|
|
- Flags need to be defined in REVIDX_KNOWN_FLAGS and REVIDX_FLAGS_ORDER.
|
|
|
|
- Only one flag processor can be registered on a specific flag.
|
|
|
|
- flagprocessors must be 3-tuples of functions (read, write, raw) with the
|
|
|
|
following signatures:
|
2017-03-30 17:59:48 +03:00
|
|
|
- (read) f(self, rawtext) -> text, bool
|
|
|
|
- (write) f(self, text) -> rawtext, bool
|
|
|
|
- (raw) f(self, rawtext) -> bool
|
|
|
|
"text" is presented to the user. "rawtext" is stored in revlog data, not
|
|
|
|
directly visible to the user.
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
The boolean returned by these transforms is used to determine whether
|
2017-03-30 17:59:48 +03:00
|
|
|
the returned text can be used for hash integrity checking. For example,
|
|
|
|
if "write" returns False, then "text" is used to generate hash. If
|
|
|
|
"write" returns True, that basically means "rawtext" returned by "write"
|
|
|
|
should be used to generate hash. Usually, "write" and "read" return
|
|
|
|
different booleans. And "raw" returns a same boolean as "write".
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
|
|
|
|
Note: The 'raw' transform is used for changegroup generation and in some
|
|
|
|
debug commands. In this case the transform only indicates whether the
|
|
|
|
contents can be used for hash integrity checks.
|
|
|
|
"""
|
|
|
|
if not flag & REVIDX_KNOWN_FLAGS:
|
|
|
|
msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
|
|
|
|
raise ProgrammingError(msg)
|
|
|
|
if flag not in REVIDX_FLAGS_ORDER:
|
|
|
|
msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % (flag)
|
|
|
|
raise ProgrammingError(msg)
|
|
|
|
if flag in _flagprocessors:
|
|
|
|
msg = _("cannot register multiple processors on flag '%#x'.") % (flag)
|
|
|
|
raise error.Abort(msg)
|
|
|
|
_flagprocessors[flag] = processor
|
2008-06-18 17:47:47 +04:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
def getoffset(q):
|
|
|
|
return int(q >> 16)
|
|
|
|
|
|
|
|
def gettype(q):
|
|
|
|
return int(q & 0xFFFF)
|
|
|
|
|
|
|
|
def offset_type(offset, type):
|
2016-11-28 15:34:01 +03:00
|
|
|
if (type & ~REVIDX_KNOWN_FLAGS) != 0:
|
|
|
|
raise ValueError('unknown revlog index flags')
|
2017-03-19 08:05:28 +03:00
|
|
|
return int(int(offset) << 16 | type)
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2016-06-10 07:10:34 +03:00
|
|
|
_nullhash = hashlib.sha1(nullid)
|
2009-03-23 17:32:29 +03:00
|
|
|
|
2005-08-28 01:43:20 +04:00
|
|
|
def hash(text, p1, p2):
|
|
|
|
"""generate a hash from the given text and its parent hashes
|
|
|
|
|
|
|
|
This hash combines both the current file contents and its history
|
|
|
|
in a manner that makes it easy to distinguish nodes with the same
|
|
|
|
content in the revision graph.
|
|
|
|
"""
|
2009-03-23 17:32:29 +03:00
|
|
|
# As of now, if one of the parent node is null, p2 is null
|
|
|
|
if p2 == nullid:
|
|
|
|
# deep copy of a hash is faster than creating one
|
2014-09-24 23:10:52 +04:00
|
|
|
s = _nullhash.copy()
|
2009-03-23 17:32:29 +03:00
|
|
|
s.update(p1)
|
|
|
|
else:
|
|
|
|
# none of the parent nodes are nullid
|
2017-07-10 23:39:28 +03:00
|
|
|
if p1 < p2:
|
|
|
|
a = p1
|
|
|
|
b = p2
|
|
|
|
else:
|
|
|
|
a = p2
|
|
|
|
b = p1
|
|
|
|
s = hashlib.sha1(a)
|
|
|
|
s.update(b)
|
2005-08-28 01:43:20 +04:00
|
|
|
s.update(text)
|
|
|
|
return s.digest()
|
|
|
|
|
2017-10-18 16:28:19 +03:00
|
|
|
def _trimchunk(revlog, revs, startidx, endidx=None):
|
|
|
|
"""returns revs[startidx:endidx] without empty trailing revs
|
|
|
|
"""
|
|
|
|
length = revlog.length
|
|
|
|
|
|
|
|
if endidx is None:
|
|
|
|
endidx = len(revs)
|
|
|
|
|
|
|
|
# Trim empty revs at the end, but never the very first revision of a chain
|
|
|
|
while endidx > 1 and endidx > startidx and length(revs[endidx - 1]) == 0:
|
|
|
|
endidx -= 1
|
|
|
|
|
|
|
|
return revs[startidx:endidx]
|
|
|
|
|
2017-10-10 18:50:27 +03:00
|
|
|
def _slicechunk(revlog, revs):
|
|
|
|
"""slice revs to reduce the amount of unrelated data to be read from disk.
|
|
|
|
|
|
|
|
``revs`` is sliced into groups that should be read in one time.
|
|
|
|
Assume that revs are sorted.
|
|
|
|
"""
|
|
|
|
start = revlog.start
|
|
|
|
length = revlog.length
|
|
|
|
|
2017-10-18 13:53:00 +03:00
|
|
|
if len(revs) <= 1:
|
|
|
|
yield revs
|
|
|
|
return
|
|
|
|
|
|
|
|
startbyte = start(revs[0])
|
|
|
|
endbyte = start(revs[-1]) + length(revs[-1])
|
|
|
|
readdata = deltachainspan = endbyte - startbyte
|
|
|
|
|
|
|
|
chainpayload = sum(length(r) for r in revs)
|
|
|
|
|
|
|
|
if deltachainspan:
|
|
|
|
density = chainpayload / float(deltachainspan)
|
|
|
|
else:
|
|
|
|
density = 1.0
|
|
|
|
|
|
|
|
# Store the gaps in a heap to have them sorted by decreasing size
|
|
|
|
gapsheap = []
|
|
|
|
heapq.heapify(gapsheap)
|
|
|
|
prevend = None
|
|
|
|
for i, rev in enumerate(revs):
|
|
|
|
revstart = start(rev)
|
|
|
|
revlen = length(rev)
|
|
|
|
|
2017-10-18 16:28:19 +03:00
|
|
|
# Skip empty revisions to form larger holes
|
|
|
|
if revlen == 0:
|
|
|
|
continue
|
|
|
|
|
2017-10-18 13:53:00 +03:00
|
|
|
if prevend is not None:
|
|
|
|
gapsize = revstart - prevend
|
2017-10-18 10:07:48 +03:00
|
|
|
# only consider holes that are large enough
|
|
|
|
if gapsize > revlog._srmingapsize:
|
2017-10-18 13:53:00 +03:00
|
|
|
heapq.heappush(gapsheap, (-gapsize, i))
|
|
|
|
|
|
|
|
prevend = revstart + revlen
|
|
|
|
|
|
|
|
# Collect the indices of the largest holes until the density is acceptable
|
|
|
|
indicesheap = []
|
|
|
|
heapq.heapify(indicesheap)
|
|
|
|
while gapsheap and density < revlog._srdensitythreshold:
|
|
|
|
oppgapsize, gapidx = heapq.heappop(gapsheap)
|
|
|
|
|
|
|
|
heapq.heappush(indicesheap, gapidx)
|
|
|
|
|
|
|
|
# the gap sizes are stored as negatives to be sorted decreasingly
|
|
|
|
# by the heap
|
|
|
|
readdata -= (-oppgapsize)
|
|
|
|
if readdata > 0:
|
|
|
|
density = chainpayload / float(readdata)
|
|
|
|
else:
|
|
|
|
density = 1.0
|
|
|
|
|
|
|
|
# Cut the revs at collected indices
|
|
|
|
previdx = 0
|
|
|
|
while indicesheap:
|
|
|
|
idx = heapq.heappop(indicesheap)
|
2017-10-18 16:28:19 +03:00
|
|
|
|
|
|
|
chunk = _trimchunk(revlog, revs, previdx, idx)
|
|
|
|
if chunk:
|
|
|
|
yield chunk
|
|
|
|
|
2017-10-18 13:53:00 +03:00
|
|
|
previdx = idx
|
2017-10-18 16:28:19 +03:00
|
|
|
|
|
|
|
chunk = _trimchunk(revlog, revs, previdx)
|
|
|
|
if chunk:
|
|
|
|
yield chunk
|
2017-10-10 18:50:27 +03:00
|
|
|
|
2013-02-09 15:08:02 +04:00
|
|
|
# index v0:
|
|
|
|
# 4 bytes: offset
|
|
|
|
# 4 bytes: compressed length
|
|
|
|
# 4 bytes: base rev
|
|
|
|
# 4 bytes: link rev
|
2015-08-01 19:14:11 +03:00
|
|
|
# 20 bytes: parent 1 nodeid
|
|
|
|
# 20 bytes: parent 2 nodeid
|
|
|
|
# 20 bytes: nodeid
|
2017-07-10 23:41:13 +03:00
|
|
|
indexformatv0 = struct.Struct(">4l20s20s20s")
|
|
|
|
indexformatv0_pack = indexformatv0.pack
|
|
|
|
indexformatv0_unpack = indexformatv0.unpack
|
2007-07-22 01:18:21 +04:00
|
|
|
|
2007-07-24 05:44:07 +04:00
|
|
|
class revlogoldio(object):
|
|
|
|
def __init__(self):
|
2017-07-10 23:41:13 +03:00
|
|
|
self.size = indexformatv0.size
|
2007-07-24 05:44:07 +04:00
|
|
|
|
2011-01-15 17:04:58 +03:00
|
|
|
def parseindex(self, data, inline):
|
2007-07-24 05:44:08 +04:00
|
|
|
s = self.size
|
2007-07-24 05:44:07 +04:00
|
|
|
index = []
|
2015-12-31 11:16:59 +03:00
|
|
|
nodemap = {nullid: nullrev}
|
2007-07-24 05:44:07 +04:00
|
|
|
n = off = 0
|
|
|
|
l = len(data)
|
|
|
|
while off + s <= l:
|
|
|
|
cur = data[off:off + s]
|
|
|
|
off += s
|
2017-07-10 23:41:13 +03:00
|
|
|
e = indexformatv0_unpack(cur)
|
2007-07-24 05:44:08 +04:00
|
|
|
# transform to revlogv1 format
|
|
|
|
e2 = (offset_type(e[0], 0), e[1], -1, e[2], e[3],
|
2007-11-24 21:13:32 +03:00
|
|
|
nodemap.get(e[4], nullrev), nodemap.get(e[5], nullrev), e[6])
|
2007-07-24 05:44:08 +04:00
|
|
|
index.append(e2)
|
|
|
|
nodemap[e[6]] = n
|
2007-07-24 05:44:07 +04:00
|
|
|
n += 1
|
2007-07-24 05:44:07 +04:00
|
|
|
|
2011-01-15 15:02:19 +03:00
|
|
|
# add the magic null revision at -1
|
|
|
|
index.append((0, 0, 0, -1, -1, -1, -1, nullid))
|
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
return index, nodemap, None
|
2007-07-24 05:44:07 +04:00
|
|
|
|
2007-09-26 08:58:45 +04:00
|
|
|
def packentry(self, entry, node, version, rev):
|
2010-02-08 19:28:19 +03:00
|
|
|
if gettype(entry[0]):
|
2017-05-20 06:14:31 +03:00
|
|
|
raise RevlogError(_('index entry flags need revlog version 1'))
|
2007-07-24 05:44:08 +04:00
|
|
|
e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
|
|
|
|
node(entry[5]), node(entry[6]), entry[7])
|
2017-07-10 23:41:13 +03:00
|
|
|
return indexformatv0_pack(*e2)
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
# index ng:
|
2010-06-10 19:10:05 +04:00
|
|
|
# 6 bytes: offset
|
|
|
|
# 2 bytes: flags
|
|
|
|
# 4 bytes: compressed length
|
|
|
|
# 4 bytes: uncompressed length
|
|
|
|
# 4 bytes: base rev
|
|
|
|
# 4 bytes: link rev
|
|
|
|
# 4 bytes: parent 1 rev
|
|
|
|
# 4 bytes: parent 2 rev
|
2007-07-24 05:44:08 +04:00
|
|
|
# 32 bytes: nodeid
|
2017-07-10 23:41:13 +03:00
|
|
|
indexformatng = struct.Struct(">Qiiiiii20s12x")
|
|
|
|
indexformatng_pack = indexformatng.pack
|
|
|
|
versionformat = struct.Struct(">I")
|
|
|
|
versionformat_pack = versionformat.pack
|
|
|
|
versionformat_unpack = versionformat.unpack
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2015-06-02 22:04:39 +03:00
|
|
|
# corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
|
|
|
|
# signed integer)
|
|
|
|
_maxentrysize = 0x7fffffff
|
|
|
|
|
2007-07-24 05:44:07 +04:00
|
|
|
class revlogio(object):
|
|
|
|
def __init__(self):
|
2017-07-10 23:41:13 +03:00
|
|
|
self.size = indexformatng.size
|
2007-07-24 05:44:07 +04:00
|
|
|
|
2011-01-15 17:04:58 +03:00
|
|
|
def parseindex(self, data, inline):
|
2008-10-17 02:24:22 +04:00
|
|
|
# call the C implementation to parse the index data
|
2011-01-12 02:01:04 +03:00
|
|
|
index, cache = parsers.parse_index2(data, inline)
|
2012-04-13 01:05:59 +04:00
|
|
|
return index, getattr(index, 'nodemap', None), cache
|
2007-07-24 05:44:07 +04:00
|
|
|
|
2007-09-26 08:58:45 +04:00
|
|
|
def packentry(self, entry, node, version, rev):
|
2017-07-10 23:41:13 +03:00
|
|
|
p = indexformatng_pack(*entry)
|
2007-09-26 08:58:45 +04:00
|
|
|
if rev == 0:
|
2017-07-10 23:41:13 +03:00
|
|
|
p = versionformat_pack(version) + p[4:]
|
2007-07-24 05:44:08 +04:00
|
|
|
return p
|
|
|
|
|
2005-11-19 09:48:47 +03:00
|
|
|
class revlog(object):
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
|
|
|
the underlying revision storage object
|
|
|
|
|
|
|
|
A revlog consists of two parts, an index and the revision data.
|
|
|
|
|
|
|
|
The index is a file with a fixed record size containing
|
2008-08-12 15:45:48 +04:00
|
|
|
information on each revision, including its nodeid (hash), the
|
2005-08-27 12:43:48 +04:00
|
|
|
nodeids of its parents, the position and offset of its data within
|
|
|
|
the data file, and the revision it's based on. Finally, each entry
|
|
|
|
contains a linkrev entry that can serve as a pointer to external
|
|
|
|
data.
|
|
|
|
|
|
|
|
The revision data itself is a linear collection of data chunks.
|
|
|
|
Each chunk represents a revision and is usually represented as a
|
|
|
|
delta against the previous chunk. To bound lookup time, runs of
|
|
|
|
deltas are limited to about 2 times the length of the original
|
|
|
|
version data. This makes retrieval of a version proportional to
|
|
|
|
its size, or O(1) relative to the number of revisions.
|
|
|
|
|
|
|
|
Both pieces of the revlog are written to in an append-only
|
|
|
|
fashion, which means we never need to rewrite a file to insert or
|
|
|
|
remove data, and can use some simple techniques to avoid the need
|
|
|
|
for locking while reading.
|
2016-09-22 15:51:58 +03:00
|
|
|
|
|
|
|
If checkambig, indexfile is opened with checkambig=True at
|
|
|
|
writing, to avoid file stat ambiguity.
|
2017-09-13 20:26:26 +03:00
|
|
|
|
|
|
|
If mmaplargeindex is True, and an mmapindexthreshold is set, the
|
|
|
|
index will be mmapped rather than read if it is larger than the
|
|
|
|
configured threshold.
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
2017-09-13 20:26:26 +03:00
|
|
|
def __init__(self, opener, indexfile, datafile=None, checkambig=False,
|
|
|
|
mmaplargeindex=False):
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
|
|
|
create a revlog object
|
|
|
|
|
|
|
|
opener is a function that abstracts the file opening operation
|
|
|
|
and can be used to implement COW semantics or the like.
|
|
|
|
"""
|
2005-05-04 01:16:10 +04:00
|
|
|
self.indexfile = indexfile
|
2017-05-18 06:14:27 +03:00
|
|
|
self.datafile = datafile or (indexfile[:-2] + ".d")
|
2005-05-04 01:16:10 +04:00
|
|
|
self.opener = opener
|
2016-09-22 15:51:58 +03:00
|
|
|
# When True, indexfile is opened with checkambig=True at writing, to
|
|
|
|
# avoid file stat ambiguity.
|
|
|
|
self._checkambig = checkambig
|
2015-11-23 03:23:20 +03:00
|
|
|
# 3-tuple of (node, rev, text) for a raw revision.
|
2007-07-24 05:44:08 +04:00
|
|
|
self._cache = None
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
# Maps rev to chain base rev.
|
|
|
|
self._chainbasecache = util.lrucachedict(100)
|
2015-11-23 03:23:20 +03:00
|
|
|
# 2-tuple of (offset, data) of raw data from the revlog at an offset.
|
2009-05-08 04:39:45 +04:00
|
|
|
self._chunkcache = (0, '')
|
2015-11-23 03:23:20 +03:00
|
|
|
# How much data to read and cache into the raw revlog data cache.
|
revlog: allow tuning of the chunk cache size (via format.chunkcachesize)
Running perfmoonwalk on the Mercurial repo (with almost 20,000 changesets) on
Mac OS X with an SSD, before this change:
$ hg --config format.chunkcachesize=1024 perfmoonwalk
! wall 2.022021 comb 2.030000 user 1.970000 sys 0.060000 (best of 5)
(16,154 cache hits, 3,840 misses.)
$ hg --config format.chunkcachesize=4096 perfmoonwalk
! wall 1.901006 comb 1.900000 user 1.880000 sys 0.020000 (best of 6)
(19,003 hits, 991 misses.)
$ hg --config format.chunkcachesize=16384 perfmoonwalk
! wall 1.802775 comb 1.800000 user 1.800000 sys 0.000000 (best of 6)
(19,746 hits, 248 misses.)
$ hg --config format.chunkcachesize=32768 perfmoonwalk
! wall 1.818545 comb 1.810000 user 1.810000 sys 0.000000 (best of 6)
(19,870 hits, 124 misses.)
$ hg --config format.chunkcachesize=65536 perfmoonwalk
! wall 1.801350 comb 1.810000 user 1.800000 sys 0.010000 (best of 6)
(19,932 hits, 62 misses.)
$ hg --config format.chunkcachesize=131072 perfmoonwalk
! wall 1.805879 comb 1.820000 user 1.810000 sys 0.010000 (best of 6)
(19,963 hits, 31 misses.)
We may want to change the default size in the future based on testing and
user feedback.
2013-11-18 03:04:29 +04:00
|
|
|
self._chunkcachesize = 65536
|
2014-11-07 01:20:05 +03:00
|
|
|
self._maxchainlen = None
|
2015-08-31 00:03:32 +03:00
|
|
|
self._aggressivemergedeltas = False
|
2007-07-24 05:44:08 +04:00
|
|
|
self.index = []
|
2015-11-23 03:23:20 +03:00
|
|
|
# Mapping of partial identifiers to full nodes.
|
2011-01-12 02:12:32 +03:00
|
|
|
self._pcache = {}
|
2015-11-23 03:23:20 +03:00
|
|
|
# Mapping of revision integer to full node.
|
2011-01-19 00:55:46 +03:00
|
|
|
self._nodecache = {nullid: nullrev}
|
|
|
|
self._nodepos = None
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
self._compengine = 'zlib'
|
2017-06-23 14:49:34 +03:00
|
|
|
self._maxdeltachainspan = -1
|
2017-10-10 18:50:27 +03:00
|
|
|
self._withsparseread = False
|
|
|
|
self._srdensitythreshold = 0.25
|
2017-10-18 10:07:48 +03:00
|
|
|
self._srmingapsize = 262144
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2017-09-13 20:26:26 +03:00
|
|
|
mmapindexthreshold = None
|
2007-07-24 05:44:08 +04:00
|
|
|
v = REVLOG_DEFAULT_VERSION
|
2011-07-26 00:43:55 +04:00
|
|
|
opts = getattr(opener, 'options', None)
|
|
|
|
if opts is not None:
|
2017-05-20 06:29:11 +03:00
|
|
|
if 'revlogv2' in opts:
|
|
|
|
# version 2 revlogs always use generaldelta.
|
|
|
|
v = REVLOGV2 | FLAG_GENERALDELTA | FLAG_INLINE_DATA
|
|
|
|
elif 'revlogv1' in opts:
|
2011-07-26 00:43:55 +04:00
|
|
|
if 'generaldelta' in opts:
|
2017-05-18 05:52:18 +03:00
|
|
|
v |= FLAG_GENERALDELTA
|
2011-05-16 14:44:34 +04:00
|
|
|
else:
|
|
|
|
v = 0
|
revlog: allow tuning of the chunk cache size (via format.chunkcachesize)
Running perfmoonwalk on the Mercurial repo (with almost 20,000 changesets) on
Mac OS X with an SSD, before this change:
$ hg --config format.chunkcachesize=1024 perfmoonwalk
! wall 2.022021 comb 2.030000 user 1.970000 sys 0.060000 (best of 5)
(16,154 cache hits, 3,840 misses.)
$ hg --config format.chunkcachesize=4096 perfmoonwalk
! wall 1.901006 comb 1.900000 user 1.880000 sys 0.020000 (best of 6)
(19,003 hits, 991 misses.)
$ hg --config format.chunkcachesize=16384 perfmoonwalk
! wall 1.802775 comb 1.800000 user 1.800000 sys 0.000000 (best of 6)
(19,746 hits, 248 misses.)
$ hg --config format.chunkcachesize=32768 perfmoonwalk
! wall 1.818545 comb 1.810000 user 1.810000 sys 0.000000 (best of 6)
(19,870 hits, 124 misses.)
$ hg --config format.chunkcachesize=65536 perfmoonwalk
! wall 1.801350 comb 1.810000 user 1.800000 sys 0.010000 (best of 6)
(19,932 hits, 62 misses.)
$ hg --config format.chunkcachesize=131072 perfmoonwalk
! wall 1.805879 comb 1.820000 user 1.810000 sys 0.010000 (best of 6)
(19,963 hits, 31 misses.)
We may want to change the default size in the future based on testing and
user feedback.
2013-11-18 03:04:29 +04:00
|
|
|
if 'chunkcachesize' in opts:
|
|
|
|
self._chunkcachesize = opts['chunkcachesize']
|
2014-11-07 01:20:05 +03:00
|
|
|
if 'maxchainlen' in opts:
|
|
|
|
self._maxchainlen = opts['maxchainlen']
|
2015-08-31 00:03:32 +03:00
|
|
|
if 'aggressivemergedeltas' in opts:
|
|
|
|
self._aggressivemergedeltas = opts['aggressivemergedeltas']
|
2015-11-02 18:59:12 +03:00
|
|
|
self._lazydeltabase = bool(opts.get('lazydeltabase', False))
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
if 'compengine' in opts:
|
|
|
|
self._compengine = opts['compengine']
|
2017-06-23 14:49:34 +03:00
|
|
|
if 'maxdeltachainspan' in opts:
|
|
|
|
self._maxdeltachainspan = opts['maxdeltachainspan']
|
2017-09-13 20:26:26 +03:00
|
|
|
if mmaplargeindex and 'mmapindexthreshold' in opts:
|
|
|
|
mmapindexthreshold = opts['mmapindexthreshold']
|
2017-10-10 18:50:27 +03:00
|
|
|
self._withsparseread = bool(opts.get('with-sparse-read', False))
|
|
|
|
if 'sparse-read-density-threshold' in opts:
|
|
|
|
self._srdensitythreshold = opts['sparse-read-density-threshold']
|
2017-10-18 10:07:48 +03:00
|
|
|
if 'sparse-read-min-gap-size' in opts:
|
|
|
|
self._srmingapsize = opts['sparse-read-min-gap-size']
|
revlog: allow tuning of the chunk cache size (via format.chunkcachesize)
Running perfmoonwalk on the Mercurial repo (with almost 20,000 changesets) on
Mac OS X with an SSD, before this change:
$ hg --config format.chunkcachesize=1024 perfmoonwalk
! wall 2.022021 comb 2.030000 user 1.970000 sys 0.060000 (best of 5)
(16,154 cache hits, 3,840 misses.)
$ hg --config format.chunkcachesize=4096 perfmoonwalk
! wall 1.901006 comb 1.900000 user 1.880000 sys 0.020000 (best of 6)
(19,003 hits, 991 misses.)
$ hg --config format.chunkcachesize=16384 perfmoonwalk
! wall 1.802775 comb 1.800000 user 1.800000 sys 0.000000 (best of 6)
(19,746 hits, 248 misses.)
$ hg --config format.chunkcachesize=32768 perfmoonwalk
! wall 1.818545 comb 1.810000 user 1.810000 sys 0.000000 (best of 6)
(19,870 hits, 124 misses.)
$ hg --config format.chunkcachesize=65536 perfmoonwalk
! wall 1.801350 comb 1.810000 user 1.800000 sys 0.010000 (best of 6)
(19,932 hits, 62 misses.)
$ hg --config format.chunkcachesize=131072 perfmoonwalk
! wall 1.805879 comb 1.820000 user 1.810000 sys 0.010000 (best of 6)
(19,963 hits, 31 misses.)
We may want to change the default size in the future based on testing and
user feedback.
2013-11-18 03:04:29 +04:00
|
|
|
|
|
|
|
if self._chunkcachesize <= 0:
|
|
|
|
raise RevlogError(_('revlog chunk cache size %r is not greater '
|
|
|
|
'than 0') % self._chunkcachesize)
|
|
|
|
elif self._chunkcachesize & (self._chunkcachesize - 1):
|
|
|
|
raise RevlogError(_('revlog chunk cache size %r is not a power '
|
|
|
|
'of 2') % self._chunkcachesize)
|
2010-08-10 20:55:08 +04:00
|
|
|
|
2015-09-12 22:47:00 +03:00
|
|
|
indexdata = ''
|
2011-05-16 15:06:48 +04:00
|
|
|
self._initempty = True
|
2005-05-04 01:16:10 +04:00
|
|
|
try:
|
2006-02-22 09:26:29 +03:00
|
|
|
f = self.opener(self.indexfile)
|
2017-09-13 20:26:26 +03:00
|
|
|
if (mmapindexthreshold is not None and
|
|
|
|
self.opener.fstat(f).st_size >= mmapindexthreshold):
|
|
|
|
indexdata = util.buffer(util.mmapread(f))
|
|
|
|
else:
|
|
|
|
indexdata = f.read()
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2015-09-12 22:47:00 +03:00
|
|
|
if len(indexdata) > 0:
|
2017-07-10 23:41:13 +03:00
|
|
|
v = versionformat_unpack(indexdata[:4])[0]
|
2011-05-16 15:06:48 +04:00
|
|
|
self._initempty = False
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2005-09-23 10:31:44 +04:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
2007-07-24 05:44:08 +04:00
|
|
|
|
|
|
|
self.version = v
|
2017-05-18 05:52:18 +03:00
|
|
|
self._inline = v & FLAG_INLINE_DATA
|
|
|
|
self._generaldelta = v & FLAG_GENERALDELTA
|
2006-04-05 00:38:43 +04:00
|
|
|
flags = v & ~0xFFFF
|
|
|
|
fmt = v & 0xFFFF
|
2017-05-20 06:10:50 +03:00
|
|
|
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))
|
2017-05-20 06:29:11 +03:00
|
|
|
elif fmt == REVLOGV2:
|
|
|
|
if flags & ~REVLOGV2_FLAGS:
|
|
|
|
raise RevlogError(_('unknown flags (%#04x) in version %d '
|
|
|
|
'revlog %s') %
|
|
|
|
(flags >> 16, fmt, self.indexfile))
|
2017-05-20 06:10:50 +03:00
|
|
|
else:
|
|
|
|
raise RevlogError(_('unknown version (%d) in revlog %s') %
|
|
|
|
(fmt, self.indexfile))
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2016-10-14 03:25:08 +03:00
|
|
|
self.storedeltachains = True
|
2016-09-24 22:25:37 +03:00
|
|
|
|
2007-07-24 05:44:07 +04:00
|
|
|
self._io = revlogio()
|
2007-07-24 05:44:07 +04:00
|
|
|
if self.version == REVLOGV0:
|
2007-07-24 05:44:07 +04:00
|
|
|
self._io = revlogoldio()
|
2011-01-15 15:02:19 +03:00
|
|
|
try:
|
2015-09-12 22:47:00 +03:00
|
|
|
d = self._io.parseindex(indexdata, self._inline)
|
2011-01-15 15:02:19 +03:00
|
|
|
except (ValueError, IndexError):
|
|
|
|
raise RevlogError(_("index %s is corrupted") % (self.indexfile))
|
2011-01-16 14:25:46 +03:00
|
|
|
self.index, nodemap, self._chunkcache = d
|
|
|
|
if nodemap is not None:
|
2011-01-19 00:55:46 +03:00
|
|
|
self.nodemap = self._nodecache = nodemap
|
2011-01-15 15:02:19 +03:00
|
|
|
if not self._chunkcache:
|
|
|
|
self._chunkclear()
|
2014-11-14 08:36:38 +03:00
|
|
|
# revnum -> (chain-length, sum-delta-length)
|
|
|
|
self._chaininfocache = {}
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
# revlog header -> revlog compressor
|
|
|
|
self._decompressors = {}
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2017-01-02 22:22:52 +03:00
|
|
|
@util.propertycache
|
|
|
|
def _compressor(self):
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
return util.compengines[self._compengine].revlogcompressor()
|
2017-01-02 22:22:52 +03:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
def tip(self):
|
|
|
|
return self.node(len(self.index) - 2)
|
2015-02-04 15:25:57 +03:00
|
|
|
def __contains__(self, rev):
|
|
|
|
return 0 <= rev < len(self)
|
2008-06-26 23:35:50 +04:00
|
|
|
def __len__(self):
|
2007-07-24 05:44:08 +04:00
|
|
|
return len(self.index) - 1
|
2008-06-26 23:35:50 +04:00
|
|
|
def __iter__(self):
|
2012-11-17 03:39:12 +04:00
|
|
|
return iter(xrange(len(self)))
|
2012-09-20 21:00:59 +04:00
|
|
|
def revs(self, start=0, stop=None):
|
|
|
|
"""iterate over all rev in this revlog (from start to stop)"""
|
2012-11-21 03:42:05 +04:00
|
|
|
step = 1
|
|
|
|
if stop is not None:
|
|
|
|
if start > stop:
|
|
|
|
step = -1
|
|
|
|
stop += step
|
2012-09-20 21:00:59 +04:00
|
|
|
else:
|
2012-11-21 03:42:05 +04:00
|
|
|
stop = len(self)
|
|
|
|
return xrange(start, stop, step)
|
2011-01-19 00:55:46 +03:00
|
|
|
|
|
|
|
@util.propertycache
|
|
|
|
def nodemap(self):
|
2011-04-30 15:59:14 +04:00
|
|
|
self.rev(self.node(0))
|
2011-01-19 00:55:46 +03:00
|
|
|
return self._nodecache
|
|
|
|
|
2012-04-08 00:43:18 +04:00
|
|
|
def hasnode(self, node):
|
|
|
|
try:
|
|
|
|
self.rev(node)
|
|
|
|
return True
|
|
|
|
except KeyError:
|
|
|
|
return False
|
|
|
|
|
2012-04-13 01:05:59 +04:00
|
|
|
def clearcaches(self):
|
2015-12-21 04:48:20 +03:00
|
|
|
self._cache = None
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
self._chainbasecache.clear()
|
2015-12-21 04:48:20 +03:00
|
|
|
self._chunkcache = (0, '')
|
|
|
|
self._pcache = {}
|
|
|
|
|
2012-04-13 01:05:59 +04:00
|
|
|
try:
|
|
|
|
self._nodecache.clearcaches()
|
|
|
|
except AttributeError:
|
|
|
|
self._nodecache = {nullid: nullrev}
|
|
|
|
self._nodepos = None
|
|
|
|
|
2011-01-19 00:55:46 +03:00
|
|
|
def rev(self, node):
|
2005-09-05 01:45:03 +04:00
|
|
|
try:
|
2011-01-19 00:55:46 +03:00
|
|
|
return self._nodecache[node]
|
2014-08-26 15:11:53 +04:00
|
|
|
except TypeError:
|
|
|
|
raise
|
2012-04-13 01:05:59 +04:00
|
|
|
except RevlogError:
|
|
|
|
# parsers.c radix tree lookup failed
|
2016-08-20 16:37:58 +03:00
|
|
|
if node == wdirid:
|
|
|
|
raise error.WdirUnsupported
|
2012-04-13 01:05:59 +04:00
|
|
|
raise LookupError(node, self.indexfile, _('no node'))
|
2005-09-05 01:45:03 +04:00
|
|
|
except KeyError:
|
2012-04-13 01:05:59 +04:00
|
|
|
# pure python cache lookup failed
|
2011-01-19 00:55:46 +03:00
|
|
|
n = self._nodecache
|
|
|
|
i = self.index
|
|
|
|
p = self._nodepos
|
|
|
|
if p is None:
|
|
|
|
p = len(i) - 2
|
|
|
|
for r in xrange(p, -1, -1):
|
|
|
|
v = i[r][7]
|
|
|
|
n[v] = r
|
|
|
|
if v == node:
|
|
|
|
self._nodepos = r - 1
|
|
|
|
return r
|
2016-08-20 16:37:58 +03:00
|
|
|
if node == wdirid:
|
|
|
|
raise error.WdirUnsupported
|
2008-03-12 01:42:29 +03:00
|
|
|
raise LookupError(node, self.indexfile, _('no node'))
|
2011-01-12 06:52:03 +03:00
|
|
|
|
2016-10-23 19:34:55 +03:00
|
|
|
# Accessors for index entries.
|
|
|
|
|
|
|
|
# First tuple entry is 8 bytes. First 6 bytes are offset. Last 2 bytes
|
|
|
|
# are flags.
|
2006-04-05 00:38:43 +04:00
|
|
|
def start(self, rev):
|
2007-07-26 21:02:58 +04:00
|
|
|
return int(self.index[rev][0] >> 16)
|
2016-10-23 19:34:55 +03:00
|
|
|
|
|
|
|
def flags(self, rev):
|
|
|
|
return self.index[rev][0] & 0xFFFF
|
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
def length(self, rev):
|
|
|
|
return self.index[rev][1]
|
2016-10-23 19:34:55 +03:00
|
|
|
|
|
|
|
def rawsize(self, rev):
|
|
|
|
"""return the length of the uncompressed text for a given revision"""
|
|
|
|
l = self.index[rev][2]
|
|
|
|
if l >= 0:
|
|
|
|
return l
|
|
|
|
|
revlog: use raw revision for rawsize
When writing the revlog-ng index, the third field is len(rawtext). See
revlog._addrevision:
textlen = len(rawtext)
....
e = (offset_type(offset, flags), l, textlen,
base, link, p1r, p2r, node)
self.index.insert(-1, e)
Therefore, revlog.index[rev][2] returned by revlog.rawsize should be
len(rawtext), where "rawtext" is revlog.revision(raw=True).
Unfortunately it's hard to add a test for this code path because "if l >= 0"
catches most cases.
2017-04-03 04:57:03 +03:00
|
|
|
t = self.revision(rev, raw=True)
|
2016-10-23 19:34:55 +03:00
|
|
|
return len(t)
|
2017-04-09 22:53:31 +03:00
|
|
|
|
|
|
|
def size(self, rev):
|
|
|
|
"""length of non-raw text (processed by a "read" flag processor)"""
|
|
|
|
# fast path: if no "read" flag processor could change the content,
|
|
|
|
# size is rawsize. note: ELLIPSIS is known to not change the content.
|
|
|
|
flags = self.flags(rev)
|
|
|
|
if flags & (REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
|
|
|
|
return self.rawsize(rev)
|
|
|
|
|
|
|
|
return len(self.revision(rev, raw=False))
|
2016-10-23 19:34:55 +03:00
|
|
|
|
2011-05-08 00:40:14 +04:00
|
|
|
def chainbase(self, rev):
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
base = self._chainbasecache.get(rev)
|
|
|
|
if base is not None:
|
|
|
|
return base
|
|
|
|
|
2011-05-08 00:40:14 +04:00
|
|
|
index = self.index
|
|
|
|
base = index[rev][3]
|
|
|
|
while base != rev:
|
|
|
|
rev = base
|
|
|
|
base = index[rev][3]
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
|
|
|
|
self._chainbasecache[rev] = base
|
2011-05-08 00:40:14 +04:00
|
|
|
return base
|
2016-10-23 19:34:55 +03:00
|
|
|
|
|
|
|
def linkrev(self, rev):
|
|
|
|
return self.index[rev][4]
|
|
|
|
|
|
|
|
def parentrevs(self, rev):
|
2017-05-19 16:42:06 +03:00
|
|
|
try:
|
|
|
|
return self.index[rev][5:7]
|
|
|
|
except IndexError:
|
|
|
|
if rev == wdirrev:
|
|
|
|
raise error.WdirUnsupported
|
|
|
|
raise
|
2016-10-23 19:34:55 +03:00
|
|
|
|
|
|
|
def node(self, rev):
|
2017-05-22 23:00:36 +03:00
|
|
|
try:
|
|
|
|
return self.index[rev][7]
|
|
|
|
except IndexError:
|
|
|
|
if rev == wdirrev:
|
|
|
|
raise error.WdirUnsupported
|
|
|
|
raise
|
2016-10-23 19:34:55 +03:00
|
|
|
|
|
|
|
# Derived from index values.
|
|
|
|
|
|
|
|
def end(self, rev):
|
|
|
|
return self.start(rev) + self.length(rev)
|
|
|
|
|
|
|
|
def parents(self, node):
|
|
|
|
i = self.index
|
|
|
|
d = i[self.rev(node)]
|
|
|
|
return i[d[5]][7], i[d[6]][7] # map revisions to nodes inline
|
|
|
|
|
2014-11-07 01:08:25 +03:00
|
|
|
def chainlen(self, rev):
|
2014-11-12 06:54:36 +03:00
|
|
|
return self._chaininfo(rev)[0]
|
2014-11-14 08:36:38 +03:00
|
|
|
|
2014-11-12 06:54:36 +03:00
|
|
|
def _chaininfo(self, rev):
|
2014-11-14 08:36:38 +03:00
|
|
|
chaininfocache = self._chaininfocache
|
|
|
|
if rev in chaininfocache:
|
|
|
|
return chaininfocache[rev]
|
2014-11-07 01:08:25 +03:00
|
|
|
index = self.index
|
|
|
|
generaldelta = self._generaldelta
|
|
|
|
iterrev = rev
|
|
|
|
e = index[iterrev]
|
|
|
|
clen = 0
|
2014-11-12 06:54:36 +03:00
|
|
|
compresseddeltalen = 0
|
2014-11-07 01:08:25 +03:00
|
|
|
while iterrev != e[3]:
|
|
|
|
clen += 1
|
2014-11-12 06:54:36 +03:00
|
|
|
compresseddeltalen += e[1]
|
2014-11-07 01:08:25 +03:00
|
|
|
if generaldelta:
|
|
|
|
iterrev = e[3]
|
|
|
|
else:
|
|
|
|
iterrev -= 1
|
2014-11-14 08:36:38 +03:00
|
|
|
if iterrev in chaininfocache:
|
|
|
|
t = chaininfocache[iterrev]
|
|
|
|
clen += t[0]
|
|
|
|
compresseddeltalen += t[1]
|
|
|
|
break
|
2014-11-07 01:08:25 +03:00
|
|
|
e = index[iterrev]
|
2014-11-14 08:36:38 +03:00
|
|
|
else:
|
|
|
|
# Add text length of base since decompressing that also takes
|
|
|
|
# work. For cache hits the length is already included.
|
|
|
|
compresseddeltalen += e[1]
|
|
|
|
r = (clen, compresseddeltalen)
|
|
|
|
chaininfocache[rev] = r
|
|
|
|
return r
|
|
|
|
|
2015-12-21 05:56:05 +03:00
|
|
|
def _deltachain(self, rev, stoprev=None):
|
|
|
|
"""Obtain the delta chain for a revision.
|
|
|
|
|
|
|
|
``stoprev`` specifies a revision to stop at. If not specified, we
|
|
|
|
stop at the base of the chain.
|
|
|
|
|
|
|
|
Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of
|
|
|
|
revs in ascending order and ``stopped`` is a bool indicating whether
|
|
|
|
``stoprev`` was hit.
|
|
|
|
"""
|
2017-06-25 22:41:34 +03:00
|
|
|
# Try C implementation.
|
|
|
|
try:
|
|
|
|
return self.index.deltachain(rev, stoprev, self._generaldelta)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
2015-12-21 05:56:05 +03:00
|
|
|
chain = []
|
|
|
|
|
|
|
|
# Alias to prevent attribute lookup in tight loop.
|
|
|
|
index = self.index
|
|
|
|
generaldelta = self._generaldelta
|
|
|
|
|
|
|
|
iterrev = rev
|
|
|
|
e = index[iterrev]
|
|
|
|
while iterrev != e[3] and iterrev != stoprev:
|
|
|
|
chain.append(iterrev)
|
|
|
|
if generaldelta:
|
|
|
|
iterrev = e[3]
|
|
|
|
else:
|
|
|
|
iterrev -= 1
|
|
|
|
e = index[iterrev]
|
|
|
|
|
|
|
|
if iterrev == stoprev:
|
|
|
|
stopped = True
|
|
|
|
else:
|
|
|
|
chain.append(iterrev)
|
|
|
|
stopped = False
|
|
|
|
|
|
|
|
chain.reverse()
|
|
|
|
return chain, stopped
|
|
|
|
|
2012-12-18 03:13:51 +04:00
|
|
|
def ancestors(self, revs, stoprev=0, inclusive=False):
|
2009-12-10 17:35:43 +03:00
|
|
|
"""Generate the ancestors of 'revs' in reverse topological order.
|
2012-06-02 02:44:13 +04:00
|
|
|
Does not generate revs lower than stoprev.
|
2009-12-10 17:35:43 +03:00
|
|
|
|
2012-12-18 22:14:01 +04:00
|
|
|
See the documentation for ancestor.lazyancestors for more details."""
|
|
|
|
|
2014-11-15 01:36:25 +03:00
|
|
|
return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev,
|
2012-12-18 22:14:01 +04:00
|
|
|
inclusive=inclusive)
|
2008-07-19 20:19:50 +04:00
|
|
|
|
2012-06-01 23:45:16 +04:00
|
|
|
def descendants(self, revs):
|
2009-12-10 17:35:43 +03:00
|
|
|
"""Generate the descendants of 'revs' in revision order.
|
|
|
|
|
|
|
|
Yield a sequence of revision numbers starting with a child of
|
|
|
|
some rev in revs, i.e., each revision is *not* considered a
|
|
|
|
descendant of itself. Results are ordered by revision number (a
|
|
|
|
topological sort)."""
|
2010-11-07 12:23:48 +03:00
|
|
|
first = min(revs)
|
|
|
|
if first == nullrev:
|
|
|
|
for i in self:
|
|
|
|
yield i
|
|
|
|
return
|
|
|
|
|
2009-04-22 02:55:32 +04:00
|
|
|
seen = set(revs)
|
2012-09-20 21:00:59 +04:00
|
|
|
for i in self.revs(start=first + 1):
|
2008-07-19 20:19:50 +04:00
|
|
|
for x in self.parentrevs(i):
|
|
|
|
if x != nullrev and x in seen:
|
|
|
|
seen.add(i)
|
|
|
|
yield i
|
|
|
|
break
|
|
|
|
|
2011-03-23 18:02:11 +03:00
|
|
|
def findcommonmissing(self, common=None, heads=None):
|
|
|
|
"""Return a tuple of the ancestors of common and the ancestors of heads
|
2012-01-09 07:15:31 +04:00
|
|
|
that are not ancestors of common. In revset terminology, we return the
|
|
|
|
tuple:
|
2009-12-10 17:35:43 +03:00
|
|
|
|
2012-01-09 07:15:31 +04:00
|
|
|
::common, (::heads) - (::common)
|
2008-10-21 19:00:35 +04:00
|
|
|
|
2009-12-10 17:35:43 +03:00
|
|
|
The list is sorted by revision number, meaning it is
|
|
|
|
topologically sorted.
|
|
|
|
|
|
|
|
'heads' and 'common' are both lists of node IDs. If heads is
|
|
|
|
not supplied, uses all of the revlog's heads. If common is not
|
|
|
|
supplied, uses nullid."""
|
2008-10-21 19:00:35 +04:00
|
|
|
if common is None:
|
|
|
|
common = [nullid]
|
|
|
|
if heads is None:
|
|
|
|
heads = self.heads()
|
|
|
|
|
|
|
|
common = [self.rev(n) for n in common]
|
|
|
|
heads = [self.rev(n) for n in heads]
|
|
|
|
|
|
|
|
# we want the ancestors, but inclusive
|
2013-11-12 04:40:02 +04:00
|
|
|
class lazyset(object):
|
|
|
|
def __init__(self, lazyvalues):
|
|
|
|
self.addedvalues = set()
|
|
|
|
self.lazyvalues = lazyvalues
|
|
|
|
|
|
|
|
def __contains__(self, value):
|
|
|
|
return value in self.addedvalues or value in self.lazyvalues
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
added = self.addedvalues
|
|
|
|
for r in added:
|
|
|
|
yield r
|
|
|
|
for r in self.lazyvalues:
|
|
|
|
if not r in added:
|
|
|
|
yield r
|
|
|
|
|
|
|
|
def add(self, value):
|
|
|
|
self.addedvalues.add(value)
|
|
|
|
|
|
|
|
def update(self, values):
|
|
|
|
self.addedvalues.update(values)
|
|
|
|
|
|
|
|
has = lazyset(self.ancestors(common))
|
2009-04-22 02:57:28 +04:00
|
|
|
has.add(nullrev)
|
|
|
|
has.update(common)
|
2008-10-21 19:00:35 +04:00
|
|
|
|
|
|
|
# take all ancestors from heads that aren't in has
|
2009-05-17 04:44:12 +04:00
|
|
|
missing = set()
|
2015-05-16 21:28:04 +03:00
|
|
|
visit = collections.deque(r for r in heads if r not in has)
|
2008-10-21 19:00:35 +04:00
|
|
|
while visit:
|
2012-05-15 21:46:23 +04:00
|
|
|
r = visit.popleft()
|
2008-10-21 19:00:35 +04:00
|
|
|
if r in missing:
|
|
|
|
continue
|
|
|
|
else:
|
2009-05-17 04:44:12 +04:00
|
|
|
missing.add(r)
|
2008-10-21 19:00:35 +04:00
|
|
|
for p in self.parentrevs(r):
|
|
|
|
if p not in has:
|
|
|
|
visit.append(p)
|
2009-05-17 04:44:12 +04:00
|
|
|
missing = list(missing)
|
2008-10-21 19:00:35 +04:00
|
|
|
missing.sort()
|
2016-11-11 00:34:43 +03:00
|
|
|
return has, [self.node(miss) for miss in missing]
|
2011-03-23 18:02:11 +03:00
|
|
|
|
2014-11-16 11:39:48 +03:00
|
|
|
def incrementalmissingrevs(self, common=None):
|
|
|
|
"""Return an object that can be used to incrementally compute the
|
|
|
|
revision numbers of the ancestors of arbitrary sets that are not
|
|
|
|
ancestors of common. This is an ancestor.incrementalmissingancestors
|
|
|
|
object.
|
|
|
|
|
|
|
|
'common' is a list of revision numbers. If common is not supplied, uses
|
|
|
|
nullrev.
|
|
|
|
"""
|
|
|
|
if common is None:
|
|
|
|
common = [nullrev]
|
|
|
|
|
|
|
|
return ancestor.incrementalmissingancestors(self.parentrevs, common)
|
|
|
|
|
2012-11-26 22:48:24 +04:00
|
|
|
def findmissingrevs(self, common=None, heads=None):
|
|
|
|
"""Return the revision numbers of the ancestors of heads that
|
|
|
|
are not ancestors of common.
|
|
|
|
|
|
|
|
More specifically, return a list of revision numbers corresponding to
|
|
|
|
nodes N such that every N satisfies the following constraints:
|
|
|
|
|
|
|
|
1. N is an ancestor of some node in 'heads'
|
|
|
|
2. N is not an ancestor of any node in 'common'
|
|
|
|
|
|
|
|
The list is sorted by revision number, meaning it is
|
|
|
|
topologically sorted.
|
|
|
|
|
|
|
|
'heads' and 'common' are both lists of revision numbers. If heads is
|
|
|
|
not supplied, uses all of the revlog's heads. If common is not
|
|
|
|
supplied, uses nullid."""
|
|
|
|
if common is None:
|
|
|
|
common = [nullrev]
|
|
|
|
if heads is None:
|
|
|
|
heads = self.headrevs()
|
|
|
|
|
2014-11-15 03:52:40 +03:00
|
|
|
inc = self.incrementalmissingrevs(common=common)
|
|
|
|
return inc.missingancestors(heads)
|
2012-11-26 22:48:24 +04:00
|
|
|
|
2011-03-23 18:02:11 +03:00
|
|
|
def findmissing(self, common=None, heads=None):
|
|
|
|
"""Return the ancestors of heads that are not ancestors of common.
|
|
|
|
|
|
|
|
More specifically, return a list of nodes N such that every N
|
|
|
|
satisfies the following constraints:
|
|
|
|
|
|
|
|
1. N is an ancestor of some node in 'heads'
|
|
|
|
2. N is not an ancestor of any node in 'common'
|
|
|
|
|
|
|
|
The list is sorted by revision number, meaning it is
|
|
|
|
topologically sorted.
|
|
|
|
|
|
|
|
'heads' and 'common' are both lists of node IDs. If heads is
|
|
|
|
not supplied, uses all of the revlog's heads. If common is not
|
|
|
|
supplied, uses nullid."""
|
2012-11-26 23:02:48 +04:00
|
|
|
if common is None:
|
|
|
|
common = [nullid]
|
|
|
|
if heads is None:
|
|
|
|
heads = self.heads()
|
|
|
|
|
|
|
|
common = [self.rev(n) for n in common]
|
|
|
|
heads = [self.rev(n) for n in heads]
|
|
|
|
|
2014-11-15 03:52:40 +03:00
|
|
|
inc = self.incrementalmissingrevs(common=common)
|
|
|
|
return [self.node(r) for r in inc.missingancestors(heads)]
|
2008-10-21 19:00:35 +04:00
|
|
|
|
2005-10-07 21:48:27 +04:00
|
|
|
def nodesbetween(self, roots=None, heads=None):
|
2009-12-10 17:35:43 +03:00
|
|
|
"""Return a topological path from 'roots' to 'heads'.
|
|
|
|
|
|
|
|
Return a tuple (nodes, outroots, outheads) where 'nodes' is a
|
|
|
|
topologically sorted list of all nodes N that satisfy both of
|
|
|
|
these constraints:
|
|
|
|
|
|
|
|
1. N is a descendant of some node in 'roots'
|
|
|
|
2. N is an ancestor of some node in 'heads'
|
|
|
|
|
|
|
|
Every node is considered to be both a descendant and an ancestor
|
|
|
|
of itself, so every reachable node in 'roots' and 'heads' will be
|
|
|
|
included in 'nodes'.
|
|
|
|
|
|
|
|
'outroots' is the list of reachable nodes in 'roots', i.e., the
|
|
|
|
subset of 'roots' that is returned in 'nodes'. Likewise,
|
|
|
|
'outheads' is the subset of 'heads' that is also in 'nodes'.
|
|
|
|
|
|
|
|
'roots' and 'heads' are both lists of node IDs. If 'roots' is
|
|
|
|
unspecified, uses nullid as the only root. If 'heads' is
|
|
|
|
unspecified, uses list of all of the revlog's heads."""
|
2005-10-11 04:20:38 +04:00
|
|
|
nonodes = ([], [], [])
|
2005-10-07 21:48:27 +04:00
|
|
|
if roots is not None:
|
|
|
|
roots = list(roots)
|
2005-10-11 04:20:38 +04:00
|
|
|
if not roots:
|
|
|
|
return nonodes
|
2005-10-07 21:48:27 +04:00
|
|
|
lowestrev = min([self.rev(n) for n in roots])
|
|
|
|
else:
|
2011-06-08 02:02:54 +04:00
|
|
|
roots = [nullid] # Everybody's a descendant of nullid
|
2006-10-29 12:53:51 +03:00
|
|
|
lowestrev = nullrev
|
|
|
|
if (lowestrev == nullrev) and (heads is None):
|
2005-10-07 21:48:27 +04:00
|
|
|
# We want _all_ the nodes!
|
2008-06-26 23:35:50 +04:00
|
|
|
return ([self.node(r) for r in self], [nullid], list(self.heads()))
|
2005-10-07 21:48:27 +04:00
|
|
|
if heads is None:
|
|
|
|
# All nodes are ancestors, so the latest ancestor is the last
|
|
|
|
# node.
|
2008-06-26 23:35:50 +04:00
|
|
|
highestrev = len(self) - 1
|
2005-10-07 21:48:27 +04:00
|
|
|
# Set ancestors to None to signal that every node is an ancestor.
|
|
|
|
ancestors = None
|
|
|
|
# Set heads to an empty dictionary for later discovery of heads
|
|
|
|
heads = {}
|
|
|
|
else:
|
2005-10-11 04:20:38 +04:00
|
|
|
heads = list(heads)
|
|
|
|
if not heads:
|
|
|
|
return nonodes
|
2009-05-17 05:49:59 +04:00
|
|
|
ancestors = set()
|
2005-10-07 21:48:27 +04:00
|
|
|
# Turn heads into a dictionary so we can remove 'fake' heads.
|
|
|
|
# Also, later we will be using it to filter out the heads we can't
|
|
|
|
# find from roots.
|
2011-05-06 14:09:20 +04:00
|
|
|
heads = dict.fromkeys(heads, False)
|
2006-10-12 13:40:26 +04:00
|
|
|
# Start at the top and keep marking parents until we're done.
|
2009-04-26 00:25:49 +04:00
|
|
|
nodestotag = set(heads)
|
2005-10-07 21:48:27 +04:00
|
|
|
# Remember where the top was so we can use it as a limit later.
|
|
|
|
highestrev = max([self.rev(n) for n in nodestotag])
|
|
|
|
while nodestotag:
|
|
|
|
# grab a node to tag
|
|
|
|
n = nodestotag.pop()
|
|
|
|
# Never tag nullid
|
|
|
|
if n == nullid:
|
|
|
|
continue
|
|
|
|
# A node's revision number represents its place in a
|
|
|
|
# topologically sorted list of nodes.
|
|
|
|
r = self.rev(n)
|
|
|
|
if r >= lowestrev:
|
|
|
|
if n not in ancestors:
|
2011-06-08 02:02:54 +04:00
|
|
|
# If we are possibly a descendant of one of the roots
|
2005-10-07 21:48:27 +04:00
|
|
|
# and we haven't already been marked as an ancestor
|
2009-05-17 05:49:59 +04:00
|
|
|
ancestors.add(n) # Mark as ancestor
|
2005-10-07 21:48:27 +04:00
|
|
|
# Add non-nullid parents to list of nodes to tag.
|
2009-04-22 22:51:20 +04:00
|
|
|
nodestotag.update([p for p in self.parents(n) if
|
2005-10-07 21:48:27 +04:00
|
|
|
p != nullid])
|
|
|
|
elif n in heads: # We've seen it before, is it a fake head?
|
|
|
|
# So it is, real heads should not be the ancestors of
|
|
|
|
# any other heads.
|
|
|
|
heads.pop(n)
|
2005-10-08 04:07:57 +04:00
|
|
|
if not ancestors:
|
2005-10-11 04:20:38 +04:00
|
|
|
return nonodes
|
2005-10-07 21:48:27 +04:00
|
|
|
# Now that we have our set of ancestors, we want to remove any
|
|
|
|
# roots that are not ancestors.
|
|
|
|
|
|
|
|
# If one of the roots was nullid, everything is included anyway.
|
2006-10-29 12:53:51 +03:00
|
|
|
if lowestrev > nullrev:
|
2005-10-07 21:48:27 +04:00
|
|
|
# But, since we weren't, let's recompute the lowest rev to not
|
|
|
|
# include roots that aren't ancestors.
|
|
|
|
|
|
|
|
# Filter out roots that aren't ancestors of heads
|
2016-11-11 00:34:43 +03:00
|
|
|
roots = [root for root in roots if root in ancestors]
|
2005-10-07 21:48:27 +04:00
|
|
|
# Recompute the lowest revision
|
|
|
|
if roots:
|
2016-11-11 00:34:43 +03:00
|
|
|
lowestrev = min([self.rev(root) for root in roots])
|
2005-10-07 21:48:27 +04:00
|
|
|
else:
|
|
|
|
# No more roots? Return empty list
|
2005-10-11 04:20:38 +04:00
|
|
|
return nonodes
|
2005-10-07 21:48:27 +04:00
|
|
|
else:
|
|
|
|
# We are descending from nullid, and don't need to care about
|
|
|
|
# any other roots.
|
2006-10-29 12:53:51 +03:00
|
|
|
lowestrev = nullrev
|
2005-10-07 21:48:27 +04:00
|
|
|
roots = [nullid]
|
2009-04-22 02:57:28 +04:00
|
|
|
# Transform our roots list into a set.
|
2011-06-08 02:02:54 +04:00
|
|
|
descendants = set(roots)
|
2005-10-07 21:48:27 +04:00
|
|
|
# Also, keep the original roots so we can filter out roots that aren't
|
|
|
|
# 'real' roots (i.e. are descended from other roots).
|
2011-06-08 02:02:54 +04:00
|
|
|
roots = descendants.copy()
|
2005-10-07 21:48:27 +04:00
|
|
|
# Our topologically sorted list of output nodes.
|
|
|
|
orderedout = []
|
|
|
|
# Don't start at nullid since we don't want nullid in our output list,
|
2012-08-16 00:38:42 +04:00
|
|
|
# and if nullid shows up in descendants, empty parents will look like
|
2011-06-08 02:02:54 +04:00
|
|
|
# they're descendants.
|
2012-09-20 21:00:59 +04:00
|
|
|
for r in self.revs(start=max(lowestrev, 0), stop=highestrev + 1):
|
2005-10-07 21:48:27 +04:00
|
|
|
n = self.node(r)
|
2011-06-08 02:02:54 +04:00
|
|
|
isdescendant = False
|
|
|
|
if lowestrev == nullrev: # Everybody is a descendant of nullid
|
|
|
|
isdescendant = True
|
|
|
|
elif n in descendants:
|
|
|
|
# n is already a descendant
|
|
|
|
isdescendant = True
|
2005-10-07 21:48:27 +04:00
|
|
|
# This check only needs to be done here because all the roots
|
2011-06-08 02:02:54 +04:00
|
|
|
# will start being marked is descendants before the loop.
|
2005-10-07 21:48:27 +04:00
|
|
|
if n in roots:
|
|
|
|
# If n was a root, check if it's a 'real' root.
|
|
|
|
p = tuple(self.parents(n))
|
2011-06-08 02:02:54 +04:00
|
|
|
# If any of its parents are descendants, it's not a root.
|
|
|
|
if (p[0] in descendants) or (p[1] in descendants):
|
2009-04-22 02:57:28 +04:00
|
|
|
roots.remove(n)
|
2005-10-07 21:48:27 +04:00
|
|
|
else:
|
|
|
|
p = tuple(self.parents(n))
|
2011-06-08 02:02:54 +04:00
|
|
|
# A node is a descendant if either of its parents are
|
|
|
|
# descendants. (We seeded the dependents list with the roots
|
2005-10-07 21:48:27 +04:00
|
|
|
# up there, remember?)
|
2011-06-08 02:02:54 +04:00
|
|
|
if (p[0] in descendants) or (p[1] in descendants):
|
|
|
|
descendants.add(n)
|
|
|
|
isdescendant = True
|
|
|
|
if isdescendant and ((ancestors is None) or (n in ancestors)):
|
|
|
|
# Only include nodes that are both descendants and ancestors.
|
2005-10-07 21:48:27 +04:00
|
|
|
orderedout.append(n)
|
|
|
|
if (ancestors is not None) and (n in heads):
|
|
|
|
# We're trying to figure out which heads are reachable
|
|
|
|
# from roots.
|
|
|
|
# Mark this head as having been reached
|
2011-05-06 14:09:20 +04:00
|
|
|
heads[n] = True
|
2005-10-07 21:48:27 +04:00
|
|
|
elif ancestors is None:
|
|
|
|
# Otherwise, we're trying to discover the heads.
|
|
|
|
# Assume this is a head because if it isn't, the next step
|
|
|
|
# will eventually remove it.
|
2011-05-06 14:09:20 +04:00
|
|
|
heads[n] = True
|
2005-10-07 21:48:27 +04:00
|
|
|
# But, obviously its parents aren't.
|
|
|
|
for p in self.parents(n):
|
|
|
|
heads.pop(p, None)
|
2016-11-11 00:34:43 +03:00
|
|
|
heads = [head for head, flag in heads.iteritems() if flag]
|
2009-04-22 02:57:28 +04:00
|
|
|
roots = list(roots)
|
2005-10-07 21:48:27 +04:00
|
|
|
assert orderedout
|
|
|
|
assert roots
|
|
|
|
assert heads
|
|
|
|
return (orderedout, roots, heads)
|
|
|
|
|
2011-05-02 21:21:30 +04:00
|
|
|
def headrevs(self):
|
2012-05-20 06:44:58 +04:00
|
|
|
try:
|
|
|
|
return self.index.headrevs()
|
|
|
|
except AttributeError:
|
2012-09-03 16:19:45 +04:00
|
|
|
return self._headrevs()
|
|
|
|
|
2015-03-20 21:14:27 +03:00
|
|
|
def computephases(self, roots):
|
2015-05-30 00:24:50 +03:00
|
|
|
return self.index.computephasesmapsets(roots)
|
2015-03-20 21:14:27 +03:00
|
|
|
|
2012-09-03 16:19:45 +04:00
|
|
|
def _headrevs(self):
|
2011-05-02 21:21:30 +04:00
|
|
|
count = len(self)
|
|
|
|
if not count:
|
|
|
|
return [nullrev]
|
2012-09-03 16:12:45 +04:00
|
|
|
# we won't iter over filtered rev so nobody is a head at start
|
|
|
|
ishead = [0] * (count + 1)
|
2011-05-02 21:21:30 +04:00
|
|
|
index = self.index
|
2012-09-20 21:00:59 +04:00
|
|
|
for r in self:
|
2012-09-03 16:12:45 +04:00
|
|
|
ishead[r] = 1 # I may be an head
|
2011-05-02 21:21:30 +04:00
|
|
|
e = index[r]
|
2012-09-03 16:12:45 +04:00
|
|
|
ishead[e[5]] = ishead[e[6]] = 0 # my parent are not
|
|
|
|
return [r for r, val in enumerate(ishead) if val]
|
2011-05-02 21:21:30 +04:00
|
|
|
|
2006-12-17 07:00:22 +03:00
|
|
|
def heads(self, start=None, stop=None):
|
2005-11-16 14:08:25 +03:00
|
|
|
"""return the list of all nodes that have no children
|
2005-11-16 14:56:19 +03:00
|
|
|
|
|
|
|
if start is specified, only heads that are descendants of
|
|
|
|
start will be returned
|
2006-12-17 07:00:22 +03:00
|
|
|
if stop is specified, it will consider all the revs from stop
|
|
|
|
as if they had no children
|
2005-11-16 14:56:19 +03:00
|
|
|
"""
|
2007-07-24 05:44:08 +04:00
|
|
|
if start is None and stop is None:
|
2011-05-02 21:21:30 +04:00
|
|
|
if not len(self):
|
2007-07-24 05:44:08 +04:00
|
|
|
return [nullid]
|
2011-05-02 21:21:30 +04:00
|
|
|
return [self.node(r) for r in self.headrevs()]
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2005-11-16 14:56:19 +03:00
|
|
|
if start is None:
|
|
|
|
start = nullid
|
2006-12-17 07:00:22 +03:00
|
|
|
if stop is None:
|
|
|
|
stop = []
|
2009-04-22 02:57:28 +04:00
|
|
|
stoprevs = set([self.rev(n) for n in stop])
|
2005-11-16 14:08:25 +03:00
|
|
|
startrev = self.rev(start)
|
2017-02-11 03:56:29 +03:00
|
|
|
reachable = {startrev}
|
|
|
|
heads = {startrev}
|
2005-11-16 14:08:25 +03:00
|
|
|
|
2006-06-20 22:02:23 +04:00
|
|
|
parentrevs = self.parentrevs
|
2012-09-20 21:00:59 +04:00
|
|
|
for r in self.revs(start=startrev + 1):
|
2006-06-20 22:02:23 +04:00
|
|
|
for p in parentrevs(r):
|
|
|
|
if p in reachable:
|
2006-12-17 07:00:22 +03:00
|
|
|
if r not in stoprevs:
|
2009-05-17 05:49:59 +04:00
|
|
|
reachable.add(r)
|
|
|
|
heads.add(r)
|
2006-12-17 07:00:22 +03:00
|
|
|
if p in heads and p not in stoprevs:
|
2009-05-17 05:49:59 +04:00
|
|
|
heads.remove(p)
|
2006-12-17 07:00:22 +03:00
|
|
|
|
2006-06-20 22:02:23 +04:00
|
|
|
return [self.node(r) for r in heads]
|
2005-06-16 07:48:04 +04:00
|
|
|
|
|
|
|
def children(self, node):
|
2005-08-27 12:43:48 +04:00
|
|
|
"""find the children of a given node"""
|
2005-06-16 07:48:04 +04:00
|
|
|
c = []
|
|
|
|
p = self.rev(node)
|
2012-09-20 21:00:59 +04:00
|
|
|
for r in self.revs(start=p + 1):
|
2007-07-03 14:45:33 +04:00
|
|
|
prevs = [pr for pr in self.parentrevs(r) if pr != nullrev]
|
|
|
|
if prevs:
|
|
|
|
for pr in prevs:
|
|
|
|
if pr == p:
|
|
|
|
c.append(self.node(r))
|
|
|
|
elif p == nullrev:
|
|
|
|
c.append(self.node(r))
|
2005-06-16 07:48:04 +04:00
|
|
|
return c
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2010-04-14 00:06:17 +04:00
|
|
|
def descendant(self, start, end):
|
2010-11-07 12:16:07 +03:00
|
|
|
if start == nullrev:
|
|
|
|
return True
|
2012-06-01 23:45:16 +04:00
|
|
|
for i in self.descendants([start]):
|
2010-04-14 00:06:17 +04:00
|
|
|
if i == end:
|
|
|
|
return True
|
|
|
|
elif i > end:
|
|
|
|
break
|
|
|
|
return False
|
|
|
|
|
2014-04-17 22:01:35 +04:00
|
|
|
def commonancestorsheads(self, a, b):
|
|
|
|
"""calculate all the heads of the common ancestors of nodes a and b"""
|
|
|
|
a, b = self.rev(a), self.rev(b)
|
|
|
|
try:
|
|
|
|
ancs = self.index.commonancestorsheads(a, b)
|
|
|
|
except (AttributeError, OverflowError): # C implementation failed
|
|
|
|
ancs = ancestor.commonancestorsheads(self.parentrevs, a, b)
|
2017-03-22 00:39:49 +03:00
|
|
|
return pycompat.maplist(self.node, ancs)
|
2014-04-17 22:01:35 +04:00
|
|
|
|
2014-08-19 03:13:10 +04:00
|
|
|
def isancestor(self, a, b):
|
|
|
|
"""return True if node a is an ancestor of node b
|
|
|
|
|
|
|
|
The implementation of this is trivial but the use of
|
|
|
|
commonancestorsheads is not."""
|
|
|
|
return a in self.commonancestorsheads(a, b)
|
|
|
|
|
2014-04-17 22:01:39 +04:00
|
|
|
def ancestor(self, a, b):
|
2014-08-19 03:13:10 +04:00
|
|
|
"""calculate the "best" common ancestor of nodes a and b"""
|
2014-04-17 22:01:39 +04:00
|
|
|
|
2010-04-14 00:06:17 +04:00
|
|
|
a, b = self.rev(a), self.rev(b)
|
2013-04-16 21:08:20 +04:00
|
|
|
try:
|
|
|
|
ancs = self.index.ancestors(a, b)
|
2014-04-17 22:01:39 +04:00
|
|
|
except (AttributeError, OverflowError):
|
2013-04-16 21:08:20 +04:00
|
|
|
ancs = ancestor.ancestors(self.parentrevs, a, b)
|
2013-04-16 21:08:19 +04:00
|
|
|
if ancs:
|
|
|
|
# choose a consistent winner when there's a tie
|
2014-04-17 22:01:39 +04:00
|
|
|
return min(map(self.node, ancs))
|
2013-04-16 21:08:19 +04:00
|
|
|
return nullid
|
2010-04-14 00:06:17 +04:00
|
|
|
|
2006-10-18 20:44:56 +04:00
|
|
|
def _match(self, id):
|
2012-05-22 01:36:09 +04:00
|
|
|
if isinstance(id, int):
|
2006-09-24 15:52:25 +04:00
|
|
|
# rev
|
2006-07-17 03:58:50 +04:00
|
|
|
return self.node(id)
|
2006-10-18 07:07:54 +04:00
|
|
|
if len(id) == 20:
|
|
|
|
# possibly a binary node
|
|
|
|
# odds of a binary node being all hex in ASCII are 1 in 10**25
|
|
|
|
try:
|
|
|
|
node = id
|
2009-03-23 15:13:02 +03:00
|
|
|
self.rev(node) # quick search the index
|
2006-10-18 07:07:54 +04:00
|
|
|
return node
|
2006-12-18 23:22:43 +03:00
|
|
|
except LookupError:
|
2006-10-18 07:07:54 +04:00
|
|
|
pass # may be partial hex id
|
2005-05-08 04:11:36 +04:00
|
|
|
try:
|
2006-09-24 15:52:25 +04:00
|
|
|
# str(rev)
|
2005-05-08 04:11:36 +04:00
|
|
|
rev = int(id)
|
2007-07-24 05:44:08 +04:00
|
|
|
if str(rev) != id:
|
|
|
|
raise ValueError
|
|
|
|
if rev < 0:
|
2008-06-26 23:35:50 +04:00
|
|
|
rev = len(self) + rev
|
|
|
|
if rev < 0 or rev >= len(self):
|
2007-07-24 05:44:08 +04:00
|
|
|
raise ValueError
|
2005-05-08 04:11:36 +04:00
|
|
|
return self.node(rev)
|
2005-06-25 11:50:27 +04:00
|
|
|
except (ValueError, OverflowError):
|
2006-09-24 15:52:25 +04:00
|
|
|
pass
|
2006-10-18 20:44:56 +04:00
|
|
|
if len(id) == 40:
|
|
|
|
try:
|
2006-10-18 07:07:54 +04:00
|
|
|
# a full hex nodeid?
|
|
|
|
node = bin(id)
|
2009-03-23 15:13:02 +03:00
|
|
|
self.rev(node)
|
2006-09-24 15:52:27 +04:00
|
|
|
return node
|
2008-10-04 12:14:39 +04:00
|
|
|
except (TypeError, LookupError):
|
2006-10-18 20:44:56 +04:00
|
|
|
pass
|
|
|
|
|
|
|
|
def _partialmatch(self, id):
|
2016-08-19 12:26:04 +03:00
|
|
|
maybewdir = wdirhex.startswith(id)
|
2012-05-12 12:55:08 +04:00
|
|
|
try:
|
2016-11-11 00:34:43 +03:00
|
|
|
partial = self.index.partialmatch(id)
|
|
|
|
if partial and self.hasnode(partial):
|
2016-08-19 12:26:04 +03:00
|
|
|
if maybewdir:
|
|
|
|
# single 'ff...' match in radix tree, ambiguous with wdir
|
|
|
|
raise RevlogError
|
2016-11-11 00:34:43 +03:00
|
|
|
return partial
|
2016-08-19 12:26:04 +03:00
|
|
|
if maybewdir:
|
|
|
|
# no 'ff...' match in radix tree, wdir identified
|
|
|
|
raise error.WdirUnsupported
|
2013-07-24 02:28:12 +04:00
|
|
|
return None
|
2012-05-12 12:55:08 +04:00
|
|
|
except RevlogError:
|
|
|
|
# parsers.c radix tree lookup gave multiple matches
|
2016-06-22 23:30:49 +03:00
|
|
|
# fast path: for unfiltered changelog, radix tree is accurate
|
|
|
|
if not getattr(self, 'filteredrevs', None):
|
|
|
|
raise LookupError(id, self.indexfile,
|
|
|
|
_('ambiguous identifier'))
|
2013-07-24 02:28:12 +04:00
|
|
|
# fall through to slow path that filters hidden revisions
|
2012-05-12 12:55:08 +04:00
|
|
|
except (AttributeError, ValueError):
|
|
|
|
# we are pure python, or key was too short to search radix tree
|
|
|
|
pass
|
|
|
|
|
2011-01-12 02:12:32 +03:00
|
|
|
if id in self._pcache:
|
|
|
|
return self._pcache[id]
|
|
|
|
|
2006-10-18 20:44:56 +04:00
|
|
|
if len(id) < 40:
|
|
|
|
try:
|
2006-10-18 07:07:54 +04:00
|
|
|
# hex(node)[:...]
|
2009-07-05 13:00:44 +04:00
|
|
|
l = len(id) // 2 # grab an even number of digits
|
2011-01-12 06:52:03 +03:00
|
|
|
prefix = bin(id[:l * 2])
|
|
|
|
nl = [e[7] for e in self.index if e[7].startswith(prefix)]
|
2013-07-24 02:28:12 +04:00
|
|
|
nl = [n for n in nl if hex(n).startswith(id) and
|
|
|
|
self.hasnode(n)]
|
2008-11-13 04:11:34 +03:00
|
|
|
if len(nl) > 0:
|
2016-08-19 12:26:04 +03:00
|
|
|
if len(nl) == 1 and not maybewdir:
|
2011-01-12 02:12:32 +03:00
|
|
|
self._pcache[id] = nl[0]
|
2008-11-13 04:11:34 +03:00
|
|
|
return nl[0]
|
|
|
|
raise LookupError(id, self.indexfile,
|
|
|
|
_('ambiguous identifier'))
|
2016-08-19 12:26:04 +03:00
|
|
|
if maybewdir:
|
|
|
|
raise error.WdirUnsupported
|
2008-11-13 04:11:34 +03:00
|
|
|
return None
|
2017-06-20 19:41:46 +03:00
|
|
|
except (TypeError, binascii.Error):
|
2006-10-18 20:44:56 +04:00
|
|
|
pass
|
|
|
|
|
|
|
|
def lookup(self, id):
|
|
|
|
"""locate a node based on:
|
|
|
|
- revision number or str(revision number)
|
|
|
|
- nodeid or subset of hex nodeid
|
|
|
|
"""
|
|
|
|
n = self._match(id)
|
|
|
|
if n is not None:
|
|
|
|
return n
|
|
|
|
n = self._partialmatch(id)
|
|
|
|
if n:
|
|
|
|
return n
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2008-03-12 01:42:29 +03:00
|
|
|
raise LookupError(id, self.indexfile, _('no match found'))
|
2005-05-08 04:11:36 +04:00
|
|
|
|
2017-09-15 10:01:57 +03:00
|
|
|
def shortest(self, hexnode, minlength=1):
|
|
|
|
"""Find the shortest unambiguous prefix that matches hexnode."""
|
|
|
|
def isvalid(test):
|
|
|
|
try:
|
|
|
|
if self._partialmatch(test) is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
i = int(test)
|
|
|
|
# if we are a pure int, then starting with zero will not be
|
|
|
|
# confused as a rev; or, obviously, if the int is larger
|
|
|
|
# than the value of the tip rev
|
|
|
|
if test[0] == '0' or i > len(self):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
except ValueError:
|
|
|
|
return True
|
|
|
|
except error.RevlogError:
|
|
|
|
return False
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
# single 'ff...' match
|
|
|
|
return True
|
|
|
|
|
|
|
|
shortest = hexnode
|
|
|
|
startlength = max(6, minlength)
|
|
|
|
length = startlength
|
|
|
|
while True:
|
|
|
|
test = hexnode[:length]
|
|
|
|
if isvalid(test):
|
|
|
|
shortest = test
|
|
|
|
if length == minlength or length > startlength:
|
|
|
|
return shortest
|
|
|
|
length -= 1
|
|
|
|
else:
|
|
|
|
length += 1
|
|
|
|
if len(shortest) <= length:
|
|
|
|
return shortest
|
|
|
|
|
2006-08-15 23:18:13 +04:00
|
|
|
def cmp(self, node, text):
|
2010-07-09 06:02:39 +04:00
|
|
|
"""compare text with a given file revision
|
|
|
|
|
|
|
|
returns True if text is different than what is stored.
|
|
|
|
"""
|
2006-08-15 23:18:13 +04:00
|
|
|
p1, p2 = self.parents(node)
|
|
|
|
return hash(text, p1, p2) != node
|
|
|
|
|
2017-05-06 22:02:12 +03:00
|
|
|
def _cachesegment(self, offset, data):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Add a segment to the revlog cache.
|
|
|
|
|
|
|
|
Accepts an absolute offset and the data that is at that location.
|
|
|
|
"""
|
2009-05-08 04:39:45 +04:00
|
|
|
o, d = self._chunkcache
|
|
|
|
# try to add to existing cache
|
2011-01-04 23:12:52 +03:00
|
|
|
if o + len(d) == offset and len(d) + len(data) < _chunksize:
|
2009-05-08 04:39:45 +04:00
|
|
|
self._chunkcache = o, d + data
|
2005-12-27 22:09:49 +03:00
|
|
|
else:
|
2009-05-08 04:39:45 +04:00
|
|
|
self._chunkcache = offset, data
|
|
|
|
|
2017-05-06 22:02:12 +03:00
|
|
|
def _readsegment(self, offset, length, df=None):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Load a segment of raw data from the revlog.
|
2015-09-28 01:48:35 +03:00
|
|
|
|
2015-11-23 03:23:20 +03:00
|
|
|
Accepts an absolute offset, length to read, and an optional existing
|
2015-09-28 01:48:35 +03:00
|
|
|
file handle to read from.
|
|
|
|
|
|
|
|
If an existing file handle is passed, it will be seeked and the
|
|
|
|
original seek position will NOT be restored.
|
2015-11-23 03:23:20 +03:00
|
|
|
|
|
|
|
Returns a str or buffer of raw byte data.
|
2015-09-28 01:48:35 +03:00
|
|
|
"""
|
|
|
|
if df is not None:
|
|
|
|
closehandle = False
|
2009-05-28 01:01:34 +04:00
|
|
|
else:
|
2015-09-28 01:48:35 +03:00
|
|
|
if self._inline:
|
|
|
|
df = self.opener(self.indexfile)
|
|
|
|
else:
|
|
|
|
df = self.opener(self.datafile)
|
|
|
|
closehandle = True
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2013-11-18 03:04:28 +04:00
|
|
|
# Cache data both forward and backward around the requested
|
|
|
|
# data, in a fixed size window. This helps speed up operations
|
|
|
|
# involving reading the revlog backwards.
|
revlog: allow tuning of the chunk cache size (via format.chunkcachesize)
Running perfmoonwalk on the Mercurial repo (with almost 20,000 changesets) on
Mac OS X with an SSD, before this change:
$ hg --config format.chunkcachesize=1024 perfmoonwalk
! wall 2.022021 comb 2.030000 user 1.970000 sys 0.060000 (best of 5)
(16,154 cache hits, 3,840 misses.)
$ hg --config format.chunkcachesize=4096 perfmoonwalk
! wall 1.901006 comb 1.900000 user 1.880000 sys 0.020000 (best of 6)
(19,003 hits, 991 misses.)
$ hg --config format.chunkcachesize=16384 perfmoonwalk
! wall 1.802775 comb 1.800000 user 1.800000 sys 0.000000 (best of 6)
(19,746 hits, 248 misses.)
$ hg --config format.chunkcachesize=32768 perfmoonwalk
! wall 1.818545 comb 1.810000 user 1.810000 sys 0.000000 (best of 6)
(19,870 hits, 124 misses.)
$ hg --config format.chunkcachesize=65536 perfmoonwalk
! wall 1.801350 comb 1.810000 user 1.800000 sys 0.010000 (best of 6)
(19,932 hits, 62 misses.)
$ hg --config format.chunkcachesize=131072 perfmoonwalk
! wall 1.805879 comb 1.820000 user 1.810000 sys 0.010000 (best of 6)
(19,963 hits, 31 misses.)
We may want to change the default size in the future based on testing and
user feedback.
2013-11-18 03:04:29 +04:00
|
|
|
cachesize = self._chunkcachesize
|
|
|
|
realoffset = offset & ~(cachesize - 1)
|
|
|
|
reallength = (((offset + length + cachesize) & ~(cachesize - 1))
|
|
|
|
- realoffset)
|
2013-11-18 03:04:28 +04:00
|
|
|
df.seek(realoffset)
|
|
|
|
d = df.read(reallength)
|
2015-09-28 01:48:35 +03:00
|
|
|
if closehandle:
|
|
|
|
df.close()
|
2017-05-06 22:02:12 +03:00
|
|
|
self._cachesegment(realoffset, d)
|
2013-11-18 03:04:28 +04:00
|
|
|
if offset != realoffset or reallength != length:
|
|
|
|
return util.buffer(d, offset - realoffset, length)
|
2009-05-08 04:39:45 +04:00
|
|
|
return d
|
|
|
|
|
2017-05-06 22:02:12 +03:00
|
|
|
def _getsegment(self, offset, length, df=None):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Obtain a segment of raw data from the revlog.
|
|
|
|
|
|
|
|
Accepts an absolute offset, length of bytes to obtain, and an
|
|
|
|
optional file handle to the already-opened revlog. If the file
|
|
|
|
handle is used, it's original seek position will not be preserved.
|
|
|
|
|
|
|
|
Requests for data may be returned from a cache.
|
|
|
|
|
|
|
|
Returns a str or a buffer instance of raw byte data.
|
|
|
|
"""
|
2009-05-08 04:39:45 +04:00
|
|
|
o, d = self._chunkcache
|
|
|
|
l = len(d)
|
|
|
|
|
|
|
|
# is it in the cache?
|
|
|
|
cachestart = offset - o
|
|
|
|
cacheend = cachestart + length
|
|
|
|
if cachestart >= 0 and cacheend <= l:
|
|
|
|
if cachestart == 0 and cacheend == l:
|
|
|
|
return d # avoid a copy
|
2012-04-13 07:26:33 +04:00
|
|
|
return util.buffer(d, cachestart, cacheend - cachestart)
|
2005-12-27 22:09:49 +03:00
|
|
|
|
2017-05-06 22:02:12 +03:00
|
|
|
return self._readsegment(offset, length, df=df)
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2017-05-06 22:12:53 +03:00
|
|
|
def _getsegmentforrevs(self, startrev, endrev, df=None):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Obtain a segment of raw data corresponding to a range of revisions.
|
|
|
|
|
|
|
|
Accepts the start and end revisions and an optional already-open
|
|
|
|
file handle to be used for reading. If the file handle is read, its
|
|
|
|
seek position will not be preserved.
|
|
|
|
|
|
|
|
Requests for data may be satisfied by a cache.
|
|
|
|
|
2016-01-06 06:51:51 +03:00
|
|
|
Returns a 2-tuple of (offset, data) for the requested range of
|
|
|
|
revisions. Offset is the integer offset from the beginning of the
|
|
|
|
revlog and data is a str or buffer of the raw byte data.
|
|
|
|
|
|
|
|
Callers will need to call ``self.start(rev)`` and ``self.length(rev)``
|
|
|
|
to determine where each revision's data begins and ends.
|
2015-11-23 03:23:20 +03:00
|
|
|
"""
|
2016-10-23 01:41:23 +03:00
|
|
|
# Inlined self.start(startrev) & self.end(endrev) for perf reasons
|
|
|
|
# (functions are expensive).
|
|
|
|
index = self.index
|
|
|
|
istart = index[startrev]
|
|
|
|
start = int(istart[0] >> 16)
|
2016-10-23 20:40:33 +03:00
|
|
|
if startrev == endrev:
|
|
|
|
end = start + istart[1]
|
|
|
|
else:
|
|
|
|
iend = index[endrev]
|
|
|
|
end = int(iend[0] >> 16) + iend[1]
|
2016-10-23 01:41:23 +03:00
|
|
|
|
2009-05-08 04:39:45 +04:00
|
|
|
if self._inline:
|
|
|
|
start += (startrev + 1) * self._io.size
|
2013-09-07 23:42:46 +04:00
|
|
|
end += (endrev + 1) * self._io.size
|
|
|
|
length = end - start
|
2016-01-06 06:51:51 +03:00
|
|
|
|
2017-05-06 22:02:12 +03:00
|
|
|
return start, self._getsegment(start, length, df=df)
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2015-09-28 01:48:35 +03:00
|
|
|
def _chunk(self, rev, df=None):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Obtain a single decompressed chunk for a revision.
|
|
|
|
|
|
|
|
Accepts an integer revision and an optional already-open file handle
|
|
|
|
to be used for reading. If used, the seek position of the file will not
|
|
|
|
be preserved.
|
|
|
|
|
|
|
|
Returns a str holding uncompressed data for the requested revision.
|
|
|
|
"""
|
2017-05-06 22:12:53 +03:00
|
|
|
return self.decompress(self._getsegmentforrevs(rev, rev, df=df)[1])
|
2009-05-28 01:01:34 +04:00
|
|
|
|
2015-09-28 01:48:35 +03:00
|
|
|
def _chunks(self, revs, df=None):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Obtain decompressed chunks for the specified revisions.
|
|
|
|
|
|
|
|
Accepts an iterable of numeric revisions that are assumed to be in
|
|
|
|
ascending order. Also accepts an optional already-open file handle
|
|
|
|
to be used for reading. If used, the seek position of the file will
|
|
|
|
not be preserved.
|
2013-09-07 03:31:35 +04:00
|
|
|
|
2015-11-23 03:23:20 +03:00
|
|
|
This function is similar to calling ``self._chunk()`` multiple times,
|
|
|
|
but is faster.
|
|
|
|
|
|
|
|
Returns a list with decompressed data for each requested revision.
|
|
|
|
"""
|
2013-09-07 10:05:11 +04:00
|
|
|
if not revs:
|
|
|
|
return []
|
2013-09-07 03:31:35 +04:00
|
|
|
start = self.start
|
|
|
|
length = self.length
|
|
|
|
inline = self._inline
|
|
|
|
iosize = self._io.size
|
2013-09-07 09:57:51 +04:00
|
|
|
buffer = util.buffer
|
2013-09-07 03:31:35 +04:00
|
|
|
|
|
|
|
l = []
|
|
|
|
ladd = l.append
|
|
|
|
|
2017-10-10 18:50:27 +03:00
|
|
|
if not self._withsparseread:
|
|
|
|
slicedchunks = (revs,)
|
|
|
|
else:
|
|
|
|
slicedchunks = _slicechunk(self, revs)
|
2017-10-09 16:13:41 +03:00
|
|
|
|
2017-10-10 18:50:27 +03:00
|
|
|
for revschunk in slicedchunks:
|
|
|
|
firstrev = revschunk[0]
|
|
|
|
# Skip trailing revisions with empty diff
|
|
|
|
for lastrev in revschunk[::-1]:
|
|
|
|
if length(lastrev) != 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
offset, data = self._getsegmentforrevs(firstrev, lastrev, df=df)
|
|
|
|
except OverflowError:
|
|
|
|
# issue4215 - we can't cache a run of chunks greater than
|
|
|
|
# 2G on Windows
|
|
|
|
return [self._chunk(rev, df=df) for rev in revschunk]
|
|
|
|
|
|
|
|
decomp = self.decompress
|
|
|
|
for rev in revschunk:
|
|
|
|
chunkstart = start(rev)
|
|
|
|
if inline:
|
|
|
|
chunkstart += (rev + 1) * iosize
|
|
|
|
chunklength = length(rev)
|
|
|
|
ladd(decomp(buffer(data, chunkstart - offset, chunklength)))
|
2013-09-07 03:31:35 +04:00
|
|
|
|
|
|
|
return l
|
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _chunkclear(self):
|
2015-11-23 03:23:20 +03:00
|
|
|
"""Clear the raw chunk cache."""
|
2009-05-28 01:01:34 +04:00
|
|
|
self._chunkcache = (0, '')
|
2005-12-27 22:09:49 +03:00
|
|
|
|
2010-08-10 20:56:08 +04:00
|
|
|
def deltaparent(self, rev):
|
2011-05-05 14:55:12 +04:00
|
|
|
"""return deltaparent of the given revision"""
|
2011-05-08 00:40:17 +04:00
|
|
|
base = self.index[rev][3]
|
|
|
|
if base == rev:
|
2011-05-05 20:05:24 +04:00
|
|
|
return nullrev
|
2011-05-08 00:40:17 +04:00
|
|
|
elif self._generaldelta:
|
|
|
|
return base
|
2011-05-05 20:05:24 +04:00
|
|
|
else:
|
|
|
|
return rev - 1
|
2010-08-10 20:56:08 +04:00
|
|
|
|
2006-03-13 05:54:23 +03:00
|
|
|
def revdiff(self, rev1, rev2):
|
2017-03-31 04:23:27 +03:00
|
|
|
"""return or calculate a delta between two revisions
|
|
|
|
|
|
|
|
The delta calculated is in binary form and is intended to be written to
|
|
|
|
revlog data directly. So this function needs raw revision data.
|
|
|
|
"""
|
2011-05-05 20:05:24 +04:00
|
|
|
if rev1 != nullrev and self.deltaparent(rev2) == rev1:
|
2017-03-12 22:27:02 +03:00
|
|
|
return bytes(self._chunk(rev2))
|
2007-07-26 21:02:58 +04:00
|
|
|
|
2017-03-31 04:23:27 +03:00
|
|
|
return mdiff.textdiff(self.revision(rev1, raw=True),
|
|
|
|
self.revision(rev2, raw=True))
|
2005-05-21 05:40:24 +04:00
|
|
|
|
2017-01-05 20:16:07 +03:00
|
|
|
def revision(self, nodeorrev, _df=None, raw=False):
|
2012-04-13 12:14:59 +04:00
|
|
|
"""return an uncompressed revision of a given node or revision
|
|
|
|
number.
|
2015-09-28 01:48:35 +03:00
|
|
|
|
2017-01-05 20:16:07 +03:00
|
|
|
_df - an existing file handle to read from. (internal-only)
|
|
|
|
raw - an optional argument specifying if the revision data is to be
|
|
|
|
treated as raw data when applying flag transforms. 'raw' should be set
|
|
|
|
to True when generating changegroups or in debug commands.
|
2012-04-13 12:14:59 +04:00
|
|
|
"""
|
2012-04-08 21:38:02 +04:00
|
|
|
if isinstance(nodeorrev, int):
|
|
|
|
rev = nodeorrev
|
|
|
|
node = self.node(rev)
|
|
|
|
else:
|
|
|
|
node = nodeorrev
|
|
|
|
rev = None
|
|
|
|
|
2010-08-20 02:17:50 +04:00
|
|
|
cachedrev = None
|
2017-04-03 04:25:12 +03:00
|
|
|
flags = None
|
2017-04-03 04:40:13 +03:00
|
|
|
rawtext = None
|
2007-07-24 05:44:08 +04:00
|
|
|
if node == nullid:
|
|
|
|
return ""
|
2015-09-13 01:16:47 +03:00
|
|
|
if self._cache:
|
|
|
|
if self._cache[0] == node:
|
2017-03-31 01:34:08 +03:00
|
|
|
# _cache only stores rawtext
|
|
|
|
if raw:
|
|
|
|
return self._cache[2]
|
2017-03-31 07:21:15 +03:00
|
|
|
# duplicated, but good for perf
|
|
|
|
if rev is None:
|
|
|
|
rev = self.rev(node)
|
2017-04-03 04:25:12 +03:00
|
|
|
if flags is None:
|
|
|
|
flags = self.flags(rev)
|
2017-03-31 07:21:15 +03:00
|
|
|
# no extra flags set, no flag processor runs, text = rawtext
|
2017-04-03 04:25:12 +03:00
|
|
|
if flags == REVIDX_DEFAULT_FLAGS:
|
2017-03-31 07:21:15 +03:00
|
|
|
return self._cache[2]
|
2017-04-03 04:40:13 +03:00
|
|
|
# rawtext is reusable. need to run flag processor
|
|
|
|
rawtext = self._cache[2]
|
2017-03-31 07:21:15 +03:00
|
|
|
|
2015-09-13 01:16:47 +03:00
|
|
|
cachedrev = self._cache[1]
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2005-08-27 12:43:48 +04:00
|
|
|
# look up what we need to read
|
2017-04-03 04:29:24 +03:00
|
|
|
if rawtext is None:
|
|
|
|
if rev is None:
|
|
|
|
rev = self.rev(node)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2017-04-03 04:29:24 +03:00
|
|
|
chain, stopped = self._deltachain(rev, stoprev=cachedrev)
|
|
|
|
if stopped:
|
|
|
|
rawtext = self._cache[2]
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2017-04-03 04:29:24 +03:00
|
|
|
# drop cache to save memory
|
|
|
|
self._cache = None
|
2010-08-06 01:17:17 +04:00
|
|
|
|
2017-04-03 04:29:24 +03:00
|
|
|
bins = self._chunks(chain, df=_df)
|
|
|
|
if rawtext is None:
|
|
|
|
rawtext = bytes(bins[0])
|
|
|
|
bins = bins[1:]
|
2009-05-28 01:01:34 +04:00
|
|
|
|
2017-04-03 04:29:24 +03:00
|
|
|
rawtext = mdiff.patches(rawtext, bins)
|
2017-04-03 04:40:13 +03:00
|
|
|
self._cache = (node, rev, rawtext)
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
|
2017-04-03 04:25:12 +03:00
|
|
|
if flags is None:
|
2017-04-03 04:40:13 +03:00
|
|
|
if rev is None:
|
|
|
|
rev = self.rev(node)
|
2017-04-03 04:25:12 +03:00
|
|
|
flags = self.flags(rev)
|
|
|
|
|
|
|
|
text, validatehash = self._processflags(rawtext, flags, 'read', raw=raw)
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
if validatehash:
|
|
|
|
self.checkhash(text, node, rev=rev)
|
|
|
|
|
2011-01-07 02:04:41 +03:00
|
|
|
return text
|
|
|
|
|
2014-09-24 23:14:44 +04:00
|
|
|
def hash(self, text, p1, p2):
|
|
|
|
"""Compute a node hash.
|
|
|
|
|
|
|
|
Available as a function so that subclasses can replace the hash
|
|
|
|
as needed.
|
|
|
|
"""
|
|
|
|
return hash(text, p1, p2)
|
|
|
|
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
def _processflags(self, text, flags, operation, raw=False):
|
|
|
|
"""Inspect revision data flags and applies transforms defined by
|
|
|
|
registered flag processors.
|
|
|
|
|
|
|
|
``text`` - the revision data to process
|
|
|
|
``flags`` - the revision flags
|
|
|
|
``operation`` - the operation being performed (read or write)
|
|
|
|
``raw`` - an optional argument describing if the raw transform should be
|
|
|
|
applied.
|
|
|
|
|
|
|
|
This method processes the flags in the order (or reverse order if
|
|
|
|
``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the
|
|
|
|
flag processors registered for present flags. The order of flags defined
|
|
|
|
in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity.
|
|
|
|
|
|
|
|
Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
|
|
|
|
processed text and ``validatehash`` is a bool indicating whether the
|
|
|
|
returned text should be checked for hash integrity.
|
|
|
|
|
|
|
|
Note: If the ``raw`` argument is set, it has precedence over the
|
|
|
|
operation and will only update the value of ``validatehash``.
|
|
|
|
"""
|
2017-05-11 02:17:58 +03:00
|
|
|
# fast path: no flag processors will run
|
|
|
|
if flags == 0:
|
|
|
|
return text, True
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
if not operation in ('read', 'write'):
|
|
|
|
raise ProgrammingError(_("invalid '%s' operation ") % (operation))
|
|
|
|
# Check all flags are known.
|
|
|
|
if flags & ~REVIDX_KNOWN_FLAGS:
|
|
|
|
raise RevlogError(_("incompatible revision flag '%#x'") %
|
|
|
|
(flags & ~REVIDX_KNOWN_FLAGS))
|
|
|
|
validatehash = True
|
|
|
|
# Depending on the operation (read or write), the order might be
|
|
|
|
# reversed due to non-commutative transforms.
|
|
|
|
orderedflags = REVIDX_FLAGS_ORDER
|
|
|
|
if operation == 'write':
|
|
|
|
orderedflags = reversed(orderedflags)
|
|
|
|
|
|
|
|
for flag in orderedflags:
|
|
|
|
# If a flagprocessor has been registered for a known flag, apply the
|
|
|
|
# related operation transform and update result tuple.
|
|
|
|
if flag & flags:
|
|
|
|
vhash = True
|
|
|
|
|
|
|
|
if flag not in _flagprocessors:
|
|
|
|
message = _("missing processor for flag '%#x'") % (flag)
|
|
|
|
raise RevlogError(message)
|
|
|
|
|
|
|
|
processor = _flagprocessors[flag]
|
|
|
|
if processor is not None:
|
|
|
|
readtransform, writetransform, rawtransform = processor
|
|
|
|
|
|
|
|
if raw:
|
|
|
|
vhash = rawtransform(self, text)
|
|
|
|
elif operation == 'read':
|
|
|
|
text, vhash = readtransform(self, text)
|
|
|
|
else: # write operation
|
|
|
|
text, vhash = writetransform(self, text)
|
|
|
|
validatehash = validatehash and vhash
|
|
|
|
|
|
|
|
return text, validatehash
|
|
|
|
|
2016-12-13 17:21:36 +03:00
|
|
|
def checkhash(self, text, node, p1=None, p2=None, rev=None):
|
|
|
|
"""Check node hash integrity.
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2016-12-13 17:21:36 +03:00
|
|
|
Available as a function so that subclasses can extend hash mismatch
|
|
|
|
behaviors as needed.
|
|
|
|
"""
|
|
|
|
if p1 is None and p2 is None:
|
|
|
|
p1, p2 = self.parents(node)
|
2014-09-24 23:14:44 +04:00
|
|
|
if node != self.hash(text, p1, p2):
|
2013-08-19 22:06:38 +04:00
|
|
|
revornode = rev
|
|
|
|
if revornode is None:
|
|
|
|
revornode = templatefilters.short(hex(node))
|
|
|
|
raise RevlogError(_("integrity check failed on %s:%s")
|
2017-08-23 04:21:43 +03:00
|
|
|
% (self.indexfile, pycompat.bytestr(revornode)))
|
2013-08-19 22:06:38 +04:00
|
|
|
|
2006-04-05 00:38:43 +04:00
|
|
|
def checkinlinesize(self, tr, fp=None):
|
2015-09-28 01:31:50 +03:00
|
|
|
"""Check if the revlog is too big for inline and convert if so.
|
|
|
|
|
|
|
|
This should be called after revisions are added to the revlog. If the
|
|
|
|
revlog has grown too large to be an inline revlog, it will convert it
|
|
|
|
to use multiple index and data files.
|
|
|
|
"""
|
2010-04-14 01:58:38 +04:00
|
|
|
if not self._inline or (self.start(-2) + self.length(-2)) < _maxinline:
|
2006-04-05 00:38:43 +04:00
|
|
|
return
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2006-04-17 21:19:58 +04:00
|
|
|
trinfo = tr.find(self.indexfile)
|
2009-05-20 02:52:46 +04:00
|
|
|
if trinfo is None:
|
2006-11-19 18:09:04 +03:00
|
|
|
raise RevlogError(_("%s not found in the transaction")
|
|
|
|
% self.indexfile)
|
2006-04-17 21:19:58 +04:00
|
|
|
|
|
|
|
trindex = trinfo[2]
|
2015-03-25 22:58:31 +03:00
|
|
|
if trindex is not None:
|
|
|
|
dataoff = self.start(trindex)
|
|
|
|
else:
|
|
|
|
# revlog was stripped at start of transaction, use all leftover data
|
|
|
|
trindex = len(self) - 1
|
|
|
|
dataoff = self.end(-2)
|
2006-04-17 21:19:58 +04:00
|
|
|
|
|
|
|
tr.add(self.datafile, dataoff)
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2009-05-08 04:39:45 +04:00
|
|
|
if fp:
|
|
|
|
fp.flush()
|
|
|
|
fp.close()
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2006-04-05 00:38:43 +04:00
|
|
|
df = self.opener(self.datafile, 'w')
|
2008-03-15 00:12:50 +03:00
|
|
|
try:
|
2008-06-26 23:35:50 +04:00
|
|
|
for r in self:
|
2017-05-06 22:12:53 +03:00
|
|
|
df.write(self._getsegmentforrevs(r, r)[1])
|
2008-03-15 00:12:50 +03:00
|
|
|
finally:
|
|
|
|
df.close()
|
|
|
|
|
2016-09-22 15:51:58 +03:00
|
|
|
fp = self.opener(self.indexfile, 'w', atomictemp=True,
|
|
|
|
checkambig=self._checkambig)
|
2017-05-18 05:52:18 +03:00
|
|
|
self.version &= ~FLAG_INLINE_DATA
|
2007-07-24 05:44:08 +04:00
|
|
|
self._inline = False
|
2008-06-26 23:35:50 +04:00
|
|
|
for i in self:
|
2007-09-26 08:58:45 +04:00
|
|
|
e = self._io.packentry(self.index[i], self.node, self.version, i)
|
2006-04-05 00:38:43 +04:00
|
|
|
fp.write(e)
|
|
|
|
|
2011-08-26 04:21:04 +04:00
|
|
|
# if we don't call close, the temp file will never replace the
|
2006-04-05 00:38:44 +04:00
|
|
|
# real index
|
2011-08-26 04:21:04 +04:00
|
|
|
fp.close()
|
2006-04-17 21:19:58 +04:00
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
tr.replace(self.indexfile, trindex * self._io.size)
|
|
|
|
self._chunkclear()
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2013-08-19 22:25:23 +04:00
|
|
|
def addrevision(self, text, transaction, link, p1, p2, cachedelta=None,
|
2017-01-05 20:16:07 +03:00
|
|
|
node=None, flags=REVIDX_DEFAULT_FLAGS):
|
2005-08-27 12:43:48 +04:00
|
|
|
"""add a revision to the log
|
|
|
|
|
|
|
|
text - the revision data to add
|
|
|
|
transaction - the transaction object used for rollback
|
|
|
|
link - the linkrev data to add
|
|
|
|
p1, p2 - the parent nodeids of the revision
|
2010-08-21 21:31:59 +04:00
|
|
|
cachedelta - an optional precomputed delta
|
2013-08-19 22:25:23 +04:00
|
|
|
node - nodeid of revision; typically node is not specified, and it is
|
|
|
|
computed by default as hash(text, p1, p2), however subclasses might
|
|
|
|
use different hashing method (and override checkhash() in such case)
|
2017-01-05 20:16:07 +03:00
|
|
|
flags - the known flags to set on the revision
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
2013-06-18 06:44:00 +04:00
|
|
|
if link == nullrev:
|
|
|
|
raise RevlogError(_("attempted to add linkrev -1 to %s")
|
|
|
|
% self.indexfile)
|
2015-06-04 22:57:58 +03:00
|
|
|
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
if flags:
|
|
|
|
node = node or self.hash(text, p1, p2)
|
|
|
|
|
2017-03-31 00:56:09 +03:00
|
|
|
rawtext, validatehash = self._processflags(text, flags, 'write')
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
|
|
|
|
# If the flag processor modifies the revision data, ignore any provided
|
|
|
|
# cachedelta.
|
2017-03-31 00:56:09 +03:00
|
|
|
if rawtext != text:
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
cachedelta = None
|
|
|
|
|
2017-03-31 00:56:09 +03:00
|
|
|
if len(rawtext) > _maxentrysize:
|
2015-06-04 22:57:58 +03:00
|
|
|
raise RevlogError(
|
|
|
|
_("%s: size of %d bytes exceeds maximum revlog storage of 2GiB")
|
2017-03-31 00:56:09 +03:00
|
|
|
% (self.indexfile, len(rawtext)))
|
2015-06-04 22:57:58 +03:00
|
|
|
|
2017-03-31 00:56:09 +03:00
|
|
|
node = node or self.hash(rawtext, p1, p2)
|
2011-05-05 14:46:02 +04:00
|
|
|
if node in self.nodemap:
|
2010-08-23 01:17:17 +04:00
|
|
|
return node
|
|
|
|
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
if validatehash:
|
2017-03-31 00:56:09 +03:00
|
|
|
self.checkhash(rawtext, node, p1=p1, p2=p2)
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
|
2017-05-10 07:27:06 +03:00
|
|
|
return self.addrawrevision(rawtext, transaction, link, p1, p2, node,
|
|
|
|
flags, cachedelta=cachedelta)
|
|
|
|
|
|
|
|
def addrawrevision(self, rawtext, transaction, link, p1, p2, node, flags,
|
|
|
|
cachedelta=None):
|
|
|
|
"""add a raw revision with known flags, node and parents
|
|
|
|
useful when reusing a revision not stored in this revlog (ex: received
|
|
|
|
over wire, or read from an external bundle).
|
|
|
|
"""
|
2007-07-24 05:44:08 +04:00
|
|
|
dfh = None
|
2007-07-24 05:44:08 +04:00
|
|
|
if not self._inline:
|
2015-09-28 01:59:19 +03:00
|
|
|
dfh = self.opener(self.datafile, "a+")
|
2016-09-22 15:51:58 +03:00
|
|
|
ifh = self.opener(self.indexfile, "a+", checkambig=self._checkambig)
|
2008-03-15 00:12:50 +03:00
|
|
|
try:
|
2017-03-31 00:56:09 +03:00
|
|
|
return self._addrevision(node, rawtext, transaction, link, p1, p2,
|
2017-01-05 20:16:07 +03:00
|
|
|
flags, cachedelta, ifh, dfh)
|
2008-03-15 00:12:50 +03:00
|
|
|
finally:
|
|
|
|
if dfh:
|
|
|
|
dfh.close()
|
|
|
|
ifh.close()
|
2006-10-15 01:47:48 +04:00
|
|
|
|
2017-01-02 22:22:52 +03:00
|
|
|
def compress(self, data):
|
|
|
|
"""Generate a possibly-compressed representation of data."""
|
|
|
|
if not data:
|
|
|
|
return '', data
|
|
|
|
|
|
|
|
compressed = self._compressor.compress(data)
|
|
|
|
|
|
|
|
if compressed:
|
|
|
|
# The revlog compressor added the header in the returned data.
|
|
|
|
return '', compressed
|
|
|
|
|
2017-03-26 11:12:06 +03:00
|
|
|
if data[0:1] == '\0':
|
2017-01-02 22:22:52 +03:00
|
|
|
return '', data
|
|
|
|
return 'u', data
|
2012-06-26 00:56:13 +04:00
|
|
|
|
2017-01-03 00:00:16 +03:00
|
|
|
def decompress(self, data):
|
|
|
|
"""Decompress a revlog chunk.
|
|
|
|
|
|
|
|
The chunk is expected to begin with a header identifying the
|
|
|
|
format type so it can be routed to an appropriate decompressor.
|
|
|
|
"""
|
|
|
|
if not data:
|
|
|
|
return data
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
|
|
|
|
# Revlogs are read much more frequently than they are written and many
|
|
|
|
# chunks only take microseconds to decompress, so performance is
|
|
|
|
# important here.
|
|
|
|
#
|
|
|
|
# We can make a few assumptions about revlogs:
|
|
|
|
#
|
|
|
|
# 1) the majority of chunks will be compressed (as opposed to inline
|
|
|
|
# raw data).
|
|
|
|
# 2) decompressing *any* data will likely by at least 10x slower than
|
|
|
|
# returning raw inline data.
|
|
|
|
# 3) we want to prioritize common and officially supported compression
|
|
|
|
# engines
|
|
|
|
#
|
|
|
|
# It follows that we want to optimize for "decompress compressed data
|
|
|
|
# when encoded with common and officially supported compression engines"
|
|
|
|
# case over "raw data" and "data encoded by less common or non-official
|
|
|
|
# compression engines." That is why we have the inline lookup first
|
|
|
|
# followed by the compengines lookup.
|
|
|
|
#
|
|
|
|
# According to `hg perfrevlogchunks`, this is ~0.5% faster for zlib
|
|
|
|
# compressed chunks. And this matters for changelog and manifest reads.
|
2017-03-12 08:49:49 +03:00
|
|
|
t = data[0:1]
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
|
2017-01-03 00:00:16 +03:00
|
|
|
if t == 'x':
|
|
|
|
try:
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
return _zlibdecompress(data)
|
2017-01-03 00:00:16 +03:00
|
|
|
except zlib.error as e:
|
|
|
|
raise RevlogError(_('revlog decompress error: %s') % str(e))
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
# '\0' is more common than 'u' so it goes first.
|
|
|
|
elif t == '\0':
|
|
|
|
return data
|
|
|
|
elif t == 'u':
|
2017-01-03 00:00:16 +03:00
|
|
|
return util.buffer(data, 1)
|
revlog: use compression engine APIs for decompression
Now that compression engines declare their header in revlog chunks
and can decompress revlog chunks, we refactor revlog.decompress()
to use them.
Making full use of the property that revlog compressor objects are
reusable, revlog instances now maintain a dict mapping an engine's
revlog header to a compressor object. This is not only a performance
optimization for engines where compressor object reuse can result in
better performance, but it also serves as a cache of header values
so we don't need to perform redundant lookups against the compression
engine manager. (Yes, I measured and the overhead of a function call
versus a dict lookup was observed.)
Replacing the previous inline lookup table with a dict lookup was
measured to make chunk reading ~2.5% slower on changelogs and ~4.5%
slower on manifests. So, the inline lookup table has been mostly
preserved so we don't lose performance. This is unfortunate. But
many decompression operations complete in microseconds, so Python
attribute lookup, dict lookup, and function calls do matter.
The impact of this change on mozilla-unified is as follows:
$ hg perfrevlogchunks -c
! chunk
! wall 1.953663 comb 1.950000 user 1.920000 sys 0.030000 (best of 6)
! wall 1.946000 comb 1.940000 user 1.910000 sys 0.030000 (best of 6)
! chunk batch
! wall 1.791075 comb 1.800000 user 1.760000 sys 0.040000 (best of 6)
! wall 1.785690 comb 1.770000 user 1.750000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.587262 comb 2.580000 user 2.550000 sys 0.030000 (best of 4)
! wall 2.616330 comb 2.610000 user 2.560000 sys 0.050000 (best of 4)
! chunk batch
! wall 2.427092 comb 2.420000 user 2.400000 sys 0.020000 (best of 5)
! wall 2.462061 comb 2.460000 user 2.400000 sys 0.060000 (best of 4)
Changelog chunk reading is slightly faster but manifest reading is
slower. What gives?
On this repo, 99.85% of changelog entries are zlib compressed (the 'x'
header). On the manifest, 67.5% are zlib and 32.4% are '\0'. This patch
swapped the test order of 'x' and '\0' so now 'x' is tested first. This
makes changelogs faster since they almost always hit the first branch.
This makes a significant percentage of manifest '\0' chunks slower
because that code path now performs an extra test. Yes, I too can't
believe we're able to measure the impact of an if..elif with simple
string compares. I reckon this code would benefit from being written
in C...
2017-01-14 06:58:00 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
compressor = self._decompressors[t]
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
engine = util.compengines.forrevlogheader(t)
|
|
|
|
compressor = engine.revlogcompressor()
|
|
|
|
self._decompressors[t] = compressor
|
|
|
|
except KeyError:
|
|
|
|
raise RevlogError(_('unknown compression type %r') % t)
|
|
|
|
|
|
|
|
return compressor.decompress(data)
|
2017-01-03 00:00:16 +03:00
|
|
|
|
2015-08-30 23:33:00 +03:00
|
|
|
def _isgooddelta(self, d, textlen):
|
|
|
|
"""Returns True if the given delta is good. Good means that it is within
|
|
|
|
the disk span, disk size, and chain length bounds that we know to be
|
|
|
|
performant."""
|
|
|
|
if d is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# - 'dist' is the distance from the base revision -- bounding it limits
|
|
|
|
# the amount of I/O we need to do.
|
|
|
|
# - 'compresseddeltalen' is the sum of the total size of deltas we need
|
|
|
|
# to apply -- bounding it limits the amount of CPU we consume.
|
|
|
|
dist, l, data, base, chainbase, chainlen, compresseddeltalen = d
|
2017-06-23 14:49:34 +03:00
|
|
|
|
|
|
|
defaultmax = textlen * 4
|
|
|
|
maxdist = self._maxdeltachainspan
|
|
|
|
if not maxdist:
|
|
|
|
maxdist = dist # ensure the conditional pass
|
|
|
|
maxdist = max(maxdist, defaultmax)
|
|
|
|
if (dist > maxdist or l > textlen or
|
2015-08-30 23:33:00 +03:00
|
|
|
compresseddeltalen > textlen * 2 or
|
|
|
|
(self._maxchainlen and chainlen > self._maxchainlen)):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2017-03-31 04:38:03 +03:00
|
|
|
def _addrevision(self, node, rawtext, transaction, link, p1, p2, flags,
|
|
|
|
cachedelta, ifh, dfh, alwayscache=False):
|
2011-05-11 13:04:44 +04:00
|
|
|
"""internal function to add revisions to the log
|
2010-10-09 03:00:16 +04:00
|
|
|
|
2011-05-11 13:04:44 +04:00
|
|
|
see addrevision for argument descriptions.
|
2017-03-31 04:38:03 +03:00
|
|
|
|
|
|
|
note: "addrevision" takes non-raw text, "_addrevision" takes raw text.
|
|
|
|
|
2011-05-11 13:04:44 +04:00
|
|
|
invariants:
|
2017-03-31 04:38:03 +03:00
|
|
|
- rawtext is optional (can be None); if not set, cachedelta must be set.
|
2012-08-16 00:38:42 +04:00
|
|
|
if both are set, they must correspond to each other.
|
2011-05-11 13:04:44 +04:00
|
|
|
"""
|
2017-08-26 01:50:07 +03:00
|
|
|
if node == nullid:
|
|
|
|
raise RevlogError(_("%s: attempt to add null revision") %
|
|
|
|
(self.indexfile))
|
2017-08-30 19:21:31 +03:00
|
|
|
if node == wdirid:
|
|
|
|
raise RevlogError(_("%s: attempt to add wdir revision") %
|
|
|
|
(self.indexfile))
|
|
|
|
|
2017-03-31 04:38:03 +03:00
|
|
|
btext = [rawtext]
|
2010-10-30 11:47:34 +04:00
|
|
|
def buildtext():
|
|
|
|
if btext[0] is not None:
|
|
|
|
return btext[0]
|
2015-02-06 04:38:16 +03:00
|
|
|
baserev = cachedelta[0]
|
|
|
|
delta = cachedelta[1]
|
|
|
|
# special case deltas which replace entire base; no need to decode
|
|
|
|
# base revision. this neatly avoids censored bases, which throw when
|
|
|
|
# they're decoded.
|
|
|
|
hlen = struct.calcsize(">lll")
|
|
|
|
if delta[:hlen] == mdiff.replacediffheader(self.rawsize(baserev),
|
|
|
|
len(delta) - hlen):
|
|
|
|
btext[0] = delta[hlen:]
|
|
|
|
else:
|
revlog: use existing file handle when reading during _addrevision
_addrevision() may need to read from revlogs as part of computing
deltas. Previously, we would flush existing file handles and open
a new, short-lived file handle to perform the reading.
If we have an existing file handle, it seems logical to reuse it
for reading instead of opening a new file handle. This patch
makes that the new behavior.
After this patch, revlog files are only reopened when adding
revisions if the revlog is switched from inline to non-inline.
On Linux when unbundling a bundle of the mozilla-central repo, this
patch has the following impact on system call counts:
Call Before After Delta
write 827,639 673,390 -154,249
open 700,103 684,089 -16,014
read 74,489 74,489 0
fstat 493,924 461,896 -32,028
close 249,131 233,117 -16,014
stat 242,001 242,001 0
lstat 18,676 18,676 0
lseek 20,268 20,268 0
ioctl 14,652 13,173 -1,479
TOTAL 3,180,758 2,930,679 -250,079
It's worth noting that many of the open() calls fail due to missing
files. That's why there are many more open() calls than close().
Despite the significant system call reduction, this change does not
seem to have a significant performance impact on Linux.
On Windows 10 (not a VM, on a SSD), this patch appears to reduce
unbundle time for mozilla-central from ~960s to ~920s. This isn't
as significant as I was hoping. But a decrease it is nonetheless.
Still, Windows unbundle performance is still >2x slower than Linux.
Despite the lack of significant gains, fewer system calls is fewer
system calls. If nothing else, this will narrow the focus of potential
areas to optimize in the future.
2015-09-28 02:08:18 +03:00
|
|
|
if self._inline:
|
|
|
|
fh = ifh
|
|
|
|
else:
|
|
|
|
fh = dfh
|
2017-03-31 04:38:03 +03:00
|
|
|
basetext = self.revision(baserev, _df=fh, raw=True)
|
2015-02-06 04:38:16 +03:00
|
|
|
btext[0] = mdiff.patch(basetext, delta)
|
2017-01-05 20:16:07 +03:00
|
|
|
|
2014-09-04 00:34:29 +04:00
|
|
|
try:
|
2017-03-31 04:38:03 +03:00
|
|
|
res = self._processflags(btext[0], flags, 'read', raw=True)
|
revlog: flag processor
Add the ability for revlog objects to process revision flags and apply
registered transforms on read/write operations.
This patch introduces:
- the 'revlog._processflags()' method that looks at revision flags and applies
flag processors registered on them. Due to the need to handle non-commutative
operations, flag transforms are applied in stable order but the order in which
the transforms are applied is reversed between read and write operations.
- the 'addflagprocessor()' method allowing to register processors on flags.
Flag processors are defined as a 3-tuple of (read, write, raw) functions to be
applied depending on the operation being performed.
- an update on 'revlog.addrevision()' behavior. The current flagprocessor design
relies on extensions to wrap around 'addrevision()' to set flags on revision
data, and on the flagprocessor to perform the actual transformation of its
contents. In the lfs case, this means we need to process flags before we meet
the 2GB size check, leading to performing some operations before it happens:
- if flags are set on the revision data, we assume some extensions might be
modifying the contents using the flag processor next, and we compute the
node for the original revision data (still allowing extension to override
the node by wrapping around 'addrevision()').
- we then invoke the flag processor to apply registered transforms (in lfs's
case, drastically reducing the size of large blobs).
- finally, we proceed with the 2GB size check.
Note: In the case a cachedelta is passed to 'addrevision()' and we detect the
flag processor modified the revision data, we chose to trust the flag processor
and drop the cachedelta.
2017-01-10 19:15:21 +03:00
|
|
|
btext[0], validatehash = res
|
|
|
|
if validatehash:
|
|
|
|
self.checkhash(btext[0], node, p1=p1, p2=p2)
|
2015-01-12 22:41:25 +03:00
|
|
|
if flags & REVIDX_ISCENSORED:
|
|
|
|
raise RevlogError(_('node %s is not censored') % node)
|
2014-09-04 00:34:29 +04:00
|
|
|
except CensoredNodeError:
|
2015-01-12 22:41:25 +03:00
|
|
|
# must pass the censored index flag to add censored revisions
|
|
|
|
if not flags & REVIDX_ISCENSORED:
|
|
|
|
raise
|
2010-10-30 11:47:34 +04:00
|
|
|
return btext[0]
|
2010-10-09 03:00:16 +04:00
|
|
|
|
2010-10-30 11:47:34 +04:00
|
|
|
def builddelta(rev):
|
|
|
|
# can we use the cached delta?
|
|
|
|
if cachedelta and cachedelta[0] == rev:
|
|
|
|
delta = cachedelta[1]
|
|
|
|
else:
|
|
|
|
t = buildtext()
|
2015-01-22 01:11:37 +03:00
|
|
|
if self.iscensored(rev):
|
|
|
|
# deltas based on a censored revision must replace the
|
|
|
|
# full content in one patch, so delta works everywhere
|
|
|
|
header = mdiff.replacediffheader(self.rawsize(rev), len(t))
|
|
|
|
delta = header + t
|
|
|
|
else:
|
revlog: use existing file handle when reading during _addrevision
_addrevision() may need to read from revlogs as part of computing
deltas. Previously, we would flush existing file handles and open
a new, short-lived file handle to perform the reading.
If we have an existing file handle, it seems logical to reuse it
for reading instead of opening a new file handle. This patch
makes that the new behavior.
After this patch, revlog files are only reopened when adding
revisions if the revlog is switched from inline to non-inline.
On Linux when unbundling a bundle of the mozilla-central repo, this
patch has the following impact on system call counts:
Call Before After Delta
write 827,639 673,390 -154,249
open 700,103 684,089 -16,014
read 74,489 74,489 0
fstat 493,924 461,896 -32,028
close 249,131 233,117 -16,014
stat 242,001 242,001 0
lstat 18,676 18,676 0
lseek 20,268 20,268 0
ioctl 14,652 13,173 -1,479
TOTAL 3,180,758 2,930,679 -250,079
It's worth noting that many of the open() calls fail due to missing
files. That's why there are many more open() calls than close().
Despite the significant system call reduction, this change does not
seem to have a significant performance impact on Linux.
On Windows 10 (not a VM, on a SSD), this patch appears to reduce
unbundle time for mozilla-central from ~960s to ~920s. This isn't
as significant as I was hoping. But a decrease it is nonetheless.
Still, Windows unbundle performance is still >2x slower than Linux.
Despite the lack of significant gains, fewer system calls is fewer
system calls. If nothing else, this will narrow the focus of potential
areas to optimize in the future.
2015-09-28 02:08:18 +03:00
|
|
|
if self._inline:
|
|
|
|
fh = ifh
|
|
|
|
else:
|
|
|
|
fh = dfh
|
2017-03-31 03:58:03 +03:00
|
|
|
ptext = self.revision(rev, _df=fh, raw=True)
|
2015-01-22 01:11:37 +03:00
|
|
|
delta = mdiff.textdiff(ptext, t)
|
2016-08-25 06:00:52 +03:00
|
|
|
header, data = self.compress(delta)
|
|
|
|
deltalen = len(header) + len(data)
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
chainbase = self.chainbase(rev)
|
2016-08-25 06:00:52 +03:00
|
|
|
dist = deltalen + offset - self.start(chainbase)
|
2011-05-08 23:32:33 +04:00
|
|
|
if self._generaldelta:
|
|
|
|
base = rev
|
|
|
|
else:
|
|
|
|
base = chainbase
|
2014-11-12 07:01:19 +03:00
|
|
|
chainlen, compresseddeltalen = self._chaininfo(rev)
|
|
|
|
chainlen += 1
|
2016-08-25 06:00:52 +03:00
|
|
|
compresseddeltalen += deltalen
|
|
|
|
return (dist, deltalen, (header, data), base,
|
|
|
|
chainbase, chainlen, compresseddeltalen)
|
2010-10-30 11:47:34 +04:00
|
|
|
|
2008-06-26 23:35:50 +04:00
|
|
|
curr = len(self)
|
2007-07-24 05:44:08 +04:00
|
|
|
prev = curr - 1
|
|
|
|
offset = self.end(prev)
|
2015-12-02 02:29:11 +03:00
|
|
|
delta = None
|
2010-10-30 11:47:34 +04:00
|
|
|
p1r, p2r = self.rev(p1), self.rev(p2)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2015-08-30 23:34:30 +03:00
|
|
|
# full versions are inserted when the needed deltas
|
|
|
|
# become comparable to the uncompressed text
|
2017-03-31 04:38:03 +03:00
|
|
|
if rawtext is None:
|
2015-08-30 23:34:30 +03:00
|
|
|
textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]),
|
|
|
|
cachedelta[1])
|
|
|
|
else:
|
2017-03-31 04:38:03 +03:00
|
|
|
textlen = len(rawtext)
|
2015-08-30 23:34:30 +03:00
|
|
|
|
2010-08-18 21:37:23 +04:00
|
|
|
# should we try to build a delta?
|
2016-10-14 03:25:08 +03:00
|
|
|
if prev != nullrev and self.storedeltachains:
|
2015-12-02 03:15:59 +03:00
|
|
|
tested = set()
|
2016-08-25 06:18:58 +03:00
|
|
|
# This condition is true most of the time when processing
|
|
|
|
# changegroup data into a generaldelta repo. The only time it
|
|
|
|
# isn't true is if this is the first revision in a delta chain
|
|
|
|
# or if ``format.generaldelta=true`` disabled ``lazydeltabase``.
|
2015-11-02 18:59:12 +03:00
|
|
|
if cachedelta and self._generaldelta and self._lazydeltabase:
|
|
|
|
# Assume what we received from the server is a good choice
|
|
|
|
# build delta will reuse the cache
|
2015-12-02 03:06:20 +03:00
|
|
|
candidatedelta = builddelta(cachedelta[0])
|
2015-12-05 03:45:06 +03:00
|
|
|
tested.add(cachedelta[0])
|
2015-12-02 03:06:20 +03:00
|
|
|
if self._isgooddelta(candidatedelta, textlen):
|
|
|
|
delta = candidatedelta
|
2015-12-02 03:15:59 +03:00
|
|
|
if delta is None and self._generaldelta:
|
|
|
|
# exclude already lazy tested base if any
|
revlog: don't consider nullrev when choosing delta base
In the most complex case, we try using the incoming delta base, then
we try both parents, and then we try the previous revlog entry. If
none of these result in a good delta, we natually use the null
revision as base. However, we sometimes consider the nullrev before we
have exhausted our other options. Specifically, when both parents are
null, we use the nullrev as delta base if it produces a good delta
(according to _isgooddelta()), and we fail to try the previous revlog
entry as delta base. After e60126c6093d (addrevision: use general
delta when the incoming base delta is bad, 2015-12-01), it can also
happen for non-merge commits when the incoming delta is not good.
The Firefox repo (from many months back) shrinks a tiny bit with this
patch: from 1.855GB to 1.830GB (1.4%). The hg repo itself shrinks even
less: by less than 0.1%. There may be repos that get larger instead.
This undoes the unexplained test change in e60126c6093d.
2015-12-05 04:46:56 +03:00
|
|
|
parents = [p for p in (p1r, p2r)
|
|
|
|
if p != nullrev and p not in tested]
|
2015-12-02 03:15:59 +03:00
|
|
|
if parents and not self._aggressivemergedeltas:
|
2015-08-31 00:03:32 +03:00
|
|
|
# Pick whichever parent is closer to us (to minimize the
|
2015-12-02 03:15:59 +03:00
|
|
|
# chance of having to build a fulltext).
|
2015-12-02 05:45:16 +03:00
|
|
|
parents = [max(parents)]
|
2015-12-02 03:15:59 +03:00
|
|
|
tested.update(parents)
|
2015-12-02 05:45:16 +03:00
|
|
|
pdeltas = []
|
|
|
|
for p in parents:
|
|
|
|
pd = builddelta(p)
|
|
|
|
if self._isgooddelta(pd, textlen):
|
|
|
|
pdeltas.append(pd)
|
|
|
|
if pdeltas:
|
|
|
|
delta = min(pdeltas, key=lambda x: x[1])
|
2015-12-02 03:15:59 +03:00
|
|
|
if delta is None and prev not in tested:
|
|
|
|
# other approach failed try against prev to hopefully save us a
|
|
|
|
# fulltext.
|
2015-12-05 04:14:14 +03:00
|
|
|
candidatedelta = builddelta(prev)
|
|
|
|
if self._isgooddelta(candidatedelta, textlen):
|
|
|
|
delta = candidatedelta
|
2015-12-02 03:22:49 +03:00
|
|
|
if delta is not None:
|
2015-12-02 02:29:11 +03:00
|
|
|
dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta
|
2015-12-05 04:14:14 +03:00
|
|
|
else:
|
2017-03-31 04:38:03 +03:00
|
|
|
rawtext = buildtext()
|
|
|
|
data = self.compress(rawtext)
|
2005-11-12 05:20:19 +03:00
|
|
|
l = len(data[1]) + len(data[0])
|
2011-05-12 15:47:17 +04:00
|
|
|
base = chainbase = curr
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2010-10-09 03:00:16 +04:00
|
|
|
e = (offset_type(offset, flags), l, textlen,
|
2010-10-30 11:47:34 +04:00
|
|
|
base, link, p1r, p2r, node)
|
2007-07-24 05:44:08 +04:00
|
|
|
self.index.insert(-1, e)
|
2007-07-24 05:44:08 +04:00
|
|
|
self.nodemap[node] = curr
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2007-09-26 08:58:45 +04:00
|
|
|
entry = self._io.packentry(e, self.node, self.version, curr)
|
2013-11-27 00:58:27 +04:00
|
|
|
self._writeentry(transaction, ifh, dfh, entry, data, link, offset)
|
|
|
|
|
2017-03-31 04:38:03 +03:00
|
|
|
if alwayscache and rawtext is None:
|
|
|
|
rawtext = buildtext()
|
2015-09-13 02:11:17 +03:00
|
|
|
|
2017-03-31 04:38:03 +03:00
|
|
|
if type(rawtext) == str: # only accept immutable objects
|
|
|
|
self._cache = (node, curr, rawtext)
|
revlog: use an LRU cache for delta chain bases
Profiling using statprof revealed a hotspot during changegroup
application calculating delta chain bases on generaldelta repos.
Essentially, revlog._addrevision() was performing a lot of redundant
work tracing the delta chain as part of determining when the chain
distance was acceptable. This was most pronounced when adding
revisions to manifests, which can have delta chains thousands of
revisions long.
There was a delta chain base cache on revlogs before, but it only
captured a single revision. This was acceptable before generaldelta,
when _addrevision would build deltas from the previous revision and
thus we'd pretty much guarantee a cache hit when resolving the delta
chain base on a subsequent _addrevision call. However, it isn't
suitable for generaldelta because parent revisions aren't necessarily
the last processed revision.
This patch converts the delta chain base cache to an LRU dict cache.
The cache can hold multiple entries, so generaldelta repos have a
higher chance of getting a cache hit.
The impact of this change when processing changegroup additions is
significant. On a generaldelta conversion of the "mozilla-unified"
repo (which contains heads of the main Firefox repositories in
chronological order - this means there are lots of transitions between
heads in revlog order), this change has the following impact when
performing an `hg unbundle` of an uncompressed bundle of the repo:
before: 5:42 CPU time
after: 4:34 CPU time
Most of this time is saved when applying the changelog and manifest
revlogs:
before: 2:30 CPU time
after: 1:17 CPU time
That nearly a 50% reduction in CPU time applying changesets and
manifests!
Applying a gzipped bundle of the same repo (effectively simulating a
`hg clone` over HTTP) showed a similar speedup:
before: 5:53 CPU time
after: 4:46 CPU time
Wall time improvements were basically the same as CPU time.
I didn't measure explicitly, but it feels like most of the time
is saved when processing manifests. This makes sense, as large
manifests tend to have very long delta chains and thus benefit the
most from this cache.
So, this change effectively makes changegroup application (which is
used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and
various other commands) significantly faster when delta chains are
long (which can happen on repos with large numbers of files and thus
large manifests).
In theory, this change can result in more memory utilization. However,
we're caching a dict of ints. At most we have 200 ints + Python object
overhead per revlog. And, the cache is really only populated when
performing read-heavy operations, such as adding changegroups or
scanning an individual revlog. For memory bloat to be an issue, we'd
need to scan/read several revisions from several revlogs all while
having active references to several revlogs. I don't think there are
many operations that do this, so I don't think memory bloat from the
cache will be an issue.
2016-08-23 07:48:50 +03:00
|
|
|
self._chainbasecache[curr] = chainbase
|
2013-11-27 00:58:27 +04:00
|
|
|
return node
|
|
|
|
|
|
|
|
def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset):
|
2015-12-18 04:16:02 +03:00
|
|
|
# Files opened in a+ mode have inconsistent behavior on various
|
|
|
|
# platforms. Windows requires that a file positioning call be made
|
|
|
|
# when the file handle transitions between reads and writes. See
|
|
|
|
# 3686fa2b8eee and the mixedfilemodewrapper in windows.py. On other
|
|
|
|
# platforms, Python or the platform itself can be buggy. Some versions
|
|
|
|
# of Solaris have been observed to not append at the end of the file
|
|
|
|
# if the file was seeked to before the end. See issue4943 for more.
|
|
|
|
#
|
|
|
|
# We work around this issue by inserting a seek() before writing.
|
|
|
|
# Note: This is likely not necessary on Python 3.
|
|
|
|
ifh.seek(0, os.SEEK_END)
|
2015-12-18 23:40:11 +03:00
|
|
|
if dfh:
|
2015-12-18 04:16:02 +03:00
|
|
|
dfh.seek(0, os.SEEK_END)
|
|
|
|
|
2013-11-27 00:58:27 +04:00
|
|
|
curr = len(self) - 1
|
2007-07-24 05:44:08 +04:00
|
|
|
if not self._inline:
|
2006-04-05 00:38:43 +04:00
|
|
|
transaction.add(self.datafile, offset)
|
2007-07-24 05:44:08 +04:00
|
|
|
transaction.add(self.indexfile, curr * len(entry))
|
2006-04-05 00:38:43 +04:00
|
|
|
if data[0]:
|
2006-10-15 01:47:48 +04:00
|
|
|
dfh.write(data[0])
|
|
|
|
dfh.write(data[1])
|
2007-07-24 05:44:08 +04:00
|
|
|
ifh.write(entry)
|
2006-04-05 00:38:43 +04:00
|
|
|
else:
|
2007-07-24 05:44:08 +04:00
|
|
|
offset += curr * self._io.size
|
2007-09-23 20:24:19 +04:00
|
|
|
transaction.add(self.indexfile, offset, curr)
|
2007-07-24 05:44:08 +04:00
|
|
|
ifh.write(entry)
|
2006-10-15 01:47:48 +04:00
|
|
|
ifh.write(data[0])
|
|
|
|
ifh.write(data[1])
|
|
|
|
self.checkinlinesize(transaction, ifh)
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2017-09-20 19:22:22 +03:00
|
|
|
def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None):
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
|
|
|
add a delta group
|
|
|
|
|
|
|
|
given a set of deltas, add them to the revision log. the
|
|
|
|
first delta is against its parent, which should be in our
|
|
|
|
log, the rest are against the previous delta.
|
2015-07-18 20:29:37 +03:00
|
|
|
|
|
|
|
If ``addrevisioncb`` is defined, it will be called with arguments of
|
|
|
|
this revlog and the node that was added.
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2017-06-15 23:42:35 +03:00
|
|
|
nodes = []
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2010-10-09 03:00:19 +04:00
|
|
|
r = len(self)
|
|
|
|
end = 0
|
2005-05-10 12:40:49 +04:00
|
|
|
if r:
|
2010-10-09 03:00:19 +04:00
|
|
|
end = self.end(r - 1)
|
2016-09-22 15:51:58 +03:00
|
|
|
ifh = self.opener(self.indexfile, "a+", checkambig=self._checkambig)
|
2007-07-24 05:44:08 +04:00
|
|
|
isize = r * self._io.size
|
2007-07-24 05:44:08 +04:00
|
|
|
if self._inline:
|
2007-07-24 05:44:08 +04:00
|
|
|
transaction.add(self.indexfile, end + isize, r)
|
2006-04-05 00:38:43 +04:00
|
|
|
dfh = None
|
|
|
|
else:
|
2007-07-24 05:44:08 +04:00
|
|
|
transaction.add(self.indexfile, isize, r)
|
2006-04-05 00:38:43 +04:00
|
|
|
transaction.add(self.datafile, end)
|
2015-09-28 01:59:19 +03:00
|
|
|
dfh = self.opener(self.datafile, "a+")
|
2015-01-14 23:16:08 +03:00
|
|
|
def flush():
|
|
|
|
if dfh:
|
|
|
|
dfh.flush()
|
|
|
|
ifh.flush()
|
2008-03-15 00:12:50 +03:00
|
|
|
try:
|
|
|
|
# loop through our set of deltas
|
2017-09-13 20:43:44 +03:00
|
|
|
for data in deltas:
|
2017-09-20 19:22:22 +03:00
|
|
|
node, p1, p2, linknode, deltabase, delta, flags = data
|
|
|
|
link = linkmapper(linknode)
|
2017-09-13 20:43:44 +03:00
|
|
|
flags = flags or REVIDX_DEFAULT_FLAGS
|
2010-09-19 22:12:45 +04:00
|
|
|
|
2017-06-15 23:42:35 +03:00
|
|
|
nodes.append(node)
|
2012-01-13 04:29:03 +04:00
|
|
|
|
2011-05-05 14:46:02 +04:00
|
|
|
if node in self.nodemap:
|
2008-03-15 00:12:50 +03:00
|
|
|
# this can happen if two branches make the same change
|
|
|
|
continue
|
|
|
|
|
|
|
|
for p in (p1, p2):
|
2012-05-12 18:00:57 +04:00
|
|
|
if p not in self.nodemap:
|
2011-05-05 14:46:02 +04:00
|
|
|
raise LookupError(p, self.indexfile,
|
|
|
|
_('unknown parent'))
|
2008-03-15 00:12:50 +03:00
|
|
|
|
2011-04-30 12:00:41 +04:00
|
|
|
if deltabase not in self.nodemap:
|
|
|
|
raise LookupError(deltabase, self.indexfile,
|
|
|
|
_('unknown delta base'))
|
2008-03-15 00:12:50 +03:00
|
|
|
|
2011-04-30 12:00:41 +04:00
|
|
|
baserev = self.rev(deltabase)
|
2015-02-06 03:55:29 +03:00
|
|
|
|
|
|
|
if baserev != nullrev and self.iscensored(baserev):
|
|
|
|
# if base is censored, delta must be full replacement in a
|
|
|
|
# single patch operation
|
|
|
|
hlen = struct.calcsize(">lll")
|
|
|
|
oldlen = self.rawsize(baserev)
|
|
|
|
newlen = len(delta) - hlen
|
|
|
|
if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen):
|
|
|
|
raise error.CensoredBaseError(self.indexfile,
|
|
|
|
self.node(baserev))
|
|
|
|
|
2015-12-14 23:55:12 +03:00
|
|
|
if not flags and self._peek_iscensored(baserev, delta, flush):
|
2015-01-14 23:16:08 +03:00
|
|
|
flags |= REVIDX_ISCENSORED
|
|
|
|
|
2015-09-13 02:11:17 +03:00
|
|
|
# We assume consumers of addrevisioncb will want to retrieve
|
|
|
|
# the added revision, which will require a call to
|
|
|
|
# revision(). revision() will fast path if there is a cache
|
|
|
|
# hit. So, we tell _addrevision() to always cache in this case.
|
2017-01-05 20:16:07 +03:00
|
|
|
# We're only using addgroup() in the context of changegroup
|
|
|
|
# generation so the revision data can always be handled as raw
|
|
|
|
# by the flagprocessor.
|
2017-09-13 20:43:16 +03:00
|
|
|
self._addrevision(node, None, transaction, link,
|
|
|
|
p1, p2, flags, (baserev, delta),
|
|
|
|
ifh, dfh,
|
|
|
|
alwayscache=bool(addrevisioncb))
|
2015-07-18 20:29:37 +03:00
|
|
|
|
|
|
|
if addrevisioncb:
|
2017-09-13 20:43:16 +03:00
|
|
|
addrevisioncb(self, node)
|
2015-07-18 20:29:37 +03:00
|
|
|
|
2010-10-09 03:00:19 +04:00
|
|
|
if not dfh and not self._inline:
|
|
|
|
# addrevision switched from inline to conventional
|
|
|
|
# reopen the index
|
2010-12-24 17:23:01 +03:00
|
|
|
ifh.close()
|
2015-09-28 01:59:19 +03:00
|
|
|
dfh = self.opener(self.datafile, "a+")
|
2016-09-22 15:51:58 +03:00
|
|
|
ifh = self.opener(self.indexfile, "a+",
|
|
|
|
checkambig=self._checkambig)
|
2008-03-15 00:12:50 +03:00
|
|
|
finally:
|
|
|
|
if dfh:
|
|
|
|
dfh.close()
|
|
|
|
ifh.close()
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2017-06-15 23:42:35 +03:00
|
|
|
return nodes
|
2005-11-03 06:26:23 +03:00
|
|
|
|
2015-01-24 01:01:39 +03:00
|
|
|
def iscensored(self, rev):
|
|
|
|
"""Check if a file revision is censored."""
|
|
|
|
return False
|
|
|
|
|
2015-01-14 23:16:08 +03:00
|
|
|
def _peek_iscensored(self, baserev, delta, flush):
|
|
|
|
"""Quickly check if a delta produces a censored revision."""
|
|
|
|
return False
|
|
|
|
|
2013-11-12 04:42:49 +04:00
|
|
|
def getstrippoint(self, minlink):
|
|
|
|
"""find the minimum rev that must be stripped to strip the linkrev
|
|
|
|
|
|
|
|
Returns a tuple containing the minimum rev and a set of all revs that
|
|
|
|
have linkrevs that will be broken by this strip.
|
|
|
|
"""
|
|
|
|
brokenrevs = set()
|
|
|
|
strippoint = len(self)
|
|
|
|
|
|
|
|
heads = {}
|
|
|
|
futurelargelinkrevs = set()
|
|
|
|
for head in self.headrevs():
|
|
|
|
headlinkrev = self.linkrev(head)
|
|
|
|
heads[head] = headlinkrev
|
|
|
|
if headlinkrev >= minlink:
|
|
|
|
futurelargelinkrevs.add(headlinkrev)
|
|
|
|
|
|
|
|
# This algorithm involves walking down the rev graph, starting at the
|
|
|
|
# heads. Since the revs are topologically sorted according to linkrev,
|
|
|
|
# once all head linkrevs are below the minlink, we know there are
|
|
|
|
# no more revs that could have a linkrev greater than minlink.
|
|
|
|
# So we can stop walking.
|
|
|
|
while futurelargelinkrevs:
|
|
|
|
strippoint -= 1
|
|
|
|
linkrev = heads.pop(strippoint)
|
|
|
|
|
|
|
|
if linkrev < minlink:
|
|
|
|
brokenrevs.add(strippoint)
|
|
|
|
else:
|
|
|
|
futurelargelinkrevs.remove(linkrev)
|
|
|
|
|
|
|
|
for p in self.parentrevs(strippoint):
|
|
|
|
if p != nullrev:
|
|
|
|
plinkrev = self.linkrev(p)
|
|
|
|
heads[p] = plinkrev
|
|
|
|
if plinkrev >= minlink:
|
|
|
|
futurelargelinkrevs.add(plinkrev)
|
|
|
|
|
|
|
|
return strippoint, brokenrevs
|
|
|
|
|
2009-04-16 17:34:03 +04:00
|
|
|
def strip(self, minlink, transaction):
|
2008-01-19 23:01:16 +03:00
|
|
|
"""truncate the revlog on the first revision with a linkrev >= minlink
|
|
|
|
|
|
|
|
This function is called when we're stripping revision minlink and
|
|
|
|
its descendants from the repository.
|
|
|
|
|
|
|
|
We have to remove all revisions with linkrev >= minlink, because
|
|
|
|
the equivalent changelog revisions will be renumbered after the
|
|
|
|
strip.
|
|
|
|
|
|
|
|
So we truncate the revlog on the first of these revisions, and
|
|
|
|
trust that the caller has saved the revisions that shouldn't be
|
2012-01-10 18:35:25 +04:00
|
|
|
removed and that it'll re-add them after this truncation.
|
2008-01-19 23:01:16 +03:00
|
|
|
"""
|
2008-06-26 23:35:50 +04:00
|
|
|
if len(self) == 0:
|
2005-11-12 05:20:24 +03:00
|
|
|
return
|
|
|
|
|
2013-11-12 04:42:49 +04:00
|
|
|
rev, _ = self.getstrippoint(minlink)
|
|
|
|
if rev == len(self):
|
2008-01-19 23:01:16 +03:00
|
|
|
return
|
2005-11-12 05:20:24 +03:00
|
|
|
|
|
|
|
# first truncate the files on disk
|
|
|
|
end = self.start(rev)
|
2007-07-24 05:44:08 +04:00
|
|
|
if not self._inline:
|
2009-04-16 17:34:03 +04:00
|
|
|
transaction.add(self.datafile, end)
|
2007-07-24 05:44:08 +04:00
|
|
|
end = rev * self._io.size
|
2006-04-05 00:38:43 +04:00
|
|
|
else:
|
2007-07-24 05:44:08 +04:00
|
|
|
end += rev * self._io.size
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2009-04-16 17:34:03 +04:00
|
|
|
transaction.add(self.indexfile, end)
|
2005-11-12 05:20:24 +03:00
|
|
|
|
|
|
|
# then reset internal state in memory to forget those revisions
|
2007-07-24 05:44:08 +04:00
|
|
|
self._cache = None
|
2014-11-14 08:36:38 +03:00
|
|
|
self._chaininfocache = {}
|
2009-05-28 01:01:34 +04:00
|
|
|
self._chunkclear()
|
2008-06-26 23:35:50 +04:00
|
|
|
for x in xrange(rev, len(self)):
|
2006-04-05 00:38:43 +04:00
|
|
|
del self.nodemap[self.node(x)]
|
2005-11-12 05:20:24 +03:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
del self.index[rev:-1]
|
2005-11-12 05:20:24 +03:00
|
|
|
|
2005-11-03 06:26:23 +03:00
|
|
|
def checksize(self):
|
|
|
|
expected = 0
|
2008-06-26 23:35:50 +04:00
|
|
|
if len(self):
|
|
|
|
expected = max(0, self.end(len(self) - 1))
|
2006-01-30 09:34:35 +03:00
|
|
|
|
2005-11-03 07:09:19 +03:00
|
|
|
try:
|
|
|
|
f = self.opener(self.datafile)
|
|
|
|
f.seek(0, 2)
|
|
|
|
actual = f.tell()
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2006-01-30 09:34:35 +03:00
|
|
|
dd = actual - expected
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2006-01-30 09:34:35 +03:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
dd = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
f = self.opener(self.indexfile)
|
|
|
|
f.seek(0, 2)
|
|
|
|
actual = f.tell()
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2007-07-24 05:44:08 +04:00
|
|
|
s = self._io.size
|
2009-07-05 13:00:44 +04:00
|
|
|
i = max(0, actual // s)
|
2006-01-30 09:34:35 +03:00
|
|
|
di = actual - (i * s)
|
2007-07-24 05:44:08 +04:00
|
|
|
if self._inline:
|
2006-04-05 00:38:43 +04:00
|
|
|
databytes = 0
|
2008-06-26 23:35:50 +04:00
|
|
|
for r in self:
|
2007-09-22 02:14:39 +04:00
|
|
|
databytes += max(0, self.length(r))
|
2006-04-05 00:38:43 +04:00
|
|
|
dd = 0
|
2008-06-26 23:35:50 +04:00
|
|
|
di = actual - len(self) * s - databytes
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2006-01-30 09:34:35 +03:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
di = 0
|
|
|
|
|
|
|
|
return (dd, di)
|
2008-08-14 05:18:41 +04:00
|
|
|
|
|
|
|
def files(self):
|
2010-01-25 09:05:27 +03:00
|
|
|
res = [self.indexfile]
|
2008-08-14 05:18:41 +04:00
|
|
|
if not self._inline:
|
|
|
|
res.append(self.datafile)
|
|
|
|
return res
|
2016-12-19 04:02:57 +03:00
|
|
|
|
|
|
|
DELTAREUSEALWAYS = 'always'
|
|
|
|
DELTAREUSESAMEREVS = 'samerevs'
|
|
|
|
DELTAREUSENEVER = 'never'
|
|
|
|
|
2017-02-11 03:56:29 +03:00
|
|
|
DELTAREUSEALL = {'always', 'samerevs', 'never'}
|
2016-12-19 04:02:57 +03:00
|
|
|
|
|
|
|
def clone(self, tr, destrevlog, addrevisioncb=None,
|
|
|
|
deltareuse=DELTAREUSESAMEREVS, aggressivemergedeltas=None):
|
|
|
|
"""Copy this revlog to another, possibly with format changes.
|
|
|
|
|
|
|
|
The destination revlog will contain the same revisions and nodes.
|
|
|
|
However, it may not be bit-for-bit identical due to e.g. delta encoding
|
|
|
|
differences.
|
|
|
|
|
|
|
|
The ``deltareuse`` argument control how deltas from the existing revlog
|
|
|
|
are preserved in the destination revlog. The argument can have the
|
|
|
|
following values:
|
|
|
|
|
|
|
|
DELTAREUSEALWAYS
|
|
|
|
Deltas will always be reused (if possible), even if the destination
|
|
|
|
revlog would not select the same revisions for the delta. This is the
|
|
|
|
fastest mode of operation.
|
|
|
|
DELTAREUSESAMEREVS
|
|
|
|
Deltas will be reused if the destination revlog would pick the same
|
|
|
|
revisions for the delta. This mode strikes a balance between speed
|
|
|
|
and optimization.
|
|
|
|
DELTAREUSENEVER
|
|
|
|
Deltas will never be reused. This is the slowest mode of execution.
|
|
|
|
This mode can be used to recompute deltas (e.g. if the diff/delta
|
|
|
|
algorithm changes).
|
|
|
|
|
|
|
|
Delta computation can be slow, so the choice of delta reuse policy can
|
|
|
|
significantly affect run time.
|
|
|
|
|
|
|
|
The default policy (``DELTAREUSESAMEREVS``) strikes a balance between
|
|
|
|
two extremes. Deltas will be reused if they are appropriate. But if the
|
|
|
|
delta could choose a better revision, it will do so. This means if you
|
|
|
|
are converting a non-generaldelta revlog to a generaldelta revlog,
|
|
|
|
deltas will be recomputed if the delta's parent isn't a parent of the
|
|
|
|
revision.
|
|
|
|
|
|
|
|
In addition to the delta policy, the ``aggressivemergedeltas`` argument
|
|
|
|
controls whether to compute deltas against both parents for merges.
|
|
|
|
By default, the current default is used.
|
|
|
|
"""
|
|
|
|
if deltareuse not in self.DELTAREUSEALL:
|
|
|
|
raise ValueError(_('value for deltareuse invalid: %s') % deltareuse)
|
|
|
|
|
|
|
|
if len(destrevlog):
|
|
|
|
raise ValueError(_('destination revlog is not empty'))
|
|
|
|
|
|
|
|
if getattr(self, 'filteredrevs', None):
|
|
|
|
raise ValueError(_('source revlog has filtered revisions'))
|
|
|
|
if getattr(destrevlog, 'filteredrevs', None):
|
|
|
|
raise ValueError(_('destination revlog has filtered revisions'))
|
|
|
|
|
|
|
|
# lazydeltabase controls whether to reuse a cached delta, if possible.
|
|
|
|
oldlazydeltabase = destrevlog._lazydeltabase
|
|
|
|
oldamd = destrevlog._aggressivemergedeltas
|
|
|
|
|
|
|
|
try:
|
|
|
|
if deltareuse == self.DELTAREUSEALWAYS:
|
|
|
|
destrevlog._lazydeltabase = True
|
|
|
|
elif deltareuse == self.DELTAREUSESAMEREVS:
|
|
|
|
destrevlog._lazydeltabase = False
|
|
|
|
|
|
|
|
destrevlog._aggressivemergedeltas = aggressivemergedeltas or oldamd
|
|
|
|
|
|
|
|
populatecachedelta = deltareuse in (self.DELTAREUSEALWAYS,
|
|
|
|
self.DELTAREUSESAMEREVS)
|
|
|
|
|
|
|
|
index = self.index
|
|
|
|
for rev in self:
|
|
|
|
entry = index[rev]
|
|
|
|
|
|
|
|
# Some classes override linkrev to take filtered revs into
|
|
|
|
# account. Use raw entry from index.
|
|
|
|
flags = entry[0] & 0xffff
|
|
|
|
linkrev = entry[4]
|
|
|
|
p1 = index[entry[5]][7]
|
|
|
|
p2 = index[entry[6]][7]
|
|
|
|
node = entry[7]
|
|
|
|
|
|
|
|
# (Possibly) reuse the delta from the revlog if allowed and
|
|
|
|
# the revlog chunk is a delta.
|
|
|
|
cachedelta = None
|
2017-03-31 04:24:23 +03:00
|
|
|
rawtext = None
|
2016-12-19 04:02:57 +03:00
|
|
|
if populatecachedelta:
|
|
|
|
dp = self.deltaparent(rev)
|
|
|
|
if dp != nullrev:
|
|
|
|
cachedelta = (dp, str(self._chunk(rev)))
|
|
|
|
|
|
|
|
if not cachedelta:
|
2017-03-31 04:24:23 +03:00
|
|
|
rawtext = self.revision(rev, raw=True)
|
2016-12-19 04:02:57 +03:00
|
|
|
|
|
|
|
ifh = destrevlog.opener(destrevlog.indexfile, 'a+',
|
|
|
|
checkambig=False)
|
|
|
|
dfh = None
|
|
|
|
if not destrevlog._inline:
|
|
|
|
dfh = destrevlog.opener(destrevlog.datafile, 'a+')
|
|
|
|
try:
|
2017-03-31 04:24:23 +03:00
|
|
|
destrevlog._addrevision(node, rawtext, tr, linkrev, p1, p2,
|
2016-12-19 04:02:57 +03:00
|
|
|
flags, cachedelta, ifh, dfh)
|
|
|
|
finally:
|
|
|
|
if dfh:
|
|
|
|
dfh.close()
|
|
|
|
ifh.close()
|
|
|
|
|
|
|
|
if addrevisioncb:
|
|
|
|
addrevisioncb(self, rev, node)
|
|
|
|
finally:
|
|
|
|
destrevlog._lazydeltabase = oldlazydeltabase
|
|
|
|
destrevlog._aggressivemergedeltas = oldamd
|