comparison hgext/git/gitutil.py @ 44496:ec54b3d2af0b

git: don't fail import when pygit2 is not install `test-duplicateoptions.py` was failing on py2 for be because I didn't have pygit2 installed. It failed because we depend on pygit2 at import time. This patch makes it so we successfully load the git extension even if pygit2 doesn't exist -- we just won't be able to use it in that case. Differential Revision: https://phab.mercurial-scm.org/D8268
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 09 Mar 2020 11:18:33 -0700
parents ad718271a9eb
children c7c1efdfd4de
comparison
equal deleted inserted replaced
44495:2e464925f662 44496:ec54b3d2af0b
2 from __future__ import absolute_import 2 from __future__ import absolute_import
3 3
4 from mercurial.node import bin, hex, nullid 4 from mercurial.node import bin, hex, nullid
5 5
6 from mercurial import pycompat 6 from mercurial import pycompat
7
8 pygit2_module = None
9
10
11 def get_pygit2():
12 global pygit2_module
13 if pygit2_module is None:
14 try:
15 import pygit2 as pygit2_module
16
17 pygit2_module.InvalidSpecError
18 except (ImportError, AttributeError):
19 pass
20 return pygit2_module
7 21
8 22
9 def togitnode(n): 23 def togitnode(n):
10 """Wrapper to convert a Mercurial binary node to a unicode hexlified node. 24 """Wrapper to convert a Mercurial binary node to a unicode hexlified node.
11 25