hgext/git/index.py
changeset 44484 ec54b3d2af0b
parent 44477 ad718271a9eb
child 44946 fb2936c5f6dc
--- a/hgext/git/index.py	Mon Mar 09 12:53:21 2020 -0700
+++ b/hgext/git/index.py	Mon Mar 09 11:18:33 2020 -0700
@@ -4,8 +4,6 @@
 import os
 import sqlite3
 
-import pygit2
-
 from mercurial.i18n import _
 
 from mercurial import (
@@ -18,6 +16,8 @@
 from . import gitutil
 
 
+pygit2 = gitutil.get_pygit2()
+
 _CURRENT_SCHEMA_VERSION = 1
 _SCHEMA = (
     """
@@ -101,9 +101,13 @@
     return db
 
 
-_OUR_ORDER = (
-    pygit2.GIT_SORT_TOPOLOGICAL | pygit2.GIT_SORT_TIME | pygit2.GIT_SORT_REVERSE
-)
+_OUR_ORDER = ()
+if pygit2:
+    _OUR_ORDER = (
+        pygit2.GIT_SORT_TOPOLOGICAL
+        | pygit2.GIT_SORT_TIME
+        | pygit2.GIT_SORT_REVERSE
+    )
 
 _DIFF_FLAGS = 1 << 21  # GIT_DIFF_FORCE_BINARY, which isn't exposed by pygit2