30 if not bin: return bin |
30 if not bin: return bin |
31 t = bin[0] |
31 t = bin[0] |
32 if t == '\0': return bin |
32 if t == '\0': return bin |
33 if t == 'x': return zlib.decompress(bin) |
33 if t == 'x': return zlib.decompress(bin) |
34 if t == 'u': return bin[1:] |
34 if t == 'u': return bin[1:] |
35 raise "unknown compression type %s" % t |
35 raise RevlogError("unknown compression type %s" % t) |
36 |
36 |
37 def hash(text, p1, p2): |
37 def hash(text, p1, p2): |
38 l = [p1, p2] |
38 l = [p1, p2] |
39 l.sort() |
39 l.sort() |
40 s = sha.new(l[0]) |
40 s = sha.new(l[0]) |
118 except KeyError: |
118 except KeyError: |
119 raise KeyError("node " + hex(key)) |
119 raise KeyError("node " + hex(key)) |
120 def __setitem__(self, key, val): |
120 def __setitem__(self, key, val): |
121 self.p.map[key] = val |
121 self.p.map[key] = val |
122 |
122 |
|
123 class RevlogError(Exception): pass |
|
124 |
123 class revlog: |
125 class revlog: |
124 def __init__(self, opener, indexfile, datafile): |
126 def __init__(self, opener, indexfile, datafile): |
125 self.indexfile = indexfile |
127 self.indexfile = indexfile |
126 self.datafile = datafile |
128 self.datafile = datafile |
127 self.opener = opener |
129 self.opener = opener |
503 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) |
505 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) |
504 link = linkmapper(cs) |
506 link = linkmapper(cs) |
505 if node in self.nodemap: |
507 if node in self.nodemap: |
506 # this can happen if two branches make the same change |
508 # this can happen if two branches make the same change |
507 if unique: |
509 if unique: |
508 raise "already have %s" % hex(node[:4]) |
510 raise RevlogError("already have %s" % hex(node[:4])) |
509 chain = node |
511 chain = node |
510 continue |
512 continue |
511 delta = chunk[80:] |
513 delta = chunk[80:] |
512 |
514 |
513 if not chain: |
515 if not chain: |
514 # retrieve the parent revision of the delta chain |
516 # retrieve the parent revision of the delta chain |
515 chain = p1 |
517 chain = p1 |
516 if not chain in self.nodemap: |
518 if not chain in self.nodemap: |
517 raise "unknown base %s" % short(chain[:4]) |
519 raise RevlogError("unknown base %s" % short(chain[:4])) |
518 |
520 |
519 # full versions are inserted when the needed deltas become |
521 # full versions are inserted when the needed deltas become |
520 # comparable to the uncompressed text or when the previous |
522 # comparable to the uncompressed text or when the previous |
521 # version is not the one we have a delta against. We use |
523 # version is not the one we have a delta against. We use |
522 # the size of the previous full rev as a proxy for the |
524 # the size of the previous full rev as a proxy for the |
531 ifh.flush() |
533 ifh.flush() |
532 text = self.revision(chain) |
534 text = self.revision(chain) |
533 text = self.patches(text, [delta]) |
535 text = self.patches(text, [delta]) |
534 chk = self.addrevision(text, transaction, link, p1, p2) |
536 chk = self.addrevision(text, transaction, link, p1, p2) |
535 if chk != node: |
537 if chk != node: |
536 raise "consistency error adding group" |
538 raise RevlogError("consistency error adding group") |
537 measure = len(text) |
539 measure = len(text) |
538 else: |
540 else: |
539 e = (end, len(cdelta), self.base(t), link, p1, p2, node) |
541 e = (end, len(cdelta), self.base(t), link, p1, p2, node) |
540 self.index.append(e) |
542 self.index.append(e) |
541 self.nodemap[node] = r |
543 self.nodemap[node] = r |