##// END OF EJS Templates
Make the appendfile class inline-data index friendly...
Make the appendfile class inline-data index friendly The appendfile class needs a few changes to make it work with interleaved index files. It needs to support the tell() method, opening in a+ mode, and it needs to delay the checkinlinesize call until after the append file is written. Given that open(file, "a+") doesn't always seek to the end of the file, this adds seek operations to appendfile that understand whence args

File last commit:

r2075:343aeefb default
r2075:343aeefb default
Show More
revlog.py
1064 lines | 36.0 KiB | text/x-python | PythonLexer
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """
revlog.py - storage back-end for mercurial
This provides efficient delta storage with O(1) retrieve and append
and O(changes) merge between branches
Copyright 2005 Matt Mackall <mpm@selenic.com>
This software may be used and distributed according to the terms
of the GNU General Public License, incorporated herein by reference.
"""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Break apart hg.py...
r1089 from node import *
Benoit Boissinot
i18n first part: make '_' available for files who need it
r1400 from i18n import gettext as _
Bryan O'Sullivan
Make revlog constructor more discerning in its treatment of errors.
r1322 from demandload import demandload
Thomas Arendsen Hein
make incoming work via ssh (issue139); move chunk code into separate module....
r1981 demandload(globals(), "binascii changegroup errno heapq mdiff os")
demandload(globals(), "sha struct zlib")
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36
mason@suse.com
Implement revlogng....
r2072 # revlog version strings
REVLOGV0 = 0
REVLOGNG = 1
mason@suse.com
Implement data inlined with the index file...
r2073 # revlog flags
REVLOGNGINLINEDATA = (1 << 16)
def flagstr(flag):
if flag == "inline":
return REVLOGNGINLINEDATA
raise RevlogError(_("unknown revlog flag %s" % flag))
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.
"""
l = [p1, p2]
l.sort()
s = sha.new(l[0])
s.update(l[1])
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 """
mason@suse.com
Reduce string duplication in compression code...
r1533 if not text: return ("", text)
mpm@selenic.com
Make compression more intelligent:...
r112 if len(text) < 44:
mason@suse.com
Reduce string duplication in compression code...
r1533 if text[0] == '\0': return ("", text)
return ('u', text)
mpm@selenic.com
Make compression more intelligent:...
r112 bin = zlib.compress(text)
if len(bin) > len(text):
mason@suse.com
Reduce string duplication in compression code...
r1533 if text[0] == '\0': return ("", text)
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 """
mpm@selenic.com
Make compression more intelligent:...
r112 if not bin: return bin
t = bin[0]
if t == '\0': return bin
if t == 'x': return zlib.decompress(bin)
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
mason@suse.com
Implement revlogng....
r2072 indexformatv0 = ">4l20s20s20s"
# 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"
versionformat = ">i"
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
By default we parse and load 1000 entries at a time.
If no position is specified, we load the whole index, and replace
the lazy objects in revlog with the underlying objects for
efficiency in cases where we look at most of the nodes.
"""
mason@suse.com
Implement revlogng....
r2072 def __init__(self, data, revlog, indexformat):
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 self.data = data
self.s = struct.calcsize(indexformat)
mason@suse.com
Implement revlogng....
r2072 self.indexformat = indexformat
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 self.l = len(data)/self.s
self.index = [None] * self.l
self.map = {nullid: -1}
mpm@selenic.com
lazyparser speed ups...
r323 self.all = 0
self.revlog = revlog
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76
mpm@selenic.com
lazyparser speed ups...
r323 def load(self, pos=None):
if self.all: return
if pos is not None:
block = pos / 1000
i = block * 1000
end = min(self.l, i + 1000)
else:
self.all = 1
i = 0
end = self.l
self.revlog.index = self.index
self.revlog.nodemap = self.map
mpm@selenic.com
Whitespace cleanups...
r515
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 while i < end:
mason@suse.com
Implement revlogng....
r2072 if not self.index[i]:
d = self.data[i * self.s: (i + 1) * self.s]
e = struct.unpack(self.indexformat, d)
self.index[i] = e
self.map[e[-1]] = i
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 i += 1
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)
mpm@selenic.com
Make lazyindex load slightly faster
r115 self.p.load(pos)
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):
mpm@selenic.com
Make lazyindex load slightly faster
r115 return self.p.index[pos] or self.load(pos)
mason@suse.com
Implement revlogng....
r2072 def __setitem__(self, pos, item):
self.p.index[pos] = item
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 def __delitem__(self, pos):
del self.p.index[pos]
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 def append(self, e):
self.p.index.append(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):
mpm@selenic.com
lazyparser speed ups...
r323 if self.p.all: return
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 n = self.p.data.find(key)
mpm@selenic.com
Smarter handling of revlog key errors...
r1214 if n < 0:
raise KeyError(key)
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 pos = n / self.p.s
self.p.load(pos)
def __contains__(self, key):
mpm@selenic.com
lazyparser speed ups...
r323 self.p.load()
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):
try:
mason@suse.com
Implement revlogng....
r2072 yield self.p.index[i][-1]
mpm@selenic.com
Add iterator to the lazymap code
r97 except:
self.p.load(i)
mason@suse.com
Implement revlogng....
r2072 yield self.p.index[i][-1]
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
Bart Trojanowski
[PATCH] raise exceptions with Exception subclasses...
r1073 class RevlogError(Exception): pass
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
information on each revision, includings its nodeid (hash), the
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.
"""
mason@suse.com
Implement revlogng....
r2072 def __init__(self, opener, indexfile, datafile, defversion=0):
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
self.datafile = datafile
self.opener = opener
Benoit Boissinot
revalidate revlog data after locking the repo (issue132)
r1784
self.indexstat = None
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 self.cache = None
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 self.chunkcache = None
mason@suse.com
Implement revlogng....
r2072 self.defversion = defversion
Benoit Boissinot
revalidate revlog data after locking the repo (issue132)
r1784 self.load()
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
Benoit Boissinot
revalidate revlog data after locking the repo (issue132)
r1784 def load(self):
mason@suse.com
Implement revlogng....
r2072 v = self.defversion
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)
mason@suse.com
Implement revlogng....
r2072 i = f.read()
Bryan O'Sullivan
Make revlog constructor more discerning in its treatment of errors.
r1322 except IOError, inst:
if inst.errno != errno.ENOENT:
raise
mpm@selenic.com
Add lazy{parser,index,map} to speed up processing of index files
r76 i = ""
Benoit Boissinot
revalidate revlog data after locking the repo (issue132)
r1784 else:
try:
st = os.fstat(f.fileno())
except AttributeError, inst:
st = None
else:
oldst = self.indexstat
if (oldst and st.st_dev == oldst.st_dev
and st.st_ino == oldst.st_ino
and st.st_mtime == oldst.st_mtime
and st.st_ctime == oldst.st_ctime):
return
mason@suse.com
Implement revlogng....
r2072 self.indexstat = st
if len(i) > 0:
v = struct.unpack(versionformat, i[:4])[0]
mason@suse.com
Implement data inlined with the index file...
r2073 flags = v & ~0xFFFF
fmt = v & 0xFFFF
if fmt == 0:
if flags:
raise RevlogError(_("index %s invalid flags %x for format v0" %
(self.indexfile, flags)))
elif fmt == REVLOGNG:
if flags & ~REVLOGNGINLINEDATA:
raise RevlogError(_("index %s invalid flags %x for revlogng" %
(self.indexfile, flags)))
else:
raise RevlogError(_("index %s invalid format %d" %
(self.indexfile, fmt)))
mason@suse.com
Implement revlogng....
r2072 self.version = v
if v == 0:
self.indexformat = indexformatv0
else:
self.indexformat = indexformatng
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
mason@suse.com
Implement revlogng....
r2072 if i:
mason@suse.com
Implement data inlined with the index file...
r2073 if not self.inlinedata() and st and st.st_size > 10000:
mason@suse.com
Implement revlogng....
r2072 # big index, let's parse it on demand
parser = lazyparser(i, self, self.indexformat)
self.index = lazyindex(parser)
self.nodemap = lazymap(parser)
else:
self.parseindex(i)
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
# we've already got the entire data file read in, save it
# in the chunk data
self.chunkcache = (0, i)
mason@suse.com
Implement revlogng....
r2072 if self.version != 0:
e = list(self.index[0])
type = self.ngtype(e[0])
e[0] = self.offset_type(0, type)
self.index[0] = e
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116 else:
mason@suse.com
Implement revlogng....
r2072 self.nodemap = { nullid: -1}
self.index = []
def parseindex(self, data):
s = struct.calcsize(self.indexformat)
l = len(data)
self.index = []
self.nodemap = {nullid: -1}
mason@suse.com
Implement data inlined with the index file...
r2073 inline = self.inlinedata()
mason@suse.com
Implement revlogng....
r2072 off = 0
n = 0
while off < l:
e = struct.unpack(self.indexformat, data[off:off + s])
self.index.append(e)
self.nodemap[e[-1]] = n
n += 1
off += s
mason@suse.com
Implement data inlined with the index file...
r2073 if inline:
off += e[1]
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
mason@suse.com
Implement revlogng....
r2072 def ngoffset(self, q):
if q & 0xFFFF:
raise RevlogError(_('%s: incompatible revision flag %x') %
(self.indexfile, type))
return long(q >> 16)
def ngtype(self, q):
return int(q & 0xFFFF)
mpm@selenic.com
Only use lazy indexing for big indices and avoid the overhead of the...
r116
mason@suse.com
Implement revlogng....
r2072 def offset_type(self, offset, type):
return long(long(offset) << 16 | type)
def loadindexmap(self):
"""loads both the map and the index from the lazy parser"""
if isinstance(self.index, lazyindex):
p = self.index.p
p.load()
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Implement data inlined with the index file...
r2073 def inlinedata(self): return self.version & REVLOGNGINLINEDATA
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 def tip(self): return self.node(len(self.index) - 1)
def count(self): return len(self.index)
mason@suse.com
Implement revlogng....
r2072 def node(self, rev):
return (rev < 0) and nullid or self.index[rev][-1]
Bryan O'Sullivan
revlog: raise informative exception if file is missing.
r1201 def rev(self, node):
try:
return self.nodemap[node]
except KeyError:
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 raise RevlogError(_('%s: no node %s') % (self.indexfile, hex(node)))
mason@suse.com
Implement revlogng....
r2072 def linkrev(self, node): return self.index[self.rev(node)][-4]
mpm@selenic.com
Handle nullid better for ancestor
r2 def parents(self, node):
if node == nullid: return (nullid, nullid)
mason@suse.com
Implement revlogng....
r2072 r = self.rev(node)
d = self.index[r][-3:-1]
if self.version == 0:
return d
return [ self.node(x) for x in d ]
def start(self, rev):
if rev < 0:
return -1
if self.version != 0:
return self.ngoffset(self.index[rev][0])
return self.index[rev][0]
def end(self, rev): return self.start(rev) + self.length(rev)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Benoit Boissinot
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 def length(self, rev):
if rev < 0:
return 0
else:
return self.index[rev][1]
mason@suse.com
Implement revlogng....
r2072 def base(self, rev): return (rev < 0) and rev or self.index[rev][-5]
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Add revlog.reachable to find a graph of ancestors for a given rev
r1074 def reachable(self, rev, stop=None):
reachable = {}
visit = [rev]
reachable[rev] = 1
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:
reachable[p] = 1
visit.append(p)
return reachable
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 def nodesbetween(self, roots=None, heads=None):
"""Return a tuple containing three elements. Elements 1 and 2 contain
a final list bases and heads after all the unreachable ones have been
pruned. Element 0 contains a topologically sorted list of all
nodes that satisfy these constraints:
1. All nodes must be descended from a node in roots (the nodes on
roots are considered descended from themselves).
2. All nodes must also be ancestors of a node in heads (the nodes in
heads are considered to be their own ancestors).
If roots is unspecified, nullid is assumed as the only root.
If heads is unspecified, it is taken to be the output of the
heads method (i.e. a list of all nodes in the repository that
have no children)."""
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
lowestrev = -1
if (lowestrev == -1) and (heads is None):
# We want _all_ the nodes!
return ([self.node(r) for r in xrange(0, self.count())],
[nullid], list(self.heads()))
if heads is None:
# All nodes are ancestors, so the latest ancestor is the last
# node.
highestrev = self.count() - 1
# 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
Eric Hopper
This implements the nodesbetween method, and it removes the newer method...
r1457 ancestors = {}
# Start at the top and keep marking parents until we're done.
Eric Hopper
Fix to handle case of empty list for roots or heads in nodesbetween.
r1463 nodestotag = heads[:]
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)
# 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
ancestors[n] = 1 # Mark as ancestor
# Add non-nullid parents to list of nodes to tag.
nodestotag.extend([p for p in self.parents(n) if
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.
if lowestrev > -1:
# 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.
lowestrev = -1
roots = [nullid]
# Transform our roots list into a 'set' (i.e. a dictionary where the
# values don't matter.
descendents = dict.fromkeys(roots, 1)
# 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
if lowestrev == -1: # Everybody is a descendent of nullid
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):
roots.pop(n)
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):
descendents[n] = 1
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]
roots = roots.keys()
assert orderedout
assert roots
assert heads
return (orderedout, roots, heads)
Thomas Arendsen Hein
Fixes to "hg heads -r FOO":...
r1551 def heads(self, start=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
"""
if start is None:
start = nullid
Benoit Boissinot
add a -r/--rev option to heads to show only heads descendant from rev
r1550 reachable = {start: 1}
heads = {start: 1}
startrev = self.rev(start)
mpm@selenic.com
Add some docstrings to revlog.py
r1083
Benoit Boissinot
add a -r/--rev option to heads to show only heads descendant from rev
r1550 for r in xrange(startrev + 1, self.count()):
mpm@selenic.com
Beginning of multi-head support...
r221 n = self.node(r)
for pn in self.parents(n):
Benoit Boissinot
add a -r/--rev option to heads to show only heads descendant from rev
r1550 if pn in reachable:
reachable[n] = 1
heads[n] = 1
if pn in heads:
del heads[pn]
return heads.keys()
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)
for r in range(p + 1, self.count()):
n = self.node(r)
for pn in self.parents(n):
Tristan Wibberley
Fixed revlog.children....
r854 if pn == node:
c.append(n)
mpm@selenic.com
revlog: add a children function...
r370 continue
elif pn == nullid:
continue
return c
mpm@selenic.com
Whitespace cleanups...
r515
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 def lookup(self, id):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """locate a node based on revision number or subset of hex nodeid"""
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 try:
rev = int(id)
mpm@selenic.com
Various node id lookup tweaks...
r469 if str(rev) != id: raise ValueError
if rev < 0: rev = self.count() + rev
Thomas Arendsen Hein
Really _call_ method revlog.count in revlog.lookup()...
r476 if rev < 0 or rev >= self.count(): 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):
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 c = []
for n in self.nodemap:
mpm@selenic.com
Various node id lookup tweaks...
r469 if hex(n).startswith(id):
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 c.append(n)
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 if len(c) > 1: raise RevlogError(_("Ambiguous identifier"))
if len(c) < 1: raise RevlogError(_("No match found"))
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 return c[0]
mpm@selenic.com
Whitespace cleanups...
r515
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 return None
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 def diff(self, a, b):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """return a delta between two revisions"""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 return mdiff.textdiff(a, b)
mpm@selenic.com
Change revlog to use new patch code
r73 def patches(self, t, pl):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """apply a list of patches to a string"""
mpm@selenic.com
Change revlog to use new patch code
r73 return mdiff.patches(t, pl)
mason@suse.com
Implement revlogng....
r2072 def chunk(self, rev, df=None, cachelen=4096):
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 start, length = self.start(rev), self.length(rev)
mason@suse.com
Implement data inlined with the index file...
r2073 inline = self.inlinedata()
if inline:
start += (rev + 1) * struct.calcsize(self.indexformat)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 end = start + length
mason@suse.com
Implement revlogng....
r2072 def loadcache(df):
cache_length = max(cachelen, length) # 4k
if not df:
mason@suse.com
Implement data inlined with the index file...
r2073 if inline:
df = self.opener(self.indexfile)
else:
df = self.opener(self.datafile)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 df.seek(start)
self.chunkcache = (start, df.read(cache_length))
if not self.chunkcache:
mason@suse.com
Implement revlogng....
r2072 loadcache(df)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598
cache_start = self.chunkcache[0]
cache_end = cache_start + len(self.chunkcache[1])
if start >= cache_start and end <= cache_end:
# it is cached
offset = start - cache_start
else:
mason@suse.com
Implement revlogng....
r2072 loadcache(df)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 offset = 0
#def checkchunk():
# df = self.opener(self.datafile)
# df.seek(start)
# return df.read(length)
#assert s == checkchunk()
return decompress(self.chunkcache[1][offset:offset + length])
mpm@selenic.com
Add code to retrieve or construct a revlog delta
r119 def delta(self, node):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """return or calculate a delta between a node and its predecessor"""
mpm@selenic.com
Add code to retrieve or construct a revlog delta
r119 r = self.rev(node)
Benoit Boissinot
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 return self.revdiff(r - 1, r)
def revdiff(self, rev1, rev2):
"""return or calculate a delta between two revisions"""
b1 = self.base(rev1)
b2 = self.base(rev2)
if b1 == b2 and rev1 + 1 == rev2:
return self.chunk(rev2)
mpm@selenic.com
Add code to retrieve or construct a revlog delta
r119 else:
Benoit Boissinot
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 return self.diff(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):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """return an uncompressed revision of a given"""
mpm@selenic.com
Add smart node lookup by substring or by rev number
r36 if node == nullid: return ""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 if self.cache and self.cache[0] == node: return self.cache[2]
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
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
# we probably have the whole chunk cached
df = None
else:
df = self.opener(self.datafile)
mason@suse.com
Implement revlogng....
r2072
mpm@selenic.com
Add some docstrings to revlog.py
r1083 # do we have useful data cached?
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 if self.cache and self.cache[1] >= base and self.cache[1] < rev:
base = self.cache[1]
text = self.cache[2]
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 else:
mason@suse.com
Implement revlogng....
r2072 text = self.chunk(base, df=df)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Add mdiff.patches to speed up applying thousands of patches to the manifest
r71 bins = []
mpm@selenic.com
Diff in subdirectories from Jake Edge...
r64 for r in xrange(base + 1, rev + 1):
mason@suse.com
Implement revlogng....
r2072 bins.append(self.chunk(r, df=df))
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
Benoit Boissinot
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 text = self.patches(text, bins)
mpm@selenic.com
Add mdiff.patches to speed up applying thousands of patches to the manifest
r71
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")
mpm@selenic.com
Add paranoia to diff code
r98 % (self.datafile, rev))
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
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):
mason@suse.com
Implement data inlined with the index file...
r2073 if not self.inlinedata():
return
mason@suse.com
Make the appendfile class inline-data index friendly...
r2075 if not fp:
fp = self.opener(self.indexfile, 'r')
mason@suse.com
Implement data inlined with the index file...
r2073 size = fp.tell()
if size < 131072:
return
tr.add(self.datafile, 0)
df = self.opener(self.datafile, 'w')
calc = struct.calcsize(self.indexformat)
for r in xrange(self.count()):
start = self.start(r) + (r + 1) * calc
length = self.length(r)
fp.seek(start)
d = fp.read(length)
df.write(d)
fp.close()
df.close()
fp = self.opener(self.indexfile, 'w', atomic=True)
self.version &= ~(REVLOGNGINLINEDATA)
if self.count():
x = self.index[0]
e = struct.pack(self.indexformat, *x)[4:]
l = struct.pack(versionformat, self.version)
fp.write(l)
fp.write(e)
for i in xrange(1, self.count()):
x = self.index[i]
e = struct.pack(self.indexformat, *x)
fp.write(e)
fp.close()
self.chunkcache = None
mason@suse.com
Performance enhancements for manifest.add()...
r644 def addrevision(self, text, transaction, link, p1=None, p2=None, 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
"""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 if text is None: text = ""
if p1 is None: p1 = self.tip()
if p2 is None: p2 = nullid
node = hash(text, p1, p2)
mpm@selenic.com
revlog: allow duplicates...
r301 if node in self.nodemap:
return node
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 n = self.count()
t = n - 1
if n:
mpm@selenic.com
Diff in subdirectories from Jake Edge...
r64 base = self.base(t)
start = self.start(base)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 end = self.end(t)
mason@suse.com
Performance enhancements for manifest.add()...
r644 if not d:
prev = self.revision(self.tip())
mason@suse.com
Reduce string duplication in compression code...
r1533 d = self.diff(prev, str(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])
dist = end - start + l
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
mpm@selenic.com
Diff in subdirectories from Jake Edge...
r64 if not n 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])
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 base = n
else:
base = self.base(t)
offset = 0
if t >= 0:
offset = self.end(t)
mason@suse.com
Implement revlogng....
r2072 if self.version == 0:
e = (offset, l, base, link, p1, p2, node)
else:
e = (self.offset_type(offset, 0), l, len(text),
base, link, self.rev(p1), self.rev(p2), node)
mpm@selenic.com
Whitespace cleanups...
r515
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 self.index.append(e)
self.nodemap[node] = n
mason@suse.com
Implement revlogng....
r2072 entry = struct.pack(self.indexformat, *e)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Implement data inlined with the index file...
r2073 if not self.inlinedata():
transaction.add(self.datafile, offset)
transaction.add(self.indexfile, n * len(entry))
f = self.opener(self.datafile, "a")
if data[0]:
f.write(data[0])
f.write(data[1])
f = self.opener(self.indexfile, "a")
else:
f = self.opener(self.indexfile, "a+")
transaction.add(self.indexfile, f.tell())
mason@suse.com
Implement revlogng....
r2072
if len(self.index) == 1 and self.version != 0:
l = struct.pack(versionformat, self.version)
f.write(l)
entry = entry[4:]
f.write(entry)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
f.write(data[0])
f.write(data[1])
mason@suse.com
Make the appendfile class inline-data index friendly...
r2075 self.checkinlinesize(transaction, f)
mason@suse.com
Implement data inlined with the index file...
r2073
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 self.cache = (node, n, text)
return node
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"""
mpm@selenic.com
A new ancestor algorithm...
r147 # calculate the distance of every node from root
dist = {nullid: 0}
for i in xrange(self.count()):
n = self.node(i)
p1, p2 = self.parents(n)
dist[n] = max(dist[p1], dist[p2]) + 1
mpm@selenic.com
Whitespace cleanups...
r515
mpm@selenic.com
A new ancestor algorithm...
r147 # traverse ancestors in order of decreasing distance from root
def ancestors(node):
# we store negative distances because heap returns smallest member
h = [(-dist[node], node)]
seen = {}
while h:
d, n = heapq.heappop(h)
if n not in seen:
seen[n] = 1
Matt Mackall
Repair ancestor logic, fix up test cases
r1351 yield (-d, n)
mpm@selenic.com
A new ancestor algorithm...
r147 for p in self.parents(n):
heapq.heappush(h, (-dist[p], p))
mpm@selenic.com
Fix recursion depth trouble with ancestor algorithm
r45
Matt Mackall
Repair ancestor logic, fix up test cases
r1351 def generations(node):
sg, s = None, {}
for g,n in ancestors(node):
if g != sg:
if sg:
yield sg, s
sg, s = g, {n:1}
else:
s[n] = 1
yield sg, s
x = generations(a)
y = generations(b)
gx = x.next()
gy = y.next()
mpm@selenic.com
Fix recursion depth trouble with ancestor algorithm
r45
mpm@selenic.com
A new ancestor algorithm...
r147 # increment each ancestor list until it is closer to root than
# the other, or they match
while 1:
Matt Mackall
Repair ancestor logic, fix up test cases
r1351 #print "ancestor gen %s %s" % (gx[0], gy[0])
if gx[0] == gy[0]:
# find the intersection
i = [ n for n in gx[1] if n in gy[1] ]
if i:
return i[0]
else:
#print "next"
gy = y.next()
gx = x.next()
elif gx[0] < gy[0]:
#print "next y"
gy = y.next()
else:
#print "next x"
gx = x.next()
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):
mpm@selenic.com
Add some docstrings to revlog.py
r1083 """calculate a delta group
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]
"""
Eric Hopper
This changes the revlog.group and re-implements the localrepo.changeroup...
r1458 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
mpm@selenic.com
Changes to network protocol...
r192 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
p = self.parents(self.node(revs[0]))[0]
revs.insert(0, self.rev(p))
# build deltas
mpm@selenic.com
Add mdiff.patches to speed up applying thousands of patches to the manifest
r71 for d in xrange(0, 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
revlog.py: factorization and fixes for rev < 0 (nullid)
r1941 d = self.revdiff(a, b)
Benoit Boissinot
cleanup of revlog.group when repository is local...
r1598 p = self.parents(nb)
meta = nb + p[0] + p[1] + lookup(nb)
Thomas Arendsen Hein
make incoming work via ssh (issue139); move chunk code into separate module....
r1981 yield changegroup.genchunk("%s%s" % (meta, 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
benoit.boissinot@ens-lyon.fr
pep-0008 cleanup...
r1062 def addgroup(self, revs, linkmapper, transaction, unique=0):
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
mpm@selenic.com
Add changegroup support
r46 r = self.count()
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
Matt Mackall
Fix out of range regression...
r655 base = prev = -1
Matt Mackall
Fix corruption resulting from skipping parts of a revision group...
r653 start = end = measure = 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+")
transaction.add(self.indexfile, ifh.tell())
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
dfh = None
else:
transaction.add(self.datafile, end)
dfh = self.opener(self.datafile, "a")
mpm@selenic.com
Add changegroup support
r46
# loop through our set of deltas
mpm@selenic.com
Changes to network protocol...
r192 chain = None
for chunk in revs:
node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
mpm@selenic.com
Refactor merge code...
r94 link = linkmapper(cs)
mpm@selenic.com
Fix bug in lazymap code...
r77 if node in self.nodemap:
mpm@selenic.com
fix bad assumption about uniqueness of file versions...
r224 # this can happen if two branches make the same change
mpm@selenic.com
Add preliminary support for the bundle and unbundle commands
r1218 # if unique:
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 # raise RevlogError(_("already have %s") % hex(node[:4]))
Matt Mackall
Fix corruption resulting from skipping parts of a revision group...
r653 chain = node
mpm@selenic.com
fix bad assumption about uniqueness of file versions...
r224 continue
mpm@selenic.com
Changes to network protocol...
r192 delta = chunk[80:]
Matt Mackall
Add safety check for addgroup
r1509 for p in (p1, p2):
if not p in self.nodemap:
raise RevlogError(_("unknown parent %s") % short(p1))
mpm@selenic.com
Changes to network protocol...
r192 if not chain:
# retrieve the parent revision of the delta chain
chain = p1
if not chain in self.nodemap:
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 raise RevlogError(_("unknown base %s") % short(chain[:4]))
mpm@selenic.com
Add changegroup support
r46
# 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:
mason@suse.com
Reduce string duplication in compression code...
r1533 tempd = compress(delta)
cdelta = tempd[0] + tempd[1]
mpm@selenic.com
Add changegroup support
r46
if chain != prev or (end - start + len(cdelta)) > measure * 2:
# flush our writes here so we can read it in revision
mason@suse.com
Implement revlogng....
r2072 if dfh:
dfh.flush()
mpm@selenic.com
Add changegroup support
r46 ifh.flush()
mpm@selenic.com
Fix up a bunch of bugs in the new merge code...
r65 text = self.revision(chain)
mpm@selenic.com
Change revlog to use new patch code
r73 text = self.patches(text, [delta])
mpm@selenic.com
Add changegroup support
r46 chk = self.addrevision(text, transaction, link, p1, p2)
if chk != node:
Benoit Boissinot
i18n part2: use '_' for all strings who are part of the user interface
r1402 raise RevlogError(_("consistency error adding group"))
mpm@selenic.com
Add changegroup support
r46 measure = len(text)
else:
mason@suse.com
Implement revlogng....
r2072 if self.version == 0:
e = (end, len(cdelta), base, link, p1, p2, node)
else:
e = (self.offset_type(end, 0), len(cdelta), -1, base,
link, self.rev(p1), self.rev(p2), node)
mpm@selenic.com
Add changegroup support
r46 self.index.append(e)
self.nodemap[node] = r
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
ifh.write(struct.pack(self.indexformat, *e))
ifh.write(cdelta)
mason@suse.com
Make the appendfile class inline-data index friendly...
r2075 self.checkinlinesize(transaction, ifh)
mason@suse.com
Implement data inlined with the index file...
r2073 if not self.inlinedata():
dfh = self.opener(self.datafile, "a")
ifh = self.opener(self.indexfile, "a")
else:
if not dfh:
# addrevision switched from inline to conventional
# reopen the index
dfh = self.opener(self.datafile, "a")
ifh = self.opener(self.indexfile, "a")
dfh.write(cdelta)
ifh.write(struct.pack(self.indexformat, *e))
mpm@selenic.com
Add changegroup support
r46
mpm@selenic.com
Fix up a bunch of bugs in the new merge code...
r65 t, r, chain, prev = r, r + 1, node, node
Benoit Boissinot
fix warnings from pychecker (unused variables and shadowing)
r1749 base = self.base(t)
start = self.start(base)
mpm@selenic.com
Add changegroup support
r46 end = self.end(t)
Thomas Arendsen Hein
Calling revlog.addgroup with an empty changegroup now raises RevlogError....
r2002 if node is None:
raise RevlogError(_("group to be added is empty"))
mpm@selenic.com
Add changegroup support
r46 return node
Matt Mackall
verify: add check for mismatch of index and data length
r1493
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 def strip(self, rev, minlink):
if self.count() == 0 or rev >= self.count():
return
mason@suse.com
Implement revlogng....
r2072 if isinstance(self.index, lazyindex):
self.loadindexmap()
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 # When stripping away a revision, we need to make sure it
# does not actually belong to an older changeset.
# The minlink parameter defines the oldest revision
# we're allowed to strip away.
mason@suse.com
Implement revlogng....
r2072 while minlink > self.index[rev][-4]:
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535 rev += 1
if rev >= self.count():
return
# first truncate the files on disk
end = self.start(rev)
mason@suse.com
Implement data inlined with the index file...
r2073 if not self.inlinedata():
df = self.opener(self.datafile, "a")
df.truncate(end)
end = rev * struct.calcsize(self.indexformat)
else:
end += rev * struct.calcsize(self.indexformat)
mason@suse.com
Implement revlogng....
r2072
indexf = self.opener(self.indexfile, "a")
indexf.truncate(end)
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
# then reset internal state in memory to forget those revisions
self.cache = None
mason@suse.com
revlog.strip should clear the chunkcache...
r1711 self.chunkcache = None
mason@suse.com
Implement revlogng....
r2072 for x in xrange(rev, self.count()):
del self.nodemap[self.node(x)]
mason@suse.com
Add revlog.strip to truncate away revisions....
r1535
mason@suse.com
Implement revlogng....
r2072 del self.index[rev:]
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
if self.count():
expected = self.end(self.count() - 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()
mason@suse.com
Implement revlogng....
r2072 s = struct.calcsize(self.indexformat)
Matt Mackall
verify: notice extra data in indices
r1667 i = actual / s
di = actual - (i * s)
mason@suse.com
Implement data inlined with the index file...
r2073 if self.inlinedata():
databytes = 0
for r in xrange(self.count()):
databytes += self.length(r)
dd = 0
di = actual - self.count() * 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)
Matt Mackall
Handle empty logs in repo.checksize
r1494