##// END OF EJS Templates
py3: don’t encode node.bin() argument...
Manuel Jacob -
r50185:76f56d69 default
parent child Browse files
Show More
@@ -1,52 +1,50
1 1 """utilities to assist in working with pygit2"""
2 2
3 3 from mercurial.node import bin, hex, sha1nodeconstants
4 4
5 5 from mercurial import pycompat
6 6
7 7 pygit2_module = None
8 8
9 9
10 10 def get_pygit2():
11 11 global pygit2_module
12 12 if pygit2_module is None:
13 13 try:
14 14 import pygit2 as pygit2_module
15 15
16 16 pygit2_module.InvalidSpecError
17 17 except (ImportError, AttributeError):
18 18 pass
19 19 return pygit2_module
20 20
21 21
22 22 def pygit2_version():
23 23 mod = get_pygit2()
24 24 v = "N/A"
25 25
26 26 if mod:
27 27 try:
28 28 v = mod.__version__
29 29 except AttributeError:
30 30 pass
31 31
32 32 return b"(pygit2 %s)" % v.encode("utf-8")
33 33
34 34
35 35 def togitnode(n):
36 36 """Wrapper to convert a Mercurial binary node to a unicode hexlified node.
37 37
38 38 pygit2 and sqlite both need nodes as strings, not bytes.
39 39 """
40 40 assert len(n) == 20
41 41 return pycompat.sysstr(hex(n))
42 42
43 43
44 44 def fromgitnode(n):
45 45 """Opposite of togitnode."""
46 46 assert len(n) == 40
47 if pycompat.ispy3:
48 return bin(n.encode('ascii'))
49 47 return bin(n)
50 48
51 49
52 50 nullgit = togitnode(sha1nodeconstants.nullid)
General Comments 0
You need to be logged in to leave comments. Login now