Mercurial > hg
comparison hgext/git/dirstate.py @ 49077:20d151e43429
git: adapt to some recent dirstate API changes
There are still old methods like add() and drop(). I don't see anything that
looks equivalent, so there's likely more work to do. But this allows diff and
commit to work again on the simple webpage repo for thg.
Differential Revision: https://phab.mercurial-scm.org/D12567
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 18 Apr 2022 11:21:09 -0400 |
parents | 642e31cb55f0 |
children | 020328be00cb |
comparison
equal
deleted
inserted
replaced
49076:9c8d67a3af5e | 49077:20d151e43429 |
---|---|
2 import errno | 2 import errno |
3 import os | 3 import os |
4 | 4 |
5 from mercurial.node import sha1nodeconstants | 5 from mercurial.node import sha1nodeconstants |
6 from mercurial import ( | 6 from mercurial import ( |
7 dirstatemap, | |
7 error, | 8 error, |
8 extensions, | 9 extensions, |
9 match as matchmod, | 10 match as matchmod, |
10 pycompat, | 11 pycompat, |
11 scmutil, | 12 scmutil, |
12 util, | 13 util, |
13 ) | 14 ) |
15 from mercurial.dirstateutils import ( | |
16 timestamp, | |
17 ) | |
14 from mercurial.interfaces import ( | 18 from mercurial.interfaces import ( |
15 dirstate as intdirstate, | 19 dirstate as intdirstate, |
16 util as interfaceutil, | 20 util as interfaceutil, |
17 ) | 21 ) |
18 | 22 |
19 from . import gitutil | 23 from . import gitutil |
20 | 24 |
25 | |
26 DirstateItem = dirstatemap.DirstateItem | |
27 propertycache = util.propertycache | |
21 pygit2 = gitutil.get_pygit2() | 28 pygit2 = gitutil.get_pygit2() |
22 | 29 |
23 | 30 |
24 def readpatternfile(orig, filepath, warn, sourceinfo=False): | 31 def readpatternfile(orig, filepath, warn, sourceinfo=False): |
25 if not (b'info/exclude' in filepath or filepath.endswith(b'.gitignore')): | 32 if not (b'info/exclude' in filepath or filepath.endswith(b'.gitignore')): |
65 } | 72 } |
66 | 73 |
67 | 74 |
68 @interfaceutil.implementer(intdirstate.idirstate) | 75 @interfaceutil.implementer(intdirstate.idirstate) |
69 class gitdirstate: | 76 class gitdirstate: |
70 def __init__(self, ui, root, gitrepo): | 77 def __init__(self, ui, vfs, gitrepo, use_dirstate_v2): |
71 self._ui = ui | 78 self._ui = ui |
72 self._root = os.path.dirname(root) | 79 self._root = os.path.dirname(vfs.base) |
80 self._opener = vfs | |
73 self.git = gitrepo | 81 self.git = gitrepo |
74 self._plchangecallbacks = {} | 82 self._plchangecallbacks = {} |
75 # TODO: context.poststatusfixup is bad and uses this attribute | 83 # TODO: context.poststatusfixup is bad and uses this attribute |
76 self._dirty = False | 84 self._dirty = False |
85 self._mapcls = dirstatemap.dirstatemap | |
86 self._use_dirstate_v2 = use_dirstate_v2 | |
87 | |
88 @propertycache | |
89 def _map(self): | |
90 """Return the dirstate contents (see documentation for dirstatemap).""" | |
91 self._map = self._mapcls( | |
92 self._ui, | |
93 self._opener, | |
94 self._root, | |
95 sha1nodeconstants, | |
96 self._use_dirstate_v2, | |
97 ) | |
98 return self._map | |
77 | 99 |
78 def p1(self): | 100 def p1(self): |
79 try: | 101 try: |
80 return self.git.head.peel().id.raw | 102 return self.git.head.peel().id.raw |
81 except pygit2.GitError: | 103 except pygit2.GitError: |
140 [], | 162 [], |
141 [], | 163 [], |
142 [], | 164 [], |
143 [], | 165 [], |
144 ) | 166 ) |
167 | |
168 try: | |
169 mtime_boundary = timestamp.get_fs_now(self._opener) | |
170 except OSError: | |
171 # In largefiles or readonly context | |
172 mtime_boundary = None | |
173 | |
145 gstatus = self.git.status() | 174 gstatus = self.git.status() |
146 for path, status in gstatus.items(): | 175 for path, status in gstatus.items(): |
147 path = pycompat.fsencode(path) | 176 path = pycompat.fsencode(path) |
148 if not match(path): | 177 if not match(path): |
149 continue | 178 continue |
191 return ( | 220 return ( |
192 False, | 221 False, |
193 scmutil.status( | 222 scmutil.status( |
194 modified, added, removed, deleted, unknown, ignored, clean | 223 modified, added, removed, deleted, unknown, ignored, clean |
195 ), | 224 ), |
225 mtime_boundary, | |
196 ) | 226 ) |
197 | 227 |
198 def flagfunc(self, buildfallback): | 228 def flagfunc(self, buildfallback): |
199 # TODO we can do better | 229 # TODO we can do better |
200 return buildfallback() | 230 return buildfallback() |
202 def getcwd(self): | 232 def getcwd(self): |
203 # TODO is this a good way to do this? | 233 # TODO is this a good way to do this? |
204 return os.path.dirname( | 234 return os.path.dirname( |
205 os.path.dirname(pycompat.fsencode(self.git.path)) | 235 os.path.dirname(pycompat.fsencode(self.git.path)) |
206 ) | 236 ) |
237 | |
238 def get_entry(self, path): | |
239 """return a DirstateItem for the associated path""" | |
240 entry = self._map.get(path) | |
241 if entry is None: | |
242 return DirstateItem() | |
243 return entry | |
207 | 244 |
208 def normalize(self, path): | 245 def normalize(self, path): |
209 normed = util.normcase(path) | 246 normed = util.normcase(path) |
210 assert normed == path, b"TODO handling of case folding: %s != %s" % ( | 247 assert normed == path, b"TODO handling of case folding: %s != %s" % ( |
211 normed, | 248 normed, |