Mercurial > public > mercurial-scm > hg
comparison hgext/git/index.py @ 44484: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 | fb2936c5f6dc |
comparison
equal
deleted
inserted
replaced
44483:2e464925f662 | 44484:ec54b3d2af0b |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 import collections | 3 import collections |
4 import os | 4 import os |
5 import sqlite3 | 5 import sqlite3 |
6 | |
7 import pygit2 | |
8 | 6 |
9 from mercurial.i18n import _ | 7 from mercurial.i18n import _ |
10 | 8 |
11 from mercurial import ( | 9 from mercurial import ( |
12 encoding, | 10 encoding, |
15 pycompat, | 13 pycompat, |
16 ) | 14 ) |
17 | 15 |
18 from . import gitutil | 16 from . import gitutil |
19 | 17 |
18 | |
19 pygit2 = gitutil.get_pygit2() | |
20 | 20 |
21 _CURRENT_SCHEMA_VERSION = 1 | 21 _CURRENT_SCHEMA_VERSION = 1 |
22 _SCHEMA = ( | 22 _SCHEMA = ( |
23 """ | 23 """ |
24 CREATE TABLE refs ( | 24 CREATE TABLE refs ( |
99 db.execute('PRAGMA journal_mode=WAL') | 99 db.execute('PRAGMA journal_mode=WAL') |
100 | 100 |
101 return db | 101 return db |
102 | 102 |
103 | 103 |
104 _OUR_ORDER = ( | 104 _OUR_ORDER = () |
105 pygit2.GIT_SORT_TOPOLOGICAL | pygit2.GIT_SORT_TIME | pygit2.GIT_SORT_REVERSE | 105 if pygit2: |
106 ) | 106 _OUR_ORDER = ( |
107 pygit2.GIT_SORT_TOPOLOGICAL | |
108 | pygit2.GIT_SORT_TIME | |
109 | pygit2.GIT_SORT_REVERSE | |
110 ) | |
107 | 111 |
108 _DIFF_FLAGS = 1 << 21 # GIT_DIFF_FORCE_BINARY, which isn't exposed by pygit2 | 112 _DIFF_FLAGS = 1 << 21 # GIT_DIFF_FORCE_BINARY, which isn't exposed by pygit2 |
109 | 113 |
110 | 114 |
111 def _find_nearest_ancestor_introducing_node( | 115 def _find_nearest_ancestor_introducing_node( |