# HG changeset patch # User mpm@selenic.com # Date 2005-05-17 06:10:02 # Node ID ee1cbe841e01e143c6685f12415de7d30b774617 # Parent 4a6ab4d80dc4fe5449e702242402e1fe91fc41e7 Change revlog to use new patch code diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -35,19 +35,28 @@ class revlog: self.index = [] self.opener = opener self.cache = None - self.nodemap = {nullid: -1} # read the whole index for now, handle on-demand later try: n = 0 i = self.opener(self.indexfile).read() s = struct.calcsize(indexformat) + + # preallocate arrays + l = len(i)/s + self.index = [None] * l + m = [None] * l + for f in xrange(0, len(i), s): # offset, size, base, linkrev, p1, p2, nodeid e = struct.unpack(indexformat, i[f:f + s]) - self.nodemap[e[6]] = n - self.index.append(e) + self.index[n] = e + m[n] = (e[6], n) n += 1 - except IOError: pass + + self.nodemap = dict(m) + except IOError: + self.nodemap = {} + self.nodemap[nullid] = -1 def tip(self): return self.node(len(self.index) - 1) def count(self): return len(self.index) @@ -87,6 +96,9 @@ class revlog: def diff(self, a, b): return mdiff.textdiff(a, b) + def patches(self, t, pl): + return mdiff.patches(t, pl) + def revision(self, node): if node == nullid: return "" if self.cache and self.cache[0] == node: return self.cache[2] @@ -388,7 +400,7 @@ class revlog: dfh.flush() ifh.flush() text = self.revision(chain) - text = self.patch(text, delta) + text = self.patches(text, [delta]) chk = self.addrevision(text, transaction, link, p1, p2) if chk != node: raise "consistency error adding group"