Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 1089:142b5d5ec9cc
Break apart hg.py
- move the various parts of hg.py into their own files
- create node.py to store node manipulation functions
author | mpm@selenic.com |
---|---|
date | Sat, 27 Aug 2005 14:21:25 -0700 |
parents | 30974cf73435 |
children | d62130f99a73 |
comparison
equal
deleted
inserted
replaced
1088:39b916b1d8e4 | 1089:142b5d5ec9cc |
---|---|
10 of the GNU General Public License, incorporated herein by reference. | 10 of the GNU General Public License, incorporated herein by reference. |
11 """ | 11 """ |
12 | 12 |
13 import zlib, struct, sha, binascii, heapq | 13 import zlib, struct, sha, binascii, heapq |
14 from mercurial import mdiff | 14 from mercurial import mdiff |
15 | 15 from node import * |
16 def hex(node): return binascii.hexlify(node) | |
17 def bin(node): return binascii.unhexlify(node) | |
18 def short(node): return hex(node[:6]) | |
19 | 16 |
20 def compress(text): | 17 def compress(text): |
21 """ generate a possibly-compressed representation of text """ | 18 """ generate a possibly-compressed representation of text """ |
22 if not text: return text | 19 if not text: return text |
23 if len(text) < 44: | 20 if len(text) < 44: |
36 if t == '\0': return bin | 33 if t == '\0': return bin |
37 if t == 'x': return zlib.decompress(bin) | 34 if t == 'x': return zlib.decompress(bin) |
38 if t == 'u': return bin[1:] | 35 if t == 'u': return bin[1:] |
39 raise RevlogError("unknown compression type %s" % t) | 36 raise RevlogError("unknown compression type %s" % t) |
40 | 37 |
41 def hash(text, p1, p2): | |
42 """generate a hash from the given text and its parent hashes | |
43 | |
44 This hash combines both the current file contents and its history | |
45 in a manner that makes it easy to distinguish nodes with the same | |
46 content in the revision graph. | |
47 """ | |
48 l = [p1, p2] | |
49 l.sort() | |
50 s = sha.new(l[0]) | |
51 s.update(l[1]) | |
52 s.update(text) | |
53 return s.digest() | |
54 | |
55 nullid = "\0" * 20 | |
56 indexformat = ">4l20s20s20s" | 38 indexformat = ">4l20s20s20s" |
57 | 39 |
58 class lazyparser: | 40 class lazyparser: |
59 """ | 41 """ |
60 this class avoids the need to parse the entirety of large indices | 42 this class avoids the need to parse the entirety of large indices |