##// END OF EJS Templates
diff: make use of output labeling
diff: make use of output labeling

File last commit:

r10404:3e7cbe85 default
r10818:d14d45fa default
Show More
revlog.py
1396 lines | 47.4 KiB | text/x-python | PythonLexer
Martin Geisler
put license and copyright info into comment blocks
r8226 # 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
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Martin Geisler
turn some comments back into module docstrings
r8227 """Storage back-end for Mercurial.
This provides efficient delta storage with O(1) retrieve and append
and O(changes) merge between branches.
"""
Peter Arrenbrecht
cleanup: drop unused imports
r7873 # import stuff from node for others to import from revlog
from node import bin, hex, nullid, nullrev, short #@UnusedImport
Matt Mackall
Simplify i18n imports
r3891 from i18n import _
Simon Heimberg
separate import lines from mercurial and general python modules
r8312 import changegroup, ancestor, mdiff, parsers, error, util
import struct, zlib, errno
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36
Matt Mackall
revlog: localize some fastpath functions
r5007 _pack = struct.pack
_unpack = struct.unpack
_compress = zlib.compress
_decompress = zlib.decompress
Dirkjan Ochtman
python 2.6 compatibility: compatibility wrappers for hash functions
r6470 _sha = util.sha1
Matt Mackall
revlog: localize some fastpath functions
r5007
Matt Mackall
revlog: some basic code reordering
r4987 # revlog flags
mason@suse.com
Implement revlogng....
r2072 REVLOGV0 = 0
REVLOGNG = 1
mason@suse.com
Implement data inlined with the index file...
r2073 REVLOGNGINLINEDATA = (1 << 16)
mason@suse.com
Use revlogng and inlined data files by default...
r2222 REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
REVLOG_DEFAULT_FORMAT = REVLOGNG
REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
mason@suse.com
Implement data inlined with the index file...
r2073
Matt Mackall
revlog: preread revlog .i file...
r8314 _prereadsize = 1048576
Matt Mackall
errors: move revlog errors...
r7633 RevlogError = error.RevlogError
LookupError = error.LookupError
Alexander Solovyov
LookupError should have same __str__ as RevlogError
r6703
Matt Mackall
revlog: some basic code reordering
r4987 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)
Nicolas Dumazet
revlog: faster hash computation when one of the parent node is null...
r7883 nullhash = _sha(nullid)
mpm@selenic.com
Move hash function back to revlog from node
r1091 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.
"""
Nicolas Dumazet
revlog: faster hash computation when one of the parent node is null...
r7883 # 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])
mpm@selenic.com
Move hash function back to revlog from node
r1091 s.update(text)
return s.digest()
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 def compress(text):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """ generate a possibly-compressed representation of text """
Matt Mackall
revlog: some codingstyle cleanups
r4980 if not text:
return ("", text)
Matt Mackall
revlog: break up compression of large deltas...
r5451 l = len(text)
Benoit Boissinot
fix UnboundLocalError, refactor a bit...
r5453 bin = None
Matt Mackall
revlog: break up compression of large deltas...
r5451 if l < 44:
Benoit Boissinot
fix UnboundLocalError, refactor a bit...
r5453 pass
Matt Mackall
revlog: break up compression of large deltas...
r5451 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)
Benoit Boissinot
fix UnboundLocalError, refactor a bit...
r5453 if bin is None or len(bin) > l:
Matt Mackall
revlog: some codingstyle cleanups
r4980 if text[0] == '\0':
return ("", text)
mason@suse.com
Reduce string duplication in compression code...
r1533 return ('u', text)
return ("", bin)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
def decompress(bin):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """ decompress the given input """
Matt Mackall
revlog: some codingstyle cleanups
r4980 if not bin:
return bin
mpm@selenic.com
Make compression more intelligent:...
r112 t = bin[0]
Matt Mackall
revlog: some codingstyle cleanups
r4980 if t == '\0':
return bin
if t == 'x':
Matt Mackall
revlog: localize some fastpath functions
r5007 return _decompress(bin)
Matt Mackall
revlog: some codingstyle cleanups
r4980 if t == 'u':
return bin[1:]
Thomas Arendsen Hein
Fix some problems when working on broken repositories:...
r1853 raise RevlogError(_("unknown compression type %r") % t)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Eric Hopper
Convert all classes to new-style classes by deriving them from object.
r1559 class lazyparser(object):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """
this class avoids the need to parse the entirety of large indices
"""
Vadim Gelfer
windows: revlog.lazyparser not always safe to use....
r2250
# lazyparser is not safe to use on windows if win32 extensions not
# available. it keeps file handle open, which make it not possible
# to break hardlinks on local cloned repos.
Matt Mackall
revlog: move stat inside lazyparser
r8641 def __init__(self, dataf):
try:
size = util.fstat(dataf).st_size
except AttributeError:
size = 0
mason@suse.com
New lazy index code for revlogs....
r2079 self.dataf = dataf
Matt Mackall
revlog: only allow lazy parsing with revlogng files...
r4976 self.s = struct.calcsize(indexformatng)
mason@suse.com
New lazy index code for revlogs....
r2079 self.datasize = size
Matt Mackall
many, many trivial check-code fixups
r10282 self.l = size / self.s
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 self.index = [None] * self.l
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 self.map = {nullid: nullrev}
mason@suse.com
New lazy index code for revlogs....
r2079 self.allmap = 0
mpm@selenic.com
lazyparser speed ups...
r323 self.all = 0
mason@suse.com
New lazy index code for revlogs....
r2079 self.mapfind_count = 0
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76
mason@suse.com
New lazy index code for revlogs....
r2079 def loadmap(self):
"""
during a commit, we need to make sure the rev being added is
not a duplicate. This requires loading the entire index,
which is fairly slow. loadmap can load up just the node map,
which takes much less time.
"""
Matt Mackall
revlog: some codingstyle cleanups
r4980 if self.allmap:
return
mason@suse.com
New lazy index code for revlogs....
r2079 end = self.datasize
self.allmap = 1
cur = 0
count = 0
blocksize = self.s * 256
self.dataf.seek(0)
while cur < end:
data = self.dataf.read(blocksize)
off = 0
for x in xrange(256):
Matt Mackall
revlog: only allow lazy parsing with revlogng files...
r4976 n = data[off + ngshaoffset:off + ngshaoffset + 20]
mason@suse.com
New lazy index code for revlogs....
r2079 self.map[n] = count
count += 1
if count >= self.l:
break
off += self.s
cur += blocksize
def loadblock(self, blockstart, blocksize, data=None):
Matt Mackall
revlog: some codingstyle cleanups
r4980 if self.all:
return
mason@suse.com
New lazy index code for revlogs....
r2079 if data is None:
self.dataf.seek(blockstart)
Alexis S. L. Carvalho
don't let lazyparser read more data than it can handle...
r3078 if blockstart + blocksize > self.datasize:
# the revlog may have grown since we've started running,
# but we don't have space in self.index for more entries.
# limit blocksize so that we don't get too much data.
Alexis S. L. Carvalho
Avoid negative block sizes in lazyparser....
r3089 blocksize = max(self.datasize - blockstart, 0)
mason@suse.com
New lazy index code for revlogs....
r2079 data = self.dataf.read(blocksize)
lend = len(data) / self.s
i = blockstart / self.s
off = 0
Brendan Cully
lazyindex: handle __delitem__ in loadblock
r4061 # lazyindex supports __delitem__
if lend > len(self.index) - i:
lend = len(self.index) - i
mason@suse.com
New lazy index code for revlogs....
r2079 for x in xrange(lend):
Martin Geisler
use 'x is None' instead of 'x == None'...
r8527 if self.index[i + x] is None:
mason@suse.com
New lazy index code for revlogs....
r2079 b = data[off : off + self.s]
mason@suse.com
Reduce index memory usage by storing the bare string instead of tuples...
r2080 self.index[i + x] = b
Matt Mackall
revlog: only allow lazy parsing with revlogng files...
r4976 n = b[ngshaoffset:ngshaoffset + 20]
mason@suse.com
Reduce index memory usage by storing the bare string instead of tuples...
r2080 self.map[n] = i + x
mason@suse.com
New lazy index code for revlogs....
r2079 off += self.s
def findnode(self, node):
"""search backwards through the index file for a specific node"""
Matt Mackall
revlog: some codingstyle cleanups
r4980 if self.allmap:
return None
mason@suse.com
New lazy index code for revlogs....
r2079
# hg log will cause many many searches for the manifest
# nodes. After we get called a few times, just load the whole
# thing.
if self.mapfind_count > 8:
self.loadmap()
if node in self.map:
return node
return None
self.mapfind_count += 1
last = self.l - 1
while self.index[last] != None:
if last == 0:
self.all = 1
self.allmap = 1
return None
last -= 1
end = (last + 1) * self.s
blocksize = self.s * 256
while end >= 0:
start = max(end - blocksize, 0)
self.dataf.seek(start)
data = self.dataf.read(end - start)
findend = end - start
while True:
Matt Mackall
lazyparser.findnode: fix typo and s/rfind/find/...
r4994 # we're searching backwards, so we have to make sure
mason@suse.com
New lazy index code for revlogs....
r2079 # we don't find a changeset where this node is a parent
Matt Mackall
lazyparser.findnode: fix typo and s/rfind/find/...
r4994 off = data.find(node, 0, findend)
mason@suse.com
New lazy index code for revlogs....
r2079 findend = off
if off >= 0:
i = off / self.s
off = i * self.s
Matt Mackall
revlog: only allow lazy parsing with revlogng files...
r4976 n = data[off + ngshaoffset:off + ngshaoffset + 20]
mason@suse.com
New lazy index code for revlogs....
r2079 if n == node:
self.map[n] = i + start / self.s
return node
else:
break
end -= blocksize
return None
def loadindex(self, i=None, end=None):
Matt Mackall
revlog: some codingstyle cleanups
r4980 if self.all:
return
mason@suse.com
New lazy index code for revlogs....
r2079 all = False
Martin Geisler
use 'x is None' instead of 'x == None'...
r8527 if i is None:
mason@suse.com
New lazy index code for revlogs....
r2079 blockstart = 0
Matt Mackall
lazyparser: up the blocksize from 512 bytes to 64k
r4992 blocksize = (65536 / self.s) * self.s
mason@suse.com
New lazy index code for revlogs....
r2079 end = self.datasize
all = True
mpm@selenic.com
lazyparser speed ups...
r323 else:
mason@suse.com
New lazy index code for revlogs....
r2079 if end:
blockstart = i * self.s
end = end * self.s
blocksize = end - blockstart
else:
Matt Mackall
lazyparser: up the blocksize from 512 bytes to 64k
r4992 blockstart = (i & ~1023) * self.s
blocksize = self.s * 1024
mason@suse.com
New lazy index code for revlogs....
r2079 end = blockstart + blocksize
while blockstart < end:
self.loadblock(blockstart, blocksize)
blockstart += blocksize
Matt Mackall
revlog: some codingstyle cleanups
r4980 if all:
self.all = True
mpm@selenic.com
Whitespace cleanups...
r515
Eric Hopper
Convert all classes to new-style classes by deriving them from object.
r1559 class lazyindex(object):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """a lazy version of the index array"""
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __init__(self, parser):
self.p = parser
def __len__(self):
return len(self.p.index)
mpm@selenic.com
Make lazyindex load slightly faster
r115 def load(self, pos):
Eric Hopper
lazyindex fix, make load handle negative indexes properly.
r1403 if pos < 0:
pos += len(self.p.index)
mason@suse.com
New lazy index code for revlogs....
r2079 self.p.loadindex(pos)
mpm@selenic.com
Make lazyindex load slightly faster
r115 return self.p.index[pos]
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __getitem__(self, pos):
Matt Mackall
revlog: localize some fastpath functions
r5007 return _unpack(indexformatng, self.p.index[pos] or self.load(pos))
mason@suse.com
Implement revlogng....
r2072 def __setitem__(self, pos, item):
Matt Mackall
revlog: localize some fastpath functions
r5007 self.p.index[pos] = _pack(indexformatng, *item)
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 def __delitem__(self, pos):
del self.p.index[pos]
Matt Mackall
revlog: add a magic null revision to our index...
r4979 def insert(self, pos, e):
Matt Mackall
revlog: localize some fastpath functions
r5007 self.p.index.insert(pos, _pack(indexformatng, *e))
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def append(self, e):
Matt Mackall
revlog: localize some fastpath functions
r5007 self.p.index.append(_pack(indexformatng, *e))
mpm@selenic.com
Whitespace cleanups...
r515
Eric Hopper
Convert all classes to new-style classes by deriving them from object.
r1559 class lazymap(object):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """a lazy version of the node map"""
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __init__(self, parser):
self.p = parser
def load(self, key):
mason@suse.com
New lazy index code for revlogs....
r2079 n = self.p.findnode(key)
Martin Geisler
use 'x is None' instead of 'x == None'...
r8527 if n is None:
mpm@selenic.com
Smarter handling of revlog key errors...
r1214 raise KeyError(key)
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __contains__(self, key):
mason@suse.com
New lazy index code for revlogs....
r2079 if key in self.p.map:
return True
self.p.loadmap()
mpm@selenic.com
lazyparser speed ups...
r323 return key in self.p.map
mpm@selenic.com
Add iterator to the lazymap code
r97 def __iter__(self):
mpm@selenic.com
Various node id lookup tweaks...
r469 yield nullid
mpm@selenic.com
Add iterator to the lazymap code
r97 for i in xrange(self.p.l):
mason@suse.com
Reduce index memory usage by storing the bare string instead of tuples...
r2080 ret = self.p.index[i]
if not ret:
mason@suse.com
New lazy index code for revlogs....
r2079 self.p.loadindex(i)
mason@suse.com
Reduce index memory usage by storing the bare string instead of tuples...
r2080 ret = self.p.index[i]
if isinstance(ret, str):
Matt Mackall
revlog: localize some fastpath functions
r5007 ret = _unpack(indexformatng, ret)
Matt Mackall
revlog: change accesses to index entry elements to use positive offsets
r4978 yield ret[7]
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __getitem__(self, key):
try:
return self.p.map[key]
except KeyError:
mpm@selenic.com
Friendlier exceptions for unknown node errors
r86 try:
self.load(key)
return self.p.map[key]
except KeyError:
raise KeyError("node " + hex(key))
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def __setitem__(self, key, val):
self.p.map[key] = val
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 def __delitem__(self, key):
del self.p.map[key]
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76
Matt Mackall
revlog: some basic code reordering
r4987 indexformatv0 = ">4l20s20s20s"
v0shaoffset = 56
Matt Mackall
revlog: raise offset/type helpers to global scope
r4918
Matt Mackall
revlog: add revlogio interface...
r4972 class revlogoldio(object):
def __init__(self):
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 self.size = struct.calcsize(indexformatv0)
Matt Mackall
revlog: add revlogio interface...
r4972
Matt Mackall
revlog: preread revlog .i file...
r8314 def parseindex(self, fp, data, inline):
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 s = self.size
Matt Mackall
revlog: add revlogio interface...
r4972 index = []
nodemap = {nullid: nullrev}
Matt Mackall
revlog: simplify the v0 parser
r4973 n = off = 0
Matt Mackall
revlog: fix reading of larger revlog indices on Windows
r8558 if len(data) == _prereadsize:
Matt Mackall
revlog: preread revlog .i file...
r8314 data += fp.read() # read the rest
Matt Mackall
revlog: simplify the v0 parser
r4973 l = len(data)
while off + s <= l:
cur = data[off:off + s]
off += s
Matt Mackall
revlog: localize some fastpath functions
r5007 e = _unpack(indexformatv0, cur)
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 # transform to revlogv1 format
e2 = (offset_type(e[0], 0), e[1], -1, e[2], e[3],
Matt Mackall
revlog: make revlogv0 loading more robust against corruption
r5544 nodemap.get(e[4], nullrev), nodemap.get(e[5], nullrev), e[6])
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 index.append(e2)
nodemap[e[6]] = n
Matt Mackall
revlog: simplify the v0 parser
r4973 n += 1
Matt Mackall
revlog: add revlogio interface...
r4972
Matt Mackall
revlog: pull chunkcache back into revlog
r4983 return index, nodemap, None
Matt Mackall
revlog: add revlogio interface...
r4972
Alexis S. L. Carvalho
revlog: fix revlogio.packentry corner case...
r5338 def packentry(self, entry, node, version, rev):
Benoit Boissinot
revlog: don't silently discard revlog flags on revlogv0
r10395 if gettype(entry[0]):
raise RevlogError(_("index entry flags need RevlogNG"))
Matt Mackall
revlog: abstract out index entry packing...
r4986 e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
node(entry[5]), node(entry[6]), entry[7])
Matt Mackall
revlog: localize some fastpath functions
r5007 return _pack(indexformatv0, *e2)
Matt Mackall
revlog: abstract out index entry packing...
r4986
Matt Mackall
revlog: some basic code reordering
r4987 # index ng:
# 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
# 32 bytes: nodeid
indexformatng = ">Qiiiiii20s12x"
ngshaoffset = 32
versionformat = ">I"
Matt Mackall
revlog: add revlogio interface...
r4972 class revlogio(object):
def __init__(self):
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 self.size = struct.calcsize(indexformatng)
Matt Mackall
revlog: add revlogio interface...
r4972
Matt Mackall
revlog: preread revlog .i file...
r8314 def parseindex(self, fp, data, inline):
Matt Mackall
revlog: move stat inside lazyparser
r8641 if len(data) == _prereadsize:
Matt Mackall
revlog: fix reading of larger revlog indices on Windows
r8558 if util.openhardlinks() and not inline:
# big index, let's parse it on demand
Matt Mackall
revlog: move stat inside lazyparser
r8641 parser = lazyparser(fp)
Matt Mackall
revlog: fix reading of larger revlog indices on Windows
r8558 index = lazyindex(parser)
nodemap = lazymap(parser)
e = list(index[0])
type = gettype(e[0])
e[0] = offset_type(0, type)
index[0] = e
return index, nodemap, None
else:
data += fp.read()
Matt Mackall
revlog: add revlogio interface...
r4972
Bernhard Leiner
use the new parseindex implementation C in parsers
r7109 # call the C implementation to parse the index data
index, nodemap, cache = parsers.parse_index(data, inline)
Matt Mackall
revlog: pull chunkcache back into revlog
r4983 return index, nodemap, cache
Matt Mackall
revlog: add revlogio interface...
r4972
Alexis S. L. Carvalho
revlog: fix revlogio.packentry corner case...
r5338 def packentry(self, entry, node, version, rev):
Matt Mackall
revlog: localize some fastpath functions
r5007 p = _pack(indexformatng, *entry)
Alexis S. L. Carvalho
revlog: fix revlogio.packentry corner case...
r5338 if rev == 0:
Matt Mackall
revlog: localize some fastpath functions
r5007 p = _pack(versionformat, version) + p[4:]
Matt Mackall
revlog: abstract out index entry packing...
r4986 return p
Eric Hopper
Convert all classes to new-style classes by deriving them from object.
r1559 class revlog(object):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """
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
Martin Geisler
Fixed docstring typos
r6912 information on each revision, including its nodeid (hash), the
mpm@selenic.com
Add some docstrings to revlog.py
r1083 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.
"""
Matt Mackall
revlog: simplify revlog version handling...
r4258 def __init__(self, opener, indexfile):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """
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.
"""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 self.indexfile = indexfile
Matt Mackall
revlog: don't pass datafile as an argument
r4257 self.datafile = indexfile[:-2] + ".d"
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 self.opener = opener
Matt Mackall
revlog: mark cache private
r4984 self._cache = None
Matt Mackall
revlog: clean up the chunk caching code
r8316 self._chunkcache = (0, '')
Matt Mackall
revlog: simplify revlog.__init__...
r4985 self.nodemap = {nullid: nullrev}
self.index = []
v = REVLOG_DEFAULT_VERSION
Vsevolod Solovyov
add options dict to localrepo.store.opener and use it for defversion
r10322 if hasattr(opener, 'options') and 'defversion' in opener.options:
v = opener.options['defversion']
Matt Mackall
revlog: simplify revlog.__init__...
r4985 if v & REVLOGNG:
v |= REVLOGNGINLINEDATA
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
Matt Mackall
revlog: preread revlog .i file...
r8314 i = ''
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 try:
Benoit Boissinot
revalidate revlog data after locking the repo (issue132)
r1784 f = self.opener(self.indexfile)
Matt Mackall
revlog: preread revlog .i file...
r8314 i = f.read(_prereadsize)
Matt Mackall
revlog: raise offset/type helpers to global scope
r4918 if len(i) > 0:
Matt Mackall
revlog: preread revlog .i file...
r8314 v = struct.unpack(versionformat, i[:4])[0]
Bryan O'Sullivan
Make revlog constructor more discerning in its treatment of errors.
r1322 except IOError, inst:
if inst.errno != errno.ENOENT:
raise
Matt Mackall
revlog: simplify revlog.__init__...
r4985
self.version = v
self._inline = v & REVLOGNGINLINEDATA
mason@suse.com
Implement data inlined with the index file...
r2073 flags = v & ~0xFFFF
fmt = v & 0xFFFF
Matt Mackall
revlog: simplify revlog.__init__...
r4985 if fmt == REVLOGV0 and flags:
raise RevlogError(_("index %s unknown flags %#04x for format v0")
% (self.indexfile, flags >> 16))
elif fmt == REVLOGNG and flags & ~REVLOGNGINLINEDATA:
raise RevlogError(_("index %s unknown flags %#04x for revlogng")
% (self.indexfile, flags >> 16))
elif fmt > REVLOGNG:
Matt Mackall
Make revlog error slightly less scary
r3743 raise RevlogError(_("index %s unknown format %d")
Thomas Arendsen Hein
Indentation cleanups for 2956948b81f3.
r3680 % (self.indexfile, fmt))
Matt Mackall
revlog: simplify revlog.__init__...
r4985
Matt Mackall
revlog: add revlogio interface...
r4972 self._io = revlogio()
Matt Mackall
revlog: regroup parsing code
r4971 if self.version == REVLOGV0:
Matt Mackall
revlog: add revlogio interface...
r4972 self._io = revlogoldio()
mason@suse.com
Implement revlogng....
r2072 if i:
Benoit Boissinot
raise RevlogError when parser can't parse the revlog index...
r8016 try:
Matt Mackall
revlog: preread revlog .i file...
r8314 d = self._io.parseindex(f, i, self._inline)
Benoit Boissinot
pychecker: remove unused local variables
r9679 except (ValueError, IndexError):
Benoit Boissinot
raise RevlogError when parser can't parse the revlog index...
r8016 raise RevlogError(_("index %s is corrupted") % (self.indexfile))
Matt Mackall
revlog: pull chunkcache back into revlog
r4983 self.index, self.nodemap, self._chunkcache = d
Matt Mackall
revlog: clean up the chunk caching code
r8316 if not self._chunkcache:
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 self._chunkclear()
Matt Mackall
revlog: simplify revlog.__init__...
r4985
Bernhard Leiner
use the new parseindex implementation C in parsers
r7109 # add the magic null revision at -1 (if it hasn't been done already)
if (self.index == [] or isinstance(self.index, lazyindex) or
self.index[-1][7] != nullid) :
self.index.append((0, 0, 0, -1, -1, -1, -1, nullid))
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
Matt Mackall
revlog: privatize some methods
r4920 def _loadindex(self, start, end):
mason@suse.com
New lazy index code for revlogs....
r2079 """load a block of indexes all at once from the lazy parser"""
if isinstance(self.index, lazyindex):
self.index.p.loadindex(start, end)
Matt Mackall
revlog: privatize some methods
r4920 def _loadindexmap(self):
mason@suse.com
Implement revlogng....
r2072 """loads both the map and the index from the lazy parser"""
if isinstance(self.index, lazyindex):
p = self.index.p
mason@suse.com
New lazy index code for revlogs....
r2079 p.loadindex()
self.nodemap = p.map
Matt Mackall
revlog: privatize some methods
r4920 def _loadmap(self):
mason@suse.com
New lazy index code for revlogs....
r2079 """loads the map from the lazy parser"""
if isinstance(self.nodemap, lazymap):
self.nodemap.p.loadmap()
self.nodemap = self.nodemap.p.map
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: some codingstyle cleanups
r4980 def tip(self):
return self.node(len(self.index) - 2)
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 def __len__(self):
Matt Mackall
revlog: some codingstyle cleanups
r4980 return len(self.index) - 1
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 def __iter__(self):
for i in xrange(len(self)):
yield i
Bryan O'Sullivan
revlog: raise informative exception if file is missing.
r1201 def rev(self, node):
try:
return self.nodemap[node]
except KeyError:
Matt Mackall
revlog: report node and file when lookup fails
r6228 raise LookupError(node, self.indexfile, _('no node'))
Matt Mackall
revlog: some codingstyle cleanups
r4980 def node(self, rev):
return self.index[rev][7]
Matt Mackall
linkrev: take a revision number rather than a hash
r7361 def linkrev(self, rev):
return self.index[rev][4]
mpm@selenic.com
Handle nullid better for ancestor
r2 def parents(self, node):
Matt Mackall
revlog: speed up parents()
r7363 i = self.index
d = i[self.rev(node)]
return i[d[5]][7], i[d[6]][7] # map revisions to nodes inline
Alexis S. L. Carvalho
Add revlog.parentrevs function....
r2489 def parentrevs(self, rev):
Matt Mackall
revlog: add a magic null revision to our index...
r4979 return self.index[rev][5:7]
mason@suse.com
Implement revlogng....
r2072 def start(self, rev):
Matt Mackall
revlog: minor chunk speed-up
r5006 return int(self.index[rev][0] >> 16)
Matt Mackall
revlog: some codingstyle cleanups
r4980 def end(self, rev):
return self.start(rev) + self.length(rev)
def length(self, rev):
return self.index[rev][1]
def base(self, rev):
return self.index[rev][3]
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Fill in the uncompressed size during revlog.addgroup...
r2078 def size(self, rev):
"""return the length of the uncompressed text for a given revision"""
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 l = self.index[rev][2]
mason@suse.com
Fill in the uncompressed size during revlog.addgroup...
r2078 if l >= 0:
return l
t = self.revision(self.node(rev))
return len(t)
Matt Mackall
revlog: reachable actually takes a node
r3630 def reachable(self, node, stop=None):
Benoit Boissinot
revlog: use set instead of dict
r8464 """return the set of all nodes ancestral to a given node, including
Matt Mackall
add docstring to reachable
r3683 the node itself, stopping when stop is matched"""
Benoit Boissinot
revlog: use set instead of dict
r8464 reachable = set((node,))
Matt Mackall
revlog: reachable actually takes a node
r3630 visit = [node]
mason@suse.com
Add revlog.reachable to find a graph of ancestors for a given rev
r1074 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:
Benoit Boissinot
revlog: use set instead of dict
r8464 reachable.add(p)
mason@suse.com
Add revlog.reachable to find a graph of ancestors for a given rev
r1074 visit.append(p)
return reachable
Stefano Tortarolo
Add ancestors and descendants to revlog...
r6872 def ancestors(self, *revs):
Greg Ward
revlog: rewrite several method docstrings...
r10047 """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."""
Stefano Tortarolo
Add ancestors and descendants to revlog...
r6872 visit = list(revs)
Martin Geisler
util: use built-in set and frozenset...
r8150 seen = set([nullrev])
Stefano Tortarolo
Add ancestors and descendants to revlog...
r6872 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):
Greg Ward
revlog: rewrite several method docstrings...
r10047 """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)."""
Martin Geisler
util: use built-in set and frozenset...
r8150 seen = set(revs)
Stefano Tortarolo
Add ancestors and descendants to revlog...
r6872 for i in xrange(min(revs) + 1, len(self)):
for x in self.parentrevs(i):
if x != nullrev and x in seen:
seen.add(i)
yield i
break
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233 def findmissing(self, common=None, heads=None):
Greg Ward
revlog: rewrite several method docstrings...
r10047 """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:
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233
Greg Ward
revlog: rewrite several method docstrings...
r10047 1. N is an ancestor of some node in 'heads'
2. N is not an ancestor of any node in 'common'
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233
Greg Ward
revlog: rewrite several method docstrings...
r10047 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."""
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233 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
Martin Geisler
replace set-like dictionaries with real sets...
r8152 has = set(self.ancestors(*common))
has.add(nullrev)
has.update(common)
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233
# take all ancestors from heads that aren't in has
Benoit Boissinot
revlog.missing(): use sets instead of a dict
r8453 missing = set()
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233 visit = [r for r in heads if r not in has]
while visit:
r = visit.pop(0)
if r in missing:
continue
else:
Benoit Boissinot
revlog.missing(): use sets instead of a dict
r8453 missing.add(r)
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233 for p in self.parentrevs(r):
if p not in has:
visit.append(p)
Benoit Boissinot
revlog.missing(): use sets instead of a dict
r8453 missing = list(missing)
Benoit Boissinot
fix pull racing with push/commit (issue1320)...
r7233 missing.sort()
return [self.node(r) for r in missing]
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 def nodesbetween(self, roots=None, heads=None):
Greg Ward
revlog: rewrite several method docstrings...
r10047 """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'
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457
Greg Ward
revlog: rewrite several method docstrings...
r10047 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'.
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457
Greg Ward
revlog: rewrite several method docstrings...
r10047 '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."""
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 nonodes = ([], [], [])
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 if roots is not None:
roots = list(roots)
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 if not roots:
return nonodes
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 lowestrev = min([self.rev(n) for n in roots])
else:
roots = [nullid] # Everybody's a descendent of nullid
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 lowestrev = nullrev
if (lowestrev == nullrev) and (heads is None):
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # We want _all_ the nodes!
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 return ([self.node(r) for r in self], [nullid], list(self.heads()))
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 if heads is None:
# All nodes are ancestors, so the latest ancestor is the last
# node.
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 highestrev = len(self) - 1
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # 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:
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 heads = list(heads)
if not heads:
return nonodes
Benoit Boissinot
revlog: use set instead of dict
r8464 ancestors = set()
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # 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.
heads = dict.fromkeys(heads, 0)
Benoit Boissinot
nodesbetween: fix a bug with duplicate heads
r3360 # Start at the top and keep marking parents until we're done.
Martin Geisler
rebase, revlog: use set(x) instead of set(x.keys())...
r8163 nodestotag = set(heads)
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # 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:
# If we are possibly a descendent of one of the roots
# and we haven't already been marked as an ancestor
Benoit Boissinot
revlog: use set instead of dict
r8464 ancestors.add(n) # Mark as ancestor
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # Add non-nullid parents to list of nodes to tag.
Martin Geisler
revlog: let nodestotag be a set instead of a list
r8153 nodestotag.update([p for p in self.parents(n) if
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 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)
Eric Hopper
Fix small bug in nodesbetween if heads is [nullid].
r1459 if not ancestors:
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 return nonodes
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # 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.
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 if lowestrev > nullrev:
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # 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
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 return nonodes
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 else:
# We are descending from nullid, and don't need to care about
# any other roots.
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 lowestrev = nullrev
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 roots = [nullid]
Martin Geisler
replace set-like dictionaries with real sets...
r8152 # Transform our roots list into a set.
descendents = set(roots)
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 # Also, keep the original roots so we can filter out roots that aren't
# 'real' roots (i.e. are descended from other roots).
roots = descendents.copy()
# 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
# they're descendents.
for r in xrange(max(lowestrev, 0), highestrev + 1):
n = self.node(r)
isdescendent = False
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 if lowestrev == nullrev: # Everybody is a descendent of nullid
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 isdescendent = True
elif n in descendents:
# n is already a descendent
isdescendent = True
# This check only needs to be done here because all the roots
# will start being marked is descendents before the loop.
if n in roots:
# If n was a root, check if it's a 'real' root.
p = tuple(self.parents(n))
# If any of its parents are descendents, it's not a root.
if (p[0] in descendents) or (p[1] in descendents):
Martin Geisler
replace set-like dictionaries with real sets...
r8152 roots.remove(n)
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 else:
p = tuple(self.parents(n))
# A node is a descendent if either of its parents are
# descendents. (We seeded the dependents list with the roots
# up there, remember?)
if (p[0] in descendents) or (p[1] in descendents):
Martin Geisler
replace set-like dictionaries with real sets...
r8152 descendents.add(n)
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 isdescendent = True
if isdescendent and ((ancestors is None) or (n in ancestors)):
# Only include nodes that are both descendents and ancestors.
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
heads[n] = 1
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.
heads[n] = 1
# But, obviously its parents aren't.
for p in self.parents(n):
heads.pop(p, None)
heads = [n for n in heads.iterkeys() if heads[n] != 0]
Martin Geisler
replace set-like dictionaries with real sets...
r8152 roots = list(roots)
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 assert orderedout
assert roots
assert heads
return (orderedout, roots, heads)
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923 def heads(self, start=None, stop=None):
Benoit Boissinot
add a -r/--rev option to heads to show only heads descendant from rev
r1550 """return the list of all nodes that have no children
Thomas Arendsen Hein
Fixes to "hg heads -r FOO":...
r1551
if start is specified, only heads that are descendants of
start will be returned
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923 if stop is specified, it will consider all the revs from stop
as if they had no children
Thomas Arendsen Hein
Fixes to "hg heads -r FOO":...
r1551 """
Matt Mackall
revlog: implement a fast path for heads
r4991 if start is None and stop is None:
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 count = len(self)
Matt Mackall
revlog: implement a fast path for heads
r4991 if not count:
return [nullid]
ishead = [1] * (count + 1)
index = self.index
Matt Mackall
revlog: fix heads performance regression
r7089 for r in xrange(count):
Matt Mackall
revlog: implement a fast path for heads
r4991 e = index[r]
ishead[e[5]] = ishead[e[6]] = 0
Matt Mackall
revlog: fix heads performance regression
r7089 return [self.node(r) for r in xrange(count) if ishead[r]]
Matt Mackall
revlog: implement a fast path for heads
r4991
Thomas Arendsen Hein
Fixes to "hg heads -r FOO":...
r1551 if start is None:
start = nullid
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923 if stop is None:
stop = []
Martin Geisler
replace set-like dictionaries with real sets...
r8152 stoprevs = set([self.rev(n) for n in stop])
Benoit Boissinot
add a -r/--rev option to heads to show only heads descendant from rev
r1550 startrev = self.rev(start)
Benoit Boissinot
revlog: use set instead of dict
r8464 reachable = set((startrev,))
heads = set((startrev,))
mpm@selenic.com
Add some docstrings to revlog.py
r1083
Alexis S. L. Carvalho
Change revlog.heads to walk the revision graph using revision numbers...
r2490 parentrevs = self.parentrevs
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for r in xrange(startrev + 1, len(self)):
Alexis S. L. Carvalho
Change revlog.heads to walk the revision graph using revision numbers...
r2490 for p in parentrevs(r):
if p in reachable:
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923 if r not in stoprevs:
Benoit Boissinot
revlog: use set instead of dict
r8464 reachable.add(r)
heads.add(r)
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923 if p in heads and p not in stoprevs:
Benoit Boissinot
revlog: use set instead of dict
r8464 heads.remove(p)
Benoit Boissinot
fix calculation of new heads added during push with -r...
r3923
Alexis S. L. Carvalho
Change revlog.heads to walk the revision graph using revision numbers...
r2490 return [self.node(r) for r in heads]
mpm@selenic.com
revlog: add a children function...
r370
def children(self, node):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """find the children of a given node"""
mpm@selenic.com
revlog: add a children function...
r370 c = []
p = self.rev(node)
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for r in range(p + 1, len(self)):
Thomas Arendsen Hein
Fix revlog.children so the real children of the null revision can be calculated.
r4746 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))
mpm@selenic.com
revlog: add a children function...
r370 return c
mpm@selenic.com
Whitespace cleanups...
r515
Matt Mackall
Only look up tags and branches as a last resort
r3453 def _match(self, id):
Benoit Boissinot
correctly find the type of 'id' in revlog.lookup
r3210 if isinstance(id, (long, int)):
Benoit Boissinot
cleanups in revlog.lookup...
r3156 # rev
Benoit Boissinot
lookup should allow -1 to represent nullid (if passed an int as arg)
r2641 return self.node(id)
Matt Mackall
revlog.lookup tweaks...
r3438 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
Peter Arrenbrecht
cleanup: drop variables for unused return values...
r7874 self.rev(node) # quick search the index
Matt Mackall
revlog.lookup tweaks...
r3438 return node
Brendan Cully
Add revlog.LookupError exception, and use it instead of RevlogError....
r3930 except LookupError:
Matt Mackall
revlog.lookup tweaks...
r3438 pass # may be partial hex id
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 try:
Benoit Boissinot
cleanups in revlog.lookup...
r3156 # str(rev)
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 rev = int(id)
Matt Mackall
revlog: some codingstyle cleanups
r4980 if str(rev) != id:
raise ValueError
if rev < 0:
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 rev = len(self) + rev
if rev < 0 or rev >= len(self):
Matt Mackall
revlog: some codingstyle cleanups
r4980 raise ValueError
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 return self.node(rev)
mpm@selenic.com
Various node id lookup tweaks...
r469 except (ValueError, OverflowError):
Benoit Boissinot
cleanups in revlog.lookup...
r3156 pass
Matt Mackall
Only look up tags and branches as a last resort
r3453 if len(id) == 40:
try:
Matt Mackall
revlog.lookup tweaks...
r3438 # a full hex nodeid?
node = bin(id)
Peter Arrenbrecht
cleanup: drop variables for unused return values...
r7874 self.rev(node)
Benoit Boissinot
optimize revlog.lookup when passed hex(node)[:...]...
r3157 return node
Sune Foldager
provide nicer feedback when an unknown node id is passed to a command...
r7062 except (TypeError, LookupError):
Matt Mackall
Only look up tags and branches as a last resort
r3453 pass
def _partialmatch(self, id):
if len(id) < 40:
try:
Matt Mackall
revlog.lookup tweaks...
r3438 # hex(node)[:...]
Alejandro Santos
compat: use // for integer division
r9029 l = len(id) // 2 # grab an even number of digits
Matt Mackall
many, many trivial check-code fixups
r10282 bin_id = bin(id[:l * 2])
Matt Mackall
lookup: speed up partial lookup
r7365 nl = [n for n in self.nodemap if n[:l] == bin_id]
nl = [n for n in nl if hex(n).startswith(id)]
if len(nl) > 0:
if len(nl) == 1:
return nl[0]
raise LookupError(id, self.indexfile,
_('ambiguous identifier'))
return None
Matt Mackall
Only look up tags and branches as a last resort
r3453 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
mpm@selenic.com
Whitespace cleanups...
r515
Matt Mackall
revlog: report node and file when lookup fails
r6228 raise LookupError(id, self.indexfile, _('no match found'))
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36
Matt Mackall
Move cmp bits from filelog to revlog
r2890 def cmp(self, node, text):
"""compare text with a given file revision"""
p1, p2 = self.parents(node)
return hash(text, p1, p2) != node
Matt Mackall
revlog: clean up the chunk caching code
r8316 def _addchunk(self, offset, data):
o, d = self._chunkcache
# try to add to existing cache
if o + len(d) == offset and len(d) + len(data) < _prereadsize:
self._chunkcache = o, d + data
else:
self._chunkcache = offset, data
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 def _loadchunk(self, offset, length):
if self._inline:
df = self.opener(self.indexfile)
else:
df = self.opener(self.datafile)
Matt Mackall
revlog: clean up the chunk caching code
r8316
readahead = max(65536, length)
df.seek(offset)
d = df.read(readahead)
self._addchunk(offset, d)
if readahead > length:
return d[:length]
return d
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 def _getchunk(self, offset, length):
Matt Mackall
revlog: clean up the chunk caching code
r8316 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
return d[cachestart:cacheend]
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 return self._loadchunk(offset, length)
Matt Mackall
revlog: clean up the chunk caching code
r8316
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 def _chunkraw(self, startrev, endrev):
Matt Mackall
revlog: add cache priming for reconstructing delta chains
r8318 start = self.start(startrev)
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 length = self.end(endrev) - start
Matt Mackall
revlog: add cache priming for reconstructing delta chains
r8318 if self._inline:
start += (startrev + 1) * self._io.size
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 return self._getchunk(start, length)
Matt Mackall
revlog: add cache priming for reconstructing delta chains
r8318
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 def _chunk(self, rev):
return decompress(self._chunkraw(rev, rev))
def _chunkclear(self):
self._chunkcache = (0, '')
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598
Benoit Boissinot
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 def revdiff(self, rev1, rev2):
"""return or calculate a delta between two revisions"""
Matt Mackall
revlog: minor revdiff reorganization
r5005 if rev1 + 1 == rev2 and self.base(rev1) == self.base(rev2):
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 return self._chunk(rev2)
Matt Mackall
revlog: minor revdiff reorganization
r5005
return mdiff.textdiff(self.revision(self.node(rev1)),
self.revision(self.node(rev2)))
mpm@selenic.com
Add code to retrieve or construct a revlog delta
r119
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 def revision(self, node):
Martin Geisler
Fixed docstring typos
r6912 """return an uncompressed revision of a given node"""
Matt Mackall
revlog: some codingstyle cleanups
r4980 if node == nullid:
return ""
Matt Mackall
revlog: mark cache private
r4984 if self._cache and self._cache[0] == node:
Benoit Boissinot
manifest/revlog: do not let the revlog cache mutable objects...
r9420 return self._cache[2]
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Add some docstrings to revlog.py
r1083 # look up what we need to read
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 text = None
rev = self.rev(node)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 base = self.base(rev)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: move flag checking out of the offset fastpath
r5004 # check rev flags
if self.index[rev][0] & 0xFFFF:
Matt Mackall
revlog: more robust for damaged indexes...
r5312 raise RevlogError(_('incompatible revision flag %x') %
(self.index[rev][0] & 0xFFFF))
Matt Mackall
revlog: move flag checking out of the offset fastpath
r5004
mpm@selenic.com
Add some docstrings to revlog.py
r1083 # do we have useful data cached?
Matt Mackall
revlog: mark cache private
r4984 if self._cache and self._cache[1] >= base and self._cache[1] < rev:
base = self._cache[1]
Benoit Boissinot
manifest/revlog: do not let the revlog cache mutable objects...
r9420 text = self._cache[2]
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 self._loadindex(base, rev + 1)
self._chunkraw(base, rev)
if text is None:
text = self._chunk(base)
bins = [self._chunk(r) for r in xrange(base + 1, rev + 1)]
Matt Mackall
revlog: eliminate diff and patches functions...
r4989 text = mdiff.patches(text, bins)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 p1, p2 = self.parents(node)
mpm@selenic.com
Simplify integrity checking...
r26 if node != hash(text, p1, p2):
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 raise RevlogError(_("integrity check failed on %s:%d")
Matt Mackall
revlog: report indexfile rather than datafile for integrity check
r8643 % (self.indexfile, rev))
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: mark cache private
r4984 self._cache = (node, rev, text)
mpm@selenic.com
Whitespace cleanups...
r515 return text
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Make the appendfile class inline-data index friendly...
r2075 def checkinlinesize(self, tr, fp=None):
Matt Mackall
revlog: use index to find index size
r8315 if not self._inline or (self.start(-2) + self.length(-2)) < 131072:
mason@suse.com
Implement data inlined with the index file...
r2073 return
Matt Mackall
revlog: use index to find index size
r8315
Chris Mason
...
r2084 trinfo = tr.find(self.indexfile)
Martin Geisler
use 'x is None' instead of 'x == None'...
r8527 if trinfo is None:
Thomas Arendsen Hein
Indentation cleanups for 2956948b81f3.
r3680 raise RevlogError(_("%s not found in the transaction")
% self.indexfile)
Chris Mason
...
r2084
trindex = trinfo[2]
dataoff = self.start(trindex)
tr.add(self.datafile, dataoff)
Matt Mackall
revlog: use index to find index size
r8315
Matt Mackall
revlog: use chunk cache to avoid rereading when splitting inline files
r8317 if fp:
fp.flush()
fp.close()
Matt Mackall
revlog: use index to find index size
r8315
mason@suse.com
Implement data inlined with the index file...
r2073 df = self.opener(self.datafile, 'w')
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 try:
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for r in self:
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 df.write(self._chunkraw(r, r))
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 finally:
df.close()
mason@suse.com
Create an atomic opener that does not automatically rename on close...
r2076 fp = self.opener(self.indexfile, 'w', atomictemp=True)
mason@suse.com
Implement data inlined with the index file...
r2073 self.version &= ~(REVLOGNGINLINEDATA)
Matt Mackall
revlog: change _inline from a function to a variable
r4982 self._inline = False
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for i in self:
Alexis S. L. Carvalho
revlog: fix revlogio.packentry corner case...
r5338 e = self._io.packentry(self.index[i], self.node, self.version, i)
mason@suse.com
Implement data inlined with the index file...
r2073 fp.write(e)
mason@suse.com
Create an atomic opener that does not automatically rename on close...
r2076 # if we don't call rename, the temp file will never replace the
# real index
fp.rename()
Chris Mason
...
r2084
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 tr.replace(self.indexfile, trindex * self._io.size)
self._chunkclear()
mason@suse.com
Implement data inlined with the index file...
r2073
Matt Mackall
revlog: simplify addrevision...
r4981 def addrevision(self, text, transaction, link, p1, p2, d=None):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """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
d - an optional precomputed delta
"""
Matt Mackall
revlog: simplify addrevision...
r4981 dfh = None
Matt Mackall
revlog: change _inline from a function to a variable
r4982 if not self._inline:
Alexis S. L. Carvalho
make revlog.addgroup pass its file handles to addrevision...
r3390 dfh = self.opener(self.datafile, "a")
ifh = self.opener(self.indexfile, "a+")
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 try:
return self._addrevision(text, transaction, link, p1, p2, d, ifh, dfh)
finally:
if dfh:
dfh.close()
ifh.close()
Alexis S. L. Carvalho
make revlog.addgroup pass its file handles to addrevision...
r3390
def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh):
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 node = hash(text, p1, p2)
mpm@selenic.com
revlog: allow duplicates...
r301 if node in self.nodemap:
return node
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 curr = len(self)
Matt Mackall
revlog: simplify addrevision...
r4981 prev = curr - 1
base = self.base(prev)
offset = self.end(prev)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: simplify addrevision...
r4981 if curr:
mason@suse.com
Performance enhancements for manifest.add()...
r644 if not d:
Matt Mackall
revlog: simplify addrevision...
r4981 ptext = self.revision(self.node(prev))
Matt Mackall
revlog: eliminate diff and patches functions...
r4989 d = mdiff.textdiff(ptext, text)
mpm@selenic.com
Add paranoia to diff code
r98 data = compress(d)
mason@suse.com
Reduce string duplication in compression code...
r1533 l = len(data[1]) + len(data[0])
Matt Mackall
revlog: simplify addrevision...
r4981 dist = l + offset - self.start(base)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
# full versions are inserted when the needed deltas
# become comparable to the uncompressed text
Matt Mackall
revlog: simplify addrevision...
r4981 if not curr or dist > len(text) * 2:
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 data = compress(text)
mason@suse.com
Reduce string duplication in compression code...
r1533 l = len(data[1]) + len(data[0])
Matt Mackall
revlog: simplify addrevision...
r4981 base = curr
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 e = (offset_type(offset, 0), l, len(text),
base, link, self.rev(p1), self.rev(p2), node)
Matt Mackall
revlog: add a magic null revision to our index...
r4979 self.index.insert(-1, e)
Matt Mackall
revlog: simplify addrevision...
r4981 self.nodemap[node] = curr
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977
Alexis S. L. Carvalho
revlog: fix revlogio.packentry corner case...
r5338 entry = self._io.packentry(e, self.node, self.version, curr)
Matt Mackall
revlog: change _inline from a function to a variable
r4982 if not self._inline:
mason@suse.com
Implement data inlined with the index file...
r2073 transaction.add(self.datafile, offset)
Matt Mackall
revlog: simplify addrevision...
r4981 transaction.add(self.indexfile, curr * len(entry))
mason@suse.com
Implement data inlined with the index file...
r2073 if data[0]:
Alexis S. L. Carvalho
make revlog.addgroup pass its file handles to addrevision...
r3390 dfh.write(data[0])
dfh.write(data[1])
dfh.flush()
Matt Mackall
revlog: simplify addrevision...
r4981 ifh.write(entry)
mason@suse.com
Implement data inlined with the index file...
r2073 else:
Matt Mackall
revlog: avoid some unnecessary seek/tell syscalls
r4996 offset += curr * self._io.size
Patrick Mezard
revlog: fix inlined revision transaction extra data (issue 749)
r5324 transaction.add(self.indexfile, offset, curr)
Matt Mackall
revlog: simplify addrevision...
r4981 ifh.write(entry)
Alexis S. L. Carvalho
make revlog.addgroup pass its file handles to addrevision...
r3390 ifh.write(data[0])
ifh.write(data[1])
self.checkinlinesize(transaction, ifh)
mason@suse.com
Implement data inlined with the index file...
r2073
Benoit Boissinot
manifest/revlog: do not let the revlog cache mutable objects...
r9420 if type(text) == str: # only accept immutable objects
self._cache = (node, curr, text)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 return node
Dirkjan Ochtman
revlog: fix up previously stupid API change
r10329 def descendant(self, start, end):
for i in self.descendants(start):
if i == end:
Dirkjan Ochtman
revlog: add a fast path for checking ancestry
r10325 return True
Dirkjan Ochtman
revlog: fix up previously stupid API change
r10329 elif i > end:
Dirkjan Ochtman
revlog: add a fast path for checking ancestry
r10325 break
return False
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 def ancestor(self, a, b):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """calculate the least common ancestor of nodes a and b"""
Chris Mason
Speedup revlog.ancestors for the linear case...
r2081
Dirkjan Ochtman
revlog: fix up previously stupid API change
r10329 # fast path, check if it is a descendant
a, b = self.rev(a), self.rev(b)
Benoit Boissinot
revlog: add fast path to ancestor
r9991 start, end = sorted((a, b))
Dirkjan Ochtman
revlog: fix up previously stupid API change
r10329 if self.descendant(start, end):
Dirkjan Ochtman
revlog: add a fast path for checking ancestry
r10325 return self.node(start)
Benoit Boissinot
revlog: add fast path to ancestor
r9991
Matt Mackall
Switch revlog.ancestor to use revisions rather than nodeids
r3139 def parents(rev):
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 return [p for p in self.parentrevs(rev) if p != nullrev]
mpm@selenic.com
Whitespace cleanups...
r515
Benoit Boissinot
revlog: add fast path to ancestor
r9991 c = ancestor.ancestor(a, b, parents)
Matt Mackall
Switch revlog.ancestor to use revisions rather than nodeids
r3139 if c is None:
return nullid
return self.node(c)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 def group(self, nodelist, lookup, infocollect=None):
Greg Ward
Improve some docstrings relating to changegroups and prepush().
r9437 """Calculate a delta group, yielding a sequence of changegroup chunks
(strings).
mpm@selenic.com
Add changegroup support
r46
mpm@selenic.com
Add some docstrings to revlog.py
r1083 Given a list of changeset revs, return a set of deltas and
metadata corresponding to nodes. the first delta is
parent(nodes[0]) -> nodes[0] the receiver is guaranteed to
have this parent as it has all history before these
changesets. parent is parent[0]
"""
mpm@selenic.com
Add changegroup support
r46
Benoit Boissinot
changegroup: the node list might be an empty generator (fix issue1678)
r8634 revs = [self.rev(n) for n in nodelist]
mpm@selenic.com
Add changegroup support
r46 # if we don't have any revisions touched by these changesets, bail
Benoit Boissinot
changegroup: the node list might be an empty generator (fix issue1678)
r8634 if not revs:
Thomas Arendsen Hein
make incoming work via ssh (issue139); move chunk code into separate module....
r1981 yield changegroup.closechunk()
mpm@selenic.com
Changes to network protocol...
r192 return
mpm@selenic.com
Add changegroup support
r46
# add the parent of the first rev
Peter Arrenbrecht
revlog: slightly tune group() by not going rev->node->rev
r8391 p = self.parentrevs(revs[0])[0]
revs.insert(0, p)
mpm@selenic.com
Add changegroup support
r46
# build deltas
Martin Geisler
replace xrange(0, n) with xrange(n)
r8624 for d in xrange(len(revs) - 1):
mpm@selenic.com
Add changegroup support
r46 a, b = revs[d], revs[d + 1]
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 nb = self.node(b)
mpm@selenic.com
Changes to network protocol...
r192
Eric Hopper
This changes the revlog.group and re-implements the localrepo.changeroup...
r1458 if infocollect is not None:
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 infocollect(nb)
Eric Hopper
This changes the revlog.group and re-implements the localrepo.changeroup...
r1458
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 p = self.parents(nb)
meta = nb + p[0] + p[1] + lookup(nb)
Matt Mackall
revlog: generate trivial deltas against null revision...
r5367 if a == -1:
d = self.revision(nb)
meta += mdiff.trivialdiffheader(len(d))
else:
d = self.revdiff(a, b)
Matt Mackall
changegroup: avoid large copies...
r5368 yield changegroup.chunkheader(len(meta) + len(d))
yield meta
Matt Mackall
revlog: avoid large yields in group()...
r5448 if len(d) > 2**20:
pos = 0
while pos < len(d):
pos2 = pos + 2 ** 18
yield d[pos:pos2]
pos = pos2
else:
yield d
mpm@selenic.com
Add changegroup support
r46
Thomas Arendsen Hein
make incoming work via ssh (issue139); move chunk code into separate module....
r1981 yield changegroup.closechunk()
mpm@selenic.com
Changes to network protocol...
r192
Peter Arrenbrecht
drop superfluous param from revlog.addgroup()
r6647 def addgroup(self, revs, linkmapper, transaction):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """
add a delta group
mpm@selenic.com
Add changegroup support
r46
mpm@selenic.com
Add some docstrings to revlog.py
r1083 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.
"""
#track the base of the current delta log
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 r = len(self)
mpm@selenic.com
Add changegroup support
r46 t = r - 1
Thomas Arendsen Hein
Calling revlog.addgroup with an empty changegroup now raises RevlogError....
r2002 node = None
mpm@selenic.com
Whitespace cleanups...
r515
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 base = prev = nullrev
mason@suse.com
Fill in the uncompressed size during revlog.addgroup...
r2078 start = end = textlen = 0
mpm@selenic.com
Add changegroup support
r46 if r:
end = self.end(t)
mason@suse.com
Implement revlogng....
r2072 ifh = self.opener(self.indexfile, "a+")
Matt Mackall
revlog: avoid some unnecessary seek/tell syscalls
r4996 isize = r * self._io.size
Matt Mackall
revlog: change _inline from a function to a variable
r4982 if self._inline:
Matt Mackall
revlog: avoid some unnecessary seek/tell syscalls
r4996 transaction.add(self.indexfile, end + isize, r)
mason@suse.com
Implement data inlined with the index file...
r2073 dfh = None
else:
Matt Mackall
revlog: avoid some unnecessary seek/tell syscalls
r4996 transaction.add(self.indexfile, isize, r)
mason@suse.com
Implement data inlined with the index file...
r2073 transaction.add(self.datafile, end)
dfh = self.opener(self.datafile, "a")
mpm@selenic.com
Add changegroup support
r46
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 try:
# loop through our set of deltas
chain = None
for chunk in revs:
node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
link = linkmapper(cs)
if node in self.nodemap:
# this can happen if two branches make the same change
chain = node
continue
delta = buffer(chunk, 80)
del chunk
mpm@selenic.com
Changes to network protocol...
r192
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 for p in (p1, p2):
if not p in self.nodemap:
raise LookupError(p, self.indexfile, _('unknown parent'))
mpm@selenic.com
Add changegroup support
r46
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 if not chain:
# retrieve the parent revision of the delta chain
chain = p1
if not chain in self.nodemap:
raise LookupError(chain, self.indexfile, _('unknown base'))
mpm@selenic.com
Add changegroup support
r46
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 # full versions are inserted when the needed deltas become
# comparable to the uncompressed text or when the previous
# version is not the one we have a delta against. We use
# the size of the previous full rev as a proxy for the
# current size.
if chain == prev:
cdelta = compress(delta)
cdeltalen = len(cdelta[0]) + len(cdelta[1])
textlen = mdiff.patchedsize(textlen, delta)
if chain != prev or (end - start + cdeltalen) > textlen * 2:
# flush our writes here so we can read it in revision
if dfh:
dfh.flush()
ifh.flush()
text = self.revision(chain)
if len(text) == 0:
# skip over trivial delta header
text = buffer(delta, 12)
else:
text = mdiff.patches(text, [delta])
del delta
chk = self._addrevision(text, transaction, link, p1, p2, None,
ifh, dfh)
if not dfh and not self._inline:
# addrevision switched from inline to conventional
# reopen the index
mason@suse.com
Implement data inlined with the index file...
r2073 dfh = self.opener(self.datafile, "a")
ifh = self.opener(self.indexfile, "a")
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 if chk != node:
raise RevlogError(_("consistency error adding group"))
textlen = len(text)
mason@suse.com
Implement data inlined with the index file...
r2073 else:
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 e = (offset_type(end, 0), cdeltalen, textlen, base,
link, self.rev(p1), self.rev(p2), node)
self.index.insert(-1, e)
self.nodemap[node] = r
entry = self._io.packentry(e, self.node, self.version, r)
if self._inline:
ifh.write(entry)
ifh.write(cdelta[0])
ifh.write(cdelta[1])
self.checkinlinesize(transaction, ifh)
if not self._inline:
dfh = self.opener(self.datafile, "a")
ifh = self.opener(self.indexfile, "a")
else:
dfh.write(cdelta[0])
dfh.write(cdelta[1])
ifh.write(entry)
mpm@selenic.com
Add changegroup support
r46
Benoit Boissinot
revlog: make sure the files are closed after an exception happens...
r6261 t, r, chain, prev = r, r + 1, node, node
base = self.base(t)
start = self.start(base)
end = self.end(t)
finally:
if dfh:
dfh.close()
ifh.close()
mpm@selenic.com
Add changegroup support
r46
return node
Matt Mackall
verify: add check for mismatch of index and data length
r1493
Henrik Stuart
strip: make repair.strip transactional to avoid repository corruption...
r8073 def strip(self, minlink, transaction):
Alexis S. L. Carvalho
simplify revlog.strip interface and callers; add docstring...
r5910 """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
removed and that it'll readd them after this truncation.
"""
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 if len(self) == 0:
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 return
mason@suse.com
Implement revlogng....
r2072 if isinstance(self.index, lazyindex):
Matt Mackall
revlog: privatize some methods
r4920 self._loadindexmap()
mason@suse.com
Implement revlogng....
r2072
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for rev in self:
Alexis S. L. Carvalho
strip: calculate list of extra nodes to save and pass it to changegroupsubset...
r5909 if self.index[rev][4] >= minlink:
break
else:
return
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
# first truncate the files on disk
end = self.start(rev)
Matt Mackall
revlog: change _inline from a function to a variable
r4982 if not self._inline:
Henrik Stuart
strip: make repair.strip transactional to avoid repository corruption...
r8073 transaction.add(self.datafile, end)
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 end = rev * self._io.size
mason@suse.com
Implement data inlined with the index file...
r2073 else:
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 end += rev * self._io.size
mason@suse.com
Implement revlogng....
r2072
Henrik Stuart
strip: make repair.strip transactional to avoid repository corruption...
r8073 transaction.add(self.indexfile, end)
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
# then reset internal state in memory to forget those revisions
Matt Mackall
revlog: mark cache private
r4984 self._cache = None
Matt Mackall
revlog: refactor chunk cache interface again...
r8650 self._chunkclear()
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for x in xrange(rev, len(self)):
mason@suse.com
Implement revlogng....
r2072 del self.nodemap[self.node(x)]
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
Matt Mackall
revlog: add a magic null revision to our index...
r4979 del self.index[rev:-1]
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
Matt Mackall
verify: add check for mismatch of index and data length
r1493 def checksize(self):
expected = 0
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 if len(self):
expected = max(0, self.end(len(self) - 1))
Matt Mackall
verify: notice extra data in indices
r1667
Matt Mackall
Handle empty logs in repo.checksize
r1494 try:
f = self.opener(self.datafile)
f.seek(0, 2)
actual = f.tell()
Matt Mackall
verify: notice extra data in indices
r1667 dd = actual - expected
Matt Mackall
Handle empty logs in repo.checksize
r1494 except IOError, inst:
Matt Mackall
verify: notice extra data in indices
r1667 if inst.errno != errno.ENOENT:
raise
dd = 0
try:
f = self.opener(self.indexfile)
f.seek(0, 2)
actual = f.tell()
Matt Mackall
revlog: parse revlogv0 indexes into v1 internally...
r4977 s = self._io.size
Alejandro Santos
compat: use // for integer division
r9029 i = max(0, actual // s)
Matt Mackall
verify: notice extra data in indices
r1667 di = actual - (i * s)
Matt Mackall
revlog: change _inline from a function to a variable
r4982 if self._inline:
mason@suse.com
Implement data inlined with the index file...
r2073 databytes = 0
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for r in self:
Matt Mackall
revlog: more robust for damaged indexes...
r5312 databytes += max(0, self.length(r))
mason@suse.com
Implement data inlined with the index file...
r2073 dd = 0
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 di = actual - len(self) * s - databytes
Matt Mackall
verify: notice extra data in indices
r1667 except IOError, inst:
if inst.errno != errno.ENOENT:
raise
di = 0
return (dd, di)
Adrian Buehlmann
revlog: add files method
r6891
def files(self):
Matt Mackall
many, many trivial check-code fixups
r10282 res = [self.indexfile]
Adrian Buehlmann
revlog: add files method
r6891 if not self._inline:
res.append(self.datafile)
return res