Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/node.py @ 46793:6266d19556ad
node: introduce nodeconstants class
In preparing for moving from SHA1 hashes to a modern hash function,
place nullid and other constant magic vules in a class. Provide the
active set of constants in the repository and push it down. Provide
nullid directly in strategic places like the repository as it is
accessed very often. This changeset introduces the API change, but not
the mechanical replacement of the node.py attributes itself.
Differential Revision: https://phab.mercurial-scm.org/D9750
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Wed, 13 Jan 2021 16:14:58 +0100 |
parents | 687b865b95ad |
children | d4ba4d51f85f |
comparison
equal
deleted
inserted
replaced
46792:49fd21f32695 | 46793:6266d19556ad |
---|---|
19 return binascii.unhexlify(s) | 19 return binascii.unhexlify(s) |
20 except binascii.Error as e: | 20 except binascii.Error as e: |
21 raise TypeError(e) | 21 raise TypeError(e) |
22 | 22 |
23 | 23 |
24 nullrev = -1 | 24 def short(node): |
25 # In hex, this is '0000000000000000000000000000000000000000' | 25 return hex(node[:6]) |
26 nullid = b"\0" * 20 | |
27 nullhex = hex(nullid) | |
28 | |
29 # Phony node value to stand-in for new files in some uses of | |
30 # manifests. | |
31 # In hex, this is '2121212121212121212121212121212121212121' | |
32 newnodeid = b'!!!!!!!!!!!!!!!!!!!!' | |
33 # In hex, this is '3030303030303030303030303030306164646564' | |
34 addednodeid = b'000000000000000added' | |
35 # In hex, this is '3030303030303030303030306d6f646966696564' | |
36 modifiednodeid = b'000000000000modified' | |
37 | |
38 wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid} | |
39 | |
40 # pseudo identifiers for working directory | |
41 # (they are experimental, so don't add too many dependencies on them) | |
42 wdirrev = 0x7FFFFFFF | |
43 # In hex, this is 'ffffffffffffffffffffffffffffffffffffffff' | |
44 wdirid = b"\xff" * 20 | |
45 wdirhex = hex(wdirid) | |
46 | 26 |
47 | 27 |
48 def short(node): | 28 nullrev = -1 |
49 return hex(node[:6]) | 29 |
30 # pseudo identifier for working directory | |
31 # (experimental, so don't add too many dependencies on it) | |
32 wdirrev = 0x7FFFFFFF | |
33 | |
34 | |
35 class sha1nodeconstants(object): | |
36 nodelen = 20 | |
37 | |
38 # In hex, this is '0000000000000000000000000000000000000000' | |
39 nullid = b"\0" * nodelen | |
40 nullhex = hex(nullid) | |
41 | |
42 # Phony node value to stand-in for new files in some uses of | |
43 # manifests. | |
44 # In hex, this is '2121212121212121212121212121212121212121' | |
45 newnodeid = b'!!!!!!!!!!!!!!!!!!!!' | |
46 # In hex, this is '3030303030303030303030303030306164646564' | |
47 addednodeid = b'000000000000000added' | |
48 # In hex, this is '3030303030303030303030306d6f646966696564' | |
49 modifiednodeid = b'000000000000modified' | |
50 | |
51 wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid} | |
52 | |
53 # pseudo identifier for working directory | |
54 # (experimental, so don't add too many dependencies on it) | |
55 # In hex, this is 'ffffffffffffffffffffffffffffffffffffffff' | |
56 wdirid = b"\xff" * nodelen | |
57 wdirhex = hex(wdirid) | |
58 | |
59 | |
60 # legacy starting point for porting modules | |
61 nullid = sha1nodeconstants.nullid | |
62 nullhex = sha1nodeconstants.nullhex | |
63 newnodeid = sha1nodeconstants.newnodeid | |
64 addednodeid = sha1nodeconstants.addednodeid | |
65 modifiednodeid = sha1nodeconstants.modifiednodeid | |
66 wdirfilenodeids = sha1nodeconstants.wdirfilenodeids | |
67 wdirid = sha1nodeconstants.wdirid | |
68 wdirhex = sha1nodeconstants.wdirhex |