Show More
@@ -8,8 +8,6 b' from __future__ import absolute_import' | |||||
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 |
|
10 | |||
11 | import pygit2 |
|
|||
12 |
|
||||
13 | from mercurial.i18n import _ |
|
11 | from mercurial.i18n import _ | |
14 |
|
12 | |||
15 | from mercurial import ( |
|
13 | from mercurial import ( | |
@@ -29,7 +27,6 b' from . import (' | |||||
29 | index, |
|
27 | index, | |
30 | ) |
|
28 | ) | |
31 |
|
29 | |||
32 |
|
||||
33 | # TODO: extract an interface for this in core |
|
30 | # TODO: extract an interface for this in core | |
34 | class gitstore(object): # store.basicstore): |
|
31 | class gitstore(object): # store.basicstore): | |
35 | def __init__(self, path, vfstype): |
|
32 | def __init__(self, path, vfstype): | |
@@ -39,7 +36,7 b' class gitstore(object): # store.basicst' | |||||
39 | # above lines should go away in favor of: |
|
36 | # above lines should go away in favor of: | |
40 | # super(gitstore, self).__init__(path, vfstype) |
|
37 | # super(gitstore, self).__init__(path, vfstype) | |
41 |
|
38 | |||
42 | self.git = pygit2.Repository( |
|
39 | self.git = gitutil.get_pygit2().Repository( | |
43 | os.path.normpath(os.path.join(path, b'..', b'.git')) |
|
40 | os.path.normpath(os.path.join(path, b'..', b'.git')) | |
44 | ) |
|
41 | ) | |
45 | self._progress_factory = lambda *args, **kwargs: None |
|
42 | self._progress_factory = lambda *args, **kwargs: None | |
@@ -89,6 +86,16 b' class gitstore(object): # store.basicst' | |||||
89 |
|
86 | |||
90 |
|
87 | |||
91 | def _makestore(orig, requirements, storebasepath, vfstype): |
|
88 | def _makestore(orig, requirements, storebasepath, vfstype): | |
|
89 | # Check for presence of pygit2 only here. The assumption is that we'll | |||
|
90 | # run this code iff we'll later need pygit2. | |||
|
91 | if gitutil.get_pygit2() is None: | |||
|
92 | raise error.Abort( | |||
|
93 | _( | |||
|
94 | b'the git extension requires the Python ' | |||
|
95 | b'pygit2 library to be installed' | |||
|
96 | ) | |||
|
97 | ) | |||
|
98 | ||||
92 | if os.path.exists( |
|
99 | if os.path.exists( | |
93 | os.path.join(storebasepath, b'this-is-git') |
|
100 | os.path.join(storebasepath, b'this-is-git') | |
94 | ) and os.path.exists(os.path.join(storebasepath, b'..', b'.git')): |
|
101 | ) and os.path.exists(os.path.join(storebasepath, b'..', b'.git')): | |
@@ -156,7 +163,7 b' class gitbmstore(object):' | |||||
156 | if k in self: |
|
163 | if k in self: | |
157 | return self[k] |
|
164 | return self[k] | |
158 | return default |
|
165 | return default | |
159 | except pygit2.InvalidSpecError: |
|
166 | except gitutil.get_pygit2().InvalidSpecError: | |
160 | return default |
|
167 | return default | |
161 |
|
168 | |||
162 | @property |
|
169 | @property |
@@ -4,8 +4,6 b' import contextlib' | |||||
4 | import errno |
|
4 | import errno | |
5 | import os |
|
5 | import os | |
6 |
|
6 | |||
7 | import pygit2 |
|
|||
8 |
|
||||
9 | from mercurial import ( |
|
7 | from mercurial import ( | |
10 | error, |
|
8 | error, | |
11 | extensions, |
|
9 | extensions, | |
@@ -22,6 +20,8 b' from mercurial.interfaces import (' | |||||
22 |
|
20 | |||
23 | from . import gitutil |
|
21 | from . import gitutil | |
24 |
|
22 | |||
|
23 | pygit2 = gitutil.get_pygit2() | |||
|
24 | ||||
25 |
|
25 | |||
26 | def readpatternfile(orig, filepath, warn, sourceinfo=False): |
|
26 | def readpatternfile(orig, filepath, warn, sourceinfo=False): | |
27 | if not (b'info/exclude' in filepath or filepath.endswith(b'.gitignore')): |
|
27 | if not (b'info/exclude' in filepath or filepath.endswith(b'.gitignore')): | |
@@ -46,23 +46,25 b' def readpatternfile(orig, filepath, warn' | |||||
46 | extensions.wrapfunction(matchmod, b'readpatternfile', readpatternfile) |
|
46 | extensions.wrapfunction(matchmod, b'readpatternfile', readpatternfile) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | _STATUS_MAP = { |
|
49 | _STATUS_MAP = {} | |
50 | pygit2.GIT_STATUS_CONFLICTED: b'm', |
|
50 | if pygit2: | |
51 | pygit2.GIT_STATUS_CURRENT: b'n', |
|
51 | _STATUS_MAP = { | |
52 |
pygit2.GIT_STATUS_ |
|
52 | pygit2.GIT_STATUS_CONFLICTED: b'm', | |
53 |
pygit2.GIT_STATUS_ |
|
53 | pygit2.GIT_STATUS_CURRENT: b'n', | |
54 |
pygit2.GIT_STATUS_I |
|
54 | pygit2.GIT_STATUS_IGNORED: b'?', | |
55 |
pygit2.GIT_STATUS_INDEX_ |
|
55 | pygit2.GIT_STATUS_INDEX_DELETED: b'r', | |
56 |
pygit2.GIT_STATUS_INDEX_ |
|
56 | pygit2.GIT_STATUS_INDEX_MODIFIED: b'n', | |
57 |
pygit2.GIT_STATUS_INDEX_ |
|
57 | pygit2.GIT_STATUS_INDEX_NEW: b'a', | |
58 |
pygit2.GIT_STATUS_ |
|
58 | pygit2.GIT_STATUS_INDEX_RENAMED: b'a', | |
59 |
pygit2.GIT_STATUS_ |
|
59 | pygit2.GIT_STATUS_INDEX_TYPECHANGE: b'n', | |
60 |
pygit2.GIT_STATUS_WT_ |
|
60 | pygit2.GIT_STATUS_WT_DELETED: b'r', | |
61 |
pygit2.GIT_STATUS_WT_ |
|
61 | pygit2.GIT_STATUS_WT_MODIFIED: b'n', | |
62 |
pygit2.GIT_STATUS_WT_ |
|
62 | pygit2.GIT_STATUS_WT_NEW: b'?', | |
63 |
pygit2.GIT_STATUS_WT_ |
|
63 | pygit2.GIT_STATUS_WT_RENAMED: b'a', | |
64 | pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_WT_MODIFIED: 'm', |
|
64 | pygit2.GIT_STATUS_WT_TYPECHANGE: b'n', | |
65 | } |
|
65 | pygit2.GIT_STATUS_WT_UNREADABLE: b'?', | |
|
66 | pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_WT_MODIFIED: 'm', | |||
|
67 | } | |||
66 |
|
68 | |||
67 |
|
69 | |||
68 | @interfaceutil.implementer(intdirstate.idirstate) |
|
70 | @interfaceutil.implementer(intdirstate.idirstate) |
@@ -1,7 +1,5 b'' | |||||
1 | from __future__ import absolute_import |
|
1 | from __future__ import absolute_import | |
2 |
|
2 | |||
3 | import pygit2 |
|
|||
4 |
|
||||
5 | from mercurial.i18n import _ |
|
3 | from mercurial.i18n import _ | |
6 |
|
4 | |||
7 | from mercurial import ( |
|
5 | from mercurial import ( | |
@@ -25,6 +23,8 b' from . import (' | |||||
25 | manifest as gitmanifest, |
|
23 | manifest as gitmanifest, | |
26 | ) |
|
24 | ) | |
27 |
|
25 | |||
|
26 | pygit2 = gitutil.get_pygit2() | |||
|
27 | ||||
28 |
|
28 | |||
29 | class baselog(object): # revlog.revlog): |
|
29 | class baselog(object): # revlog.revlog): | |
30 | """Common implementations between changelog and manifestlog.""" |
|
30 | """Common implementations between changelog and manifestlog.""" |
@@ -5,6 +5,20 b' from mercurial.node import bin, hex, nul' | |||||
5 |
|
5 | |||
6 | from mercurial import pycompat |
|
6 | from mercurial import pycompat | |
7 |
|
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 | |||
|
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. |
@@ -4,8 +4,6 b' import collections' | |||||
4 | import os |
|
4 | import os | |
5 | import sqlite3 |
|
5 | import sqlite3 | |
6 |
|
6 | |||
7 | import pygit2 |
|
|||
8 |
|
||||
9 | from mercurial.i18n import _ |
|
7 | from mercurial.i18n import _ | |
10 |
|
8 | |||
11 | from mercurial import ( |
|
9 | from mercurial import ( | |
@@ -18,6 +16,8 b' from mercurial import (' | |||||
18 | from . import gitutil |
|
16 | from . import gitutil | |
19 |
|
17 | |||
20 |
|
18 | |||
|
19 | pygit2 = gitutil.get_pygit2() | |||
|
20 | ||||
21 | _CURRENT_SCHEMA_VERSION = 1 |
|
21 | _CURRENT_SCHEMA_VERSION = 1 | |
22 | _SCHEMA = ( |
|
22 | _SCHEMA = ( | |
23 | """ |
|
23 | """ | |
@@ -101,9 +101,13 b' def _createdb(path):' | |||||
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 |
@@ -1,7 +1,5 b'' | |||||
1 | from __future__ import absolute_import |
|
1 | from __future__ import absolute_import | |
2 |
|
2 | |||
3 | import pygit2 |
|
|||
4 |
|
||||
5 | from mercurial import ( |
|
3 | from mercurial import ( | |
6 | match as matchmod, |
|
4 | match as matchmod, | |
7 | pathutil, |
|
5 | pathutil, | |
@@ -15,6 +13,9 b' from mercurial.interfaces import (' | |||||
15 | from . import gitutil |
|
13 | from . import gitutil | |
16 |
|
14 | |||
17 |
|
15 | |||
|
16 | pygit2 = gitutil.get_pygit2() | |||
|
17 | ||||
|
18 | ||||
18 | @interfaceutil.implementer(repository.imanifestdict) |
|
19 | @interfaceutil.implementer(repository.imanifestdict) | |
19 | class gittreemanifest(object): |
|
20 | class gittreemanifest(object): | |
20 | """Expose git trees (and optionally a builder's overlay) as a manifestdict. |
|
21 | """Expose git trees (and optionally a builder's overlay) as a manifestdict. |
General Comments 0
You need to be logged in to leave comments.
Login now