annotate mercurial/node.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
children d62130f99a73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
1 """
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
2 node.py - basic nodeid manipulation for mercurial
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
3
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
4 Copyright 2005 Matt Mackall <mpm@selenic.com>
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
5
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
6 This software may be used and distributed according to the terms
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
7 of the GNU General Public License, incorporated herein by reference.
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
8 """
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
9
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
10 import sha, binascii
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
11
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
12 nullid = "\0" * 20
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
13
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
14 def hex(node):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
15 return binascii.hexlify(node)
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
16
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
17 def bin(node):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
18 return binascii.unhexlify(node)
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
19
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
20 def short(node):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
21 return hex(node[:6])
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
22
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
23 def hash(text, p1, p2):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
24 """generate a hash from the given text and its parent hashes
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
25
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
26 This hash combines both the current file contents and its history
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
27 in a manner that makes it easy to distinguish nodes with the same
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
28 content in the revision graph.
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
29 """
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
30 l = [p1, p2]
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
31 l.sort()
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
32 s = sha.new(l[0])
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
33 s.update(l[1])
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
34 s.update(text)
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
35 return s.digest()
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
36