Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/revlog.py @ 73:ee1cbe841e01
Change revlog to use new patch code
author | mpm@selenic.com |
---|---|
date | Mon, 16 May 2005 22:10:02 -0800 |
parents | 47c9a869adee |
children | d993ebd69d28 |
comparison
equal
deleted
inserted
replaced
72:4a6ab4d80dc4 | 73:ee1cbe841e01 |
---|---|
33 self.indexfile = indexfile | 33 self.indexfile = indexfile |
34 self.datafile = datafile | 34 self.datafile = datafile |
35 self.index = [] | 35 self.index = [] |
36 self.opener = opener | 36 self.opener = opener |
37 self.cache = None | 37 self.cache = None |
38 self.nodemap = {nullid: -1} | |
39 # read the whole index for now, handle on-demand later | 38 # read the whole index for now, handle on-demand later |
40 try: | 39 try: |
41 n = 0 | 40 n = 0 |
42 i = self.opener(self.indexfile).read() | 41 i = self.opener(self.indexfile).read() |
43 s = struct.calcsize(indexformat) | 42 s = struct.calcsize(indexformat) |
43 | |
44 # preallocate arrays | |
45 l = len(i)/s | |
46 self.index = [None] * l | |
47 m = [None] * l | |
48 | |
44 for f in xrange(0, len(i), s): | 49 for f in xrange(0, len(i), s): |
45 # offset, size, base, linkrev, p1, p2, nodeid | 50 # offset, size, base, linkrev, p1, p2, nodeid |
46 e = struct.unpack(indexformat, i[f:f + s]) | 51 e = struct.unpack(indexformat, i[f:f + s]) |
47 self.nodemap[e[6]] = n | 52 self.index[n] = e |
48 self.index.append(e) | 53 m[n] = (e[6], n) |
49 n += 1 | 54 n += 1 |
50 except IOError: pass | 55 |
56 self.nodemap = dict(m) | |
57 except IOError: | |
58 self.nodemap = {} | |
59 self.nodemap[nullid] = -1 | |
51 | 60 |
52 def tip(self): return self.node(len(self.index) - 1) | 61 def tip(self): return self.node(len(self.index) - 1) |
53 def count(self): return len(self.index) | 62 def count(self): return len(self.index) |
54 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6] | 63 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6] |
55 def rev(self, node): return self.nodemap[node] | 64 def rev(self, node): return self.nodemap[node] |
84 for node in list: | 93 for node in list: |
85 yield self.revision(node) | 94 yield self.revision(node) |
86 | 95 |
87 def diff(self, a, b): | 96 def diff(self, a, b): |
88 return mdiff.textdiff(a, b) | 97 return mdiff.textdiff(a, b) |
98 | |
99 def patches(self, t, pl): | |
100 return mdiff.patches(t, pl) | |
89 | 101 |
90 def revision(self, node): | 102 def revision(self, node): |
91 if node == nullid: return "" | 103 if node == nullid: return "" |
92 if self.cache and self.cache[0] == node: return self.cache[2] | 104 if self.cache and self.cache[0] == node: return self.cache[2] |
93 | 105 |
386 if chain != prev or (end - start + len(cdelta)) > measure * 2: | 398 if chain != prev or (end - start + len(cdelta)) > measure * 2: |
387 # flush our writes here so we can read it in revision | 399 # flush our writes here so we can read it in revision |
388 dfh.flush() | 400 dfh.flush() |
389 ifh.flush() | 401 ifh.flush() |
390 text = self.revision(chain) | 402 text = self.revision(chain) |
391 text = self.patch(text, delta) | 403 text = self.patches(text, [delta]) |
392 chk = self.addrevision(text, transaction, link, p1, p2) | 404 chk = self.addrevision(text, transaction, link, p1, p2) |
393 if chk != node: | 405 if chk != node: |
394 raise "consistency error adding group" | 406 raise "consistency error adding group" |
395 measure = len(text) | 407 measure = len(text) |
396 else: | 408 else: |