Mercurial > hg-stable
diff 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 |
line wrap: on
line diff
--- a/hgext/git/gitutil.py Mon Mar 09 12:53:21 2020 -0700 +++ b/hgext/git/gitutil.py Mon Mar 09 11:18:33 2020 -0700 @@ -5,6 +5,20 @@ from mercurial import pycompat +pygit2_module = None + + +def get_pygit2(): + global pygit2_module + if pygit2_module is None: + try: + import pygit2 as pygit2_module + + pygit2_module.InvalidSpecError + except (ImportError, AttributeError): + pass + return pygit2_module + def togitnode(n): """Wrapper to convert a Mercurial binary node to a unicode hexlified node.