Show More
@@ -1,3734 +1,3734 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import os |
|
11 | import os | |
12 | import random |
|
12 | import random | |
13 | import sys |
|
13 | import sys | |
14 | import time |
|
14 | import time | |
15 | import weakref |
|
15 | import weakref | |
16 |
|
16 | |||
17 | from .i18n import _ |
|
17 | from .i18n import _ | |
18 | from .node import ( |
|
18 | from .node import ( | |
19 | bin, |
|
19 | bin, | |
20 | hex, |
|
20 | hex, | |
21 | nullid, |
|
21 | nullid, | |
22 | nullrev, |
|
22 | nullrev, | |
23 | short, |
|
23 | short, | |
24 | ) |
|
24 | ) | |
25 | from .pycompat import ( |
|
25 | from .pycompat import ( | |
26 | delattr, |
|
26 | delattr, | |
27 | getattr, |
|
27 | getattr, | |
28 | ) |
|
28 | ) | |
29 | from . import ( |
|
29 | from . import ( | |
30 | bookmarks, |
|
30 | bookmarks, | |
31 | branchmap, |
|
31 | branchmap, | |
32 | bundle2, |
|
32 | bundle2, | |
33 | changegroup, |
|
33 | changegroup, | |
34 | color, |
|
34 | color, | |
35 | context, |
|
35 | context, | |
36 | dirstate, |
|
36 | dirstate, | |
37 | dirstateguard, |
|
37 | dirstateguard, | |
38 | discovery, |
|
38 | discovery, | |
39 | encoding, |
|
39 | encoding, | |
40 | error, |
|
40 | error, | |
41 | exchange, |
|
41 | exchange, | |
42 | extensions, |
|
42 | extensions, | |
43 | filelog, |
|
43 | filelog, | |
44 | hook, |
|
44 | hook, | |
45 | lock as lockmod, |
|
45 | lock as lockmod, | |
46 | match as matchmod, |
|
46 | match as matchmod, | |
47 | merge as mergemod, |
|
47 | merge as mergemod, | |
48 | mergeutil, |
|
48 | mergeutil, | |
49 | namespaces, |
|
49 | namespaces, | |
50 | narrowspec, |
|
50 | narrowspec, | |
51 | obsolete, |
|
51 | obsolete, | |
52 | pathutil, |
|
52 | pathutil, | |
53 | phases, |
|
53 | phases, | |
54 | pushkey, |
|
54 | pushkey, | |
55 | pycompat, |
|
55 | pycompat, | |
56 | repoview, |
|
56 | repoview, | |
57 | revset, |
|
57 | revset, | |
58 | revsetlang, |
|
58 | revsetlang, | |
59 | scmutil, |
|
59 | scmutil, | |
60 | sparse, |
|
60 | sparse, | |
61 | store as storemod, |
|
61 | store as storemod, | |
62 | subrepoutil, |
|
62 | subrepoutil, | |
63 | tags as tagsmod, |
|
63 | tags as tagsmod, | |
64 | transaction, |
|
64 | transaction, | |
65 | txnutil, |
|
65 | txnutil, | |
66 | util, |
|
66 | util, | |
67 | vfs as vfsmod, |
|
67 | vfs as vfsmod, | |
68 | ) |
|
68 | ) | |
69 |
|
69 | |||
70 | from .interfaces import ( |
|
70 | from .interfaces import ( | |
71 | repository, |
|
71 | repository, | |
72 | util as interfaceutil, |
|
72 | util as interfaceutil, | |
73 | ) |
|
73 | ) | |
74 |
|
74 | |||
75 | from .utils import ( |
|
75 | from .utils import ( | |
76 | hashutil, |
|
76 | hashutil, | |
77 | procutil, |
|
77 | procutil, | |
78 | stringutil, |
|
78 | stringutil, | |
79 | ) |
|
79 | ) | |
80 |
|
80 | |||
81 | from .revlogutils import constants as revlogconst |
|
81 | from .revlogutils import constants as revlogconst | |
82 |
|
82 | |||
83 | release = lockmod.release |
|
83 | release = lockmod.release | |
84 | urlerr = util.urlerr |
|
84 | urlerr = util.urlerr | |
85 | urlreq = util.urlreq |
|
85 | urlreq = util.urlreq | |
86 |
|
86 | |||
87 | # set of (path, vfs-location) tuples. vfs-location is: |
|
87 | # set of (path, vfs-location) tuples. vfs-location is: | |
88 | # - 'plain for vfs relative paths |
|
88 | # - 'plain for vfs relative paths | |
89 | # - '' for svfs relative paths |
|
89 | # - '' for svfs relative paths | |
90 | _cachedfiles = set() |
|
90 | _cachedfiles = set() | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | class _basefilecache(scmutil.filecache): |
|
93 | class _basefilecache(scmutil.filecache): | |
94 | """All filecache usage on repo are done for logic that should be unfiltered |
|
94 | """All filecache usage on repo are done for logic that should be unfiltered | |
95 | """ |
|
95 | """ | |
96 |
|
96 | |||
97 | def __get__(self, repo, type=None): |
|
97 | def __get__(self, repo, type=None): | |
98 | if repo is None: |
|
98 | if repo is None: | |
99 | return self |
|
99 | return self | |
100 | # proxy to unfiltered __dict__ since filtered repo has no entry |
|
100 | # proxy to unfiltered __dict__ since filtered repo has no entry | |
101 | unfi = repo.unfiltered() |
|
101 | unfi = repo.unfiltered() | |
102 | try: |
|
102 | try: | |
103 | return unfi.__dict__[self.sname] |
|
103 | return unfi.__dict__[self.sname] | |
104 | except KeyError: |
|
104 | except KeyError: | |
105 | pass |
|
105 | pass | |
106 | return super(_basefilecache, self).__get__(unfi, type) |
|
106 | return super(_basefilecache, self).__get__(unfi, type) | |
107 |
|
107 | |||
108 | def set(self, repo, value): |
|
108 | def set(self, repo, value): | |
109 | return super(_basefilecache, self).set(repo.unfiltered(), value) |
|
109 | return super(_basefilecache, self).set(repo.unfiltered(), value) | |
110 |
|
110 | |||
111 |
|
111 | |||
112 | class repofilecache(_basefilecache): |
|
112 | class repofilecache(_basefilecache): | |
113 | """filecache for files in .hg but outside of .hg/store""" |
|
113 | """filecache for files in .hg but outside of .hg/store""" | |
114 |
|
114 | |||
115 | def __init__(self, *paths): |
|
115 | def __init__(self, *paths): | |
116 | super(repofilecache, self).__init__(*paths) |
|
116 | super(repofilecache, self).__init__(*paths) | |
117 | for path in paths: |
|
117 | for path in paths: | |
118 | _cachedfiles.add((path, b'plain')) |
|
118 | _cachedfiles.add((path, b'plain')) | |
119 |
|
119 | |||
120 | def join(self, obj, fname): |
|
120 | def join(self, obj, fname): | |
121 | return obj.vfs.join(fname) |
|
121 | return obj.vfs.join(fname) | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | class storecache(_basefilecache): |
|
124 | class storecache(_basefilecache): | |
125 | """filecache for files in the store""" |
|
125 | """filecache for files in the store""" | |
126 |
|
126 | |||
127 | def __init__(self, *paths): |
|
127 | def __init__(self, *paths): | |
128 | super(storecache, self).__init__(*paths) |
|
128 | super(storecache, self).__init__(*paths) | |
129 | for path in paths: |
|
129 | for path in paths: | |
130 | _cachedfiles.add((path, b'')) |
|
130 | _cachedfiles.add((path, b'')) | |
131 |
|
131 | |||
132 | def join(self, obj, fname): |
|
132 | def join(self, obj, fname): | |
133 | return obj.sjoin(fname) |
|
133 | return obj.sjoin(fname) | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | class mixedrepostorecache(_basefilecache): |
|
136 | class mixedrepostorecache(_basefilecache): | |
137 | """filecache for a mix files in .hg/store and outside""" |
|
137 | """filecache for a mix files in .hg/store and outside""" | |
138 |
|
138 | |||
139 | def __init__(self, *pathsandlocations): |
|
139 | def __init__(self, *pathsandlocations): | |
140 | # scmutil.filecache only uses the path for passing back into our |
|
140 | # scmutil.filecache only uses the path for passing back into our | |
141 | # join(), so we can safely pass a list of paths and locations |
|
141 | # join(), so we can safely pass a list of paths and locations | |
142 | super(mixedrepostorecache, self).__init__(*pathsandlocations) |
|
142 | super(mixedrepostorecache, self).__init__(*pathsandlocations) | |
143 | _cachedfiles.update(pathsandlocations) |
|
143 | _cachedfiles.update(pathsandlocations) | |
144 |
|
144 | |||
145 | def join(self, obj, fnameandlocation): |
|
145 | def join(self, obj, fnameandlocation): | |
146 | fname, location = fnameandlocation |
|
146 | fname, location = fnameandlocation | |
147 | if location == b'plain': |
|
147 | if location == b'plain': | |
148 | return obj.vfs.join(fname) |
|
148 | return obj.vfs.join(fname) | |
149 | else: |
|
149 | else: | |
150 | if location != b'': |
|
150 | if location != b'': | |
151 | raise error.ProgrammingError( |
|
151 | raise error.ProgrammingError( | |
152 | b'unexpected location: %s' % location |
|
152 | b'unexpected location: %s' % location | |
153 | ) |
|
153 | ) | |
154 | return obj.sjoin(fname) |
|
154 | return obj.sjoin(fname) | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | def isfilecached(repo, name): |
|
157 | def isfilecached(repo, name): | |
158 | """check if a repo has already cached "name" filecache-ed property |
|
158 | """check if a repo has already cached "name" filecache-ed property | |
159 |
|
159 | |||
160 | This returns (cachedobj-or-None, iscached) tuple. |
|
160 | This returns (cachedobj-or-None, iscached) tuple. | |
161 | """ |
|
161 | """ | |
162 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
162 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
163 | if not cacheentry: |
|
163 | if not cacheentry: | |
164 | return None, False |
|
164 | return None, False | |
165 | return cacheentry.obj, True |
|
165 | return cacheentry.obj, True | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | class unfilteredpropertycache(util.propertycache): |
|
168 | class unfilteredpropertycache(util.propertycache): | |
169 | """propertycache that apply to unfiltered repo only""" |
|
169 | """propertycache that apply to unfiltered repo only""" | |
170 |
|
170 | |||
171 | def __get__(self, repo, type=None): |
|
171 | def __get__(self, repo, type=None): | |
172 | unfi = repo.unfiltered() |
|
172 | unfi = repo.unfiltered() | |
173 | if unfi is repo: |
|
173 | if unfi is repo: | |
174 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
174 | return super(unfilteredpropertycache, self).__get__(unfi) | |
175 | return getattr(unfi, self.name) |
|
175 | return getattr(unfi, self.name) | |
176 |
|
176 | |||
177 |
|
177 | |||
178 | class filteredpropertycache(util.propertycache): |
|
178 | class filteredpropertycache(util.propertycache): | |
179 | """propertycache that must take filtering in account""" |
|
179 | """propertycache that must take filtering in account""" | |
180 |
|
180 | |||
181 | def cachevalue(self, obj, value): |
|
181 | def cachevalue(self, obj, value): | |
182 | object.__setattr__(obj, self.name, value) |
|
182 | object.__setattr__(obj, self.name, value) | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | def hasunfilteredcache(repo, name): |
|
185 | def hasunfilteredcache(repo, name): | |
186 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
186 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
187 | return name in vars(repo.unfiltered()) |
|
187 | return name in vars(repo.unfiltered()) | |
188 |
|
188 | |||
189 |
|
189 | |||
190 | def unfilteredmethod(orig): |
|
190 | def unfilteredmethod(orig): | |
191 | """decorate method that always need to be run on unfiltered version""" |
|
191 | """decorate method that always need to be run on unfiltered version""" | |
192 |
|
192 | |||
193 | def wrapper(repo, *args, **kwargs): |
|
193 | def wrapper(repo, *args, **kwargs): | |
194 | return orig(repo.unfiltered(), *args, **kwargs) |
|
194 | return orig(repo.unfiltered(), *args, **kwargs) | |
195 |
|
195 | |||
196 | return wrapper |
|
196 | return wrapper | |
197 |
|
197 | |||
198 |
|
198 | |||
199 | moderncaps = { |
|
199 | moderncaps = { | |
200 | b'lookup', |
|
200 | b'lookup', | |
201 | b'branchmap', |
|
201 | b'branchmap', | |
202 | b'pushkey', |
|
202 | b'pushkey', | |
203 | b'known', |
|
203 | b'known', | |
204 | b'getbundle', |
|
204 | b'getbundle', | |
205 | b'unbundle', |
|
205 | b'unbundle', | |
206 | } |
|
206 | } | |
207 | legacycaps = moderncaps.union({b'changegroupsubset'}) |
|
207 | legacycaps = moderncaps.union({b'changegroupsubset'}) | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | @interfaceutil.implementer(repository.ipeercommandexecutor) |
|
210 | @interfaceutil.implementer(repository.ipeercommandexecutor) | |
211 | class localcommandexecutor(object): |
|
211 | class localcommandexecutor(object): | |
212 | def __init__(self, peer): |
|
212 | def __init__(self, peer): | |
213 | self._peer = peer |
|
213 | self._peer = peer | |
214 | self._sent = False |
|
214 | self._sent = False | |
215 | self._closed = False |
|
215 | self._closed = False | |
216 |
|
216 | |||
217 | def __enter__(self): |
|
217 | def __enter__(self): | |
218 | return self |
|
218 | return self | |
219 |
|
219 | |||
220 | def __exit__(self, exctype, excvalue, exctb): |
|
220 | def __exit__(self, exctype, excvalue, exctb): | |
221 | self.close() |
|
221 | self.close() | |
222 |
|
222 | |||
223 | def callcommand(self, command, args): |
|
223 | def callcommand(self, command, args): | |
224 | if self._sent: |
|
224 | if self._sent: | |
225 | raise error.ProgrammingError( |
|
225 | raise error.ProgrammingError( | |
226 | b'callcommand() cannot be used after sendcommands()' |
|
226 | b'callcommand() cannot be used after sendcommands()' | |
227 | ) |
|
227 | ) | |
228 |
|
228 | |||
229 | if self._closed: |
|
229 | if self._closed: | |
230 | raise error.ProgrammingError( |
|
230 | raise error.ProgrammingError( | |
231 | b'callcommand() cannot be used after close()' |
|
231 | b'callcommand() cannot be used after close()' | |
232 | ) |
|
232 | ) | |
233 |
|
233 | |||
234 | # We don't need to support anything fancy. Just call the named |
|
234 | # We don't need to support anything fancy. Just call the named | |
235 | # method on the peer and return a resolved future. |
|
235 | # method on the peer and return a resolved future. | |
236 | fn = getattr(self._peer, pycompat.sysstr(command)) |
|
236 | fn = getattr(self._peer, pycompat.sysstr(command)) | |
237 |
|
237 | |||
238 | f = pycompat.futures.Future() |
|
238 | f = pycompat.futures.Future() | |
239 |
|
239 | |||
240 | try: |
|
240 | try: | |
241 | result = fn(**pycompat.strkwargs(args)) |
|
241 | result = fn(**pycompat.strkwargs(args)) | |
242 | except Exception: |
|
242 | except Exception: | |
243 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) |
|
243 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) | |
244 | else: |
|
244 | else: | |
245 | f.set_result(result) |
|
245 | f.set_result(result) | |
246 |
|
246 | |||
247 | return f |
|
247 | return f | |
248 |
|
248 | |||
249 | def sendcommands(self): |
|
249 | def sendcommands(self): | |
250 | self._sent = True |
|
250 | self._sent = True | |
251 |
|
251 | |||
252 | def close(self): |
|
252 | def close(self): | |
253 | self._closed = True |
|
253 | self._closed = True | |
254 |
|
254 | |||
255 |
|
255 | |||
256 | @interfaceutil.implementer(repository.ipeercommands) |
|
256 | @interfaceutil.implementer(repository.ipeercommands) | |
257 | class localpeer(repository.peer): |
|
257 | class localpeer(repository.peer): | |
258 | '''peer for a local repo; reflects only the most recent API''' |
|
258 | '''peer for a local repo; reflects only the most recent API''' | |
259 |
|
259 | |||
260 | def __init__(self, repo, caps=None): |
|
260 | def __init__(self, repo, caps=None): | |
261 | super(localpeer, self).__init__() |
|
261 | super(localpeer, self).__init__() | |
262 |
|
262 | |||
263 | if caps is None: |
|
263 | if caps is None: | |
264 | caps = moderncaps.copy() |
|
264 | caps = moderncaps.copy() | |
265 | self._repo = repo.filtered(b'served') |
|
265 | self._repo = repo.filtered(b'served') | |
266 | self.ui = repo.ui |
|
266 | self.ui = repo.ui | |
267 | self._caps = repo._restrictcapabilities(caps) |
|
267 | self._caps = repo._restrictcapabilities(caps) | |
268 |
|
268 | |||
269 | # Begin of _basepeer interface. |
|
269 | # Begin of _basepeer interface. | |
270 |
|
270 | |||
271 | def url(self): |
|
271 | def url(self): | |
272 | return self._repo.url() |
|
272 | return self._repo.url() | |
273 |
|
273 | |||
274 | def local(self): |
|
274 | def local(self): | |
275 | return self._repo |
|
275 | return self._repo | |
276 |
|
276 | |||
277 | def peer(self): |
|
277 | def peer(self): | |
278 | return self |
|
278 | return self | |
279 |
|
279 | |||
280 | def canpush(self): |
|
280 | def canpush(self): | |
281 | return True |
|
281 | return True | |
282 |
|
282 | |||
283 | def close(self): |
|
283 | def close(self): | |
284 | self._repo.close() |
|
284 | self._repo.close() | |
285 |
|
285 | |||
286 | # End of _basepeer interface. |
|
286 | # End of _basepeer interface. | |
287 |
|
287 | |||
288 | # Begin of _basewirecommands interface. |
|
288 | # Begin of _basewirecommands interface. | |
289 |
|
289 | |||
290 | def branchmap(self): |
|
290 | def branchmap(self): | |
291 | return self._repo.branchmap() |
|
291 | return self._repo.branchmap() | |
292 |
|
292 | |||
293 | def capabilities(self): |
|
293 | def capabilities(self): | |
294 | return self._caps |
|
294 | return self._caps | |
295 |
|
295 | |||
296 | def clonebundles(self): |
|
296 | def clonebundles(self): | |
297 | return self._repo.tryread(b'clonebundles.manifest') |
|
297 | return self._repo.tryread(b'clonebundles.manifest') | |
298 |
|
298 | |||
299 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
299 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
300 | """Used to test argument passing over the wire""" |
|
300 | """Used to test argument passing over the wire""" | |
301 | return b"%s %s %s %s %s" % ( |
|
301 | return b"%s %s %s %s %s" % ( | |
302 | one, |
|
302 | one, | |
303 | two, |
|
303 | two, | |
304 | pycompat.bytestr(three), |
|
304 | pycompat.bytestr(three), | |
305 | pycompat.bytestr(four), |
|
305 | pycompat.bytestr(four), | |
306 | pycompat.bytestr(five), |
|
306 | pycompat.bytestr(five), | |
307 | ) |
|
307 | ) | |
308 |
|
308 | |||
309 | def getbundle( |
|
309 | def getbundle( | |
310 | self, source, heads=None, common=None, bundlecaps=None, **kwargs |
|
310 | self, source, heads=None, common=None, bundlecaps=None, **kwargs | |
311 | ): |
|
311 | ): | |
312 | chunks = exchange.getbundlechunks( |
|
312 | chunks = exchange.getbundlechunks( | |
313 | self._repo, |
|
313 | self._repo, | |
314 | source, |
|
314 | source, | |
315 | heads=heads, |
|
315 | heads=heads, | |
316 | common=common, |
|
316 | common=common, | |
317 | bundlecaps=bundlecaps, |
|
317 | bundlecaps=bundlecaps, | |
318 | **kwargs |
|
318 | **kwargs | |
319 | )[1] |
|
319 | )[1] | |
320 | cb = util.chunkbuffer(chunks) |
|
320 | cb = util.chunkbuffer(chunks) | |
321 |
|
321 | |||
322 | if exchange.bundle2requested(bundlecaps): |
|
322 | if exchange.bundle2requested(bundlecaps): | |
323 | # When requesting a bundle2, getbundle returns a stream to make the |
|
323 | # When requesting a bundle2, getbundle returns a stream to make the | |
324 | # wire level function happier. We need to build a proper object |
|
324 | # wire level function happier. We need to build a proper object | |
325 | # from it in local peer. |
|
325 | # from it in local peer. | |
326 | return bundle2.getunbundler(self.ui, cb) |
|
326 | return bundle2.getunbundler(self.ui, cb) | |
327 | else: |
|
327 | else: | |
328 | return changegroup.getunbundler(b'01', cb, None) |
|
328 | return changegroup.getunbundler(b'01', cb, None) | |
329 |
|
329 | |||
330 | def heads(self): |
|
330 | def heads(self): | |
331 | return self._repo.heads() |
|
331 | return self._repo.heads() | |
332 |
|
332 | |||
333 | def known(self, nodes): |
|
333 | def known(self, nodes): | |
334 | return self._repo.known(nodes) |
|
334 | return self._repo.known(nodes) | |
335 |
|
335 | |||
336 | def listkeys(self, namespace): |
|
336 | def listkeys(self, namespace): | |
337 | return self._repo.listkeys(namespace) |
|
337 | return self._repo.listkeys(namespace) | |
338 |
|
338 | |||
339 | def lookup(self, key): |
|
339 | def lookup(self, key): | |
340 | return self._repo.lookup(key) |
|
340 | return self._repo.lookup(key) | |
341 |
|
341 | |||
342 | def pushkey(self, namespace, key, old, new): |
|
342 | def pushkey(self, namespace, key, old, new): | |
343 | return self._repo.pushkey(namespace, key, old, new) |
|
343 | return self._repo.pushkey(namespace, key, old, new) | |
344 |
|
344 | |||
345 | def stream_out(self): |
|
345 | def stream_out(self): | |
346 | raise error.Abort(_(b'cannot perform stream clone against local peer')) |
|
346 | raise error.Abort(_(b'cannot perform stream clone against local peer')) | |
347 |
|
347 | |||
348 | def unbundle(self, bundle, heads, url): |
|
348 | def unbundle(self, bundle, heads, url): | |
349 | """apply a bundle on a repo |
|
349 | """apply a bundle on a repo | |
350 |
|
350 | |||
351 | This function handles the repo locking itself.""" |
|
351 | This function handles the repo locking itself.""" | |
352 | try: |
|
352 | try: | |
353 | try: |
|
353 | try: | |
354 | bundle = exchange.readbundle(self.ui, bundle, None) |
|
354 | bundle = exchange.readbundle(self.ui, bundle, None) | |
355 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) |
|
355 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) | |
356 | if util.safehasattr(ret, b'getchunks'): |
|
356 | if util.safehasattr(ret, b'getchunks'): | |
357 | # This is a bundle20 object, turn it into an unbundler. |
|
357 | # This is a bundle20 object, turn it into an unbundler. | |
358 | # This little dance should be dropped eventually when the |
|
358 | # This little dance should be dropped eventually when the | |
359 | # API is finally improved. |
|
359 | # API is finally improved. | |
360 | stream = util.chunkbuffer(ret.getchunks()) |
|
360 | stream = util.chunkbuffer(ret.getchunks()) | |
361 | ret = bundle2.getunbundler(self.ui, stream) |
|
361 | ret = bundle2.getunbundler(self.ui, stream) | |
362 | return ret |
|
362 | return ret | |
363 | except Exception as exc: |
|
363 | except Exception as exc: | |
364 | # If the exception contains output salvaged from a bundle2 |
|
364 | # If the exception contains output salvaged from a bundle2 | |
365 | # reply, we need to make sure it is printed before continuing |
|
365 | # reply, we need to make sure it is printed before continuing | |
366 | # to fail. So we build a bundle2 with such output and consume |
|
366 | # to fail. So we build a bundle2 with such output and consume | |
367 | # it directly. |
|
367 | # it directly. | |
368 | # |
|
368 | # | |
369 | # This is not very elegant but allows a "simple" solution for |
|
369 | # This is not very elegant but allows a "simple" solution for | |
370 | # issue4594 |
|
370 | # issue4594 | |
371 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
371 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
372 | if output: |
|
372 | if output: | |
373 | bundler = bundle2.bundle20(self._repo.ui) |
|
373 | bundler = bundle2.bundle20(self._repo.ui) | |
374 | for out in output: |
|
374 | for out in output: | |
375 | bundler.addpart(out) |
|
375 | bundler.addpart(out) | |
376 | stream = util.chunkbuffer(bundler.getchunks()) |
|
376 | stream = util.chunkbuffer(bundler.getchunks()) | |
377 | b = bundle2.getunbundler(self.ui, stream) |
|
377 | b = bundle2.getunbundler(self.ui, stream) | |
378 | bundle2.processbundle(self._repo, b) |
|
378 | bundle2.processbundle(self._repo, b) | |
379 | raise |
|
379 | raise | |
380 | except error.PushRaced as exc: |
|
380 | except error.PushRaced as exc: | |
381 | raise error.ResponseError( |
|
381 | raise error.ResponseError( | |
382 | _(b'push failed:'), stringutil.forcebytestr(exc) |
|
382 | _(b'push failed:'), stringutil.forcebytestr(exc) | |
383 | ) |
|
383 | ) | |
384 |
|
384 | |||
385 | # End of _basewirecommands interface. |
|
385 | # End of _basewirecommands interface. | |
386 |
|
386 | |||
387 | # Begin of peer interface. |
|
387 | # Begin of peer interface. | |
388 |
|
388 | |||
389 | def commandexecutor(self): |
|
389 | def commandexecutor(self): | |
390 | return localcommandexecutor(self) |
|
390 | return localcommandexecutor(self) | |
391 |
|
391 | |||
392 | # End of peer interface. |
|
392 | # End of peer interface. | |
393 |
|
393 | |||
394 |
|
394 | |||
395 | @interfaceutil.implementer(repository.ipeerlegacycommands) |
|
395 | @interfaceutil.implementer(repository.ipeerlegacycommands) | |
396 | class locallegacypeer(localpeer): |
|
396 | class locallegacypeer(localpeer): | |
397 | '''peer extension which implements legacy methods too; used for tests with |
|
397 | '''peer extension which implements legacy methods too; used for tests with | |
398 | restricted capabilities''' |
|
398 | restricted capabilities''' | |
399 |
|
399 | |||
400 | def __init__(self, repo): |
|
400 | def __init__(self, repo): | |
401 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
401 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
402 |
|
402 | |||
403 | # Begin of baselegacywirecommands interface. |
|
403 | # Begin of baselegacywirecommands interface. | |
404 |
|
404 | |||
405 | def between(self, pairs): |
|
405 | def between(self, pairs): | |
406 | return self._repo.between(pairs) |
|
406 | return self._repo.between(pairs) | |
407 |
|
407 | |||
408 | def branches(self, nodes): |
|
408 | def branches(self, nodes): | |
409 | return self._repo.branches(nodes) |
|
409 | return self._repo.branches(nodes) | |
410 |
|
410 | |||
411 | def changegroup(self, nodes, source): |
|
411 | def changegroup(self, nodes, source): | |
412 | outgoing = discovery.outgoing( |
|
412 | outgoing = discovery.outgoing( | |
413 | self._repo, missingroots=nodes, missingheads=self._repo.heads() |
|
413 | self._repo, missingroots=nodes, missingheads=self._repo.heads() | |
414 | ) |
|
414 | ) | |
415 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
415 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
416 |
|
416 | |||
417 | def changegroupsubset(self, bases, heads, source): |
|
417 | def changegroupsubset(self, bases, heads, source): | |
418 | outgoing = discovery.outgoing( |
|
418 | outgoing = discovery.outgoing( | |
419 | self._repo, missingroots=bases, missingheads=heads |
|
419 | self._repo, missingroots=bases, missingheads=heads | |
420 | ) |
|
420 | ) | |
421 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
421 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
422 |
|
422 | |||
423 | # End of baselegacywirecommands interface. |
|
423 | # End of baselegacywirecommands interface. | |
424 |
|
424 | |||
425 |
|
425 | |||
426 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
426 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
427 | # clients. |
|
427 | # clients. | |
428 | REVLOGV2_REQUIREMENT = b'exp-revlogv2.1' |
|
428 | REVLOGV2_REQUIREMENT = b'exp-revlogv2.1' | |
429 |
|
429 | |||
430 | # A repository with the sparserevlog feature will have delta chains that |
|
430 | # A repository with the sparserevlog feature will have delta chains that | |
431 | # can spread over a larger span. Sparse reading cuts these large spans into |
|
431 | # can spread over a larger span. Sparse reading cuts these large spans into | |
432 | # pieces, so that each piece isn't too big. |
|
432 | # pieces, so that each piece isn't too big. | |
433 | # Without the sparserevlog capability, reading from the repository could use |
|
433 | # Without the sparserevlog capability, reading from the repository could use | |
434 | # huge amounts of memory, because the whole span would be read at once, |
|
434 | # huge amounts of memory, because the whole span would be read at once, | |
435 | # including all the intermediate revisions that aren't pertinent for the chain. |
|
435 | # including all the intermediate revisions that aren't pertinent for the chain. | |
436 | # This is why once a repository has enabled sparse-read, it becomes required. |
|
436 | # This is why once a repository has enabled sparse-read, it becomes required. | |
437 | SPARSEREVLOG_REQUIREMENT = b'sparserevlog' |
|
437 | SPARSEREVLOG_REQUIREMENT = b'sparserevlog' | |
438 |
|
438 | |||
439 | # A repository with the sidedataflag requirement will allow to store extra |
|
439 | # A repository with the sidedataflag requirement will allow to store extra | |
440 | # information for revision without altering their original hashes. |
|
440 | # information for revision without altering their original hashes. | |
441 | SIDEDATA_REQUIREMENT = b'exp-sidedata-flag' |
|
441 | SIDEDATA_REQUIREMENT = b'exp-sidedata-flag' | |
442 |
|
442 | |||
443 | # A repository with the the copies-sidedata-changeset requirement will store |
|
443 | # A repository with the the copies-sidedata-changeset requirement will store | |
444 | # copies related information in changeset's sidedata. |
|
444 | # copies related information in changeset's sidedata. | |
445 | COPIESSDC_REQUIREMENT = b'exp-copies-sidedata-changeset' |
|
445 | COPIESSDC_REQUIREMENT = b'exp-copies-sidedata-changeset' | |
446 |
|
446 | |||
447 | # Functions receiving (ui, features) that extensions can register to impact |
|
447 | # Functions receiving (ui, features) that extensions can register to impact | |
448 | # the ability to load repositories with custom requirements. Only |
|
448 | # the ability to load repositories with custom requirements. Only | |
449 | # functions defined in loaded extensions are called. |
|
449 | # functions defined in loaded extensions are called. | |
450 | # |
|
450 | # | |
451 | # The function receives a set of requirement strings that the repository |
|
451 | # The function receives a set of requirement strings that the repository | |
452 | # is capable of opening. Functions will typically add elements to the |
|
452 | # is capable of opening. Functions will typically add elements to the | |
453 | # set to reflect that the extension knows how to handle that requirements. |
|
453 | # set to reflect that the extension knows how to handle that requirements. | |
454 | featuresetupfuncs = set() |
|
454 | featuresetupfuncs = set() | |
455 |
|
455 | |||
456 |
|
456 | |||
457 | def makelocalrepository(baseui, path, intents=None): |
|
457 | def makelocalrepository(baseui, path, intents=None): | |
458 | """Create a local repository object. |
|
458 | """Create a local repository object. | |
459 |
|
459 | |||
460 | Given arguments needed to construct a local repository, this function |
|
460 | Given arguments needed to construct a local repository, this function | |
461 | performs various early repository loading functionality (such as |
|
461 | performs various early repository loading functionality (such as | |
462 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that |
|
462 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that | |
463 | the repository can be opened, derives a type suitable for representing |
|
463 | the repository can be opened, derives a type suitable for representing | |
464 | that repository, and returns an instance of it. |
|
464 | that repository, and returns an instance of it. | |
465 |
|
465 | |||
466 | The returned object conforms to the ``repository.completelocalrepository`` |
|
466 | The returned object conforms to the ``repository.completelocalrepository`` | |
467 | interface. |
|
467 | interface. | |
468 |
|
468 | |||
469 | The repository type is derived by calling a series of factory functions |
|
469 | The repository type is derived by calling a series of factory functions | |
470 | for each aspect/interface of the final repository. These are defined by |
|
470 | for each aspect/interface of the final repository. These are defined by | |
471 | ``REPO_INTERFACES``. |
|
471 | ``REPO_INTERFACES``. | |
472 |
|
472 | |||
473 | Each factory function is called to produce a type implementing a specific |
|
473 | Each factory function is called to produce a type implementing a specific | |
474 | interface. The cumulative list of returned types will be combined into a |
|
474 | interface. The cumulative list of returned types will be combined into a | |
475 | new type and that type will be instantiated to represent the local |
|
475 | new type and that type will be instantiated to represent the local | |
476 | repository. |
|
476 | repository. | |
477 |
|
477 | |||
478 | The factory functions each receive various state that may be consulted |
|
478 | The factory functions each receive various state that may be consulted | |
479 | as part of deriving a type. |
|
479 | as part of deriving a type. | |
480 |
|
480 | |||
481 | Extensions should wrap these factory functions to customize repository type |
|
481 | Extensions should wrap these factory functions to customize repository type | |
482 | creation. Note that an extension's wrapped function may be called even if |
|
482 | creation. Note that an extension's wrapped function may be called even if | |
483 | that extension is not loaded for the repo being constructed. Extensions |
|
483 | that extension is not loaded for the repo being constructed. Extensions | |
484 | should check if their ``__name__`` appears in the |
|
484 | should check if their ``__name__`` appears in the | |
485 | ``extensionmodulenames`` set passed to the factory function and no-op if |
|
485 | ``extensionmodulenames`` set passed to the factory function and no-op if | |
486 | not. |
|
486 | not. | |
487 | """ |
|
487 | """ | |
488 | ui = baseui.copy() |
|
488 | ui = baseui.copy() | |
489 | # Prevent copying repo configuration. |
|
489 | # Prevent copying repo configuration. | |
490 | ui.copy = baseui.copy |
|
490 | ui.copy = baseui.copy | |
491 |
|
491 | |||
492 | # Working directory VFS rooted at repository root. |
|
492 | # Working directory VFS rooted at repository root. | |
493 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
493 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
494 |
|
494 | |||
495 | # Main VFS for .hg/ directory. |
|
495 | # Main VFS for .hg/ directory. | |
496 | hgpath = wdirvfs.join(b'.hg') |
|
496 | hgpath = wdirvfs.join(b'.hg') | |
497 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) |
|
497 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) | |
498 |
|
498 | |||
499 | # The .hg/ path should exist and should be a directory. All other |
|
499 | # The .hg/ path should exist and should be a directory. All other | |
500 | # cases are errors. |
|
500 | # cases are errors. | |
501 | if not hgvfs.isdir(): |
|
501 | if not hgvfs.isdir(): | |
502 | try: |
|
502 | try: | |
503 | hgvfs.stat() |
|
503 | hgvfs.stat() | |
504 | except OSError as e: |
|
504 | except OSError as e: | |
505 | if e.errno != errno.ENOENT: |
|
505 | if e.errno != errno.ENOENT: | |
506 | raise |
|
506 | raise | |
507 |
|
507 | |||
508 | raise error.RepoError(_(b'repository %s not found') % path) |
|
508 | raise error.RepoError(_(b'repository %s not found') % path) | |
509 |
|
509 | |||
510 | # .hg/requires file contains a newline-delimited list of |
|
510 | # .hg/requires file contains a newline-delimited list of | |
511 | # features/capabilities the opener (us) must have in order to use |
|
511 | # features/capabilities the opener (us) must have in order to use | |
512 | # the repository. This file was introduced in Mercurial 0.9.2, |
|
512 | # the repository. This file was introduced in Mercurial 0.9.2, | |
513 | # which means very old repositories may not have one. We assume |
|
513 | # which means very old repositories may not have one. We assume | |
514 | # a missing file translates to no requirements. |
|
514 | # a missing file translates to no requirements. | |
515 | try: |
|
515 | try: | |
516 | requirements = set(hgvfs.read(b'requires').splitlines()) |
|
516 | requirements = set(hgvfs.read(b'requires').splitlines()) | |
517 | except IOError as e: |
|
517 | except IOError as e: | |
518 | if e.errno != errno.ENOENT: |
|
518 | if e.errno != errno.ENOENT: | |
519 | raise |
|
519 | raise | |
520 | requirements = set() |
|
520 | requirements = set() | |
521 |
|
521 | |||
522 | # The .hg/hgrc file may load extensions or contain config options |
|
522 | # The .hg/hgrc file may load extensions or contain config options | |
523 | # that influence repository construction. Attempt to load it and |
|
523 | # that influence repository construction. Attempt to load it and | |
524 | # process any new extensions that it may have pulled in. |
|
524 | # process any new extensions that it may have pulled in. | |
525 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
525 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
526 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
|
526 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) | |
527 | extensions.loadall(ui) |
|
527 | extensions.loadall(ui) | |
528 | extensions.populateui(ui) |
|
528 | extensions.populateui(ui) | |
529 |
|
529 | |||
530 | # Set of module names of extensions loaded for this repository. |
|
530 | # Set of module names of extensions loaded for this repository. | |
531 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} |
|
531 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} | |
532 |
|
532 | |||
533 | supportedrequirements = gathersupportedrequirements(ui) |
|
533 | supportedrequirements = gathersupportedrequirements(ui) | |
534 |
|
534 | |||
535 | # We first validate the requirements are known. |
|
535 | # We first validate the requirements are known. | |
536 | ensurerequirementsrecognized(requirements, supportedrequirements) |
|
536 | ensurerequirementsrecognized(requirements, supportedrequirements) | |
537 |
|
537 | |||
538 | # Then we validate that the known set is reasonable to use together. |
|
538 | # Then we validate that the known set is reasonable to use together. | |
539 | ensurerequirementscompatible(ui, requirements) |
|
539 | ensurerequirementscompatible(ui, requirements) | |
540 |
|
540 | |||
541 | # TODO there are unhandled edge cases related to opening repositories with |
|
541 | # TODO there are unhandled edge cases related to opening repositories with | |
542 | # shared storage. If storage is shared, we should also test for requirements |
|
542 | # shared storage. If storage is shared, we should also test for requirements | |
543 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in |
|
543 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in | |
544 | # that repo, as that repo may load extensions needed to open it. This is a |
|
544 | # that repo, as that repo may load extensions needed to open it. This is a | |
545 | # bit complicated because we don't want the other hgrc to overwrite settings |
|
545 | # bit complicated because we don't want the other hgrc to overwrite settings | |
546 | # in this hgrc. |
|
546 | # in this hgrc. | |
547 | # |
|
547 | # | |
548 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires |
|
548 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires | |
549 | # file when sharing repos. But if a requirement is added after the share is |
|
549 | # file when sharing repos. But if a requirement is added after the share is | |
550 | # performed, thereby introducing a new requirement for the opener, we may |
|
550 | # performed, thereby introducing a new requirement for the opener, we may | |
551 | # will not see that and could encounter a run-time error interacting with |
|
551 | # will not see that and could encounter a run-time error interacting with | |
552 | # that shared store since it has an unknown-to-us requirement. |
|
552 | # that shared store since it has an unknown-to-us requirement. | |
553 |
|
553 | |||
554 | # At this point, we know we should be capable of opening the repository. |
|
554 | # At this point, we know we should be capable of opening the repository. | |
555 | # Now get on with doing that. |
|
555 | # Now get on with doing that. | |
556 |
|
556 | |||
557 | features = set() |
|
557 | features = set() | |
558 |
|
558 | |||
559 | # The "store" part of the repository holds versioned data. How it is |
|
559 | # The "store" part of the repository holds versioned data. How it is | |
560 | # accessed is determined by various requirements. The ``shared`` or |
|
560 | # accessed is determined by various requirements. The ``shared`` or | |
561 | # ``relshared`` requirements indicate the store lives in the path contained |
|
561 | # ``relshared`` requirements indicate the store lives in the path contained | |
562 | # in the ``.hg/sharedpath`` file. This is an absolute path for |
|
562 | # in the ``.hg/sharedpath`` file. This is an absolute path for | |
563 | # ``shared`` and relative to ``.hg/`` for ``relshared``. |
|
563 | # ``shared`` and relative to ``.hg/`` for ``relshared``. | |
564 | if b'shared' in requirements or b'relshared' in requirements: |
|
564 | if b'shared' in requirements or b'relshared' in requirements: | |
565 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') |
|
565 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') | |
566 | if b'relshared' in requirements: |
|
566 | if b'relshared' in requirements: | |
567 | sharedpath = hgvfs.join(sharedpath) |
|
567 | sharedpath = hgvfs.join(sharedpath) | |
568 |
|
568 | |||
569 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) |
|
569 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) | |
570 |
|
570 | |||
571 | if not sharedvfs.exists(): |
|
571 | if not sharedvfs.exists(): | |
572 | raise error.RepoError( |
|
572 | raise error.RepoError( | |
573 | _(b'.hg/sharedpath points to nonexistent directory %s') |
|
573 | _(b'.hg/sharedpath points to nonexistent directory %s') | |
574 | % sharedvfs.base |
|
574 | % sharedvfs.base | |
575 | ) |
|
575 | ) | |
576 |
|
576 | |||
577 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) |
|
577 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) | |
578 |
|
578 | |||
579 | storebasepath = sharedvfs.base |
|
579 | storebasepath = sharedvfs.base | |
580 | cachepath = sharedvfs.join(b'cache') |
|
580 | cachepath = sharedvfs.join(b'cache') | |
581 | else: |
|
581 | else: | |
582 | storebasepath = hgvfs.base |
|
582 | storebasepath = hgvfs.base | |
583 | cachepath = hgvfs.join(b'cache') |
|
583 | cachepath = hgvfs.join(b'cache') | |
584 | wcachepath = hgvfs.join(b'wcache') |
|
584 | wcachepath = hgvfs.join(b'wcache') | |
585 |
|
585 | |||
586 | # The store has changed over time and the exact layout is dictated by |
|
586 | # The store has changed over time and the exact layout is dictated by | |
587 | # requirements. The store interface abstracts differences across all |
|
587 | # requirements. The store interface abstracts differences across all | |
588 | # of them. |
|
588 | # of them. | |
589 | store = makestore( |
|
589 | store = makestore( | |
590 | requirements, |
|
590 | requirements, | |
591 | storebasepath, |
|
591 | storebasepath, | |
592 | lambda base: vfsmod.vfs(base, cacheaudited=True), |
|
592 | lambda base: vfsmod.vfs(base, cacheaudited=True), | |
593 | ) |
|
593 | ) | |
594 | hgvfs.createmode = store.createmode |
|
594 | hgvfs.createmode = store.createmode | |
595 |
|
595 | |||
596 | storevfs = store.vfs |
|
596 | storevfs = store.vfs | |
597 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) |
|
597 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) | |
598 |
|
598 | |||
599 | # The cache vfs is used to manage cache files. |
|
599 | # The cache vfs is used to manage cache files. | |
600 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
600 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
601 | cachevfs.createmode = store.createmode |
|
601 | cachevfs.createmode = store.createmode | |
602 | # The cache vfs is used to manage cache files related to the working copy |
|
602 | # The cache vfs is used to manage cache files related to the working copy | |
603 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) |
|
603 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) | |
604 | wcachevfs.createmode = store.createmode |
|
604 | wcachevfs.createmode = store.createmode | |
605 |
|
605 | |||
606 | # Now resolve the type for the repository object. We do this by repeatedly |
|
606 | # Now resolve the type for the repository object. We do this by repeatedly | |
607 | # calling a factory function to produces types for specific aspects of the |
|
607 | # calling a factory function to produces types for specific aspects of the | |
608 | # repo's operation. The aggregate returned types are used as base classes |
|
608 | # repo's operation. The aggregate returned types are used as base classes | |
609 | # for a dynamically-derived type, which will represent our new repository. |
|
609 | # for a dynamically-derived type, which will represent our new repository. | |
610 |
|
610 | |||
611 | bases = [] |
|
611 | bases = [] | |
612 | extrastate = {} |
|
612 | extrastate = {} | |
613 |
|
613 | |||
614 | for iface, fn in REPO_INTERFACES: |
|
614 | for iface, fn in REPO_INTERFACES: | |
615 | # We pass all potentially useful state to give extensions tons of |
|
615 | # We pass all potentially useful state to give extensions tons of | |
616 | # flexibility. |
|
616 | # flexibility. | |
617 | typ = fn()( |
|
617 | typ = fn()( | |
618 | ui=ui, |
|
618 | ui=ui, | |
619 | intents=intents, |
|
619 | intents=intents, | |
620 | requirements=requirements, |
|
620 | requirements=requirements, | |
621 | features=features, |
|
621 | features=features, | |
622 | wdirvfs=wdirvfs, |
|
622 | wdirvfs=wdirvfs, | |
623 | hgvfs=hgvfs, |
|
623 | hgvfs=hgvfs, | |
624 | store=store, |
|
624 | store=store, | |
625 | storevfs=storevfs, |
|
625 | storevfs=storevfs, | |
626 | storeoptions=storevfs.options, |
|
626 | storeoptions=storevfs.options, | |
627 | cachevfs=cachevfs, |
|
627 | cachevfs=cachevfs, | |
628 | wcachevfs=wcachevfs, |
|
628 | wcachevfs=wcachevfs, | |
629 | extensionmodulenames=extensionmodulenames, |
|
629 | extensionmodulenames=extensionmodulenames, | |
630 | extrastate=extrastate, |
|
630 | extrastate=extrastate, | |
631 | baseclasses=bases, |
|
631 | baseclasses=bases, | |
632 | ) |
|
632 | ) | |
633 |
|
633 | |||
634 | if not isinstance(typ, type): |
|
634 | if not isinstance(typ, type): | |
635 | raise error.ProgrammingError( |
|
635 | raise error.ProgrammingError( | |
636 | b'unable to construct type for %s' % iface |
|
636 | b'unable to construct type for %s' % iface | |
637 | ) |
|
637 | ) | |
638 |
|
638 | |||
639 | bases.append(typ) |
|
639 | bases.append(typ) | |
640 |
|
640 | |||
641 | # type() allows you to use characters in type names that wouldn't be |
|
641 | # type() allows you to use characters in type names that wouldn't be | |
642 | # recognized as Python symbols in source code. We abuse that to add |
|
642 | # recognized as Python symbols in source code. We abuse that to add | |
643 | # rich information about our constructed repo. |
|
643 | # rich information about our constructed repo. | |
644 | name = pycompat.sysstr( |
|
644 | name = pycompat.sysstr( | |
645 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) |
|
645 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) | |
646 | ) |
|
646 | ) | |
647 |
|
647 | |||
648 | cls = type(name, tuple(bases), {}) |
|
648 | cls = type(name, tuple(bases), {}) | |
649 |
|
649 | |||
650 | return cls( |
|
650 | return cls( | |
651 | baseui=baseui, |
|
651 | baseui=baseui, | |
652 | ui=ui, |
|
652 | ui=ui, | |
653 | origroot=path, |
|
653 | origroot=path, | |
654 | wdirvfs=wdirvfs, |
|
654 | wdirvfs=wdirvfs, | |
655 | hgvfs=hgvfs, |
|
655 | hgvfs=hgvfs, | |
656 | requirements=requirements, |
|
656 | requirements=requirements, | |
657 | supportedrequirements=supportedrequirements, |
|
657 | supportedrequirements=supportedrequirements, | |
658 | sharedpath=storebasepath, |
|
658 | sharedpath=storebasepath, | |
659 | store=store, |
|
659 | store=store, | |
660 | cachevfs=cachevfs, |
|
660 | cachevfs=cachevfs, | |
661 | wcachevfs=wcachevfs, |
|
661 | wcachevfs=wcachevfs, | |
662 | features=features, |
|
662 | features=features, | |
663 | intents=intents, |
|
663 | intents=intents, | |
664 | ) |
|
664 | ) | |
665 |
|
665 | |||
666 |
|
666 | |||
667 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
667 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
668 | """Load hgrc files/content into a ui instance. |
|
668 | """Load hgrc files/content into a ui instance. | |
669 |
|
669 | |||
670 | This is called during repository opening to load any additional |
|
670 | This is called during repository opening to load any additional | |
671 | config files or settings relevant to the current repository. |
|
671 | config files or settings relevant to the current repository. | |
672 |
|
672 | |||
673 | Returns a bool indicating whether any additional configs were loaded. |
|
673 | Returns a bool indicating whether any additional configs were loaded. | |
674 |
|
674 | |||
675 | Extensions should monkeypatch this function to modify how per-repo |
|
675 | Extensions should monkeypatch this function to modify how per-repo | |
676 | configs are loaded. For example, an extension may wish to pull in |
|
676 | configs are loaded. For example, an extension may wish to pull in | |
677 | configs from alternate files or sources. |
|
677 | configs from alternate files or sources. | |
678 | """ |
|
678 | """ | |
679 | try: |
|
679 | try: | |
680 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
|
680 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
681 | return True |
|
681 | return True | |
682 | except IOError: |
|
682 | except IOError: | |
683 | return False |
|
683 | return False | |
684 |
|
684 | |||
685 |
|
685 | |||
686 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): |
|
686 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | |
687 | """Perform additional actions after .hg/hgrc is loaded. |
|
687 | """Perform additional actions after .hg/hgrc is loaded. | |
688 |
|
688 | |||
689 | This function is called during repository loading immediately after |
|
689 | This function is called during repository loading immediately after | |
690 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. |
|
690 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. | |
691 |
|
691 | |||
692 | The function can be used to validate configs, automatically add |
|
692 | The function can be used to validate configs, automatically add | |
693 | options (including extensions) based on requirements, etc. |
|
693 | options (including extensions) based on requirements, etc. | |
694 | """ |
|
694 | """ | |
695 |
|
695 | |||
696 | # Map of requirements to list of extensions to load automatically when |
|
696 | # Map of requirements to list of extensions to load automatically when | |
697 | # requirement is present. |
|
697 | # requirement is present. | |
698 | autoextensions = { |
|
698 | autoextensions = { | |
699 | b'largefiles': [b'largefiles'], |
|
699 | b'largefiles': [b'largefiles'], | |
700 | b'lfs': [b'lfs'], |
|
700 | b'lfs': [b'lfs'], | |
701 | } |
|
701 | } | |
702 |
|
702 | |||
703 | for requirement, names in sorted(autoextensions.items()): |
|
703 | for requirement, names in sorted(autoextensions.items()): | |
704 | if requirement not in requirements: |
|
704 | if requirement not in requirements: | |
705 | continue |
|
705 | continue | |
706 |
|
706 | |||
707 | for name in names: |
|
707 | for name in names: | |
708 | if not ui.hasconfig(b'extensions', name): |
|
708 | if not ui.hasconfig(b'extensions', name): | |
709 | ui.setconfig(b'extensions', name, b'', source=b'autoload') |
|
709 | ui.setconfig(b'extensions', name, b'', source=b'autoload') | |
710 |
|
710 | |||
711 |
|
711 | |||
712 | def gathersupportedrequirements(ui): |
|
712 | def gathersupportedrequirements(ui): | |
713 | """Determine the complete set of recognized requirements.""" |
|
713 | """Determine the complete set of recognized requirements.""" | |
714 | # Start with all requirements supported by this file. |
|
714 | # Start with all requirements supported by this file. | |
715 | supported = set(localrepository._basesupported) |
|
715 | supported = set(localrepository._basesupported) | |
716 |
|
716 | |||
717 | # Execute ``featuresetupfuncs`` entries if they belong to an extension |
|
717 | # Execute ``featuresetupfuncs`` entries if they belong to an extension | |
718 | # relevant to this ui instance. |
|
718 | # relevant to this ui instance. | |
719 | modules = {m.__name__ for n, m in extensions.extensions(ui)} |
|
719 | modules = {m.__name__ for n, m in extensions.extensions(ui)} | |
720 |
|
720 | |||
721 | for fn in featuresetupfuncs: |
|
721 | for fn in featuresetupfuncs: | |
722 | if fn.__module__ in modules: |
|
722 | if fn.__module__ in modules: | |
723 | fn(ui, supported) |
|
723 | fn(ui, supported) | |
724 |
|
724 | |||
725 | # Add derived requirements from registered compression engines. |
|
725 | # Add derived requirements from registered compression engines. | |
726 | for name in util.compengines: |
|
726 | for name in util.compengines: | |
727 | engine = util.compengines[name] |
|
727 | engine = util.compengines[name] | |
728 | if engine.available() and engine.revlogheader(): |
|
728 | if engine.available() and engine.revlogheader(): | |
729 | supported.add(b'exp-compression-%s' % name) |
|
729 | supported.add(b'exp-compression-%s' % name) | |
730 | if engine.name() == b'zstd': |
|
730 | if engine.name() == b'zstd': | |
731 | supported.add(b'revlog-compression-zstd') |
|
731 | supported.add(b'revlog-compression-zstd') | |
732 |
|
732 | |||
733 | return supported |
|
733 | return supported | |
734 |
|
734 | |||
735 |
|
735 | |||
736 | def ensurerequirementsrecognized(requirements, supported): |
|
736 | def ensurerequirementsrecognized(requirements, supported): | |
737 | """Validate that a set of local requirements is recognized. |
|
737 | """Validate that a set of local requirements is recognized. | |
738 |
|
738 | |||
739 | Receives a set of requirements. Raises an ``error.RepoError`` if there |
|
739 | Receives a set of requirements. Raises an ``error.RepoError`` if there | |
740 | exists any requirement in that set that currently loaded code doesn't |
|
740 | exists any requirement in that set that currently loaded code doesn't | |
741 | recognize. |
|
741 | recognize. | |
742 |
|
742 | |||
743 | Returns a set of supported requirements. |
|
743 | Returns a set of supported requirements. | |
744 | """ |
|
744 | """ | |
745 | missing = set() |
|
745 | missing = set() | |
746 |
|
746 | |||
747 | for requirement in requirements: |
|
747 | for requirement in requirements: | |
748 | if requirement in supported: |
|
748 | if requirement in supported: | |
749 | continue |
|
749 | continue | |
750 |
|
750 | |||
751 | if not requirement or not requirement[0:1].isalnum(): |
|
751 | if not requirement or not requirement[0:1].isalnum(): | |
752 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) |
|
752 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) | |
753 |
|
753 | |||
754 | missing.add(requirement) |
|
754 | missing.add(requirement) | |
755 |
|
755 | |||
756 | if missing: |
|
756 | if missing: | |
757 | raise error.RequirementError( |
|
757 | raise error.RequirementError( | |
758 | _(b'repository requires features unknown to this Mercurial: %s') |
|
758 | _(b'repository requires features unknown to this Mercurial: %s') | |
759 | % b' '.join(sorted(missing)), |
|
759 | % b' '.join(sorted(missing)), | |
760 | hint=_( |
|
760 | hint=_( | |
761 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' |
|
761 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' | |
762 | b'for more information' |
|
762 | b'for more information' | |
763 | ), |
|
763 | ), | |
764 | ) |
|
764 | ) | |
765 |
|
765 | |||
766 |
|
766 | |||
767 | def ensurerequirementscompatible(ui, requirements): |
|
767 | def ensurerequirementscompatible(ui, requirements): | |
768 | """Validates that a set of recognized requirements is mutually compatible. |
|
768 | """Validates that a set of recognized requirements is mutually compatible. | |
769 |
|
769 | |||
770 | Some requirements may not be compatible with others or require |
|
770 | Some requirements may not be compatible with others or require | |
771 | config options that aren't enabled. This function is called during |
|
771 | config options that aren't enabled. This function is called during | |
772 | repository opening to ensure that the set of requirements needed |
|
772 | repository opening to ensure that the set of requirements needed | |
773 | to open a repository is sane and compatible with config options. |
|
773 | to open a repository is sane and compatible with config options. | |
774 |
|
774 | |||
775 | Extensions can monkeypatch this function to perform additional |
|
775 | Extensions can monkeypatch this function to perform additional | |
776 | checking. |
|
776 | checking. | |
777 |
|
777 | |||
778 | ``error.RepoError`` should be raised on failure. |
|
778 | ``error.RepoError`` should be raised on failure. | |
779 | """ |
|
779 | """ | |
780 | if b'exp-sparse' in requirements and not sparse.enabled: |
|
780 | if b'exp-sparse' in requirements and not sparse.enabled: | |
781 | raise error.RepoError( |
|
781 | raise error.RepoError( | |
782 | _( |
|
782 | _( | |
783 | b'repository is using sparse feature but ' |
|
783 | b'repository is using sparse feature but ' | |
784 | b'sparse is not enabled; enable the ' |
|
784 | b'sparse is not enabled; enable the ' | |
785 | b'"sparse" extensions to access' |
|
785 | b'"sparse" extensions to access' | |
786 | ) |
|
786 | ) | |
787 | ) |
|
787 | ) | |
788 |
|
788 | |||
789 |
|
789 | |||
790 | def makestore(requirements, path, vfstype): |
|
790 | def makestore(requirements, path, vfstype): | |
791 | """Construct a storage object for a repository.""" |
|
791 | """Construct a storage object for a repository.""" | |
792 | if b'store' in requirements: |
|
792 | if b'store' in requirements: | |
793 | if b'fncache' in requirements: |
|
793 | if b'fncache' in requirements: | |
794 | return storemod.fncachestore( |
|
794 | return storemod.fncachestore( | |
795 | path, vfstype, b'dotencode' in requirements |
|
795 | path, vfstype, b'dotencode' in requirements | |
796 | ) |
|
796 | ) | |
797 |
|
797 | |||
798 | return storemod.encodedstore(path, vfstype) |
|
798 | return storemod.encodedstore(path, vfstype) | |
799 |
|
799 | |||
800 | return storemod.basicstore(path, vfstype) |
|
800 | return storemod.basicstore(path, vfstype) | |
801 |
|
801 | |||
802 |
|
802 | |||
803 | def resolvestorevfsoptions(ui, requirements, features): |
|
803 | def resolvestorevfsoptions(ui, requirements, features): | |
804 | """Resolve the options to pass to the store vfs opener. |
|
804 | """Resolve the options to pass to the store vfs opener. | |
805 |
|
805 | |||
806 | The returned dict is used to influence behavior of the storage layer. |
|
806 | The returned dict is used to influence behavior of the storage layer. | |
807 | """ |
|
807 | """ | |
808 | options = {} |
|
808 | options = {} | |
809 |
|
809 | |||
810 | if b'treemanifest' in requirements: |
|
810 | if b'treemanifest' in requirements: | |
811 | options[b'treemanifest'] = True |
|
811 | options[b'treemanifest'] = True | |
812 |
|
812 | |||
813 | # experimental config: format.manifestcachesize |
|
813 | # experimental config: format.manifestcachesize | |
814 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') |
|
814 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') | |
815 | if manifestcachesize is not None: |
|
815 | if manifestcachesize is not None: | |
816 | options[b'manifestcachesize'] = manifestcachesize |
|
816 | options[b'manifestcachesize'] = manifestcachesize | |
817 |
|
817 | |||
818 | # In the absence of another requirement superseding a revlog-related |
|
818 | # In the absence of another requirement superseding a revlog-related | |
819 | # requirement, we have to assume the repo is using revlog version 0. |
|
819 | # requirement, we have to assume the repo is using revlog version 0. | |
820 | # This revlog format is super old and we don't bother trying to parse |
|
820 | # This revlog format is super old and we don't bother trying to parse | |
821 | # opener options for it because those options wouldn't do anything |
|
821 | # opener options for it because those options wouldn't do anything | |
822 | # meaningful on such old repos. |
|
822 | # meaningful on such old repos. | |
823 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: |
|
823 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: | |
824 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) |
|
824 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) | |
825 | else: # explicitly mark repo as using revlogv0 |
|
825 | else: # explicitly mark repo as using revlogv0 | |
826 | options[b'revlogv0'] = True |
|
826 | options[b'revlogv0'] = True | |
827 |
|
827 | |||
828 | if COPIESSDC_REQUIREMENT in requirements: |
|
828 | if COPIESSDC_REQUIREMENT in requirements: | |
829 | options[b'copies-storage'] = b'changeset-sidedata' |
|
829 | options[b'copies-storage'] = b'changeset-sidedata' | |
830 | else: |
|
830 | else: | |
831 | writecopiesto = ui.config(b'experimental', b'copies.write-to') |
|
831 | writecopiesto = ui.config(b'experimental', b'copies.write-to') | |
832 | copiesextramode = (b'changeset-only', b'compatibility') |
|
832 | copiesextramode = (b'changeset-only', b'compatibility') | |
833 | if writecopiesto in copiesextramode: |
|
833 | if writecopiesto in copiesextramode: | |
834 | options[b'copies-storage'] = b'extra' |
|
834 | options[b'copies-storage'] = b'extra' | |
835 |
|
835 | |||
836 | return options |
|
836 | return options | |
837 |
|
837 | |||
838 |
|
838 | |||
839 | def resolverevlogstorevfsoptions(ui, requirements, features): |
|
839 | def resolverevlogstorevfsoptions(ui, requirements, features): | |
840 | """Resolve opener options specific to revlogs.""" |
|
840 | """Resolve opener options specific to revlogs.""" | |
841 |
|
841 | |||
842 | options = {} |
|
842 | options = {} | |
843 | options[b'flagprocessors'] = {} |
|
843 | options[b'flagprocessors'] = {} | |
844 |
|
844 | |||
845 | if b'revlogv1' in requirements: |
|
845 | if b'revlogv1' in requirements: | |
846 | options[b'revlogv1'] = True |
|
846 | options[b'revlogv1'] = True | |
847 | if REVLOGV2_REQUIREMENT in requirements: |
|
847 | if REVLOGV2_REQUIREMENT in requirements: | |
848 | options[b'revlogv2'] = True |
|
848 | options[b'revlogv2'] = True | |
849 |
|
849 | |||
850 | if b'generaldelta' in requirements: |
|
850 | if b'generaldelta' in requirements: | |
851 | options[b'generaldelta'] = True |
|
851 | options[b'generaldelta'] = True | |
852 |
|
852 | |||
853 | # experimental config: format.chunkcachesize |
|
853 | # experimental config: format.chunkcachesize | |
854 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') |
|
854 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') | |
855 | if chunkcachesize is not None: |
|
855 | if chunkcachesize is not None: | |
856 | options[b'chunkcachesize'] = chunkcachesize |
|
856 | options[b'chunkcachesize'] = chunkcachesize | |
857 |
|
857 | |||
858 | deltabothparents = ui.configbool( |
|
858 | deltabothparents = ui.configbool( | |
859 | b'storage', b'revlog.optimize-delta-parent-choice' |
|
859 | b'storage', b'revlog.optimize-delta-parent-choice' | |
860 | ) |
|
860 | ) | |
861 | options[b'deltabothparents'] = deltabothparents |
|
861 | options[b'deltabothparents'] = deltabothparents | |
862 |
|
862 | |||
863 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') |
|
863 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') | |
864 | lazydeltabase = False |
|
864 | lazydeltabase = False | |
865 | if lazydelta: |
|
865 | if lazydelta: | |
866 | lazydeltabase = ui.configbool( |
|
866 | lazydeltabase = ui.configbool( | |
867 | b'storage', b'revlog.reuse-external-delta-parent' |
|
867 | b'storage', b'revlog.reuse-external-delta-parent' | |
868 | ) |
|
868 | ) | |
869 | if lazydeltabase is None: |
|
869 | if lazydeltabase is None: | |
870 | lazydeltabase = not scmutil.gddeltaconfig(ui) |
|
870 | lazydeltabase = not scmutil.gddeltaconfig(ui) | |
871 | options[b'lazydelta'] = lazydelta |
|
871 | options[b'lazydelta'] = lazydelta | |
872 | options[b'lazydeltabase'] = lazydeltabase |
|
872 | options[b'lazydeltabase'] = lazydeltabase | |
873 |
|
873 | |||
874 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') |
|
874 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') | |
875 | if 0 <= chainspan: |
|
875 | if 0 <= chainspan: | |
876 | options[b'maxdeltachainspan'] = chainspan |
|
876 | options[b'maxdeltachainspan'] = chainspan | |
877 |
|
877 | |||
878 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') |
|
878 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') | |
879 | if mmapindexthreshold is not None: |
|
879 | if mmapindexthreshold is not None: | |
880 | options[b'mmapindexthreshold'] = mmapindexthreshold |
|
880 | options[b'mmapindexthreshold'] = mmapindexthreshold | |
881 |
|
881 | |||
882 | withsparseread = ui.configbool(b'experimental', b'sparse-read') |
|
882 | withsparseread = ui.configbool(b'experimental', b'sparse-read') | |
883 | srdensitythres = float( |
|
883 | srdensitythres = float( | |
884 | ui.config(b'experimental', b'sparse-read.density-threshold') |
|
884 | ui.config(b'experimental', b'sparse-read.density-threshold') | |
885 | ) |
|
885 | ) | |
886 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') |
|
886 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') | |
887 | options[b'with-sparse-read'] = withsparseread |
|
887 | options[b'with-sparse-read'] = withsparseread | |
888 | options[b'sparse-read-density-threshold'] = srdensitythres |
|
888 | options[b'sparse-read-density-threshold'] = srdensitythres | |
889 | options[b'sparse-read-min-gap-size'] = srmingapsize |
|
889 | options[b'sparse-read-min-gap-size'] = srmingapsize | |
890 |
|
890 | |||
891 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements |
|
891 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements | |
892 | options[b'sparse-revlog'] = sparserevlog |
|
892 | options[b'sparse-revlog'] = sparserevlog | |
893 | if sparserevlog: |
|
893 | if sparserevlog: | |
894 | options[b'generaldelta'] = True |
|
894 | options[b'generaldelta'] = True | |
895 |
|
895 | |||
896 | sidedata = SIDEDATA_REQUIREMENT in requirements |
|
896 | sidedata = SIDEDATA_REQUIREMENT in requirements | |
897 | options[b'side-data'] = sidedata |
|
897 | options[b'side-data'] = sidedata | |
898 |
|
898 | |||
899 | maxchainlen = None |
|
899 | maxchainlen = None | |
900 | if sparserevlog: |
|
900 | if sparserevlog: | |
901 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH |
|
901 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH | |
902 | # experimental config: format.maxchainlen |
|
902 | # experimental config: format.maxchainlen | |
903 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) |
|
903 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) | |
904 | if maxchainlen is not None: |
|
904 | if maxchainlen is not None: | |
905 | options[b'maxchainlen'] = maxchainlen |
|
905 | options[b'maxchainlen'] = maxchainlen | |
906 |
|
906 | |||
907 | for r in requirements: |
|
907 | for r in requirements: | |
908 | # we allow multiple compression engine requirement to co-exist because |
|
908 | # we allow multiple compression engine requirement to co-exist because | |
909 | # strickly speaking, revlog seems to support mixed compression style. |
|
909 | # strickly speaking, revlog seems to support mixed compression style. | |
910 | # |
|
910 | # | |
911 | # The compression used for new entries will be "the last one" |
|
911 | # The compression used for new entries will be "the last one" | |
912 | prefix = r.startswith |
|
912 | prefix = r.startswith | |
913 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): |
|
913 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): | |
914 | options[b'compengine'] = r.split(b'-', 2)[2] |
|
914 | options[b'compengine'] = r.split(b'-', 2)[2] | |
915 |
|
915 | |||
916 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') |
|
916 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') | |
917 | if options[b'zlib.level'] is not None: |
|
917 | if options[b'zlib.level'] is not None: | |
918 | if not (0 <= options[b'zlib.level'] <= 9): |
|
918 | if not (0 <= options[b'zlib.level'] <= 9): | |
919 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') |
|
919 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') | |
920 | raise error.Abort(msg % options[b'zlib.level']) |
|
920 | raise error.Abort(msg % options[b'zlib.level']) | |
921 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') |
|
921 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') | |
922 | if options[b'zstd.level'] is not None: |
|
922 | if options[b'zstd.level'] is not None: | |
923 | if not (0 <= options[b'zstd.level'] <= 22): |
|
923 | if not (0 <= options[b'zstd.level'] <= 22): | |
924 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') |
|
924 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') | |
925 | raise error.Abort(msg % options[b'zstd.level']) |
|
925 | raise error.Abort(msg % options[b'zstd.level']) | |
926 |
|
926 | |||
927 | if repository.NARROW_REQUIREMENT in requirements: |
|
927 | if repository.NARROW_REQUIREMENT in requirements: | |
928 | options[b'enableellipsis'] = True |
|
928 | options[b'enableellipsis'] = True | |
929 |
|
929 | |||
930 | if ui.configbool(b'experimental', b'rust.index'): |
|
930 | if ui.configbool(b'experimental', b'rust.index'): | |
931 | options[b'rust.index'] = True |
|
931 | options[b'rust.index'] = True | |
932 |
|
932 | |||
933 | return options |
|
933 | return options | |
934 |
|
934 | |||
935 |
|
935 | |||
936 | def makemain(**kwargs): |
|
936 | def makemain(**kwargs): | |
937 | """Produce a type conforming to ``ilocalrepositorymain``.""" |
|
937 | """Produce a type conforming to ``ilocalrepositorymain``.""" | |
938 | return localrepository |
|
938 | return localrepository | |
939 |
|
939 | |||
940 |
|
940 | |||
941 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
941 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
942 | class revlogfilestorage(object): |
|
942 | class revlogfilestorage(object): | |
943 | """File storage when using revlogs.""" |
|
943 | """File storage when using revlogs.""" | |
944 |
|
944 | |||
945 | def file(self, path): |
|
945 | def file(self, path): | |
946 | if path[0] == b'/': |
|
946 | if path[0] == b'/': | |
947 | path = path[1:] |
|
947 | path = path[1:] | |
948 |
|
948 | |||
949 | return filelog.filelog(self.svfs, path) |
|
949 | return filelog.filelog(self.svfs, path) | |
950 |
|
950 | |||
951 |
|
951 | |||
952 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
952 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
953 | class revlognarrowfilestorage(object): |
|
953 | class revlognarrowfilestorage(object): | |
954 | """File storage when using revlogs and narrow files.""" |
|
954 | """File storage when using revlogs and narrow files.""" | |
955 |
|
955 | |||
956 | def file(self, path): |
|
956 | def file(self, path): | |
957 | if path[0] == b'/': |
|
957 | if path[0] == b'/': | |
958 | path = path[1:] |
|
958 | path = path[1:] | |
959 |
|
959 | |||
960 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) |
|
960 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) | |
961 |
|
961 | |||
962 |
|
962 | |||
963 | def makefilestorage(requirements, features, **kwargs): |
|
963 | def makefilestorage(requirements, features, **kwargs): | |
964 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
|
964 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" | |
965 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) |
|
965 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) | |
966 | features.add(repository.REPO_FEATURE_STREAM_CLONE) |
|
966 | features.add(repository.REPO_FEATURE_STREAM_CLONE) | |
967 |
|
967 | |||
968 | if repository.NARROW_REQUIREMENT in requirements: |
|
968 | if repository.NARROW_REQUIREMENT in requirements: | |
969 | return revlognarrowfilestorage |
|
969 | return revlognarrowfilestorage | |
970 | else: |
|
970 | else: | |
971 | return revlogfilestorage |
|
971 | return revlogfilestorage | |
972 |
|
972 | |||
973 |
|
973 | |||
974 | # List of repository interfaces and factory functions for them. Each |
|
974 | # List of repository interfaces and factory functions for them. Each | |
975 | # will be called in order during ``makelocalrepository()`` to iteratively |
|
975 | # will be called in order during ``makelocalrepository()`` to iteratively | |
976 | # derive the final type for a local repository instance. We capture the |
|
976 | # derive the final type for a local repository instance. We capture the | |
977 | # function as a lambda so we don't hold a reference and the module-level |
|
977 | # function as a lambda so we don't hold a reference and the module-level | |
978 | # functions can be wrapped. |
|
978 | # functions can be wrapped. | |
979 | REPO_INTERFACES = [ |
|
979 | REPO_INTERFACES = [ | |
980 | (repository.ilocalrepositorymain, lambda: makemain), |
|
980 | (repository.ilocalrepositorymain, lambda: makemain), | |
981 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), |
|
981 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), | |
982 | ] |
|
982 | ] | |
983 |
|
983 | |||
984 |
|
984 | |||
985 | @interfaceutil.implementer(repository.ilocalrepositorymain) |
|
985 | @interfaceutil.implementer(repository.ilocalrepositorymain) | |
986 | class localrepository(object): |
|
986 | class localrepository(object): | |
987 | """Main class for representing local repositories. |
|
987 | """Main class for representing local repositories. | |
988 |
|
988 | |||
989 | All local repositories are instances of this class. |
|
989 | All local repositories are instances of this class. | |
990 |
|
990 | |||
991 | Constructed on its own, instances of this class are not usable as |
|
991 | Constructed on its own, instances of this class are not usable as | |
992 | repository objects. To obtain a usable repository object, call |
|
992 | repository objects. To obtain a usable repository object, call | |
993 | ``hg.repository()``, ``localrepo.instance()``, or |
|
993 | ``hg.repository()``, ``localrepo.instance()``, or | |
994 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. |
|
994 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. | |
995 | ``instance()`` adds support for creating new repositories. |
|
995 | ``instance()`` adds support for creating new repositories. | |
996 | ``hg.repository()`` adds more extension integration, including calling |
|
996 | ``hg.repository()`` adds more extension integration, including calling | |
997 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be |
|
997 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be | |
998 | used. |
|
998 | used. | |
999 | """ |
|
999 | """ | |
1000 |
|
1000 | |||
1001 | # obsolete experimental requirements: |
|
1001 | # obsolete experimental requirements: | |
1002 | # - manifestv2: An experimental new manifest format that allowed |
|
1002 | # - manifestv2: An experimental new manifest format that allowed | |
1003 | # for stem compression of long paths. Experiment ended up not |
|
1003 | # for stem compression of long paths. Experiment ended up not | |
1004 | # being successful (repository sizes went up due to worse delta |
|
1004 | # being successful (repository sizes went up due to worse delta | |
1005 | # chains), and the code was deleted in 4.6. |
|
1005 | # chains), and the code was deleted in 4.6. | |
1006 | supportedformats = { |
|
1006 | supportedformats = { | |
1007 | b'revlogv1', |
|
1007 | b'revlogv1', | |
1008 | b'generaldelta', |
|
1008 | b'generaldelta', | |
1009 | b'treemanifest', |
|
1009 | b'treemanifest', | |
1010 | COPIESSDC_REQUIREMENT, |
|
1010 | COPIESSDC_REQUIREMENT, | |
1011 | REVLOGV2_REQUIREMENT, |
|
1011 | REVLOGV2_REQUIREMENT, | |
1012 | SIDEDATA_REQUIREMENT, |
|
1012 | SIDEDATA_REQUIREMENT, | |
1013 | SPARSEREVLOG_REQUIREMENT, |
|
1013 | SPARSEREVLOG_REQUIREMENT, | |
1014 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, |
|
1014 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, | |
1015 | } |
|
1015 | } | |
1016 | _basesupported = supportedformats | { |
|
1016 | _basesupported = supportedformats | { | |
1017 | b'store', |
|
1017 | b'store', | |
1018 | b'fncache', |
|
1018 | b'fncache', | |
1019 | b'shared', |
|
1019 | b'shared', | |
1020 | b'relshared', |
|
1020 | b'relshared', | |
1021 | b'dotencode', |
|
1021 | b'dotencode', | |
1022 | b'exp-sparse', |
|
1022 | b'exp-sparse', | |
1023 | b'internal-phase', |
|
1023 | b'internal-phase', | |
1024 | } |
|
1024 | } | |
1025 |
|
1025 | |||
1026 | # list of prefix for file which can be written without 'wlock' |
|
1026 | # list of prefix for file which can be written without 'wlock' | |
1027 | # Extensions should extend this list when needed |
|
1027 | # Extensions should extend this list when needed | |
1028 | _wlockfreeprefix = { |
|
1028 | _wlockfreeprefix = { | |
1029 | # We migh consider requiring 'wlock' for the next |
|
1029 | # We migh consider requiring 'wlock' for the next | |
1030 | # two, but pretty much all the existing code assume |
|
1030 | # two, but pretty much all the existing code assume | |
1031 | # wlock is not needed so we keep them excluded for |
|
1031 | # wlock is not needed so we keep them excluded for | |
1032 | # now. |
|
1032 | # now. | |
1033 | b'hgrc', |
|
1033 | b'hgrc', | |
1034 | b'requires', |
|
1034 | b'requires', | |
1035 | # XXX cache is a complicatged business someone |
|
1035 | # XXX cache is a complicatged business someone | |
1036 | # should investigate this in depth at some point |
|
1036 | # should investigate this in depth at some point | |
1037 | b'cache/', |
|
1037 | b'cache/', | |
1038 | # XXX shouldn't be dirstate covered by the wlock? |
|
1038 | # XXX shouldn't be dirstate covered by the wlock? | |
1039 | b'dirstate', |
|
1039 | b'dirstate', | |
1040 | # XXX bisect was still a bit too messy at the time |
|
1040 | # XXX bisect was still a bit too messy at the time | |
1041 | # this changeset was introduced. Someone should fix |
|
1041 | # this changeset was introduced. Someone should fix | |
1042 | # the remainig bit and drop this line |
|
1042 | # the remainig bit and drop this line | |
1043 | b'bisect.state', |
|
1043 | b'bisect.state', | |
1044 | } |
|
1044 | } | |
1045 |
|
1045 | |||
1046 | def __init__( |
|
1046 | def __init__( | |
1047 | self, |
|
1047 | self, | |
1048 | baseui, |
|
1048 | baseui, | |
1049 | ui, |
|
1049 | ui, | |
1050 | origroot, |
|
1050 | origroot, | |
1051 | wdirvfs, |
|
1051 | wdirvfs, | |
1052 | hgvfs, |
|
1052 | hgvfs, | |
1053 | requirements, |
|
1053 | requirements, | |
1054 | supportedrequirements, |
|
1054 | supportedrequirements, | |
1055 | sharedpath, |
|
1055 | sharedpath, | |
1056 | store, |
|
1056 | store, | |
1057 | cachevfs, |
|
1057 | cachevfs, | |
1058 | wcachevfs, |
|
1058 | wcachevfs, | |
1059 | features, |
|
1059 | features, | |
1060 | intents=None, |
|
1060 | intents=None, | |
1061 | ): |
|
1061 | ): | |
1062 | """Create a new local repository instance. |
|
1062 | """Create a new local repository instance. | |
1063 |
|
1063 | |||
1064 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, |
|
1064 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, | |
1065 | or ``localrepo.makelocalrepository()`` for obtaining a new repository |
|
1065 | or ``localrepo.makelocalrepository()`` for obtaining a new repository | |
1066 | object. |
|
1066 | object. | |
1067 |
|
1067 | |||
1068 | Arguments: |
|
1068 | Arguments: | |
1069 |
|
1069 | |||
1070 | baseui |
|
1070 | baseui | |
1071 | ``ui.ui`` instance that ``ui`` argument was based off of. |
|
1071 | ``ui.ui`` instance that ``ui`` argument was based off of. | |
1072 |
|
1072 | |||
1073 | ui |
|
1073 | ui | |
1074 | ``ui.ui`` instance for use by the repository. |
|
1074 | ``ui.ui`` instance for use by the repository. | |
1075 |
|
1075 | |||
1076 | origroot |
|
1076 | origroot | |
1077 | ``bytes`` path to working directory root of this repository. |
|
1077 | ``bytes`` path to working directory root of this repository. | |
1078 |
|
1078 | |||
1079 | wdirvfs |
|
1079 | wdirvfs | |
1080 | ``vfs.vfs`` rooted at the working directory. |
|
1080 | ``vfs.vfs`` rooted at the working directory. | |
1081 |
|
1081 | |||
1082 | hgvfs |
|
1082 | hgvfs | |
1083 | ``vfs.vfs`` rooted at .hg/ |
|
1083 | ``vfs.vfs`` rooted at .hg/ | |
1084 |
|
1084 | |||
1085 | requirements |
|
1085 | requirements | |
1086 | ``set`` of bytestrings representing repository opening requirements. |
|
1086 | ``set`` of bytestrings representing repository opening requirements. | |
1087 |
|
1087 | |||
1088 | supportedrequirements |
|
1088 | supportedrequirements | |
1089 | ``set`` of bytestrings representing repository requirements that we |
|
1089 | ``set`` of bytestrings representing repository requirements that we | |
1090 | know how to open. May be a supetset of ``requirements``. |
|
1090 | know how to open. May be a supetset of ``requirements``. | |
1091 |
|
1091 | |||
1092 | sharedpath |
|
1092 | sharedpath | |
1093 | ``bytes`` Defining path to storage base directory. Points to a |
|
1093 | ``bytes`` Defining path to storage base directory. Points to a | |
1094 | ``.hg/`` directory somewhere. |
|
1094 | ``.hg/`` directory somewhere. | |
1095 |
|
1095 | |||
1096 | store |
|
1096 | store | |
1097 | ``store.basicstore`` (or derived) instance providing access to |
|
1097 | ``store.basicstore`` (or derived) instance providing access to | |
1098 | versioned storage. |
|
1098 | versioned storage. | |
1099 |
|
1099 | |||
1100 | cachevfs |
|
1100 | cachevfs | |
1101 | ``vfs.vfs`` used for cache files. |
|
1101 | ``vfs.vfs`` used for cache files. | |
1102 |
|
1102 | |||
1103 | wcachevfs |
|
1103 | wcachevfs | |
1104 | ``vfs.vfs`` used for cache files related to the working copy. |
|
1104 | ``vfs.vfs`` used for cache files related to the working copy. | |
1105 |
|
1105 | |||
1106 | features |
|
1106 | features | |
1107 | ``set`` of bytestrings defining features/capabilities of this |
|
1107 | ``set`` of bytestrings defining features/capabilities of this | |
1108 | instance. |
|
1108 | instance. | |
1109 |
|
1109 | |||
1110 | intents |
|
1110 | intents | |
1111 | ``set`` of system strings indicating what this repo will be used |
|
1111 | ``set`` of system strings indicating what this repo will be used | |
1112 | for. |
|
1112 | for. | |
1113 | """ |
|
1113 | """ | |
1114 | self.baseui = baseui |
|
1114 | self.baseui = baseui | |
1115 | self.ui = ui |
|
1115 | self.ui = ui | |
1116 | self.origroot = origroot |
|
1116 | self.origroot = origroot | |
1117 | # vfs rooted at working directory. |
|
1117 | # vfs rooted at working directory. | |
1118 | self.wvfs = wdirvfs |
|
1118 | self.wvfs = wdirvfs | |
1119 | self.root = wdirvfs.base |
|
1119 | self.root = wdirvfs.base | |
1120 | # vfs rooted at .hg/. Used to access most non-store paths. |
|
1120 | # vfs rooted at .hg/. Used to access most non-store paths. | |
1121 | self.vfs = hgvfs |
|
1121 | self.vfs = hgvfs | |
1122 | self.path = hgvfs.base |
|
1122 | self.path = hgvfs.base | |
1123 | self.requirements = requirements |
|
1123 | self.requirements = requirements | |
1124 | self.supported = supportedrequirements |
|
1124 | self.supported = supportedrequirements | |
1125 | self.sharedpath = sharedpath |
|
1125 | self.sharedpath = sharedpath | |
1126 | self.store = store |
|
1126 | self.store = store | |
1127 | self.cachevfs = cachevfs |
|
1127 | self.cachevfs = cachevfs | |
1128 | self.wcachevfs = wcachevfs |
|
1128 | self.wcachevfs = wcachevfs | |
1129 | self.features = features |
|
1129 | self.features = features | |
1130 |
|
1130 | |||
1131 | self.filtername = None |
|
1131 | self.filtername = None | |
1132 |
|
1132 | |||
1133 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1133 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1134 | b'devel', b'check-locks' |
|
1134 | b'devel', b'check-locks' | |
1135 | ): |
|
1135 | ): | |
1136 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
1136 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
1137 | # A list of callback to shape the phase if no data were found. |
|
1137 | # A list of callback to shape the phase if no data were found. | |
1138 | # Callback are in the form: func(repo, roots) --> processed root. |
|
1138 | # Callback are in the form: func(repo, roots) --> processed root. | |
1139 | # This list it to be filled by extension during repo setup |
|
1139 | # This list it to be filled by extension during repo setup | |
1140 | self._phasedefaults = [] |
|
1140 | self._phasedefaults = [] | |
1141 |
|
1141 | |||
1142 | color.setup(self.ui) |
|
1142 | color.setup(self.ui) | |
1143 |
|
1143 | |||
1144 | self.spath = self.store.path |
|
1144 | self.spath = self.store.path | |
1145 | self.svfs = self.store.vfs |
|
1145 | self.svfs = self.store.vfs | |
1146 | self.sjoin = self.store.join |
|
1146 | self.sjoin = self.store.join | |
1147 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1147 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1148 | b'devel', b'check-locks' |
|
1148 | b'devel', b'check-locks' | |
1149 | ): |
|
1149 | ): | |
1150 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs |
|
1150 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs | |
1151 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
1151 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
1152 | else: # standard vfs |
|
1152 | else: # standard vfs | |
1153 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
1153 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
1154 |
|
1154 | |||
1155 | self._dirstatevalidatewarned = False |
|
1155 | self._dirstatevalidatewarned = False | |
1156 |
|
1156 | |||
1157 | self._branchcaches = branchmap.BranchMapCache() |
|
1157 | self._branchcaches = branchmap.BranchMapCache() | |
1158 | self._revbranchcache = None |
|
1158 | self._revbranchcache = None | |
1159 | self._filterpats = {} |
|
1159 | self._filterpats = {} | |
1160 | self._datafilters = {} |
|
1160 | self._datafilters = {} | |
1161 | self._transref = self._lockref = self._wlockref = None |
|
1161 | self._transref = self._lockref = self._wlockref = None | |
1162 |
|
1162 | |||
1163 | # A cache for various files under .hg/ that tracks file changes, |
|
1163 | # A cache for various files under .hg/ that tracks file changes, | |
1164 | # (used by the filecache decorator) |
|
1164 | # (used by the filecache decorator) | |
1165 | # |
|
1165 | # | |
1166 | # Maps a property name to its util.filecacheentry |
|
1166 | # Maps a property name to its util.filecacheentry | |
1167 | self._filecache = {} |
|
1167 | self._filecache = {} | |
1168 |
|
1168 | |||
1169 | # hold sets of revision to be filtered |
|
1169 | # hold sets of revision to be filtered | |
1170 | # should be cleared when something might have changed the filter value: |
|
1170 | # should be cleared when something might have changed the filter value: | |
1171 | # - new changesets, |
|
1171 | # - new changesets, | |
1172 | # - phase change, |
|
1172 | # - phase change, | |
1173 | # - new obsolescence marker, |
|
1173 | # - new obsolescence marker, | |
1174 | # - working directory parent change, |
|
1174 | # - working directory parent change, | |
1175 | # - bookmark changes |
|
1175 | # - bookmark changes | |
1176 | self.filteredrevcache = {} |
|
1176 | self.filteredrevcache = {} | |
1177 |
|
1177 | |||
1178 | # post-dirstate-status hooks |
|
1178 | # post-dirstate-status hooks | |
1179 | self._postdsstatus = [] |
|
1179 | self._postdsstatus = [] | |
1180 |
|
1180 | |||
1181 | # generic mapping between names and nodes |
|
1181 | # generic mapping between names and nodes | |
1182 | self.names = namespaces.namespaces() |
|
1182 | self.names = namespaces.namespaces() | |
1183 |
|
1183 | |||
1184 | # Key to signature value. |
|
1184 | # Key to signature value. | |
1185 | self._sparsesignaturecache = {} |
|
1185 | self._sparsesignaturecache = {} | |
1186 | # Signature to cached matcher instance. |
|
1186 | # Signature to cached matcher instance. | |
1187 | self._sparsematchercache = {} |
|
1187 | self._sparsematchercache = {} | |
1188 |
|
1188 | |||
1189 | self._extrafilterid = repoview.extrafilter(ui) |
|
1189 | self._extrafilterid = repoview.extrafilter(ui) | |
1190 |
|
1190 | |||
1191 | self.filecopiesmode = None |
|
1191 | self.filecopiesmode = None | |
1192 | if COPIESSDC_REQUIREMENT in self.requirements: |
|
1192 | if COPIESSDC_REQUIREMENT in self.requirements: | |
1193 | self.filecopiesmode = b'changeset-sidedata' |
|
1193 | self.filecopiesmode = b'changeset-sidedata' | |
1194 |
|
1194 | |||
1195 | def _getvfsward(self, origfunc): |
|
1195 | def _getvfsward(self, origfunc): | |
1196 | """build a ward for self.vfs""" |
|
1196 | """build a ward for self.vfs""" | |
1197 | rref = weakref.ref(self) |
|
1197 | rref = weakref.ref(self) | |
1198 |
|
1198 | |||
1199 | def checkvfs(path, mode=None): |
|
1199 | def checkvfs(path, mode=None): | |
1200 | ret = origfunc(path, mode=mode) |
|
1200 | ret = origfunc(path, mode=mode) | |
1201 | repo = rref() |
|
1201 | repo = rref() | |
1202 | if ( |
|
1202 | if ( | |
1203 | repo is None |
|
1203 | repo is None | |
1204 | or not util.safehasattr(repo, b'_wlockref') |
|
1204 | or not util.safehasattr(repo, b'_wlockref') | |
1205 | or not util.safehasattr(repo, b'_lockref') |
|
1205 | or not util.safehasattr(repo, b'_lockref') | |
1206 | ): |
|
1206 | ): | |
1207 | return |
|
1207 | return | |
1208 | if mode in (None, b'r', b'rb'): |
|
1208 | if mode in (None, b'r', b'rb'): | |
1209 | return |
|
1209 | return | |
1210 | if path.startswith(repo.path): |
|
1210 | if path.startswith(repo.path): | |
1211 | # truncate name relative to the repository (.hg) |
|
1211 | # truncate name relative to the repository (.hg) | |
1212 | path = path[len(repo.path) + 1 :] |
|
1212 | path = path[len(repo.path) + 1 :] | |
1213 | if path.startswith(b'cache/'): |
|
1213 | if path.startswith(b'cache/'): | |
1214 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' |
|
1214 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' | |
1215 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") |
|
1215 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") | |
1216 | if path.startswith(b'journal.') or path.startswith(b'undo.'): |
|
1216 | if path.startswith(b'journal.') or path.startswith(b'undo.'): | |
1217 | # journal is covered by 'lock' |
|
1217 | # journal is covered by 'lock' | |
1218 | if repo._currentlock(repo._lockref) is None: |
|
1218 | if repo._currentlock(repo._lockref) is None: | |
1219 | repo.ui.develwarn( |
|
1219 | repo.ui.develwarn( | |
1220 | b'write with no lock: "%s"' % path, |
|
1220 | b'write with no lock: "%s"' % path, | |
1221 | stacklevel=3, |
|
1221 | stacklevel=3, | |
1222 | config=b'check-locks', |
|
1222 | config=b'check-locks', | |
1223 | ) |
|
1223 | ) | |
1224 | elif repo._currentlock(repo._wlockref) is None: |
|
1224 | elif repo._currentlock(repo._wlockref) is None: | |
1225 | # rest of vfs files are covered by 'wlock' |
|
1225 | # rest of vfs files are covered by 'wlock' | |
1226 | # |
|
1226 | # | |
1227 | # exclude special files |
|
1227 | # exclude special files | |
1228 | for prefix in self._wlockfreeprefix: |
|
1228 | for prefix in self._wlockfreeprefix: | |
1229 | if path.startswith(prefix): |
|
1229 | if path.startswith(prefix): | |
1230 | return |
|
1230 | return | |
1231 | repo.ui.develwarn( |
|
1231 | repo.ui.develwarn( | |
1232 | b'write with no wlock: "%s"' % path, |
|
1232 | b'write with no wlock: "%s"' % path, | |
1233 | stacklevel=3, |
|
1233 | stacklevel=3, | |
1234 | config=b'check-locks', |
|
1234 | config=b'check-locks', | |
1235 | ) |
|
1235 | ) | |
1236 | return ret |
|
1236 | return ret | |
1237 |
|
1237 | |||
1238 | return checkvfs |
|
1238 | return checkvfs | |
1239 |
|
1239 | |||
1240 | def _getsvfsward(self, origfunc): |
|
1240 | def _getsvfsward(self, origfunc): | |
1241 | """build a ward for self.svfs""" |
|
1241 | """build a ward for self.svfs""" | |
1242 | rref = weakref.ref(self) |
|
1242 | rref = weakref.ref(self) | |
1243 |
|
1243 | |||
1244 | def checksvfs(path, mode=None): |
|
1244 | def checksvfs(path, mode=None): | |
1245 | ret = origfunc(path, mode=mode) |
|
1245 | ret = origfunc(path, mode=mode) | |
1246 | repo = rref() |
|
1246 | repo = rref() | |
1247 | if repo is None or not util.safehasattr(repo, b'_lockref'): |
|
1247 | if repo is None or not util.safehasattr(repo, b'_lockref'): | |
1248 | return |
|
1248 | return | |
1249 | if mode in (None, b'r', b'rb'): |
|
1249 | if mode in (None, b'r', b'rb'): | |
1250 | return |
|
1250 | return | |
1251 | if path.startswith(repo.sharedpath): |
|
1251 | if path.startswith(repo.sharedpath): | |
1252 | # truncate name relative to the repository (.hg) |
|
1252 | # truncate name relative to the repository (.hg) | |
1253 | path = path[len(repo.sharedpath) + 1 :] |
|
1253 | path = path[len(repo.sharedpath) + 1 :] | |
1254 | if repo._currentlock(repo._lockref) is None: |
|
1254 | if repo._currentlock(repo._lockref) is None: | |
1255 | repo.ui.develwarn( |
|
1255 | repo.ui.develwarn( | |
1256 | b'write with no lock: "%s"' % path, stacklevel=4 |
|
1256 | b'write with no lock: "%s"' % path, stacklevel=4 | |
1257 | ) |
|
1257 | ) | |
1258 | return ret |
|
1258 | return ret | |
1259 |
|
1259 | |||
1260 | return checksvfs |
|
1260 | return checksvfs | |
1261 |
|
1261 | |||
1262 | def close(self): |
|
1262 | def close(self): | |
1263 | self._writecaches() |
|
1263 | self._writecaches() | |
1264 |
|
1264 | |||
1265 | def _writecaches(self): |
|
1265 | def _writecaches(self): | |
1266 | if self._revbranchcache: |
|
1266 | if self._revbranchcache: | |
1267 | self._revbranchcache.write() |
|
1267 | self._revbranchcache.write() | |
1268 |
|
1268 | |||
1269 | def _restrictcapabilities(self, caps): |
|
1269 | def _restrictcapabilities(self, caps): | |
1270 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): |
|
1270 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): | |
1271 | caps = set(caps) |
|
1271 | caps = set(caps) | |
1272 | capsblob = bundle2.encodecaps( |
|
1272 | capsblob = bundle2.encodecaps( | |
1273 | bundle2.getrepocaps(self, role=b'client') |
|
1273 | bundle2.getrepocaps(self, role=b'client') | |
1274 | ) |
|
1274 | ) | |
1275 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) |
|
1275 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) | |
1276 | return caps |
|
1276 | return caps | |
1277 |
|
1277 | |||
1278 | def _writerequirements(self): |
|
1278 | def _writerequirements(self): | |
1279 | scmutil.writerequires(self.vfs, self.requirements) |
|
1279 | scmutil.writerequires(self.vfs, self.requirements) | |
1280 |
|
1280 | |||
1281 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: |
|
1281 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: | |
1282 | # self -> auditor -> self._checknested -> self |
|
1282 | # self -> auditor -> self._checknested -> self | |
1283 |
|
1283 | |||
1284 | @property |
|
1284 | @property | |
1285 | def auditor(self): |
|
1285 | def auditor(self): | |
1286 | # This is only used by context.workingctx.match in order to |
|
1286 | # This is only used by context.workingctx.match in order to | |
1287 | # detect files in subrepos. |
|
1287 | # detect files in subrepos. | |
1288 | return pathutil.pathauditor(self.root, callback=self._checknested) |
|
1288 | return pathutil.pathauditor(self.root, callback=self._checknested) | |
1289 |
|
1289 | |||
1290 | @property |
|
1290 | @property | |
1291 | def nofsauditor(self): |
|
1291 | def nofsauditor(self): | |
1292 | # This is only used by context.basectx.match in order to detect |
|
1292 | # This is only used by context.basectx.match in order to detect | |
1293 | # files in subrepos. |
|
1293 | # files in subrepos. | |
1294 | return pathutil.pathauditor( |
|
1294 | return pathutil.pathauditor( | |
1295 | self.root, callback=self._checknested, realfs=False, cached=True |
|
1295 | self.root, callback=self._checknested, realfs=False, cached=True | |
1296 | ) |
|
1296 | ) | |
1297 |
|
1297 | |||
1298 | def _checknested(self, path): |
|
1298 | def _checknested(self, path): | |
1299 | """Determine if path is a legal nested repository.""" |
|
1299 | """Determine if path is a legal nested repository.""" | |
1300 | if not path.startswith(self.root): |
|
1300 | if not path.startswith(self.root): | |
1301 | return False |
|
1301 | return False | |
1302 | subpath = path[len(self.root) + 1 :] |
|
1302 | subpath = path[len(self.root) + 1 :] | |
1303 | normsubpath = util.pconvert(subpath) |
|
1303 | normsubpath = util.pconvert(subpath) | |
1304 |
|
1304 | |||
1305 | # XXX: Checking against the current working copy is wrong in |
|
1305 | # XXX: Checking against the current working copy is wrong in | |
1306 | # the sense that it can reject things like |
|
1306 | # the sense that it can reject things like | |
1307 | # |
|
1307 | # | |
1308 | # $ hg cat -r 10 sub/x.txt |
|
1308 | # $ hg cat -r 10 sub/x.txt | |
1309 | # |
|
1309 | # | |
1310 | # if sub/ is no longer a subrepository in the working copy |
|
1310 | # if sub/ is no longer a subrepository in the working copy | |
1311 | # parent revision. |
|
1311 | # parent revision. | |
1312 | # |
|
1312 | # | |
1313 | # However, it can of course also allow things that would have |
|
1313 | # However, it can of course also allow things that would have | |
1314 | # been rejected before, such as the above cat command if sub/ |
|
1314 | # been rejected before, such as the above cat command if sub/ | |
1315 | # is a subrepository now, but was a normal directory before. |
|
1315 | # is a subrepository now, but was a normal directory before. | |
1316 | # The old path auditor would have rejected by mistake since it |
|
1316 | # The old path auditor would have rejected by mistake since it | |
1317 | # panics when it sees sub/.hg/. |
|
1317 | # panics when it sees sub/.hg/. | |
1318 | # |
|
1318 | # | |
1319 | # All in all, checking against the working copy seems sensible |
|
1319 | # All in all, checking against the working copy seems sensible | |
1320 | # since we want to prevent access to nested repositories on |
|
1320 | # since we want to prevent access to nested repositories on | |
1321 | # the filesystem *now*. |
|
1321 | # the filesystem *now*. | |
1322 | ctx = self[None] |
|
1322 | ctx = self[None] | |
1323 | parts = util.splitpath(subpath) |
|
1323 | parts = util.splitpath(subpath) | |
1324 | while parts: |
|
1324 | while parts: | |
1325 | prefix = b'/'.join(parts) |
|
1325 | prefix = b'/'.join(parts) | |
1326 | if prefix in ctx.substate: |
|
1326 | if prefix in ctx.substate: | |
1327 | if prefix == normsubpath: |
|
1327 | if prefix == normsubpath: | |
1328 | return True |
|
1328 | return True | |
1329 | else: |
|
1329 | else: | |
1330 | sub = ctx.sub(prefix) |
|
1330 | sub = ctx.sub(prefix) | |
1331 | return sub.checknested(subpath[len(prefix) + 1 :]) |
|
1331 | return sub.checknested(subpath[len(prefix) + 1 :]) | |
1332 | else: |
|
1332 | else: | |
1333 | parts.pop() |
|
1333 | parts.pop() | |
1334 | return False |
|
1334 | return False | |
1335 |
|
1335 | |||
1336 | def peer(self): |
|
1336 | def peer(self): | |
1337 | return localpeer(self) # not cached to avoid reference cycle |
|
1337 | return localpeer(self) # not cached to avoid reference cycle | |
1338 |
|
1338 | |||
1339 | def unfiltered(self): |
|
1339 | def unfiltered(self): | |
1340 | """Return unfiltered version of the repository |
|
1340 | """Return unfiltered version of the repository | |
1341 |
|
1341 | |||
1342 | Intended to be overwritten by filtered repo.""" |
|
1342 | Intended to be overwritten by filtered repo.""" | |
1343 | return self |
|
1343 | return self | |
1344 |
|
1344 | |||
1345 | def filtered(self, name, visibilityexceptions=None): |
|
1345 | def filtered(self, name, visibilityexceptions=None): | |
1346 | """Return a filtered version of a repository |
|
1346 | """Return a filtered version of a repository | |
1347 |
|
1347 | |||
1348 | The `name` parameter is the identifier of the requested view. This |
|
1348 | The `name` parameter is the identifier of the requested view. This | |
1349 | will return a repoview object set "exactly" to the specified view. |
|
1349 | will return a repoview object set "exactly" to the specified view. | |
1350 |
|
1350 | |||
1351 | This function does not apply recursive filtering to a repository. For |
|
1351 | This function does not apply recursive filtering to a repository. For | |
1352 | example calling `repo.filtered("served")` will return a repoview using |
|
1352 | example calling `repo.filtered("served")` will return a repoview using | |
1353 | the "served" view, regardless of the initial view used by `repo`. |
|
1353 | the "served" view, regardless of the initial view used by `repo`. | |
1354 |
|
1354 | |||
1355 | In other word, there is always only one level of `repoview` "filtering". |
|
1355 | In other word, there is always only one level of `repoview` "filtering". | |
1356 | """ |
|
1356 | """ | |
1357 | if self._extrafilterid is not None and b'%' not in name: |
|
1357 | if self._extrafilterid is not None and b'%' not in name: | |
1358 | name = name + b'%' + self._extrafilterid |
|
1358 | name = name + b'%' + self._extrafilterid | |
1359 |
|
1359 | |||
1360 | cls = repoview.newtype(self.unfiltered().__class__) |
|
1360 | cls = repoview.newtype(self.unfiltered().__class__) | |
1361 | return cls(self, name, visibilityexceptions) |
|
1361 | return cls(self, name, visibilityexceptions) | |
1362 |
|
1362 | |||
1363 | @mixedrepostorecache( |
|
1363 | @mixedrepostorecache( | |
1364 | (b'bookmarks', b'plain'), |
|
1364 | (b'bookmarks', b'plain'), | |
1365 | (b'bookmarks.current', b'plain'), |
|
1365 | (b'bookmarks.current', b'plain'), | |
1366 | (b'bookmarks', b''), |
|
1366 | (b'bookmarks', b''), | |
1367 | (b'00changelog.i', b''), |
|
1367 | (b'00changelog.i', b''), | |
1368 | ) |
|
1368 | ) | |
1369 | def _bookmarks(self): |
|
1369 | def _bookmarks(self): | |
1370 | # Since the multiple files involved in the transaction cannot be |
|
1370 | # Since the multiple files involved in the transaction cannot be | |
1371 | # written atomically (with current repository format), there is a race |
|
1371 | # written atomically (with current repository format), there is a race | |
1372 | # condition here. |
|
1372 | # condition here. | |
1373 | # |
|
1373 | # | |
1374 | # 1) changelog content A is read |
|
1374 | # 1) changelog content A is read | |
1375 | # 2) outside transaction update changelog to content B |
|
1375 | # 2) outside transaction update changelog to content B | |
1376 | # 3) outside transaction update bookmark file referring to content B |
|
1376 | # 3) outside transaction update bookmark file referring to content B | |
1377 | # 4) bookmarks file content is read and filtered against changelog-A |
|
1377 | # 4) bookmarks file content is read and filtered against changelog-A | |
1378 | # |
|
1378 | # | |
1379 | # When this happens, bookmarks against nodes missing from A are dropped. |
|
1379 | # When this happens, bookmarks against nodes missing from A are dropped. | |
1380 | # |
|
1380 | # | |
1381 | # Having this happening during read is not great, but it become worse |
|
1381 | # Having this happening during read is not great, but it become worse | |
1382 | # when this happen during write because the bookmarks to the "unknown" |
|
1382 | # when this happen during write because the bookmarks to the "unknown" | |
1383 | # nodes will be dropped for good. However, writes happen within locks. |
|
1383 | # nodes will be dropped for good. However, writes happen within locks. | |
1384 | # This locking makes it possible to have a race free consistent read. |
|
1384 | # This locking makes it possible to have a race free consistent read. | |
1385 | # For this purpose data read from disc before locking are |
|
1385 | # For this purpose data read from disc before locking are | |
1386 | # "invalidated" right after the locks are taken. This invalidations are |
|
1386 | # "invalidated" right after the locks are taken. This invalidations are | |
1387 | # "light", the `filecache` mechanism keep the data in memory and will |
|
1387 | # "light", the `filecache` mechanism keep the data in memory and will | |
1388 | # reuse them if the underlying files did not changed. Not parsing the |
|
1388 | # reuse them if the underlying files did not changed. Not parsing the | |
1389 | # same data multiple times helps performances. |
|
1389 | # same data multiple times helps performances. | |
1390 | # |
|
1390 | # | |
1391 | # Unfortunately in the case describe above, the files tracked by the |
|
1391 | # Unfortunately in the case describe above, the files tracked by the | |
1392 | # bookmarks file cache might not have changed, but the in-memory |
|
1392 | # bookmarks file cache might not have changed, but the in-memory | |
1393 | # content is still "wrong" because we used an older changelog content |
|
1393 | # content is still "wrong" because we used an older changelog content | |
1394 | # to process the on-disk data. So after locking, the changelog would be |
|
1394 | # to process the on-disk data. So after locking, the changelog would be | |
1395 | # refreshed but `_bookmarks` would be preserved. |
|
1395 | # refreshed but `_bookmarks` would be preserved. | |
1396 | # Adding `00changelog.i` to the list of tracked file is not |
|
1396 | # Adding `00changelog.i` to the list of tracked file is not | |
1397 | # enough, because at the time we build the content for `_bookmarks` in |
|
1397 | # enough, because at the time we build the content for `_bookmarks` in | |
1398 | # (4), the changelog file has already diverged from the content used |
|
1398 | # (4), the changelog file has already diverged from the content used | |
1399 | # for loading `changelog` in (1) |
|
1399 | # for loading `changelog` in (1) | |
1400 | # |
|
1400 | # | |
1401 | # To prevent the issue, we force the changelog to be explicitly |
|
1401 | # To prevent the issue, we force the changelog to be explicitly | |
1402 | # reloaded while computing `_bookmarks`. The data race can still happen |
|
1402 | # reloaded while computing `_bookmarks`. The data race can still happen | |
1403 | # without the lock (with a narrower window), but it would no longer go |
|
1403 | # without the lock (with a narrower window), but it would no longer go | |
1404 | # undetected during the lock time refresh. |
|
1404 | # undetected during the lock time refresh. | |
1405 | # |
|
1405 | # | |
1406 | # The new schedule is as follow |
|
1406 | # The new schedule is as follow | |
1407 | # |
|
1407 | # | |
1408 | # 1) filecache logic detect that `_bookmarks` needs to be computed |
|
1408 | # 1) filecache logic detect that `_bookmarks` needs to be computed | |
1409 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) |
|
1409 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) | |
1410 | # 3) We force `changelog` filecache to be tested |
|
1410 | # 3) We force `changelog` filecache to be tested | |
1411 | # 4) cachestat for `changelog` are captured (for changelog) |
|
1411 | # 4) cachestat for `changelog` are captured (for changelog) | |
1412 | # 5) `_bookmarks` is computed and cached |
|
1412 | # 5) `_bookmarks` is computed and cached | |
1413 | # |
|
1413 | # | |
1414 | # The step in (3) ensure we have a changelog at least as recent as the |
|
1414 | # The step in (3) ensure we have a changelog at least as recent as the | |
1415 | # cache stat computed in (1). As a result at locking time: |
|
1415 | # cache stat computed in (1). As a result at locking time: | |
1416 | # * if the changelog did not changed since (1) -> we can reuse the data |
|
1416 | # * if the changelog did not changed since (1) -> we can reuse the data | |
1417 | # * otherwise -> the bookmarks get refreshed. |
|
1417 | # * otherwise -> the bookmarks get refreshed. | |
1418 | self._refreshchangelog() |
|
1418 | self._refreshchangelog() | |
1419 | return bookmarks.bmstore(self) |
|
1419 | return bookmarks.bmstore(self) | |
1420 |
|
1420 | |||
1421 | def _refreshchangelog(self): |
|
1421 | def _refreshchangelog(self): | |
1422 | """make sure the in memory changelog match the on-disk one""" |
|
1422 | """make sure the in memory changelog match the on-disk one""" | |
1423 | if 'changelog' in vars(self) and self.currenttransaction() is None: |
|
1423 | if 'changelog' in vars(self) and self.currenttransaction() is None: | |
1424 | del self.changelog |
|
1424 | del self.changelog | |
1425 |
|
1425 | |||
1426 | @property |
|
1426 | @property | |
1427 | def _activebookmark(self): |
|
1427 | def _activebookmark(self): | |
1428 | return self._bookmarks.active |
|
1428 | return self._bookmarks.active | |
1429 |
|
1429 | |||
1430 | # _phasesets depend on changelog. what we need is to call |
|
1430 | # _phasesets depend on changelog. what we need is to call | |
1431 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
1431 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
1432 | # can't be easily expressed in filecache mechanism. |
|
1432 | # can't be easily expressed in filecache mechanism. | |
1433 | @storecache(b'phaseroots', b'00changelog.i') |
|
1433 | @storecache(b'phaseroots', b'00changelog.i') | |
1434 | def _phasecache(self): |
|
1434 | def _phasecache(self): | |
1435 | return phases.phasecache(self, self._phasedefaults) |
|
1435 | return phases.phasecache(self, self._phasedefaults) | |
1436 |
|
1436 | |||
1437 | @storecache(b'obsstore') |
|
1437 | @storecache(b'obsstore') | |
1438 | def obsstore(self): |
|
1438 | def obsstore(self): | |
1439 | return obsolete.makestore(self.ui, self) |
|
1439 | return obsolete.makestore(self.ui, self) | |
1440 |
|
1440 | |||
1441 | @storecache(b'00changelog.i') |
|
1441 | @storecache(b'00changelog.i') | |
1442 | def changelog(self): |
|
1442 | def changelog(self): | |
1443 | return self.store.changelog(txnutil.mayhavepending(self.root)) |
|
1443 | return self.store.changelog(txnutil.mayhavepending(self.root)) | |
1444 |
|
1444 | |||
1445 | @storecache(b'00manifest.i') |
|
1445 | @storecache(b'00manifest.i') | |
1446 | def manifestlog(self): |
|
1446 | def manifestlog(self): | |
1447 | return self.store.manifestlog(self, self._storenarrowmatch) |
|
1447 | return self.store.manifestlog(self, self._storenarrowmatch) | |
1448 |
|
1448 | |||
1449 | @repofilecache(b'dirstate') |
|
1449 | @repofilecache(b'dirstate') | |
1450 | def dirstate(self): |
|
1450 | def dirstate(self): | |
1451 | return self._makedirstate() |
|
1451 | return self._makedirstate() | |
1452 |
|
1452 | |||
1453 | def _makedirstate(self): |
|
1453 | def _makedirstate(self): | |
1454 | """Extension point for wrapping the dirstate per-repo.""" |
|
1454 | """Extension point for wrapping the dirstate per-repo.""" | |
1455 | sparsematchfn = lambda: sparse.matcher(self) |
|
1455 | sparsematchfn = lambda: sparse.matcher(self) | |
1456 |
|
1456 | |||
1457 | return dirstate.dirstate( |
|
1457 | return dirstate.dirstate( | |
1458 | self.vfs, self.ui, self.root, self._dirstatevalidate, sparsematchfn |
|
1458 | self.vfs, self.ui, self.root, self._dirstatevalidate, sparsematchfn | |
1459 | ) |
|
1459 | ) | |
1460 |
|
1460 | |||
1461 | def _dirstatevalidate(self, node): |
|
1461 | def _dirstatevalidate(self, node): | |
1462 | try: |
|
1462 | try: | |
1463 | self.changelog.rev(node) |
|
1463 | self.changelog.rev(node) | |
1464 | return node |
|
1464 | return node | |
1465 | except error.LookupError: |
|
1465 | except error.LookupError: | |
1466 | if not self._dirstatevalidatewarned: |
|
1466 | if not self._dirstatevalidatewarned: | |
1467 | self._dirstatevalidatewarned = True |
|
1467 | self._dirstatevalidatewarned = True | |
1468 | self.ui.warn( |
|
1468 | self.ui.warn( | |
1469 | _(b"warning: ignoring unknown working parent %s!\n") |
|
1469 | _(b"warning: ignoring unknown working parent %s!\n") | |
1470 | % short(node) |
|
1470 | % short(node) | |
1471 | ) |
|
1471 | ) | |
1472 | return nullid |
|
1472 | return nullid | |
1473 |
|
1473 | |||
1474 | @storecache(narrowspec.FILENAME) |
|
1474 | @storecache(narrowspec.FILENAME) | |
1475 | def narrowpats(self): |
|
1475 | def narrowpats(self): | |
1476 | """matcher patterns for this repository's narrowspec |
|
1476 | """matcher patterns for this repository's narrowspec | |
1477 |
|
1477 | |||
1478 | A tuple of (includes, excludes). |
|
1478 | A tuple of (includes, excludes). | |
1479 | """ |
|
1479 | """ | |
1480 | return narrowspec.load(self) |
|
1480 | return narrowspec.load(self) | |
1481 |
|
1481 | |||
1482 | @storecache(narrowspec.FILENAME) |
|
1482 | @storecache(narrowspec.FILENAME) | |
1483 | def _storenarrowmatch(self): |
|
1483 | def _storenarrowmatch(self): | |
1484 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1484 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1485 | return matchmod.always() |
|
1485 | return matchmod.always() | |
1486 | include, exclude = self.narrowpats |
|
1486 | include, exclude = self.narrowpats | |
1487 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1487 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1488 |
|
1488 | |||
1489 | @storecache(narrowspec.FILENAME) |
|
1489 | @storecache(narrowspec.FILENAME) | |
1490 | def _narrowmatch(self): |
|
1490 | def _narrowmatch(self): | |
1491 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1491 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1492 | return matchmod.always() |
|
1492 | return matchmod.always() | |
1493 | narrowspec.checkworkingcopynarrowspec(self) |
|
1493 | narrowspec.checkworkingcopynarrowspec(self) | |
1494 | include, exclude = self.narrowpats |
|
1494 | include, exclude = self.narrowpats | |
1495 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1495 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1496 |
|
1496 | |||
1497 | def narrowmatch(self, match=None, includeexact=False): |
|
1497 | def narrowmatch(self, match=None, includeexact=False): | |
1498 | """matcher corresponding the the repo's narrowspec |
|
1498 | """matcher corresponding the the repo's narrowspec | |
1499 |
|
1499 | |||
1500 | If `match` is given, then that will be intersected with the narrow |
|
1500 | If `match` is given, then that will be intersected with the narrow | |
1501 | matcher. |
|
1501 | matcher. | |
1502 |
|
1502 | |||
1503 | If `includeexact` is True, then any exact matches from `match` will |
|
1503 | If `includeexact` is True, then any exact matches from `match` will | |
1504 | be included even if they're outside the narrowspec. |
|
1504 | be included even if they're outside the narrowspec. | |
1505 | """ |
|
1505 | """ | |
1506 | if match: |
|
1506 | if match: | |
1507 | if includeexact and not self._narrowmatch.always(): |
|
1507 | if includeexact and not self._narrowmatch.always(): | |
1508 | # do not exclude explicitly-specified paths so that they can |
|
1508 | # do not exclude explicitly-specified paths so that they can | |
1509 | # be warned later on |
|
1509 | # be warned later on | |
1510 | em = matchmod.exact(match.files()) |
|
1510 | em = matchmod.exact(match.files()) | |
1511 | nm = matchmod.unionmatcher([self._narrowmatch, em]) |
|
1511 | nm = matchmod.unionmatcher([self._narrowmatch, em]) | |
1512 | return matchmod.intersectmatchers(match, nm) |
|
1512 | return matchmod.intersectmatchers(match, nm) | |
1513 | return matchmod.intersectmatchers(match, self._narrowmatch) |
|
1513 | return matchmod.intersectmatchers(match, self._narrowmatch) | |
1514 | return self._narrowmatch |
|
1514 | return self._narrowmatch | |
1515 |
|
1515 | |||
1516 | def setnarrowpats(self, newincludes, newexcludes): |
|
1516 | def setnarrowpats(self, newincludes, newexcludes): | |
1517 | narrowspec.save(self, newincludes, newexcludes) |
|
1517 | narrowspec.save(self, newincludes, newexcludes) | |
1518 | self.invalidate(clearfilecache=True) |
|
1518 | self.invalidate(clearfilecache=True) | |
1519 |
|
1519 | |||
1520 | @util.propertycache |
|
1520 | @util.propertycache | |
1521 | def _quick_access_changeid(self): |
|
1521 | def _quick_access_changeid(self): | |
1522 | """an helper dictionnary for __getitem__ calls |
|
1522 | """an helper dictionnary for __getitem__ calls | |
1523 |
|
1523 | |||
1524 | This contains a list of symbol we can recognise right away without |
|
1524 | This contains a list of symbol we can recognise right away without | |
1525 | further processing. |
|
1525 | further processing. | |
1526 | """ |
|
1526 | """ | |
1527 | return { |
|
1527 | return { | |
1528 | b'null': (nullrev, nullid), |
|
1528 | b'null': (nullrev, nullid), | |
1529 | nullrev: (nullrev, nullid), |
|
1529 | nullrev: (nullrev, nullid), | |
1530 | nullid: (nullrev, nullid), |
|
1530 | nullid: (nullrev, nullid), | |
1531 | } |
|
1531 | } | |
1532 |
|
1532 | |||
1533 | def __getitem__(self, changeid): |
|
1533 | def __getitem__(self, changeid): | |
1534 | # dealing with special cases |
|
1534 | # dealing with special cases | |
1535 | if changeid is None: |
|
1535 | if changeid is None: | |
1536 | return context.workingctx(self) |
|
1536 | return context.workingctx(self) | |
1537 | if isinstance(changeid, context.basectx): |
|
1537 | if isinstance(changeid, context.basectx): | |
1538 | return changeid |
|
1538 | return changeid | |
1539 |
|
1539 | |||
1540 | # dealing with multiple revisions |
|
1540 | # dealing with multiple revisions | |
1541 | if isinstance(changeid, slice): |
|
1541 | if isinstance(changeid, slice): | |
1542 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
1542 | # wdirrev isn't contiguous so the slice shouldn't include it | |
1543 | return [ |
|
1543 | return [ | |
1544 | self[i] |
|
1544 | self[i] | |
1545 | for i in pycompat.xrange(*changeid.indices(len(self))) |
|
1545 | for i in pycompat.xrange(*changeid.indices(len(self))) | |
1546 | if i not in self.changelog.filteredrevs |
|
1546 | if i not in self.changelog.filteredrevs | |
1547 | ] |
|
1547 | ] | |
1548 |
|
1548 | |||
1549 | # dealing with some special values |
|
1549 | # dealing with some special values | |
1550 | quick_access = self._quick_access_changeid.get(changeid) |
|
1550 | quick_access = self._quick_access_changeid.get(changeid) | |
1551 | if quick_access is not None: |
|
1551 | if quick_access is not None: | |
1552 | rev, node = quick_access |
|
1552 | rev, node = quick_access | |
1553 | return context.changectx(self, rev, node, maybe_filtered=False) |
|
1553 | return context.changectx(self, rev, node, maybe_filtered=False) | |
1554 | if changeid == b'tip': |
|
1554 | if changeid == b'tip': | |
1555 | node = self.changelog.tip() |
|
1555 | node = self.changelog.tip() | |
1556 | rev = self.changelog.rev(node) |
|
1556 | rev = self.changelog.rev(node) | |
1557 | return context.changectx(self, rev, node) |
|
1557 | return context.changectx(self, rev, node) | |
1558 |
|
1558 | |||
1559 | # dealing with arbitrary values |
|
1559 | # dealing with arbitrary values | |
1560 | try: |
|
1560 | try: | |
1561 | if isinstance(changeid, int): |
|
1561 | if isinstance(changeid, int): | |
1562 | node = self.changelog.node(changeid) |
|
1562 | node = self.changelog.node(changeid) | |
1563 | rev = changeid |
|
1563 | rev = changeid | |
1564 | elif changeid == b'.': |
|
1564 | elif changeid == b'.': | |
1565 | # this is a hack to delay/avoid loading obsmarkers |
|
1565 | # this is a hack to delay/avoid loading obsmarkers | |
1566 | # when we know that '.' won't be hidden |
|
1566 | # when we know that '.' won't be hidden | |
1567 | node = self.dirstate.p1() |
|
1567 | node = self.dirstate.p1() | |
1568 | rev = self.unfiltered().changelog.rev(node) |
|
1568 | rev = self.unfiltered().changelog.rev(node) | |
1569 | elif len(changeid) == 20: |
|
1569 | elif len(changeid) == 20: | |
1570 | try: |
|
1570 | try: | |
1571 | node = changeid |
|
1571 | node = changeid | |
1572 | rev = self.changelog.rev(changeid) |
|
1572 | rev = self.changelog.rev(changeid) | |
1573 | except error.FilteredLookupError: |
|
1573 | except error.FilteredLookupError: | |
1574 | changeid = hex(changeid) # for the error message |
|
1574 | changeid = hex(changeid) # for the error message | |
1575 | raise |
|
1575 | raise | |
1576 | except LookupError: |
|
1576 | except LookupError: | |
1577 | # check if it might have come from damaged dirstate |
|
1577 | # check if it might have come from damaged dirstate | |
1578 | # |
|
1578 | # | |
1579 | # XXX we could avoid the unfiltered if we had a recognizable |
|
1579 | # XXX we could avoid the unfiltered if we had a recognizable | |
1580 | # exception for filtered changeset access |
|
1580 | # exception for filtered changeset access | |
1581 | if ( |
|
1581 | if ( | |
1582 | self.local() |
|
1582 | self.local() | |
1583 | and changeid in self.unfiltered().dirstate.parents() |
|
1583 | and changeid in self.unfiltered().dirstate.parents() | |
1584 | ): |
|
1584 | ): | |
1585 | msg = _(b"working directory has unknown parent '%s'!") |
|
1585 | msg = _(b"working directory has unknown parent '%s'!") | |
1586 | raise error.Abort(msg % short(changeid)) |
|
1586 | raise error.Abort(msg % short(changeid)) | |
1587 | changeid = hex(changeid) # for the error message |
|
1587 | changeid = hex(changeid) # for the error message | |
1588 | raise |
|
1588 | raise | |
1589 |
|
1589 | |||
1590 | elif len(changeid) == 40: |
|
1590 | elif len(changeid) == 40: | |
1591 | node = bin(changeid) |
|
1591 | node = bin(changeid) | |
1592 | rev = self.changelog.rev(node) |
|
1592 | rev = self.changelog.rev(node) | |
1593 | else: |
|
1593 | else: | |
1594 | raise error.ProgrammingError( |
|
1594 | raise error.ProgrammingError( | |
1595 | b"unsupported changeid '%s' of type %s" |
|
1595 | b"unsupported changeid '%s' of type %s" | |
1596 | % (changeid, pycompat.bytestr(type(changeid))) |
|
1596 | % (changeid, pycompat.bytestr(type(changeid))) | |
1597 | ) |
|
1597 | ) | |
1598 |
|
1598 | |||
1599 | return context.changectx(self, rev, node) |
|
1599 | return context.changectx(self, rev, node) | |
1600 |
|
1600 | |||
1601 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
1601 | except (error.FilteredIndexError, error.FilteredLookupError): | |
1602 | raise error.FilteredRepoLookupError( |
|
1602 | raise error.FilteredRepoLookupError( | |
1603 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) |
|
1603 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) | |
1604 | ) |
|
1604 | ) | |
1605 | except (IndexError, LookupError): |
|
1605 | except (IndexError, LookupError): | |
1606 | raise error.RepoLookupError( |
|
1606 | raise error.RepoLookupError( | |
1607 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) |
|
1607 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) | |
1608 | ) |
|
1608 | ) | |
1609 | except error.WdirUnsupported: |
|
1609 | except error.WdirUnsupported: | |
1610 | return context.workingctx(self) |
|
1610 | return context.workingctx(self) | |
1611 |
|
1611 | |||
1612 | def __contains__(self, changeid): |
|
1612 | def __contains__(self, changeid): | |
1613 | """True if the given changeid exists |
|
1613 | """True if the given changeid exists | |
1614 |
|
1614 | |||
1615 | error.AmbiguousPrefixLookupError is raised if an ambiguous node |
|
1615 | error.AmbiguousPrefixLookupError is raised if an ambiguous node | |
1616 | specified. |
|
1616 | specified. | |
1617 | """ |
|
1617 | """ | |
1618 | try: |
|
1618 | try: | |
1619 | self[changeid] |
|
1619 | self[changeid] | |
1620 | return True |
|
1620 | return True | |
1621 | except error.RepoLookupError: |
|
1621 | except error.RepoLookupError: | |
1622 | return False |
|
1622 | return False | |
1623 |
|
1623 | |||
1624 | def __nonzero__(self): |
|
1624 | def __nonzero__(self): | |
1625 | return True |
|
1625 | return True | |
1626 |
|
1626 | |||
1627 | __bool__ = __nonzero__ |
|
1627 | __bool__ = __nonzero__ | |
1628 |
|
1628 | |||
1629 | def __len__(self): |
|
1629 | def __len__(self): | |
1630 | # no need to pay the cost of repoview.changelog |
|
1630 | # no need to pay the cost of repoview.changelog | |
1631 | unfi = self.unfiltered() |
|
1631 | unfi = self.unfiltered() | |
1632 | return len(unfi.changelog) |
|
1632 | return len(unfi.changelog) | |
1633 |
|
1633 | |||
1634 | def __iter__(self): |
|
1634 | def __iter__(self): | |
1635 | return iter(self.changelog) |
|
1635 | return iter(self.changelog) | |
1636 |
|
1636 | |||
1637 | def revs(self, expr, *args): |
|
1637 | def revs(self, expr, *args): | |
1638 | '''Find revisions matching a revset. |
|
1638 | '''Find revisions matching a revset. | |
1639 |
|
1639 | |||
1640 | The revset is specified as a string ``expr`` that may contain |
|
1640 | The revset is specified as a string ``expr`` that may contain | |
1641 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
1641 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
1642 |
|
1642 | |||
1643 | Revset aliases from the configuration are not expanded. To expand |
|
1643 | Revset aliases from the configuration are not expanded. To expand | |
1644 | user aliases, consider calling ``scmutil.revrange()`` or |
|
1644 | user aliases, consider calling ``scmutil.revrange()`` or | |
1645 | ``repo.anyrevs([expr], user=True)``. |
|
1645 | ``repo.anyrevs([expr], user=True)``. | |
1646 |
|
1646 | |||
1647 |
Returns a |
|
1647 | Returns a smartset.abstractsmartset, which is a list-like interface | |
1648 | that contains integer revisions. |
|
1648 | that contains integer revisions. | |
1649 | ''' |
|
1649 | ''' | |
1650 | tree = revsetlang.spectree(expr, *args) |
|
1650 | tree = revsetlang.spectree(expr, *args) | |
1651 | return revset.makematcher(tree)(self) |
|
1651 | return revset.makematcher(tree)(self) | |
1652 |
|
1652 | |||
1653 | def set(self, expr, *args): |
|
1653 | def set(self, expr, *args): | |
1654 | '''Find revisions matching a revset and emit changectx instances. |
|
1654 | '''Find revisions matching a revset and emit changectx instances. | |
1655 |
|
1655 | |||
1656 | This is a convenience wrapper around ``revs()`` that iterates the |
|
1656 | This is a convenience wrapper around ``revs()`` that iterates the | |
1657 | result and is a generator of changectx instances. |
|
1657 | result and is a generator of changectx instances. | |
1658 |
|
1658 | |||
1659 | Revset aliases from the configuration are not expanded. To expand |
|
1659 | Revset aliases from the configuration are not expanded. To expand | |
1660 | user aliases, consider calling ``scmutil.revrange()``. |
|
1660 | user aliases, consider calling ``scmutil.revrange()``. | |
1661 | ''' |
|
1661 | ''' | |
1662 | for r in self.revs(expr, *args): |
|
1662 | for r in self.revs(expr, *args): | |
1663 | yield self[r] |
|
1663 | yield self[r] | |
1664 |
|
1664 | |||
1665 | def anyrevs(self, specs, user=False, localalias=None): |
|
1665 | def anyrevs(self, specs, user=False, localalias=None): | |
1666 | '''Find revisions matching one of the given revsets. |
|
1666 | '''Find revisions matching one of the given revsets. | |
1667 |
|
1667 | |||
1668 | Revset aliases from the configuration are not expanded by default. To |
|
1668 | Revset aliases from the configuration are not expanded by default. To | |
1669 | expand user aliases, specify ``user=True``. To provide some local |
|
1669 | expand user aliases, specify ``user=True``. To provide some local | |
1670 | definitions overriding user aliases, set ``localalias`` to |
|
1670 | definitions overriding user aliases, set ``localalias`` to | |
1671 | ``{name: definitionstring}``. |
|
1671 | ``{name: definitionstring}``. | |
1672 | ''' |
|
1672 | ''' | |
1673 | if specs == [b'null']: |
|
1673 | if specs == [b'null']: | |
1674 | return revset.baseset([nullrev]) |
|
1674 | return revset.baseset([nullrev]) | |
1675 | if user: |
|
1675 | if user: | |
1676 | m = revset.matchany( |
|
1676 | m = revset.matchany( | |
1677 | self.ui, |
|
1677 | self.ui, | |
1678 | specs, |
|
1678 | specs, | |
1679 | lookup=revset.lookupfn(self), |
|
1679 | lookup=revset.lookupfn(self), | |
1680 | localalias=localalias, |
|
1680 | localalias=localalias, | |
1681 | ) |
|
1681 | ) | |
1682 | else: |
|
1682 | else: | |
1683 | m = revset.matchany(None, specs, localalias=localalias) |
|
1683 | m = revset.matchany(None, specs, localalias=localalias) | |
1684 | return m(self) |
|
1684 | return m(self) | |
1685 |
|
1685 | |||
1686 | def url(self): |
|
1686 | def url(self): | |
1687 | return b'file:' + self.root |
|
1687 | return b'file:' + self.root | |
1688 |
|
1688 | |||
1689 | def hook(self, name, throw=False, **args): |
|
1689 | def hook(self, name, throw=False, **args): | |
1690 | """Call a hook, passing this repo instance. |
|
1690 | """Call a hook, passing this repo instance. | |
1691 |
|
1691 | |||
1692 | This a convenience method to aid invoking hooks. Extensions likely |
|
1692 | This a convenience method to aid invoking hooks. Extensions likely | |
1693 | won't call this unless they have registered a custom hook or are |
|
1693 | won't call this unless they have registered a custom hook or are | |
1694 | replacing code that is expected to call a hook. |
|
1694 | replacing code that is expected to call a hook. | |
1695 | """ |
|
1695 | """ | |
1696 | return hook.hook(self.ui, self, name, throw, **args) |
|
1696 | return hook.hook(self.ui, self, name, throw, **args) | |
1697 |
|
1697 | |||
1698 | @filteredpropertycache |
|
1698 | @filteredpropertycache | |
1699 | def _tagscache(self): |
|
1699 | def _tagscache(self): | |
1700 | '''Returns a tagscache object that contains various tags related |
|
1700 | '''Returns a tagscache object that contains various tags related | |
1701 | caches.''' |
|
1701 | caches.''' | |
1702 |
|
1702 | |||
1703 | # This simplifies its cache management by having one decorated |
|
1703 | # This simplifies its cache management by having one decorated | |
1704 | # function (this one) and the rest simply fetch things from it. |
|
1704 | # function (this one) and the rest simply fetch things from it. | |
1705 | class tagscache(object): |
|
1705 | class tagscache(object): | |
1706 | def __init__(self): |
|
1706 | def __init__(self): | |
1707 | # These two define the set of tags for this repository. tags |
|
1707 | # These two define the set of tags for this repository. tags | |
1708 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
1708 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
1709 | # 'local'. (Global tags are defined by .hgtags across all |
|
1709 | # 'local'. (Global tags are defined by .hgtags across all | |
1710 | # heads, and local tags are defined in .hg/localtags.) |
|
1710 | # heads, and local tags are defined in .hg/localtags.) | |
1711 | # They constitute the in-memory cache of tags. |
|
1711 | # They constitute the in-memory cache of tags. | |
1712 | self.tags = self.tagtypes = None |
|
1712 | self.tags = self.tagtypes = None | |
1713 |
|
1713 | |||
1714 | self.nodetagscache = self.tagslist = None |
|
1714 | self.nodetagscache = self.tagslist = None | |
1715 |
|
1715 | |||
1716 | cache = tagscache() |
|
1716 | cache = tagscache() | |
1717 | cache.tags, cache.tagtypes = self._findtags() |
|
1717 | cache.tags, cache.tagtypes = self._findtags() | |
1718 |
|
1718 | |||
1719 | return cache |
|
1719 | return cache | |
1720 |
|
1720 | |||
1721 | def tags(self): |
|
1721 | def tags(self): | |
1722 | '''return a mapping of tag to node''' |
|
1722 | '''return a mapping of tag to node''' | |
1723 | t = {} |
|
1723 | t = {} | |
1724 | if self.changelog.filteredrevs: |
|
1724 | if self.changelog.filteredrevs: | |
1725 | tags, tt = self._findtags() |
|
1725 | tags, tt = self._findtags() | |
1726 | else: |
|
1726 | else: | |
1727 | tags = self._tagscache.tags |
|
1727 | tags = self._tagscache.tags | |
1728 | rev = self.changelog.rev |
|
1728 | rev = self.changelog.rev | |
1729 | for k, v in pycompat.iteritems(tags): |
|
1729 | for k, v in pycompat.iteritems(tags): | |
1730 | try: |
|
1730 | try: | |
1731 | # ignore tags to unknown nodes |
|
1731 | # ignore tags to unknown nodes | |
1732 | rev(v) |
|
1732 | rev(v) | |
1733 | t[k] = v |
|
1733 | t[k] = v | |
1734 | except (error.LookupError, ValueError): |
|
1734 | except (error.LookupError, ValueError): | |
1735 | pass |
|
1735 | pass | |
1736 | return t |
|
1736 | return t | |
1737 |
|
1737 | |||
1738 | def _findtags(self): |
|
1738 | def _findtags(self): | |
1739 | '''Do the hard work of finding tags. Return a pair of dicts |
|
1739 | '''Do the hard work of finding tags. Return a pair of dicts | |
1740 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
1740 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
1741 | maps tag name to a string like \'global\' or \'local\'. |
|
1741 | maps tag name to a string like \'global\' or \'local\'. | |
1742 | Subclasses or extensions are free to add their own tags, but |
|
1742 | Subclasses or extensions are free to add their own tags, but | |
1743 | should be aware that the returned dicts will be retained for the |
|
1743 | should be aware that the returned dicts will be retained for the | |
1744 | duration of the localrepo object.''' |
|
1744 | duration of the localrepo object.''' | |
1745 |
|
1745 | |||
1746 | # XXX what tagtype should subclasses/extensions use? Currently |
|
1746 | # XXX what tagtype should subclasses/extensions use? Currently | |
1747 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
1747 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
1748 | # Should each extension invent its own tag type? Should there |
|
1748 | # Should each extension invent its own tag type? Should there | |
1749 | # be one tagtype for all such "virtual" tags? Or is the status |
|
1749 | # be one tagtype for all such "virtual" tags? Or is the status | |
1750 | # quo fine? |
|
1750 | # quo fine? | |
1751 |
|
1751 | |||
1752 | # map tag name to (node, hist) |
|
1752 | # map tag name to (node, hist) | |
1753 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
1753 | alltags = tagsmod.findglobaltags(self.ui, self) | |
1754 | # map tag name to tag type |
|
1754 | # map tag name to tag type | |
1755 | tagtypes = dict((tag, b'global') for tag in alltags) |
|
1755 | tagtypes = dict((tag, b'global') for tag in alltags) | |
1756 |
|
1756 | |||
1757 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
1757 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
1758 |
|
1758 | |||
1759 | # Build the return dicts. Have to re-encode tag names because |
|
1759 | # Build the return dicts. Have to re-encode tag names because | |
1760 | # the tags module always uses UTF-8 (in order not to lose info |
|
1760 | # the tags module always uses UTF-8 (in order not to lose info | |
1761 | # writing to the cache), but the rest of Mercurial wants them in |
|
1761 | # writing to the cache), but the rest of Mercurial wants them in | |
1762 | # local encoding. |
|
1762 | # local encoding. | |
1763 | tags = {} |
|
1763 | tags = {} | |
1764 | for (name, (node, hist)) in pycompat.iteritems(alltags): |
|
1764 | for (name, (node, hist)) in pycompat.iteritems(alltags): | |
1765 | if node != nullid: |
|
1765 | if node != nullid: | |
1766 | tags[encoding.tolocal(name)] = node |
|
1766 | tags[encoding.tolocal(name)] = node | |
1767 | tags[b'tip'] = self.changelog.tip() |
|
1767 | tags[b'tip'] = self.changelog.tip() | |
1768 | tagtypes = dict( |
|
1768 | tagtypes = dict( | |
1769 | [ |
|
1769 | [ | |
1770 | (encoding.tolocal(name), value) |
|
1770 | (encoding.tolocal(name), value) | |
1771 | for (name, value) in pycompat.iteritems(tagtypes) |
|
1771 | for (name, value) in pycompat.iteritems(tagtypes) | |
1772 | ] |
|
1772 | ] | |
1773 | ) |
|
1773 | ) | |
1774 | return (tags, tagtypes) |
|
1774 | return (tags, tagtypes) | |
1775 |
|
1775 | |||
1776 | def tagtype(self, tagname): |
|
1776 | def tagtype(self, tagname): | |
1777 | ''' |
|
1777 | ''' | |
1778 | return the type of the given tag. result can be: |
|
1778 | return the type of the given tag. result can be: | |
1779 |
|
1779 | |||
1780 | 'local' : a local tag |
|
1780 | 'local' : a local tag | |
1781 | 'global' : a global tag |
|
1781 | 'global' : a global tag | |
1782 | None : tag does not exist |
|
1782 | None : tag does not exist | |
1783 | ''' |
|
1783 | ''' | |
1784 |
|
1784 | |||
1785 | return self._tagscache.tagtypes.get(tagname) |
|
1785 | return self._tagscache.tagtypes.get(tagname) | |
1786 |
|
1786 | |||
1787 | def tagslist(self): |
|
1787 | def tagslist(self): | |
1788 | '''return a list of tags ordered by revision''' |
|
1788 | '''return a list of tags ordered by revision''' | |
1789 | if not self._tagscache.tagslist: |
|
1789 | if not self._tagscache.tagslist: | |
1790 | l = [] |
|
1790 | l = [] | |
1791 | for t, n in pycompat.iteritems(self.tags()): |
|
1791 | for t, n in pycompat.iteritems(self.tags()): | |
1792 | l.append((self.changelog.rev(n), t, n)) |
|
1792 | l.append((self.changelog.rev(n), t, n)) | |
1793 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
1793 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
1794 |
|
1794 | |||
1795 | return self._tagscache.tagslist |
|
1795 | return self._tagscache.tagslist | |
1796 |
|
1796 | |||
1797 | def nodetags(self, node): |
|
1797 | def nodetags(self, node): | |
1798 | '''return the tags associated with a node''' |
|
1798 | '''return the tags associated with a node''' | |
1799 | if not self._tagscache.nodetagscache: |
|
1799 | if not self._tagscache.nodetagscache: | |
1800 | nodetagscache = {} |
|
1800 | nodetagscache = {} | |
1801 | for t, n in pycompat.iteritems(self._tagscache.tags): |
|
1801 | for t, n in pycompat.iteritems(self._tagscache.tags): | |
1802 | nodetagscache.setdefault(n, []).append(t) |
|
1802 | nodetagscache.setdefault(n, []).append(t) | |
1803 | for tags in pycompat.itervalues(nodetagscache): |
|
1803 | for tags in pycompat.itervalues(nodetagscache): | |
1804 | tags.sort() |
|
1804 | tags.sort() | |
1805 | self._tagscache.nodetagscache = nodetagscache |
|
1805 | self._tagscache.nodetagscache = nodetagscache | |
1806 | return self._tagscache.nodetagscache.get(node, []) |
|
1806 | return self._tagscache.nodetagscache.get(node, []) | |
1807 |
|
1807 | |||
1808 | def nodebookmarks(self, node): |
|
1808 | def nodebookmarks(self, node): | |
1809 | """return the list of bookmarks pointing to the specified node""" |
|
1809 | """return the list of bookmarks pointing to the specified node""" | |
1810 | return self._bookmarks.names(node) |
|
1810 | return self._bookmarks.names(node) | |
1811 |
|
1811 | |||
1812 | def branchmap(self): |
|
1812 | def branchmap(self): | |
1813 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
1813 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
1814 | ordered by increasing revision number''' |
|
1814 | ordered by increasing revision number''' | |
1815 | return self._branchcaches[self] |
|
1815 | return self._branchcaches[self] | |
1816 |
|
1816 | |||
1817 | @unfilteredmethod |
|
1817 | @unfilteredmethod | |
1818 | def revbranchcache(self): |
|
1818 | def revbranchcache(self): | |
1819 | if not self._revbranchcache: |
|
1819 | if not self._revbranchcache: | |
1820 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
1820 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
1821 | return self._revbranchcache |
|
1821 | return self._revbranchcache | |
1822 |
|
1822 | |||
1823 | def branchtip(self, branch, ignoremissing=False): |
|
1823 | def branchtip(self, branch, ignoremissing=False): | |
1824 | '''return the tip node for a given branch |
|
1824 | '''return the tip node for a given branch | |
1825 |
|
1825 | |||
1826 | If ignoremissing is True, then this method will not raise an error. |
|
1826 | If ignoremissing is True, then this method will not raise an error. | |
1827 | This is helpful for callers that only expect None for a missing branch |
|
1827 | This is helpful for callers that only expect None for a missing branch | |
1828 | (e.g. namespace). |
|
1828 | (e.g. namespace). | |
1829 |
|
1829 | |||
1830 | ''' |
|
1830 | ''' | |
1831 | try: |
|
1831 | try: | |
1832 | return self.branchmap().branchtip(branch) |
|
1832 | return self.branchmap().branchtip(branch) | |
1833 | except KeyError: |
|
1833 | except KeyError: | |
1834 | if not ignoremissing: |
|
1834 | if not ignoremissing: | |
1835 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) |
|
1835 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) | |
1836 | else: |
|
1836 | else: | |
1837 | pass |
|
1837 | pass | |
1838 |
|
1838 | |||
1839 | def lookup(self, key): |
|
1839 | def lookup(self, key): | |
1840 | node = scmutil.revsymbol(self, key).node() |
|
1840 | node = scmutil.revsymbol(self, key).node() | |
1841 | if node is None: |
|
1841 | if node is None: | |
1842 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) |
|
1842 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) | |
1843 | return node |
|
1843 | return node | |
1844 |
|
1844 | |||
1845 | def lookupbranch(self, key): |
|
1845 | def lookupbranch(self, key): | |
1846 | if self.branchmap().hasbranch(key): |
|
1846 | if self.branchmap().hasbranch(key): | |
1847 | return key |
|
1847 | return key | |
1848 |
|
1848 | |||
1849 | return scmutil.revsymbol(self, key).branch() |
|
1849 | return scmutil.revsymbol(self, key).branch() | |
1850 |
|
1850 | |||
1851 | def known(self, nodes): |
|
1851 | def known(self, nodes): | |
1852 | cl = self.changelog |
|
1852 | cl = self.changelog | |
1853 | get_rev = cl.index.get_rev |
|
1853 | get_rev = cl.index.get_rev | |
1854 | filtered = cl.filteredrevs |
|
1854 | filtered = cl.filteredrevs | |
1855 | result = [] |
|
1855 | result = [] | |
1856 | for n in nodes: |
|
1856 | for n in nodes: | |
1857 | r = get_rev(n) |
|
1857 | r = get_rev(n) | |
1858 | resp = not (r is None or r in filtered) |
|
1858 | resp = not (r is None or r in filtered) | |
1859 | result.append(resp) |
|
1859 | result.append(resp) | |
1860 | return result |
|
1860 | return result | |
1861 |
|
1861 | |||
1862 | def local(self): |
|
1862 | def local(self): | |
1863 | return self |
|
1863 | return self | |
1864 |
|
1864 | |||
1865 | def publishing(self): |
|
1865 | def publishing(self): | |
1866 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1866 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1867 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1867 | # so that we don't finalize changes shared between users via ssh or nfs | |
1868 | return self.ui.configbool(b'phases', b'publish', untrusted=True) |
|
1868 | return self.ui.configbool(b'phases', b'publish', untrusted=True) | |
1869 |
|
1869 | |||
1870 | def cancopy(self): |
|
1870 | def cancopy(self): | |
1871 | # so statichttprepo's override of local() works |
|
1871 | # so statichttprepo's override of local() works | |
1872 | if not self.local(): |
|
1872 | if not self.local(): | |
1873 | return False |
|
1873 | return False | |
1874 | if not self.publishing(): |
|
1874 | if not self.publishing(): | |
1875 | return True |
|
1875 | return True | |
1876 | # if publishing we can't copy if there is filtered content |
|
1876 | # if publishing we can't copy if there is filtered content | |
1877 | return not self.filtered(b'visible').changelog.filteredrevs |
|
1877 | return not self.filtered(b'visible').changelog.filteredrevs | |
1878 |
|
1878 | |||
1879 | def shared(self): |
|
1879 | def shared(self): | |
1880 | '''the type of shared repository (None if not shared)''' |
|
1880 | '''the type of shared repository (None if not shared)''' | |
1881 | if self.sharedpath != self.path: |
|
1881 | if self.sharedpath != self.path: | |
1882 | return b'store' |
|
1882 | return b'store' | |
1883 | return None |
|
1883 | return None | |
1884 |
|
1884 | |||
1885 | def wjoin(self, f, *insidef): |
|
1885 | def wjoin(self, f, *insidef): | |
1886 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1886 | return self.vfs.reljoin(self.root, f, *insidef) | |
1887 |
|
1887 | |||
1888 | def setparents(self, p1, p2=nullid): |
|
1888 | def setparents(self, p1, p2=nullid): | |
1889 | self[None].setparents(p1, p2) |
|
1889 | self[None].setparents(p1, p2) | |
1890 |
|
1890 | |||
1891 | def filectx(self, path, changeid=None, fileid=None, changectx=None): |
|
1891 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
1892 | """changeid must be a changeset revision, if specified. |
|
1892 | """changeid must be a changeset revision, if specified. | |
1893 | fileid can be a file revision or node.""" |
|
1893 | fileid can be a file revision or node.""" | |
1894 | return context.filectx( |
|
1894 | return context.filectx( | |
1895 | self, path, changeid, fileid, changectx=changectx |
|
1895 | self, path, changeid, fileid, changectx=changectx | |
1896 | ) |
|
1896 | ) | |
1897 |
|
1897 | |||
1898 | def getcwd(self): |
|
1898 | def getcwd(self): | |
1899 | return self.dirstate.getcwd() |
|
1899 | return self.dirstate.getcwd() | |
1900 |
|
1900 | |||
1901 | def pathto(self, f, cwd=None): |
|
1901 | def pathto(self, f, cwd=None): | |
1902 | return self.dirstate.pathto(f, cwd) |
|
1902 | return self.dirstate.pathto(f, cwd) | |
1903 |
|
1903 | |||
1904 | def _loadfilter(self, filter): |
|
1904 | def _loadfilter(self, filter): | |
1905 | if filter not in self._filterpats: |
|
1905 | if filter not in self._filterpats: | |
1906 | l = [] |
|
1906 | l = [] | |
1907 | for pat, cmd in self.ui.configitems(filter): |
|
1907 | for pat, cmd in self.ui.configitems(filter): | |
1908 | if cmd == b'!': |
|
1908 | if cmd == b'!': | |
1909 | continue |
|
1909 | continue | |
1910 | mf = matchmod.match(self.root, b'', [pat]) |
|
1910 | mf = matchmod.match(self.root, b'', [pat]) | |
1911 | fn = None |
|
1911 | fn = None | |
1912 | params = cmd |
|
1912 | params = cmd | |
1913 | for name, filterfn in pycompat.iteritems(self._datafilters): |
|
1913 | for name, filterfn in pycompat.iteritems(self._datafilters): | |
1914 | if cmd.startswith(name): |
|
1914 | if cmd.startswith(name): | |
1915 | fn = filterfn |
|
1915 | fn = filterfn | |
1916 | params = cmd[len(name) :].lstrip() |
|
1916 | params = cmd[len(name) :].lstrip() | |
1917 | break |
|
1917 | break | |
1918 | if not fn: |
|
1918 | if not fn: | |
1919 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1919 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1920 | fn.__name__ = 'commandfilter' |
|
1920 | fn.__name__ = 'commandfilter' | |
1921 | # Wrap old filters not supporting keyword arguments |
|
1921 | # Wrap old filters not supporting keyword arguments | |
1922 | if not pycompat.getargspec(fn)[2]: |
|
1922 | if not pycompat.getargspec(fn)[2]: | |
1923 | oldfn = fn |
|
1923 | oldfn = fn | |
1924 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) |
|
1924 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) | |
1925 | fn.__name__ = 'compat-' + oldfn.__name__ |
|
1925 | fn.__name__ = 'compat-' + oldfn.__name__ | |
1926 | l.append((mf, fn, params)) |
|
1926 | l.append((mf, fn, params)) | |
1927 | self._filterpats[filter] = l |
|
1927 | self._filterpats[filter] = l | |
1928 | return self._filterpats[filter] |
|
1928 | return self._filterpats[filter] | |
1929 |
|
1929 | |||
1930 | def _filter(self, filterpats, filename, data): |
|
1930 | def _filter(self, filterpats, filename, data): | |
1931 | for mf, fn, cmd in filterpats: |
|
1931 | for mf, fn, cmd in filterpats: | |
1932 | if mf(filename): |
|
1932 | if mf(filename): | |
1933 | self.ui.debug( |
|
1933 | self.ui.debug( | |
1934 | b"filtering %s through %s\n" |
|
1934 | b"filtering %s through %s\n" | |
1935 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) |
|
1935 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) | |
1936 | ) |
|
1936 | ) | |
1937 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1937 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1938 | break |
|
1938 | break | |
1939 |
|
1939 | |||
1940 | return data |
|
1940 | return data | |
1941 |
|
1941 | |||
1942 | @unfilteredpropertycache |
|
1942 | @unfilteredpropertycache | |
1943 | def _encodefilterpats(self): |
|
1943 | def _encodefilterpats(self): | |
1944 | return self._loadfilter(b'encode') |
|
1944 | return self._loadfilter(b'encode') | |
1945 |
|
1945 | |||
1946 | @unfilteredpropertycache |
|
1946 | @unfilteredpropertycache | |
1947 | def _decodefilterpats(self): |
|
1947 | def _decodefilterpats(self): | |
1948 | return self._loadfilter(b'decode') |
|
1948 | return self._loadfilter(b'decode') | |
1949 |
|
1949 | |||
1950 | def adddatafilter(self, name, filter): |
|
1950 | def adddatafilter(self, name, filter): | |
1951 | self._datafilters[name] = filter |
|
1951 | self._datafilters[name] = filter | |
1952 |
|
1952 | |||
1953 | def wread(self, filename): |
|
1953 | def wread(self, filename): | |
1954 | if self.wvfs.islink(filename): |
|
1954 | if self.wvfs.islink(filename): | |
1955 | data = self.wvfs.readlink(filename) |
|
1955 | data = self.wvfs.readlink(filename) | |
1956 | else: |
|
1956 | else: | |
1957 | data = self.wvfs.read(filename) |
|
1957 | data = self.wvfs.read(filename) | |
1958 | return self._filter(self._encodefilterpats, filename, data) |
|
1958 | return self._filter(self._encodefilterpats, filename, data) | |
1959 |
|
1959 | |||
1960 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
1960 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
1961 | """write ``data`` into ``filename`` in the working directory |
|
1961 | """write ``data`` into ``filename`` in the working directory | |
1962 |
|
1962 | |||
1963 | This returns length of written (maybe decoded) data. |
|
1963 | This returns length of written (maybe decoded) data. | |
1964 | """ |
|
1964 | """ | |
1965 | data = self._filter(self._decodefilterpats, filename, data) |
|
1965 | data = self._filter(self._decodefilterpats, filename, data) | |
1966 | if b'l' in flags: |
|
1966 | if b'l' in flags: | |
1967 | self.wvfs.symlink(data, filename) |
|
1967 | self.wvfs.symlink(data, filename) | |
1968 | else: |
|
1968 | else: | |
1969 | self.wvfs.write( |
|
1969 | self.wvfs.write( | |
1970 | filename, data, backgroundclose=backgroundclose, **kwargs |
|
1970 | filename, data, backgroundclose=backgroundclose, **kwargs | |
1971 | ) |
|
1971 | ) | |
1972 | if b'x' in flags: |
|
1972 | if b'x' in flags: | |
1973 | self.wvfs.setflags(filename, False, True) |
|
1973 | self.wvfs.setflags(filename, False, True) | |
1974 | else: |
|
1974 | else: | |
1975 | self.wvfs.setflags(filename, False, False) |
|
1975 | self.wvfs.setflags(filename, False, False) | |
1976 | return len(data) |
|
1976 | return len(data) | |
1977 |
|
1977 | |||
1978 | def wwritedata(self, filename, data): |
|
1978 | def wwritedata(self, filename, data): | |
1979 | return self._filter(self._decodefilterpats, filename, data) |
|
1979 | return self._filter(self._decodefilterpats, filename, data) | |
1980 |
|
1980 | |||
1981 | def currenttransaction(self): |
|
1981 | def currenttransaction(self): | |
1982 | """return the current transaction or None if non exists""" |
|
1982 | """return the current transaction or None if non exists""" | |
1983 | if self._transref: |
|
1983 | if self._transref: | |
1984 | tr = self._transref() |
|
1984 | tr = self._transref() | |
1985 | else: |
|
1985 | else: | |
1986 | tr = None |
|
1986 | tr = None | |
1987 |
|
1987 | |||
1988 | if tr and tr.running(): |
|
1988 | if tr and tr.running(): | |
1989 | return tr |
|
1989 | return tr | |
1990 | return None |
|
1990 | return None | |
1991 |
|
1991 | |||
1992 | def transaction(self, desc, report=None): |
|
1992 | def transaction(self, desc, report=None): | |
1993 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1993 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1994 | b'devel', b'check-locks' |
|
1994 | b'devel', b'check-locks' | |
1995 | ): |
|
1995 | ): | |
1996 | if self._currentlock(self._lockref) is None: |
|
1996 | if self._currentlock(self._lockref) is None: | |
1997 | raise error.ProgrammingError(b'transaction requires locking') |
|
1997 | raise error.ProgrammingError(b'transaction requires locking') | |
1998 | tr = self.currenttransaction() |
|
1998 | tr = self.currenttransaction() | |
1999 | if tr is not None: |
|
1999 | if tr is not None: | |
2000 | return tr.nest(name=desc) |
|
2000 | return tr.nest(name=desc) | |
2001 |
|
2001 | |||
2002 | # abort here if the journal already exists |
|
2002 | # abort here if the journal already exists | |
2003 | if self.svfs.exists(b"journal"): |
|
2003 | if self.svfs.exists(b"journal"): | |
2004 | raise error.RepoError( |
|
2004 | raise error.RepoError( | |
2005 | _(b"abandoned transaction found"), |
|
2005 | _(b"abandoned transaction found"), | |
2006 | hint=_(b"run 'hg recover' to clean up transaction"), |
|
2006 | hint=_(b"run 'hg recover' to clean up transaction"), | |
2007 | ) |
|
2007 | ) | |
2008 |
|
2008 | |||
2009 | idbase = b"%.40f#%f" % (random.random(), time.time()) |
|
2009 | idbase = b"%.40f#%f" % (random.random(), time.time()) | |
2010 | ha = hex(hashutil.sha1(idbase).digest()) |
|
2010 | ha = hex(hashutil.sha1(idbase).digest()) | |
2011 | txnid = b'TXN:' + ha |
|
2011 | txnid = b'TXN:' + ha | |
2012 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
2012 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
2013 |
|
2013 | |||
2014 | self._writejournal(desc) |
|
2014 | self._writejournal(desc) | |
2015 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
2015 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
2016 | if report: |
|
2016 | if report: | |
2017 | rp = report |
|
2017 | rp = report | |
2018 | else: |
|
2018 | else: | |
2019 | rp = self.ui.warn |
|
2019 | rp = self.ui.warn | |
2020 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ |
|
2020 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ | |
2021 | # we must avoid cyclic reference between repo and transaction. |
|
2021 | # we must avoid cyclic reference between repo and transaction. | |
2022 | reporef = weakref.ref(self) |
|
2022 | reporef = weakref.ref(self) | |
2023 | # Code to track tag movement |
|
2023 | # Code to track tag movement | |
2024 | # |
|
2024 | # | |
2025 | # Since tags are all handled as file content, it is actually quite hard |
|
2025 | # Since tags are all handled as file content, it is actually quite hard | |
2026 | # to track these movement from a code perspective. So we fallback to a |
|
2026 | # to track these movement from a code perspective. So we fallback to a | |
2027 | # tracking at the repository level. One could envision to track changes |
|
2027 | # tracking at the repository level. One could envision to track changes | |
2028 | # to the '.hgtags' file through changegroup apply but that fails to |
|
2028 | # to the '.hgtags' file through changegroup apply but that fails to | |
2029 | # cope with case where transaction expose new heads without changegroup |
|
2029 | # cope with case where transaction expose new heads without changegroup | |
2030 | # being involved (eg: phase movement). |
|
2030 | # being involved (eg: phase movement). | |
2031 | # |
|
2031 | # | |
2032 | # For now, We gate the feature behind a flag since this likely comes |
|
2032 | # For now, We gate the feature behind a flag since this likely comes | |
2033 | # with performance impacts. The current code run more often than needed |
|
2033 | # with performance impacts. The current code run more often than needed | |
2034 | # and do not use caches as much as it could. The current focus is on |
|
2034 | # and do not use caches as much as it could. The current focus is on | |
2035 | # the behavior of the feature so we disable it by default. The flag |
|
2035 | # the behavior of the feature so we disable it by default. The flag | |
2036 | # will be removed when we are happy with the performance impact. |
|
2036 | # will be removed when we are happy with the performance impact. | |
2037 | # |
|
2037 | # | |
2038 | # Once this feature is no longer experimental move the following |
|
2038 | # Once this feature is no longer experimental move the following | |
2039 | # documentation to the appropriate help section: |
|
2039 | # documentation to the appropriate help section: | |
2040 | # |
|
2040 | # | |
2041 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
2041 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
2042 | # tags (new or changed or deleted tags). In addition the details of |
|
2042 | # tags (new or changed or deleted tags). In addition the details of | |
2043 | # these changes are made available in a file at: |
|
2043 | # these changes are made available in a file at: | |
2044 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
2044 | # ``REPOROOT/.hg/changes/tags.changes``. | |
2045 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
2045 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
2046 | # might exist from a previous transaction even if no tag were touched |
|
2046 | # might exist from a previous transaction even if no tag were touched | |
2047 | # in this one. Changes are recorded in a line base format:: |
|
2047 | # in this one. Changes are recorded in a line base format:: | |
2048 | # |
|
2048 | # | |
2049 | # <action> <hex-node> <tag-name>\n |
|
2049 | # <action> <hex-node> <tag-name>\n | |
2050 | # |
|
2050 | # | |
2051 | # Actions are defined as follow: |
|
2051 | # Actions are defined as follow: | |
2052 | # "-R": tag is removed, |
|
2052 | # "-R": tag is removed, | |
2053 | # "+A": tag is added, |
|
2053 | # "+A": tag is added, | |
2054 | # "-M": tag is moved (old value), |
|
2054 | # "-M": tag is moved (old value), | |
2055 | # "+M": tag is moved (new value), |
|
2055 | # "+M": tag is moved (new value), | |
2056 | tracktags = lambda x: None |
|
2056 | tracktags = lambda x: None | |
2057 | # experimental config: experimental.hook-track-tags |
|
2057 | # experimental config: experimental.hook-track-tags | |
2058 | shouldtracktags = self.ui.configbool( |
|
2058 | shouldtracktags = self.ui.configbool( | |
2059 | b'experimental', b'hook-track-tags' |
|
2059 | b'experimental', b'hook-track-tags' | |
2060 | ) |
|
2060 | ) | |
2061 | if desc != b'strip' and shouldtracktags: |
|
2061 | if desc != b'strip' and shouldtracktags: | |
2062 | oldheads = self.changelog.headrevs() |
|
2062 | oldheads = self.changelog.headrevs() | |
2063 |
|
2063 | |||
2064 | def tracktags(tr2): |
|
2064 | def tracktags(tr2): | |
2065 | repo = reporef() |
|
2065 | repo = reporef() | |
2066 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
2066 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
2067 | newheads = repo.changelog.headrevs() |
|
2067 | newheads = repo.changelog.headrevs() | |
2068 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
2068 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
2069 | # notes: we compare lists here. |
|
2069 | # notes: we compare lists here. | |
2070 | # As we do it only once buiding set would not be cheaper |
|
2070 | # As we do it only once buiding set would not be cheaper | |
2071 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
2071 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
2072 | if changes: |
|
2072 | if changes: | |
2073 | tr2.hookargs[b'tag_moved'] = b'1' |
|
2073 | tr2.hookargs[b'tag_moved'] = b'1' | |
2074 | with repo.vfs( |
|
2074 | with repo.vfs( | |
2075 | b'changes/tags.changes', b'w', atomictemp=True |
|
2075 | b'changes/tags.changes', b'w', atomictemp=True | |
2076 | ) as changesfile: |
|
2076 | ) as changesfile: | |
2077 | # note: we do not register the file to the transaction |
|
2077 | # note: we do not register the file to the transaction | |
2078 | # because we needs it to still exist on the transaction |
|
2078 | # because we needs it to still exist on the transaction | |
2079 | # is close (for txnclose hooks) |
|
2079 | # is close (for txnclose hooks) | |
2080 | tagsmod.writediff(changesfile, changes) |
|
2080 | tagsmod.writediff(changesfile, changes) | |
2081 |
|
2081 | |||
2082 | def validate(tr2): |
|
2082 | def validate(tr2): | |
2083 | """will run pre-closing hooks""" |
|
2083 | """will run pre-closing hooks""" | |
2084 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
2084 | # XXX the transaction API is a bit lacking here so we take a hacky | |
2085 | # path for now |
|
2085 | # path for now | |
2086 | # |
|
2086 | # | |
2087 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
2087 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
2088 | # dict is copied before these run. In addition we needs the data |
|
2088 | # dict is copied before these run. In addition we needs the data | |
2089 | # available to in memory hooks too. |
|
2089 | # available to in memory hooks too. | |
2090 | # |
|
2090 | # | |
2091 | # Moreover, we also need to make sure this runs before txnclose |
|
2091 | # Moreover, we also need to make sure this runs before txnclose | |
2092 | # hooks and there is no "pending" mechanism that would execute |
|
2092 | # hooks and there is no "pending" mechanism that would execute | |
2093 | # logic only if hooks are about to run. |
|
2093 | # logic only if hooks are about to run. | |
2094 | # |
|
2094 | # | |
2095 | # Fixing this limitation of the transaction is also needed to track |
|
2095 | # Fixing this limitation of the transaction is also needed to track | |
2096 | # other families of changes (bookmarks, phases, obsolescence). |
|
2096 | # other families of changes (bookmarks, phases, obsolescence). | |
2097 | # |
|
2097 | # | |
2098 | # This will have to be fixed before we remove the experimental |
|
2098 | # This will have to be fixed before we remove the experimental | |
2099 | # gating. |
|
2099 | # gating. | |
2100 | tracktags(tr2) |
|
2100 | tracktags(tr2) | |
2101 | repo = reporef() |
|
2101 | repo = reporef() | |
2102 |
|
2102 | |||
2103 | singleheadopt = (b'experimental', b'single-head-per-branch') |
|
2103 | singleheadopt = (b'experimental', b'single-head-per-branch') | |
2104 | singlehead = repo.ui.configbool(*singleheadopt) |
|
2104 | singlehead = repo.ui.configbool(*singleheadopt) | |
2105 | if singlehead: |
|
2105 | if singlehead: | |
2106 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] |
|
2106 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] | |
2107 | accountclosed = singleheadsub.get( |
|
2107 | accountclosed = singleheadsub.get( | |
2108 | b"account-closed-heads", False |
|
2108 | b"account-closed-heads", False | |
2109 | ) |
|
2109 | ) | |
2110 | scmutil.enforcesinglehead(repo, tr2, desc, accountclosed) |
|
2110 | scmutil.enforcesinglehead(repo, tr2, desc, accountclosed) | |
2111 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): |
|
2111 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): | |
2112 | for name, (old, new) in sorted( |
|
2112 | for name, (old, new) in sorted( | |
2113 | tr.changes[b'bookmarks'].items() |
|
2113 | tr.changes[b'bookmarks'].items() | |
2114 | ): |
|
2114 | ): | |
2115 | args = tr.hookargs.copy() |
|
2115 | args = tr.hookargs.copy() | |
2116 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2116 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2117 | repo.hook( |
|
2117 | repo.hook( | |
2118 | b'pretxnclose-bookmark', |
|
2118 | b'pretxnclose-bookmark', | |
2119 | throw=True, |
|
2119 | throw=True, | |
2120 | **pycompat.strkwargs(args) |
|
2120 | **pycompat.strkwargs(args) | |
2121 | ) |
|
2121 | ) | |
2122 | if hook.hashook(repo.ui, b'pretxnclose-phase'): |
|
2122 | if hook.hashook(repo.ui, b'pretxnclose-phase'): | |
2123 | cl = repo.unfiltered().changelog |
|
2123 | cl = repo.unfiltered().changelog | |
2124 | for rev, (old, new) in tr.changes[b'phases'].items(): |
|
2124 | for rev, (old, new) in tr.changes[b'phases'].items(): | |
2125 | args = tr.hookargs.copy() |
|
2125 | args = tr.hookargs.copy() | |
2126 | node = hex(cl.node(rev)) |
|
2126 | node = hex(cl.node(rev)) | |
2127 | args.update(phases.preparehookargs(node, old, new)) |
|
2127 | args.update(phases.preparehookargs(node, old, new)) | |
2128 | repo.hook( |
|
2128 | repo.hook( | |
2129 | b'pretxnclose-phase', |
|
2129 | b'pretxnclose-phase', | |
2130 | throw=True, |
|
2130 | throw=True, | |
2131 | **pycompat.strkwargs(args) |
|
2131 | **pycompat.strkwargs(args) | |
2132 | ) |
|
2132 | ) | |
2133 |
|
2133 | |||
2134 | repo.hook( |
|
2134 | repo.hook( | |
2135 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) |
|
2135 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) | |
2136 | ) |
|
2136 | ) | |
2137 |
|
2137 | |||
2138 | def releasefn(tr, success): |
|
2138 | def releasefn(tr, success): | |
2139 | repo = reporef() |
|
2139 | repo = reporef() | |
2140 | if repo is None: |
|
2140 | if repo is None: | |
2141 | # If the repo has been GC'd (and this release function is being |
|
2141 | # If the repo has been GC'd (and this release function is being | |
2142 | # called from transaction.__del__), there's not much we can do, |
|
2142 | # called from transaction.__del__), there's not much we can do, | |
2143 | # so just leave the unfinished transaction there and let the |
|
2143 | # so just leave the unfinished transaction there and let the | |
2144 | # user run `hg recover`. |
|
2144 | # user run `hg recover`. | |
2145 | return |
|
2145 | return | |
2146 | if success: |
|
2146 | if success: | |
2147 | # this should be explicitly invoked here, because |
|
2147 | # this should be explicitly invoked here, because | |
2148 | # in-memory changes aren't written out at closing |
|
2148 | # in-memory changes aren't written out at closing | |
2149 | # transaction, if tr.addfilegenerator (via |
|
2149 | # transaction, if tr.addfilegenerator (via | |
2150 | # dirstate.write or so) isn't invoked while |
|
2150 | # dirstate.write or so) isn't invoked while | |
2151 | # transaction running |
|
2151 | # transaction running | |
2152 | repo.dirstate.write(None) |
|
2152 | repo.dirstate.write(None) | |
2153 | else: |
|
2153 | else: | |
2154 | # discard all changes (including ones already written |
|
2154 | # discard all changes (including ones already written | |
2155 | # out) in this transaction |
|
2155 | # out) in this transaction | |
2156 | narrowspec.restorebackup(self, b'journal.narrowspec') |
|
2156 | narrowspec.restorebackup(self, b'journal.narrowspec') | |
2157 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') |
|
2157 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') | |
2158 | repo.dirstate.restorebackup(None, b'journal.dirstate') |
|
2158 | repo.dirstate.restorebackup(None, b'journal.dirstate') | |
2159 |
|
2159 | |||
2160 | repo.invalidate(clearfilecache=True) |
|
2160 | repo.invalidate(clearfilecache=True) | |
2161 |
|
2161 | |||
2162 | tr = transaction.transaction( |
|
2162 | tr = transaction.transaction( | |
2163 | rp, |
|
2163 | rp, | |
2164 | self.svfs, |
|
2164 | self.svfs, | |
2165 | vfsmap, |
|
2165 | vfsmap, | |
2166 | b"journal", |
|
2166 | b"journal", | |
2167 | b"undo", |
|
2167 | b"undo", | |
2168 | aftertrans(renames), |
|
2168 | aftertrans(renames), | |
2169 | self.store.createmode, |
|
2169 | self.store.createmode, | |
2170 | validator=validate, |
|
2170 | validator=validate, | |
2171 | releasefn=releasefn, |
|
2171 | releasefn=releasefn, | |
2172 | checkambigfiles=_cachedfiles, |
|
2172 | checkambigfiles=_cachedfiles, | |
2173 | name=desc, |
|
2173 | name=desc, | |
2174 | ) |
|
2174 | ) | |
2175 | tr.changes[b'origrepolen'] = len(self) |
|
2175 | tr.changes[b'origrepolen'] = len(self) | |
2176 | tr.changes[b'obsmarkers'] = set() |
|
2176 | tr.changes[b'obsmarkers'] = set() | |
2177 | tr.changes[b'phases'] = {} |
|
2177 | tr.changes[b'phases'] = {} | |
2178 | tr.changes[b'bookmarks'] = {} |
|
2178 | tr.changes[b'bookmarks'] = {} | |
2179 |
|
2179 | |||
2180 | tr.hookargs[b'txnid'] = txnid |
|
2180 | tr.hookargs[b'txnid'] = txnid | |
2181 | tr.hookargs[b'txnname'] = desc |
|
2181 | tr.hookargs[b'txnname'] = desc | |
2182 | # note: writing the fncache only during finalize mean that the file is |
|
2182 | # note: writing the fncache only during finalize mean that the file is | |
2183 | # outdated when running hooks. As fncache is used for streaming clone, |
|
2183 | # outdated when running hooks. As fncache is used for streaming clone, | |
2184 | # this is not expected to break anything that happen during the hooks. |
|
2184 | # this is not expected to break anything that happen during the hooks. | |
2185 | tr.addfinalize(b'flush-fncache', self.store.write) |
|
2185 | tr.addfinalize(b'flush-fncache', self.store.write) | |
2186 |
|
2186 | |||
2187 | def txnclosehook(tr2): |
|
2187 | def txnclosehook(tr2): | |
2188 | """To be run if transaction is successful, will schedule a hook run |
|
2188 | """To be run if transaction is successful, will schedule a hook run | |
2189 | """ |
|
2189 | """ | |
2190 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
2190 | # Don't reference tr2 in hook() so we don't hold a reference. | |
2191 | # This reduces memory consumption when there are multiple |
|
2191 | # This reduces memory consumption when there are multiple | |
2192 | # transactions per lock. This can likely go away if issue5045 |
|
2192 | # transactions per lock. This can likely go away if issue5045 | |
2193 | # fixes the function accumulation. |
|
2193 | # fixes the function accumulation. | |
2194 | hookargs = tr2.hookargs |
|
2194 | hookargs = tr2.hookargs | |
2195 |
|
2195 | |||
2196 | def hookfunc(unused_success): |
|
2196 | def hookfunc(unused_success): | |
2197 | repo = reporef() |
|
2197 | repo = reporef() | |
2198 | if hook.hashook(repo.ui, b'txnclose-bookmark'): |
|
2198 | if hook.hashook(repo.ui, b'txnclose-bookmark'): | |
2199 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) |
|
2199 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) | |
2200 | for name, (old, new) in bmchanges: |
|
2200 | for name, (old, new) in bmchanges: | |
2201 | args = tr.hookargs.copy() |
|
2201 | args = tr.hookargs.copy() | |
2202 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2202 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2203 | repo.hook( |
|
2203 | repo.hook( | |
2204 | b'txnclose-bookmark', |
|
2204 | b'txnclose-bookmark', | |
2205 | throw=False, |
|
2205 | throw=False, | |
2206 | **pycompat.strkwargs(args) |
|
2206 | **pycompat.strkwargs(args) | |
2207 | ) |
|
2207 | ) | |
2208 |
|
2208 | |||
2209 | if hook.hashook(repo.ui, b'txnclose-phase'): |
|
2209 | if hook.hashook(repo.ui, b'txnclose-phase'): | |
2210 | cl = repo.unfiltered().changelog |
|
2210 | cl = repo.unfiltered().changelog | |
2211 | phasemv = sorted(tr.changes[b'phases'].items()) |
|
2211 | phasemv = sorted(tr.changes[b'phases'].items()) | |
2212 | for rev, (old, new) in phasemv: |
|
2212 | for rev, (old, new) in phasemv: | |
2213 | args = tr.hookargs.copy() |
|
2213 | args = tr.hookargs.copy() | |
2214 | node = hex(cl.node(rev)) |
|
2214 | node = hex(cl.node(rev)) | |
2215 | args.update(phases.preparehookargs(node, old, new)) |
|
2215 | args.update(phases.preparehookargs(node, old, new)) | |
2216 | repo.hook( |
|
2216 | repo.hook( | |
2217 | b'txnclose-phase', |
|
2217 | b'txnclose-phase', | |
2218 | throw=False, |
|
2218 | throw=False, | |
2219 | **pycompat.strkwargs(args) |
|
2219 | **pycompat.strkwargs(args) | |
2220 | ) |
|
2220 | ) | |
2221 |
|
2221 | |||
2222 | repo.hook( |
|
2222 | repo.hook( | |
2223 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) |
|
2223 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) | |
2224 | ) |
|
2224 | ) | |
2225 |
|
2225 | |||
2226 | reporef()._afterlock(hookfunc) |
|
2226 | reporef()._afterlock(hookfunc) | |
2227 |
|
2227 | |||
2228 | tr.addfinalize(b'txnclose-hook', txnclosehook) |
|
2228 | tr.addfinalize(b'txnclose-hook', txnclosehook) | |
2229 | # Include a leading "-" to make it happen before the transaction summary |
|
2229 | # Include a leading "-" to make it happen before the transaction summary | |
2230 | # reports registered via scmutil.registersummarycallback() whose names |
|
2230 | # reports registered via scmutil.registersummarycallback() whose names | |
2231 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
2231 | # are 00-txnreport etc. That way, the caches will be warm when the | |
2232 | # callbacks run. |
|
2232 | # callbacks run. | |
2233 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) |
|
2233 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) | |
2234 |
|
2234 | |||
2235 | def txnaborthook(tr2): |
|
2235 | def txnaborthook(tr2): | |
2236 | """To be run if transaction is aborted |
|
2236 | """To be run if transaction is aborted | |
2237 | """ |
|
2237 | """ | |
2238 | reporef().hook( |
|
2238 | reporef().hook( | |
2239 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) |
|
2239 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) | |
2240 | ) |
|
2240 | ) | |
2241 |
|
2241 | |||
2242 | tr.addabort(b'txnabort-hook', txnaborthook) |
|
2242 | tr.addabort(b'txnabort-hook', txnaborthook) | |
2243 | # avoid eager cache invalidation. in-memory data should be identical |
|
2243 | # avoid eager cache invalidation. in-memory data should be identical | |
2244 | # to stored data if transaction has no error. |
|
2244 | # to stored data if transaction has no error. | |
2245 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) |
|
2245 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) | |
2246 | self._transref = weakref.ref(tr) |
|
2246 | self._transref = weakref.ref(tr) | |
2247 | scmutil.registersummarycallback(self, tr, desc) |
|
2247 | scmutil.registersummarycallback(self, tr, desc) | |
2248 | return tr |
|
2248 | return tr | |
2249 |
|
2249 | |||
2250 | def _journalfiles(self): |
|
2250 | def _journalfiles(self): | |
2251 | return ( |
|
2251 | return ( | |
2252 | (self.svfs, b'journal'), |
|
2252 | (self.svfs, b'journal'), | |
2253 | (self.svfs, b'journal.narrowspec'), |
|
2253 | (self.svfs, b'journal.narrowspec'), | |
2254 | (self.vfs, b'journal.narrowspec.dirstate'), |
|
2254 | (self.vfs, b'journal.narrowspec.dirstate'), | |
2255 | (self.vfs, b'journal.dirstate'), |
|
2255 | (self.vfs, b'journal.dirstate'), | |
2256 | (self.vfs, b'journal.branch'), |
|
2256 | (self.vfs, b'journal.branch'), | |
2257 | (self.vfs, b'journal.desc'), |
|
2257 | (self.vfs, b'journal.desc'), | |
2258 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), |
|
2258 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), | |
2259 | (self.svfs, b'journal.phaseroots'), |
|
2259 | (self.svfs, b'journal.phaseroots'), | |
2260 | ) |
|
2260 | ) | |
2261 |
|
2261 | |||
2262 | def undofiles(self): |
|
2262 | def undofiles(self): | |
2263 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
2263 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
2264 |
|
2264 | |||
2265 | @unfilteredmethod |
|
2265 | @unfilteredmethod | |
2266 | def _writejournal(self, desc): |
|
2266 | def _writejournal(self, desc): | |
2267 | self.dirstate.savebackup(None, b'journal.dirstate') |
|
2267 | self.dirstate.savebackup(None, b'journal.dirstate') | |
2268 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') |
|
2268 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') | |
2269 | narrowspec.savebackup(self, b'journal.narrowspec') |
|
2269 | narrowspec.savebackup(self, b'journal.narrowspec') | |
2270 | self.vfs.write( |
|
2270 | self.vfs.write( | |
2271 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) |
|
2271 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) | |
2272 | ) |
|
2272 | ) | |
2273 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) |
|
2273 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) | |
2274 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2274 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2275 | bookmarksvfs.write( |
|
2275 | bookmarksvfs.write( | |
2276 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") |
|
2276 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") | |
2277 | ) |
|
2277 | ) | |
2278 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) |
|
2278 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) | |
2279 |
|
2279 | |||
2280 | def recover(self): |
|
2280 | def recover(self): | |
2281 | with self.lock(): |
|
2281 | with self.lock(): | |
2282 | if self.svfs.exists(b"journal"): |
|
2282 | if self.svfs.exists(b"journal"): | |
2283 | self.ui.status(_(b"rolling back interrupted transaction\n")) |
|
2283 | self.ui.status(_(b"rolling back interrupted transaction\n")) | |
2284 | vfsmap = { |
|
2284 | vfsmap = { | |
2285 | b'': self.svfs, |
|
2285 | b'': self.svfs, | |
2286 | b'plain': self.vfs, |
|
2286 | b'plain': self.vfs, | |
2287 | } |
|
2287 | } | |
2288 | transaction.rollback( |
|
2288 | transaction.rollback( | |
2289 | self.svfs, |
|
2289 | self.svfs, | |
2290 | vfsmap, |
|
2290 | vfsmap, | |
2291 | b"journal", |
|
2291 | b"journal", | |
2292 | self.ui.warn, |
|
2292 | self.ui.warn, | |
2293 | checkambigfiles=_cachedfiles, |
|
2293 | checkambigfiles=_cachedfiles, | |
2294 | ) |
|
2294 | ) | |
2295 | self.invalidate() |
|
2295 | self.invalidate() | |
2296 | return True |
|
2296 | return True | |
2297 | else: |
|
2297 | else: | |
2298 | self.ui.warn(_(b"no interrupted transaction available\n")) |
|
2298 | self.ui.warn(_(b"no interrupted transaction available\n")) | |
2299 | return False |
|
2299 | return False | |
2300 |
|
2300 | |||
2301 | def rollback(self, dryrun=False, force=False): |
|
2301 | def rollback(self, dryrun=False, force=False): | |
2302 | wlock = lock = dsguard = None |
|
2302 | wlock = lock = dsguard = None | |
2303 | try: |
|
2303 | try: | |
2304 | wlock = self.wlock() |
|
2304 | wlock = self.wlock() | |
2305 | lock = self.lock() |
|
2305 | lock = self.lock() | |
2306 | if self.svfs.exists(b"undo"): |
|
2306 | if self.svfs.exists(b"undo"): | |
2307 | dsguard = dirstateguard.dirstateguard(self, b'rollback') |
|
2307 | dsguard = dirstateguard.dirstateguard(self, b'rollback') | |
2308 |
|
2308 | |||
2309 | return self._rollback(dryrun, force, dsguard) |
|
2309 | return self._rollback(dryrun, force, dsguard) | |
2310 | else: |
|
2310 | else: | |
2311 | self.ui.warn(_(b"no rollback information available\n")) |
|
2311 | self.ui.warn(_(b"no rollback information available\n")) | |
2312 | return 1 |
|
2312 | return 1 | |
2313 | finally: |
|
2313 | finally: | |
2314 | release(dsguard, lock, wlock) |
|
2314 | release(dsguard, lock, wlock) | |
2315 |
|
2315 | |||
2316 | @unfilteredmethod # Until we get smarter cache management |
|
2316 | @unfilteredmethod # Until we get smarter cache management | |
2317 | def _rollback(self, dryrun, force, dsguard): |
|
2317 | def _rollback(self, dryrun, force, dsguard): | |
2318 | ui = self.ui |
|
2318 | ui = self.ui | |
2319 | try: |
|
2319 | try: | |
2320 | args = self.vfs.read(b'undo.desc').splitlines() |
|
2320 | args = self.vfs.read(b'undo.desc').splitlines() | |
2321 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
2321 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
2322 | if len(args) >= 3: |
|
2322 | if len(args) >= 3: | |
2323 | detail = args[2] |
|
2323 | detail = args[2] | |
2324 | oldtip = oldlen - 1 |
|
2324 | oldtip = oldlen - 1 | |
2325 |
|
2325 | |||
2326 | if detail and ui.verbose: |
|
2326 | if detail and ui.verbose: | |
2327 | msg = _( |
|
2327 | msg = _( | |
2328 | b'repository tip rolled back to revision %d' |
|
2328 | b'repository tip rolled back to revision %d' | |
2329 | b' (undo %s: %s)\n' |
|
2329 | b' (undo %s: %s)\n' | |
2330 | ) % (oldtip, desc, detail) |
|
2330 | ) % (oldtip, desc, detail) | |
2331 | else: |
|
2331 | else: | |
2332 | msg = _( |
|
2332 | msg = _( | |
2333 | b'repository tip rolled back to revision %d (undo %s)\n' |
|
2333 | b'repository tip rolled back to revision %d (undo %s)\n' | |
2334 | ) % (oldtip, desc) |
|
2334 | ) % (oldtip, desc) | |
2335 | except IOError: |
|
2335 | except IOError: | |
2336 | msg = _(b'rolling back unknown transaction\n') |
|
2336 | msg = _(b'rolling back unknown transaction\n') | |
2337 | desc = None |
|
2337 | desc = None | |
2338 |
|
2338 | |||
2339 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': |
|
2339 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': | |
2340 | raise error.Abort( |
|
2340 | raise error.Abort( | |
2341 | _( |
|
2341 | _( | |
2342 | b'rollback of last commit while not checked out ' |
|
2342 | b'rollback of last commit while not checked out ' | |
2343 | b'may lose data' |
|
2343 | b'may lose data' | |
2344 | ), |
|
2344 | ), | |
2345 | hint=_(b'use -f to force'), |
|
2345 | hint=_(b'use -f to force'), | |
2346 | ) |
|
2346 | ) | |
2347 |
|
2347 | |||
2348 | ui.status(msg) |
|
2348 | ui.status(msg) | |
2349 | if dryrun: |
|
2349 | if dryrun: | |
2350 | return 0 |
|
2350 | return 0 | |
2351 |
|
2351 | |||
2352 | parents = self.dirstate.parents() |
|
2352 | parents = self.dirstate.parents() | |
2353 | self.destroying() |
|
2353 | self.destroying() | |
2354 | vfsmap = {b'plain': self.vfs, b'': self.svfs} |
|
2354 | vfsmap = {b'plain': self.vfs, b'': self.svfs} | |
2355 | transaction.rollback( |
|
2355 | transaction.rollback( | |
2356 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles |
|
2356 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles | |
2357 | ) |
|
2357 | ) | |
2358 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2358 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2359 | if bookmarksvfs.exists(b'undo.bookmarks'): |
|
2359 | if bookmarksvfs.exists(b'undo.bookmarks'): | |
2360 | bookmarksvfs.rename( |
|
2360 | bookmarksvfs.rename( | |
2361 | b'undo.bookmarks', b'bookmarks', checkambig=True |
|
2361 | b'undo.bookmarks', b'bookmarks', checkambig=True | |
2362 | ) |
|
2362 | ) | |
2363 | if self.svfs.exists(b'undo.phaseroots'): |
|
2363 | if self.svfs.exists(b'undo.phaseroots'): | |
2364 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) |
|
2364 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) | |
2365 | self.invalidate() |
|
2365 | self.invalidate() | |
2366 |
|
2366 | |||
2367 | has_node = self.changelog.index.has_node |
|
2367 | has_node = self.changelog.index.has_node | |
2368 | parentgone = any(not has_node(p) for p in parents) |
|
2368 | parentgone = any(not has_node(p) for p in parents) | |
2369 | if parentgone: |
|
2369 | if parentgone: | |
2370 | # prevent dirstateguard from overwriting already restored one |
|
2370 | # prevent dirstateguard from overwriting already restored one | |
2371 | dsguard.close() |
|
2371 | dsguard.close() | |
2372 |
|
2372 | |||
2373 | narrowspec.restorebackup(self, b'undo.narrowspec') |
|
2373 | narrowspec.restorebackup(self, b'undo.narrowspec') | |
2374 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') |
|
2374 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') | |
2375 | self.dirstate.restorebackup(None, b'undo.dirstate') |
|
2375 | self.dirstate.restorebackup(None, b'undo.dirstate') | |
2376 | try: |
|
2376 | try: | |
2377 | branch = self.vfs.read(b'undo.branch') |
|
2377 | branch = self.vfs.read(b'undo.branch') | |
2378 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
2378 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
2379 | except IOError: |
|
2379 | except IOError: | |
2380 | ui.warn( |
|
2380 | ui.warn( | |
2381 | _( |
|
2381 | _( | |
2382 | b'named branch could not be reset: ' |
|
2382 | b'named branch could not be reset: ' | |
2383 | b'current branch is still \'%s\'\n' |
|
2383 | b'current branch is still \'%s\'\n' | |
2384 | ) |
|
2384 | ) | |
2385 | % self.dirstate.branch() |
|
2385 | % self.dirstate.branch() | |
2386 | ) |
|
2386 | ) | |
2387 |
|
2387 | |||
2388 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
2388 | parents = tuple([p.rev() for p in self[None].parents()]) | |
2389 | if len(parents) > 1: |
|
2389 | if len(parents) > 1: | |
2390 | ui.status( |
|
2390 | ui.status( | |
2391 | _( |
|
2391 | _( | |
2392 | b'working directory now based on ' |
|
2392 | b'working directory now based on ' | |
2393 | b'revisions %d and %d\n' |
|
2393 | b'revisions %d and %d\n' | |
2394 | ) |
|
2394 | ) | |
2395 | % parents |
|
2395 | % parents | |
2396 | ) |
|
2396 | ) | |
2397 | else: |
|
2397 | else: | |
2398 | ui.status( |
|
2398 | ui.status( | |
2399 | _(b'working directory now based on revision %d\n') % parents |
|
2399 | _(b'working directory now based on revision %d\n') % parents | |
2400 | ) |
|
2400 | ) | |
2401 | mergemod.mergestate.clean(self, self[b'.'].node()) |
|
2401 | mergemod.mergestate.clean(self, self[b'.'].node()) | |
2402 |
|
2402 | |||
2403 | # TODO: if we know which new heads may result from this rollback, pass |
|
2403 | # TODO: if we know which new heads may result from this rollback, pass | |
2404 | # them to destroy(), which will prevent the branchhead cache from being |
|
2404 | # them to destroy(), which will prevent the branchhead cache from being | |
2405 | # invalidated. |
|
2405 | # invalidated. | |
2406 | self.destroyed() |
|
2406 | self.destroyed() | |
2407 | return 0 |
|
2407 | return 0 | |
2408 |
|
2408 | |||
2409 | def _buildcacheupdater(self, newtransaction): |
|
2409 | def _buildcacheupdater(self, newtransaction): | |
2410 | """called during transaction to build the callback updating cache |
|
2410 | """called during transaction to build the callback updating cache | |
2411 |
|
2411 | |||
2412 | Lives on the repository to help extension who might want to augment |
|
2412 | Lives on the repository to help extension who might want to augment | |
2413 | this logic. For this purpose, the created transaction is passed to the |
|
2413 | this logic. For this purpose, the created transaction is passed to the | |
2414 | method. |
|
2414 | method. | |
2415 | """ |
|
2415 | """ | |
2416 | # we must avoid cyclic reference between repo and transaction. |
|
2416 | # we must avoid cyclic reference between repo and transaction. | |
2417 | reporef = weakref.ref(self) |
|
2417 | reporef = weakref.ref(self) | |
2418 |
|
2418 | |||
2419 | def updater(tr): |
|
2419 | def updater(tr): | |
2420 | repo = reporef() |
|
2420 | repo = reporef() | |
2421 | repo.updatecaches(tr) |
|
2421 | repo.updatecaches(tr) | |
2422 |
|
2422 | |||
2423 | return updater |
|
2423 | return updater | |
2424 |
|
2424 | |||
2425 | @unfilteredmethod |
|
2425 | @unfilteredmethod | |
2426 | def updatecaches(self, tr=None, full=False): |
|
2426 | def updatecaches(self, tr=None, full=False): | |
2427 | """warm appropriate caches |
|
2427 | """warm appropriate caches | |
2428 |
|
2428 | |||
2429 | If this function is called after a transaction closed. The transaction |
|
2429 | If this function is called after a transaction closed. The transaction | |
2430 | will be available in the 'tr' argument. This can be used to selectively |
|
2430 | will be available in the 'tr' argument. This can be used to selectively | |
2431 | update caches relevant to the changes in that transaction. |
|
2431 | update caches relevant to the changes in that transaction. | |
2432 |
|
2432 | |||
2433 | If 'full' is set, make sure all caches the function knows about have |
|
2433 | If 'full' is set, make sure all caches the function knows about have | |
2434 | up-to-date data. Even the ones usually loaded more lazily. |
|
2434 | up-to-date data. Even the ones usually loaded more lazily. | |
2435 | """ |
|
2435 | """ | |
2436 | if tr is not None and tr.hookargs.get(b'source') == b'strip': |
|
2436 | if tr is not None and tr.hookargs.get(b'source') == b'strip': | |
2437 | # During strip, many caches are invalid but |
|
2437 | # During strip, many caches are invalid but | |
2438 | # later call to `destroyed` will refresh them. |
|
2438 | # later call to `destroyed` will refresh them. | |
2439 | return |
|
2439 | return | |
2440 |
|
2440 | |||
2441 | if tr is None or tr.changes[b'origrepolen'] < len(self): |
|
2441 | if tr is None or tr.changes[b'origrepolen'] < len(self): | |
2442 | # accessing the 'ser ved' branchmap should refresh all the others, |
|
2442 | # accessing the 'ser ved' branchmap should refresh all the others, | |
2443 | self.ui.debug(b'updating the branch cache\n') |
|
2443 | self.ui.debug(b'updating the branch cache\n') | |
2444 | self.filtered(b'served').branchmap() |
|
2444 | self.filtered(b'served').branchmap() | |
2445 | self.filtered(b'served.hidden').branchmap() |
|
2445 | self.filtered(b'served.hidden').branchmap() | |
2446 |
|
2446 | |||
2447 | if full: |
|
2447 | if full: | |
2448 | unfi = self.unfiltered() |
|
2448 | unfi = self.unfiltered() | |
2449 | rbc = unfi.revbranchcache() |
|
2449 | rbc = unfi.revbranchcache() | |
2450 | for r in unfi.changelog: |
|
2450 | for r in unfi.changelog: | |
2451 | rbc.branchinfo(r) |
|
2451 | rbc.branchinfo(r) | |
2452 | rbc.write() |
|
2452 | rbc.write() | |
2453 |
|
2453 | |||
2454 | # ensure the working copy parents are in the manifestfulltextcache |
|
2454 | # ensure the working copy parents are in the manifestfulltextcache | |
2455 | for ctx in self[b'.'].parents(): |
|
2455 | for ctx in self[b'.'].parents(): | |
2456 | ctx.manifest() # accessing the manifest is enough |
|
2456 | ctx.manifest() # accessing the manifest is enough | |
2457 |
|
2457 | |||
2458 | # accessing fnode cache warms the cache |
|
2458 | # accessing fnode cache warms the cache | |
2459 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) |
|
2459 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) | |
2460 | # accessing tags warm the cache |
|
2460 | # accessing tags warm the cache | |
2461 | self.tags() |
|
2461 | self.tags() | |
2462 | self.filtered(b'served').tags() |
|
2462 | self.filtered(b'served').tags() | |
2463 |
|
2463 | |||
2464 | # The `full` arg is documented as updating even the lazily-loaded |
|
2464 | # The `full` arg is documented as updating even the lazily-loaded | |
2465 | # caches immediately, so we're forcing a write to cause these caches |
|
2465 | # caches immediately, so we're forcing a write to cause these caches | |
2466 | # to be warmed up even if they haven't explicitly been requested |
|
2466 | # to be warmed up even if they haven't explicitly been requested | |
2467 | # yet (if they've never been used by hg, they won't ever have been |
|
2467 | # yet (if they've never been used by hg, they won't ever have been | |
2468 | # written, even if they're a subset of another kind of cache that |
|
2468 | # written, even if they're a subset of another kind of cache that | |
2469 | # *has* been used). |
|
2469 | # *has* been used). | |
2470 | for filt in repoview.filtertable.keys(): |
|
2470 | for filt in repoview.filtertable.keys(): | |
2471 | filtered = self.filtered(filt) |
|
2471 | filtered = self.filtered(filt) | |
2472 | filtered.branchmap().write(filtered) |
|
2472 | filtered.branchmap().write(filtered) | |
2473 |
|
2473 | |||
2474 | def invalidatecaches(self): |
|
2474 | def invalidatecaches(self): | |
2475 |
|
2475 | |||
2476 | if '_tagscache' in vars(self): |
|
2476 | if '_tagscache' in vars(self): | |
2477 | # can't use delattr on proxy |
|
2477 | # can't use delattr on proxy | |
2478 | del self.__dict__['_tagscache'] |
|
2478 | del self.__dict__['_tagscache'] | |
2479 |
|
2479 | |||
2480 | self._branchcaches.clear() |
|
2480 | self._branchcaches.clear() | |
2481 | self.invalidatevolatilesets() |
|
2481 | self.invalidatevolatilesets() | |
2482 | self._sparsesignaturecache.clear() |
|
2482 | self._sparsesignaturecache.clear() | |
2483 |
|
2483 | |||
2484 | def invalidatevolatilesets(self): |
|
2484 | def invalidatevolatilesets(self): | |
2485 | self.filteredrevcache.clear() |
|
2485 | self.filteredrevcache.clear() | |
2486 | obsolete.clearobscaches(self) |
|
2486 | obsolete.clearobscaches(self) | |
2487 |
|
2487 | |||
2488 | def invalidatedirstate(self): |
|
2488 | def invalidatedirstate(self): | |
2489 | '''Invalidates the dirstate, causing the next call to dirstate |
|
2489 | '''Invalidates the dirstate, causing the next call to dirstate | |
2490 | to check if it was modified since the last time it was read, |
|
2490 | to check if it was modified since the last time it was read, | |
2491 | rereading it if it has. |
|
2491 | rereading it if it has. | |
2492 |
|
2492 | |||
2493 | This is different to dirstate.invalidate() that it doesn't always |
|
2493 | This is different to dirstate.invalidate() that it doesn't always | |
2494 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
2494 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
2495 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
2495 | explicitly read the dirstate again (i.e. restoring it to a previous | |
2496 | known good state).''' |
|
2496 | known good state).''' | |
2497 | if hasunfilteredcache(self, 'dirstate'): |
|
2497 | if hasunfilteredcache(self, 'dirstate'): | |
2498 | for k in self.dirstate._filecache: |
|
2498 | for k in self.dirstate._filecache: | |
2499 | try: |
|
2499 | try: | |
2500 | delattr(self.dirstate, k) |
|
2500 | delattr(self.dirstate, k) | |
2501 | except AttributeError: |
|
2501 | except AttributeError: | |
2502 | pass |
|
2502 | pass | |
2503 | delattr(self.unfiltered(), 'dirstate') |
|
2503 | delattr(self.unfiltered(), 'dirstate') | |
2504 |
|
2504 | |||
2505 | def invalidate(self, clearfilecache=False): |
|
2505 | def invalidate(self, clearfilecache=False): | |
2506 | '''Invalidates both store and non-store parts other than dirstate |
|
2506 | '''Invalidates both store and non-store parts other than dirstate | |
2507 |
|
2507 | |||
2508 | If a transaction is running, invalidation of store is omitted, |
|
2508 | If a transaction is running, invalidation of store is omitted, | |
2509 | because discarding in-memory changes might cause inconsistency |
|
2509 | because discarding in-memory changes might cause inconsistency | |
2510 | (e.g. incomplete fncache causes unintentional failure, but |
|
2510 | (e.g. incomplete fncache causes unintentional failure, but | |
2511 | redundant one doesn't). |
|
2511 | redundant one doesn't). | |
2512 | ''' |
|
2512 | ''' | |
2513 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
2513 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
2514 | for k in list(self._filecache.keys()): |
|
2514 | for k in list(self._filecache.keys()): | |
2515 | # dirstate is invalidated separately in invalidatedirstate() |
|
2515 | # dirstate is invalidated separately in invalidatedirstate() | |
2516 | if k == b'dirstate': |
|
2516 | if k == b'dirstate': | |
2517 | continue |
|
2517 | continue | |
2518 | if ( |
|
2518 | if ( | |
2519 | k == b'changelog' |
|
2519 | k == b'changelog' | |
2520 | and self.currenttransaction() |
|
2520 | and self.currenttransaction() | |
2521 | and self.changelog._delayed |
|
2521 | and self.changelog._delayed | |
2522 | ): |
|
2522 | ): | |
2523 | # The changelog object may store unwritten revisions. We don't |
|
2523 | # The changelog object may store unwritten revisions. We don't | |
2524 | # want to lose them. |
|
2524 | # want to lose them. | |
2525 | # TODO: Solve the problem instead of working around it. |
|
2525 | # TODO: Solve the problem instead of working around it. | |
2526 | continue |
|
2526 | continue | |
2527 |
|
2527 | |||
2528 | if clearfilecache: |
|
2528 | if clearfilecache: | |
2529 | del self._filecache[k] |
|
2529 | del self._filecache[k] | |
2530 | try: |
|
2530 | try: | |
2531 | delattr(unfiltered, k) |
|
2531 | delattr(unfiltered, k) | |
2532 | except AttributeError: |
|
2532 | except AttributeError: | |
2533 | pass |
|
2533 | pass | |
2534 | self.invalidatecaches() |
|
2534 | self.invalidatecaches() | |
2535 | if not self.currenttransaction(): |
|
2535 | if not self.currenttransaction(): | |
2536 | # TODO: Changing contents of store outside transaction |
|
2536 | # TODO: Changing contents of store outside transaction | |
2537 | # causes inconsistency. We should make in-memory store |
|
2537 | # causes inconsistency. We should make in-memory store | |
2538 | # changes detectable, and abort if changed. |
|
2538 | # changes detectable, and abort if changed. | |
2539 | self.store.invalidatecaches() |
|
2539 | self.store.invalidatecaches() | |
2540 |
|
2540 | |||
2541 | def invalidateall(self): |
|
2541 | def invalidateall(self): | |
2542 | '''Fully invalidates both store and non-store parts, causing the |
|
2542 | '''Fully invalidates both store and non-store parts, causing the | |
2543 | subsequent operation to reread any outside changes.''' |
|
2543 | subsequent operation to reread any outside changes.''' | |
2544 | # extension should hook this to invalidate its caches |
|
2544 | # extension should hook this to invalidate its caches | |
2545 | self.invalidate() |
|
2545 | self.invalidate() | |
2546 | self.invalidatedirstate() |
|
2546 | self.invalidatedirstate() | |
2547 |
|
2547 | |||
2548 | @unfilteredmethod |
|
2548 | @unfilteredmethod | |
2549 | def _refreshfilecachestats(self, tr): |
|
2549 | def _refreshfilecachestats(self, tr): | |
2550 | """Reload stats of cached files so that they are flagged as valid""" |
|
2550 | """Reload stats of cached files so that they are flagged as valid""" | |
2551 | for k, ce in self._filecache.items(): |
|
2551 | for k, ce in self._filecache.items(): | |
2552 | k = pycompat.sysstr(k) |
|
2552 | k = pycompat.sysstr(k) | |
2553 | if k == 'dirstate' or k not in self.__dict__: |
|
2553 | if k == 'dirstate' or k not in self.__dict__: | |
2554 | continue |
|
2554 | continue | |
2555 | ce.refresh() |
|
2555 | ce.refresh() | |
2556 |
|
2556 | |||
2557 | def _lock( |
|
2557 | def _lock( | |
2558 | self, |
|
2558 | self, | |
2559 | vfs, |
|
2559 | vfs, | |
2560 | lockname, |
|
2560 | lockname, | |
2561 | wait, |
|
2561 | wait, | |
2562 | releasefn, |
|
2562 | releasefn, | |
2563 | acquirefn, |
|
2563 | acquirefn, | |
2564 | desc, |
|
2564 | desc, | |
2565 | inheritchecker=None, |
|
2565 | inheritchecker=None, | |
2566 | parentenvvar=None, |
|
2566 | parentenvvar=None, | |
2567 | ): |
|
2567 | ): | |
2568 | parentlock = None |
|
2568 | parentlock = None | |
2569 | # the contents of parentenvvar are used by the underlying lock to |
|
2569 | # the contents of parentenvvar are used by the underlying lock to | |
2570 | # determine whether it can be inherited |
|
2570 | # determine whether it can be inherited | |
2571 | if parentenvvar is not None: |
|
2571 | if parentenvvar is not None: | |
2572 | parentlock = encoding.environ.get(parentenvvar) |
|
2572 | parentlock = encoding.environ.get(parentenvvar) | |
2573 |
|
2573 | |||
2574 | timeout = 0 |
|
2574 | timeout = 0 | |
2575 | warntimeout = 0 |
|
2575 | warntimeout = 0 | |
2576 | if wait: |
|
2576 | if wait: | |
2577 | timeout = self.ui.configint(b"ui", b"timeout") |
|
2577 | timeout = self.ui.configint(b"ui", b"timeout") | |
2578 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") |
|
2578 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") | |
2579 | # internal config: ui.signal-safe-lock |
|
2579 | # internal config: ui.signal-safe-lock | |
2580 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') |
|
2580 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') | |
2581 |
|
2581 | |||
2582 | l = lockmod.trylock( |
|
2582 | l = lockmod.trylock( | |
2583 | self.ui, |
|
2583 | self.ui, | |
2584 | vfs, |
|
2584 | vfs, | |
2585 | lockname, |
|
2585 | lockname, | |
2586 | timeout, |
|
2586 | timeout, | |
2587 | warntimeout, |
|
2587 | warntimeout, | |
2588 | releasefn=releasefn, |
|
2588 | releasefn=releasefn, | |
2589 | acquirefn=acquirefn, |
|
2589 | acquirefn=acquirefn, | |
2590 | desc=desc, |
|
2590 | desc=desc, | |
2591 | inheritchecker=inheritchecker, |
|
2591 | inheritchecker=inheritchecker, | |
2592 | parentlock=parentlock, |
|
2592 | parentlock=parentlock, | |
2593 | signalsafe=signalsafe, |
|
2593 | signalsafe=signalsafe, | |
2594 | ) |
|
2594 | ) | |
2595 | return l |
|
2595 | return l | |
2596 |
|
2596 | |||
2597 | def _afterlock(self, callback): |
|
2597 | def _afterlock(self, callback): | |
2598 | """add a callback to be run when the repository is fully unlocked |
|
2598 | """add a callback to be run when the repository is fully unlocked | |
2599 |
|
2599 | |||
2600 | The callback will be executed when the outermost lock is released |
|
2600 | The callback will be executed when the outermost lock is released | |
2601 | (with wlock being higher level than 'lock').""" |
|
2601 | (with wlock being higher level than 'lock').""" | |
2602 | for ref in (self._wlockref, self._lockref): |
|
2602 | for ref in (self._wlockref, self._lockref): | |
2603 | l = ref and ref() |
|
2603 | l = ref and ref() | |
2604 | if l and l.held: |
|
2604 | if l and l.held: | |
2605 | l.postrelease.append(callback) |
|
2605 | l.postrelease.append(callback) | |
2606 | break |
|
2606 | break | |
2607 | else: # no lock have been found. |
|
2607 | else: # no lock have been found. | |
2608 | callback(True) |
|
2608 | callback(True) | |
2609 |
|
2609 | |||
2610 | def lock(self, wait=True): |
|
2610 | def lock(self, wait=True): | |
2611 | '''Lock the repository store (.hg/store) and return a weak reference |
|
2611 | '''Lock the repository store (.hg/store) and return a weak reference | |
2612 | to the lock. Use this before modifying the store (e.g. committing or |
|
2612 | to the lock. Use this before modifying the store (e.g. committing or | |
2613 | stripping). If you are opening a transaction, get a lock as well.) |
|
2613 | stripping). If you are opening a transaction, get a lock as well.) | |
2614 |
|
2614 | |||
2615 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2615 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2616 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2616 | 'wlock' first to avoid a dead-lock hazard.''' | |
2617 | l = self._currentlock(self._lockref) |
|
2617 | l = self._currentlock(self._lockref) | |
2618 | if l is not None: |
|
2618 | if l is not None: | |
2619 | l.lock() |
|
2619 | l.lock() | |
2620 | return l |
|
2620 | return l | |
2621 |
|
2621 | |||
2622 | l = self._lock( |
|
2622 | l = self._lock( | |
2623 | vfs=self.svfs, |
|
2623 | vfs=self.svfs, | |
2624 | lockname=b"lock", |
|
2624 | lockname=b"lock", | |
2625 | wait=wait, |
|
2625 | wait=wait, | |
2626 | releasefn=None, |
|
2626 | releasefn=None, | |
2627 | acquirefn=self.invalidate, |
|
2627 | acquirefn=self.invalidate, | |
2628 | desc=_(b'repository %s') % self.origroot, |
|
2628 | desc=_(b'repository %s') % self.origroot, | |
2629 | ) |
|
2629 | ) | |
2630 | self._lockref = weakref.ref(l) |
|
2630 | self._lockref = weakref.ref(l) | |
2631 | return l |
|
2631 | return l | |
2632 |
|
2632 | |||
2633 | def _wlockchecktransaction(self): |
|
2633 | def _wlockchecktransaction(self): | |
2634 | if self.currenttransaction() is not None: |
|
2634 | if self.currenttransaction() is not None: | |
2635 | raise error.LockInheritanceContractViolation( |
|
2635 | raise error.LockInheritanceContractViolation( | |
2636 | b'wlock cannot be inherited in the middle of a transaction' |
|
2636 | b'wlock cannot be inherited in the middle of a transaction' | |
2637 | ) |
|
2637 | ) | |
2638 |
|
2638 | |||
2639 | def wlock(self, wait=True): |
|
2639 | def wlock(self, wait=True): | |
2640 | '''Lock the non-store parts of the repository (everything under |
|
2640 | '''Lock the non-store parts of the repository (everything under | |
2641 | .hg except .hg/store) and return a weak reference to the lock. |
|
2641 | .hg except .hg/store) and return a weak reference to the lock. | |
2642 |
|
2642 | |||
2643 | Use this before modifying files in .hg. |
|
2643 | Use this before modifying files in .hg. | |
2644 |
|
2644 | |||
2645 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2645 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2646 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2646 | 'wlock' first to avoid a dead-lock hazard.''' | |
2647 | l = self._wlockref and self._wlockref() |
|
2647 | l = self._wlockref and self._wlockref() | |
2648 | if l is not None and l.held: |
|
2648 | if l is not None and l.held: | |
2649 | l.lock() |
|
2649 | l.lock() | |
2650 | return l |
|
2650 | return l | |
2651 |
|
2651 | |||
2652 | # We do not need to check for non-waiting lock acquisition. Such |
|
2652 | # We do not need to check for non-waiting lock acquisition. Such | |
2653 | # acquisition would not cause dead-lock as they would just fail. |
|
2653 | # acquisition would not cause dead-lock as they would just fail. | |
2654 | if wait and ( |
|
2654 | if wait and ( | |
2655 | self.ui.configbool(b'devel', b'all-warnings') |
|
2655 | self.ui.configbool(b'devel', b'all-warnings') | |
2656 | or self.ui.configbool(b'devel', b'check-locks') |
|
2656 | or self.ui.configbool(b'devel', b'check-locks') | |
2657 | ): |
|
2657 | ): | |
2658 | if self._currentlock(self._lockref) is not None: |
|
2658 | if self._currentlock(self._lockref) is not None: | |
2659 | self.ui.develwarn(b'"wlock" acquired after "lock"') |
|
2659 | self.ui.develwarn(b'"wlock" acquired after "lock"') | |
2660 |
|
2660 | |||
2661 | def unlock(): |
|
2661 | def unlock(): | |
2662 | if self.dirstate.pendingparentchange(): |
|
2662 | if self.dirstate.pendingparentchange(): | |
2663 | self.dirstate.invalidate() |
|
2663 | self.dirstate.invalidate() | |
2664 | else: |
|
2664 | else: | |
2665 | self.dirstate.write(None) |
|
2665 | self.dirstate.write(None) | |
2666 |
|
2666 | |||
2667 | self._filecache[b'dirstate'].refresh() |
|
2667 | self._filecache[b'dirstate'].refresh() | |
2668 |
|
2668 | |||
2669 | l = self._lock( |
|
2669 | l = self._lock( | |
2670 | self.vfs, |
|
2670 | self.vfs, | |
2671 | b"wlock", |
|
2671 | b"wlock", | |
2672 | wait, |
|
2672 | wait, | |
2673 | unlock, |
|
2673 | unlock, | |
2674 | self.invalidatedirstate, |
|
2674 | self.invalidatedirstate, | |
2675 | _(b'working directory of %s') % self.origroot, |
|
2675 | _(b'working directory of %s') % self.origroot, | |
2676 | inheritchecker=self._wlockchecktransaction, |
|
2676 | inheritchecker=self._wlockchecktransaction, | |
2677 | parentenvvar=b'HG_WLOCK_LOCKER', |
|
2677 | parentenvvar=b'HG_WLOCK_LOCKER', | |
2678 | ) |
|
2678 | ) | |
2679 | self._wlockref = weakref.ref(l) |
|
2679 | self._wlockref = weakref.ref(l) | |
2680 | return l |
|
2680 | return l | |
2681 |
|
2681 | |||
2682 | def _currentlock(self, lockref): |
|
2682 | def _currentlock(self, lockref): | |
2683 | """Returns the lock if it's held, or None if it's not.""" |
|
2683 | """Returns the lock if it's held, or None if it's not.""" | |
2684 | if lockref is None: |
|
2684 | if lockref is None: | |
2685 | return None |
|
2685 | return None | |
2686 | l = lockref() |
|
2686 | l = lockref() | |
2687 | if l is None or not l.held: |
|
2687 | if l is None or not l.held: | |
2688 | return None |
|
2688 | return None | |
2689 | return l |
|
2689 | return l | |
2690 |
|
2690 | |||
2691 | def currentwlock(self): |
|
2691 | def currentwlock(self): | |
2692 | """Returns the wlock if it's held, or None if it's not.""" |
|
2692 | """Returns the wlock if it's held, or None if it's not.""" | |
2693 | return self._currentlock(self._wlockref) |
|
2693 | return self._currentlock(self._wlockref) | |
2694 |
|
2694 | |||
2695 | def _filecommit( |
|
2695 | def _filecommit( | |
2696 | self, |
|
2696 | self, | |
2697 | fctx, |
|
2697 | fctx, | |
2698 | manifest1, |
|
2698 | manifest1, | |
2699 | manifest2, |
|
2699 | manifest2, | |
2700 | linkrev, |
|
2700 | linkrev, | |
2701 | tr, |
|
2701 | tr, | |
2702 | changelist, |
|
2702 | changelist, | |
2703 | includecopymeta, |
|
2703 | includecopymeta, | |
2704 | ): |
|
2704 | ): | |
2705 | """ |
|
2705 | """ | |
2706 | commit an individual file as part of a larger transaction |
|
2706 | commit an individual file as part of a larger transaction | |
2707 | """ |
|
2707 | """ | |
2708 |
|
2708 | |||
2709 | fname = fctx.path() |
|
2709 | fname = fctx.path() | |
2710 | fparent1 = manifest1.get(fname, nullid) |
|
2710 | fparent1 = manifest1.get(fname, nullid) | |
2711 | fparent2 = manifest2.get(fname, nullid) |
|
2711 | fparent2 = manifest2.get(fname, nullid) | |
2712 | if isinstance(fctx, context.filectx): |
|
2712 | if isinstance(fctx, context.filectx): | |
2713 | node = fctx.filenode() |
|
2713 | node = fctx.filenode() | |
2714 | if node in [fparent1, fparent2]: |
|
2714 | if node in [fparent1, fparent2]: | |
2715 | self.ui.debug(b'reusing %s filelog entry\n' % fname) |
|
2715 | self.ui.debug(b'reusing %s filelog entry\n' % fname) | |
2716 | if ( |
|
2716 | if ( | |
2717 | fparent1 != nullid |
|
2717 | fparent1 != nullid | |
2718 | and manifest1.flags(fname) != fctx.flags() |
|
2718 | and manifest1.flags(fname) != fctx.flags() | |
2719 | ) or ( |
|
2719 | ) or ( | |
2720 | fparent2 != nullid |
|
2720 | fparent2 != nullid | |
2721 | and manifest2.flags(fname) != fctx.flags() |
|
2721 | and manifest2.flags(fname) != fctx.flags() | |
2722 | ): |
|
2722 | ): | |
2723 | changelist.append(fname) |
|
2723 | changelist.append(fname) | |
2724 | return node |
|
2724 | return node | |
2725 |
|
2725 | |||
2726 | flog = self.file(fname) |
|
2726 | flog = self.file(fname) | |
2727 | meta = {} |
|
2727 | meta = {} | |
2728 | cfname = fctx.copysource() |
|
2728 | cfname = fctx.copysource() | |
2729 | if cfname and cfname != fname: |
|
2729 | if cfname and cfname != fname: | |
2730 | # Mark the new revision of this file as a copy of another |
|
2730 | # Mark the new revision of this file as a copy of another | |
2731 | # file. This copy data will effectively act as a parent |
|
2731 | # file. This copy data will effectively act as a parent | |
2732 | # of this new revision. If this is a merge, the first |
|
2732 | # of this new revision. If this is a merge, the first | |
2733 | # parent will be the nullid (meaning "look up the copy data") |
|
2733 | # parent will be the nullid (meaning "look up the copy data") | |
2734 | # and the second one will be the other parent. For example: |
|
2734 | # and the second one will be the other parent. For example: | |
2735 | # |
|
2735 | # | |
2736 | # 0 --- 1 --- 3 rev1 changes file foo |
|
2736 | # 0 --- 1 --- 3 rev1 changes file foo | |
2737 | # \ / rev2 renames foo to bar and changes it |
|
2737 | # \ / rev2 renames foo to bar and changes it | |
2738 | # \- 2 -/ rev3 should have bar with all changes and |
|
2738 | # \- 2 -/ rev3 should have bar with all changes and | |
2739 | # should record that bar descends from |
|
2739 | # should record that bar descends from | |
2740 | # bar in rev2 and foo in rev1 |
|
2740 | # bar in rev2 and foo in rev1 | |
2741 | # |
|
2741 | # | |
2742 | # this allows this merge to succeed: |
|
2742 | # this allows this merge to succeed: | |
2743 | # |
|
2743 | # | |
2744 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
2744 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
2745 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
2745 | # \ / merging rev3 and rev4 should use bar@rev2 | |
2746 | # \- 2 --- 4 as the merge base |
|
2746 | # \- 2 --- 4 as the merge base | |
2747 | # |
|
2747 | # | |
2748 |
|
2748 | |||
2749 | cnode = manifest1.get(cfname) |
|
2749 | cnode = manifest1.get(cfname) | |
2750 | newfparent = fparent2 |
|
2750 | newfparent = fparent2 | |
2751 |
|
2751 | |||
2752 | if manifest2: # branch merge |
|
2752 | if manifest2: # branch merge | |
2753 | if fparent2 == nullid or cnode is None: # copied on remote side |
|
2753 | if fparent2 == nullid or cnode is None: # copied on remote side | |
2754 | if cfname in manifest2: |
|
2754 | if cfname in manifest2: | |
2755 | cnode = manifest2[cfname] |
|
2755 | cnode = manifest2[cfname] | |
2756 | newfparent = fparent1 |
|
2756 | newfparent = fparent1 | |
2757 |
|
2757 | |||
2758 | # Here, we used to search backwards through history to try to find |
|
2758 | # Here, we used to search backwards through history to try to find | |
2759 | # where the file copy came from if the source of a copy was not in |
|
2759 | # where the file copy came from if the source of a copy was not in | |
2760 | # the parent directory. However, this doesn't actually make sense to |
|
2760 | # the parent directory. However, this doesn't actually make sense to | |
2761 | # do (what does a copy from something not in your working copy even |
|
2761 | # do (what does a copy from something not in your working copy even | |
2762 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
2762 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
2763 | # the user that copy information was dropped, so if they didn't |
|
2763 | # the user that copy information was dropped, so if they didn't | |
2764 | # expect this outcome it can be fixed, but this is the correct |
|
2764 | # expect this outcome it can be fixed, but this is the correct | |
2765 | # behavior in this circumstance. |
|
2765 | # behavior in this circumstance. | |
2766 |
|
2766 | |||
2767 | if cnode: |
|
2767 | if cnode: | |
2768 | self.ui.debug( |
|
2768 | self.ui.debug( | |
2769 | b" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)) |
|
2769 | b" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)) | |
2770 | ) |
|
2770 | ) | |
2771 | if includecopymeta: |
|
2771 | if includecopymeta: | |
2772 | meta[b"copy"] = cfname |
|
2772 | meta[b"copy"] = cfname | |
2773 | meta[b"copyrev"] = hex(cnode) |
|
2773 | meta[b"copyrev"] = hex(cnode) | |
2774 | fparent1, fparent2 = nullid, newfparent |
|
2774 | fparent1, fparent2 = nullid, newfparent | |
2775 | else: |
|
2775 | else: | |
2776 | self.ui.warn( |
|
2776 | self.ui.warn( | |
2777 | _( |
|
2777 | _( | |
2778 | b"warning: can't find ancestor for '%s' " |
|
2778 | b"warning: can't find ancestor for '%s' " | |
2779 | b"copied from '%s'!\n" |
|
2779 | b"copied from '%s'!\n" | |
2780 | ) |
|
2780 | ) | |
2781 | % (fname, cfname) |
|
2781 | % (fname, cfname) | |
2782 | ) |
|
2782 | ) | |
2783 |
|
2783 | |||
2784 | elif fparent1 == nullid: |
|
2784 | elif fparent1 == nullid: | |
2785 | fparent1, fparent2 = fparent2, nullid |
|
2785 | fparent1, fparent2 = fparent2, nullid | |
2786 | elif fparent2 != nullid: |
|
2786 | elif fparent2 != nullid: | |
2787 | # is one parent an ancestor of the other? |
|
2787 | # is one parent an ancestor of the other? | |
2788 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
2788 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
2789 | if fparent1 in fparentancestors: |
|
2789 | if fparent1 in fparentancestors: | |
2790 | fparent1, fparent2 = fparent2, nullid |
|
2790 | fparent1, fparent2 = fparent2, nullid | |
2791 | elif fparent2 in fparentancestors: |
|
2791 | elif fparent2 in fparentancestors: | |
2792 | fparent2 = nullid |
|
2792 | fparent2 = nullid | |
2793 |
|
2793 | |||
2794 | # is the file changed? |
|
2794 | # is the file changed? | |
2795 | text = fctx.data() |
|
2795 | text = fctx.data() | |
2796 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
2796 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
2797 | changelist.append(fname) |
|
2797 | changelist.append(fname) | |
2798 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
2798 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
2799 | # are just the flags changed during merge? |
|
2799 | # are just the flags changed during merge? | |
2800 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
2800 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
2801 | changelist.append(fname) |
|
2801 | changelist.append(fname) | |
2802 |
|
2802 | |||
2803 | return fparent1 |
|
2803 | return fparent1 | |
2804 |
|
2804 | |||
2805 | def checkcommitpatterns(self, wctx, match, status, fail): |
|
2805 | def checkcommitpatterns(self, wctx, match, status, fail): | |
2806 | """check for commit arguments that aren't committable""" |
|
2806 | """check for commit arguments that aren't committable""" | |
2807 | if match.isexact() or match.prefix(): |
|
2807 | if match.isexact() or match.prefix(): | |
2808 | matched = set(status.modified + status.added + status.removed) |
|
2808 | matched = set(status.modified + status.added + status.removed) | |
2809 |
|
2809 | |||
2810 | for f in match.files(): |
|
2810 | for f in match.files(): | |
2811 | f = self.dirstate.normalize(f) |
|
2811 | f = self.dirstate.normalize(f) | |
2812 | if f == b'.' or f in matched or f in wctx.substate: |
|
2812 | if f == b'.' or f in matched or f in wctx.substate: | |
2813 | continue |
|
2813 | continue | |
2814 | if f in status.deleted: |
|
2814 | if f in status.deleted: | |
2815 | fail(f, _(b'file not found!')) |
|
2815 | fail(f, _(b'file not found!')) | |
2816 | # Is it a directory that exists or used to exist? |
|
2816 | # Is it a directory that exists or used to exist? | |
2817 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): |
|
2817 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): | |
2818 | d = f + b'/' |
|
2818 | d = f + b'/' | |
2819 | for mf in matched: |
|
2819 | for mf in matched: | |
2820 | if mf.startswith(d): |
|
2820 | if mf.startswith(d): | |
2821 | break |
|
2821 | break | |
2822 | else: |
|
2822 | else: | |
2823 | fail(f, _(b"no match under directory!")) |
|
2823 | fail(f, _(b"no match under directory!")) | |
2824 | elif f not in self.dirstate: |
|
2824 | elif f not in self.dirstate: | |
2825 | fail(f, _(b"file not tracked!")) |
|
2825 | fail(f, _(b"file not tracked!")) | |
2826 |
|
2826 | |||
2827 | @unfilteredmethod |
|
2827 | @unfilteredmethod | |
2828 | def commit( |
|
2828 | def commit( | |
2829 | self, |
|
2829 | self, | |
2830 | text=b"", |
|
2830 | text=b"", | |
2831 | user=None, |
|
2831 | user=None, | |
2832 | date=None, |
|
2832 | date=None, | |
2833 | match=None, |
|
2833 | match=None, | |
2834 | force=False, |
|
2834 | force=False, | |
2835 | editor=None, |
|
2835 | editor=None, | |
2836 | extra=None, |
|
2836 | extra=None, | |
2837 | ): |
|
2837 | ): | |
2838 | """Add a new revision to current repository. |
|
2838 | """Add a new revision to current repository. | |
2839 |
|
2839 | |||
2840 | Revision information is gathered from the working directory, |
|
2840 | Revision information is gathered from the working directory, | |
2841 | match can be used to filter the committed files. If editor is |
|
2841 | match can be used to filter the committed files. If editor is | |
2842 | supplied, it is called to get a commit message. |
|
2842 | supplied, it is called to get a commit message. | |
2843 | """ |
|
2843 | """ | |
2844 | if extra is None: |
|
2844 | if extra is None: | |
2845 | extra = {} |
|
2845 | extra = {} | |
2846 |
|
2846 | |||
2847 | def fail(f, msg): |
|
2847 | def fail(f, msg): | |
2848 | raise error.Abort(b'%s: %s' % (f, msg)) |
|
2848 | raise error.Abort(b'%s: %s' % (f, msg)) | |
2849 |
|
2849 | |||
2850 | if not match: |
|
2850 | if not match: | |
2851 | match = matchmod.always() |
|
2851 | match = matchmod.always() | |
2852 |
|
2852 | |||
2853 | if not force: |
|
2853 | if not force: | |
2854 | match.bad = fail |
|
2854 | match.bad = fail | |
2855 |
|
2855 | |||
2856 | # lock() for recent changelog (see issue4368) |
|
2856 | # lock() for recent changelog (see issue4368) | |
2857 | with self.wlock(), self.lock(): |
|
2857 | with self.wlock(), self.lock(): | |
2858 | wctx = self[None] |
|
2858 | wctx = self[None] | |
2859 | merge = len(wctx.parents()) > 1 |
|
2859 | merge = len(wctx.parents()) > 1 | |
2860 |
|
2860 | |||
2861 | if not force and merge and not match.always(): |
|
2861 | if not force and merge and not match.always(): | |
2862 | raise error.Abort( |
|
2862 | raise error.Abort( | |
2863 | _( |
|
2863 | _( | |
2864 | b'cannot partially commit a merge ' |
|
2864 | b'cannot partially commit a merge ' | |
2865 | b'(do not specify files or patterns)' |
|
2865 | b'(do not specify files or patterns)' | |
2866 | ) |
|
2866 | ) | |
2867 | ) |
|
2867 | ) | |
2868 |
|
2868 | |||
2869 | status = self.status(match=match, clean=force) |
|
2869 | status = self.status(match=match, clean=force) | |
2870 | if force: |
|
2870 | if force: | |
2871 | status.modified.extend( |
|
2871 | status.modified.extend( | |
2872 | status.clean |
|
2872 | status.clean | |
2873 | ) # mq may commit clean files |
|
2873 | ) # mq may commit clean files | |
2874 |
|
2874 | |||
2875 | # check subrepos |
|
2875 | # check subrepos | |
2876 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
2876 | subs, commitsubs, newstate = subrepoutil.precommit( | |
2877 | self.ui, wctx, status, match, force=force |
|
2877 | self.ui, wctx, status, match, force=force | |
2878 | ) |
|
2878 | ) | |
2879 |
|
2879 | |||
2880 | # make sure all explicit patterns are matched |
|
2880 | # make sure all explicit patterns are matched | |
2881 | if not force: |
|
2881 | if not force: | |
2882 | self.checkcommitpatterns(wctx, match, status, fail) |
|
2882 | self.checkcommitpatterns(wctx, match, status, fail) | |
2883 |
|
2883 | |||
2884 | cctx = context.workingcommitctx( |
|
2884 | cctx = context.workingcommitctx( | |
2885 | self, status, text, user, date, extra |
|
2885 | self, status, text, user, date, extra | |
2886 | ) |
|
2886 | ) | |
2887 |
|
2887 | |||
2888 | # internal config: ui.allowemptycommit |
|
2888 | # internal config: ui.allowemptycommit | |
2889 | allowemptycommit = ( |
|
2889 | allowemptycommit = ( | |
2890 | wctx.branch() != wctx.p1().branch() |
|
2890 | wctx.branch() != wctx.p1().branch() | |
2891 | or extra.get(b'close') |
|
2891 | or extra.get(b'close') | |
2892 | or merge |
|
2892 | or merge | |
2893 | or cctx.files() |
|
2893 | or cctx.files() | |
2894 | or self.ui.configbool(b'ui', b'allowemptycommit') |
|
2894 | or self.ui.configbool(b'ui', b'allowemptycommit') | |
2895 | ) |
|
2895 | ) | |
2896 | if not allowemptycommit: |
|
2896 | if not allowemptycommit: | |
2897 | return None |
|
2897 | return None | |
2898 |
|
2898 | |||
2899 | if merge and cctx.deleted(): |
|
2899 | if merge and cctx.deleted(): | |
2900 | raise error.Abort(_(b"cannot commit merge with missing files")) |
|
2900 | raise error.Abort(_(b"cannot commit merge with missing files")) | |
2901 |
|
2901 | |||
2902 | ms = mergemod.mergestate.read(self) |
|
2902 | ms = mergemod.mergestate.read(self) | |
2903 | mergeutil.checkunresolved(ms) |
|
2903 | mergeutil.checkunresolved(ms) | |
2904 |
|
2904 | |||
2905 | if editor: |
|
2905 | if editor: | |
2906 | cctx._text = editor(self, cctx, subs) |
|
2906 | cctx._text = editor(self, cctx, subs) | |
2907 | edited = text != cctx._text |
|
2907 | edited = text != cctx._text | |
2908 |
|
2908 | |||
2909 | # Save commit message in case this transaction gets rolled back |
|
2909 | # Save commit message in case this transaction gets rolled back | |
2910 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
2910 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
2911 | # the assumption that the user will use the same editor again. |
|
2911 | # the assumption that the user will use the same editor again. | |
2912 | msgfn = self.savecommitmessage(cctx._text) |
|
2912 | msgfn = self.savecommitmessage(cctx._text) | |
2913 |
|
2913 | |||
2914 | # commit subs and write new state |
|
2914 | # commit subs and write new state | |
2915 | if subs: |
|
2915 | if subs: | |
2916 | uipathfn = scmutil.getuipathfn(self) |
|
2916 | uipathfn = scmutil.getuipathfn(self) | |
2917 | for s in sorted(commitsubs): |
|
2917 | for s in sorted(commitsubs): | |
2918 | sub = wctx.sub(s) |
|
2918 | sub = wctx.sub(s) | |
2919 | self.ui.status( |
|
2919 | self.ui.status( | |
2920 | _(b'committing subrepository %s\n') |
|
2920 | _(b'committing subrepository %s\n') | |
2921 | % uipathfn(subrepoutil.subrelpath(sub)) |
|
2921 | % uipathfn(subrepoutil.subrelpath(sub)) | |
2922 | ) |
|
2922 | ) | |
2923 | sr = sub.commit(cctx._text, user, date) |
|
2923 | sr = sub.commit(cctx._text, user, date) | |
2924 | newstate[s] = (newstate[s][0], sr) |
|
2924 | newstate[s] = (newstate[s][0], sr) | |
2925 | subrepoutil.writestate(self, newstate) |
|
2925 | subrepoutil.writestate(self, newstate) | |
2926 |
|
2926 | |||
2927 | p1, p2 = self.dirstate.parents() |
|
2927 | p1, p2 = self.dirstate.parents() | |
2928 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or b'') |
|
2928 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or b'') | |
2929 | try: |
|
2929 | try: | |
2930 | self.hook( |
|
2930 | self.hook( | |
2931 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 |
|
2931 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 | |
2932 | ) |
|
2932 | ) | |
2933 | with self.transaction(b'commit'): |
|
2933 | with self.transaction(b'commit'): | |
2934 | ret = self.commitctx(cctx, True) |
|
2934 | ret = self.commitctx(cctx, True) | |
2935 | # update bookmarks, dirstate and mergestate |
|
2935 | # update bookmarks, dirstate and mergestate | |
2936 | bookmarks.update(self, [p1, p2], ret) |
|
2936 | bookmarks.update(self, [p1, p2], ret) | |
2937 | cctx.markcommitted(ret) |
|
2937 | cctx.markcommitted(ret) | |
2938 | ms.reset() |
|
2938 | ms.reset() | |
2939 | except: # re-raises |
|
2939 | except: # re-raises | |
2940 | if edited: |
|
2940 | if edited: | |
2941 | self.ui.write( |
|
2941 | self.ui.write( | |
2942 | _(b'note: commit message saved in %s\n') % msgfn |
|
2942 | _(b'note: commit message saved in %s\n') % msgfn | |
2943 | ) |
|
2943 | ) | |
2944 | raise |
|
2944 | raise | |
2945 |
|
2945 | |||
2946 | def commithook(unused_success): |
|
2946 | def commithook(unused_success): | |
2947 | # hack for command that use a temporary commit (eg: histedit) |
|
2947 | # hack for command that use a temporary commit (eg: histedit) | |
2948 | # temporary commit got stripped before hook release |
|
2948 | # temporary commit got stripped before hook release | |
2949 | if self.changelog.hasnode(ret): |
|
2949 | if self.changelog.hasnode(ret): | |
2950 | self.hook( |
|
2950 | self.hook( | |
2951 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 |
|
2951 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 | |
2952 | ) |
|
2952 | ) | |
2953 |
|
2953 | |||
2954 | self._afterlock(commithook) |
|
2954 | self._afterlock(commithook) | |
2955 | return ret |
|
2955 | return ret | |
2956 |
|
2956 | |||
2957 | @unfilteredmethod |
|
2957 | @unfilteredmethod | |
2958 | def commitctx(self, ctx, error=False, origctx=None): |
|
2958 | def commitctx(self, ctx, error=False, origctx=None): | |
2959 | """Add a new revision to current repository. |
|
2959 | """Add a new revision to current repository. | |
2960 | Revision information is passed via the context argument. |
|
2960 | Revision information is passed via the context argument. | |
2961 |
|
2961 | |||
2962 | ctx.files() should list all files involved in this commit, i.e. |
|
2962 | ctx.files() should list all files involved in this commit, i.e. | |
2963 | modified/added/removed files. On merge, it may be wider than the |
|
2963 | modified/added/removed files. On merge, it may be wider than the | |
2964 | ctx.files() to be committed, since any file nodes derived directly |
|
2964 | ctx.files() to be committed, since any file nodes derived directly | |
2965 | from p1 or p2 are excluded from the committed ctx.files(). |
|
2965 | from p1 or p2 are excluded from the committed ctx.files(). | |
2966 |
|
2966 | |||
2967 | origctx is for convert to work around the problem that bug |
|
2967 | origctx is for convert to work around the problem that bug | |
2968 | fixes to the files list in changesets change hashes. For |
|
2968 | fixes to the files list in changesets change hashes. For | |
2969 | convert to be the identity, it can pass an origctx and this |
|
2969 | convert to be the identity, it can pass an origctx and this | |
2970 | function will use the same files list when it makes sense to |
|
2970 | function will use the same files list when it makes sense to | |
2971 | do so. |
|
2971 | do so. | |
2972 | """ |
|
2972 | """ | |
2973 |
|
2973 | |||
2974 | p1, p2 = ctx.p1(), ctx.p2() |
|
2974 | p1, p2 = ctx.p1(), ctx.p2() | |
2975 | user = ctx.user() |
|
2975 | user = ctx.user() | |
2976 |
|
2976 | |||
2977 | if self.filecopiesmode == b'changeset-sidedata': |
|
2977 | if self.filecopiesmode == b'changeset-sidedata': | |
2978 | writechangesetcopy = True |
|
2978 | writechangesetcopy = True | |
2979 | writefilecopymeta = True |
|
2979 | writefilecopymeta = True | |
2980 | writecopiesto = None |
|
2980 | writecopiesto = None | |
2981 | else: |
|
2981 | else: | |
2982 | writecopiesto = self.ui.config(b'experimental', b'copies.write-to') |
|
2982 | writecopiesto = self.ui.config(b'experimental', b'copies.write-to') | |
2983 | writefilecopymeta = writecopiesto != b'changeset-only' |
|
2983 | writefilecopymeta = writecopiesto != b'changeset-only' | |
2984 | writechangesetcopy = writecopiesto in ( |
|
2984 | writechangesetcopy = writecopiesto in ( | |
2985 | b'changeset-only', |
|
2985 | b'changeset-only', | |
2986 | b'compatibility', |
|
2986 | b'compatibility', | |
2987 | ) |
|
2987 | ) | |
2988 | p1copies, p2copies = None, None |
|
2988 | p1copies, p2copies = None, None | |
2989 | if writechangesetcopy: |
|
2989 | if writechangesetcopy: | |
2990 | p1copies = ctx.p1copies() |
|
2990 | p1copies = ctx.p1copies() | |
2991 | p2copies = ctx.p2copies() |
|
2991 | p2copies = ctx.p2copies() | |
2992 | filesadded, filesremoved = None, None |
|
2992 | filesadded, filesremoved = None, None | |
2993 | with self.lock(), self.transaction(b"commit") as tr: |
|
2993 | with self.lock(), self.transaction(b"commit") as tr: | |
2994 | trp = weakref.proxy(tr) |
|
2994 | trp = weakref.proxy(tr) | |
2995 |
|
2995 | |||
2996 | if ctx.manifestnode(): |
|
2996 | if ctx.manifestnode(): | |
2997 | # reuse an existing manifest revision |
|
2997 | # reuse an existing manifest revision | |
2998 | self.ui.debug(b'reusing known manifest\n') |
|
2998 | self.ui.debug(b'reusing known manifest\n') | |
2999 | mn = ctx.manifestnode() |
|
2999 | mn = ctx.manifestnode() | |
3000 | files = ctx.files() |
|
3000 | files = ctx.files() | |
3001 | if writechangesetcopy: |
|
3001 | if writechangesetcopy: | |
3002 | filesadded = ctx.filesadded() |
|
3002 | filesadded = ctx.filesadded() | |
3003 | filesremoved = ctx.filesremoved() |
|
3003 | filesremoved = ctx.filesremoved() | |
3004 | elif ctx.files(): |
|
3004 | elif ctx.files(): | |
3005 | m1ctx = p1.manifestctx() |
|
3005 | m1ctx = p1.manifestctx() | |
3006 | m2ctx = p2.manifestctx() |
|
3006 | m2ctx = p2.manifestctx() | |
3007 | mctx = m1ctx.copy() |
|
3007 | mctx = m1ctx.copy() | |
3008 |
|
3008 | |||
3009 | m = mctx.read() |
|
3009 | m = mctx.read() | |
3010 | m1 = m1ctx.read() |
|
3010 | m1 = m1ctx.read() | |
3011 | m2 = m2ctx.read() |
|
3011 | m2 = m2ctx.read() | |
3012 |
|
3012 | |||
3013 | # check in files |
|
3013 | # check in files | |
3014 | added = [] |
|
3014 | added = [] | |
3015 | changed = [] |
|
3015 | changed = [] | |
3016 | removed = list(ctx.removed()) |
|
3016 | removed = list(ctx.removed()) | |
3017 | linkrev = len(self) |
|
3017 | linkrev = len(self) | |
3018 | self.ui.note(_(b"committing files:\n")) |
|
3018 | self.ui.note(_(b"committing files:\n")) | |
3019 | uipathfn = scmutil.getuipathfn(self) |
|
3019 | uipathfn = scmutil.getuipathfn(self) | |
3020 | for f in sorted(ctx.modified() + ctx.added()): |
|
3020 | for f in sorted(ctx.modified() + ctx.added()): | |
3021 | self.ui.note(uipathfn(f) + b"\n") |
|
3021 | self.ui.note(uipathfn(f) + b"\n") | |
3022 | try: |
|
3022 | try: | |
3023 | fctx = ctx[f] |
|
3023 | fctx = ctx[f] | |
3024 | if fctx is None: |
|
3024 | if fctx is None: | |
3025 | removed.append(f) |
|
3025 | removed.append(f) | |
3026 | else: |
|
3026 | else: | |
3027 | added.append(f) |
|
3027 | added.append(f) | |
3028 | m[f] = self._filecommit( |
|
3028 | m[f] = self._filecommit( | |
3029 | fctx, |
|
3029 | fctx, | |
3030 | m1, |
|
3030 | m1, | |
3031 | m2, |
|
3031 | m2, | |
3032 | linkrev, |
|
3032 | linkrev, | |
3033 | trp, |
|
3033 | trp, | |
3034 | changed, |
|
3034 | changed, | |
3035 | writefilecopymeta, |
|
3035 | writefilecopymeta, | |
3036 | ) |
|
3036 | ) | |
3037 | m.setflag(f, fctx.flags()) |
|
3037 | m.setflag(f, fctx.flags()) | |
3038 | except OSError: |
|
3038 | except OSError: | |
3039 | self.ui.warn( |
|
3039 | self.ui.warn( | |
3040 | _(b"trouble committing %s!\n") % uipathfn(f) |
|
3040 | _(b"trouble committing %s!\n") % uipathfn(f) | |
3041 | ) |
|
3041 | ) | |
3042 | raise |
|
3042 | raise | |
3043 | except IOError as inst: |
|
3043 | except IOError as inst: | |
3044 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
3044 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
3045 | if error or errcode and errcode != errno.ENOENT: |
|
3045 | if error or errcode and errcode != errno.ENOENT: | |
3046 | self.ui.warn( |
|
3046 | self.ui.warn( | |
3047 | _(b"trouble committing %s!\n") % uipathfn(f) |
|
3047 | _(b"trouble committing %s!\n") % uipathfn(f) | |
3048 | ) |
|
3048 | ) | |
3049 | raise |
|
3049 | raise | |
3050 |
|
3050 | |||
3051 | # update manifest |
|
3051 | # update manifest | |
3052 | removed = [f for f in removed if f in m1 or f in m2] |
|
3052 | removed = [f for f in removed if f in m1 or f in m2] | |
3053 | drop = sorted([f for f in removed if f in m]) |
|
3053 | drop = sorted([f for f in removed if f in m]) | |
3054 | for f in drop: |
|
3054 | for f in drop: | |
3055 | del m[f] |
|
3055 | del m[f] | |
3056 | if p2.rev() != nullrev: |
|
3056 | if p2.rev() != nullrev: | |
3057 |
|
3057 | |||
3058 | @util.cachefunc |
|
3058 | @util.cachefunc | |
3059 | def mas(): |
|
3059 | def mas(): | |
3060 | p1n = p1.node() |
|
3060 | p1n = p1.node() | |
3061 | p2n = p2.node() |
|
3061 | p2n = p2.node() | |
3062 | cahs = self.changelog.commonancestorsheads(p1n, p2n) |
|
3062 | cahs = self.changelog.commonancestorsheads(p1n, p2n) | |
3063 | if not cahs: |
|
3063 | if not cahs: | |
3064 | cahs = [nullrev] |
|
3064 | cahs = [nullrev] | |
3065 | return [self[r].manifest() for r in cahs] |
|
3065 | return [self[r].manifest() for r in cahs] | |
3066 |
|
3066 | |||
3067 | def deletionfromparent(f): |
|
3067 | def deletionfromparent(f): | |
3068 | # When a file is removed relative to p1 in a merge, this |
|
3068 | # When a file is removed relative to p1 in a merge, this | |
3069 | # function determines whether the absence is due to a |
|
3069 | # function determines whether the absence is due to a | |
3070 | # deletion from a parent, or whether the merge commit |
|
3070 | # deletion from a parent, or whether the merge commit | |
3071 | # itself deletes the file. We decide this by doing a |
|
3071 | # itself deletes the file. We decide this by doing a | |
3072 | # simplified three way merge of the manifest entry for |
|
3072 | # simplified three way merge of the manifest entry for | |
3073 | # the file. There are two ways we decide the merge |
|
3073 | # the file. There are two ways we decide the merge | |
3074 | # itself didn't delete a file: |
|
3074 | # itself didn't delete a file: | |
3075 | # - neither parent (nor the merge) contain the file |
|
3075 | # - neither parent (nor the merge) contain the file | |
3076 | # - exactly one parent contains the file, and that |
|
3076 | # - exactly one parent contains the file, and that | |
3077 | # parent has the same filelog entry as the merge |
|
3077 | # parent has the same filelog entry as the merge | |
3078 | # ancestor (or all of them if there two). In other |
|
3078 | # ancestor (or all of them if there two). In other | |
3079 | # words, that parent left the file unchanged while the |
|
3079 | # words, that parent left the file unchanged while the | |
3080 | # other one deleted it. |
|
3080 | # other one deleted it. | |
3081 | # One way to think about this is that deleting a file is |
|
3081 | # One way to think about this is that deleting a file is | |
3082 | # similar to emptying it, so the list of changed files |
|
3082 | # similar to emptying it, so the list of changed files | |
3083 | # should be similar either way. The computation |
|
3083 | # should be similar either way. The computation | |
3084 | # described above is not done directly in _filecommit |
|
3084 | # described above is not done directly in _filecommit | |
3085 | # when creating the list of changed files, however |
|
3085 | # when creating the list of changed files, however | |
3086 | # it does something very similar by comparing filelog |
|
3086 | # it does something very similar by comparing filelog | |
3087 | # nodes. |
|
3087 | # nodes. | |
3088 | if f in m1: |
|
3088 | if f in m1: | |
3089 | return f not in m2 and all( |
|
3089 | return f not in m2 and all( | |
3090 | f in ma and ma.find(f) == m1.find(f) |
|
3090 | f in ma and ma.find(f) == m1.find(f) | |
3091 | for ma in mas() |
|
3091 | for ma in mas() | |
3092 | ) |
|
3092 | ) | |
3093 | elif f in m2: |
|
3093 | elif f in m2: | |
3094 | return all( |
|
3094 | return all( | |
3095 | f in ma and ma.find(f) == m2.find(f) |
|
3095 | f in ma and ma.find(f) == m2.find(f) | |
3096 | for ma in mas() |
|
3096 | for ma in mas() | |
3097 | ) |
|
3097 | ) | |
3098 | else: |
|
3098 | else: | |
3099 | return True |
|
3099 | return True | |
3100 |
|
3100 | |||
3101 | removed = [f for f in removed if not deletionfromparent(f)] |
|
3101 | removed = [f for f in removed if not deletionfromparent(f)] | |
3102 |
|
3102 | |||
3103 | files = changed + removed |
|
3103 | files = changed + removed | |
3104 | md = None |
|
3104 | md = None | |
3105 | if not files: |
|
3105 | if not files: | |
3106 | # if no "files" actually changed in terms of the changelog, |
|
3106 | # if no "files" actually changed in terms of the changelog, | |
3107 | # try hard to detect unmodified manifest entry so that the |
|
3107 | # try hard to detect unmodified manifest entry so that the | |
3108 | # exact same commit can be reproduced later on convert. |
|
3108 | # exact same commit can be reproduced later on convert. | |
3109 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) |
|
3109 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) | |
3110 | if not files and md: |
|
3110 | if not files and md: | |
3111 | self.ui.debug( |
|
3111 | self.ui.debug( | |
3112 | b'not reusing manifest (no file change in ' |
|
3112 | b'not reusing manifest (no file change in ' | |
3113 | b'changelog, but manifest differs)\n' |
|
3113 | b'changelog, but manifest differs)\n' | |
3114 | ) |
|
3114 | ) | |
3115 | if files or md: |
|
3115 | if files or md: | |
3116 | self.ui.note(_(b"committing manifest\n")) |
|
3116 | self.ui.note(_(b"committing manifest\n")) | |
3117 | # we're using narrowmatch here since it's already applied at |
|
3117 | # we're using narrowmatch here since it's already applied at | |
3118 | # other stages (such as dirstate.walk), so we're already |
|
3118 | # other stages (such as dirstate.walk), so we're already | |
3119 | # ignoring things outside of narrowspec in most cases. The |
|
3119 | # ignoring things outside of narrowspec in most cases. The | |
3120 | # one case where we might have files outside the narrowspec |
|
3120 | # one case where we might have files outside the narrowspec | |
3121 | # at this point is merges, and we already error out in the |
|
3121 | # at this point is merges, and we already error out in the | |
3122 | # case where the merge has files outside of the narrowspec, |
|
3122 | # case where the merge has files outside of the narrowspec, | |
3123 | # so this is safe. |
|
3123 | # so this is safe. | |
3124 | mn = mctx.write( |
|
3124 | mn = mctx.write( | |
3125 | trp, |
|
3125 | trp, | |
3126 | linkrev, |
|
3126 | linkrev, | |
3127 | p1.manifestnode(), |
|
3127 | p1.manifestnode(), | |
3128 | p2.manifestnode(), |
|
3128 | p2.manifestnode(), | |
3129 | added, |
|
3129 | added, | |
3130 | drop, |
|
3130 | drop, | |
3131 | match=self.narrowmatch(), |
|
3131 | match=self.narrowmatch(), | |
3132 | ) |
|
3132 | ) | |
3133 |
|
3133 | |||
3134 | if writechangesetcopy: |
|
3134 | if writechangesetcopy: | |
3135 | filesadded = [ |
|
3135 | filesadded = [ | |
3136 | f for f in changed if not (f in m1 or f in m2) |
|
3136 | f for f in changed if not (f in m1 or f in m2) | |
3137 | ] |
|
3137 | ] | |
3138 | filesremoved = removed |
|
3138 | filesremoved = removed | |
3139 | else: |
|
3139 | else: | |
3140 | self.ui.debug( |
|
3140 | self.ui.debug( | |
3141 | b'reusing manifest from p1 (listed files ' |
|
3141 | b'reusing manifest from p1 (listed files ' | |
3142 | b'actually unchanged)\n' |
|
3142 | b'actually unchanged)\n' | |
3143 | ) |
|
3143 | ) | |
3144 | mn = p1.manifestnode() |
|
3144 | mn = p1.manifestnode() | |
3145 | else: |
|
3145 | else: | |
3146 | self.ui.debug(b'reusing manifest from p1 (no file change)\n') |
|
3146 | self.ui.debug(b'reusing manifest from p1 (no file change)\n') | |
3147 | mn = p1.manifestnode() |
|
3147 | mn = p1.manifestnode() | |
3148 | files = [] |
|
3148 | files = [] | |
3149 |
|
3149 | |||
3150 | if writecopiesto == b'changeset-only': |
|
3150 | if writecopiesto == b'changeset-only': | |
3151 | # If writing only to changeset extras, use None to indicate that |
|
3151 | # If writing only to changeset extras, use None to indicate that | |
3152 | # no entry should be written. If writing to both, write an empty |
|
3152 | # no entry should be written. If writing to both, write an empty | |
3153 | # entry to prevent the reader from falling back to reading |
|
3153 | # entry to prevent the reader from falling back to reading | |
3154 | # filelogs. |
|
3154 | # filelogs. | |
3155 | p1copies = p1copies or None |
|
3155 | p1copies = p1copies or None | |
3156 | p2copies = p2copies or None |
|
3156 | p2copies = p2copies or None | |
3157 | filesadded = filesadded or None |
|
3157 | filesadded = filesadded or None | |
3158 | filesremoved = filesremoved or None |
|
3158 | filesremoved = filesremoved or None | |
3159 |
|
3159 | |||
3160 | if origctx and origctx.manifestnode() == mn: |
|
3160 | if origctx and origctx.manifestnode() == mn: | |
3161 | files = origctx.files() |
|
3161 | files = origctx.files() | |
3162 |
|
3162 | |||
3163 | # update changelog |
|
3163 | # update changelog | |
3164 | self.ui.note(_(b"committing changelog\n")) |
|
3164 | self.ui.note(_(b"committing changelog\n")) | |
3165 | self.changelog.delayupdate(tr) |
|
3165 | self.changelog.delayupdate(tr) | |
3166 | n = self.changelog.add( |
|
3166 | n = self.changelog.add( | |
3167 | mn, |
|
3167 | mn, | |
3168 | files, |
|
3168 | files, | |
3169 | ctx.description(), |
|
3169 | ctx.description(), | |
3170 | trp, |
|
3170 | trp, | |
3171 | p1.node(), |
|
3171 | p1.node(), | |
3172 | p2.node(), |
|
3172 | p2.node(), | |
3173 | user, |
|
3173 | user, | |
3174 | ctx.date(), |
|
3174 | ctx.date(), | |
3175 | ctx.extra().copy(), |
|
3175 | ctx.extra().copy(), | |
3176 | p1copies, |
|
3176 | p1copies, | |
3177 | p2copies, |
|
3177 | p2copies, | |
3178 | filesadded, |
|
3178 | filesadded, | |
3179 | filesremoved, |
|
3179 | filesremoved, | |
3180 | ) |
|
3180 | ) | |
3181 | xp1, xp2 = p1.hex(), p2 and p2.hex() or b'' |
|
3181 | xp1, xp2 = p1.hex(), p2 and p2.hex() or b'' | |
3182 | self.hook( |
|
3182 | self.hook( | |
3183 | b'pretxncommit', |
|
3183 | b'pretxncommit', | |
3184 | throw=True, |
|
3184 | throw=True, | |
3185 | node=hex(n), |
|
3185 | node=hex(n), | |
3186 | parent1=xp1, |
|
3186 | parent1=xp1, | |
3187 | parent2=xp2, |
|
3187 | parent2=xp2, | |
3188 | ) |
|
3188 | ) | |
3189 | # set the new commit is proper phase |
|
3189 | # set the new commit is proper phase | |
3190 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
3190 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
3191 | if targetphase: |
|
3191 | if targetphase: | |
3192 | # retract boundary do not alter parent changeset. |
|
3192 | # retract boundary do not alter parent changeset. | |
3193 | # if a parent have higher the resulting phase will |
|
3193 | # if a parent have higher the resulting phase will | |
3194 | # be compliant anyway |
|
3194 | # be compliant anyway | |
3195 | # |
|
3195 | # | |
3196 | # if minimal phase was 0 we don't need to retract anything |
|
3196 | # if minimal phase was 0 we don't need to retract anything | |
3197 | phases.registernew(self, tr, targetphase, [n]) |
|
3197 | phases.registernew(self, tr, targetphase, [n]) | |
3198 | return n |
|
3198 | return n | |
3199 |
|
3199 | |||
3200 | @unfilteredmethod |
|
3200 | @unfilteredmethod | |
3201 | def destroying(self): |
|
3201 | def destroying(self): | |
3202 | '''Inform the repository that nodes are about to be destroyed. |
|
3202 | '''Inform the repository that nodes are about to be destroyed. | |
3203 | Intended for use by strip and rollback, so there's a common |
|
3203 | Intended for use by strip and rollback, so there's a common | |
3204 | place for anything that has to be done before destroying history. |
|
3204 | place for anything that has to be done before destroying history. | |
3205 |
|
3205 | |||
3206 | This is mostly useful for saving state that is in memory and waiting |
|
3206 | This is mostly useful for saving state that is in memory and waiting | |
3207 | to be flushed when the current lock is released. Because a call to |
|
3207 | to be flushed when the current lock is released. Because a call to | |
3208 | destroyed is imminent, the repo will be invalidated causing those |
|
3208 | destroyed is imminent, the repo will be invalidated causing those | |
3209 | changes to stay in memory (waiting for the next unlock), or vanish |
|
3209 | changes to stay in memory (waiting for the next unlock), or vanish | |
3210 | completely. |
|
3210 | completely. | |
3211 | ''' |
|
3211 | ''' | |
3212 | # When using the same lock to commit and strip, the phasecache is left |
|
3212 | # When using the same lock to commit and strip, the phasecache is left | |
3213 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
3213 | # dirty after committing. Then when we strip, the repo is invalidated, | |
3214 | # causing those changes to disappear. |
|
3214 | # causing those changes to disappear. | |
3215 | if '_phasecache' in vars(self): |
|
3215 | if '_phasecache' in vars(self): | |
3216 | self._phasecache.write() |
|
3216 | self._phasecache.write() | |
3217 |
|
3217 | |||
3218 | @unfilteredmethod |
|
3218 | @unfilteredmethod | |
3219 | def destroyed(self): |
|
3219 | def destroyed(self): | |
3220 | '''Inform the repository that nodes have been destroyed. |
|
3220 | '''Inform the repository that nodes have been destroyed. | |
3221 | Intended for use by strip and rollback, so there's a common |
|
3221 | Intended for use by strip and rollback, so there's a common | |
3222 | place for anything that has to be done after destroying history. |
|
3222 | place for anything that has to be done after destroying history. | |
3223 | ''' |
|
3223 | ''' | |
3224 | # When one tries to: |
|
3224 | # When one tries to: | |
3225 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
3225 | # 1) destroy nodes thus calling this method (e.g. strip) | |
3226 | # 2) use phasecache somewhere (e.g. commit) |
|
3226 | # 2) use phasecache somewhere (e.g. commit) | |
3227 | # |
|
3227 | # | |
3228 | # then 2) will fail because the phasecache contains nodes that were |
|
3228 | # then 2) will fail because the phasecache contains nodes that were | |
3229 | # removed. We can either remove phasecache from the filecache, |
|
3229 | # removed. We can either remove phasecache from the filecache, | |
3230 | # causing it to reload next time it is accessed, or simply filter |
|
3230 | # causing it to reload next time it is accessed, or simply filter | |
3231 | # the removed nodes now and write the updated cache. |
|
3231 | # the removed nodes now and write the updated cache. | |
3232 | self._phasecache.filterunknown(self) |
|
3232 | self._phasecache.filterunknown(self) | |
3233 | self._phasecache.write() |
|
3233 | self._phasecache.write() | |
3234 |
|
3234 | |||
3235 | # refresh all repository caches |
|
3235 | # refresh all repository caches | |
3236 | self.updatecaches() |
|
3236 | self.updatecaches() | |
3237 |
|
3237 | |||
3238 | # Ensure the persistent tag cache is updated. Doing it now |
|
3238 | # Ensure the persistent tag cache is updated. Doing it now | |
3239 | # means that the tag cache only has to worry about destroyed |
|
3239 | # means that the tag cache only has to worry about destroyed | |
3240 | # heads immediately after a strip/rollback. That in turn |
|
3240 | # heads immediately after a strip/rollback. That in turn | |
3241 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
3241 | # guarantees that "cachetip == currenttip" (comparing both rev | |
3242 | # and node) always means no nodes have been added or destroyed. |
|
3242 | # and node) always means no nodes have been added or destroyed. | |
3243 |
|
3243 | |||
3244 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
3244 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
3245 | # head, refresh the tag cache, then immediately add a new head. |
|
3245 | # head, refresh the tag cache, then immediately add a new head. | |
3246 | # But I think doing it this way is necessary for the "instant |
|
3246 | # But I think doing it this way is necessary for the "instant | |
3247 | # tag cache retrieval" case to work. |
|
3247 | # tag cache retrieval" case to work. | |
3248 | self.invalidate() |
|
3248 | self.invalidate() | |
3249 |
|
3249 | |||
3250 | def status( |
|
3250 | def status( | |
3251 | self, |
|
3251 | self, | |
3252 | node1=b'.', |
|
3252 | node1=b'.', | |
3253 | node2=None, |
|
3253 | node2=None, | |
3254 | match=None, |
|
3254 | match=None, | |
3255 | ignored=False, |
|
3255 | ignored=False, | |
3256 | clean=False, |
|
3256 | clean=False, | |
3257 | unknown=False, |
|
3257 | unknown=False, | |
3258 | listsubrepos=False, |
|
3258 | listsubrepos=False, | |
3259 | ): |
|
3259 | ): | |
3260 | '''a convenience method that calls node1.status(node2)''' |
|
3260 | '''a convenience method that calls node1.status(node2)''' | |
3261 | return self[node1].status( |
|
3261 | return self[node1].status( | |
3262 | node2, match, ignored, clean, unknown, listsubrepos |
|
3262 | node2, match, ignored, clean, unknown, listsubrepos | |
3263 | ) |
|
3263 | ) | |
3264 |
|
3264 | |||
3265 | def addpostdsstatus(self, ps): |
|
3265 | def addpostdsstatus(self, ps): | |
3266 | """Add a callback to run within the wlock, at the point at which status |
|
3266 | """Add a callback to run within the wlock, at the point at which status | |
3267 | fixups happen. |
|
3267 | fixups happen. | |
3268 |
|
3268 | |||
3269 | On status completion, callback(wctx, status) will be called with the |
|
3269 | On status completion, callback(wctx, status) will be called with the | |
3270 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
3270 | wlock held, unless the dirstate has changed from underneath or the wlock | |
3271 | couldn't be grabbed. |
|
3271 | couldn't be grabbed. | |
3272 |
|
3272 | |||
3273 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
3273 | Callbacks should not capture and use a cached copy of the dirstate -- | |
3274 | it might change in the meanwhile. Instead, they should access the |
|
3274 | it might change in the meanwhile. Instead, they should access the | |
3275 | dirstate via wctx.repo().dirstate. |
|
3275 | dirstate via wctx.repo().dirstate. | |
3276 |
|
3276 | |||
3277 | This list is emptied out after each status run -- extensions should |
|
3277 | This list is emptied out after each status run -- extensions should | |
3278 | make sure it adds to this list each time dirstate.status is called. |
|
3278 | make sure it adds to this list each time dirstate.status is called. | |
3279 | Extensions should also make sure they don't call this for statuses |
|
3279 | Extensions should also make sure they don't call this for statuses | |
3280 | that don't involve the dirstate. |
|
3280 | that don't involve the dirstate. | |
3281 | """ |
|
3281 | """ | |
3282 |
|
3282 | |||
3283 | # The list is located here for uniqueness reasons -- it is actually |
|
3283 | # The list is located here for uniqueness reasons -- it is actually | |
3284 | # managed by the workingctx, but that isn't unique per-repo. |
|
3284 | # managed by the workingctx, but that isn't unique per-repo. | |
3285 | self._postdsstatus.append(ps) |
|
3285 | self._postdsstatus.append(ps) | |
3286 |
|
3286 | |||
3287 | def postdsstatus(self): |
|
3287 | def postdsstatus(self): | |
3288 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
3288 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
3289 | return self._postdsstatus |
|
3289 | return self._postdsstatus | |
3290 |
|
3290 | |||
3291 | def clearpostdsstatus(self): |
|
3291 | def clearpostdsstatus(self): | |
3292 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
3292 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
3293 | del self._postdsstatus[:] |
|
3293 | del self._postdsstatus[:] | |
3294 |
|
3294 | |||
3295 | def heads(self, start=None): |
|
3295 | def heads(self, start=None): | |
3296 | if start is None: |
|
3296 | if start is None: | |
3297 | cl = self.changelog |
|
3297 | cl = self.changelog | |
3298 | headrevs = reversed(cl.headrevs()) |
|
3298 | headrevs = reversed(cl.headrevs()) | |
3299 | return [cl.node(rev) for rev in headrevs] |
|
3299 | return [cl.node(rev) for rev in headrevs] | |
3300 |
|
3300 | |||
3301 | heads = self.changelog.heads(start) |
|
3301 | heads = self.changelog.heads(start) | |
3302 | # sort the output in rev descending order |
|
3302 | # sort the output in rev descending order | |
3303 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
3303 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
3304 |
|
3304 | |||
3305 | def branchheads(self, branch=None, start=None, closed=False): |
|
3305 | def branchheads(self, branch=None, start=None, closed=False): | |
3306 | '''return a (possibly filtered) list of heads for the given branch |
|
3306 | '''return a (possibly filtered) list of heads for the given branch | |
3307 |
|
3307 | |||
3308 | Heads are returned in topological order, from newest to oldest. |
|
3308 | Heads are returned in topological order, from newest to oldest. | |
3309 | If branch is None, use the dirstate branch. |
|
3309 | If branch is None, use the dirstate branch. | |
3310 | If start is not None, return only heads reachable from start. |
|
3310 | If start is not None, return only heads reachable from start. | |
3311 | If closed is True, return heads that are marked as closed as well. |
|
3311 | If closed is True, return heads that are marked as closed as well. | |
3312 | ''' |
|
3312 | ''' | |
3313 | if branch is None: |
|
3313 | if branch is None: | |
3314 | branch = self[None].branch() |
|
3314 | branch = self[None].branch() | |
3315 | branches = self.branchmap() |
|
3315 | branches = self.branchmap() | |
3316 | if not branches.hasbranch(branch): |
|
3316 | if not branches.hasbranch(branch): | |
3317 | return [] |
|
3317 | return [] | |
3318 | # the cache returns heads ordered lowest to highest |
|
3318 | # the cache returns heads ordered lowest to highest | |
3319 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
3319 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
3320 | if start is not None: |
|
3320 | if start is not None: | |
3321 | # filter out the heads that cannot be reached from startrev |
|
3321 | # filter out the heads that cannot be reached from startrev | |
3322 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
3322 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
3323 | bheads = [h for h in bheads if h in fbheads] |
|
3323 | bheads = [h for h in bheads if h in fbheads] | |
3324 | return bheads |
|
3324 | return bheads | |
3325 |
|
3325 | |||
3326 | def branches(self, nodes): |
|
3326 | def branches(self, nodes): | |
3327 | if not nodes: |
|
3327 | if not nodes: | |
3328 | nodes = [self.changelog.tip()] |
|
3328 | nodes = [self.changelog.tip()] | |
3329 | b = [] |
|
3329 | b = [] | |
3330 | for n in nodes: |
|
3330 | for n in nodes: | |
3331 | t = n |
|
3331 | t = n | |
3332 | while True: |
|
3332 | while True: | |
3333 | p = self.changelog.parents(n) |
|
3333 | p = self.changelog.parents(n) | |
3334 | if p[1] != nullid or p[0] == nullid: |
|
3334 | if p[1] != nullid or p[0] == nullid: | |
3335 | b.append((t, n, p[0], p[1])) |
|
3335 | b.append((t, n, p[0], p[1])) | |
3336 | break |
|
3336 | break | |
3337 | n = p[0] |
|
3337 | n = p[0] | |
3338 | return b |
|
3338 | return b | |
3339 |
|
3339 | |||
3340 | def between(self, pairs): |
|
3340 | def between(self, pairs): | |
3341 | r = [] |
|
3341 | r = [] | |
3342 |
|
3342 | |||
3343 | for top, bottom in pairs: |
|
3343 | for top, bottom in pairs: | |
3344 | n, l, i = top, [], 0 |
|
3344 | n, l, i = top, [], 0 | |
3345 | f = 1 |
|
3345 | f = 1 | |
3346 |
|
3346 | |||
3347 | while n != bottom and n != nullid: |
|
3347 | while n != bottom and n != nullid: | |
3348 | p = self.changelog.parents(n)[0] |
|
3348 | p = self.changelog.parents(n)[0] | |
3349 | if i == f: |
|
3349 | if i == f: | |
3350 | l.append(n) |
|
3350 | l.append(n) | |
3351 | f = f * 2 |
|
3351 | f = f * 2 | |
3352 | n = p |
|
3352 | n = p | |
3353 | i += 1 |
|
3353 | i += 1 | |
3354 |
|
3354 | |||
3355 | r.append(l) |
|
3355 | r.append(l) | |
3356 |
|
3356 | |||
3357 | return r |
|
3357 | return r | |
3358 |
|
3358 | |||
3359 | def checkpush(self, pushop): |
|
3359 | def checkpush(self, pushop): | |
3360 | """Extensions can override this function if additional checks have |
|
3360 | """Extensions can override this function if additional checks have | |
3361 | to be performed before pushing, or call it if they override push |
|
3361 | to be performed before pushing, or call it if they override push | |
3362 | command. |
|
3362 | command. | |
3363 | """ |
|
3363 | """ | |
3364 |
|
3364 | |||
3365 | @unfilteredpropertycache |
|
3365 | @unfilteredpropertycache | |
3366 | def prepushoutgoinghooks(self): |
|
3366 | def prepushoutgoinghooks(self): | |
3367 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
3367 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
3368 | methods, which are called before pushing changesets. |
|
3368 | methods, which are called before pushing changesets. | |
3369 | """ |
|
3369 | """ | |
3370 | return util.hooks() |
|
3370 | return util.hooks() | |
3371 |
|
3371 | |||
3372 | def pushkey(self, namespace, key, old, new): |
|
3372 | def pushkey(self, namespace, key, old, new): | |
3373 | try: |
|
3373 | try: | |
3374 | tr = self.currenttransaction() |
|
3374 | tr = self.currenttransaction() | |
3375 | hookargs = {} |
|
3375 | hookargs = {} | |
3376 | if tr is not None: |
|
3376 | if tr is not None: | |
3377 | hookargs.update(tr.hookargs) |
|
3377 | hookargs.update(tr.hookargs) | |
3378 | hookargs = pycompat.strkwargs(hookargs) |
|
3378 | hookargs = pycompat.strkwargs(hookargs) | |
3379 | hookargs['namespace'] = namespace |
|
3379 | hookargs['namespace'] = namespace | |
3380 | hookargs['key'] = key |
|
3380 | hookargs['key'] = key | |
3381 | hookargs['old'] = old |
|
3381 | hookargs['old'] = old | |
3382 | hookargs['new'] = new |
|
3382 | hookargs['new'] = new | |
3383 | self.hook(b'prepushkey', throw=True, **hookargs) |
|
3383 | self.hook(b'prepushkey', throw=True, **hookargs) | |
3384 | except error.HookAbort as exc: |
|
3384 | except error.HookAbort as exc: | |
3385 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) |
|
3385 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) | |
3386 | if exc.hint: |
|
3386 | if exc.hint: | |
3387 | self.ui.write_err(_(b"(%s)\n") % exc.hint) |
|
3387 | self.ui.write_err(_(b"(%s)\n") % exc.hint) | |
3388 | return False |
|
3388 | return False | |
3389 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) |
|
3389 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) | |
3390 | ret = pushkey.push(self, namespace, key, old, new) |
|
3390 | ret = pushkey.push(self, namespace, key, old, new) | |
3391 |
|
3391 | |||
3392 | def runhook(unused_success): |
|
3392 | def runhook(unused_success): | |
3393 | self.hook( |
|
3393 | self.hook( | |
3394 | b'pushkey', |
|
3394 | b'pushkey', | |
3395 | namespace=namespace, |
|
3395 | namespace=namespace, | |
3396 | key=key, |
|
3396 | key=key, | |
3397 | old=old, |
|
3397 | old=old, | |
3398 | new=new, |
|
3398 | new=new, | |
3399 | ret=ret, |
|
3399 | ret=ret, | |
3400 | ) |
|
3400 | ) | |
3401 |
|
3401 | |||
3402 | self._afterlock(runhook) |
|
3402 | self._afterlock(runhook) | |
3403 | return ret |
|
3403 | return ret | |
3404 |
|
3404 | |||
3405 | def listkeys(self, namespace): |
|
3405 | def listkeys(self, namespace): | |
3406 | self.hook(b'prelistkeys', throw=True, namespace=namespace) |
|
3406 | self.hook(b'prelistkeys', throw=True, namespace=namespace) | |
3407 | self.ui.debug(b'listing keys for "%s"\n' % namespace) |
|
3407 | self.ui.debug(b'listing keys for "%s"\n' % namespace) | |
3408 | values = pushkey.list(self, namespace) |
|
3408 | values = pushkey.list(self, namespace) | |
3409 | self.hook(b'listkeys', namespace=namespace, values=values) |
|
3409 | self.hook(b'listkeys', namespace=namespace, values=values) | |
3410 | return values |
|
3410 | return values | |
3411 |
|
3411 | |||
3412 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
3412 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
3413 | '''used to test argument passing over the wire''' |
|
3413 | '''used to test argument passing over the wire''' | |
3414 | return b"%s %s %s %s %s" % ( |
|
3414 | return b"%s %s %s %s %s" % ( | |
3415 | one, |
|
3415 | one, | |
3416 | two, |
|
3416 | two, | |
3417 | pycompat.bytestr(three), |
|
3417 | pycompat.bytestr(three), | |
3418 | pycompat.bytestr(four), |
|
3418 | pycompat.bytestr(four), | |
3419 | pycompat.bytestr(five), |
|
3419 | pycompat.bytestr(five), | |
3420 | ) |
|
3420 | ) | |
3421 |
|
3421 | |||
3422 | def savecommitmessage(self, text): |
|
3422 | def savecommitmessage(self, text): | |
3423 | fp = self.vfs(b'last-message.txt', b'wb') |
|
3423 | fp = self.vfs(b'last-message.txt', b'wb') | |
3424 | try: |
|
3424 | try: | |
3425 | fp.write(text) |
|
3425 | fp.write(text) | |
3426 | finally: |
|
3426 | finally: | |
3427 | fp.close() |
|
3427 | fp.close() | |
3428 | return self.pathto(fp.name[len(self.root) + 1 :]) |
|
3428 | return self.pathto(fp.name[len(self.root) + 1 :]) | |
3429 |
|
3429 | |||
3430 |
|
3430 | |||
3431 | # used to avoid circular references so destructors work |
|
3431 | # used to avoid circular references so destructors work | |
3432 | def aftertrans(files): |
|
3432 | def aftertrans(files): | |
3433 | renamefiles = [tuple(t) for t in files] |
|
3433 | renamefiles = [tuple(t) for t in files] | |
3434 |
|
3434 | |||
3435 | def a(): |
|
3435 | def a(): | |
3436 | for vfs, src, dest in renamefiles: |
|
3436 | for vfs, src, dest in renamefiles: | |
3437 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
3437 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
3438 | # leaving both src and dest on disk. delete dest to make sure |
|
3438 | # leaving both src and dest on disk. delete dest to make sure | |
3439 | # the rename couldn't be such a no-op. |
|
3439 | # the rename couldn't be such a no-op. | |
3440 | vfs.tryunlink(dest) |
|
3440 | vfs.tryunlink(dest) | |
3441 | try: |
|
3441 | try: | |
3442 | vfs.rename(src, dest) |
|
3442 | vfs.rename(src, dest) | |
3443 | except OSError: # journal file does not yet exist |
|
3443 | except OSError: # journal file does not yet exist | |
3444 | pass |
|
3444 | pass | |
3445 |
|
3445 | |||
3446 | return a |
|
3446 | return a | |
3447 |
|
3447 | |||
3448 |
|
3448 | |||
3449 | def undoname(fn): |
|
3449 | def undoname(fn): | |
3450 | base, name = os.path.split(fn) |
|
3450 | base, name = os.path.split(fn) | |
3451 | assert name.startswith(b'journal') |
|
3451 | assert name.startswith(b'journal') | |
3452 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) |
|
3452 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) | |
3453 |
|
3453 | |||
3454 |
|
3454 | |||
3455 | def instance(ui, path, create, intents=None, createopts=None): |
|
3455 | def instance(ui, path, create, intents=None, createopts=None): | |
3456 | localpath = util.urllocalpath(path) |
|
3456 | localpath = util.urllocalpath(path) | |
3457 | if create: |
|
3457 | if create: | |
3458 | createrepository(ui, localpath, createopts=createopts) |
|
3458 | createrepository(ui, localpath, createopts=createopts) | |
3459 |
|
3459 | |||
3460 | return makelocalrepository(ui, localpath, intents=intents) |
|
3460 | return makelocalrepository(ui, localpath, intents=intents) | |
3461 |
|
3461 | |||
3462 |
|
3462 | |||
3463 | def islocal(path): |
|
3463 | def islocal(path): | |
3464 | return True |
|
3464 | return True | |
3465 |
|
3465 | |||
3466 |
|
3466 | |||
3467 | def defaultcreateopts(ui, createopts=None): |
|
3467 | def defaultcreateopts(ui, createopts=None): | |
3468 | """Populate the default creation options for a repository. |
|
3468 | """Populate the default creation options for a repository. | |
3469 |
|
3469 | |||
3470 | A dictionary of explicitly requested creation options can be passed |
|
3470 | A dictionary of explicitly requested creation options can be passed | |
3471 | in. Missing keys will be populated. |
|
3471 | in. Missing keys will be populated. | |
3472 | """ |
|
3472 | """ | |
3473 | createopts = dict(createopts or {}) |
|
3473 | createopts = dict(createopts or {}) | |
3474 |
|
3474 | |||
3475 | if b'backend' not in createopts: |
|
3475 | if b'backend' not in createopts: | |
3476 | # experimental config: storage.new-repo-backend |
|
3476 | # experimental config: storage.new-repo-backend | |
3477 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') |
|
3477 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') | |
3478 |
|
3478 | |||
3479 | return createopts |
|
3479 | return createopts | |
3480 |
|
3480 | |||
3481 |
|
3481 | |||
3482 | def newreporequirements(ui, createopts): |
|
3482 | def newreporequirements(ui, createopts): | |
3483 | """Determine the set of requirements for a new local repository. |
|
3483 | """Determine the set of requirements for a new local repository. | |
3484 |
|
3484 | |||
3485 | Extensions can wrap this function to specify custom requirements for |
|
3485 | Extensions can wrap this function to specify custom requirements for | |
3486 | new repositories. |
|
3486 | new repositories. | |
3487 | """ |
|
3487 | """ | |
3488 | # If the repo is being created from a shared repository, we copy |
|
3488 | # If the repo is being created from a shared repository, we copy | |
3489 | # its requirements. |
|
3489 | # its requirements. | |
3490 | if b'sharedrepo' in createopts: |
|
3490 | if b'sharedrepo' in createopts: | |
3491 | requirements = set(createopts[b'sharedrepo'].requirements) |
|
3491 | requirements = set(createopts[b'sharedrepo'].requirements) | |
3492 | if createopts.get(b'sharedrelative'): |
|
3492 | if createopts.get(b'sharedrelative'): | |
3493 | requirements.add(b'relshared') |
|
3493 | requirements.add(b'relshared') | |
3494 | else: |
|
3494 | else: | |
3495 | requirements.add(b'shared') |
|
3495 | requirements.add(b'shared') | |
3496 |
|
3496 | |||
3497 | return requirements |
|
3497 | return requirements | |
3498 |
|
3498 | |||
3499 | if b'backend' not in createopts: |
|
3499 | if b'backend' not in createopts: | |
3500 | raise error.ProgrammingError( |
|
3500 | raise error.ProgrammingError( | |
3501 | b'backend key not present in createopts; ' |
|
3501 | b'backend key not present in createopts; ' | |
3502 | b'was defaultcreateopts() called?' |
|
3502 | b'was defaultcreateopts() called?' | |
3503 | ) |
|
3503 | ) | |
3504 |
|
3504 | |||
3505 | if createopts[b'backend'] != b'revlogv1': |
|
3505 | if createopts[b'backend'] != b'revlogv1': | |
3506 | raise error.Abort( |
|
3506 | raise error.Abort( | |
3507 | _( |
|
3507 | _( | |
3508 | b'unable to determine repository requirements for ' |
|
3508 | b'unable to determine repository requirements for ' | |
3509 | b'storage backend: %s' |
|
3509 | b'storage backend: %s' | |
3510 | ) |
|
3510 | ) | |
3511 | % createopts[b'backend'] |
|
3511 | % createopts[b'backend'] | |
3512 | ) |
|
3512 | ) | |
3513 |
|
3513 | |||
3514 | requirements = {b'revlogv1'} |
|
3514 | requirements = {b'revlogv1'} | |
3515 | if ui.configbool(b'format', b'usestore'): |
|
3515 | if ui.configbool(b'format', b'usestore'): | |
3516 | requirements.add(b'store') |
|
3516 | requirements.add(b'store') | |
3517 | if ui.configbool(b'format', b'usefncache'): |
|
3517 | if ui.configbool(b'format', b'usefncache'): | |
3518 | requirements.add(b'fncache') |
|
3518 | requirements.add(b'fncache') | |
3519 | if ui.configbool(b'format', b'dotencode'): |
|
3519 | if ui.configbool(b'format', b'dotencode'): | |
3520 | requirements.add(b'dotencode') |
|
3520 | requirements.add(b'dotencode') | |
3521 |
|
3521 | |||
3522 | compengine = ui.config(b'format', b'revlog-compression') |
|
3522 | compengine = ui.config(b'format', b'revlog-compression') | |
3523 | if compengine not in util.compengines: |
|
3523 | if compengine not in util.compengines: | |
3524 | raise error.Abort( |
|
3524 | raise error.Abort( | |
3525 | _( |
|
3525 | _( | |
3526 | b'compression engine %s defined by ' |
|
3526 | b'compression engine %s defined by ' | |
3527 | b'format.revlog-compression not available' |
|
3527 | b'format.revlog-compression not available' | |
3528 | ) |
|
3528 | ) | |
3529 | % compengine, |
|
3529 | % compengine, | |
3530 | hint=_( |
|
3530 | hint=_( | |
3531 | b'run "hg debuginstall" to list available ' |
|
3531 | b'run "hg debuginstall" to list available ' | |
3532 | b'compression engines' |
|
3532 | b'compression engines' | |
3533 | ), |
|
3533 | ), | |
3534 | ) |
|
3534 | ) | |
3535 |
|
3535 | |||
3536 | # zlib is the historical default and doesn't need an explicit requirement. |
|
3536 | # zlib is the historical default and doesn't need an explicit requirement. | |
3537 | elif compengine == b'zstd': |
|
3537 | elif compengine == b'zstd': | |
3538 | requirements.add(b'revlog-compression-zstd') |
|
3538 | requirements.add(b'revlog-compression-zstd') | |
3539 | elif compengine != b'zlib': |
|
3539 | elif compengine != b'zlib': | |
3540 | requirements.add(b'exp-compression-%s' % compengine) |
|
3540 | requirements.add(b'exp-compression-%s' % compengine) | |
3541 |
|
3541 | |||
3542 | if scmutil.gdinitconfig(ui): |
|
3542 | if scmutil.gdinitconfig(ui): | |
3543 | requirements.add(b'generaldelta') |
|
3543 | requirements.add(b'generaldelta') | |
3544 | if ui.configbool(b'format', b'sparse-revlog'): |
|
3544 | if ui.configbool(b'format', b'sparse-revlog'): | |
3545 | requirements.add(SPARSEREVLOG_REQUIREMENT) |
|
3545 | requirements.add(SPARSEREVLOG_REQUIREMENT) | |
3546 |
|
3546 | |||
3547 | # experimental config: format.exp-use-side-data |
|
3547 | # experimental config: format.exp-use-side-data | |
3548 | if ui.configbool(b'format', b'exp-use-side-data'): |
|
3548 | if ui.configbool(b'format', b'exp-use-side-data'): | |
3549 | requirements.add(SIDEDATA_REQUIREMENT) |
|
3549 | requirements.add(SIDEDATA_REQUIREMENT) | |
3550 | # experimental config: format.exp-use-copies-side-data-changeset |
|
3550 | # experimental config: format.exp-use-copies-side-data-changeset | |
3551 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): |
|
3551 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): | |
3552 | requirements.add(SIDEDATA_REQUIREMENT) |
|
3552 | requirements.add(SIDEDATA_REQUIREMENT) | |
3553 | requirements.add(COPIESSDC_REQUIREMENT) |
|
3553 | requirements.add(COPIESSDC_REQUIREMENT) | |
3554 | if ui.configbool(b'experimental', b'treemanifest'): |
|
3554 | if ui.configbool(b'experimental', b'treemanifest'): | |
3555 | requirements.add(b'treemanifest') |
|
3555 | requirements.add(b'treemanifest') | |
3556 |
|
3556 | |||
3557 | revlogv2 = ui.config(b'experimental', b'revlogv2') |
|
3557 | revlogv2 = ui.config(b'experimental', b'revlogv2') | |
3558 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': |
|
3558 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': | |
3559 | requirements.remove(b'revlogv1') |
|
3559 | requirements.remove(b'revlogv1') | |
3560 | # generaldelta is implied by revlogv2. |
|
3560 | # generaldelta is implied by revlogv2. | |
3561 | requirements.discard(b'generaldelta') |
|
3561 | requirements.discard(b'generaldelta') | |
3562 | requirements.add(REVLOGV2_REQUIREMENT) |
|
3562 | requirements.add(REVLOGV2_REQUIREMENT) | |
3563 | # experimental config: format.internal-phase |
|
3563 | # experimental config: format.internal-phase | |
3564 | if ui.configbool(b'format', b'internal-phase'): |
|
3564 | if ui.configbool(b'format', b'internal-phase'): | |
3565 | requirements.add(b'internal-phase') |
|
3565 | requirements.add(b'internal-phase') | |
3566 |
|
3566 | |||
3567 | if createopts.get(b'narrowfiles'): |
|
3567 | if createopts.get(b'narrowfiles'): | |
3568 | requirements.add(repository.NARROW_REQUIREMENT) |
|
3568 | requirements.add(repository.NARROW_REQUIREMENT) | |
3569 |
|
3569 | |||
3570 | if createopts.get(b'lfs'): |
|
3570 | if createopts.get(b'lfs'): | |
3571 | requirements.add(b'lfs') |
|
3571 | requirements.add(b'lfs') | |
3572 |
|
3572 | |||
3573 | if ui.configbool(b'format', b'bookmarks-in-store'): |
|
3573 | if ui.configbool(b'format', b'bookmarks-in-store'): | |
3574 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) |
|
3574 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) | |
3575 |
|
3575 | |||
3576 | return requirements |
|
3576 | return requirements | |
3577 |
|
3577 | |||
3578 |
|
3578 | |||
3579 | def filterknowncreateopts(ui, createopts): |
|
3579 | def filterknowncreateopts(ui, createopts): | |
3580 | """Filters a dict of repo creation options against options that are known. |
|
3580 | """Filters a dict of repo creation options against options that are known. | |
3581 |
|
3581 | |||
3582 | Receives a dict of repo creation options and returns a dict of those |
|
3582 | Receives a dict of repo creation options and returns a dict of those | |
3583 | options that we don't know how to handle. |
|
3583 | options that we don't know how to handle. | |
3584 |
|
3584 | |||
3585 | This function is called as part of repository creation. If the |
|
3585 | This function is called as part of repository creation. If the | |
3586 | returned dict contains any items, repository creation will not |
|
3586 | returned dict contains any items, repository creation will not | |
3587 | be allowed, as it means there was a request to create a repository |
|
3587 | be allowed, as it means there was a request to create a repository | |
3588 | with options not recognized by loaded code. |
|
3588 | with options not recognized by loaded code. | |
3589 |
|
3589 | |||
3590 | Extensions can wrap this function to filter out creation options |
|
3590 | Extensions can wrap this function to filter out creation options | |
3591 | they know how to handle. |
|
3591 | they know how to handle. | |
3592 | """ |
|
3592 | """ | |
3593 | known = { |
|
3593 | known = { | |
3594 | b'backend', |
|
3594 | b'backend', | |
3595 | b'lfs', |
|
3595 | b'lfs', | |
3596 | b'narrowfiles', |
|
3596 | b'narrowfiles', | |
3597 | b'sharedrepo', |
|
3597 | b'sharedrepo', | |
3598 | b'sharedrelative', |
|
3598 | b'sharedrelative', | |
3599 | b'shareditems', |
|
3599 | b'shareditems', | |
3600 | b'shallowfilestore', |
|
3600 | b'shallowfilestore', | |
3601 | } |
|
3601 | } | |
3602 |
|
3602 | |||
3603 | return {k: v for k, v in createopts.items() if k not in known} |
|
3603 | return {k: v for k, v in createopts.items() if k not in known} | |
3604 |
|
3604 | |||
3605 |
|
3605 | |||
3606 | def createrepository(ui, path, createopts=None): |
|
3606 | def createrepository(ui, path, createopts=None): | |
3607 | """Create a new repository in a vfs. |
|
3607 | """Create a new repository in a vfs. | |
3608 |
|
3608 | |||
3609 | ``path`` path to the new repo's working directory. |
|
3609 | ``path`` path to the new repo's working directory. | |
3610 | ``createopts`` options for the new repository. |
|
3610 | ``createopts`` options for the new repository. | |
3611 |
|
3611 | |||
3612 | The following keys for ``createopts`` are recognized: |
|
3612 | The following keys for ``createopts`` are recognized: | |
3613 |
|
3613 | |||
3614 | backend |
|
3614 | backend | |
3615 | The storage backend to use. |
|
3615 | The storage backend to use. | |
3616 | lfs |
|
3616 | lfs | |
3617 | Repository will be created with ``lfs`` requirement. The lfs extension |
|
3617 | Repository will be created with ``lfs`` requirement. The lfs extension | |
3618 | will automatically be loaded when the repository is accessed. |
|
3618 | will automatically be loaded when the repository is accessed. | |
3619 | narrowfiles |
|
3619 | narrowfiles | |
3620 | Set up repository to support narrow file storage. |
|
3620 | Set up repository to support narrow file storage. | |
3621 | sharedrepo |
|
3621 | sharedrepo | |
3622 | Repository object from which storage should be shared. |
|
3622 | Repository object from which storage should be shared. | |
3623 | sharedrelative |
|
3623 | sharedrelative | |
3624 | Boolean indicating if the path to the shared repo should be |
|
3624 | Boolean indicating if the path to the shared repo should be | |
3625 | stored as relative. By default, the pointer to the "parent" repo |
|
3625 | stored as relative. By default, the pointer to the "parent" repo | |
3626 | is stored as an absolute path. |
|
3626 | is stored as an absolute path. | |
3627 | shareditems |
|
3627 | shareditems | |
3628 | Set of items to share to the new repository (in addition to storage). |
|
3628 | Set of items to share to the new repository (in addition to storage). | |
3629 | shallowfilestore |
|
3629 | shallowfilestore | |
3630 | Indicates that storage for files should be shallow (not all ancestor |
|
3630 | Indicates that storage for files should be shallow (not all ancestor | |
3631 | revisions are known). |
|
3631 | revisions are known). | |
3632 | """ |
|
3632 | """ | |
3633 | createopts = defaultcreateopts(ui, createopts=createopts) |
|
3633 | createopts = defaultcreateopts(ui, createopts=createopts) | |
3634 |
|
3634 | |||
3635 | unknownopts = filterknowncreateopts(ui, createopts) |
|
3635 | unknownopts = filterknowncreateopts(ui, createopts) | |
3636 |
|
3636 | |||
3637 | if not isinstance(unknownopts, dict): |
|
3637 | if not isinstance(unknownopts, dict): | |
3638 | raise error.ProgrammingError( |
|
3638 | raise error.ProgrammingError( | |
3639 | b'filterknowncreateopts() did not return a dict' |
|
3639 | b'filterknowncreateopts() did not return a dict' | |
3640 | ) |
|
3640 | ) | |
3641 |
|
3641 | |||
3642 | if unknownopts: |
|
3642 | if unknownopts: | |
3643 | raise error.Abort( |
|
3643 | raise error.Abort( | |
3644 | _( |
|
3644 | _( | |
3645 | b'unable to create repository because of unknown ' |
|
3645 | b'unable to create repository because of unknown ' | |
3646 | b'creation option: %s' |
|
3646 | b'creation option: %s' | |
3647 | ) |
|
3647 | ) | |
3648 | % b', '.join(sorted(unknownopts)), |
|
3648 | % b', '.join(sorted(unknownopts)), | |
3649 | hint=_(b'is a required extension not loaded?'), |
|
3649 | hint=_(b'is a required extension not loaded?'), | |
3650 | ) |
|
3650 | ) | |
3651 |
|
3651 | |||
3652 | requirements = newreporequirements(ui, createopts=createopts) |
|
3652 | requirements = newreporequirements(ui, createopts=createopts) | |
3653 |
|
3653 | |||
3654 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
3654 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
3655 |
|
3655 | |||
3656 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
|
3656 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | |
3657 | if hgvfs.exists(): |
|
3657 | if hgvfs.exists(): | |
3658 | raise error.RepoError(_(b'repository %s already exists') % path) |
|
3658 | raise error.RepoError(_(b'repository %s already exists') % path) | |
3659 |
|
3659 | |||
3660 | if b'sharedrepo' in createopts: |
|
3660 | if b'sharedrepo' in createopts: | |
3661 | sharedpath = createopts[b'sharedrepo'].sharedpath |
|
3661 | sharedpath = createopts[b'sharedrepo'].sharedpath | |
3662 |
|
3662 | |||
3663 | if createopts.get(b'sharedrelative'): |
|
3663 | if createopts.get(b'sharedrelative'): | |
3664 | try: |
|
3664 | try: | |
3665 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) |
|
3665 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) | |
3666 | except (IOError, ValueError) as e: |
|
3666 | except (IOError, ValueError) as e: | |
3667 | # ValueError is raised on Windows if the drive letters differ |
|
3667 | # ValueError is raised on Windows if the drive letters differ | |
3668 | # on each path. |
|
3668 | # on each path. | |
3669 | raise error.Abort( |
|
3669 | raise error.Abort( | |
3670 | _(b'cannot calculate relative path'), |
|
3670 | _(b'cannot calculate relative path'), | |
3671 | hint=stringutil.forcebytestr(e), |
|
3671 | hint=stringutil.forcebytestr(e), | |
3672 | ) |
|
3672 | ) | |
3673 |
|
3673 | |||
3674 | if not wdirvfs.exists(): |
|
3674 | if not wdirvfs.exists(): | |
3675 | wdirvfs.makedirs() |
|
3675 | wdirvfs.makedirs() | |
3676 |
|
3676 | |||
3677 | hgvfs.makedir(notindexed=True) |
|
3677 | hgvfs.makedir(notindexed=True) | |
3678 | if b'sharedrepo' not in createopts: |
|
3678 | if b'sharedrepo' not in createopts: | |
3679 | hgvfs.mkdir(b'cache') |
|
3679 | hgvfs.mkdir(b'cache') | |
3680 | hgvfs.mkdir(b'wcache') |
|
3680 | hgvfs.mkdir(b'wcache') | |
3681 |
|
3681 | |||
3682 | if b'store' in requirements and b'sharedrepo' not in createopts: |
|
3682 | if b'store' in requirements and b'sharedrepo' not in createopts: | |
3683 | hgvfs.mkdir(b'store') |
|
3683 | hgvfs.mkdir(b'store') | |
3684 |
|
3684 | |||
3685 | # We create an invalid changelog outside the store so very old |
|
3685 | # We create an invalid changelog outside the store so very old | |
3686 | # Mercurial versions (which didn't know about the requirements |
|
3686 | # Mercurial versions (which didn't know about the requirements | |
3687 | # file) encounter an error on reading the changelog. This |
|
3687 | # file) encounter an error on reading the changelog. This | |
3688 | # effectively locks out old clients and prevents them from |
|
3688 | # effectively locks out old clients and prevents them from | |
3689 | # mucking with a repo in an unknown format. |
|
3689 | # mucking with a repo in an unknown format. | |
3690 | # |
|
3690 | # | |
3691 | # The revlog header has version 2, which won't be recognized by |
|
3691 | # The revlog header has version 2, which won't be recognized by | |
3692 | # such old clients. |
|
3692 | # such old clients. | |
3693 | hgvfs.append( |
|
3693 | hgvfs.append( | |
3694 | b'00changelog.i', |
|
3694 | b'00changelog.i', | |
3695 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' |
|
3695 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' | |
3696 | b'layout', |
|
3696 | b'layout', | |
3697 | ) |
|
3697 | ) | |
3698 |
|
3698 | |||
3699 | scmutil.writerequires(hgvfs, requirements) |
|
3699 | scmutil.writerequires(hgvfs, requirements) | |
3700 |
|
3700 | |||
3701 | # Write out file telling readers where to find the shared store. |
|
3701 | # Write out file telling readers where to find the shared store. | |
3702 | if b'sharedrepo' in createopts: |
|
3702 | if b'sharedrepo' in createopts: | |
3703 | hgvfs.write(b'sharedpath', sharedpath) |
|
3703 | hgvfs.write(b'sharedpath', sharedpath) | |
3704 |
|
3704 | |||
3705 | if createopts.get(b'shareditems'): |
|
3705 | if createopts.get(b'shareditems'): | |
3706 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' |
|
3706 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' | |
3707 | hgvfs.write(b'shared', shared) |
|
3707 | hgvfs.write(b'shared', shared) | |
3708 |
|
3708 | |||
3709 |
|
3709 | |||
3710 | def poisonrepository(repo): |
|
3710 | def poisonrepository(repo): | |
3711 | """Poison a repository instance so it can no longer be used.""" |
|
3711 | """Poison a repository instance so it can no longer be used.""" | |
3712 | # Perform any cleanup on the instance. |
|
3712 | # Perform any cleanup on the instance. | |
3713 | repo.close() |
|
3713 | repo.close() | |
3714 |
|
3714 | |||
3715 | # Our strategy is to replace the type of the object with one that |
|
3715 | # Our strategy is to replace the type of the object with one that | |
3716 | # has all attribute lookups result in error. |
|
3716 | # has all attribute lookups result in error. | |
3717 | # |
|
3717 | # | |
3718 | # But we have to allow the close() method because some constructors |
|
3718 | # But we have to allow the close() method because some constructors | |
3719 | # of repos call close() on repo references. |
|
3719 | # of repos call close() on repo references. | |
3720 | class poisonedrepository(object): |
|
3720 | class poisonedrepository(object): | |
3721 | def __getattribute__(self, item): |
|
3721 | def __getattribute__(self, item): | |
3722 | if item == 'close': |
|
3722 | if item == 'close': | |
3723 | return object.__getattribute__(self, item) |
|
3723 | return object.__getattribute__(self, item) | |
3724 |
|
3724 | |||
3725 | raise error.ProgrammingError( |
|
3725 | raise error.ProgrammingError( | |
3726 | b'repo instances should not be used after unshare' |
|
3726 | b'repo instances should not be used after unshare' | |
3727 | ) |
|
3727 | ) | |
3728 |
|
3728 | |||
3729 | def close(self): |
|
3729 | def close(self): | |
3730 | pass |
|
3730 | pass | |
3731 |
|
3731 | |||
3732 | # We may have a repoview, which intercepts __setattr__. So be sure |
|
3732 | # We may have a repoview, which intercepts __setattr__. So be sure | |
3733 | # we operate at the lowest level possible. |
|
3733 | # we operate at the lowest level possible. | |
3734 | object.__setattr__(repo, '__class__', poisonedrepository) |
|
3734 | object.__setattr__(repo, '__class__', poisonedrepository) |
@@ -1,2201 +1,2201 b'' | |||||
1 | # scmutil.py - Mercurial core utility functions |
|
1 | # scmutil.py - Mercurial core utility functions | |
2 | # |
|
2 | # | |
3 | # Copyright Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import glob |
|
11 | import glob | |
12 | import os |
|
12 | import os | |
13 | import posixpath |
|
13 | import posixpath | |
14 | import re |
|
14 | import re | |
15 | import subprocess |
|
15 | import subprocess | |
16 | import weakref |
|
16 | import weakref | |
17 |
|
17 | |||
18 | from .i18n import _ |
|
18 | from .i18n import _ | |
19 | from .node import ( |
|
19 | from .node import ( | |
20 | bin, |
|
20 | bin, | |
21 | hex, |
|
21 | hex, | |
22 | nullid, |
|
22 | nullid, | |
23 | nullrev, |
|
23 | nullrev, | |
24 | short, |
|
24 | short, | |
25 | wdirid, |
|
25 | wdirid, | |
26 | wdirrev, |
|
26 | wdirrev, | |
27 | ) |
|
27 | ) | |
28 | from .pycompat import getattr |
|
28 | from .pycompat import getattr | |
29 | from .thirdparty import attr |
|
29 | from .thirdparty import attr | |
30 | from . import ( |
|
30 | from . import ( | |
31 | copies as copiesmod, |
|
31 | copies as copiesmod, | |
32 | encoding, |
|
32 | encoding, | |
33 | error, |
|
33 | error, | |
34 | match as matchmod, |
|
34 | match as matchmod, | |
35 | obsolete, |
|
35 | obsolete, | |
36 | obsutil, |
|
36 | obsutil, | |
37 | pathutil, |
|
37 | pathutil, | |
38 | phases, |
|
38 | phases, | |
39 | policy, |
|
39 | policy, | |
40 | pycompat, |
|
40 | pycompat, | |
41 | revsetlang, |
|
41 | revsetlang, | |
42 | similar, |
|
42 | similar, | |
43 | smartset, |
|
43 | smartset, | |
44 | url, |
|
44 | url, | |
45 | util, |
|
45 | util, | |
46 | vfs, |
|
46 | vfs, | |
47 | ) |
|
47 | ) | |
48 |
|
48 | |||
49 | from .utils import ( |
|
49 | from .utils import ( | |
50 | hashutil, |
|
50 | hashutil, | |
51 | procutil, |
|
51 | procutil, | |
52 | stringutil, |
|
52 | stringutil, | |
53 | ) |
|
53 | ) | |
54 |
|
54 | |||
55 | if pycompat.iswindows: |
|
55 | if pycompat.iswindows: | |
56 | from . import scmwindows as scmplatform |
|
56 | from . import scmwindows as scmplatform | |
57 | else: |
|
57 | else: | |
58 | from . import scmposix as scmplatform |
|
58 | from . import scmposix as scmplatform | |
59 |
|
59 | |||
60 | parsers = policy.importmod('parsers') |
|
60 | parsers = policy.importmod('parsers') | |
61 | rustrevlog = policy.importrust('revlog') |
|
61 | rustrevlog = policy.importrust('revlog') | |
62 |
|
62 | |||
63 | termsize = scmplatform.termsize |
|
63 | termsize = scmplatform.termsize | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | @attr.s(slots=True, repr=False) |
|
66 | @attr.s(slots=True, repr=False) | |
67 | class status(object): |
|
67 | class status(object): | |
68 | '''Struct with a list of files per status. |
|
68 | '''Struct with a list of files per status. | |
69 |
|
69 | |||
70 | The 'deleted', 'unknown' and 'ignored' properties are only |
|
70 | The 'deleted', 'unknown' and 'ignored' properties are only | |
71 | relevant to the working copy. |
|
71 | relevant to the working copy. | |
72 | ''' |
|
72 | ''' | |
73 |
|
73 | |||
74 | modified = attr.ib(default=attr.Factory(list)) |
|
74 | modified = attr.ib(default=attr.Factory(list)) | |
75 | added = attr.ib(default=attr.Factory(list)) |
|
75 | added = attr.ib(default=attr.Factory(list)) | |
76 | removed = attr.ib(default=attr.Factory(list)) |
|
76 | removed = attr.ib(default=attr.Factory(list)) | |
77 | deleted = attr.ib(default=attr.Factory(list)) |
|
77 | deleted = attr.ib(default=attr.Factory(list)) | |
78 | unknown = attr.ib(default=attr.Factory(list)) |
|
78 | unknown = attr.ib(default=attr.Factory(list)) | |
79 | ignored = attr.ib(default=attr.Factory(list)) |
|
79 | ignored = attr.ib(default=attr.Factory(list)) | |
80 | clean = attr.ib(default=attr.Factory(list)) |
|
80 | clean = attr.ib(default=attr.Factory(list)) | |
81 |
|
81 | |||
82 | def __iter__(self): |
|
82 | def __iter__(self): | |
83 | yield self.modified |
|
83 | yield self.modified | |
84 | yield self.added |
|
84 | yield self.added | |
85 | yield self.removed |
|
85 | yield self.removed | |
86 | yield self.deleted |
|
86 | yield self.deleted | |
87 | yield self.unknown |
|
87 | yield self.unknown | |
88 | yield self.ignored |
|
88 | yield self.ignored | |
89 | yield self.clean |
|
89 | yield self.clean | |
90 |
|
90 | |||
91 | def __repr__(self): |
|
91 | def __repr__(self): | |
92 | return ( |
|
92 | return ( | |
93 | r'<status modified=%s, added=%s, removed=%s, deleted=%s, ' |
|
93 | r'<status modified=%s, added=%s, removed=%s, deleted=%s, ' | |
94 | r'unknown=%s, ignored=%s, clean=%s>' |
|
94 | r'unknown=%s, ignored=%s, clean=%s>' | |
95 | ) % tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self) |
|
95 | ) % tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self) | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | def itersubrepos(ctx1, ctx2): |
|
98 | def itersubrepos(ctx1, ctx2): | |
99 | """find subrepos in ctx1 or ctx2""" |
|
99 | """find subrepos in ctx1 or ctx2""" | |
100 | # Create a (subpath, ctx) mapping where we prefer subpaths from |
|
100 | # Create a (subpath, ctx) mapping where we prefer subpaths from | |
101 | # ctx1. The subpaths from ctx2 are important when the .hgsub file |
|
101 | # ctx1. The subpaths from ctx2 are important when the .hgsub file | |
102 | # has been modified (in ctx2) but not yet committed (in ctx1). |
|
102 | # has been modified (in ctx2) but not yet committed (in ctx1). | |
103 | subpaths = dict.fromkeys(ctx2.substate, ctx2) |
|
103 | subpaths = dict.fromkeys(ctx2.substate, ctx2) | |
104 | subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
|
104 | subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) | |
105 |
|
105 | |||
106 | missing = set() |
|
106 | missing = set() | |
107 |
|
107 | |||
108 | for subpath in ctx2.substate: |
|
108 | for subpath in ctx2.substate: | |
109 | if subpath not in ctx1.substate: |
|
109 | if subpath not in ctx1.substate: | |
110 | del subpaths[subpath] |
|
110 | del subpaths[subpath] | |
111 | missing.add(subpath) |
|
111 | missing.add(subpath) | |
112 |
|
112 | |||
113 | for subpath, ctx in sorted(pycompat.iteritems(subpaths)): |
|
113 | for subpath, ctx in sorted(pycompat.iteritems(subpaths)): | |
114 | yield subpath, ctx.sub(subpath) |
|
114 | yield subpath, ctx.sub(subpath) | |
115 |
|
115 | |||
116 | # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, |
|
116 | # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, | |
117 | # status and diff will have an accurate result when it does |
|
117 | # status and diff will have an accurate result when it does | |
118 | # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared |
|
118 | # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared | |
119 | # against itself. |
|
119 | # against itself. | |
120 | for subpath in missing: |
|
120 | for subpath in missing: | |
121 | yield subpath, ctx2.nullsub(subpath, ctx1) |
|
121 | yield subpath, ctx2.nullsub(subpath, ctx1) | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | def nochangesfound(ui, repo, excluded=None): |
|
124 | def nochangesfound(ui, repo, excluded=None): | |
125 | '''Report no changes for push/pull, excluded is None or a list of |
|
125 | '''Report no changes for push/pull, excluded is None or a list of | |
126 | nodes excluded from the push/pull. |
|
126 | nodes excluded from the push/pull. | |
127 | ''' |
|
127 | ''' | |
128 | secretlist = [] |
|
128 | secretlist = [] | |
129 | if excluded: |
|
129 | if excluded: | |
130 | for n in excluded: |
|
130 | for n in excluded: | |
131 | ctx = repo[n] |
|
131 | ctx = repo[n] | |
132 | if ctx.phase() >= phases.secret and not ctx.extinct(): |
|
132 | if ctx.phase() >= phases.secret and not ctx.extinct(): | |
133 | secretlist.append(n) |
|
133 | secretlist.append(n) | |
134 |
|
134 | |||
135 | if secretlist: |
|
135 | if secretlist: | |
136 | ui.status( |
|
136 | ui.status( | |
137 | _(b"no changes found (ignored %d secret changesets)\n") |
|
137 | _(b"no changes found (ignored %d secret changesets)\n") | |
138 | % len(secretlist) |
|
138 | % len(secretlist) | |
139 | ) |
|
139 | ) | |
140 | else: |
|
140 | else: | |
141 | ui.status(_(b"no changes found\n")) |
|
141 | ui.status(_(b"no changes found\n")) | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | def callcatch(ui, func): |
|
144 | def callcatch(ui, func): | |
145 | """call func() with global exception handling |
|
145 | """call func() with global exception handling | |
146 |
|
146 | |||
147 | return func() if no exception happens. otherwise do some error handling |
|
147 | return func() if no exception happens. otherwise do some error handling | |
148 | and return an exit code accordingly. does not handle all exceptions. |
|
148 | and return an exit code accordingly. does not handle all exceptions. | |
149 | """ |
|
149 | """ | |
150 | try: |
|
150 | try: | |
151 | try: |
|
151 | try: | |
152 | return func() |
|
152 | return func() | |
153 | except: # re-raises |
|
153 | except: # re-raises | |
154 | ui.traceback() |
|
154 | ui.traceback() | |
155 | raise |
|
155 | raise | |
156 | # Global exception handling, alphabetically |
|
156 | # Global exception handling, alphabetically | |
157 | # Mercurial-specific first, followed by built-in and library exceptions |
|
157 | # Mercurial-specific first, followed by built-in and library exceptions | |
158 | except error.LockHeld as inst: |
|
158 | except error.LockHeld as inst: | |
159 | if inst.errno == errno.ETIMEDOUT: |
|
159 | if inst.errno == errno.ETIMEDOUT: | |
160 | reason = _(b'timed out waiting for lock held by %r') % ( |
|
160 | reason = _(b'timed out waiting for lock held by %r') % ( | |
161 | pycompat.bytestr(inst.locker) |
|
161 | pycompat.bytestr(inst.locker) | |
162 | ) |
|
162 | ) | |
163 | else: |
|
163 | else: | |
164 | reason = _(b'lock held by %r') % inst.locker |
|
164 | reason = _(b'lock held by %r') % inst.locker | |
165 | ui.error( |
|
165 | ui.error( | |
166 | _(b"abort: %s: %s\n") |
|
166 | _(b"abort: %s: %s\n") | |
167 | % (inst.desc or stringutil.forcebytestr(inst.filename), reason) |
|
167 | % (inst.desc or stringutil.forcebytestr(inst.filename), reason) | |
168 | ) |
|
168 | ) | |
169 | if not inst.locker: |
|
169 | if not inst.locker: | |
170 | ui.error(_(b"(lock might be very busy)\n")) |
|
170 | ui.error(_(b"(lock might be very busy)\n")) | |
171 | except error.LockUnavailable as inst: |
|
171 | except error.LockUnavailable as inst: | |
172 | ui.error( |
|
172 | ui.error( | |
173 | _(b"abort: could not lock %s: %s\n") |
|
173 | _(b"abort: could not lock %s: %s\n") | |
174 | % ( |
|
174 | % ( | |
175 | inst.desc or stringutil.forcebytestr(inst.filename), |
|
175 | inst.desc or stringutil.forcebytestr(inst.filename), | |
176 | encoding.strtolocal(inst.strerror), |
|
176 | encoding.strtolocal(inst.strerror), | |
177 | ) |
|
177 | ) | |
178 | ) |
|
178 | ) | |
179 | except error.OutOfBandError as inst: |
|
179 | except error.OutOfBandError as inst: | |
180 | if inst.args: |
|
180 | if inst.args: | |
181 | msg = _(b"abort: remote error:\n") |
|
181 | msg = _(b"abort: remote error:\n") | |
182 | else: |
|
182 | else: | |
183 | msg = _(b"abort: remote error\n") |
|
183 | msg = _(b"abort: remote error\n") | |
184 | ui.error(msg) |
|
184 | ui.error(msg) | |
185 | if inst.args: |
|
185 | if inst.args: | |
186 | ui.error(b''.join(inst.args)) |
|
186 | ui.error(b''.join(inst.args)) | |
187 | if inst.hint: |
|
187 | if inst.hint: | |
188 | ui.error(b'(%s)\n' % inst.hint) |
|
188 | ui.error(b'(%s)\n' % inst.hint) | |
189 | except error.RepoError as inst: |
|
189 | except error.RepoError as inst: | |
190 | ui.error(_(b"abort: %s!\n") % inst) |
|
190 | ui.error(_(b"abort: %s!\n") % inst) | |
191 | if inst.hint: |
|
191 | if inst.hint: | |
192 | ui.error(_(b"(%s)\n") % inst.hint) |
|
192 | ui.error(_(b"(%s)\n") % inst.hint) | |
193 | except error.ResponseError as inst: |
|
193 | except error.ResponseError as inst: | |
194 | ui.error(_(b"abort: %s") % inst.args[0]) |
|
194 | ui.error(_(b"abort: %s") % inst.args[0]) | |
195 | msg = inst.args[1] |
|
195 | msg = inst.args[1] | |
196 | if isinstance(msg, type(u'')): |
|
196 | if isinstance(msg, type(u'')): | |
197 | msg = pycompat.sysbytes(msg) |
|
197 | msg = pycompat.sysbytes(msg) | |
198 | if not isinstance(msg, bytes): |
|
198 | if not isinstance(msg, bytes): | |
199 | ui.error(b" %r\n" % (msg,)) |
|
199 | ui.error(b" %r\n" % (msg,)) | |
200 | elif not msg: |
|
200 | elif not msg: | |
201 | ui.error(_(b" empty string\n")) |
|
201 | ui.error(_(b" empty string\n")) | |
202 | else: |
|
202 | else: | |
203 | ui.error(b"\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) |
|
203 | ui.error(b"\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) | |
204 | except error.CensoredNodeError as inst: |
|
204 | except error.CensoredNodeError as inst: | |
205 | ui.error(_(b"abort: file censored %s!\n") % inst) |
|
205 | ui.error(_(b"abort: file censored %s!\n") % inst) | |
206 | except error.StorageError as inst: |
|
206 | except error.StorageError as inst: | |
207 | ui.error(_(b"abort: %s!\n") % inst) |
|
207 | ui.error(_(b"abort: %s!\n") % inst) | |
208 | if inst.hint: |
|
208 | if inst.hint: | |
209 | ui.error(_(b"(%s)\n") % inst.hint) |
|
209 | ui.error(_(b"(%s)\n") % inst.hint) | |
210 | except error.InterventionRequired as inst: |
|
210 | except error.InterventionRequired as inst: | |
211 | ui.error(b"%s\n" % inst) |
|
211 | ui.error(b"%s\n" % inst) | |
212 | if inst.hint: |
|
212 | if inst.hint: | |
213 | ui.error(_(b"(%s)\n") % inst.hint) |
|
213 | ui.error(_(b"(%s)\n") % inst.hint) | |
214 | return 1 |
|
214 | return 1 | |
215 | except error.WdirUnsupported: |
|
215 | except error.WdirUnsupported: | |
216 | ui.error(_(b"abort: working directory revision cannot be specified\n")) |
|
216 | ui.error(_(b"abort: working directory revision cannot be specified\n")) | |
217 | except error.Abort as inst: |
|
217 | except error.Abort as inst: | |
218 | ui.error(_(b"abort: %s\n") % inst) |
|
218 | ui.error(_(b"abort: %s\n") % inst) | |
219 | if inst.hint: |
|
219 | if inst.hint: | |
220 | ui.error(_(b"(%s)\n") % inst.hint) |
|
220 | ui.error(_(b"(%s)\n") % inst.hint) | |
221 | except ImportError as inst: |
|
221 | except ImportError as inst: | |
222 | ui.error(_(b"abort: %s!\n") % stringutil.forcebytestr(inst)) |
|
222 | ui.error(_(b"abort: %s!\n") % stringutil.forcebytestr(inst)) | |
223 | m = stringutil.forcebytestr(inst).split()[-1] |
|
223 | m = stringutil.forcebytestr(inst).split()[-1] | |
224 | if m in b"mpatch bdiff".split(): |
|
224 | if m in b"mpatch bdiff".split(): | |
225 | ui.error(_(b"(did you forget to compile extensions?)\n")) |
|
225 | ui.error(_(b"(did you forget to compile extensions?)\n")) | |
226 | elif m in b"zlib".split(): |
|
226 | elif m in b"zlib".split(): | |
227 | ui.error(_(b"(is your Python install correct?)\n")) |
|
227 | ui.error(_(b"(is your Python install correct?)\n")) | |
228 | except (IOError, OSError) as inst: |
|
228 | except (IOError, OSError) as inst: | |
229 | if util.safehasattr(inst, b"code"): # HTTPError |
|
229 | if util.safehasattr(inst, b"code"): # HTTPError | |
230 | ui.error(_(b"abort: %s\n") % stringutil.forcebytestr(inst)) |
|
230 | ui.error(_(b"abort: %s\n") % stringutil.forcebytestr(inst)) | |
231 | elif util.safehasattr(inst, b"reason"): # URLError or SSLError |
|
231 | elif util.safehasattr(inst, b"reason"): # URLError or SSLError | |
232 | try: # usually it is in the form (errno, strerror) |
|
232 | try: # usually it is in the form (errno, strerror) | |
233 | reason = inst.reason.args[1] |
|
233 | reason = inst.reason.args[1] | |
234 | except (AttributeError, IndexError): |
|
234 | except (AttributeError, IndexError): | |
235 | # it might be anything, for example a string |
|
235 | # it might be anything, for example a string | |
236 | reason = inst.reason |
|
236 | reason = inst.reason | |
237 | if isinstance(reason, pycompat.unicode): |
|
237 | if isinstance(reason, pycompat.unicode): | |
238 | # SSLError of Python 2.7.9 contains a unicode |
|
238 | # SSLError of Python 2.7.9 contains a unicode | |
239 | reason = encoding.unitolocal(reason) |
|
239 | reason = encoding.unitolocal(reason) | |
240 | ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) |
|
240 | ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) | |
241 | elif ( |
|
241 | elif ( | |
242 | util.safehasattr(inst, b"args") |
|
242 | util.safehasattr(inst, b"args") | |
243 | and inst.args |
|
243 | and inst.args | |
244 | and inst.args[0] == errno.EPIPE |
|
244 | and inst.args[0] == errno.EPIPE | |
245 | ): |
|
245 | ): | |
246 | pass |
|
246 | pass | |
247 | elif getattr(inst, "strerror", None): # common IOError or OSError |
|
247 | elif getattr(inst, "strerror", None): # common IOError or OSError | |
248 | if getattr(inst, "filename", None) is not None: |
|
248 | if getattr(inst, "filename", None) is not None: | |
249 | ui.error( |
|
249 | ui.error( | |
250 | _(b"abort: %s: '%s'\n") |
|
250 | _(b"abort: %s: '%s'\n") | |
251 | % ( |
|
251 | % ( | |
252 | encoding.strtolocal(inst.strerror), |
|
252 | encoding.strtolocal(inst.strerror), | |
253 | stringutil.forcebytestr(inst.filename), |
|
253 | stringutil.forcebytestr(inst.filename), | |
254 | ) |
|
254 | ) | |
255 | ) |
|
255 | ) | |
256 | else: |
|
256 | else: | |
257 | ui.error(_(b"abort: %s\n") % encoding.strtolocal(inst.strerror)) |
|
257 | ui.error(_(b"abort: %s\n") % encoding.strtolocal(inst.strerror)) | |
258 | else: # suspicious IOError |
|
258 | else: # suspicious IOError | |
259 | raise |
|
259 | raise | |
260 | except MemoryError: |
|
260 | except MemoryError: | |
261 | ui.error(_(b"abort: out of memory\n")) |
|
261 | ui.error(_(b"abort: out of memory\n")) | |
262 | except SystemExit as inst: |
|
262 | except SystemExit as inst: | |
263 | # Commands shouldn't sys.exit directly, but give a return code. |
|
263 | # Commands shouldn't sys.exit directly, but give a return code. | |
264 | # Just in case catch this and and pass exit code to caller. |
|
264 | # Just in case catch this and and pass exit code to caller. | |
265 | return inst.code |
|
265 | return inst.code | |
266 |
|
266 | |||
267 | return -1 |
|
267 | return -1 | |
268 |
|
268 | |||
269 |
|
269 | |||
270 | def checknewlabel(repo, lbl, kind): |
|
270 | def checknewlabel(repo, lbl, kind): | |
271 | # Do not use the "kind" parameter in ui output. |
|
271 | # Do not use the "kind" parameter in ui output. | |
272 | # It makes strings difficult to translate. |
|
272 | # It makes strings difficult to translate. | |
273 | if lbl in [b'tip', b'.', b'null']: |
|
273 | if lbl in [b'tip', b'.', b'null']: | |
274 | raise error.Abort(_(b"the name '%s' is reserved") % lbl) |
|
274 | raise error.Abort(_(b"the name '%s' is reserved") % lbl) | |
275 | for c in (b':', b'\0', b'\n', b'\r'): |
|
275 | for c in (b':', b'\0', b'\n', b'\r'): | |
276 | if c in lbl: |
|
276 | if c in lbl: | |
277 | raise error.Abort( |
|
277 | raise error.Abort( | |
278 | _(b"%r cannot be used in a name") % pycompat.bytestr(c) |
|
278 | _(b"%r cannot be used in a name") % pycompat.bytestr(c) | |
279 | ) |
|
279 | ) | |
280 | try: |
|
280 | try: | |
281 | int(lbl) |
|
281 | int(lbl) | |
282 | raise error.Abort(_(b"cannot use an integer as a name")) |
|
282 | raise error.Abort(_(b"cannot use an integer as a name")) | |
283 | except ValueError: |
|
283 | except ValueError: | |
284 | pass |
|
284 | pass | |
285 | if lbl.strip() != lbl: |
|
285 | if lbl.strip() != lbl: | |
286 | raise error.Abort(_(b"leading or trailing whitespace in name %r") % lbl) |
|
286 | raise error.Abort(_(b"leading or trailing whitespace in name %r") % lbl) | |
287 |
|
287 | |||
288 |
|
288 | |||
289 | def checkfilename(f): |
|
289 | def checkfilename(f): | |
290 | '''Check that the filename f is an acceptable filename for a tracked file''' |
|
290 | '''Check that the filename f is an acceptable filename for a tracked file''' | |
291 | if b'\r' in f or b'\n' in f: |
|
291 | if b'\r' in f or b'\n' in f: | |
292 | raise error.Abort( |
|
292 | raise error.Abort( | |
293 | _(b"'\\n' and '\\r' disallowed in filenames: %r") |
|
293 | _(b"'\\n' and '\\r' disallowed in filenames: %r") | |
294 | % pycompat.bytestr(f) |
|
294 | % pycompat.bytestr(f) | |
295 | ) |
|
295 | ) | |
296 |
|
296 | |||
297 |
|
297 | |||
298 | def checkportable(ui, f): |
|
298 | def checkportable(ui, f): | |
299 | '''Check if filename f is portable and warn or abort depending on config''' |
|
299 | '''Check if filename f is portable and warn or abort depending on config''' | |
300 | checkfilename(f) |
|
300 | checkfilename(f) | |
301 | abort, warn = checkportabilityalert(ui) |
|
301 | abort, warn = checkportabilityalert(ui) | |
302 | if abort or warn: |
|
302 | if abort or warn: | |
303 | msg = util.checkwinfilename(f) |
|
303 | msg = util.checkwinfilename(f) | |
304 | if msg: |
|
304 | if msg: | |
305 | msg = b"%s: %s" % (msg, procutil.shellquote(f)) |
|
305 | msg = b"%s: %s" % (msg, procutil.shellquote(f)) | |
306 | if abort: |
|
306 | if abort: | |
307 | raise error.Abort(msg) |
|
307 | raise error.Abort(msg) | |
308 | ui.warn(_(b"warning: %s\n") % msg) |
|
308 | ui.warn(_(b"warning: %s\n") % msg) | |
309 |
|
309 | |||
310 |
|
310 | |||
311 | def checkportabilityalert(ui): |
|
311 | def checkportabilityalert(ui): | |
312 | '''check if the user's config requests nothing, a warning, or abort for |
|
312 | '''check if the user's config requests nothing, a warning, or abort for | |
313 | non-portable filenames''' |
|
313 | non-portable filenames''' | |
314 | val = ui.config(b'ui', b'portablefilenames') |
|
314 | val = ui.config(b'ui', b'portablefilenames') | |
315 | lval = val.lower() |
|
315 | lval = val.lower() | |
316 | bval = stringutil.parsebool(val) |
|
316 | bval = stringutil.parsebool(val) | |
317 | abort = pycompat.iswindows or lval == b'abort' |
|
317 | abort = pycompat.iswindows or lval == b'abort' | |
318 | warn = bval or lval == b'warn' |
|
318 | warn = bval or lval == b'warn' | |
319 | if bval is None and not (warn or abort or lval == b'ignore'): |
|
319 | if bval is None and not (warn or abort or lval == b'ignore'): | |
320 | raise error.ConfigError( |
|
320 | raise error.ConfigError( | |
321 | _(b"ui.portablefilenames value is invalid ('%s')") % val |
|
321 | _(b"ui.portablefilenames value is invalid ('%s')") % val | |
322 | ) |
|
322 | ) | |
323 | return abort, warn |
|
323 | return abort, warn | |
324 |
|
324 | |||
325 |
|
325 | |||
326 | class casecollisionauditor(object): |
|
326 | class casecollisionauditor(object): | |
327 | def __init__(self, ui, abort, dirstate): |
|
327 | def __init__(self, ui, abort, dirstate): | |
328 | self._ui = ui |
|
328 | self._ui = ui | |
329 | self._abort = abort |
|
329 | self._abort = abort | |
330 | allfiles = b'\0'.join(dirstate) |
|
330 | allfiles = b'\0'.join(dirstate) | |
331 | self._loweredfiles = set(encoding.lower(allfiles).split(b'\0')) |
|
331 | self._loweredfiles = set(encoding.lower(allfiles).split(b'\0')) | |
332 | self._dirstate = dirstate |
|
332 | self._dirstate = dirstate | |
333 | # The purpose of _newfiles is so that we don't complain about |
|
333 | # The purpose of _newfiles is so that we don't complain about | |
334 | # case collisions if someone were to call this object with the |
|
334 | # case collisions if someone were to call this object with the | |
335 | # same filename twice. |
|
335 | # same filename twice. | |
336 | self._newfiles = set() |
|
336 | self._newfiles = set() | |
337 |
|
337 | |||
338 | def __call__(self, f): |
|
338 | def __call__(self, f): | |
339 | if f in self._newfiles: |
|
339 | if f in self._newfiles: | |
340 | return |
|
340 | return | |
341 | fl = encoding.lower(f) |
|
341 | fl = encoding.lower(f) | |
342 | if fl in self._loweredfiles and f not in self._dirstate: |
|
342 | if fl in self._loweredfiles and f not in self._dirstate: | |
343 | msg = _(b'possible case-folding collision for %s') % f |
|
343 | msg = _(b'possible case-folding collision for %s') % f | |
344 | if self._abort: |
|
344 | if self._abort: | |
345 | raise error.Abort(msg) |
|
345 | raise error.Abort(msg) | |
346 | self._ui.warn(_(b"warning: %s\n") % msg) |
|
346 | self._ui.warn(_(b"warning: %s\n") % msg) | |
347 | self._loweredfiles.add(fl) |
|
347 | self._loweredfiles.add(fl) | |
348 | self._newfiles.add(f) |
|
348 | self._newfiles.add(f) | |
349 |
|
349 | |||
350 |
|
350 | |||
351 | def filteredhash(repo, maxrev): |
|
351 | def filteredhash(repo, maxrev): | |
352 | """build hash of filtered revisions in the current repoview. |
|
352 | """build hash of filtered revisions in the current repoview. | |
353 |
|
353 | |||
354 | Multiple caches perform up-to-date validation by checking that the |
|
354 | Multiple caches perform up-to-date validation by checking that the | |
355 | tiprev and tipnode stored in the cache file match the current repository. |
|
355 | tiprev and tipnode stored in the cache file match the current repository. | |
356 | However, this is not sufficient for validating repoviews because the set |
|
356 | However, this is not sufficient for validating repoviews because the set | |
357 | of revisions in the view may change without the repository tiprev and |
|
357 | of revisions in the view may change without the repository tiprev and | |
358 | tipnode changing. |
|
358 | tipnode changing. | |
359 |
|
359 | |||
360 | This function hashes all the revs filtered from the view and returns |
|
360 | This function hashes all the revs filtered from the view and returns | |
361 | that SHA-1 digest. |
|
361 | that SHA-1 digest. | |
362 | """ |
|
362 | """ | |
363 | cl = repo.changelog |
|
363 | cl = repo.changelog | |
364 | if not cl.filteredrevs: |
|
364 | if not cl.filteredrevs: | |
365 | return None |
|
365 | return None | |
366 | key = None |
|
366 | key = None | |
367 | revs = sorted(r for r in cl.filteredrevs if r <= maxrev) |
|
367 | revs = sorted(r for r in cl.filteredrevs if r <= maxrev) | |
368 | if revs: |
|
368 | if revs: | |
369 | s = hashutil.sha1() |
|
369 | s = hashutil.sha1() | |
370 | for rev in revs: |
|
370 | for rev in revs: | |
371 | s.update(b'%d;' % rev) |
|
371 | s.update(b'%d;' % rev) | |
372 | key = s.digest() |
|
372 | key = s.digest() | |
373 | return key |
|
373 | return key | |
374 |
|
374 | |||
375 |
|
375 | |||
376 | def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): |
|
376 | def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): | |
377 | '''yield every hg repository under path, always recursively. |
|
377 | '''yield every hg repository under path, always recursively. | |
378 | The recurse flag will only control recursion into repo working dirs''' |
|
378 | The recurse flag will only control recursion into repo working dirs''' | |
379 |
|
379 | |||
380 | def errhandler(err): |
|
380 | def errhandler(err): | |
381 | if err.filename == path: |
|
381 | if err.filename == path: | |
382 | raise err |
|
382 | raise err | |
383 |
|
383 | |||
384 | samestat = getattr(os.path, 'samestat', None) |
|
384 | samestat = getattr(os.path, 'samestat', None) | |
385 | if followsym and samestat is not None: |
|
385 | if followsym and samestat is not None: | |
386 |
|
386 | |||
387 | def adddir(dirlst, dirname): |
|
387 | def adddir(dirlst, dirname): | |
388 | dirstat = os.stat(dirname) |
|
388 | dirstat = os.stat(dirname) | |
389 | match = any(samestat(dirstat, lstdirstat) for lstdirstat in dirlst) |
|
389 | match = any(samestat(dirstat, lstdirstat) for lstdirstat in dirlst) | |
390 | if not match: |
|
390 | if not match: | |
391 | dirlst.append(dirstat) |
|
391 | dirlst.append(dirstat) | |
392 | return not match |
|
392 | return not match | |
393 |
|
393 | |||
394 | else: |
|
394 | else: | |
395 | followsym = False |
|
395 | followsym = False | |
396 |
|
396 | |||
397 | if (seen_dirs is None) and followsym: |
|
397 | if (seen_dirs is None) and followsym: | |
398 | seen_dirs = [] |
|
398 | seen_dirs = [] | |
399 | adddir(seen_dirs, path) |
|
399 | adddir(seen_dirs, path) | |
400 | for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): |
|
400 | for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): | |
401 | dirs.sort() |
|
401 | dirs.sort() | |
402 | if b'.hg' in dirs: |
|
402 | if b'.hg' in dirs: | |
403 | yield root # found a repository |
|
403 | yield root # found a repository | |
404 | qroot = os.path.join(root, b'.hg', b'patches') |
|
404 | qroot = os.path.join(root, b'.hg', b'patches') | |
405 | if os.path.isdir(os.path.join(qroot, b'.hg')): |
|
405 | if os.path.isdir(os.path.join(qroot, b'.hg')): | |
406 | yield qroot # we have a patch queue repo here |
|
406 | yield qroot # we have a patch queue repo here | |
407 | if recurse: |
|
407 | if recurse: | |
408 | # avoid recursing inside the .hg directory |
|
408 | # avoid recursing inside the .hg directory | |
409 | dirs.remove(b'.hg') |
|
409 | dirs.remove(b'.hg') | |
410 | else: |
|
410 | else: | |
411 | dirs[:] = [] # don't descend further |
|
411 | dirs[:] = [] # don't descend further | |
412 | elif followsym: |
|
412 | elif followsym: | |
413 | newdirs = [] |
|
413 | newdirs = [] | |
414 | for d in dirs: |
|
414 | for d in dirs: | |
415 | fname = os.path.join(root, d) |
|
415 | fname = os.path.join(root, d) | |
416 | if adddir(seen_dirs, fname): |
|
416 | if adddir(seen_dirs, fname): | |
417 | if os.path.islink(fname): |
|
417 | if os.path.islink(fname): | |
418 | for hgname in walkrepos(fname, True, seen_dirs): |
|
418 | for hgname in walkrepos(fname, True, seen_dirs): | |
419 | yield hgname |
|
419 | yield hgname | |
420 | else: |
|
420 | else: | |
421 | newdirs.append(d) |
|
421 | newdirs.append(d) | |
422 | dirs[:] = newdirs |
|
422 | dirs[:] = newdirs | |
423 |
|
423 | |||
424 |
|
424 | |||
425 | def binnode(ctx): |
|
425 | def binnode(ctx): | |
426 | """Return binary node id for a given basectx""" |
|
426 | """Return binary node id for a given basectx""" | |
427 | node = ctx.node() |
|
427 | node = ctx.node() | |
428 | if node is None: |
|
428 | if node is None: | |
429 | return wdirid |
|
429 | return wdirid | |
430 | return node |
|
430 | return node | |
431 |
|
431 | |||
432 |
|
432 | |||
433 | def intrev(ctx): |
|
433 | def intrev(ctx): | |
434 | """Return integer for a given basectx that can be used in comparison or |
|
434 | """Return integer for a given basectx that can be used in comparison or | |
435 | arithmetic operation""" |
|
435 | arithmetic operation""" | |
436 | rev = ctx.rev() |
|
436 | rev = ctx.rev() | |
437 | if rev is None: |
|
437 | if rev is None: | |
438 | return wdirrev |
|
438 | return wdirrev | |
439 | return rev |
|
439 | return rev | |
440 |
|
440 | |||
441 |
|
441 | |||
442 | def formatchangeid(ctx): |
|
442 | def formatchangeid(ctx): | |
443 | """Format changectx as '{rev}:{node|formatnode}', which is the default |
|
443 | """Format changectx as '{rev}:{node|formatnode}', which is the default | |
444 | template provided by logcmdutil.changesettemplater""" |
|
444 | template provided by logcmdutil.changesettemplater""" | |
445 | repo = ctx.repo() |
|
445 | repo = ctx.repo() | |
446 | return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) |
|
446 | return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) | |
447 |
|
447 | |||
448 |
|
448 | |||
449 | def formatrevnode(ui, rev, node): |
|
449 | def formatrevnode(ui, rev, node): | |
450 | """Format given revision and node depending on the current verbosity""" |
|
450 | """Format given revision and node depending on the current verbosity""" | |
451 | if ui.debugflag: |
|
451 | if ui.debugflag: | |
452 | hexfunc = hex |
|
452 | hexfunc = hex | |
453 | else: |
|
453 | else: | |
454 | hexfunc = short |
|
454 | hexfunc = short | |
455 | return b'%d:%s' % (rev, hexfunc(node)) |
|
455 | return b'%d:%s' % (rev, hexfunc(node)) | |
456 |
|
456 | |||
457 |
|
457 | |||
458 | def resolvehexnodeidprefix(repo, prefix): |
|
458 | def resolvehexnodeidprefix(repo, prefix): | |
459 | if prefix.startswith(b'x') and repo.ui.configbool( |
|
459 | if prefix.startswith(b'x') and repo.ui.configbool( | |
460 | b'experimental', b'revisions.prefixhexnode' |
|
460 | b'experimental', b'revisions.prefixhexnode' | |
461 | ): |
|
461 | ): | |
462 | prefix = prefix[1:] |
|
462 | prefix = prefix[1:] | |
463 | try: |
|
463 | try: | |
464 | # Uses unfiltered repo because it's faster when prefix is ambiguous/ |
|
464 | # Uses unfiltered repo because it's faster when prefix is ambiguous/ | |
465 | # This matches the shortesthexnodeidprefix() function below. |
|
465 | # This matches the shortesthexnodeidprefix() function below. | |
466 | node = repo.unfiltered().changelog._partialmatch(prefix) |
|
466 | node = repo.unfiltered().changelog._partialmatch(prefix) | |
467 | except error.AmbiguousPrefixLookupError: |
|
467 | except error.AmbiguousPrefixLookupError: | |
468 | revset = repo.ui.config( |
|
468 | revset = repo.ui.config( | |
469 | b'experimental', b'revisions.disambiguatewithin' |
|
469 | b'experimental', b'revisions.disambiguatewithin' | |
470 | ) |
|
470 | ) | |
471 | if revset: |
|
471 | if revset: | |
472 | # Clear config to avoid infinite recursion |
|
472 | # Clear config to avoid infinite recursion | |
473 | configoverrides = { |
|
473 | configoverrides = { | |
474 | (b'experimental', b'revisions.disambiguatewithin'): None |
|
474 | (b'experimental', b'revisions.disambiguatewithin'): None | |
475 | } |
|
475 | } | |
476 | with repo.ui.configoverride(configoverrides): |
|
476 | with repo.ui.configoverride(configoverrides): | |
477 | revs = repo.anyrevs([revset], user=True) |
|
477 | revs = repo.anyrevs([revset], user=True) | |
478 | matches = [] |
|
478 | matches = [] | |
479 | for rev in revs: |
|
479 | for rev in revs: | |
480 | node = repo.changelog.node(rev) |
|
480 | node = repo.changelog.node(rev) | |
481 | if hex(node).startswith(prefix): |
|
481 | if hex(node).startswith(prefix): | |
482 | matches.append(node) |
|
482 | matches.append(node) | |
483 | if len(matches) == 1: |
|
483 | if len(matches) == 1: | |
484 | return matches[0] |
|
484 | return matches[0] | |
485 | raise |
|
485 | raise | |
486 | if node is None: |
|
486 | if node is None: | |
487 | return |
|
487 | return | |
488 | repo.changelog.rev(node) # make sure node isn't filtered |
|
488 | repo.changelog.rev(node) # make sure node isn't filtered | |
489 | return node |
|
489 | return node | |
490 |
|
490 | |||
491 |
|
491 | |||
492 | def mayberevnum(repo, prefix): |
|
492 | def mayberevnum(repo, prefix): | |
493 | """Checks if the given prefix may be mistaken for a revision number""" |
|
493 | """Checks if the given prefix may be mistaken for a revision number""" | |
494 | try: |
|
494 | try: | |
495 | i = int(prefix) |
|
495 | i = int(prefix) | |
496 | # if we are a pure int, then starting with zero will not be |
|
496 | # if we are a pure int, then starting with zero will not be | |
497 | # confused as a rev; or, obviously, if the int is larger |
|
497 | # confused as a rev; or, obviously, if the int is larger | |
498 | # than the value of the tip rev. We still need to disambiguate if |
|
498 | # than the value of the tip rev. We still need to disambiguate if | |
499 | # prefix == '0', since that *is* a valid revnum. |
|
499 | # prefix == '0', since that *is* a valid revnum. | |
500 | if (prefix != b'0' and prefix[0:1] == b'0') or i >= len(repo): |
|
500 | if (prefix != b'0' and prefix[0:1] == b'0') or i >= len(repo): | |
501 | return False |
|
501 | return False | |
502 | return True |
|
502 | return True | |
503 | except ValueError: |
|
503 | except ValueError: | |
504 | return False |
|
504 | return False | |
505 |
|
505 | |||
506 |
|
506 | |||
507 | def shortesthexnodeidprefix(repo, node, minlength=1, cache=None): |
|
507 | def shortesthexnodeidprefix(repo, node, minlength=1, cache=None): | |
508 | """Find the shortest unambiguous prefix that matches hexnode. |
|
508 | """Find the shortest unambiguous prefix that matches hexnode. | |
509 |
|
509 | |||
510 | If "cache" is not None, it must be a dictionary that can be used for |
|
510 | If "cache" is not None, it must be a dictionary that can be used for | |
511 | caching between calls to this method. |
|
511 | caching between calls to this method. | |
512 | """ |
|
512 | """ | |
513 | # _partialmatch() of filtered changelog could take O(len(repo)) time, |
|
513 | # _partialmatch() of filtered changelog could take O(len(repo)) time, | |
514 | # which would be unacceptably slow. so we look for hash collision in |
|
514 | # which would be unacceptably slow. so we look for hash collision in | |
515 | # unfiltered space, which means some hashes may be slightly longer. |
|
515 | # unfiltered space, which means some hashes may be slightly longer. | |
516 |
|
516 | |||
517 | minlength = max(minlength, 1) |
|
517 | minlength = max(minlength, 1) | |
518 |
|
518 | |||
519 | def disambiguate(prefix): |
|
519 | def disambiguate(prefix): | |
520 | """Disambiguate against revnums.""" |
|
520 | """Disambiguate against revnums.""" | |
521 | if repo.ui.configbool(b'experimental', b'revisions.prefixhexnode'): |
|
521 | if repo.ui.configbool(b'experimental', b'revisions.prefixhexnode'): | |
522 | if mayberevnum(repo, prefix): |
|
522 | if mayberevnum(repo, prefix): | |
523 | return b'x' + prefix |
|
523 | return b'x' + prefix | |
524 | else: |
|
524 | else: | |
525 | return prefix |
|
525 | return prefix | |
526 |
|
526 | |||
527 | hexnode = hex(node) |
|
527 | hexnode = hex(node) | |
528 | for length in range(len(prefix), len(hexnode) + 1): |
|
528 | for length in range(len(prefix), len(hexnode) + 1): | |
529 | prefix = hexnode[:length] |
|
529 | prefix = hexnode[:length] | |
530 | if not mayberevnum(repo, prefix): |
|
530 | if not mayberevnum(repo, prefix): | |
531 | return prefix |
|
531 | return prefix | |
532 |
|
532 | |||
533 | cl = repo.unfiltered().changelog |
|
533 | cl = repo.unfiltered().changelog | |
534 | revset = repo.ui.config(b'experimental', b'revisions.disambiguatewithin') |
|
534 | revset = repo.ui.config(b'experimental', b'revisions.disambiguatewithin') | |
535 | if revset: |
|
535 | if revset: | |
536 | revs = None |
|
536 | revs = None | |
537 | if cache is not None: |
|
537 | if cache is not None: | |
538 | revs = cache.get(b'disambiguationrevset') |
|
538 | revs = cache.get(b'disambiguationrevset') | |
539 | if revs is None: |
|
539 | if revs is None: | |
540 | revs = repo.anyrevs([revset], user=True) |
|
540 | revs = repo.anyrevs([revset], user=True) | |
541 | if cache is not None: |
|
541 | if cache is not None: | |
542 | cache[b'disambiguationrevset'] = revs |
|
542 | cache[b'disambiguationrevset'] = revs | |
543 | if cl.rev(node) in revs: |
|
543 | if cl.rev(node) in revs: | |
544 | hexnode = hex(node) |
|
544 | hexnode = hex(node) | |
545 | nodetree = None |
|
545 | nodetree = None | |
546 | if cache is not None: |
|
546 | if cache is not None: | |
547 | nodetree = cache.get(b'disambiguationnodetree') |
|
547 | nodetree = cache.get(b'disambiguationnodetree') | |
548 | if not nodetree: |
|
548 | if not nodetree: | |
549 | if util.safehasattr(parsers, 'nodetree'): |
|
549 | if util.safehasattr(parsers, 'nodetree'): | |
550 | # The CExt is the only implementation to provide a nodetree |
|
550 | # The CExt is the only implementation to provide a nodetree | |
551 | # class so far. |
|
551 | # class so far. | |
552 | index = cl.index |
|
552 | index = cl.index | |
553 | if util.safehasattr(index, 'get_cindex'): |
|
553 | if util.safehasattr(index, 'get_cindex'): | |
554 | # the rust wrapped need to give access to its internal index |
|
554 | # the rust wrapped need to give access to its internal index | |
555 | index = index.get_cindex() |
|
555 | index = index.get_cindex() | |
556 | nodetree = parsers.nodetree(index, len(revs)) |
|
556 | nodetree = parsers.nodetree(index, len(revs)) | |
557 | for r in revs: |
|
557 | for r in revs: | |
558 | nodetree.insert(r) |
|
558 | nodetree.insert(r) | |
559 | if cache is not None: |
|
559 | if cache is not None: | |
560 | cache[b'disambiguationnodetree'] = nodetree |
|
560 | cache[b'disambiguationnodetree'] = nodetree | |
561 | if nodetree is not None: |
|
561 | if nodetree is not None: | |
562 | length = max(nodetree.shortest(node), minlength) |
|
562 | length = max(nodetree.shortest(node), minlength) | |
563 | prefix = hexnode[:length] |
|
563 | prefix = hexnode[:length] | |
564 | return disambiguate(prefix) |
|
564 | return disambiguate(prefix) | |
565 | for length in range(minlength, len(hexnode) + 1): |
|
565 | for length in range(minlength, len(hexnode) + 1): | |
566 | matches = [] |
|
566 | matches = [] | |
567 | prefix = hexnode[:length] |
|
567 | prefix = hexnode[:length] | |
568 | for rev in revs: |
|
568 | for rev in revs: | |
569 | otherhexnode = repo[rev].hex() |
|
569 | otherhexnode = repo[rev].hex() | |
570 | if prefix == otherhexnode[:length]: |
|
570 | if prefix == otherhexnode[:length]: | |
571 | matches.append(otherhexnode) |
|
571 | matches.append(otherhexnode) | |
572 | if len(matches) == 1: |
|
572 | if len(matches) == 1: | |
573 | return disambiguate(prefix) |
|
573 | return disambiguate(prefix) | |
574 |
|
574 | |||
575 | try: |
|
575 | try: | |
576 | return disambiguate(cl.shortest(node, minlength)) |
|
576 | return disambiguate(cl.shortest(node, minlength)) | |
577 | except error.LookupError: |
|
577 | except error.LookupError: | |
578 | raise error.RepoLookupError() |
|
578 | raise error.RepoLookupError() | |
579 |
|
579 | |||
580 |
|
580 | |||
581 | def isrevsymbol(repo, symbol): |
|
581 | def isrevsymbol(repo, symbol): | |
582 | """Checks if a symbol exists in the repo. |
|
582 | """Checks if a symbol exists in the repo. | |
583 |
|
583 | |||
584 | See revsymbol() for details. Raises error.AmbiguousPrefixLookupError if the |
|
584 | See revsymbol() for details. Raises error.AmbiguousPrefixLookupError if the | |
585 | symbol is an ambiguous nodeid prefix. |
|
585 | symbol is an ambiguous nodeid prefix. | |
586 | """ |
|
586 | """ | |
587 | try: |
|
587 | try: | |
588 | revsymbol(repo, symbol) |
|
588 | revsymbol(repo, symbol) | |
589 | return True |
|
589 | return True | |
590 | except error.RepoLookupError: |
|
590 | except error.RepoLookupError: | |
591 | return False |
|
591 | return False | |
592 |
|
592 | |||
593 |
|
593 | |||
594 | def revsymbol(repo, symbol): |
|
594 | def revsymbol(repo, symbol): | |
595 | """Returns a context given a single revision symbol (as string). |
|
595 | """Returns a context given a single revision symbol (as string). | |
596 |
|
596 | |||
597 | This is similar to revsingle(), but accepts only a single revision symbol, |
|
597 | This is similar to revsingle(), but accepts only a single revision symbol, | |
598 | i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but |
|
598 | i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but | |
599 | not "max(public())". |
|
599 | not "max(public())". | |
600 | """ |
|
600 | """ | |
601 | if not isinstance(symbol, bytes): |
|
601 | if not isinstance(symbol, bytes): | |
602 | msg = ( |
|
602 | msg = ( | |
603 | b"symbol (%s of type %s) was not a string, did you mean " |
|
603 | b"symbol (%s of type %s) was not a string, did you mean " | |
604 | b"repo[symbol]?" % (symbol, type(symbol)) |
|
604 | b"repo[symbol]?" % (symbol, type(symbol)) | |
605 | ) |
|
605 | ) | |
606 | raise error.ProgrammingError(msg) |
|
606 | raise error.ProgrammingError(msg) | |
607 | try: |
|
607 | try: | |
608 | if symbol in (b'.', b'tip', b'null'): |
|
608 | if symbol in (b'.', b'tip', b'null'): | |
609 | return repo[symbol] |
|
609 | return repo[symbol] | |
610 |
|
610 | |||
611 | try: |
|
611 | try: | |
612 | r = int(symbol) |
|
612 | r = int(symbol) | |
613 | if b'%d' % r != symbol: |
|
613 | if b'%d' % r != symbol: | |
614 | raise ValueError |
|
614 | raise ValueError | |
615 | l = len(repo.changelog) |
|
615 | l = len(repo.changelog) | |
616 | if r < 0: |
|
616 | if r < 0: | |
617 | r += l |
|
617 | r += l | |
618 | if r < 0 or r >= l and r != wdirrev: |
|
618 | if r < 0 or r >= l and r != wdirrev: | |
619 | raise ValueError |
|
619 | raise ValueError | |
620 | return repo[r] |
|
620 | return repo[r] | |
621 | except error.FilteredIndexError: |
|
621 | except error.FilteredIndexError: | |
622 | raise |
|
622 | raise | |
623 | except (ValueError, OverflowError, IndexError): |
|
623 | except (ValueError, OverflowError, IndexError): | |
624 | pass |
|
624 | pass | |
625 |
|
625 | |||
626 | if len(symbol) == 40: |
|
626 | if len(symbol) == 40: | |
627 | try: |
|
627 | try: | |
628 | node = bin(symbol) |
|
628 | node = bin(symbol) | |
629 | rev = repo.changelog.rev(node) |
|
629 | rev = repo.changelog.rev(node) | |
630 | return repo[rev] |
|
630 | return repo[rev] | |
631 | except error.FilteredLookupError: |
|
631 | except error.FilteredLookupError: | |
632 | raise |
|
632 | raise | |
633 | except (TypeError, LookupError): |
|
633 | except (TypeError, LookupError): | |
634 | pass |
|
634 | pass | |
635 |
|
635 | |||
636 | # look up bookmarks through the name interface |
|
636 | # look up bookmarks through the name interface | |
637 | try: |
|
637 | try: | |
638 | node = repo.names.singlenode(repo, symbol) |
|
638 | node = repo.names.singlenode(repo, symbol) | |
639 | rev = repo.changelog.rev(node) |
|
639 | rev = repo.changelog.rev(node) | |
640 | return repo[rev] |
|
640 | return repo[rev] | |
641 | except KeyError: |
|
641 | except KeyError: | |
642 | pass |
|
642 | pass | |
643 |
|
643 | |||
644 | node = resolvehexnodeidprefix(repo, symbol) |
|
644 | node = resolvehexnodeidprefix(repo, symbol) | |
645 | if node is not None: |
|
645 | if node is not None: | |
646 | rev = repo.changelog.rev(node) |
|
646 | rev = repo.changelog.rev(node) | |
647 | return repo[rev] |
|
647 | return repo[rev] | |
648 |
|
648 | |||
649 | raise error.RepoLookupError(_(b"unknown revision '%s'") % symbol) |
|
649 | raise error.RepoLookupError(_(b"unknown revision '%s'") % symbol) | |
650 |
|
650 | |||
651 | except error.WdirUnsupported: |
|
651 | except error.WdirUnsupported: | |
652 | return repo[None] |
|
652 | return repo[None] | |
653 | except ( |
|
653 | except ( | |
654 | error.FilteredIndexError, |
|
654 | error.FilteredIndexError, | |
655 | error.FilteredLookupError, |
|
655 | error.FilteredLookupError, | |
656 | error.FilteredRepoLookupError, |
|
656 | error.FilteredRepoLookupError, | |
657 | ): |
|
657 | ): | |
658 | raise _filterederror(repo, symbol) |
|
658 | raise _filterederror(repo, symbol) | |
659 |
|
659 | |||
660 |
|
660 | |||
661 | def _filterederror(repo, changeid): |
|
661 | def _filterederror(repo, changeid): | |
662 | """build an exception to be raised about a filtered changeid |
|
662 | """build an exception to be raised about a filtered changeid | |
663 |
|
663 | |||
664 | This is extracted in a function to help extensions (eg: evolve) to |
|
664 | This is extracted in a function to help extensions (eg: evolve) to | |
665 | experiment with various message variants.""" |
|
665 | experiment with various message variants.""" | |
666 | if repo.filtername.startswith(b'visible'): |
|
666 | if repo.filtername.startswith(b'visible'): | |
667 |
|
667 | |||
668 | # Check if the changeset is obsolete |
|
668 | # Check if the changeset is obsolete | |
669 | unfilteredrepo = repo.unfiltered() |
|
669 | unfilteredrepo = repo.unfiltered() | |
670 | ctx = revsymbol(unfilteredrepo, changeid) |
|
670 | ctx = revsymbol(unfilteredrepo, changeid) | |
671 |
|
671 | |||
672 | # If the changeset is obsolete, enrich the message with the reason |
|
672 | # If the changeset is obsolete, enrich the message with the reason | |
673 | # that made this changeset not visible |
|
673 | # that made this changeset not visible | |
674 | if ctx.obsolete(): |
|
674 | if ctx.obsolete(): | |
675 | msg = obsutil._getfilteredreason(repo, changeid, ctx) |
|
675 | msg = obsutil._getfilteredreason(repo, changeid, ctx) | |
676 | else: |
|
676 | else: | |
677 | msg = _(b"hidden revision '%s'") % changeid |
|
677 | msg = _(b"hidden revision '%s'") % changeid | |
678 |
|
678 | |||
679 | hint = _(b'use --hidden to access hidden revisions') |
|
679 | hint = _(b'use --hidden to access hidden revisions') | |
680 |
|
680 | |||
681 | return error.FilteredRepoLookupError(msg, hint=hint) |
|
681 | return error.FilteredRepoLookupError(msg, hint=hint) | |
682 | msg = _(b"filtered revision '%s' (not in '%s' subset)") |
|
682 | msg = _(b"filtered revision '%s' (not in '%s' subset)") | |
683 | msg %= (changeid, repo.filtername) |
|
683 | msg %= (changeid, repo.filtername) | |
684 | return error.FilteredRepoLookupError(msg) |
|
684 | return error.FilteredRepoLookupError(msg) | |
685 |
|
685 | |||
686 |
|
686 | |||
687 | def revsingle(repo, revspec, default=b'.', localalias=None): |
|
687 | def revsingle(repo, revspec, default=b'.', localalias=None): | |
688 | if not revspec and revspec != 0: |
|
688 | if not revspec and revspec != 0: | |
689 | return repo[default] |
|
689 | return repo[default] | |
690 |
|
690 | |||
691 | l = revrange(repo, [revspec], localalias=localalias) |
|
691 | l = revrange(repo, [revspec], localalias=localalias) | |
692 | if not l: |
|
692 | if not l: | |
693 | raise error.Abort(_(b'empty revision set')) |
|
693 | raise error.Abort(_(b'empty revision set')) | |
694 | return repo[l.last()] |
|
694 | return repo[l.last()] | |
695 |
|
695 | |||
696 |
|
696 | |||
697 | def _pairspec(revspec): |
|
697 | def _pairspec(revspec): | |
698 | tree = revsetlang.parse(revspec) |
|
698 | tree = revsetlang.parse(revspec) | |
699 | return tree and tree[0] in ( |
|
699 | return tree and tree[0] in ( | |
700 | b'range', |
|
700 | b'range', | |
701 | b'rangepre', |
|
701 | b'rangepre', | |
702 | b'rangepost', |
|
702 | b'rangepost', | |
703 | b'rangeall', |
|
703 | b'rangeall', | |
704 | ) |
|
704 | ) | |
705 |
|
705 | |||
706 |
|
706 | |||
707 | def revpair(repo, revs): |
|
707 | def revpair(repo, revs): | |
708 | if not revs: |
|
708 | if not revs: | |
709 | return repo[b'.'], repo[None] |
|
709 | return repo[b'.'], repo[None] | |
710 |
|
710 | |||
711 | l = revrange(repo, revs) |
|
711 | l = revrange(repo, revs) | |
712 |
|
712 | |||
713 | if not l: |
|
713 | if not l: | |
714 | raise error.Abort(_(b'empty revision range')) |
|
714 | raise error.Abort(_(b'empty revision range')) | |
715 |
|
715 | |||
716 | first = l.first() |
|
716 | first = l.first() | |
717 | second = l.last() |
|
717 | second = l.last() | |
718 |
|
718 | |||
719 | if ( |
|
719 | if ( | |
720 | first == second |
|
720 | first == second | |
721 | and len(revs) >= 2 |
|
721 | and len(revs) >= 2 | |
722 | and not all(revrange(repo, [r]) for r in revs) |
|
722 | and not all(revrange(repo, [r]) for r in revs) | |
723 | ): |
|
723 | ): | |
724 | raise error.Abort(_(b'empty revision on one side of range')) |
|
724 | raise error.Abort(_(b'empty revision on one side of range')) | |
725 |
|
725 | |||
726 | # if top-level is range expression, the result must always be a pair |
|
726 | # if top-level is range expression, the result must always be a pair | |
727 | if first == second and len(revs) == 1 and not _pairspec(revs[0]): |
|
727 | if first == second and len(revs) == 1 and not _pairspec(revs[0]): | |
728 | return repo[first], repo[None] |
|
728 | return repo[first], repo[None] | |
729 |
|
729 | |||
730 | return repo[first], repo[second] |
|
730 | return repo[first], repo[second] | |
731 |
|
731 | |||
732 |
|
732 | |||
733 | def revrange(repo, specs, localalias=None): |
|
733 | def revrange(repo, specs, localalias=None): | |
734 | """Execute 1 to many revsets and return the union. |
|
734 | """Execute 1 to many revsets and return the union. | |
735 |
|
735 | |||
736 | This is the preferred mechanism for executing revsets using user-specified |
|
736 | This is the preferred mechanism for executing revsets using user-specified | |
737 | config options, such as revset aliases. |
|
737 | config options, such as revset aliases. | |
738 |
|
738 | |||
739 | The revsets specified by ``specs`` will be executed via a chained ``OR`` |
|
739 | The revsets specified by ``specs`` will be executed via a chained ``OR`` | |
740 | expression. If ``specs`` is empty, an empty result is returned. |
|
740 | expression. If ``specs`` is empty, an empty result is returned. | |
741 |
|
741 | |||
742 | ``specs`` can contain integers, in which case they are assumed to be |
|
742 | ``specs`` can contain integers, in which case they are assumed to be | |
743 | revision numbers. |
|
743 | revision numbers. | |
744 |
|
744 | |||
745 | It is assumed the revsets are already formatted. If you have arguments |
|
745 | It is assumed the revsets are already formatted. If you have arguments | |
746 | that need to be expanded in the revset, call ``revsetlang.formatspec()`` |
|
746 | that need to be expanded in the revset, call ``revsetlang.formatspec()`` | |
747 | and pass the result as an element of ``specs``. |
|
747 | and pass the result as an element of ``specs``. | |
748 |
|
748 | |||
749 | Specifying a single revset is allowed. |
|
749 | Specifying a single revset is allowed. | |
750 |
|
750 | |||
751 |
Returns a `` |
|
751 | Returns a ``smartset.abstractsmartset`` which is a list-like interface over | |
752 | integer revisions. |
|
752 | integer revisions. | |
753 | """ |
|
753 | """ | |
754 | allspecs = [] |
|
754 | allspecs = [] | |
755 | for spec in specs: |
|
755 | for spec in specs: | |
756 | if isinstance(spec, int): |
|
756 | if isinstance(spec, int): | |
757 | spec = revsetlang.formatspec(b'%d', spec) |
|
757 | spec = revsetlang.formatspec(b'%d', spec) | |
758 | allspecs.append(spec) |
|
758 | allspecs.append(spec) | |
759 | return repo.anyrevs(allspecs, user=True, localalias=localalias) |
|
759 | return repo.anyrevs(allspecs, user=True, localalias=localalias) | |
760 |
|
760 | |||
761 |
|
761 | |||
762 | def meaningfulparents(repo, ctx): |
|
762 | def meaningfulparents(repo, ctx): | |
763 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
763 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
764 |
|
764 | |||
765 | For merges (two non-nullrev revisions) both parents are meaningful. |
|
765 | For merges (two non-nullrev revisions) both parents are meaningful. | |
766 | Otherwise the first parent revision is considered meaningful if it |
|
766 | Otherwise the first parent revision is considered meaningful if it | |
767 | is not the preceding revision. |
|
767 | is not the preceding revision. | |
768 | """ |
|
768 | """ | |
769 | parents = ctx.parents() |
|
769 | parents = ctx.parents() | |
770 | if len(parents) > 1: |
|
770 | if len(parents) > 1: | |
771 | return parents |
|
771 | return parents | |
772 | if repo.ui.debugflag: |
|
772 | if repo.ui.debugflag: | |
773 | return [parents[0], repo[nullrev]] |
|
773 | return [parents[0], repo[nullrev]] | |
774 | if parents[0].rev() >= intrev(ctx) - 1: |
|
774 | if parents[0].rev() >= intrev(ctx) - 1: | |
775 | return [] |
|
775 | return [] | |
776 | return parents |
|
776 | return parents | |
777 |
|
777 | |||
778 |
|
778 | |||
779 | def getuipathfn(repo, legacyrelativevalue=False, forcerelativevalue=None): |
|
779 | def getuipathfn(repo, legacyrelativevalue=False, forcerelativevalue=None): | |
780 | """Return a function that produced paths for presenting to the user. |
|
780 | """Return a function that produced paths for presenting to the user. | |
781 |
|
781 | |||
782 | The returned function takes a repo-relative path and produces a path |
|
782 | The returned function takes a repo-relative path and produces a path | |
783 | that can be presented in the UI. |
|
783 | that can be presented in the UI. | |
784 |
|
784 | |||
785 | Depending on the value of ui.relative-paths, either a repo-relative or |
|
785 | Depending on the value of ui.relative-paths, either a repo-relative or | |
786 | cwd-relative path will be produced. |
|
786 | cwd-relative path will be produced. | |
787 |
|
787 | |||
788 | legacyrelativevalue is the value to use if ui.relative-paths=legacy |
|
788 | legacyrelativevalue is the value to use if ui.relative-paths=legacy | |
789 |
|
789 | |||
790 | If forcerelativevalue is not None, then that value will be used regardless |
|
790 | If forcerelativevalue is not None, then that value will be used regardless | |
791 | of what ui.relative-paths is set to. |
|
791 | of what ui.relative-paths is set to. | |
792 | """ |
|
792 | """ | |
793 | if forcerelativevalue is not None: |
|
793 | if forcerelativevalue is not None: | |
794 | relative = forcerelativevalue |
|
794 | relative = forcerelativevalue | |
795 | else: |
|
795 | else: | |
796 | config = repo.ui.config(b'ui', b'relative-paths') |
|
796 | config = repo.ui.config(b'ui', b'relative-paths') | |
797 | if config == b'legacy': |
|
797 | if config == b'legacy': | |
798 | relative = legacyrelativevalue |
|
798 | relative = legacyrelativevalue | |
799 | else: |
|
799 | else: | |
800 | relative = stringutil.parsebool(config) |
|
800 | relative = stringutil.parsebool(config) | |
801 | if relative is None: |
|
801 | if relative is None: | |
802 | raise error.ConfigError( |
|
802 | raise error.ConfigError( | |
803 | _(b"ui.relative-paths is not a boolean ('%s')") % config |
|
803 | _(b"ui.relative-paths is not a boolean ('%s')") % config | |
804 | ) |
|
804 | ) | |
805 |
|
805 | |||
806 | if relative: |
|
806 | if relative: | |
807 | cwd = repo.getcwd() |
|
807 | cwd = repo.getcwd() | |
808 | pathto = repo.pathto |
|
808 | pathto = repo.pathto | |
809 | return lambda f: pathto(f, cwd) |
|
809 | return lambda f: pathto(f, cwd) | |
810 | elif repo.ui.configbool(b'ui', b'slash'): |
|
810 | elif repo.ui.configbool(b'ui', b'slash'): | |
811 | return lambda f: f |
|
811 | return lambda f: f | |
812 | else: |
|
812 | else: | |
813 | return util.localpath |
|
813 | return util.localpath | |
814 |
|
814 | |||
815 |
|
815 | |||
816 | def subdiruipathfn(subpath, uipathfn): |
|
816 | def subdiruipathfn(subpath, uipathfn): | |
817 | '''Create a new uipathfn that treats the file as relative to subpath.''' |
|
817 | '''Create a new uipathfn that treats the file as relative to subpath.''' | |
818 | return lambda f: uipathfn(posixpath.join(subpath, f)) |
|
818 | return lambda f: uipathfn(posixpath.join(subpath, f)) | |
819 |
|
819 | |||
820 |
|
820 | |||
821 | def anypats(pats, opts): |
|
821 | def anypats(pats, opts): | |
822 | '''Checks if any patterns, including --include and --exclude were given. |
|
822 | '''Checks if any patterns, including --include and --exclude were given. | |
823 |
|
823 | |||
824 | Some commands (e.g. addremove) use this condition for deciding whether to |
|
824 | Some commands (e.g. addremove) use this condition for deciding whether to | |
825 | print absolute or relative paths. |
|
825 | print absolute or relative paths. | |
826 | ''' |
|
826 | ''' | |
827 | return bool(pats or opts.get(b'include') or opts.get(b'exclude')) |
|
827 | return bool(pats or opts.get(b'include') or opts.get(b'exclude')) | |
828 |
|
828 | |||
829 |
|
829 | |||
830 | def expandpats(pats): |
|
830 | def expandpats(pats): | |
831 | '''Expand bare globs when running on windows. |
|
831 | '''Expand bare globs when running on windows. | |
832 | On posix we assume it already has already been done by sh.''' |
|
832 | On posix we assume it already has already been done by sh.''' | |
833 | if not util.expandglobs: |
|
833 | if not util.expandglobs: | |
834 | return list(pats) |
|
834 | return list(pats) | |
835 | ret = [] |
|
835 | ret = [] | |
836 | for kindpat in pats: |
|
836 | for kindpat in pats: | |
837 | kind, pat = matchmod._patsplit(kindpat, None) |
|
837 | kind, pat = matchmod._patsplit(kindpat, None) | |
838 | if kind is None: |
|
838 | if kind is None: | |
839 | try: |
|
839 | try: | |
840 | globbed = glob.glob(pat) |
|
840 | globbed = glob.glob(pat) | |
841 | except re.error: |
|
841 | except re.error: | |
842 | globbed = [pat] |
|
842 | globbed = [pat] | |
843 | if globbed: |
|
843 | if globbed: | |
844 | ret.extend(globbed) |
|
844 | ret.extend(globbed) | |
845 | continue |
|
845 | continue | |
846 | ret.append(kindpat) |
|
846 | ret.append(kindpat) | |
847 | return ret |
|
847 | return ret | |
848 |
|
848 | |||
849 |
|
849 | |||
850 | def matchandpats( |
|
850 | def matchandpats( | |
851 | ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None |
|
851 | ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None | |
852 | ): |
|
852 | ): | |
853 | '''Return a matcher and the patterns that were used. |
|
853 | '''Return a matcher and the patterns that were used. | |
854 | The matcher will warn about bad matches, unless an alternate badfn callback |
|
854 | The matcher will warn about bad matches, unless an alternate badfn callback | |
855 | is provided.''' |
|
855 | is provided.''' | |
856 | if opts is None: |
|
856 | if opts is None: | |
857 | opts = {} |
|
857 | opts = {} | |
858 | if not globbed and default == b'relpath': |
|
858 | if not globbed and default == b'relpath': | |
859 | pats = expandpats(pats or []) |
|
859 | pats = expandpats(pats or []) | |
860 |
|
860 | |||
861 | uipathfn = getuipathfn(ctx.repo(), legacyrelativevalue=True) |
|
861 | uipathfn = getuipathfn(ctx.repo(), legacyrelativevalue=True) | |
862 |
|
862 | |||
863 | def bad(f, msg): |
|
863 | def bad(f, msg): | |
864 | ctx.repo().ui.warn(b"%s: %s\n" % (uipathfn(f), msg)) |
|
864 | ctx.repo().ui.warn(b"%s: %s\n" % (uipathfn(f), msg)) | |
865 |
|
865 | |||
866 | if badfn is None: |
|
866 | if badfn is None: | |
867 | badfn = bad |
|
867 | badfn = bad | |
868 |
|
868 | |||
869 | m = ctx.match( |
|
869 | m = ctx.match( | |
870 | pats, |
|
870 | pats, | |
871 | opts.get(b'include'), |
|
871 | opts.get(b'include'), | |
872 | opts.get(b'exclude'), |
|
872 | opts.get(b'exclude'), | |
873 | default, |
|
873 | default, | |
874 | listsubrepos=opts.get(b'subrepos'), |
|
874 | listsubrepos=opts.get(b'subrepos'), | |
875 | badfn=badfn, |
|
875 | badfn=badfn, | |
876 | ) |
|
876 | ) | |
877 |
|
877 | |||
878 | if m.always(): |
|
878 | if m.always(): | |
879 | pats = [] |
|
879 | pats = [] | |
880 | return m, pats |
|
880 | return m, pats | |
881 |
|
881 | |||
882 |
|
882 | |||
883 | def match( |
|
883 | def match( | |
884 | ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None |
|
884 | ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None | |
885 | ): |
|
885 | ): | |
886 | '''Return a matcher that will warn about bad matches.''' |
|
886 | '''Return a matcher that will warn about bad matches.''' | |
887 | return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] |
|
887 | return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] | |
888 |
|
888 | |||
889 |
|
889 | |||
890 | def matchall(repo): |
|
890 | def matchall(repo): | |
891 | '''Return a matcher that will efficiently match everything.''' |
|
891 | '''Return a matcher that will efficiently match everything.''' | |
892 | return matchmod.always() |
|
892 | return matchmod.always() | |
893 |
|
893 | |||
894 |
|
894 | |||
895 | def matchfiles(repo, files, badfn=None): |
|
895 | def matchfiles(repo, files, badfn=None): | |
896 | '''Return a matcher that will efficiently match exactly these files.''' |
|
896 | '''Return a matcher that will efficiently match exactly these files.''' | |
897 | return matchmod.exact(files, badfn=badfn) |
|
897 | return matchmod.exact(files, badfn=badfn) | |
898 |
|
898 | |||
899 |
|
899 | |||
900 | def parsefollowlinespattern(repo, rev, pat, msg): |
|
900 | def parsefollowlinespattern(repo, rev, pat, msg): | |
901 | """Return a file name from `pat` pattern suitable for usage in followlines |
|
901 | """Return a file name from `pat` pattern suitable for usage in followlines | |
902 | logic. |
|
902 | logic. | |
903 | """ |
|
903 | """ | |
904 | if not matchmod.patkind(pat): |
|
904 | if not matchmod.patkind(pat): | |
905 | return pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
905 | return pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
906 | else: |
|
906 | else: | |
907 | ctx = repo[rev] |
|
907 | ctx = repo[rev] | |
908 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) |
|
908 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) | |
909 | files = [f for f in ctx if m(f)] |
|
909 | files = [f for f in ctx if m(f)] | |
910 | if len(files) != 1: |
|
910 | if len(files) != 1: | |
911 | raise error.ParseError(msg) |
|
911 | raise error.ParseError(msg) | |
912 | return files[0] |
|
912 | return files[0] | |
913 |
|
913 | |||
914 |
|
914 | |||
915 | def getorigvfs(ui, repo): |
|
915 | def getorigvfs(ui, repo): | |
916 | """return a vfs suitable to save 'orig' file |
|
916 | """return a vfs suitable to save 'orig' file | |
917 |
|
917 | |||
918 | return None if no special directory is configured""" |
|
918 | return None if no special directory is configured""" | |
919 | origbackuppath = ui.config(b'ui', b'origbackuppath') |
|
919 | origbackuppath = ui.config(b'ui', b'origbackuppath') | |
920 | if not origbackuppath: |
|
920 | if not origbackuppath: | |
921 | return None |
|
921 | return None | |
922 | return vfs.vfs(repo.wvfs.join(origbackuppath)) |
|
922 | return vfs.vfs(repo.wvfs.join(origbackuppath)) | |
923 |
|
923 | |||
924 |
|
924 | |||
925 | def backuppath(ui, repo, filepath): |
|
925 | def backuppath(ui, repo, filepath): | |
926 | '''customize where working copy backup files (.orig files) are created |
|
926 | '''customize where working copy backup files (.orig files) are created | |
927 |
|
927 | |||
928 | Fetch user defined path from config file: [ui] origbackuppath = <path> |
|
928 | Fetch user defined path from config file: [ui] origbackuppath = <path> | |
929 | Fall back to default (filepath with .orig suffix) if not specified |
|
929 | Fall back to default (filepath with .orig suffix) if not specified | |
930 |
|
930 | |||
931 | filepath is repo-relative |
|
931 | filepath is repo-relative | |
932 |
|
932 | |||
933 | Returns an absolute path |
|
933 | Returns an absolute path | |
934 | ''' |
|
934 | ''' | |
935 | origvfs = getorigvfs(ui, repo) |
|
935 | origvfs = getorigvfs(ui, repo) | |
936 | if origvfs is None: |
|
936 | if origvfs is None: | |
937 | return repo.wjoin(filepath + b".orig") |
|
937 | return repo.wjoin(filepath + b".orig") | |
938 |
|
938 | |||
939 | origbackupdir = origvfs.dirname(filepath) |
|
939 | origbackupdir = origvfs.dirname(filepath) | |
940 | if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
|
940 | if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): | |
941 | ui.note(_(b'creating directory: %s\n') % origvfs.join(origbackupdir)) |
|
941 | ui.note(_(b'creating directory: %s\n') % origvfs.join(origbackupdir)) | |
942 |
|
942 | |||
943 | # Remove any files that conflict with the backup file's path |
|
943 | # Remove any files that conflict with the backup file's path | |
944 | for f in reversed(list(pathutil.finddirs(filepath))): |
|
944 | for f in reversed(list(pathutil.finddirs(filepath))): | |
945 | if origvfs.isfileorlink(f): |
|
945 | if origvfs.isfileorlink(f): | |
946 | ui.note(_(b'removing conflicting file: %s\n') % origvfs.join(f)) |
|
946 | ui.note(_(b'removing conflicting file: %s\n') % origvfs.join(f)) | |
947 | origvfs.unlink(f) |
|
947 | origvfs.unlink(f) | |
948 | break |
|
948 | break | |
949 |
|
949 | |||
950 | origvfs.makedirs(origbackupdir) |
|
950 | origvfs.makedirs(origbackupdir) | |
951 |
|
951 | |||
952 | if origvfs.isdir(filepath) and not origvfs.islink(filepath): |
|
952 | if origvfs.isdir(filepath) and not origvfs.islink(filepath): | |
953 | ui.note( |
|
953 | ui.note( | |
954 | _(b'removing conflicting directory: %s\n') % origvfs.join(filepath) |
|
954 | _(b'removing conflicting directory: %s\n') % origvfs.join(filepath) | |
955 | ) |
|
955 | ) | |
956 | origvfs.rmtree(filepath, forcibly=True) |
|
956 | origvfs.rmtree(filepath, forcibly=True) | |
957 |
|
957 | |||
958 | return origvfs.join(filepath) |
|
958 | return origvfs.join(filepath) | |
959 |
|
959 | |||
960 |
|
960 | |||
961 | class _containsnode(object): |
|
961 | class _containsnode(object): | |
962 | """proxy __contains__(node) to container.__contains__ which accepts revs""" |
|
962 | """proxy __contains__(node) to container.__contains__ which accepts revs""" | |
963 |
|
963 | |||
964 | def __init__(self, repo, revcontainer): |
|
964 | def __init__(self, repo, revcontainer): | |
965 | self._torev = repo.changelog.rev |
|
965 | self._torev = repo.changelog.rev | |
966 | self._revcontains = revcontainer.__contains__ |
|
966 | self._revcontains = revcontainer.__contains__ | |
967 |
|
967 | |||
968 | def __contains__(self, node): |
|
968 | def __contains__(self, node): | |
969 | return self._revcontains(self._torev(node)) |
|
969 | return self._revcontains(self._torev(node)) | |
970 |
|
970 | |||
971 |
|
971 | |||
972 | def cleanupnodes( |
|
972 | def cleanupnodes( | |
973 | repo, |
|
973 | repo, | |
974 | replacements, |
|
974 | replacements, | |
975 | operation, |
|
975 | operation, | |
976 | moves=None, |
|
976 | moves=None, | |
977 | metadata=None, |
|
977 | metadata=None, | |
978 | fixphase=False, |
|
978 | fixphase=False, | |
979 | targetphase=None, |
|
979 | targetphase=None, | |
980 | backup=True, |
|
980 | backup=True, | |
981 | ): |
|
981 | ): | |
982 | """do common cleanups when old nodes are replaced by new nodes |
|
982 | """do common cleanups when old nodes are replaced by new nodes | |
983 |
|
983 | |||
984 | That includes writing obsmarkers or stripping nodes, and moving bookmarks. |
|
984 | That includes writing obsmarkers or stripping nodes, and moving bookmarks. | |
985 | (we might also want to move working directory parent in the future) |
|
985 | (we might also want to move working directory parent in the future) | |
986 |
|
986 | |||
987 | By default, bookmark moves are calculated automatically from 'replacements', |
|
987 | By default, bookmark moves are calculated automatically from 'replacements', | |
988 | but 'moves' can be used to override that. Also, 'moves' may include |
|
988 | but 'moves' can be used to override that. Also, 'moves' may include | |
989 | additional bookmark moves that should not have associated obsmarkers. |
|
989 | additional bookmark moves that should not have associated obsmarkers. | |
990 |
|
990 | |||
991 | replacements is {oldnode: [newnode]} or a iterable of nodes if they do not |
|
991 | replacements is {oldnode: [newnode]} or a iterable of nodes if they do not | |
992 | have replacements. operation is a string, like "rebase". |
|
992 | have replacements. operation is a string, like "rebase". | |
993 |
|
993 | |||
994 | metadata is dictionary containing metadata to be stored in obsmarker if |
|
994 | metadata is dictionary containing metadata to be stored in obsmarker if | |
995 | obsolescence is enabled. |
|
995 | obsolescence is enabled. | |
996 | """ |
|
996 | """ | |
997 | assert fixphase or targetphase is None |
|
997 | assert fixphase or targetphase is None | |
998 | if not replacements and not moves: |
|
998 | if not replacements and not moves: | |
999 | return |
|
999 | return | |
1000 |
|
1000 | |||
1001 | # translate mapping's other forms |
|
1001 | # translate mapping's other forms | |
1002 | if not util.safehasattr(replacements, b'items'): |
|
1002 | if not util.safehasattr(replacements, b'items'): | |
1003 | replacements = {(n,): () for n in replacements} |
|
1003 | replacements = {(n,): () for n in replacements} | |
1004 | else: |
|
1004 | else: | |
1005 | # upgrading non tuple "source" to tuple ones for BC |
|
1005 | # upgrading non tuple "source" to tuple ones for BC | |
1006 | repls = {} |
|
1006 | repls = {} | |
1007 | for key, value in replacements.items(): |
|
1007 | for key, value in replacements.items(): | |
1008 | if not isinstance(key, tuple): |
|
1008 | if not isinstance(key, tuple): | |
1009 | key = (key,) |
|
1009 | key = (key,) | |
1010 | repls[key] = value |
|
1010 | repls[key] = value | |
1011 | replacements = repls |
|
1011 | replacements = repls | |
1012 |
|
1012 | |||
1013 | # Unfiltered repo is needed since nodes in replacements might be hidden. |
|
1013 | # Unfiltered repo is needed since nodes in replacements might be hidden. | |
1014 | unfi = repo.unfiltered() |
|
1014 | unfi = repo.unfiltered() | |
1015 |
|
1015 | |||
1016 | # Calculate bookmark movements |
|
1016 | # Calculate bookmark movements | |
1017 | if moves is None: |
|
1017 | if moves is None: | |
1018 | moves = {} |
|
1018 | moves = {} | |
1019 | for oldnodes, newnodes in replacements.items(): |
|
1019 | for oldnodes, newnodes in replacements.items(): | |
1020 | for oldnode in oldnodes: |
|
1020 | for oldnode in oldnodes: | |
1021 | if oldnode in moves: |
|
1021 | if oldnode in moves: | |
1022 | continue |
|
1022 | continue | |
1023 | if len(newnodes) > 1: |
|
1023 | if len(newnodes) > 1: | |
1024 | # usually a split, take the one with biggest rev number |
|
1024 | # usually a split, take the one with biggest rev number | |
1025 | newnode = next(unfi.set(b'max(%ln)', newnodes)).node() |
|
1025 | newnode = next(unfi.set(b'max(%ln)', newnodes)).node() | |
1026 | elif len(newnodes) == 0: |
|
1026 | elif len(newnodes) == 0: | |
1027 | # move bookmark backwards |
|
1027 | # move bookmark backwards | |
1028 | allreplaced = [] |
|
1028 | allreplaced = [] | |
1029 | for rep in replacements: |
|
1029 | for rep in replacements: | |
1030 | allreplaced.extend(rep) |
|
1030 | allreplaced.extend(rep) | |
1031 | roots = list( |
|
1031 | roots = list( | |
1032 | unfi.set(b'max((::%n) - %ln)', oldnode, allreplaced) |
|
1032 | unfi.set(b'max((::%n) - %ln)', oldnode, allreplaced) | |
1033 | ) |
|
1033 | ) | |
1034 | if roots: |
|
1034 | if roots: | |
1035 | newnode = roots[0].node() |
|
1035 | newnode = roots[0].node() | |
1036 | else: |
|
1036 | else: | |
1037 | newnode = nullid |
|
1037 | newnode = nullid | |
1038 | else: |
|
1038 | else: | |
1039 | newnode = newnodes[0] |
|
1039 | newnode = newnodes[0] | |
1040 | moves[oldnode] = newnode |
|
1040 | moves[oldnode] = newnode | |
1041 |
|
1041 | |||
1042 | allnewnodes = [n for ns in replacements.values() for n in ns] |
|
1042 | allnewnodes = [n for ns in replacements.values() for n in ns] | |
1043 | toretract = {} |
|
1043 | toretract = {} | |
1044 | toadvance = {} |
|
1044 | toadvance = {} | |
1045 | if fixphase: |
|
1045 | if fixphase: | |
1046 | precursors = {} |
|
1046 | precursors = {} | |
1047 | for oldnodes, newnodes in replacements.items(): |
|
1047 | for oldnodes, newnodes in replacements.items(): | |
1048 | for oldnode in oldnodes: |
|
1048 | for oldnode in oldnodes: | |
1049 | for newnode in newnodes: |
|
1049 | for newnode in newnodes: | |
1050 | precursors.setdefault(newnode, []).append(oldnode) |
|
1050 | precursors.setdefault(newnode, []).append(oldnode) | |
1051 |
|
1051 | |||
1052 | allnewnodes.sort(key=lambda n: unfi[n].rev()) |
|
1052 | allnewnodes.sort(key=lambda n: unfi[n].rev()) | |
1053 | newphases = {} |
|
1053 | newphases = {} | |
1054 |
|
1054 | |||
1055 | def phase(ctx): |
|
1055 | def phase(ctx): | |
1056 | return newphases.get(ctx.node(), ctx.phase()) |
|
1056 | return newphases.get(ctx.node(), ctx.phase()) | |
1057 |
|
1057 | |||
1058 | for newnode in allnewnodes: |
|
1058 | for newnode in allnewnodes: | |
1059 | ctx = unfi[newnode] |
|
1059 | ctx = unfi[newnode] | |
1060 | parentphase = max(phase(p) for p in ctx.parents()) |
|
1060 | parentphase = max(phase(p) for p in ctx.parents()) | |
1061 | if targetphase is None: |
|
1061 | if targetphase is None: | |
1062 | oldphase = max( |
|
1062 | oldphase = max( | |
1063 | unfi[oldnode].phase() for oldnode in precursors[newnode] |
|
1063 | unfi[oldnode].phase() for oldnode in precursors[newnode] | |
1064 | ) |
|
1064 | ) | |
1065 | newphase = max(oldphase, parentphase) |
|
1065 | newphase = max(oldphase, parentphase) | |
1066 | else: |
|
1066 | else: | |
1067 | newphase = max(targetphase, parentphase) |
|
1067 | newphase = max(targetphase, parentphase) | |
1068 | newphases[newnode] = newphase |
|
1068 | newphases[newnode] = newphase | |
1069 | if newphase > ctx.phase(): |
|
1069 | if newphase > ctx.phase(): | |
1070 | toretract.setdefault(newphase, []).append(newnode) |
|
1070 | toretract.setdefault(newphase, []).append(newnode) | |
1071 | elif newphase < ctx.phase(): |
|
1071 | elif newphase < ctx.phase(): | |
1072 | toadvance.setdefault(newphase, []).append(newnode) |
|
1072 | toadvance.setdefault(newphase, []).append(newnode) | |
1073 |
|
1073 | |||
1074 | with repo.transaction(b'cleanup') as tr: |
|
1074 | with repo.transaction(b'cleanup') as tr: | |
1075 | # Move bookmarks |
|
1075 | # Move bookmarks | |
1076 | bmarks = repo._bookmarks |
|
1076 | bmarks = repo._bookmarks | |
1077 | bmarkchanges = [] |
|
1077 | bmarkchanges = [] | |
1078 | for oldnode, newnode in moves.items(): |
|
1078 | for oldnode, newnode in moves.items(): | |
1079 | oldbmarks = repo.nodebookmarks(oldnode) |
|
1079 | oldbmarks = repo.nodebookmarks(oldnode) | |
1080 | if not oldbmarks: |
|
1080 | if not oldbmarks: | |
1081 | continue |
|
1081 | continue | |
1082 | from . import bookmarks # avoid import cycle |
|
1082 | from . import bookmarks # avoid import cycle | |
1083 |
|
1083 | |||
1084 | repo.ui.debug( |
|
1084 | repo.ui.debug( | |
1085 | b'moving bookmarks %r from %s to %s\n' |
|
1085 | b'moving bookmarks %r from %s to %s\n' | |
1086 | % ( |
|
1086 | % ( | |
1087 | pycompat.rapply(pycompat.maybebytestr, oldbmarks), |
|
1087 | pycompat.rapply(pycompat.maybebytestr, oldbmarks), | |
1088 | hex(oldnode), |
|
1088 | hex(oldnode), | |
1089 | hex(newnode), |
|
1089 | hex(newnode), | |
1090 | ) |
|
1090 | ) | |
1091 | ) |
|
1091 | ) | |
1092 | # Delete divergent bookmarks being parents of related newnodes |
|
1092 | # Delete divergent bookmarks being parents of related newnodes | |
1093 | deleterevs = repo.revs( |
|
1093 | deleterevs = repo.revs( | |
1094 | b'parents(roots(%ln & (::%n))) - parents(%n)', |
|
1094 | b'parents(roots(%ln & (::%n))) - parents(%n)', | |
1095 | allnewnodes, |
|
1095 | allnewnodes, | |
1096 | newnode, |
|
1096 | newnode, | |
1097 | oldnode, |
|
1097 | oldnode, | |
1098 | ) |
|
1098 | ) | |
1099 | deletenodes = _containsnode(repo, deleterevs) |
|
1099 | deletenodes = _containsnode(repo, deleterevs) | |
1100 | for name in oldbmarks: |
|
1100 | for name in oldbmarks: | |
1101 | bmarkchanges.append((name, newnode)) |
|
1101 | bmarkchanges.append((name, newnode)) | |
1102 | for b in bookmarks.divergent2delete(repo, deletenodes, name): |
|
1102 | for b in bookmarks.divergent2delete(repo, deletenodes, name): | |
1103 | bmarkchanges.append((b, None)) |
|
1103 | bmarkchanges.append((b, None)) | |
1104 |
|
1104 | |||
1105 | if bmarkchanges: |
|
1105 | if bmarkchanges: | |
1106 | bmarks.applychanges(repo, tr, bmarkchanges) |
|
1106 | bmarks.applychanges(repo, tr, bmarkchanges) | |
1107 |
|
1107 | |||
1108 | for phase, nodes in toretract.items(): |
|
1108 | for phase, nodes in toretract.items(): | |
1109 | phases.retractboundary(repo, tr, phase, nodes) |
|
1109 | phases.retractboundary(repo, tr, phase, nodes) | |
1110 | for phase, nodes in toadvance.items(): |
|
1110 | for phase, nodes in toadvance.items(): | |
1111 | phases.advanceboundary(repo, tr, phase, nodes) |
|
1111 | phases.advanceboundary(repo, tr, phase, nodes) | |
1112 |
|
1112 | |||
1113 | mayusearchived = repo.ui.config(b'experimental', b'cleanup-as-archived') |
|
1113 | mayusearchived = repo.ui.config(b'experimental', b'cleanup-as-archived') | |
1114 | # Obsolete or strip nodes |
|
1114 | # Obsolete or strip nodes | |
1115 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
1115 | if obsolete.isenabled(repo, obsolete.createmarkersopt): | |
1116 | # If a node is already obsoleted, and we want to obsolete it |
|
1116 | # If a node is already obsoleted, and we want to obsolete it | |
1117 | # without a successor, skip that obssolete request since it's |
|
1117 | # without a successor, skip that obssolete request since it's | |
1118 | # unnecessary. That's the "if s or not isobs(n)" check below. |
|
1118 | # unnecessary. That's the "if s or not isobs(n)" check below. | |
1119 | # Also sort the node in topology order, that might be useful for |
|
1119 | # Also sort the node in topology order, that might be useful for | |
1120 | # some obsstore logic. |
|
1120 | # some obsstore logic. | |
1121 | # NOTE: the sorting might belong to createmarkers. |
|
1121 | # NOTE: the sorting might belong to createmarkers. | |
1122 | torev = unfi.changelog.rev |
|
1122 | torev = unfi.changelog.rev | |
1123 | sortfunc = lambda ns: torev(ns[0][0]) |
|
1123 | sortfunc = lambda ns: torev(ns[0][0]) | |
1124 | rels = [] |
|
1124 | rels = [] | |
1125 | for ns, s in sorted(replacements.items(), key=sortfunc): |
|
1125 | for ns, s in sorted(replacements.items(), key=sortfunc): | |
1126 | rel = (tuple(unfi[n] for n in ns), tuple(unfi[m] for m in s)) |
|
1126 | rel = (tuple(unfi[n] for n in ns), tuple(unfi[m] for m in s)) | |
1127 | rels.append(rel) |
|
1127 | rels.append(rel) | |
1128 | if rels: |
|
1128 | if rels: | |
1129 | obsolete.createmarkers( |
|
1129 | obsolete.createmarkers( | |
1130 | repo, rels, operation=operation, metadata=metadata |
|
1130 | repo, rels, operation=operation, metadata=metadata | |
1131 | ) |
|
1131 | ) | |
1132 | elif phases.supportinternal(repo) and mayusearchived: |
|
1132 | elif phases.supportinternal(repo) and mayusearchived: | |
1133 | # this assume we do not have "unstable" nodes above the cleaned ones |
|
1133 | # this assume we do not have "unstable" nodes above the cleaned ones | |
1134 | allreplaced = set() |
|
1134 | allreplaced = set() | |
1135 | for ns in replacements.keys(): |
|
1135 | for ns in replacements.keys(): | |
1136 | allreplaced.update(ns) |
|
1136 | allreplaced.update(ns) | |
1137 | if backup: |
|
1137 | if backup: | |
1138 | from . import repair # avoid import cycle |
|
1138 | from . import repair # avoid import cycle | |
1139 |
|
1139 | |||
1140 | node = min(allreplaced, key=repo.changelog.rev) |
|
1140 | node = min(allreplaced, key=repo.changelog.rev) | |
1141 | repair.backupbundle( |
|
1141 | repair.backupbundle( | |
1142 | repo, allreplaced, allreplaced, node, operation |
|
1142 | repo, allreplaced, allreplaced, node, operation | |
1143 | ) |
|
1143 | ) | |
1144 | phases.retractboundary(repo, tr, phases.archived, allreplaced) |
|
1144 | phases.retractboundary(repo, tr, phases.archived, allreplaced) | |
1145 | else: |
|
1145 | else: | |
1146 | from . import repair # avoid import cycle |
|
1146 | from . import repair # avoid import cycle | |
1147 |
|
1147 | |||
1148 | tostrip = list(n for ns in replacements for n in ns) |
|
1148 | tostrip = list(n for ns in replacements for n in ns) | |
1149 | if tostrip: |
|
1149 | if tostrip: | |
1150 | repair.delayedstrip( |
|
1150 | repair.delayedstrip( | |
1151 | repo.ui, repo, tostrip, operation, backup=backup |
|
1151 | repo.ui, repo, tostrip, operation, backup=backup | |
1152 | ) |
|
1152 | ) | |
1153 |
|
1153 | |||
1154 |
|
1154 | |||
1155 | def addremove(repo, matcher, prefix, uipathfn, opts=None): |
|
1155 | def addremove(repo, matcher, prefix, uipathfn, opts=None): | |
1156 | if opts is None: |
|
1156 | if opts is None: | |
1157 | opts = {} |
|
1157 | opts = {} | |
1158 | m = matcher |
|
1158 | m = matcher | |
1159 | dry_run = opts.get(b'dry_run') |
|
1159 | dry_run = opts.get(b'dry_run') | |
1160 | try: |
|
1160 | try: | |
1161 | similarity = float(opts.get(b'similarity') or 0) |
|
1161 | similarity = float(opts.get(b'similarity') or 0) | |
1162 | except ValueError: |
|
1162 | except ValueError: | |
1163 | raise error.Abort(_(b'similarity must be a number')) |
|
1163 | raise error.Abort(_(b'similarity must be a number')) | |
1164 | if similarity < 0 or similarity > 100: |
|
1164 | if similarity < 0 or similarity > 100: | |
1165 | raise error.Abort(_(b'similarity must be between 0 and 100')) |
|
1165 | raise error.Abort(_(b'similarity must be between 0 and 100')) | |
1166 | similarity /= 100.0 |
|
1166 | similarity /= 100.0 | |
1167 |
|
1167 | |||
1168 | ret = 0 |
|
1168 | ret = 0 | |
1169 |
|
1169 | |||
1170 | wctx = repo[None] |
|
1170 | wctx = repo[None] | |
1171 | for subpath in sorted(wctx.substate): |
|
1171 | for subpath in sorted(wctx.substate): | |
1172 | submatch = matchmod.subdirmatcher(subpath, m) |
|
1172 | submatch = matchmod.subdirmatcher(subpath, m) | |
1173 | if opts.get(b'subrepos') or m.exact(subpath) or any(submatch.files()): |
|
1173 | if opts.get(b'subrepos') or m.exact(subpath) or any(submatch.files()): | |
1174 | sub = wctx.sub(subpath) |
|
1174 | sub = wctx.sub(subpath) | |
1175 | subprefix = repo.wvfs.reljoin(prefix, subpath) |
|
1175 | subprefix = repo.wvfs.reljoin(prefix, subpath) | |
1176 | subuipathfn = subdiruipathfn(subpath, uipathfn) |
|
1176 | subuipathfn = subdiruipathfn(subpath, uipathfn) | |
1177 | try: |
|
1177 | try: | |
1178 | if sub.addremove(submatch, subprefix, subuipathfn, opts): |
|
1178 | if sub.addremove(submatch, subprefix, subuipathfn, opts): | |
1179 | ret = 1 |
|
1179 | ret = 1 | |
1180 | except error.LookupError: |
|
1180 | except error.LookupError: | |
1181 | repo.ui.status( |
|
1181 | repo.ui.status( | |
1182 | _(b"skipping missing subrepository: %s\n") |
|
1182 | _(b"skipping missing subrepository: %s\n") | |
1183 | % uipathfn(subpath) |
|
1183 | % uipathfn(subpath) | |
1184 | ) |
|
1184 | ) | |
1185 |
|
1185 | |||
1186 | rejected = [] |
|
1186 | rejected = [] | |
1187 |
|
1187 | |||
1188 | def badfn(f, msg): |
|
1188 | def badfn(f, msg): | |
1189 | if f in m.files(): |
|
1189 | if f in m.files(): | |
1190 | m.bad(f, msg) |
|
1190 | m.bad(f, msg) | |
1191 | rejected.append(f) |
|
1191 | rejected.append(f) | |
1192 |
|
1192 | |||
1193 | badmatch = matchmod.badmatch(m, badfn) |
|
1193 | badmatch = matchmod.badmatch(m, badfn) | |
1194 | added, unknown, deleted, removed, forgotten = _interestingfiles( |
|
1194 | added, unknown, deleted, removed, forgotten = _interestingfiles( | |
1195 | repo, badmatch |
|
1195 | repo, badmatch | |
1196 | ) |
|
1196 | ) | |
1197 |
|
1197 | |||
1198 | unknownset = set(unknown + forgotten) |
|
1198 | unknownset = set(unknown + forgotten) | |
1199 | toprint = unknownset.copy() |
|
1199 | toprint = unknownset.copy() | |
1200 | toprint.update(deleted) |
|
1200 | toprint.update(deleted) | |
1201 | for abs in sorted(toprint): |
|
1201 | for abs in sorted(toprint): | |
1202 | if repo.ui.verbose or not m.exact(abs): |
|
1202 | if repo.ui.verbose or not m.exact(abs): | |
1203 | if abs in unknownset: |
|
1203 | if abs in unknownset: | |
1204 | status = _(b'adding %s\n') % uipathfn(abs) |
|
1204 | status = _(b'adding %s\n') % uipathfn(abs) | |
1205 | label = b'ui.addremove.added' |
|
1205 | label = b'ui.addremove.added' | |
1206 | else: |
|
1206 | else: | |
1207 | status = _(b'removing %s\n') % uipathfn(abs) |
|
1207 | status = _(b'removing %s\n') % uipathfn(abs) | |
1208 | label = b'ui.addremove.removed' |
|
1208 | label = b'ui.addremove.removed' | |
1209 | repo.ui.status(status, label=label) |
|
1209 | repo.ui.status(status, label=label) | |
1210 |
|
1210 | |||
1211 | renames = _findrenames( |
|
1211 | renames = _findrenames( | |
1212 | repo, m, added + unknown, removed + deleted, similarity, uipathfn |
|
1212 | repo, m, added + unknown, removed + deleted, similarity, uipathfn | |
1213 | ) |
|
1213 | ) | |
1214 |
|
1214 | |||
1215 | if not dry_run: |
|
1215 | if not dry_run: | |
1216 | _markchanges(repo, unknown + forgotten, deleted, renames) |
|
1216 | _markchanges(repo, unknown + forgotten, deleted, renames) | |
1217 |
|
1217 | |||
1218 | for f in rejected: |
|
1218 | for f in rejected: | |
1219 | if f in m.files(): |
|
1219 | if f in m.files(): | |
1220 | return 1 |
|
1220 | return 1 | |
1221 | return ret |
|
1221 | return ret | |
1222 |
|
1222 | |||
1223 |
|
1223 | |||
1224 | def marktouched(repo, files, similarity=0.0): |
|
1224 | def marktouched(repo, files, similarity=0.0): | |
1225 | '''Assert that files have somehow been operated upon. files are relative to |
|
1225 | '''Assert that files have somehow been operated upon. files are relative to | |
1226 | the repo root.''' |
|
1226 | the repo root.''' | |
1227 | m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) |
|
1227 | m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) | |
1228 | rejected = [] |
|
1228 | rejected = [] | |
1229 |
|
1229 | |||
1230 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) |
|
1230 | added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) | |
1231 |
|
1231 | |||
1232 | if repo.ui.verbose: |
|
1232 | if repo.ui.verbose: | |
1233 | unknownset = set(unknown + forgotten) |
|
1233 | unknownset = set(unknown + forgotten) | |
1234 | toprint = unknownset.copy() |
|
1234 | toprint = unknownset.copy() | |
1235 | toprint.update(deleted) |
|
1235 | toprint.update(deleted) | |
1236 | for abs in sorted(toprint): |
|
1236 | for abs in sorted(toprint): | |
1237 | if abs in unknownset: |
|
1237 | if abs in unknownset: | |
1238 | status = _(b'adding %s\n') % abs |
|
1238 | status = _(b'adding %s\n') % abs | |
1239 | else: |
|
1239 | else: | |
1240 | status = _(b'removing %s\n') % abs |
|
1240 | status = _(b'removing %s\n') % abs | |
1241 | repo.ui.status(status) |
|
1241 | repo.ui.status(status) | |
1242 |
|
1242 | |||
1243 | # TODO: We should probably have the caller pass in uipathfn and apply it to |
|
1243 | # TODO: We should probably have the caller pass in uipathfn and apply it to | |
1244 | # the messages above too. legacyrelativevalue=True is consistent with how |
|
1244 | # the messages above too. legacyrelativevalue=True is consistent with how | |
1245 | # it used to work. |
|
1245 | # it used to work. | |
1246 | uipathfn = getuipathfn(repo, legacyrelativevalue=True) |
|
1246 | uipathfn = getuipathfn(repo, legacyrelativevalue=True) | |
1247 | renames = _findrenames( |
|
1247 | renames = _findrenames( | |
1248 | repo, m, added + unknown, removed + deleted, similarity, uipathfn |
|
1248 | repo, m, added + unknown, removed + deleted, similarity, uipathfn | |
1249 | ) |
|
1249 | ) | |
1250 |
|
1250 | |||
1251 | _markchanges(repo, unknown + forgotten, deleted, renames) |
|
1251 | _markchanges(repo, unknown + forgotten, deleted, renames) | |
1252 |
|
1252 | |||
1253 | for f in rejected: |
|
1253 | for f in rejected: | |
1254 | if f in m.files(): |
|
1254 | if f in m.files(): | |
1255 | return 1 |
|
1255 | return 1 | |
1256 | return 0 |
|
1256 | return 0 | |
1257 |
|
1257 | |||
1258 |
|
1258 | |||
1259 | def _interestingfiles(repo, matcher): |
|
1259 | def _interestingfiles(repo, matcher): | |
1260 | '''Walk dirstate with matcher, looking for files that addremove would care |
|
1260 | '''Walk dirstate with matcher, looking for files that addremove would care | |
1261 | about. |
|
1261 | about. | |
1262 |
|
1262 | |||
1263 | This is different from dirstate.status because it doesn't care about |
|
1263 | This is different from dirstate.status because it doesn't care about | |
1264 | whether files are modified or clean.''' |
|
1264 | whether files are modified or clean.''' | |
1265 | added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
|
1265 | added, unknown, deleted, removed, forgotten = [], [], [], [], [] | |
1266 | audit_path = pathutil.pathauditor(repo.root, cached=True) |
|
1266 | audit_path = pathutil.pathauditor(repo.root, cached=True) | |
1267 |
|
1267 | |||
1268 | ctx = repo[None] |
|
1268 | ctx = repo[None] | |
1269 | dirstate = repo.dirstate |
|
1269 | dirstate = repo.dirstate | |
1270 | matcher = repo.narrowmatch(matcher, includeexact=True) |
|
1270 | matcher = repo.narrowmatch(matcher, includeexact=True) | |
1271 | walkresults = dirstate.walk( |
|
1271 | walkresults = dirstate.walk( | |
1272 | matcher, |
|
1272 | matcher, | |
1273 | subrepos=sorted(ctx.substate), |
|
1273 | subrepos=sorted(ctx.substate), | |
1274 | unknown=True, |
|
1274 | unknown=True, | |
1275 | ignored=False, |
|
1275 | ignored=False, | |
1276 | full=False, |
|
1276 | full=False, | |
1277 | ) |
|
1277 | ) | |
1278 | for abs, st in pycompat.iteritems(walkresults): |
|
1278 | for abs, st in pycompat.iteritems(walkresults): | |
1279 | dstate = dirstate[abs] |
|
1279 | dstate = dirstate[abs] | |
1280 | if dstate == b'?' and audit_path.check(abs): |
|
1280 | if dstate == b'?' and audit_path.check(abs): | |
1281 | unknown.append(abs) |
|
1281 | unknown.append(abs) | |
1282 | elif dstate != b'r' and not st: |
|
1282 | elif dstate != b'r' and not st: | |
1283 | deleted.append(abs) |
|
1283 | deleted.append(abs) | |
1284 | elif dstate == b'r' and st: |
|
1284 | elif dstate == b'r' and st: | |
1285 | forgotten.append(abs) |
|
1285 | forgotten.append(abs) | |
1286 | # for finding renames |
|
1286 | # for finding renames | |
1287 | elif dstate == b'r' and not st: |
|
1287 | elif dstate == b'r' and not st: | |
1288 | removed.append(abs) |
|
1288 | removed.append(abs) | |
1289 | elif dstate == b'a': |
|
1289 | elif dstate == b'a': | |
1290 | added.append(abs) |
|
1290 | added.append(abs) | |
1291 |
|
1291 | |||
1292 | return added, unknown, deleted, removed, forgotten |
|
1292 | return added, unknown, deleted, removed, forgotten | |
1293 |
|
1293 | |||
1294 |
|
1294 | |||
1295 | def _findrenames(repo, matcher, added, removed, similarity, uipathfn): |
|
1295 | def _findrenames(repo, matcher, added, removed, similarity, uipathfn): | |
1296 | '''Find renames from removed files to added ones.''' |
|
1296 | '''Find renames from removed files to added ones.''' | |
1297 | renames = {} |
|
1297 | renames = {} | |
1298 | if similarity > 0: |
|
1298 | if similarity > 0: | |
1299 | for old, new, score in similar.findrenames( |
|
1299 | for old, new, score in similar.findrenames( | |
1300 | repo, added, removed, similarity |
|
1300 | repo, added, removed, similarity | |
1301 | ): |
|
1301 | ): | |
1302 | if ( |
|
1302 | if ( | |
1303 | repo.ui.verbose |
|
1303 | repo.ui.verbose | |
1304 | or not matcher.exact(old) |
|
1304 | or not matcher.exact(old) | |
1305 | or not matcher.exact(new) |
|
1305 | or not matcher.exact(new) | |
1306 | ): |
|
1306 | ): | |
1307 | repo.ui.status( |
|
1307 | repo.ui.status( | |
1308 | _( |
|
1308 | _( | |
1309 | b'recording removal of %s as rename to %s ' |
|
1309 | b'recording removal of %s as rename to %s ' | |
1310 | b'(%d%% similar)\n' |
|
1310 | b'(%d%% similar)\n' | |
1311 | ) |
|
1311 | ) | |
1312 | % (uipathfn(old), uipathfn(new), score * 100) |
|
1312 | % (uipathfn(old), uipathfn(new), score * 100) | |
1313 | ) |
|
1313 | ) | |
1314 | renames[new] = old |
|
1314 | renames[new] = old | |
1315 | return renames |
|
1315 | return renames | |
1316 |
|
1316 | |||
1317 |
|
1317 | |||
1318 | def _markchanges(repo, unknown, deleted, renames): |
|
1318 | def _markchanges(repo, unknown, deleted, renames): | |
1319 | '''Marks the files in unknown as added, the files in deleted as removed, |
|
1319 | '''Marks the files in unknown as added, the files in deleted as removed, | |
1320 | and the files in renames as copied.''' |
|
1320 | and the files in renames as copied.''' | |
1321 | wctx = repo[None] |
|
1321 | wctx = repo[None] | |
1322 | with repo.wlock(): |
|
1322 | with repo.wlock(): | |
1323 | wctx.forget(deleted) |
|
1323 | wctx.forget(deleted) | |
1324 | wctx.add(unknown) |
|
1324 | wctx.add(unknown) | |
1325 | for new, old in pycompat.iteritems(renames): |
|
1325 | for new, old in pycompat.iteritems(renames): | |
1326 | wctx.copy(old, new) |
|
1326 | wctx.copy(old, new) | |
1327 |
|
1327 | |||
1328 |
|
1328 | |||
1329 | def getrenamedfn(repo, endrev=None): |
|
1329 | def getrenamedfn(repo, endrev=None): | |
1330 | if copiesmod.usechangesetcentricalgo(repo): |
|
1330 | if copiesmod.usechangesetcentricalgo(repo): | |
1331 |
|
1331 | |||
1332 | def getrenamed(fn, rev): |
|
1332 | def getrenamed(fn, rev): | |
1333 | ctx = repo[rev] |
|
1333 | ctx = repo[rev] | |
1334 | p1copies = ctx.p1copies() |
|
1334 | p1copies = ctx.p1copies() | |
1335 | if fn in p1copies: |
|
1335 | if fn in p1copies: | |
1336 | return p1copies[fn] |
|
1336 | return p1copies[fn] | |
1337 | p2copies = ctx.p2copies() |
|
1337 | p2copies = ctx.p2copies() | |
1338 | if fn in p2copies: |
|
1338 | if fn in p2copies: | |
1339 | return p2copies[fn] |
|
1339 | return p2copies[fn] | |
1340 | return None |
|
1340 | return None | |
1341 |
|
1341 | |||
1342 | return getrenamed |
|
1342 | return getrenamed | |
1343 |
|
1343 | |||
1344 | rcache = {} |
|
1344 | rcache = {} | |
1345 | if endrev is None: |
|
1345 | if endrev is None: | |
1346 | endrev = len(repo) |
|
1346 | endrev = len(repo) | |
1347 |
|
1347 | |||
1348 | def getrenamed(fn, rev): |
|
1348 | def getrenamed(fn, rev): | |
1349 | '''looks up all renames for a file (up to endrev) the first |
|
1349 | '''looks up all renames for a file (up to endrev) the first | |
1350 | time the file is given. It indexes on the changerev and only |
|
1350 | time the file is given. It indexes on the changerev and only | |
1351 | parses the manifest if linkrev != changerev. |
|
1351 | parses the manifest if linkrev != changerev. | |
1352 | Returns rename info for fn at changerev rev.''' |
|
1352 | Returns rename info for fn at changerev rev.''' | |
1353 | if fn not in rcache: |
|
1353 | if fn not in rcache: | |
1354 | rcache[fn] = {} |
|
1354 | rcache[fn] = {} | |
1355 | fl = repo.file(fn) |
|
1355 | fl = repo.file(fn) | |
1356 | for i in fl: |
|
1356 | for i in fl: | |
1357 | lr = fl.linkrev(i) |
|
1357 | lr = fl.linkrev(i) | |
1358 | renamed = fl.renamed(fl.node(i)) |
|
1358 | renamed = fl.renamed(fl.node(i)) | |
1359 | rcache[fn][lr] = renamed and renamed[0] |
|
1359 | rcache[fn][lr] = renamed and renamed[0] | |
1360 | if lr >= endrev: |
|
1360 | if lr >= endrev: | |
1361 | break |
|
1361 | break | |
1362 | if rev in rcache[fn]: |
|
1362 | if rev in rcache[fn]: | |
1363 | return rcache[fn][rev] |
|
1363 | return rcache[fn][rev] | |
1364 |
|
1364 | |||
1365 | # If linkrev != rev (i.e. rev not found in rcache) fallback to |
|
1365 | # If linkrev != rev (i.e. rev not found in rcache) fallback to | |
1366 | # filectx logic. |
|
1366 | # filectx logic. | |
1367 | try: |
|
1367 | try: | |
1368 | return repo[rev][fn].copysource() |
|
1368 | return repo[rev][fn].copysource() | |
1369 | except error.LookupError: |
|
1369 | except error.LookupError: | |
1370 | return None |
|
1370 | return None | |
1371 |
|
1371 | |||
1372 | return getrenamed |
|
1372 | return getrenamed | |
1373 |
|
1373 | |||
1374 |
|
1374 | |||
1375 | def getcopiesfn(repo, endrev=None): |
|
1375 | def getcopiesfn(repo, endrev=None): | |
1376 | if copiesmod.usechangesetcentricalgo(repo): |
|
1376 | if copiesmod.usechangesetcentricalgo(repo): | |
1377 |
|
1377 | |||
1378 | def copiesfn(ctx): |
|
1378 | def copiesfn(ctx): | |
1379 | if ctx.p2copies(): |
|
1379 | if ctx.p2copies(): | |
1380 | allcopies = ctx.p1copies().copy() |
|
1380 | allcopies = ctx.p1copies().copy() | |
1381 | # There should be no overlap |
|
1381 | # There should be no overlap | |
1382 | allcopies.update(ctx.p2copies()) |
|
1382 | allcopies.update(ctx.p2copies()) | |
1383 | return sorted(allcopies.items()) |
|
1383 | return sorted(allcopies.items()) | |
1384 | else: |
|
1384 | else: | |
1385 | return sorted(ctx.p1copies().items()) |
|
1385 | return sorted(ctx.p1copies().items()) | |
1386 |
|
1386 | |||
1387 | else: |
|
1387 | else: | |
1388 | getrenamed = getrenamedfn(repo, endrev) |
|
1388 | getrenamed = getrenamedfn(repo, endrev) | |
1389 |
|
1389 | |||
1390 | def copiesfn(ctx): |
|
1390 | def copiesfn(ctx): | |
1391 | copies = [] |
|
1391 | copies = [] | |
1392 | for fn in ctx.files(): |
|
1392 | for fn in ctx.files(): | |
1393 | rename = getrenamed(fn, ctx.rev()) |
|
1393 | rename = getrenamed(fn, ctx.rev()) | |
1394 | if rename: |
|
1394 | if rename: | |
1395 | copies.append((fn, rename)) |
|
1395 | copies.append((fn, rename)) | |
1396 | return copies |
|
1396 | return copies | |
1397 |
|
1397 | |||
1398 | return copiesfn |
|
1398 | return copiesfn | |
1399 |
|
1399 | |||
1400 |
|
1400 | |||
1401 | def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
|
1401 | def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): | |
1402 | """Update the dirstate to reflect the intent of copying src to dst. For |
|
1402 | """Update the dirstate to reflect the intent of copying src to dst. For | |
1403 | different reasons it might not end with dst being marked as copied from src. |
|
1403 | different reasons it might not end with dst being marked as copied from src. | |
1404 | """ |
|
1404 | """ | |
1405 | origsrc = repo.dirstate.copied(src) or src |
|
1405 | origsrc = repo.dirstate.copied(src) or src | |
1406 | if dst == origsrc: # copying back a copy? |
|
1406 | if dst == origsrc: # copying back a copy? | |
1407 | if repo.dirstate[dst] not in b'mn' and not dryrun: |
|
1407 | if repo.dirstate[dst] not in b'mn' and not dryrun: | |
1408 | repo.dirstate.normallookup(dst) |
|
1408 | repo.dirstate.normallookup(dst) | |
1409 | else: |
|
1409 | else: | |
1410 | if repo.dirstate[origsrc] == b'a' and origsrc == src: |
|
1410 | if repo.dirstate[origsrc] == b'a' and origsrc == src: | |
1411 | if not ui.quiet: |
|
1411 | if not ui.quiet: | |
1412 | ui.warn( |
|
1412 | ui.warn( | |
1413 | _( |
|
1413 | _( | |
1414 | b"%s has not been committed yet, so no copy " |
|
1414 | b"%s has not been committed yet, so no copy " | |
1415 | b"data will be stored for %s.\n" |
|
1415 | b"data will be stored for %s.\n" | |
1416 | ) |
|
1416 | ) | |
1417 | % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd)) |
|
1417 | % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd)) | |
1418 | ) |
|
1418 | ) | |
1419 | if repo.dirstate[dst] in b'?r' and not dryrun: |
|
1419 | if repo.dirstate[dst] in b'?r' and not dryrun: | |
1420 | wctx.add([dst]) |
|
1420 | wctx.add([dst]) | |
1421 | elif not dryrun: |
|
1421 | elif not dryrun: | |
1422 | wctx.copy(origsrc, dst) |
|
1422 | wctx.copy(origsrc, dst) | |
1423 |
|
1423 | |||
1424 |
|
1424 | |||
1425 | def movedirstate(repo, newctx, match=None): |
|
1425 | def movedirstate(repo, newctx, match=None): | |
1426 | """Move the dirstate to newctx and adjust it as necessary. |
|
1426 | """Move the dirstate to newctx and adjust it as necessary. | |
1427 |
|
1427 | |||
1428 | A matcher can be provided as an optimization. It is probably a bug to pass |
|
1428 | A matcher can be provided as an optimization. It is probably a bug to pass | |
1429 | a matcher that doesn't match all the differences between the parent of the |
|
1429 | a matcher that doesn't match all the differences between the parent of the | |
1430 | working copy and newctx. |
|
1430 | working copy and newctx. | |
1431 | """ |
|
1431 | """ | |
1432 | oldctx = repo[b'.'] |
|
1432 | oldctx = repo[b'.'] | |
1433 | ds = repo.dirstate |
|
1433 | ds = repo.dirstate | |
1434 | copies = dict(ds.copies()) |
|
1434 | copies = dict(ds.copies()) | |
1435 | ds.setparents(newctx.node(), nullid) |
|
1435 | ds.setparents(newctx.node(), nullid) | |
1436 | s = newctx.status(oldctx, match=match) |
|
1436 | s = newctx.status(oldctx, match=match) | |
1437 | for f in s.modified: |
|
1437 | for f in s.modified: | |
1438 | if ds[f] == b'r': |
|
1438 | if ds[f] == b'r': | |
1439 | # modified + removed -> removed |
|
1439 | # modified + removed -> removed | |
1440 | continue |
|
1440 | continue | |
1441 | ds.normallookup(f) |
|
1441 | ds.normallookup(f) | |
1442 |
|
1442 | |||
1443 | for f in s.added: |
|
1443 | for f in s.added: | |
1444 | if ds[f] == b'r': |
|
1444 | if ds[f] == b'r': | |
1445 | # added + removed -> unknown |
|
1445 | # added + removed -> unknown | |
1446 | ds.drop(f) |
|
1446 | ds.drop(f) | |
1447 | elif ds[f] != b'a': |
|
1447 | elif ds[f] != b'a': | |
1448 | ds.add(f) |
|
1448 | ds.add(f) | |
1449 |
|
1449 | |||
1450 | for f in s.removed: |
|
1450 | for f in s.removed: | |
1451 | if ds[f] == b'a': |
|
1451 | if ds[f] == b'a': | |
1452 | # removed + added -> normal |
|
1452 | # removed + added -> normal | |
1453 | ds.normallookup(f) |
|
1453 | ds.normallookup(f) | |
1454 | elif ds[f] != b'r': |
|
1454 | elif ds[f] != b'r': | |
1455 | ds.remove(f) |
|
1455 | ds.remove(f) | |
1456 |
|
1456 | |||
1457 | # Merge old parent and old working dir copies |
|
1457 | # Merge old parent and old working dir copies | |
1458 | oldcopies = copiesmod.pathcopies(newctx, oldctx, match) |
|
1458 | oldcopies = copiesmod.pathcopies(newctx, oldctx, match) | |
1459 | oldcopies.update(copies) |
|
1459 | oldcopies.update(copies) | |
1460 | copies = dict( |
|
1460 | copies = dict( | |
1461 | (dst, oldcopies.get(src, src)) |
|
1461 | (dst, oldcopies.get(src, src)) | |
1462 | for dst, src in pycompat.iteritems(oldcopies) |
|
1462 | for dst, src in pycompat.iteritems(oldcopies) | |
1463 | ) |
|
1463 | ) | |
1464 | # Adjust the dirstate copies |
|
1464 | # Adjust the dirstate copies | |
1465 | for dst, src in pycompat.iteritems(copies): |
|
1465 | for dst, src in pycompat.iteritems(copies): | |
1466 | if src not in newctx or dst in newctx or ds[dst] != b'a': |
|
1466 | if src not in newctx or dst in newctx or ds[dst] != b'a': | |
1467 | src = None |
|
1467 | src = None | |
1468 | ds.copy(src, dst) |
|
1468 | ds.copy(src, dst) | |
1469 |
|
1469 | |||
1470 |
|
1470 | |||
1471 | def writerequires(opener, requirements): |
|
1471 | def writerequires(opener, requirements): | |
1472 | with opener(b'requires', b'w', atomictemp=True) as fp: |
|
1472 | with opener(b'requires', b'w', atomictemp=True) as fp: | |
1473 | for r in sorted(requirements): |
|
1473 | for r in sorted(requirements): | |
1474 | fp.write(b"%s\n" % r) |
|
1474 | fp.write(b"%s\n" % r) | |
1475 |
|
1475 | |||
1476 |
|
1476 | |||
1477 | class filecachesubentry(object): |
|
1477 | class filecachesubentry(object): | |
1478 | def __init__(self, path, stat): |
|
1478 | def __init__(self, path, stat): | |
1479 | self.path = path |
|
1479 | self.path = path | |
1480 | self.cachestat = None |
|
1480 | self.cachestat = None | |
1481 | self._cacheable = None |
|
1481 | self._cacheable = None | |
1482 |
|
1482 | |||
1483 | if stat: |
|
1483 | if stat: | |
1484 | self.cachestat = filecachesubentry.stat(self.path) |
|
1484 | self.cachestat = filecachesubentry.stat(self.path) | |
1485 |
|
1485 | |||
1486 | if self.cachestat: |
|
1486 | if self.cachestat: | |
1487 | self._cacheable = self.cachestat.cacheable() |
|
1487 | self._cacheable = self.cachestat.cacheable() | |
1488 | else: |
|
1488 | else: | |
1489 | # None means we don't know yet |
|
1489 | # None means we don't know yet | |
1490 | self._cacheable = None |
|
1490 | self._cacheable = None | |
1491 |
|
1491 | |||
1492 | def refresh(self): |
|
1492 | def refresh(self): | |
1493 | if self.cacheable(): |
|
1493 | if self.cacheable(): | |
1494 | self.cachestat = filecachesubentry.stat(self.path) |
|
1494 | self.cachestat = filecachesubentry.stat(self.path) | |
1495 |
|
1495 | |||
1496 | def cacheable(self): |
|
1496 | def cacheable(self): | |
1497 | if self._cacheable is not None: |
|
1497 | if self._cacheable is not None: | |
1498 | return self._cacheable |
|
1498 | return self._cacheable | |
1499 |
|
1499 | |||
1500 | # we don't know yet, assume it is for now |
|
1500 | # we don't know yet, assume it is for now | |
1501 | return True |
|
1501 | return True | |
1502 |
|
1502 | |||
1503 | def changed(self): |
|
1503 | def changed(self): | |
1504 | # no point in going further if we can't cache it |
|
1504 | # no point in going further if we can't cache it | |
1505 | if not self.cacheable(): |
|
1505 | if not self.cacheable(): | |
1506 | return True |
|
1506 | return True | |
1507 |
|
1507 | |||
1508 | newstat = filecachesubentry.stat(self.path) |
|
1508 | newstat = filecachesubentry.stat(self.path) | |
1509 |
|
1509 | |||
1510 | # we may not know if it's cacheable yet, check again now |
|
1510 | # we may not know if it's cacheable yet, check again now | |
1511 | if newstat and self._cacheable is None: |
|
1511 | if newstat and self._cacheable is None: | |
1512 | self._cacheable = newstat.cacheable() |
|
1512 | self._cacheable = newstat.cacheable() | |
1513 |
|
1513 | |||
1514 | # check again |
|
1514 | # check again | |
1515 | if not self._cacheable: |
|
1515 | if not self._cacheable: | |
1516 | return True |
|
1516 | return True | |
1517 |
|
1517 | |||
1518 | if self.cachestat != newstat: |
|
1518 | if self.cachestat != newstat: | |
1519 | self.cachestat = newstat |
|
1519 | self.cachestat = newstat | |
1520 | return True |
|
1520 | return True | |
1521 | else: |
|
1521 | else: | |
1522 | return False |
|
1522 | return False | |
1523 |
|
1523 | |||
1524 | @staticmethod |
|
1524 | @staticmethod | |
1525 | def stat(path): |
|
1525 | def stat(path): | |
1526 | try: |
|
1526 | try: | |
1527 | return util.cachestat(path) |
|
1527 | return util.cachestat(path) | |
1528 | except OSError as e: |
|
1528 | except OSError as e: | |
1529 | if e.errno != errno.ENOENT: |
|
1529 | if e.errno != errno.ENOENT: | |
1530 | raise |
|
1530 | raise | |
1531 |
|
1531 | |||
1532 |
|
1532 | |||
1533 | class filecacheentry(object): |
|
1533 | class filecacheentry(object): | |
1534 | def __init__(self, paths, stat=True): |
|
1534 | def __init__(self, paths, stat=True): | |
1535 | self._entries = [] |
|
1535 | self._entries = [] | |
1536 | for path in paths: |
|
1536 | for path in paths: | |
1537 | self._entries.append(filecachesubentry(path, stat)) |
|
1537 | self._entries.append(filecachesubentry(path, stat)) | |
1538 |
|
1538 | |||
1539 | def changed(self): |
|
1539 | def changed(self): | |
1540 | '''true if any entry has changed''' |
|
1540 | '''true if any entry has changed''' | |
1541 | for entry in self._entries: |
|
1541 | for entry in self._entries: | |
1542 | if entry.changed(): |
|
1542 | if entry.changed(): | |
1543 | return True |
|
1543 | return True | |
1544 | return False |
|
1544 | return False | |
1545 |
|
1545 | |||
1546 | def refresh(self): |
|
1546 | def refresh(self): | |
1547 | for entry in self._entries: |
|
1547 | for entry in self._entries: | |
1548 | entry.refresh() |
|
1548 | entry.refresh() | |
1549 |
|
1549 | |||
1550 |
|
1550 | |||
1551 | class filecache(object): |
|
1551 | class filecache(object): | |
1552 | """A property like decorator that tracks files under .hg/ for updates. |
|
1552 | """A property like decorator that tracks files under .hg/ for updates. | |
1553 |
|
1553 | |||
1554 | On first access, the files defined as arguments are stat()ed and the |
|
1554 | On first access, the files defined as arguments are stat()ed and the | |
1555 | results cached. The decorated function is called. The results are stashed |
|
1555 | results cached. The decorated function is called. The results are stashed | |
1556 | away in a ``_filecache`` dict on the object whose method is decorated. |
|
1556 | away in a ``_filecache`` dict on the object whose method is decorated. | |
1557 |
|
1557 | |||
1558 | On subsequent access, the cached result is used as it is set to the |
|
1558 | On subsequent access, the cached result is used as it is set to the | |
1559 | instance dictionary. |
|
1559 | instance dictionary. | |
1560 |
|
1560 | |||
1561 | On external property set/delete operations, the caller must update the |
|
1561 | On external property set/delete operations, the caller must update the | |
1562 | corresponding _filecache entry appropriately. Use __class__.<attr>.set() |
|
1562 | corresponding _filecache entry appropriately. Use __class__.<attr>.set() | |
1563 | instead of directly setting <attr>. |
|
1563 | instead of directly setting <attr>. | |
1564 |
|
1564 | |||
1565 | When using the property API, the cached data is always used if available. |
|
1565 | When using the property API, the cached data is always used if available. | |
1566 | No stat() is performed to check if the file has changed. |
|
1566 | No stat() is performed to check if the file has changed. | |
1567 |
|
1567 | |||
1568 | Others can muck about with the state of the ``_filecache`` dict. e.g. they |
|
1568 | Others can muck about with the state of the ``_filecache`` dict. e.g. they | |
1569 | can populate an entry before the property's getter is called. In this case, |
|
1569 | can populate an entry before the property's getter is called. In this case, | |
1570 | entries in ``_filecache`` will be used during property operations, |
|
1570 | entries in ``_filecache`` will be used during property operations, | |
1571 | if available. If the underlying file changes, it is up to external callers |
|
1571 | if available. If the underlying file changes, it is up to external callers | |
1572 | to reflect this by e.g. calling ``delattr(obj, attr)`` to remove the cached |
|
1572 | to reflect this by e.g. calling ``delattr(obj, attr)`` to remove the cached | |
1573 | method result as well as possibly calling ``del obj._filecache[attr]`` to |
|
1573 | method result as well as possibly calling ``del obj._filecache[attr]`` to | |
1574 | remove the ``filecacheentry``. |
|
1574 | remove the ``filecacheentry``. | |
1575 | """ |
|
1575 | """ | |
1576 |
|
1576 | |||
1577 | def __init__(self, *paths): |
|
1577 | def __init__(self, *paths): | |
1578 | self.paths = paths |
|
1578 | self.paths = paths | |
1579 |
|
1579 | |||
1580 | def join(self, obj, fname): |
|
1580 | def join(self, obj, fname): | |
1581 | """Used to compute the runtime path of a cached file. |
|
1581 | """Used to compute the runtime path of a cached file. | |
1582 |
|
1582 | |||
1583 | Users should subclass filecache and provide their own version of this |
|
1583 | Users should subclass filecache and provide their own version of this | |
1584 | function to call the appropriate join function on 'obj' (an instance |
|
1584 | function to call the appropriate join function on 'obj' (an instance | |
1585 | of the class that its member function was decorated). |
|
1585 | of the class that its member function was decorated). | |
1586 | """ |
|
1586 | """ | |
1587 | raise NotImplementedError |
|
1587 | raise NotImplementedError | |
1588 |
|
1588 | |||
1589 | def __call__(self, func): |
|
1589 | def __call__(self, func): | |
1590 | self.func = func |
|
1590 | self.func = func | |
1591 | self.sname = func.__name__ |
|
1591 | self.sname = func.__name__ | |
1592 | self.name = pycompat.sysbytes(self.sname) |
|
1592 | self.name = pycompat.sysbytes(self.sname) | |
1593 | return self |
|
1593 | return self | |
1594 |
|
1594 | |||
1595 | def __get__(self, obj, type=None): |
|
1595 | def __get__(self, obj, type=None): | |
1596 | # if accessed on the class, return the descriptor itself. |
|
1596 | # if accessed on the class, return the descriptor itself. | |
1597 | if obj is None: |
|
1597 | if obj is None: | |
1598 | return self |
|
1598 | return self | |
1599 |
|
1599 | |||
1600 | assert self.sname not in obj.__dict__ |
|
1600 | assert self.sname not in obj.__dict__ | |
1601 |
|
1601 | |||
1602 | entry = obj._filecache.get(self.name) |
|
1602 | entry = obj._filecache.get(self.name) | |
1603 |
|
1603 | |||
1604 | if entry: |
|
1604 | if entry: | |
1605 | if entry.changed(): |
|
1605 | if entry.changed(): | |
1606 | entry.obj = self.func(obj) |
|
1606 | entry.obj = self.func(obj) | |
1607 | else: |
|
1607 | else: | |
1608 | paths = [self.join(obj, path) for path in self.paths] |
|
1608 | paths = [self.join(obj, path) for path in self.paths] | |
1609 |
|
1609 | |||
1610 | # We stat -before- creating the object so our cache doesn't lie if |
|
1610 | # We stat -before- creating the object so our cache doesn't lie if | |
1611 | # a writer modified between the time we read and stat |
|
1611 | # a writer modified between the time we read and stat | |
1612 | entry = filecacheentry(paths, True) |
|
1612 | entry = filecacheentry(paths, True) | |
1613 | entry.obj = self.func(obj) |
|
1613 | entry.obj = self.func(obj) | |
1614 |
|
1614 | |||
1615 | obj._filecache[self.name] = entry |
|
1615 | obj._filecache[self.name] = entry | |
1616 |
|
1616 | |||
1617 | obj.__dict__[self.sname] = entry.obj |
|
1617 | obj.__dict__[self.sname] = entry.obj | |
1618 | return entry.obj |
|
1618 | return entry.obj | |
1619 |
|
1619 | |||
1620 | # don't implement __set__(), which would make __dict__ lookup as slow as |
|
1620 | # don't implement __set__(), which would make __dict__ lookup as slow as | |
1621 | # function call. |
|
1621 | # function call. | |
1622 |
|
1622 | |||
1623 | def set(self, obj, value): |
|
1623 | def set(self, obj, value): | |
1624 | if self.name not in obj._filecache: |
|
1624 | if self.name not in obj._filecache: | |
1625 | # we add an entry for the missing value because X in __dict__ |
|
1625 | # we add an entry for the missing value because X in __dict__ | |
1626 | # implies X in _filecache |
|
1626 | # implies X in _filecache | |
1627 | paths = [self.join(obj, path) for path in self.paths] |
|
1627 | paths = [self.join(obj, path) for path in self.paths] | |
1628 | ce = filecacheentry(paths, False) |
|
1628 | ce = filecacheentry(paths, False) | |
1629 | obj._filecache[self.name] = ce |
|
1629 | obj._filecache[self.name] = ce | |
1630 | else: |
|
1630 | else: | |
1631 | ce = obj._filecache[self.name] |
|
1631 | ce = obj._filecache[self.name] | |
1632 |
|
1632 | |||
1633 | ce.obj = value # update cached copy |
|
1633 | ce.obj = value # update cached copy | |
1634 | obj.__dict__[self.sname] = value # update copy returned by obj.x |
|
1634 | obj.__dict__[self.sname] = value # update copy returned by obj.x | |
1635 |
|
1635 | |||
1636 |
|
1636 | |||
1637 | def extdatasource(repo, source): |
|
1637 | def extdatasource(repo, source): | |
1638 | """Gather a map of rev -> value dict from the specified source |
|
1638 | """Gather a map of rev -> value dict from the specified source | |
1639 |
|
1639 | |||
1640 | A source spec is treated as a URL, with a special case shell: type |
|
1640 | A source spec is treated as a URL, with a special case shell: type | |
1641 | for parsing the output from a shell command. |
|
1641 | for parsing the output from a shell command. | |
1642 |
|
1642 | |||
1643 | The data is parsed as a series of newline-separated records where |
|
1643 | The data is parsed as a series of newline-separated records where | |
1644 | each record is a revision specifier optionally followed by a space |
|
1644 | each record is a revision specifier optionally followed by a space | |
1645 | and a freeform string value. If the revision is known locally, it |
|
1645 | and a freeform string value. If the revision is known locally, it | |
1646 | is converted to a rev, otherwise the record is skipped. |
|
1646 | is converted to a rev, otherwise the record is skipped. | |
1647 |
|
1647 | |||
1648 | Note that both key and value are treated as UTF-8 and converted to |
|
1648 | Note that both key and value are treated as UTF-8 and converted to | |
1649 | the local encoding. This allows uniformity between local and |
|
1649 | the local encoding. This allows uniformity between local and | |
1650 | remote data sources. |
|
1650 | remote data sources. | |
1651 | """ |
|
1651 | """ | |
1652 |
|
1652 | |||
1653 | spec = repo.ui.config(b"extdata", source) |
|
1653 | spec = repo.ui.config(b"extdata", source) | |
1654 | if not spec: |
|
1654 | if not spec: | |
1655 | raise error.Abort(_(b"unknown extdata source '%s'") % source) |
|
1655 | raise error.Abort(_(b"unknown extdata source '%s'") % source) | |
1656 |
|
1656 | |||
1657 | data = {} |
|
1657 | data = {} | |
1658 | src = proc = None |
|
1658 | src = proc = None | |
1659 | try: |
|
1659 | try: | |
1660 | if spec.startswith(b"shell:"): |
|
1660 | if spec.startswith(b"shell:"): | |
1661 | # external commands should be run relative to the repo root |
|
1661 | # external commands should be run relative to the repo root | |
1662 | cmd = spec[6:] |
|
1662 | cmd = spec[6:] | |
1663 | proc = subprocess.Popen( |
|
1663 | proc = subprocess.Popen( | |
1664 | procutil.tonativestr(cmd), |
|
1664 | procutil.tonativestr(cmd), | |
1665 | shell=True, |
|
1665 | shell=True, | |
1666 | bufsize=-1, |
|
1666 | bufsize=-1, | |
1667 | close_fds=procutil.closefds, |
|
1667 | close_fds=procutil.closefds, | |
1668 | stdout=subprocess.PIPE, |
|
1668 | stdout=subprocess.PIPE, | |
1669 | cwd=procutil.tonativestr(repo.root), |
|
1669 | cwd=procutil.tonativestr(repo.root), | |
1670 | ) |
|
1670 | ) | |
1671 | src = proc.stdout |
|
1671 | src = proc.stdout | |
1672 | else: |
|
1672 | else: | |
1673 | # treat as a URL or file |
|
1673 | # treat as a URL or file | |
1674 | src = url.open(repo.ui, spec) |
|
1674 | src = url.open(repo.ui, spec) | |
1675 | for l in src: |
|
1675 | for l in src: | |
1676 | if b" " in l: |
|
1676 | if b" " in l: | |
1677 | k, v = l.strip().split(b" ", 1) |
|
1677 | k, v = l.strip().split(b" ", 1) | |
1678 | else: |
|
1678 | else: | |
1679 | k, v = l.strip(), b"" |
|
1679 | k, v = l.strip(), b"" | |
1680 |
|
1680 | |||
1681 | k = encoding.tolocal(k) |
|
1681 | k = encoding.tolocal(k) | |
1682 | try: |
|
1682 | try: | |
1683 | data[revsingle(repo, k).rev()] = encoding.tolocal(v) |
|
1683 | data[revsingle(repo, k).rev()] = encoding.tolocal(v) | |
1684 | except (error.LookupError, error.RepoLookupError): |
|
1684 | except (error.LookupError, error.RepoLookupError): | |
1685 | pass # we ignore data for nodes that don't exist locally |
|
1685 | pass # we ignore data for nodes that don't exist locally | |
1686 | finally: |
|
1686 | finally: | |
1687 | if proc: |
|
1687 | if proc: | |
1688 | try: |
|
1688 | try: | |
1689 | proc.communicate() |
|
1689 | proc.communicate() | |
1690 | except ValueError: |
|
1690 | except ValueError: | |
1691 | # This happens if we started iterating src and then |
|
1691 | # This happens if we started iterating src and then | |
1692 | # get a parse error on a line. It should be safe to ignore. |
|
1692 | # get a parse error on a line. It should be safe to ignore. | |
1693 | pass |
|
1693 | pass | |
1694 | if src: |
|
1694 | if src: | |
1695 | src.close() |
|
1695 | src.close() | |
1696 | if proc and proc.returncode != 0: |
|
1696 | if proc and proc.returncode != 0: | |
1697 | raise error.Abort( |
|
1697 | raise error.Abort( | |
1698 | _(b"extdata command '%s' failed: %s") |
|
1698 | _(b"extdata command '%s' failed: %s") | |
1699 | % (cmd, procutil.explainexit(proc.returncode)) |
|
1699 | % (cmd, procutil.explainexit(proc.returncode)) | |
1700 | ) |
|
1700 | ) | |
1701 |
|
1701 | |||
1702 | return data |
|
1702 | return data | |
1703 |
|
1703 | |||
1704 |
|
1704 | |||
1705 | def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): |
|
1705 | def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): | |
1706 | if lock is None: |
|
1706 | if lock is None: | |
1707 | raise error.LockInheritanceContractViolation( |
|
1707 | raise error.LockInheritanceContractViolation( | |
1708 | b'lock can only be inherited while held' |
|
1708 | b'lock can only be inherited while held' | |
1709 | ) |
|
1709 | ) | |
1710 | if environ is None: |
|
1710 | if environ is None: | |
1711 | environ = {} |
|
1711 | environ = {} | |
1712 | with lock.inherit() as locker: |
|
1712 | with lock.inherit() as locker: | |
1713 | environ[envvar] = locker |
|
1713 | environ[envvar] = locker | |
1714 | return repo.ui.system(cmd, environ=environ, *args, **kwargs) |
|
1714 | return repo.ui.system(cmd, environ=environ, *args, **kwargs) | |
1715 |
|
1715 | |||
1716 |
|
1716 | |||
1717 | def wlocksub(repo, cmd, *args, **kwargs): |
|
1717 | def wlocksub(repo, cmd, *args, **kwargs): | |
1718 | """run cmd as a subprocess that allows inheriting repo's wlock |
|
1718 | """run cmd as a subprocess that allows inheriting repo's wlock | |
1719 |
|
1719 | |||
1720 | This can only be called while the wlock is held. This takes all the |
|
1720 | This can only be called while the wlock is held. This takes all the | |
1721 | arguments that ui.system does, and returns the exit code of the |
|
1721 | arguments that ui.system does, and returns the exit code of the | |
1722 | subprocess.""" |
|
1722 | subprocess.""" | |
1723 | return _locksub( |
|
1723 | return _locksub( | |
1724 | repo, repo.currentwlock(), b'HG_WLOCK_LOCKER', cmd, *args, **kwargs |
|
1724 | repo, repo.currentwlock(), b'HG_WLOCK_LOCKER', cmd, *args, **kwargs | |
1725 | ) |
|
1725 | ) | |
1726 |
|
1726 | |||
1727 |
|
1727 | |||
1728 | class progress(object): |
|
1728 | class progress(object): | |
1729 | def __init__(self, ui, updatebar, topic, unit=b"", total=None): |
|
1729 | def __init__(self, ui, updatebar, topic, unit=b"", total=None): | |
1730 | self.ui = ui |
|
1730 | self.ui = ui | |
1731 | self.pos = 0 |
|
1731 | self.pos = 0 | |
1732 | self.topic = topic |
|
1732 | self.topic = topic | |
1733 | self.unit = unit |
|
1733 | self.unit = unit | |
1734 | self.total = total |
|
1734 | self.total = total | |
1735 | self.debug = ui.configbool(b'progress', b'debug') |
|
1735 | self.debug = ui.configbool(b'progress', b'debug') | |
1736 | self._updatebar = updatebar |
|
1736 | self._updatebar = updatebar | |
1737 |
|
1737 | |||
1738 | def __enter__(self): |
|
1738 | def __enter__(self): | |
1739 | return self |
|
1739 | return self | |
1740 |
|
1740 | |||
1741 | def __exit__(self, exc_type, exc_value, exc_tb): |
|
1741 | def __exit__(self, exc_type, exc_value, exc_tb): | |
1742 | self.complete() |
|
1742 | self.complete() | |
1743 |
|
1743 | |||
1744 | def update(self, pos, item=b"", total=None): |
|
1744 | def update(self, pos, item=b"", total=None): | |
1745 | assert pos is not None |
|
1745 | assert pos is not None | |
1746 | if total: |
|
1746 | if total: | |
1747 | self.total = total |
|
1747 | self.total = total | |
1748 | self.pos = pos |
|
1748 | self.pos = pos | |
1749 | self._updatebar(self.topic, self.pos, item, self.unit, self.total) |
|
1749 | self._updatebar(self.topic, self.pos, item, self.unit, self.total) | |
1750 | if self.debug: |
|
1750 | if self.debug: | |
1751 | self._printdebug(item) |
|
1751 | self._printdebug(item) | |
1752 |
|
1752 | |||
1753 | def increment(self, step=1, item=b"", total=None): |
|
1753 | def increment(self, step=1, item=b"", total=None): | |
1754 | self.update(self.pos + step, item, total) |
|
1754 | self.update(self.pos + step, item, total) | |
1755 |
|
1755 | |||
1756 | def complete(self): |
|
1756 | def complete(self): | |
1757 | self.pos = None |
|
1757 | self.pos = None | |
1758 | self.unit = b"" |
|
1758 | self.unit = b"" | |
1759 | self.total = None |
|
1759 | self.total = None | |
1760 | self._updatebar(self.topic, self.pos, b"", self.unit, self.total) |
|
1760 | self._updatebar(self.topic, self.pos, b"", self.unit, self.total) | |
1761 |
|
1761 | |||
1762 | def _printdebug(self, item): |
|
1762 | def _printdebug(self, item): | |
1763 | unit = b'' |
|
1763 | unit = b'' | |
1764 | if self.unit: |
|
1764 | if self.unit: | |
1765 | unit = b' ' + self.unit |
|
1765 | unit = b' ' + self.unit | |
1766 | if item: |
|
1766 | if item: | |
1767 | item = b' ' + item |
|
1767 | item = b' ' + item | |
1768 |
|
1768 | |||
1769 | if self.total: |
|
1769 | if self.total: | |
1770 | pct = 100.0 * self.pos / self.total |
|
1770 | pct = 100.0 * self.pos / self.total | |
1771 | self.ui.debug( |
|
1771 | self.ui.debug( | |
1772 | b'%s:%s %d/%d%s (%4.2f%%)\n' |
|
1772 | b'%s:%s %d/%d%s (%4.2f%%)\n' | |
1773 | % (self.topic, item, self.pos, self.total, unit, pct) |
|
1773 | % (self.topic, item, self.pos, self.total, unit, pct) | |
1774 | ) |
|
1774 | ) | |
1775 | else: |
|
1775 | else: | |
1776 | self.ui.debug(b'%s:%s %d%s\n' % (self.topic, item, self.pos, unit)) |
|
1776 | self.ui.debug(b'%s:%s %d%s\n' % (self.topic, item, self.pos, unit)) | |
1777 |
|
1777 | |||
1778 |
|
1778 | |||
1779 | def gdinitconfig(ui): |
|
1779 | def gdinitconfig(ui): | |
1780 | """helper function to know if a repo should be created as general delta |
|
1780 | """helper function to know if a repo should be created as general delta | |
1781 | """ |
|
1781 | """ | |
1782 | # experimental config: format.generaldelta |
|
1782 | # experimental config: format.generaldelta | |
1783 | return ui.configbool(b'format', b'generaldelta') or ui.configbool( |
|
1783 | return ui.configbool(b'format', b'generaldelta') or ui.configbool( | |
1784 | b'format', b'usegeneraldelta' |
|
1784 | b'format', b'usegeneraldelta' | |
1785 | ) |
|
1785 | ) | |
1786 |
|
1786 | |||
1787 |
|
1787 | |||
1788 | def gddeltaconfig(ui): |
|
1788 | def gddeltaconfig(ui): | |
1789 | """helper function to know if incoming delta should be optimised |
|
1789 | """helper function to know if incoming delta should be optimised | |
1790 | """ |
|
1790 | """ | |
1791 | # experimental config: format.generaldelta |
|
1791 | # experimental config: format.generaldelta | |
1792 | return ui.configbool(b'format', b'generaldelta') |
|
1792 | return ui.configbool(b'format', b'generaldelta') | |
1793 |
|
1793 | |||
1794 |
|
1794 | |||
1795 | class simplekeyvaluefile(object): |
|
1795 | class simplekeyvaluefile(object): | |
1796 | """A simple file with key=value lines |
|
1796 | """A simple file with key=value lines | |
1797 |
|
1797 | |||
1798 | Keys must be alphanumerics and start with a letter, values must not |
|
1798 | Keys must be alphanumerics and start with a letter, values must not | |
1799 | contain '\n' characters""" |
|
1799 | contain '\n' characters""" | |
1800 |
|
1800 | |||
1801 | firstlinekey = b'__firstline' |
|
1801 | firstlinekey = b'__firstline' | |
1802 |
|
1802 | |||
1803 | def __init__(self, vfs, path, keys=None): |
|
1803 | def __init__(self, vfs, path, keys=None): | |
1804 | self.vfs = vfs |
|
1804 | self.vfs = vfs | |
1805 | self.path = path |
|
1805 | self.path = path | |
1806 |
|
1806 | |||
1807 | def read(self, firstlinenonkeyval=False): |
|
1807 | def read(self, firstlinenonkeyval=False): | |
1808 | """Read the contents of a simple key-value file |
|
1808 | """Read the contents of a simple key-value file | |
1809 |
|
1809 | |||
1810 | 'firstlinenonkeyval' indicates whether the first line of file should |
|
1810 | 'firstlinenonkeyval' indicates whether the first line of file should | |
1811 | be treated as a key-value pair or reuturned fully under the |
|
1811 | be treated as a key-value pair or reuturned fully under the | |
1812 | __firstline key.""" |
|
1812 | __firstline key.""" | |
1813 | lines = self.vfs.readlines(self.path) |
|
1813 | lines = self.vfs.readlines(self.path) | |
1814 | d = {} |
|
1814 | d = {} | |
1815 | if firstlinenonkeyval: |
|
1815 | if firstlinenonkeyval: | |
1816 | if not lines: |
|
1816 | if not lines: | |
1817 | e = _(b"empty simplekeyvalue file") |
|
1817 | e = _(b"empty simplekeyvalue file") | |
1818 | raise error.CorruptedState(e) |
|
1818 | raise error.CorruptedState(e) | |
1819 | # we don't want to include '\n' in the __firstline |
|
1819 | # we don't want to include '\n' in the __firstline | |
1820 | d[self.firstlinekey] = lines[0][:-1] |
|
1820 | d[self.firstlinekey] = lines[0][:-1] | |
1821 | del lines[0] |
|
1821 | del lines[0] | |
1822 |
|
1822 | |||
1823 | try: |
|
1823 | try: | |
1824 | # the 'if line.strip()' part prevents us from failing on empty |
|
1824 | # the 'if line.strip()' part prevents us from failing on empty | |
1825 | # lines which only contain '\n' therefore are not skipped |
|
1825 | # lines which only contain '\n' therefore are not skipped | |
1826 | # by 'if line' |
|
1826 | # by 'if line' | |
1827 | updatedict = dict( |
|
1827 | updatedict = dict( | |
1828 | line[:-1].split(b'=', 1) for line in lines if line.strip() |
|
1828 | line[:-1].split(b'=', 1) for line in lines if line.strip() | |
1829 | ) |
|
1829 | ) | |
1830 | if self.firstlinekey in updatedict: |
|
1830 | if self.firstlinekey in updatedict: | |
1831 | e = _(b"%r can't be used as a key") |
|
1831 | e = _(b"%r can't be used as a key") | |
1832 | raise error.CorruptedState(e % self.firstlinekey) |
|
1832 | raise error.CorruptedState(e % self.firstlinekey) | |
1833 | d.update(updatedict) |
|
1833 | d.update(updatedict) | |
1834 | except ValueError as e: |
|
1834 | except ValueError as e: | |
1835 | raise error.CorruptedState(stringutil.forcebytestr(e)) |
|
1835 | raise error.CorruptedState(stringutil.forcebytestr(e)) | |
1836 | return d |
|
1836 | return d | |
1837 |
|
1837 | |||
1838 | def write(self, data, firstline=None): |
|
1838 | def write(self, data, firstline=None): | |
1839 | """Write key=>value mapping to a file |
|
1839 | """Write key=>value mapping to a file | |
1840 | data is a dict. Keys must be alphanumerical and start with a letter. |
|
1840 | data is a dict. Keys must be alphanumerical and start with a letter. | |
1841 | Values must not contain newline characters. |
|
1841 | Values must not contain newline characters. | |
1842 |
|
1842 | |||
1843 | If 'firstline' is not None, it is written to file before |
|
1843 | If 'firstline' is not None, it is written to file before | |
1844 | everything else, as it is, not in a key=value form""" |
|
1844 | everything else, as it is, not in a key=value form""" | |
1845 | lines = [] |
|
1845 | lines = [] | |
1846 | if firstline is not None: |
|
1846 | if firstline is not None: | |
1847 | lines.append(b'%s\n' % firstline) |
|
1847 | lines.append(b'%s\n' % firstline) | |
1848 |
|
1848 | |||
1849 | for k, v in data.items(): |
|
1849 | for k, v in data.items(): | |
1850 | if k == self.firstlinekey: |
|
1850 | if k == self.firstlinekey: | |
1851 | e = b"key name '%s' is reserved" % self.firstlinekey |
|
1851 | e = b"key name '%s' is reserved" % self.firstlinekey | |
1852 | raise error.ProgrammingError(e) |
|
1852 | raise error.ProgrammingError(e) | |
1853 | if not k[0:1].isalpha(): |
|
1853 | if not k[0:1].isalpha(): | |
1854 | e = b"keys must start with a letter in a key-value file" |
|
1854 | e = b"keys must start with a letter in a key-value file" | |
1855 | raise error.ProgrammingError(e) |
|
1855 | raise error.ProgrammingError(e) | |
1856 | if not k.isalnum(): |
|
1856 | if not k.isalnum(): | |
1857 | e = b"invalid key name in a simple key-value file" |
|
1857 | e = b"invalid key name in a simple key-value file" | |
1858 | raise error.ProgrammingError(e) |
|
1858 | raise error.ProgrammingError(e) | |
1859 | if b'\n' in v: |
|
1859 | if b'\n' in v: | |
1860 | e = b"invalid value in a simple key-value file" |
|
1860 | e = b"invalid value in a simple key-value file" | |
1861 | raise error.ProgrammingError(e) |
|
1861 | raise error.ProgrammingError(e) | |
1862 | lines.append(b"%s=%s\n" % (k, v)) |
|
1862 | lines.append(b"%s=%s\n" % (k, v)) | |
1863 | with self.vfs(self.path, mode=b'wb', atomictemp=True) as fp: |
|
1863 | with self.vfs(self.path, mode=b'wb', atomictemp=True) as fp: | |
1864 | fp.write(b''.join(lines)) |
|
1864 | fp.write(b''.join(lines)) | |
1865 |
|
1865 | |||
1866 |
|
1866 | |||
1867 | _reportobsoletedsource = [ |
|
1867 | _reportobsoletedsource = [ | |
1868 | b'debugobsolete', |
|
1868 | b'debugobsolete', | |
1869 | b'pull', |
|
1869 | b'pull', | |
1870 | b'push', |
|
1870 | b'push', | |
1871 | b'serve', |
|
1871 | b'serve', | |
1872 | b'unbundle', |
|
1872 | b'unbundle', | |
1873 | ] |
|
1873 | ] | |
1874 |
|
1874 | |||
1875 | _reportnewcssource = [ |
|
1875 | _reportnewcssource = [ | |
1876 | b'pull', |
|
1876 | b'pull', | |
1877 | b'unbundle', |
|
1877 | b'unbundle', | |
1878 | ] |
|
1878 | ] | |
1879 |
|
1879 | |||
1880 |
|
1880 | |||
1881 | def prefetchfiles(repo, revs, match): |
|
1881 | def prefetchfiles(repo, revs, match): | |
1882 | """Invokes the registered file prefetch functions, allowing extensions to |
|
1882 | """Invokes the registered file prefetch functions, allowing extensions to | |
1883 | ensure the corresponding files are available locally, before the command |
|
1883 | ensure the corresponding files are available locally, before the command | |
1884 | uses them.""" |
|
1884 | uses them.""" | |
1885 | if match: |
|
1885 | if match: | |
1886 | # The command itself will complain about files that don't exist, so |
|
1886 | # The command itself will complain about files that don't exist, so | |
1887 | # don't duplicate the message. |
|
1887 | # don't duplicate the message. | |
1888 | match = matchmod.badmatch(match, lambda fn, msg: None) |
|
1888 | match = matchmod.badmatch(match, lambda fn, msg: None) | |
1889 | else: |
|
1889 | else: | |
1890 | match = matchall(repo) |
|
1890 | match = matchall(repo) | |
1891 |
|
1891 | |||
1892 | fileprefetchhooks(repo, revs, match) |
|
1892 | fileprefetchhooks(repo, revs, match) | |
1893 |
|
1893 | |||
1894 |
|
1894 | |||
1895 | # a list of (repo, revs, match) prefetch functions |
|
1895 | # a list of (repo, revs, match) prefetch functions | |
1896 | fileprefetchhooks = util.hooks() |
|
1896 | fileprefetchhooks = util.hooks() | |
1897 |
|
1897 | |||
1898 | # A marker that tells the evolve extension to suppress its own reporting |
|
1898 | # A marker that tells the evolve extension to suppress its own reporting | |
1899 | _reportstroubledchangesets = True |
|
1899 | _reportstroubledchangesets = True | |
1900 |
|
1900 | |||
1901 |
|
1901 | |||
1902 | def registersummarycallback(repo, otr, txnname=b''): |
|
1902 | def registersummarycallback(repo, otr, txnname=b''): | |
1903 | """register a callback to issue a summary after the transaction is closed |
|
1903 | """register a callback to issue a summary after the transaction is closed | |
1904 | """ |
|
1904 | """ | |
1905 |
|
1905 | |||
1906 | def txmatch(sources): |
|
1906 | def txmatch(sources): | |
1907 | return any(txnname.startswith(source) for source in sources) |
|
1907 | return any(txnname.startswith(source) for source in sources) | |
1908 |
|
1908 | |||
1909 | categories = [] |
|
1909 | categories = [] | |
1910 |
|
1910 | |||
1911 | def reportsummary(func): |
|
1911 | def reportsummary(func): | |
1912 | """decorator for report callbacks.""" |
|
1912 | """decorator for report callbacks.""" | |
1913 | # The repoview life cycle is shorter than the one of the actual |
|
1913 | # The repoview life cycle is shorter than the one of the actual | |
1914 | # underlying repository. So the filtered object can die before the |
|
1914 | # underlying repository. So the filtered object can die before the | |
1915 | # weakref is used leading to troubles. We keep a reference to the |
|
1915 | # weakref is used leading to troubles. We keep a reference to the | |
1916 | # unfiltered object and restore the filtering when retrieving the |
|
1916 | # unfiltered object and restore the filtering when retrieving the | |
1917 | # repository through the weakref. |
|
1917 | # repository through the weakref. | |
1918 | filtername = repo.filtername |
|
1918 | filtername = repo.filtername | |
1919 | reporef = weakref.ref(repo.unfiltered()) |
|
1919 | reporef = weakref.ref(repo.unfiltered()) | |
1920 |
|
1920 | |||
1921 | def wrapped(tr): |
|
1921 | def wrapped(tr): | |
1922 | repo = reporef() |
|
1922 | repo = reporef() | |
1923 | if filtername: |
|
1923 | if filtername: | |
1924 | assert repo is not None # help pytype |
|
1924 | assert repo is not None # help pytype | |
1925 | repo = repo.filtered(filtername) |
|
1925 | repo = repo.filtered(filtername) | |
1926 | func(repo, tr) |
|
1926 | func(repo, tr) | |
1927 |
|
1927 | |||
1928 | newcat = b'%02i-txnreport' % len(categories) |
|
1928 | newcat = b'%02i-txnreport' % len(categories) | |
1929 | otr.addpostclose(newcat, wrapped) |
|
1929 | otr.addpostclose(newcat, wrapped) | |
1930 | categories.append(newcat) |
|
1930 | categories.append(newcat) | |
1931 | return wrapped |
|
1931 | return wrapped | |
1932 |
|
1932 | |||
1933 | @reportsummary |
|
1933 | @reportsummary | |
1934 | def reportchangegroup(repo, tr): |
|
1934 | def reportchangegroup(repo, tr): | |
1935 | cgchangesets = tr.changes.get(b'changegroup-count-changesets', 0) |
|
1935 | cgchangesets = tr.changes.get(b'changegroup-count-changesets', 0) | |
1936 | cgrevisions = tr.changes.get(b'changegroup-count-revisions', 0) |
|
1936 | cgrevisions = tr.changes.get(b'changegroup-count-revisions', 0) | |
1937 | cgfiles = tr.changes.get(b'changegroup-count-files', 0) |
|
1937 | cgfiles = tr.changes.get(b'changegroup-count-files', 0) | |
1938 | cgheads = tr.changes.get(b'changegroup-count-heads', 0) |
|
1938 | cgheads = tr.changes.get(b'changegroup-count-heads', 0) | |
1939 | if cgchangesets or cgrevisions or cgfiles: |
|
1939 | if cgchangesets or cgrevisions or cgfiles: | |
1940 | htext = b"" |
|
1940 | htext = b"" | |
1941 | if cgheads: |
|
1941 | if cgheads: | |
1942 | htext = _(b" (%+d heads)") % cgheads |
|
1942 | htext = _(b" (%+d heads)") % cgheads | |
1943 | msg = _(b"added %d changesets with %d changes to %d files%s\n") |
|
1943 | msg = _(b"added %d changesets with %d changes to %d files%s\n") | |
1944 | assert repo is not None # help pytype |
|
1944 | assert repo is not None # help pytype | |
1945 | repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) |
|
1945 | repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) | |
1946 |
|
1946 | |||
1947 | if txmatch(_reportobsoletedsource): |
|
1947 | if txmatch(_reportobsoletedsource): | |
1948 |
|
1948 | |||
1949 | @reportsummary |
|
1949 | @reportsummary | |
1950 | def reportobsoleted(repo, tr): |
|
1950 | def reportobsoleted(repo, tr): | |
1951 | obsoleted = obsutil.getobsoleted(repo, tr) |
|
1951 | obsoleted = obsutil.getobsoleted(repo, tr) | |
1952 | newmarkers = len(tr.changes.get(b'obsmarkers', ())) |
|
1952 | newmarkers = len(tr.changes.get(b'obsmarkers', ())) | |
1953 | if newmarkers: |
|
1953 | if newmarkers: | |
1954 | repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) |
|
1954 | repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) | |
1955 | if obsoleted: |
|
1955 | if obsoleted: | |
1956 | repo.ui.status(_(b'obsoleted %i changesets\n') % len(obsoleted)) |
|
1956 | repo.ui.status(_(b'obsoleted %i changesets\n') % len(obsoleted)) | |
1957 |
|
1957 | |||
1958 | if obsolete.isenabled( |
|
1958 | if obsolete.isenabled( | |
1959 | repo, obsolete.createmarkersopt |
|
1959 | repo, obsolete.createmarkersopt | |
1960 | ) and repo.ui.configbool( |
|
1960 | ) and repo.ui.configbool( | |
1961 | b'experimental', b'evolution.report-instabilities' |
|
1961 | b'experimental', b'evolution.report-instabilities' | |
1962 | ): |
|
1962 | ): | |
1963 | instabilitytypes = [ |
|
1963 | instabilitytypes = [ | |
1964 | (b'orphan', b'orphan'), |
|
1964 | (b'orphan', b'orphan'), | |
1965 | (b'phase-divergent', b'phasedivergent'), |
|
1965 | (b'phase-divergent', b'phasedivergent'), | |
1966 | (b'content-divergent', b'contentdivergent'), |
|
1966 | (b'content-divergent', b'contentdivergent'), | |
1967 | ] |
|
1967 | ] | |
1968 |
|
1968 | |||
1969 | def getinstabilitycounts(repo): |
|
1969 | def getinstabilitycounts(repo): | |
1970 | filtered = repo.changelog.filteredrevs |
|
1970 | filtered = repo.changelog.filteredrevs | |
1971 | counts = {} |
|
1971 | counts = {} | |
1972 | for instability, revset in instabilitytypes: |
|
1972 | for instability, revset in instabilitytypes: | |
1973 | counts[instability] = len( |
|
1973 | counts[instability] = len( | |
1974 | set(obsolete.getrevs(repo, revset)) - filtered |
|
1974 | set(obsolete.getrevs(repo, revset)) - filtered | |
1975 | ) |
|
1975 | ) | |
1976 | return counts |
|
1976 | return counts | |
1977 |
|
1977 | |||
1978 | oldinstabilitycounts = getinstabilitycounts(repo) |
|
1978 | oldinstabilitycounts = getinstabilitycounts(repo) | |
1979 |
|
1979 | |||
1980 | @reportsummary |
|
1980 | @reportsummary | |
1981 | def reportnewinstabilities(repo, tr): |
|
1981 | def reportnewinstabilities(repo, tr): | |
1982 | newinstabilitycounts = getinstabilitycounts(repo) |
|
1982 | newinstabilitycounts = getinstabilitycounts(repo) | |
1983 | for instability, revset in instabilitytypes: |
|
1983 | for instability, revset in instabilitytypes: | |
1984 | delta = ( |
|
1984 | delta = ( | |
1985 | newinstabilitycounts[instability] |
|
1985 | newinstabilitycounts[instability] | |
1986 | - oldinstabilitycounts[instability] |
|
1986 | - oldinstabilitycounts[instability] | |
1987 | ) |
|
1987 | ) | |
1988 | msg = getinstabilitymessage(delta, instability) |
|
1988 | msg = getinstabilitymessage(delta, instability) | |
1989 | if msg: |
|
1989 | if msg: | |
1990 | repo.ui.warn(msg) |
|
1990 | repo.ui.warn(msg) | |
1991 |
|
1991 | |||
1992 | if txmatch(_reportnewcssource): |
|
1992 | if txmatch(_reportnewcssource): | |
1993 |
|
1993 | |||
1994 | @reportsummary |
|
1994 | @reportsummary | |
1995 | def reportnewcs(repo, tr): |
|
1995 | def reportnewcs(repo, tr): | |
1996 | """Report the range of new revisions pulled/unbundled.""" |
|
1996 | """Report the range of new revisions pulled/unbundled.""" | |
1997 | origrepolen = tr.changes.get(b'origrepolen', len(repo)) |
|
1997 | origrepolen = tr.changes.get(b'origrepolen', len(repo)) | |
1998 | unfi = repo.unfiltered() |
|
1998 | unfi = repo.unfiltered() | |
1999 | if origrepolen >= len(unfi): |
|
1999 | if origrepolen >= len(unfi): | |
2000 | return |
|
2000 | return | |
2001 |
|
2001 | |||
2002 | # Compute the bounds of new visible revisions' range. |
|
2002 | # Compute the bounds of new visible revisions' range. | |
2003 | revs = smartset.spanset(repo, start=origrepolen) |
|
2003 | revs = smartset.spanset(repo, start=origrepolen) | |
2004 | if revs: |
|
2004 | if revs: | |
2005 | minrev, maxrev = repo[revs.min()], repo[revs.max()] |
|
2005 | minrev, maxrev = repo[revs.min()], repo[revs.max()] | |
2006 |
|
2006 | |||
2007 | if minrev == maxrev: |
|
2007 | if minrev == maxrev: | |
2008 | revrange = minrev |
|
2008 | revrange = minrev | |
2009 | else: |
|
2009 | else: | |
2010 | revrange = b'%s:%s' % (minrev, maxrev) |
|
2010 | revrange = b'%s:%s' % (minrev, maxrev) | |
2011 | draft = len(repo.revs(b'%ld and draft()', revs)) |
|
2011 | draft = len(repo.revs(b'%ld and draft()', revs)) | |
2012 | secret = len(repo.revs(b'%ld and secret()', revs)) |
|
2012 | secret = len(repo.revs(b'%ld and secret()', revs)) | |
2013 | if not (draft or secret): |
|
2013 | if not (draft or secret): | |
2014 | msg = _(b'new changesets %s\n') % revrange |
|
2014 | msg = _(b'new changesets %s\n') % revrange | |
2015 | elif draft and secret: |
|
2015 | elif draft and secret: | |
2016 | msg = _(b'new changesets %s (%d drafts, %d secrets)\n') |
|
2016 | msg = _(b'new changesets %s (%d drafts, %d secrets)\n') | |
2017 | msg %= (revrange, draft, secret) |
|
2017 | msg %= (revrange, draft, secret) | |
2018 | elif draft: |
|
2018 | elif draft: | |
2019 | msg = _(b'new changesets %s (%d drafts)\n') |
|
2019 | msg = _(b'new changesets %s (%d drafts)\n') | |
2020 | msg %= (revrange, draft) |
|
2020 | msg %= (revrange, draft) | |
2021 | elif secret: |
|
2021 | elif secret: | |
2022 | msg = _(b'new changesets %s (%d secrets)\n') |
|
2022 | msg = _(b'new changesets %s (%d secrets)\n') | |
2023 | msg %= (revrange, secret) |
|
2023 | msg %= (revrange, secret) | |
2024 | else: |
|
2024 | else: | |
2025 | errormsg = b'entered unreachable condition' |
|
2025 | errormsg = b'entered unreachable condition' | |
2026 | raise error.ProgrammingError(errormsg) |
|
2026 | raise error.ProgrammingError(errormsg) | |
2027 | repo.ui.status(msg) |
|
2027 | repo.ui.status(msg) | |
2028 |
|
2028 | |||
2029 | # search new changesets directly pulled as obsolete |
|
2029 | # search new changesets directly pulled as obsolete | |
2030 | duplicates = tr.changes.get(b'revduplicates', ()) |
|
2030 | duplicates = tr.changes.get(b'revduplicates', ()) | |
2031 | obsadded = unfi.revs( |
|
2031 | obsadded = unfi.revs( | |
2032 | b'(%d: + %ld) and obsolete()', origrepolen, duplicates |
|
2032 | b'(%d: + %ld) and obsolete()', origrepolen, duplicates | |
2033 | ) |
|
2033 | ) | |
2034 | cl = repo.changelog |
|
2034 | cl = repo.changelog | |
2035 | extinctadded = [r for r in obsadded if r not in cl] |
|
2035 | extinctadded = [r for r in obsadded if r not in cl] | |
2036 | if extinctadded: |
|
2036 | if extinctadded: | |
2037 | # They are not just obsolete, but obsolete and invisible |
|
2037 | # They are not just obsolete, but obsolete and invisible | |
2038 | # we call them "extinct" internally but the terms have not been |
|
2038 | # we call them "extinct" internally but the terms have not been | |
2039 | # exposed to users. |
|
2039 | # exposed to users. | |
2040 | msg = b'(%d other changesets obsolete on arrival)\n' |
|
2040 | msg = b'(%d other changesets obsolete on arrival)\n' | |
2041 | repo.ui.status(msg % len(extinctadded)) |
|
2041 | repo.ui.status(msg % len(extinctadded)) | |
2042 |
|
2042 | |||
2043 | @reportsummary |
|
2043 | @reportsummary | |
2044 | def reportphasechanges(repo, tr): |
|
2044 | def reportphasechanges(repo, tr): | |
2045 | """Report statistics of phase changes for changesets pre-existing |
|
2045 | """Report statistics of phase changes for changesets pre-existing | |
2046 | pull/unbundle. |
|
2046 | pull/unbundle. | |
2047 | """ |
|
2047 | """ | |
2048 | origrepolen = tr.changes.get(b'origrepolen', len(repo)) |
|
2048 | origrepolen = tr.changes.get(b'origrepolen', len(repo)) | |
2049 | phasetracking = tr.changes.get(b'phases', {}) |
|
2049 | phasetracking = tr.changes.get(b'phases', {}) | |
2050 | if not phasetracking: |
|
2050 | if not phasetracking: | |
2051 | return |
|
2051 | return | |
2052 | published = [ |
|
2052 | published = [ | |
2053 | rev |
|
2053 | rev | |
2054 | for rev, (old, new) in pycompat.iteritems(phasetracking) |
|
2054 | for rev, (old, new) in pycompat.iteritems(phasetracking) | |
2055 | if new == phases.public and rev < origrepolen |
|
2055 | if new == phases.public and rev < origrepolen | |
2056 | ] |
|
2056 | ] | |
2057 | if not published: |
|
2057 | if not published: | |
2058 | return |
|
2058 | return | |
2059 | repo.ui.status( |
|
2059 | repo.ui.status( | |
2060 | _(b'%d local changesets published\n') % len(published) |
|
2060 | _(b'%d local changesets published\n') % len(published) | |
2061 | ) |
|
2061 | ) | |
2062 |
|
2062 | |||
2063 |
|
2063 | |||
2064 | def getinstabilitymessage(delta, instability): |
|
2064 | def getinstabilitymessage(delta, instability): | |
2065 | """function to return the message to show warning about new instabilities |
|
2065 | """function to return the message to show warning about new instabilities | |
2066 |
|
2066 | |||
2067 | exists as a separate function so that extension can wrap to show more |
|
2067 | exists as a separate function so that extension can wrap to show more | |
2068 | information like how to fix instabilities""" |
|
2068 | information like how to fix instabilities""" | |
2069 | if delta > 0: |
|
2069 | if delta > 0: | |
2070 | return _(b'%i new %s changesets\n') % (delta, instability) |
|
2070 | return _(b'%i new %s changesets\n') % (delta, instability) | |
2071 |
|
2071 | |||
2072 |
|
2072 | |||
2073 | def nodesummaries(repo, nodes, maxnumnodes=4): |
|
2073 | def nodesummaries(repo, nodes, maxnumnodes=4): | |
2074 | if len(nodes) <= maxnumnodes or repo.ui.verbose: |
|
2074 | if len(nodes) <= maxnumnodes or repo.ui.verbose: | |
2075 | return b' '.join(short(h) for h in nodes) |
|
2075 | return b' '.join(short(h) for h in nodes) | |
2076 | first = b' '.join(short(h) for h in nodes[:maxnumnodes]) |
|
2076 | first = b' '.join(short(h) for h in nodes[:maxnumnodes]) | |
2077 | return _(b"%s and %d others") % (first, len(nodes) - maxnumnodes) |
|
2077 | return _(b"%s and %d others") % (first, len(nodes) - maxnumnodes) | |
2078 |
|
2078 | |||
2079 |
|
2079 | |||
2080 | def enforcesinglehead(repo, tr, desc, accountclosed=False): |
|
2080 | def enforcesinglehead(repo, tr, desc, accountclosed=False): | |
2081 | """check that no named branch has multiple heads""" |
|
2081 | """check that no named branch has multiple heads""" | |
2082 | if desc in (b'strip', b'repair'): |
|
2082 | if desc in (b'strip', b'repair'): | |
2083 | # skip the logic during strip |
|
2083 | # skip the logic during strip | |
2084 | return |
|
2084 | return | |
2085 | visible = repo.filtered(b'visible') |
|
2085 | visible = repo.filtered(b'visible') | |
2086 | # possible improvement: we could restrict the check to affected branch |
|
2086 | # possible improvement: we could restrict the check to affected branch | |
2087 | bm = visible.branchmap() |
|
2087 | bm = visible.branchmap() | |
2088 | for name in bm: |
|
2088 | for name in bm: | |
2089 | heads = bm.branchheads(name, closed=accountclosed) |
|
2089 | heads = bm.branchheads(name, closed=accountclosed) | |
2090 | if len(heads) > 1: |
|
2090 | if len(heads) > 1: | |
2091 | msg = _(b'rejecting multiple heads on branch "%s"') |
|
2091 | msg = _(b'rejecting multiple heads on branch "%s"') | |
2092 | msg %= name |
|
2092 | msg %= name | |
2093 | hint = _(b'%d heads: %s') |
|
2093 | hint = _(b'%d heads: %s') | |
2094 | hint %= (len(heads), nodesummaries(repo, heads)) |
|
2094 | hint %= (len(heads), nodesummaries(repo, heads)) | |
2095 | raise error.Abort(msg, hint=hint) |
|
2095 | raise error.Abort(msg, hint=hint) | |
2096 |
|
2096 | |||
2097 |
|
2097 | |||
2098 | def wrapconvertsink(sink): |
|
2098 | def wrapconvertsink(sink): | |
2099 | """Allow extensions to wrap the sink returned by convcmd.convertsink() |
|
2099 | """Allow extensions to wrap the sink returned by convcmd.convertsink() | |
2100 | before it is used, whether or not the convert extension was formally loaded. |
|
2100 | before it is used, whether or not the convert extension was formally loaded. | |
2101 | """ |
|
2101 | """ | |
2102 | return sink |
|
2102 | return sink | |
2103 |
|
2103 | |||
2104 |
|
2104 | |||
2105 | def unhidehashlikerevs(repo, specs, hiddentype): |
|
2105 | def unhidehashlikerevs(repo, specs, hiddentype): | |
2106 | """parse the user specs and unhide changesets whose hash or revision number |
|
2106 | """parse the user specs and unhide changesets whose hash or revision number | |
2107 | is passed. |
|
2107 | is passed. | |
2108 |
|
2108 | |||
2109 | hiddentype can be: 1) 'warn': warn while unhiding changesets |
|
2109 | hiddentype can be: 1) 'warn': warn while unhiding changesets | |
2110 | 2) 'nowarn': don't warn while unhiding changesets |
|
2110 | 2) 'nowarn': don't warn while unhiding changesets | |
2111 |
|
2111 | |||
2112 | returns a repo object with the required changesets unhidden |
|
2112 | returns a repo object with the required changesets unhidden | |
2113 | """ |
|
2113 | """ | |
2114 | if not repo.filtername or not repo.ui.configbool( |
|
2114 | if not repo.filtername or not repo.ui.configbool( | |
2115 | b'experimental', b'directaccess' |
|
2115 | b'experimental', b'directaccess' | |
2116 | ): |
|
2116 | ): | |
2117 | return repo |
|
2117 | return repo | |
2118 |
|
2118 | |||
2119 | if repo.filtername not in (b'visible', b'visible-hidden'): |
|
2119 | if repo.filtername not in (b'visible', b'visible-hidden'): | |
2120 | return repo |
|
2120 | return repo | |
2121 |
|
2121 | |||
2122 | symbols = set() |
|
2122 | symbols = set() | |
2123 | for spec in specs: |
|
2123 | for spec in specs: | |
2124 | try: |
|
2124 | try: | |
2125 | tree = revsetlang.parse(spec) |
|
2125 | tree = revsetlang.parse(spec) | |
2126 | except error.ParseError: # will be reported by scmutil.revrange() |
|
2126 | except error.ParseError: # will be reported by scmutil.revrange() | |
2127 | continue |
|
2127 | continue | |
2128 |
|
2128 | |||
2129 | symbols.update(revsetlang.gethashlikesymbols(tree)) |
|
2129 | symbols.update(revsetlang.gethashlikesymbols(tree)) | |
2130 |
|
2130 | |||
2131 | if not symbols: |
|
2131 | if not symbols: | |
2132 | return repo |
|
2132 | return repo | |
2133 |
|
2133 | |||
2134 | revs = _getrevsfromsymbols(repo, symbols) |
|
2134 | revs = _getrevsfromsymbols(repo, symbols) | |
2135 |
|
2135 | |||
2136 | if not revs: |
|
2136 | if not revs: | |
2137 | return repo |
|
2137 | return repo | |
2138 |
|
2138 | |||
2139 | if hiddentype == b'warn': |
|
2139 | if hiddentype == b'warn': | |
2140 | unfi = repo.unfiltered() |
|
2140 | unfi = repo.unfiltered() | |
2141 | revstr = b", ".join([pycompat.bytestr(unfi[l]) for l in revs]) |
|
2141 | revstr = b", ".join([pycompat.bytestr(unfi[l]) for l in revs]) | |
2142 | repo.ui.warn( |
|
2142 | repo.ui.warn( | |
2143 | _( |
|
2143 | _( | |
2144 | b"warning: accessing hidden changesets for write " |
|
2144 | b"warning: accessing hidden changesets for write " | |
2145 | b"operation: %s\n" |
|
2145 | b"operation: %s\n" | |
2146 | ) |
|
2146 | ) | |
2147 | % revstr |
|
2147 | % revstr | |
2148 | ) |
|
2148 | ) | |
2149 |
|
2149 | |||
2150 | # we have to use new filtername to separate branch/tags cache until we can |
|
2150 | # we have to use new filtername to separate branch/tags cache until we can | |
2151 | # disbale these cache when revisions are dynamically pinned. |
|
2151 | # disbale these cache when revisions are dynamically pinned. | |
2152 | return repo.filtered(b'visible-hidden', revs) |
|
2152 | return repo.filtered(b'visible-hidden', revs) | |
2153 |
|
2153 | |||
2154 |
|
2154 | |||
2155 | def _getrevsfromsymbols(repo, symbols): |
|
2155 | def _getrevsfromsymbols(repo, symbols): | |
2156 | """parse the list of symbols and returns a set of revision numbers of hidden |
|
2156 | """parse the list of symbols and returns a set of revision numbers of hidden | |
2157 | changesets present in symbols""" |
|
2157 | changesets present in symbols""" | |
2158 | revs = set() |
|
2158 | revs = set() | |
2159 | unfi = repo.unfiltered() |
|
2159 | unfi = repo.unfiltered() | |
2160 | unficl = unfi.changelog |
|
2160 | unficl = unfi.changelog | |
2161 | cl = repo.changelog |
|
2161 | cl = repo.changelog | |
2162 | tiprev = len(unficl) |
|
2162 | tiprev = len(unficl) | |
2163 | allowrevnums = repo.ui.configbool(b'experimental', b'directaccess.revnums') |
|
2163 | allowrevnums = repo.ui.configbool(b'experimental', b'directaccess.revnums') | |
2164 | for s in symbols: |
|
2164 | for s in symbols: | |
2165 | try: |
|
2165 | try: | |
2166 | n = int(s) |
|
2166 | n = int(s) | |
2167 | if n <= tiprev: |
|
2167 | if n <= tiprev: | |
2168 | if not allowrevnums: |
|
2168 | if not allowrevnums: | |
2169 | continue |
|
2169 | continue | |
2170 | else: |
|
2170 | else: | |
2171 | if n not in cl: |
|
2171 | if n not in cl: | |
2172 | revs.add(n) |
|
2172 | revs.add(n) | |
2173 | continue |
|
2173 | continue | |
2174 | except ValueError: |
|
2174 | except ValueError: | |
2175 | pass |
|
2175 | pass | |
2176 |
|
2176 | |||
2177 | try: |
|
2177 | try: | |
2178 | s = resolvehexnodeidprefix(unfi, s) |
|
2178 | s = resolvehexnodeidprefix(unfi, s) | |
2179 | except (error.LookupError, error.WdirUnsupported): |
|
2179 | except (error.LookupError, error.WdirUnsupported): | |
2180 | s = None |
|
2180 | s = None | |
2181 |
|
2181 | |||
2182 | if s is not None: |
|
2182 | if s is not None: | |
2183 | rev = unficl.rev(s) |
|
2183 | rev = unficl.rev(s) | |
2184 | if rev not in cl: |
|
2184 | if rev not in cl: | |
2185 | revs.add(rev) |
|
2185 | revs.add(rev) | |
2186 |
|
2186 | |||
2187 | return revs |
|
2187 | return revs | |
2188 |
|
2188 | |||
2189 |
|
2189 | |||
2190 | def bookmarkrevs(repo, mark): |
|
2190 | def bookmarkrevs(repo, mark): | |
2191 | """ |
|
2191 | """ | |
2192 | Select revisions reachable by a given bookmark |
|
2192 | Select revisions reachable by a given bookmark | |
2193 | """ |
|
2193 | """ | |
2194 | return repo.revs( |
|
2194 | return repo.revs( | |
2195 | b"ancestors(bookmark(%s)) - " |
|
2195 | b"ancestors(bookmark(%s)) - " | |
2196 | b"ancestors(head() and not bookmark(%s)) - " |
|
2196 | b"ancestors(head() and not bookmark(%s)) - " | |
2197 | b"ancestors(bookmark() and not bookmark(%s))", |
|
2197 | b"ancestors(bookmark() and not bookmark(%s))", | |
2198 | mark, |
|
2198 | mark, | |
2199 | mark, |
|
2199 | mark, | |
2200 | mark, |
|
2200 | mark, | |
2201 | ) |
|
2201 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now