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