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.
|
|
|
|
"""
|
|
|
|
|
2009-03-23 15:12:07 +03:00
|
|
|
# import stuff from node for others to import from revlog
|
2011-05-22 00:01:28 +04:00
|
|
|
from node import bin, hex, nullid, nullrev
|
2006-12-15 05:25:19 +03:00
|
|
|
from i18n import _
|
revlog: linearize created changegroups in generaldelta revlogs
This greatly improves the speed of the bundling process, and often reduces the
bundle size considerably. (Although if the repository is already ordered, this
has little effect on both time and bundle size.)
For non-generaldelta clients, the reduced bundle size translates to a reduced
repository size, similar to shrinking the revlogs (which uses the exact same
algorithm). For generaldelta clients the difference is minor.
When the new bundle format comes, reordering will not be necessary since we
can then store the deltaparent relationsships directly. The eventual default
behavior for clients and servers is presented in the table below, where "new"
implies support for GD as well as the new bundle format:
old client new client
old server old bundle, no reorder old bundle, no reorder
new server, non-GD old bundle, no reorder[1] old bundle, no reorder[2]
new server, GD old bundle, reorder[3] new bundle, no reorder[4]
[1] reordering is expensive on the server in this case, skip it
[2] client can choose to do its own redelta here
[3] reordering is needed because otherwise the pull does a lot of extra
work on the server
[4] reordering isn't needed because client can get deltabase in bundle
format
Currently, the default is to reorder on GD-servers, and not otherwise. A new
setting, bundle.reorder, has been added to override the default reordering
behavior. It can be set to either 'auto' (the default), or any true or false
value as a standard boolean setting, to either force the reordering on or off
regardless of generaldelta.
Some timing data from a relatively branch test repository follows. All
bundling is done with --all --type none options.
Non-generaldelta, non-shrunk repo:
-----------------------------------
Size: 276M
Without reorder (default):
Bundle time: 14.4 seconds
Bundle size: 939M
With reorder:
Bundle time: 1 minute, 29.3 seconds
Bundle size: 381M
Generaldelta, non-shrunk repo:
-----------------------------------
Size: 87M
Without reorder:
Bundle time: 2 minutes, 1.4 seconds
Bundle size: 939M
With reorder (default):
Bundle time: 25.5 seconds
Bundle size: 381M
2011-05-19 01:26:26 +04:00
|
|
|
import ancestor, mdiff, parsers, error, util, dagutil
|
2009-04-28 19:40:46 +04:00
|
|
|
import struct, zlib, errno
|
2005-05-08 04:11:36 +04:00
|
|
|
|
2007-07-26 21:02:58 +04:00
|
|
|
_pack = struct.pack
|
|
|
|
_unpack = struct.unpack
|
|
|
|
_compress = zlib.compress
|
|
|
|
_decompress = zlib.decompress
|
2008-04-05 00:36:40 +04:00
|
|
|
_sha = util.sha1
|
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
|
|
|
|
REVLOGNG = 1
|
2006-04-05 00:38:43 +04:00
|
|
|
REVLOGNGINLINEDATA = (1 << 16)
|
2011-05-08 00:40:17 +04:00
|
|
|
REVLOGGENERALDELTA = (1 << 17)
|
2006-05-08 23:26:18 +04:00
|
|
|
REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
|
|
|
|
REVLOG_DEFAULT_FORMAT = REVLOGNG
|
|
|
|
REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
|
2011-05-08 00:40:17 +04:00
|
|
|
REVLOGNG_FLAGS = REVLOGNGINLINEDATA | REVLOGGENERALDELTA
|
2010-08-03 18:08:19 +04:00
|
|
|
|
|
|
|
# revlog index flags
|
2011-05-05 14:46:02 +04:00
|
|
|
REVIDX_KNOWN_FLAGS = 0
|
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
|
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):
|
|
|
|
return long(long(offset) << 16 | type)
|
|
|
|
|
2009-03-23 17:32:29 +03:00
|
|
|
nullhash = _sha(nullid)
|
|
|
|
|
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
|
|
|
|
s = nullhash.copy()
|
|
|
|
s.update(p1)
|
|
|
|
else:
|
|
|
|
# none of the parent nodes are nullid
|
|
|
|
l = [p1, p2]
|
|
|
|
l.sort()
|
|
|
|
s = _sha(l[0])
|
|
|
|
s.update(l[1])
|
2005-08-28 01:43:20 +04:00
|
|
|
s.update(text)
|
|
|
|
return s.digest()
|
|
|
|
|
2005-05-04 01:16:10 +04:00
|
|
|
def compress(text):
|
2005-08-27 12:43:48 +04:00
|
|
|
""" generate a possibly-compressed representation of text """
|
2007-07-24 05:44:08 +04:00
|
|
|
if not text:
|
|
|
|
return ("", text)
|
2007-10-11 09:46:54 +04:00
|
|
|
l = len(text)
|
2007-10-11 14:16:55 +04:00
|
|
|
bin = None
|
2007-10-11 09:46:54 +04:00
|
|
|
if l < 44:
|
2007-10-11 14:16:55 +04:00
|
|
|
pass
|
2007-10-11 09:46:54 +04:00
|
|
|
elif l > 1000000:
|
|
|
|
# zlib makes an internal copy, thus doubling memory usage for
|
|
|
|
# large files, so lets do this in pieces
|
|
|
|
z = zlib.compressobj()
|
|
|
|
p = []
|
|
|
|
pos = 0
|
|
|
|
while pos < l:
|
|
|
|
pos2 = pos + 2**20
|
|
|
|
p.append(z.compress(text[pos:pos2]))
|
|
|
|
pos = pos2
|
|
|
|
p.append(z.flush())
|
|
|
|
if sum(map(len, p)) < l:
|
|
|
|
bin = "".join(p)
|
|
|
|
else:
|
|
|
|
bin = _compress(text)
|
2007-10-11 14:16:55 +04:00
|
|
|
if bin is None or len(bin) > l:
|
2007-07-24 05:44:08 +04:00
|
|
|
if text[0] == '\0':
|
|
|
|
return ("", text)
|
2005-11-12 05:20:19 +03:00
|
|
|
return ('u', text)
|
|
|
|
return ("", bin)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
|
|
|
def decompress(bin):
|
2005-08-27 12:43:48 +04:00
|
|
|
""" decompress the given input """
|
2007-07-24 05:44:08 +04:00
|
|
|
if not bin:
|
|
|
|
return bin
|
2005-05-21 05:31:12 +04:00
|
|
|
t = bin[0]
|
2007-07-24 05:44:08 +04:00
|
|
|
if t == '\0':
|
|
|
|
return bin
|
|
|
|
if t == 'x':
|
2007-07-26 21:02:58 +04:00
|
|
|
return _decompress(bin)
|
2007-07-24 05:44:08 +04:00
|
|
|
if t == 'u':
|
|
|
|
return bin[1:]
|
2006-03-08 02:27:23 +03:00
|
|
|
raise RevlogError(_("unknown compression type %r") % t)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
indexformatv0 = ">4l20s20s20s"
|
|
|
|
v0shaoffset = 56
|
2007-07-22 01:18:21 +04:00
|
|
|
|
2007-07-24 05:44:07 +04:00
|
|
|
class revlogoldio(object):
|
|
|
|
def __init__(self):
|
2007-07-24 05:44:08 +04:00
|
|
|
self.size = struct.calcsize(indexformatv0)
|
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 = []
|
|
|
|
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
|
2007-07-26 21:02:58 +04:00
|
|
|
e = _unpack(indexformatv0, 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]):
|
|
|
|
raise RevlogError(_("index entry flags need RevlogNG"))
|
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])
|
2007-07-26 21:02:58 +04:00
|
|
|
return _pack(indexformatv0, *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
|
|
|
|
indexformatng = ">Qiiiiii20s12x"
|
|
|
|
ngshaoffset = 32
|
|
|
|
versionformat = ">I"
|
|
|
|
|
2007-07-24 05:44:07 +04:00
|
|
|
class revlogio(object):
|
|
|
|
def __init__(self):
|
2007-07-24 05:44:08 +04:00
|
|
|
self.size = struct.calcsize(indexformatng)
|
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):
|
2007-07-26 21:02:58 +04:00
|
|
|
p = _pack(indexformatng, *entry)
|
2007-09-26 08:58:45 +04:00
|
|
|
if rev == 0:
|
2007-07-26 21:02:58 +04:00
|
|
|
p = _pack(versionformat, 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.
|
|
|
|
"""
|
2011-05-08 00:37:40 +04:00
|
|
|
def __init__(self, opener, indexfile):
|
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
|
2007-03-23 03:12:03 +03:00
|
|
|
self.datafile = indexfile[:-2] + ".d"
|
2005-05-04 01:16:10 +04:00
|
|
|
self.opener = opener
|
2007-07-24 05:44:08 +04:00
|
|
|
self._cache = None
|
2011-05-12 15:47:17 +04:00
|
|
|
self._basecache = (0, 0)
|
2009-05-08 04:39:45 +04:00
|
|
|
self._chunkcache = (0, '')
|
2007-07-24 05:44:08 +04:00
|
|
|
self.index = []
|
2011-01-12 02:12:32 +03:00
|
|
|
self._pcache = {}
|
2011-01-19 00:55:46 +03:00
|
|
|
self._nodecache = {nullid: nullrev}
|
|
|
|
self._nodepos = 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:
|
|
|
|
if 'revlogv1' in opts:
|
|
|
|
if 'generaldelta' in opts:
|
2011-05-16 14:44:34 +04:00
|
|
|
v |= REVLOGGENERALDELTA
|
|
|
|
else:
|
|
|
|
v = 0
|
2010-08-10 20:55:08 +04:00
|
|
|
|
2009-05-08 04:39:45 +04:00
|
|
|
i = ''
|
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)
|
2011-01-04 23:12:52 +03:00
|
|
|
i = f.read()
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2007-07-22 01:18:21 +04:00
|
|
|
if len(i) > 0:
|
2009-05-08 04:39:45 +04:00
|
|
|
v = struct.unpack(versionformat, i[:4])[0]
|
2011-05-16 15:06:48 +04:00
|
|
|
self._initempty = False
|
2005-09-23 10:31:44 +04:00
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
2007-07-24 05:44:08 +04:00
|
|
|
|
|
|
|
self.version = v
|
|
|
|
self._inline = v & REVLOGNGINLINEDATA
|
2011-05-08 00:40:17 +04:00
|
|
|
self._generaldelta = v & REVLOGGENERALDELTA
|
2006-04-05 00:38:43 +04:00
|
|
|
flags = v & ~0xFFFF
|
|
|
|
fmt = v & 0xFFFF
|
2007-07-24 05:44:08 +04:00
|
|
|
if fmt == REVLOGV0 and flags:
|
|
|
|
raise RevlogError(_("index %s unknown flags %#04x for format v0")
|
|
|
|
% (self.indexfile, flags >> 16))
|
2010-08-03 18:08:19 +04:00
|
|
|
elif fmt == REVLOGNG and flags & ~REVLOGNG_FLAGS:
|
2007-07-24 05:44:08 +04:00
|
|
|
raise RevlogError(_("index %s unknown flags %#04x for revlogng")
|
|
|
|
% (self.indexfile, flags >> 16))
|
|
|
|
elif fmt > REVLOGNG:
|
2006-12-01 11:24:56 +03:00
|
|
|
raise RevlogError(_("index %s unknown format %d")
|
2006-11-19 18:09:04 +03:00
|
|
|
% (self.indexfile, fmt))
|
2007-07-24 05:44:08 +04: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:
|
|
|
|
d = self._io.parseindex(i, self._inline)
|
|
|
|
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()
|
2006-04-05 00:38:43 +04:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
def tip(self):
|
|
|
|
return self.node(len(self.index) - 2)
|
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):
|
|
|
|
for i in xrange(len(self)):
|
|
|
|
yield i
|
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):
|
|
|
|
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]
|
2012-04-13 01:05:59 +04:00
|
|
|
except RevlogError:
|
|
|
|
# parsers.c radix tree lookup failed
|
|
|
|
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
|
2008-03-12 01:42:29 +03:00
|
|
|
raise LookupError(node, self.indexfile, _('no node'))
|
2011-01-12 06:52:03 +03:00
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
def node(self, rev):
|
|
|
|
return self.index[rev][7]
|
2008-11-13 00:19:14 +03:00
|
|
|
def linkrev(self, rev):
|
|
|
|
return self.index[rev][4]
|
2005-05-04 06:35:03 +04:00
|
|
|
def parents(self, node):
|
2008-11-13 00:58:46 +03:00
|
|
|
i = self.index
|
|
|
|
d = i[self.rev(node)]
|
|
|
|
return i[d[5]][7], i[d[6]][7] # map revisions to nodes inline
|
2006-06-20 21:57:30 +04:00
|
|
|
def parentrevs(self, rev):
|
2007-07-24 05:44:08 +04:00
|
|
|
return self.index[rev][5:7]
|
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)
|
2007-07-24 05:44:08 +04:00
|
|
|
def end(self, rev):
|
|
|
|
return self.start(rev) + self.length(rev)
|
|
|
|
def length(self, rev):
|
|
|
|
return self.index[rev][1]
|
2011-05-08 00:40:14 +04:00
|
|
|
def chainbase(self, rev):
|
|
|
|
index = self.index
|
|
|
|
base = index[rev][3]
|
|
|
|
while base != rev:
|
|
|
|
rev = base
|
|
|
|
base = index[rev][3]
|
|
|
|
return base
|
2010-07-26 23:46:38 +04:00
|
|
|
def flags(self, rev):
|
|
|
|
return self.index[rev][0] & 0xFFFF
|
2010-08-23 15:24:19 +04:00
|
|
|
def rawsize(self, rev):
|
2006-04-05 00:38:44 +04:00
|
|
|
"""return the length of the uncompressed text for a given revision"""
|
2007-07-24 05:44:08 +04:00
|
|
|
l = self.index[rev][2]
|
2006-04-05 00:38:44 +04:00
|
|
|
if l >= 0:
|
|
|
|
return l
|
|
|
|
|
|
|
|
t = self.revision(self.node(rev))
|
|
|
|
return len(t)
|
2010-08-23 15:24:19 +04:00
|
|
|
size = rawsize
|
2006-04-05 00:38:44 +04:00
|
|
|
|
2006-11-13 22:26:57 +03:00
|
|
|
def reachable(self, node, stop=None):
|
2009-05-17 05:49:59 +04:00
|
|
|
"""return the set of all nodes ancestral to a given node, including
|
2006-11-20 01:32:36 +03:00
|
|
|
the node itself, stopping when stop is matched"""
|
2009-05-17 05:49:59 +04:00
|
|
|
reachable = set((node,))
|
2006-11-13 22:26:57 +03:00
|
|
|
visit = [node]
|
2005-08-27 06:19:35 +04:00
|
|
|
if stop:
|
|
|
|
stopn = self.rev(stop)
|
|
|
|
else:
|
|
|
|
stopn = 0
|
|
|
|
while visit:
|
|
|
|
n = visit.pop(0)
|
|
|
|
if n == stop:
|
|
|
|
continue
|
|
|
|
if n == nullid:
|
|
|
|
continue
|
|
|
|
for p in self.parents(n):
|
|
|
|
if self.rev(p) < stopn:
|
|
|
|
continue
|
|
|
|
if p not in reachable:
|
2009-05-17 05:49:59 +04:00
|
|
|
reachable.add(p)
|
2005-08-27 06:19:35 +04:00
|
|
|
visit.append(p)
|
|
|
|
return reachable
|
|
|
|
|
2008-07-19 20:19:50 +04:00
|
|
|
def ancestors(self, *revs):
|
2009-12-10 17:35:43 +03:00
|
|
|
"""Generate the ancestors of 'revs' in reverse topological order.
|
|
|
|
|
|
|
|
Yield a sequence of revision numbers starting with the parents
|
|
|
|
of each revision in revs, i.e., each revision is *not* considered
|
|
|
|
an ancestor of itself. Results are in breadth-first order:
|
|
|
|
parents of each rev in revs, then parents of those, etc. Result
|
|
|
|
does not include the null revision."""
|
2008-07-19 20:19:50 +04:00
|
|
|
visit = list(revs)
|
2009-04-22 02:55:32 +04:00
|
|
|
seen = set([nullrev])
|
2008-07-19 20:19:50 +04:00
|
|
|
while visit:
|
|
|
|
for parent in self.parentrevs(visit.pop(0)):
|
|
|
|
if parent not in seen:
|
|
|
|
visit.append(parent)
|
|
|
|
seen.add(parent)
|
|
|
|
yield parent
|
|
|
|
|
|
|
|
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)
|
2010-11-07 12:23:48 +03:00
|
|
|
for i in xrange(first + 1, len(self)):
|
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
|
2009-04-22 02:57:28 +04:00
|
|
|
has = set(self.ancestors(*common))
|
|
|
|
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()
|
2008-10-21 19:00:35 +04:00
|
|
|
visit = [r for r in heads if r not in has]
|
|
|
|
while visit:
|
|
|
|
r = visit.pop(0)
|
|
|
|
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()
|
2011-03-23 18:02:11 +03:00
|
|
|
return has, [self.node(r) for r in missing]
|
|
|
|
|
|
|
|
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."""
|
|
|
|
_common, missing = self.findcommonmissing(common, heads)
|
|
|
|
return missing
|
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
|
|
|
|
roots = [n for n in roots if n in ancestors]
|
|
|
|
# Recompute the lowest revision
|
|
|
|
if roots:
|
|
|
|
lowestrev = min([self.rev(n) for n in roots])
|
|
|
|
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,
|
|
|
|
# and if nullid shows up in descedents, empty parents will look like
|
2011-06-08 02:02:54 +04:00
|
|
|
# they're descendants.
|
2005-10-07 21:48:27 +04:00
|
|
|
for r in xrange(max(lowestrev, 0), highestrev + 1):
|
|
|
|
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)
|
2011-05-06 14:09:20 +04:00
|
|
|
heads = [n for n, 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):
|
|
|
|
count = len(self)
|
|
|
|
if not count:
|
|
|
|
return [nullrev]
|
|
|
|
ishead = [1] * (count + 1)
|
|
|
|
index = self.index
|
|
|
|
for r in xrange(count):
|
|
|
|
e = index[r]
|
|
|
|
ishead[e[5]] = ishead[e[6]] = 0
|
|
|
|
return [r for r in xrange(count) if ishead[r]]
|
|
|
|
|
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)
|
2009-05-17 05:49:59 +04:00
|
|
|
reachable = set((startrev,))
|
|
|
|
heads = set((startrev,))
|
2005-11-16 14:08:25 +03:00
|
|
|
|
2006-06-20 22:02:23 +04:00
|
|
|
parentrevs = self.parentrevs
|
2008-06-26 23:35:50 +04:00
|
|
|
for r in xrange(startrev + 1, len(self)):
|
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)
|
2008-06-26 23:35:50 +04:00
|
|
|
for r in range(p + 1, len(self)):
|
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
|
2010-04-14 00:06:17 +04:00
|
|
|
for i in self.descendants(start):
|
|
|
|
if i == end:
|
|
|
|
return True
|
|
|
|
elif i > end:
|
|
|
|
break
|
|
|
|
return False
|
|
|
|
|
|
|
|
def ancestor(self, a, b):
|
|
|
|
"""calculate the least common ancestor of nodes a and b"""
|
|
|
|
|
|
|
|
# fast path, check if it is a descendant
|
|
|
|
a, b = self.rev(a), self.rev(b)
|
|
|
|
start, end = sorted((a, b))
|
|
|
|
if self.descendant(start, end):
|
|
|
|
return self.node(start)
|
|
|
|
|
|
|
|
def parents(rev):
|
|
|
|
return [p for p in self.parentrevs(rev) if p != nullrev]
|
|
|
|
|
|
|
|
c = ancestor.ancestor(a, b, parents)
|
|
|
|
if c is None:
|
|
|
|
return nullid
|
|
|
|
|
|
|
|
return self.node(c)
|
|
|
|
|
2006-10-18 20:44:56 +04:00
|
|
|
def _match(self, id):
|
2006-09-30 17:15:59 +04:00
|
|
|
if isinstance(id, (long, 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):
|
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)]
|
2008-11-13 04:11:34 +03:00
|
|
|
nl = [n for n in nl if hex(n).startswith(id)]
|
|
|
|
if len(nl) > 0:
|
|
|
|
if len(nl) == 1:
|
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'))
|
|
|
|
return None
|
2006-10-18 20:44:56 +04:00
|
|
|
except TypeError:
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2009-05-08 04:39:45 +04:00
|
|
|
def _addchunk(self, offset, data):
|
|
|
|
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
|
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _loadchunk(self, offset, length):
|
|
|
|
if self._inline:
|
|
|
|
df = self.opener(self.indexfile)
|
|
|
|
else:
|
|
|
|
df = self.opener(self.datafile)
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2012-04-27 22:07:29 +04:00
|
|
|
readahead = max(65536, length)
|
2009-05-08 04:39:45 +04:00
|
|
|
df.seek(offset)
|
|
|
|
d = df.read(readahead)
|
2011-11-03 20:24:55 +04:00
|
|
|
df.close()
|
2009-05-08 04:39:45 +04:00
|
|
|
self._addchunk(offset, d)
|
|
|
|
if readahead > length:
|
2012-04-13 07:26:33 +04:00
|
|
|
return util.buffer(d, 0, length)
|
2009-05-08 04:39:45 +04:00
|
|
|
return d
|
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _getchunk(self, offset, length):
|
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
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
return self._loadchunk(offset, length)
|
2007-07-24 05:44:08 +04:00
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _chunkraw(self, startrev, endrev):
|
2009-05-08 04:39:45 +04:00
|
|
|
start = self.start(startrev)
|
2009-05-28 01:01:34 +04:00
|
|
|
length = self.end(endrev) - start
|
2009-05-08 04:39:45 +04:00
|
|
|
if self._inline:
|
|
|
|
start += (startrev + 1) * self._io.size
|
2009-05-28 01:01:34 +04:00
|
|
|
return self._getchunk(start, length)
|
2009-05-08 04:39:45 +04:00
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _chunk(self, rev):
|
|
|
|
return decompress(self._chunkraw(rev, rev))
|
|
|
|
|
2011-04-30 18:33:47 +04:00
|
|
|
def _chunkbase(self, rev):
|
|
|
|
return self._chunk(rev)
|
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
def _chunkclear(self):
|
|
|
|
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):
|
|
|
|
"""return or calculate a delta between two revisions"""
|
2011-05-05 20:05:24 +04:00
|
|
|
if rev1 != nullrev and self.deltaparent(rev2) == rev1:
|
2012-04-13 07:26:33 +04:00
|
|
|
return str(self._chunk(rev2))
|
2007-07-26 21:02:58 +04:00
|
|
|
|
2012-04-14 07:55:46 +04:00
|
|
|
return mdiff.textdiff(self.revision(rev1),
|
|
|
|
self.revision(rev2))
|
2005-05-21 05:40:24 +04:00
|
|
|
|
2012-04-08 21:38:02 +04:00
|
|
|
def revision(self, nodeorrev):
|
2012-04-13 12:14:59 +04:00
|
|
|
"""return an uncompressed revision of a given node or revision
|
|
|
|
number.
|
|
|
|
"""
|
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
|
2007-07-24 05:44:08 +04:00
|
|
|
if node == nullid:
|
|
|
|
return ""
|
2010-08-10 20:57:16 +04:00
|
|
|
if self._cache:
|
|
|
|
if self._cache[0] == node:
|
|
|
|
return self._cache[2]
|
2010-08-20 02:17:50 +04: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
|
2005-05-04 01:16:10 +04:00
|
|
|
text = None
|
2012-04-08 21:38:02 +04:00
|
|
|
if rev is None:
|
|
|
|
rev = self.rev(node)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2007-07-26 21:02:58 +04:00
|
|
|
# check rev flags
|
2010-08-03 18:08:19 +04:00
|
|
|
if self.flags(rev) & ~REVIDX_KNOWN_FLAGS:
|
2007-09-22 02:14:39 +04:00
|
|
|
raise RevlogError(_('incompatible revision flag %x') %
|
2010-08-03 18:08:19 +04:00
|
|
|
(self.flags(rev) & ~REVIDX_KNOWN_FLAGS))
|
2007-07-26 21:02:58 +04:00
|
|
|
|
2010-08-20 02:17:50 +04:00
|
|
|
# build delta chain
|
2010-08-20 02:17:50 +04:00
|
|
|
chain = []
|
2011-05-08 00:40:14 +04:00
|
|
|
index = self.index # for performance
|
2011-05-08 00:40:17 +04:00
|
|
|
generaldelta = self._generaldelta
|
2010-08-20 02:17:50 +04:00
|
|
|
iterrev = rev
|
2011-05-08 00:40:14 +04:00
|
|
|
e = index[iterrev]
|
|
|
|
while iterrev != e[3] and iterrev != cachedrev:
|
2010-08-20 02:17:50 +04:00
|
|
|
chain.append(iterrev)
|
2011-05-08 00:40:17 +04:00
|
|
|
if generaldelta:
|
|
|
|
iterrev = e[3]
|
|
|
|
else:
|
|
|
|
iterrev -= 1
|
2011-05-08 00:40:14 +04:00
|
|
|
e = index[iterrev]
|
2010-08-20 02:17:50 +04:00
|
|
|
chain.reverse()
|
|
|
|
base = iterrev
|
2010-08-20 02:17:50 +04:00
|
|
|
|
2010-08-20 02:17:50 +04:00
|
|
|
if iterrev == cachedrev:
|
|
|
|
# cache hit
|
2009-09-04 12:47:55 +04:00
|
|
|
text = self._cache[2]
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2010-08-06 01:17:17 +04:00
|
|
|
# drop cache to save memory
|
|
|
|
self._cache = None
|
|
|
|
|
2009-05-28 01:01:34 +04:00
|
|
|
self._chunkraw(base, rev)
|
|
|
|
if text is None:
|
2012-04-13 07:26:33 +04:00
|
|
|
text = str(self._chunkbase(base))
|
2009-05-28 01:01:34 +04:00
|
|
|
|
2010-08-10 20:57:16 +04:00
|
|
|
bins = [self._chunk(r) for r in chain]
|
2007-07-24 05:44:08 +04:00
|
|
|
text = mdiff.patches(text, bins)
|
2011-01-07 02:04:41 +03:00
|
|
|
|
2011-01-19 00:55:48 +03:00
|
|
|
text = self._checkhash(text, node, rev)
|
2011-01-07 02:04:41 +03:00
|
|
|
|
|
|
|
self._cache = (node, rev, text)
|
|
|
|
return text
|
|
|
|
|
2011-01-19 00:55:48 +03:00
|
|
|
def _checkhash(self, text, node, rev):
|
2005-12-27 22:09:49 +03:00
|
|
|
p1, p2 = self.parents(node)
|
2011-05-05 14:46:02 +04:00
|
|
|
if node != hash(text, p1, p2):
|
2005-10-19 05:38:39 +04:00
|
|
|
raise RevlogError(_("integrity check failed on %s:%d")
|
2009-05-27 23:44:54 +04:00
|
|
|
% (self.indexfile, rev))
|
2005-06-29 22:42:35 +04:00
|
|
|
return text
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2006-04-05 00:38:43 +04:00
|
|
|
def checkinlinesize(self, tr, fp=None):
|
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]
|
|
|
|
dataoff = self.start(trindex)
|
|
|
|
|
|
|
|
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:
|
2009-05-28 01:01:34 +04:00
|
|
|
df.write(self._chunkraw(r, r))
|
2008-03-15 00:12:50 +03:00
|
|
|
finally:
|
|
|
|
df.close()
|
|
|
|
|
2006-04-05 00:38:44 +04:00
|
|
|
fp = self.opener(self.indexfile, 'w', atomictemp=True)
|
2006-04-05 00:38:43 +04:00
|
|
|
self.version &= ~(REVLOGNGINLINEDATA)
|
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
|
|
|
|
2010-08-18 21:45:52 +04:00
|
|
|
def addrevision(self, text, transaction, link, p1, p2, cachedelta=None):
|
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
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
2010-08-23 01:17:17 +04:00
|
|
|
node = hash(text, 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
|
|
|
|
|
2007-07-24 05:44:08 +04:00
|
|
|
dfh = None
|
2007-07-24 05:44:08 +04:00
|
|
|
if not self._inline:
|
2006-10-15 01:47:48 +04:00
|
|
|
dfh = self.opener(self.datafile, "a")
|
|
|
|
ifh = self.opener(self.indexfile, "a+")
|
2008-03-15 00:12:50 +03:00
|
|
|
try:
|
2010-08-23 01:17:17 +04:00
|
|
|
return self._addrevision(node, text, transaction, link, p1, p2,
|
2010-08-18 21:45:52 +04:00
|
|
|
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
|
|
|
|
2010-08-23 01:17:17 +04:00
|
|
|
def _addrevision(self, node, text, transaction, link, p1, p2,
|
2010-08-18 21:45:52 +04:00
|
|
|
cachedelta, ifh, dfh):
|
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.
|
|
|
|
invariants:
|
|
|
|
- text is optional (can be None); if not set, cachedelta must be set.
|
|
|
|
if both are set, they must correspond to eachother.
|
|
|
|
"""
|
2010-10-30 11:47:34 +04:00
|
|
|
btext = [text]
|
|
|
|
def buildtext():
|
|
|
|
if btext[0] is not None:
|
|
|
|
return btext[0]
|
2010-10-09 03:00:16 +04:00
|
|
|
# flush any pending writes here so we can read it in revision
|
|
|
|
if dfh:
|
|
|
|
dfh.flush()
|
|
|
|
ifh.flush()
|
|
|
|
basetext = self.revision(self.node(cachedelta[0]))
|
2010-10-30 11:47:34 +04:00
|
|
|
btext[0] = mdiff.patch(basetext, cachedelta[1])
|
|
|
|
chk = hash(btext[0], p1, p2)
|
2010-10-09 03:00:16 +04:00
|
|
|
if chk != node:
|
|
|
|
raise RevlogError(_("consistency error in delta"))
|
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()
|
|
|
|
ptext = self.revision(self.node(rev))
|
|
|
|
delta = mdiff.textdiff(ptext, t)
|
|
|
|
data = compress(delta)
|
|
|
|
l = len(data[1]) + len(data[0])
|
2011-05-12 15:47:17 +04:00
|
|
|
if basecache[0] == rev:
|
2011-05-08 23:32:33 +04:00
|
|
|
chainbase = basecache[1]
|
2011-05-08 00:40:14 +04:00
|
|
|
else:
|
2011-05-08 23:32:33 +04:00
|
|
|
chainbase = self.chainbase(rev)
|
|
|
|
dist = l + offset - self.start(chainbase)
|
|
|
|
if self._generaldelta:
|
|
|
|
base = rev
|
|
|
|
else:
|
|
|
|
base = chainbase
|
2011-05-12 15:47:17 +04:00
|
|
|
return dist, l, data, base, chainbase
|
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
|
2011-05-12 15:47:17 +04:00
|
|
|
base = chainbase = curr
|
2007-07-24 05:44:08 +04:00
|
|
|
offset = self.end(prev)
|
2010-08-10 20:57:41 +04:00
|
|
|
flags = 0
|
2010-08-18 21:45:52 +04:00
|
|
|
d = None
|
2011-05-12 15:47:17 +04:00
|
|
|
basecache = self._basecache
|
2010-10-30 11:47:34 +04:00
|
|
|
p1r, p2r = self.rev(p1), self.rev(p2)
|
2005-05-04 01:16:10 +04:00
|
|
|
|
2010-08-18 21:37:23 +04:00
|
|
|
# should we try to build a delta?
|
2010-10-30 11:47:34 +04:00
|
|
|
if prev != nullrev:
|
2011-05-08 23:32:33 +04:00
|
|
|
if self._generaldelta:
|
2011-05-12 17:24:33 +04:00
|
|
|
if p1r >= basecache[1]:
|
|
|
|
d = builddelta(p1r)
|
|
|
|
elif p2r >= basecache[1]:
|
|
|
|
d = builddelta(p2r)
|
|
|
|
else:
|
|
|
|
d = builddelta(prev)
|
2011-05-08 23:32:33 +04:00
|
|
|
else:
|
|
|
|
d = builddelta(prev)
|
2011-05-12 15:47:17 +04:00
|
|
|
dist, l, data, base, chainbase = d
|
2005-05-04 01:16:10 +04:00
|
|
|
|
|
|
|
# full versions are inserted when the needed deltas
|
|
|
|
# become comparable to the uncompressed text
|
2010-10-09 03:00:16 +04:00
|
|
|
if text is None:
|
|
|
|
textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]),
|
|
|
|
cachedelta[1])
|
|
|
|
else:
|
|
|
|
textlen = len(text)
|
2011-05-05 14:46:02 +04:00
|
|
|
if d is None or dist > textlen * 2:
|
2010-10-30 11:47:34 +04:00
|
|
|
text = buildtext()
|
2005-05-04 01:16:10 +04:00
|
|
|
data = compress(text)
|
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)
|
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])
|
|
|
|
dfh.flush()
|
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
|
|
|
|
2009-09-04 12:47:55 +04:00
|
|
|
if type(text) == str: # only accept immutable objects
|
|
|
|
self._cache = (node, curr, text)
|
2011-05-12 15:47:17 +04:00
|
|
|
self._basecache = (curr, chainbase)
|
2005-05-04 01:16:10 +04:00
|
|
|
return node
|
|
|
|
|
revlog: linearize created changegroups in generaldelta revlogs
This greatly improves the speed of the bundling process, and often reduces the
bundle size considerably. (Although if the repository is already ordered, this
has little effect on both time and bundle size.)
For non-generaldelta clients, the reduced bundle size translates to a reduced
repository size, similar to shrinking the revlogs (which uses the exact same
algorithm). For generaldelta clients the difference is minor.
When the new bundle format comes, reordering will not be necessary since we
can then store the deltaparent relationsships directly. The eventual default
behavior for clients and servers is presented in the table below, where "new"
implies support for GD as well as the new bundle format:
old client new client
old server old bundle, no reorder old bundle, no reorder
new server, non-GD old bundle, no reorder[1] old bundle, no reorder[2]
new server, GD old bundle, reorder[3] new bundle, no reorder[4]
[1] reordering is expensive on the server in this case, skip it
[2] client can choose to do its own redelta here
[3] reordering is needed because otherwise the pull does a lot of extra
work on the server
[4] reordering isn't needed because client can get deltabase in bundle
format
Currently, the default is to reorder on GD-servers, and not otherwise. A new
setting, bundle.reorder, has been added to override the default reordering
behavior. It can be set to either 'auto' (the default), or any true or false
value as a standard boolean setting, to either force the reordering on or off
regardless of generaldelta.
Some timing data from a relatively branch test repository follows. All
bundling is done with --all --type none options.
Non-generaldelta, non-shrunk repo:
-----------------------------------
Size: 276M
Without reorder (default):
Bundle time: 14.4 seconds
Bundle size: 939M
With reorder:
Bundle time: 1 minute, 29.3 seconds
Bundle size: 381M
Generaldelta, non-shrunk repo:
-----------------------------------
Size: 87M
Without reorder:
Bundle time: 2 minutes, 1.4 seconds
Bundle size: 939M
With reorder (default):
Bundle time: 25.5 seconds
Bundle size: 381M
2011-05-19 01:26:26 +04:00
|
|
|
def group(self, nodelist, bundler, reorder=None):
|
2009-09-09 01:58:59 +04:00
|
|
|
"""Calculate a delta group, yielding a sequence of changegroup chunks
|
|
|
|
(strings).
|
2005-08-27 12:43:48 +04:00
|
|
|
|
|
|
|
Given a list of changeset revs, return a set of deltas and
|
2010-08-13 18:11:51 +04:00
|
|
|
metadata corresponding to nodes. The first delta is
|
|
|
|
first parent(nodelist[0]) -> nodelist[0], the receiver is
|
|
|
|
guaranteed to have this parent as it has all history before
|
|
|
|
these changesets. In the case firstparent is nullrev the
|
|
|
|
changegroup starts with a full revision.
|
2005-08-27 12:43:48 +04:00
|
|
|
"""
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2011-06-03 22:32:54 +04:00
|
|
|
# if we don't have any revisions touched by these changesets, bail
|
|
|
|
if len(nodelist) == 0:
|
|
|
|
yield bundler.close()
|
|
|
|
return
|
|
|
|
|
revlog: linearize created changegroups in generaldelta revlogs
This greatly improves the speed of the bundling process, and often reduces the
bundle size considerably. (Although if the repository is already ordered, this
has little effect on both time and bundle size.)
For non-generaldelta clients, the reduced bundle size translates to a reduced
repository size, similar to shrinking the revlogs (which uses the exact same
algorithm). For generaldelta clients the difference is minor.
When the new bundle format comes, reordering will not be necessary since we
can then store the deltaparent relationsships directly. The eventual default
behavior for clients and servers is presented in the table below, where "new"
implies support for GD as well as the new bundle format:
old client new client
old server old bundle, no reorder old bundle, no reorder
new server, non-GD old bundle, no reorder[1] old bundle, no reorder[2]
new server, GD old bundle, reorder[3] new bundle, no reorder[4]
[1] reordering is expensive on the server in this case, skip it
[2] client can choose to do its own redelta here
[3] reordering is needed because otherwise the pull does a lot of extra
work on the server
[4] reordering isn't needed because client can get deltabase in bundle
format
Currently, the default is to reorder on GD-servers, and not otherwise. A new
setting, bundle.reorder, has been added to override the default reordering
behavior. It can be set to either 'auto' (the default), or any true or false
value as a standard boolean setting, to either force the reordering on or off
regardless of generaldelta.
Some timing data from a relatively branch test repository follows. All
bundling is done with --all --type none options.
Non-generaldelta, non-shrunk repo:
-----------------------------------
Size: 276M
Without reorder (default):
Bundle time: 14.4 seconds
Bundle size: 939M
With reorder:
Bundle time: 1 minute, 29.3 seconds
Bundle size: 381M
Generaldelta, non-shrunk repo:
-----------------------------------
Size: 87M
Without reorder:
Bundle time: 2 minutes, 1.4 seconds
Bundle size: 939M
With reorder (default):
Bundle time: 25.5 seconds
Bundle size: 381M
2011-05-19 01:26:26 +04:00
|
|
|
# for generaldelta revlogs, we linearize the revs; this will both be
|
|
|
|
# much quicker and generate a much smaller bundle
|
|
|
|
if (self._generaldelta and reorder is not False) or reorder:
|
|
|
|
dag = dagutil.revlogdag(self)
|
|
|
|
revs = set(self.rev(n) for n in nodelist)
|
|
|
|
revs = dag.linearize(revs)
|
|
|
|
else:
|
|
|
|
revs = sorted([self.rev(n) for n in nodelist])
|
2009-05-27 04:46:59 +04:00
|
|
|
|
2005-05-10 12:40:49 +04:00
|
|
|
# add the parent of the first rev
|
2009-05-14 18:00:21 +04:00
|
|
|
p = self.parentrevs(revs[0])[0]
|
|
|
|
revs.insert(0, p)
|
2005-05-10 12:40:49 +04:00
|
|
|
|
|
|
|
# build deltas
|
2011-03-27 01:12:02 +03:00
|
|
|
for r in xrange(len(revs) - 1):
|
2011-04-30 13:03:28 +04:00
|
|
|
prev, curr = revs[r], revs[r + 1]
|
|
|
|
for c in bundler.revchunk(self, curr, prev):
|
2011-04-01 00:24:06 +04:00
|
|
|
yield c
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2011-04-01 00:24:06 +04:00
|
|
|
yield bundler.close()
|
2005-05-30 20:03:54 +04:00
|
|
|
|
2010-09-19 21:51:54 +04:00
|
|
|
def addgroup(self, bundle, linkmapper, transaction):
|
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.
|
|
|
|
"""
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2010-10-09 03:00:19 +04:00
|
|
|
# track the base of the current delta log
|
2012-01-13 04:29:03 +04:00
|
|
|
content = []
|
2006-03-24 21:51:05 +03:00
|
|
|
node = None
|
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)
|
2006-04-05 00:38:43 +04:00
|
|
|
ifh = self.opener(self.indexfile, "a+")
|
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)
|
|
|
|
dfh = self.opener(self.datafile, "a")
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2008-03-15 00:12:50 +03:00
|
|
|
try:
|
|
|
|
# loop through our set of deltas
|
|
|
|
chain = None
|
2011-06-01 14:38:46 +04:00
|
|
|
while True:
|
2011-04-30 21:01:24 +04:00
|
|
|
chunkdata = bundle.deltachunk(chain)
|
2010-09-19 22:12:45 +04:00
|
|
|
if not chunkdata:
|
2010-09-19 21:51:54 +04:00
|
|
|
break
|
2010-09-19 22:12:45 +04:00
|
|
|
node = chunkdata['node']
|
|
|
|
p1 = chunkdata['p1']
|
|
|
|
p2 = chunkdata['p2']
|
|
|
|
cs = chunkdata['cs']
|
2011-04-30 12:00:41 +04:00
|
|
|
deltabase = chunkdata['deltabase']
|
|
|
|
delta = chunkdata['delta']
|
2010-09-19 22:12:45 +04:00
|
|
|
|
2012-01-13 04:29:03 +04:00
|
|
|
content.append(node)
|
|
|
|
|
2008-03-15 00:12:50 +03:00
|
|
|
link = linkmapper(cs)
|
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
|
|
|
|
chain = node
|
|
|
|
continue
|
|
|
|
|
|
|
|
for p in (p1, p2):
|
|
|
|
if not p 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)
|
2010-10-09 03:00:19 +04:00
|
|
|
chain = self._addrevision(node, None, transaction, link,
|
2011-04-30 12:00:41 +04:00
|
|
|
p1, p2, (baserev, delta), ifh, dfh)
|
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()
|
2010-10-09 03:00:19 +04:00
|
|
|
dfh = self.opener(self.datafile, "a")
|
|
|
|
ifh = self.opener(self.indexfile, "a")
|
2008-03-15 00:12:50 +03:00
|
|
|
finally:
|
|
|
|
if dfh:
|
|
|
|
dfh.close()
|
|
|
|
ifh.close()
|
2005-05-10 12:40:49 +04:00
|
|
|
|
2012-01-13 04:29:03 +04:00
|
|
|
return content
|
2005-11-03 06:26:23 +03:00
|
|
|
|
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
|
|
|
|
|
2008-06-26 23:35:50 +04:00
|
|
|
for rev in self:
|
2008-01-19 23:01:16 +03:00
|
|
|
if self.index[rev][4] >= minlink:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
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
|
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
|
|
|
|
except IOError, inst:
|
|
|
|
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
|
2005-11-03 07:09:19 +03:00
|
|
|
except IOError, 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
|