Show More
@@ -1,3797 +1,3798 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 | rcutil, |
|
56 | rcutil, | |
57 | repoview, |
|
57 | repoview, | |
58 | revset, |
|
58 | revset, | |
59 | revsetlang, |
|
59 | revsetlang, | |
60 | scmutil, |
|
60 | scmutil, | |
61 | sparse, |
|
61 | sparse, | |
62 | store as storemod, |
|
62 | store as storemod, | |
63 | subrepoutil, |
|
63 | subrepoutil, | |
64 | tags as tagsmod, |
|
64 | tags as tagsmod, | |
65 | transaction, |
|
65 | transaction, | |
66 | txnutil, |
|
66 | txnutil, | |
67 | util, |
|
67 | util, | |
68 | vfs as vfsmod, |
|
68 | vfs as vfsmod, | |
69 | ) |
|
69 | ) | |
70 |
|
70 | |||
71 | from .interfaces import ( |
|
71 | from .interfaces import ( | |
72 | repository, |
|
72 | repository, | |
73 | util as interfaceutil, |
|
73 | util as interfaceutil, | |
74 | ) |
|
74 | ) | |
75 |
|
75 | |||
76 | from .utils import ( |
|
76 | from .utils import ( | |
77 | hashutil, |
|
77 | hashutil, | |
78 | procutil, |
|
78 | procutil, | |
79 | stringutil, |
|
79 | stringutil, | |
80 | ) |
|
80 | ) | |
81 |
|
81 | |||
82 | from .revlogutils import constants as revlogconst |
|
82 | from .revlogutils import constants as revlogconst | |
83 |
|
83 | |||
84 | release = lockmod.release |
|
84 | release = lockmod.release | |
85 | urlerr = util.urlerr |
|
85 | urlerr = util.urlerr | |
86 | urlreq = util.urlreq |
|
86 | urlreq = util.urlreq | |
87 |
|
87 | |||
88 | # set of (path, vfs-location) tuples. vfs-location is: |
|
88 | # set of (path, vfs-location) tuples. vfs-location is: | |
89 | # - 'plain for vfs relative paths |
|
89 | # - 'plain for vfs relative paths | |
90 | # - '' for svfs relative paths |
|
90 | # - '' for svfs relative paths | |
91 | _cachedfiles = set() |
|
91 | _cachedfiles = set() | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | class _basefilecache(scmutil.filecache): |
|
94 | class _basefilecache(scmutil.filecache): | |
95 | """All filecache usage on repo are done for logic that should be unfiltered |
|
95 | """All filecache usage on repo are done for logic that should be unfiltered | |
96 | """ |
|
96 | """ | |
97 |
|
97 | |||
98 | def __get__(self, repo, type=None): |
|
98 | def __get__(self, repo, type=None): | |
99 | if repo is None: |
|
99 | if repo is None: | |
100 | return self |
|
100 | return self | |
101 | # proxy to unfiltered __dict__ since filtered repo has no entry |
|
101 | # proxy to unfiltered __dict__ since filtered repo has no entry | |
102 | unfi = repo.unfiltered() |
|
102 | unfi = repo.unfiltered() | |
103 | try: |
|
103 | try: | |
104 | return unfi.__dict__[self.sname] |
|
104 | return unfi.__dict__[self.sname] | |
105 | except KeyError: |
|
105 | except KeyError: | |
106 | pass |
|
106 | pass | |
107 | return super(_basefilecache, self).__get__(unfi, type) |
|
107 | return super(_basefilecache, self).__get__(unfi, type) | |
108 |
|
108 | |||
109 | def set(self, repo, value): |
|
109 | def set(self, repo, value): | |
110 | return super(_basefilecache, self).set(repo.unfiltered(), value) |
|
110 | return super(_basefilecache, self).set(repo.unfiltered(), value) | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | class repofilecache(_basefilecache): |
|
113 | class repofilecache(_basefilecache): | |
114 | """filecache for files in .hg but outside of .hg/store""" |
|
114 | """filecache for files in .hg but outside of .hg/store""" | |
115 |
|
115 | |||
116 | def __init__(self, *paths): |
|
116 | def __init__(self, *paths): | |
117 | super(repofilecache, self).__init__(*paths) |
|
117 | super(repofilecache, self).__init__(*paths) | |
118 | for path in paths: |
|
118 | for path in paths: | |
119 | _cachedfiles.add((path, b'plain')) |
|
119 | _cachedfiles.add((path, b'plain')) | |
120 |
|
120 | |||
121 | def join(self, obj, fname): |
|
121 | def join(self, obj, fname): | |
122 | return obj.vfs.join(fname) |
|
122 | return obj.vfs.join(fname) | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | class storecache(_basefilecache): |
|
125 | class storecache(_basefilecache): | |
126 | """filecache for files in the store""" |
|
126 | """filecache for files in the store""" | |
127 |
|
127 | |||
128 | def __init__(self, *paths): |
|
128 | def __init__(self, *paths): | |
129 | super(storecache, self).__init__(*paths) |
|
129 | super(storecache, self).__init__(*paths) | |
130 | for path in paths: |
|
130 | for path in paths: | |
131 | _cachedfiles.add((path, b'')) |
|
131 | _cachedfiles.add((path, b'')) | |
132 |
|
132 | |||
133 | def join(self, obj, fname): |
|
133 | def join(self, obj, fname): | |
134 | return obj.sjoin(fname) |
|
134 | return obj.sjoin(fname) | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | class mixedrepostorecache(_basefilecache): |
|
137 | class mixedrepostorecache(_basefilecache): | |
138 | """filecache for a mix files in .hg/store and outside""" |
|
138 | """filecache for a mix files in .hg/store and outside""" | |
139 |
|
139 | |||
140 | def __init__(self, *pathsandlocations): |
|
140 | def __init__(self, *pathsandlocations): | |
141 | # scmutil.filecache only uses the path for passing back into our |
|
141 | # scmutil.filecache only uses the path for passing back into our | |
142 | # join(), so we can safely pass a list of paths and locations |
|
142 | # join(), so we can safely pass a list of paths and locations | |
143 | super(mixedrepostorecache, self).__init__(*pathsandlocations) |
|
143 | super(mixedrepostorecache, self).__init__(*pathsandlocations) | |
144 | _cachedfiles.update(pathsandlocations) |
|
144 | _cachedfiles.update(pathsandlocations) | |
145 |
|
145 | |||
146 | def join(self, obj, fnameandlocation): |
|
146 | def join(self, obj, fnameandlocation): | |
147 | fname, location = fnameandlocation |
|
147 | fname, location = fnameandlocation | |
148 | if location == b'plain': |
|
148 | if location == b'plain': | |
149 | return obj.vfs.join(fname) |
|
149 | return obj.vfs.join(fname) | |
150 | else: |
|
150 | else: | |
151 | if location != b'': |
|
151 | if location != b'': | |
152 | raise error.ProgrammingError( |
|
152 | raise error.ProgrammingError( | |
153 | b'unexpected location: %s' % location |
|
153 | b'unexpected location: %s' % location | |
154 | ) |
|
154 | ) | |
155 | return obj.sjoin(fname) |
|
155 | return obj.sjoin(fname) | |
156 |
|
156 | |||
157 |
|
157 | |||
158 | def isfilecached(repo, name): |
|
158 | def isfilecached(repo, name): | |
159 | """check if a repo has already cached "name" filecache-ed property |
|
159 | """check if a repo has already cached "name" filecache-ed property | |
160 |
|
160 | |||
161 | This returns (cachedobj-or-None, iscached) tuple. |
|
161 | This returns (cachedobj-or-None, iscached) tuple. | |
162 | """ |
|
162 | """ | |
163 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
163 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
164 | if not cacheentry: |
|
164 | if not cacheentry: | |
165 | return None, False |
|
165 | return None, False | |
166 | return cacheentry.obj, True |
|
166 | return cacheentry.obj, True | |
167 |
|
167 | |||
168 |
|
168 | |||
169 | class unfilteredpropertycache(util.propertycache): |
|
169 | class unfilteredpropertycache(util.propertycache): | |
170 | """propertycache that apply to unfiltered repo only""" |
|
170 | """propertycache that apply to unfiltered repo only""" | |
171 |
|
171 | |||
172 | def __get__(self, repo, type=None): |
|
172 | def __get__(self, repo, type=None): | |
173 | unfi = repo.unfiltered() |
|
173 | unfi = repo.unfiltered() | |
174 | if unfi is repo: |
|
174 | if unfi is repo: | |
175 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
175 | return super(unfilteredpropertycache, self).__get__(unfi) | |
176 | return getattr(unfi, self.name) |
|
176 | return getattr(unfi, self.name) | |
177 |
|
177 | |||
178 |
|
178 | |||
179 | class filteredpropertycache(util.propertycache): |
|
179 | class filteredpropertycache(util.propertycache): | |
180 | """propertycache that must take filtering in account""" |
|
180 | """propertycache that must take filtering in account""" | |
181 |
|
181 | |||
182 | def cachevalue(self, obj, value): |
|
182 | def cachevalue(self, obj, value): | |
183 | object.__setattr__(obj, self.name, value) |
|
183 | object.__setattr__(obj, self.name, value) | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | def hasunfilteredcache(repo, name): |
|
186 | def hasunfilteredcache(repo, name): | |
187 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
187 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
188 | return name in vars(repo.unfiltered()) |
|
188 | return name in vars(repo.unfiltered()) | |
189 |
|
189 | |||
190 |
|
190 | |||
191 | def unfilteredmethod(orig): |
|
191 | def unfilteredmethod(orig): | |
192 | """decorate method that always need to be run on unfiltered version""" |
|
192 | """decorate method that always need to be run on unfiltered version""" | |
193 |
|
193 | |||
194 | def wrapper(repo, *args, **kwargs): |
|
194 | def wrapper(repo, *args, **kwargs): | |
195 | return orig(repo.unfiltered(), *args, **kwargs) |
|
195 | return orig(repo.unfiltered(), *args, **kwargs) | |
196 |
|
196 | |||
197 | return wrapper |
|
197 | return wrapper | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | moderncaps = { |
|
200 | moderncaps = { | |
201 | b'lookup', |
|
201 | b'lookup', | |
202 | b'branchmap', |
|
202 | b'branchmap', | |
203 | b'pushkey', |
|
203 | b'pushkey', | |
204 | b'known', |
|
204 | b'known', | |
205 | b'getbundle', |
|
205 | b'getbundle', | |
206 | b'unbundle', |
|
206 | b'unbundle', | |
207 | } |
|
207 | } | |
208 | legacycaps = moderncaps.union({b'changegroupsubset'}) |
|
208 | legacycaps = moderncaps.union({b'changegroupsubset'}) | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | @interfaceutil.implementer(repository.ipeercommandexecutor) |
|
211 | @interfaceutil.implementer(repository.ipeercommandexecutor) | |
212 | class localcommandexecutor(object): |
|
212 | class localcommandexecutor(object): | |
213 | def __init__(self, peer): |
|
213 | def __init__(self, peer): | |
214 | self._peer = peer |
|
214 | self._peer = peer | |
215 | self._sent = False |
|
215 | self._sent = False | |
216 | self._closed = False |
|
216 | self._closed = False | |
217 |
|
217 | |||
218 | def __enter__(self): |
|
218 | def __enter__(self): | |
219 | return self |
|
219 | return self | |
220 |
|
220 | |||
221 | def __exit__(self, exctype, excvalue, exctb): |
|
221 | def __exit__(self, exctype, excvalue, exctb): | |
222 | self.close() |
|
222 | self.close() | |
223 |
|
223 | |||
224 | def callcommand(self, command, args): |
|
224 | def callcommand(self, command, args): | |
225 | if self._sent: |
|
225 | if self._sent: | |
226 | raise error.ProgrammingError( |
|
226 | raise error.ProgrammingError( | |
227 | b'callcommand() cannot be used after sendcommands()' |
|
227 | b'callcommand() cannot be used after sendcommands()' | |
228 | ) |
|
228 | ) | |
229 |
|
229 | |||
230 | if self._closed: |
|
230 | if self._closed: | |
231 | raise error.ProgrammingError( |
|
231 | raise error.ProgrammingError( | |
232 | b'callcommand() cannot be used after close()' |
|
232 | b'callcommand() cannot be used after close()' | |
233 | ) |
|
233 | ) | |
234 |
|
234 | |||
235 | # We don't need to support anything fancy. Just call the named |
|
235 | # We don't need to support anything fancy. Just call the named | |
236 | # method on the peer and return a resolved future. |
|
236 | # method on the peer and return a resolved future. | |
237 | fn = getattr(self._peer, pycompat.sysstr(command)) |
|
237 | fn = getattr(self._peer, pycompat.sysstr(command)) | |
238 |
|
238 | |||
239 | f = pycompat.futures.Future() |
|
239 | f = pycompat.futures.Future() | |
240 |
|
240 | |||
241 | try: |
|
241 | try: | |
242 | result = fn(**pycompat.strkwargs(args)) |
|
242 | result = fn(**pycompat.strkwargs(args)) | |
243 | except Exception: |
|
243 | except Exception: | |
244 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) |
|
244 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) | |
245 | else: |
|
245 | else: | |
246 | f.set_result(result) |
|
246 | f.set_result(result) | |
247 |
|
247 | |||
248 | return f |
|
248 | return f | |
249 |
|
249 | |||
250 | def sendcommands(self): |
|
250 | def sendcommands(self): | |
251 | self._sent = True |
|
251 | self._sent = True | |
252 |
|
252 | |||
253 | def close(self): |
|
253 | def close(self): | |
254 | self._closed = True |
|
254 | self._closed = True | |
255 |
|
255 | |||
256 |
|
256 | |||
257 | @interfaceutil.implementer(repository.ipeercommands) |
|
257 | @interfaceutil.implementer(repository.ipeercommands) | |
258 | class localpeer(repository.peer): |
|
258 | class localpeer(repository.peer): | |
259 | '''peer for a local repo; reflects only the most recent API''' |
|
259 | '''peer for a local repo; reflects only the most recent API''' | |
260 |
|
260 | |||
261 | def __init__(self, repo, caps=None): |
|
261 | def __init__(self, repo, caps=None): | |
262 | super(localpeer, self).__init__() |
|
262 | super(localpeer, self).__init__() | |
263 |
|
263 | |||
264 | if caps is None: |
|
264 | if caps is None: | |
265 | caps = moderncaps.copy() |
|
265 | caps = moderncaps.copy() | |
266 | self._repo = repo.filtered(b'served') |
|
266 | self._repo = repo.filtered(b'served') | |
267 | self.ui = repo.ui |
|
267 | self.ui = repo.ui | |
268 | self._caps = repo._restrictcapabilities(caps) |
|
268 | self._caps = repo._restrictcapabilities(caps) | |
269 |
|
269 | |||
270 | # Begin of _basepeer interface. |
|
270 | # Begin of _basepeer interface. | |
271 |
|
271 | |||
272 | def url(self): |
|
272 | def url(self): | |
273 | return self._repo.url() |
|
273 | return self._repo.url() | |
274 |
|
274 | |||
275 | def local(self): |
|
275 | def local(self): | |
276 | return self._repo |
|
276 | return self._repo | |
277 |
|
277 | |||
278 | def peer(self): |
|
278 | def peer(self): | |
279 | return self |
|
279 | return self | |
280 |
|
280 | |||
281 | def canpush(self): |
|
281 | def canpush(self): | |
282 | return True |
|
282 | return True | |
283 |
|
283 | |||
284 | def close(self): |
|
284 | def close(self): | |
285 | self._repo.close() |
|
285 | self._repo.close() | |
286 |
|
286 | |||
287 | # End of _basepeer interface. |
|
287 | # End of _basepeer interface. | |
288 |
|
288 | |||
289 | # Begin of _basewirecommands interface. |
|
289 | # Begin of _basewirecommands interface. | |
290 |
|
290 | |||
291 | def branchmap(self): |
|
291 | def branchmap(self): | |
292 | return self._repo.branchmap() |
|
292 | return self._repo.branchmap() | |
293 |
|
293 | |||
294 | def capabilities(self): |
|
294 | def capabilities(self): | |
295 | return self._caps |
|
295 | return self._caps | |
296 |
|
296 | |||
297 | def clonebundles(self): |
|
297 | def clonebundles(self): | |
298 | return self._repo.tryread(b'clonebundles.manifest') |
|
298 | return self._repo.tryread(b'clonebundles.manifest') | |
299 |
|
299 | |||
300 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
300 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
301 | """Used to test argument passing over the wire""" |
|
301 | """Used to test argument passing over the wire""" | |
302 | return b"%s %s %s %s %s" % ( |
|
302 | return b"%s %s %s %s %s" % ( | |
303 | one, |
|
303 | one, | |
304 | two, |
|
304 | two, | |
305 | pycompat.bytestr(three), |
|
305 | pycompat.bytestr(three), | |
306 | pycompat.bytestr(four), |
|
306 | pycompat.bytestr(four), | |
307 | pycompat.bytestr(five), |
|
307 | pycompat.bytestr(five), | |
308 | ) |
|
308 | ) | |
309 |
|
309 | |||
310 | def getbundle( |
|
310 | def getbundle( | |
311 | self, source, heads=None, common=None, bundlecaps=None, **kwargs |
|
311 | self, source, heads=None, common=None, bundlecaps=None, **kwargs | |
312 | ): |
|
312 | ): | |
313 | chunks = exchange.getbundlechunks( |
|
313 | chunks = exchange.getbundlechunks( | |
314 | self._repo, |
|
314 | self._repo, | |
315 | source, |
|
315 | source, | |
316 | heads=heads, |
|
316 | heads=heads, | |
317 | common=common, |
|
317 | common=common, | |
318 | bundlecaps=bundlecaps, |
|
318 | bundlecaps=bundlecaps, | |
319 | **kwargs |
|
319 | **kwargs | |
320 | )[1] |
|
320 | )[1] | |
321 | cb = util.chunkbuffer(chunks) |
|
321 | cb = util.chunkbuffer(chunks) | |
322 |
|
322 | |||
323 | if exchange.bundle2requested(bundlecaps): |
|
323 | if exchange.bundle2requested(bundlecaps): | |
324 | # When requesting a bundle2, getbundle returns a stream to make the |
|
324 | # When requesting a bundle2, getbundle returns a stream to make the | |
325 | # wire level function happier. We need to build a proper object |
|
325 | # wire level function happier. We need to build a proper object | |
326 | # from it in local peer. |
|
326 | # from it in local peer. | |
327 | return bundle2.getunbundler(self.ui, cb) |
|
327 | return bundle2.getunbundler(self.ui, cb) | |
328 | else: |
|
328 | else: | |
329 | return changegroup.getunbundler(b'01', cb, None) |
|
329 | return changegroup.getunbundler(b'01', cb, None) | |
330 |
|
330 | |||
331 | def heads(self): |
|
331 | def heads(self): | |
332 | return self._repo.heads() |
|
332 | return self._repo.heads() | |
333 |
|
333 | |||
334 | def known(self, nodes): |
|
334 | def known(self, nodes): | |
335 | return self._repo.known(nodes) |
|
335 | return self._repo.known(nodes) | |
336 |
|
336 | |||
337 | def listkeys(self, namespace): |
|
337 | def listkeys(self, namespace): | |
338 | return self._repo.listkeys(namespace) |
|
338 | return self._repo.listkeys(namespace) | |
339 |
|
339 | |||
340 | def lookup(self, key): |
|
340 | def lookup(self, key): | |
341 | return self._repo.lookup(key) |
|
341 | return self._repo.lookup(key) | |
342 |
|
342 | |||
343 | def pushkey(self, namespace, key, old, new): |
|
343 | def pushkey(self, namespace, key, old, new): | |
344 | return self._repo.pushkey(namespace, key, old, new) |
|
344 | return self._repo.pushkey(namespace, key, old, new) | |
345 |
|
345 | |||
346 | def stream_out(self): |
|
346 | def stream_out(self): | |
347 | raise error.Abort(_(b'cannot perform stream clone against local peer')) |
|
347 | raise error.Abort(_(b'cannot perform stream clone against local peer')) | |
348 |
|
348 | |||
349 | def unbundle(self, bundle, heads, url): |
|
349 | def unbundle(self, bundle, heads, url): | |
350 | """apply a bundle on a repo |
|
350 | """apply a bundle on a repo | |
351 |
|
351 | |||
352 | This function handles the repo locking itself.""" |
|
352 | This function handles the repo locking itself.""" | |
353 | try: |
|
353 | try: | |
354 | try: |
|
354 | try: | |
355 | bundle = exchange.readbundle(self.ui, bundle, None) |
|
355 | bundle = exchange.readbundle(self.ui, bundle, None) | |
356 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) |
|
356 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) | |
357 | if util.safehasattr(ret, b'getchunks'): |
|
357 | if util.safehasattr(ret, b'getchunks'): | |
358 | # This is a bundle20 object, turn it into an unbundler. |
|
358 | # This is a bundle20 object, turn it into an unbundler. | |
359 | # This little dance should be dropped eventually when the |
|
359 | # This little dance should be dropped eventually when the | |
360 | # API is finally improved. |
|
360 | # API is finally improved. | |
361 | stream = util.chunkbuffer(ret.getchunks()) |
|
361 | stream = util.chunkbuffer(ret.getchunks()) | |
362 | ret = bundle2.getunbundler(self.ui, stream) |
|
362 | ret = bundle2.getunbundler(self.ui, stream) | |
363 | return ret |
|
363 | return ret | |
364 | except Exception as exc: |
|
364 | except Exception as exc: | |
365 | # If the exception contains output salvaged from a bundle2 |
|
365 | # If the exception contains output salvaged from a bundle2 | |
366 | # reply, we need to make sure it is printed before continuing |
|
366 | # reply, we need to make sure it is printed before continuing | |
367 | # to fail. So we build a bundle2 with such output and consume |
|
367 | # to fail. So we build a bundle2 with such output and consume | |
368 | # it directly. |
|
368 | # it directly. | |
369 | # |
|
369 | # | |
370 | # This is not very elegant but allows a "simple" solution for |
|
370 | # This is not very elegant but allows a "simple" solution for | |
371 | # issue4594 |
|
371 | # issue4594 | |
372 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
372 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
373 | if output: |
|
373 | if output: | |
374 | bundler = bundle2.bundle20(self._repo.ui) |
|
374 | bundler = bundle2.bundle20(self._repo.ui) | |
375 | for out in output: |
|
375 | for out in output: | |
376 | bundler.addpart(out) |
|
376 | bundler.addpart(out) | |
377 | stream = util.chunkbuffer(bundler.getchunks()) |
|
377 | stream = util.chunkbuffer(bundler.getchunks()) | |
378 | b = bundle2.getunbundler(self.ui, stream) |
|
378 | b = bundle2.getunbundler(self.ui, stream) | |
379 | bundle2.processbundle(self._repo, b) |
|
379 | bundle2.processbundle(self._repo, b) | |
380 | raise |
|
380 | raise | |
381 | except error.PushRaced as exc: |
|
381 | except error.PushRaced as exc: | |
382 | raise error.ResponseError( |
|
382 | raise error.ResponseError( | |
383 | _(b'push failed:'), stringutil.forcebytestr(exc) |
|
383 | _(b'push failed:'), stringutil.forcebytestr(exc) | |
384 | ) |
|
384 | ) | |
385 |
|
385 | |||
386 | # End of _basewirecommands interface. |
|
386 | # End of _basewirecommands interface. | |
387 |
|
387 | |||
388 | # Begin of peer interface. |
|
388 | # Begin of peer interface. | |
389 |
|
389 | |||
390 | def commandexecutor(self): |
|
390 | def commandexecutor(self): | |
391 | return localcommandexecutor(self) |
|
391 | return localcommandexecutor(self) | |
392 |
|
392 | |||
393 | # End of peer interface. |
|
393 | # End of peer interface. | |
394 |
|
394 | |||
395 |
|
395 | |||
396 | @interfaceutil.implementer(repository.ipeerlegacycommands) |
|
396 | @interfaceutil.implementer(repository.ipeerlegacycommands) | |
397 | class locallegacypeer(localpeer): |
|
397 | class locallegacypeer(localpeer): | |
398 | '''peer extension which implements legacy methods too; used for tests with |
|
398 | '''peer extension which implements legacy methods too; used for tests with | |
399 | restricted capabilities''' |
|
399 | restricted capabilities''' | |
400 |
|
400 | |||
401 | def __init__(self, repo): |
|
401 | def __init__(self, repo): | |
402 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
402 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
403 |
|
403 | |||
404 | # Begin of baselegacywirecommands interface. |
|
404 | # Begin of baselegacywirecommands interface. | |
405 |
|
405 | |||
406 | def between(self, pairs): |
|
406 | def between(self, pairs): | |
407 | return self._repo.between(pairs) |
|
407 | return self._repo.between(pairs) | |
408 |
|
408 | |||
409 | def branches(self, nodes): |
|
409 | def branches(self, nodes): | |
410 | return self._repo.branches(nodes) |
|
410 | return self._repo.branches(nodes) | |
411 |
|
411 | |||
412 | def changegroup(self, nodes, source): |
|
412 | def changegroup(self, nodes, source): | |
413 | outgoing = discovery.outgoing( |
|
413 | outgoing = discovery.outgoing( | |
414 | self._repo, missingroots=nodes, missingheads=self._repo.heads() |
|
414 | self._repo, missingroots=nodes, missingheads=self._repo.heads() | |
415 | ) |
|
415 | ) | |
416 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
416 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
417 |
|
417 | |||
418 | def changegroupsubset(self, bases, heads, source): |
|
418 | def changegroupsubset(self, bases, heads, source): | |
419 | outgoing = discovery.outgoing( |
|
419 | outgoing = discovery.outgoing( | |
420 | self._repo, missingroots=bases, missingheads=heads |
|
420 | self._repo, missingroots=bases, missingheads=heads | |
421 | ) |
|
421 | ) | |
422 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
422 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
423 |
|
423 | |||
424 | # End of baselegacywirecommands interface. |
|
424 | # End of baselegacywirecommands interface. | |
425 |
|
425 | |||
426 |
|
426 | |||
427 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
427 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
428 | # clients. |
|
428 | # clients. | |
429 | REVLOGV2_REQUIREMENT = b'exp-revlogv2.1' |
|
429 | REVLOGV2_REQUIREMENT = b'exp-revlogv2.1' | |
430 |
|
430 | |||
431 | # A repository with the sparserevlog feature will have delta chains that |
|
431 | # A repository with the sparserevlog feature will have delta chains that | |
432 | # can spread over a larger span. Sparse reading cuts these large spans into |
|
432 | # can spread over a larger span. Sparse reading cuts these large spans into | |
433 | # pieces, so that each piece isn't too big. |
|
433 | # pieces, so that each piece isn't too big. | |
434 | # Without the sparserevlog capability, reading from the repository could use |
|
434 | # Without the sparserevlog capability, reading from the repository could use | |
435 | # huge amounts of memory, because the whole span would be read at once, |
|
435 | # huge amounts of memory, because the whole span would be read at once, | |
436 | # including all the intermediate revisions that aren't pertinent for the chain. |
|
436 | # including all the intermediate revisions that aren't pertinent for the chain. | |
437 | # This is why once a repository has enabled sparse-read, it becomes required. |
|
437 | # This is why once a repository has enabled sparse-read, it becomes required. | |
438 | SPARSEREVLOG_REQUIREMENT = b'sparserevlog' |
|
438 | SPARSEREVLOG_REQUIREMENT = b'sparserevlog' | |
439 |
|
439 | |||
440 | # A repository with the sidedataflag requirement will allow to store extra |
|
440 | # A repository with the sidedataflag requirement will allow to store extra | |
441 | # information for revision without altering their original hashes. |
|
441 | # information for revision without altering their original hashes. | |
442 | SIDEDATA_REQUIREMENT = b'exp-sidedata-flag' |
|
442 | SIDEDATA_REQUIREMENT = b'exp-sidedata-flag' | |
443 |
|
443 | |||
444 | # A repository with the the copies-sidedata-changeset requirement will store |
|
444 | # A repository with the the copies-sidedata-changeset requirement will store | |
445 | # copies related information in changeset's sidedata. |
|
445 | # copies related information in changeset's sidedata. | |
446 | COPIESSDC_REQUIREMENT = b'exp-copies-sidedata-changeset' |
|
446 | COPIESSDC_REQUIREMENT = b'exp-copies-sidedata-changeset' | |
447 |
|
447 | |||
448 | # Functions receiving (ui, features) that extensions can register to impact |
|
448 | # Functions receiving (ui, features) that extensions can register to impact | |
449 | # the ability to load repositories with custom requirements. Only |
|
449 | # the ability to load repositories with custom requirements. Only | |
450 | # functions defined in loaded extensions are called. |
|
450 | # functions defined in loaded extensions are called. | |
451 | # |
|
451 | # | |
452 | # The function receives a set of requirement strings that the repository |
|
452 | # The function receives a set of requirement strings that the repository | |
453 | # is capable of opening. Functions will typically add elements to the |
|
453 | # is capable of opening. Functions will typically add elements to the | |
454 | # set to reflect that the extension knows how to handle that requirements. |
|
454 | # set to reflect that the extension knows how to handle that requirements. | |
455 | featuresetupfuncs = set() |
|
455 | featuresetupfuncs = set() | |
456 |
|
456 | |||
457 |
|
457 | |||
458 | def makelocalrepository(baseui, path, intents=None): |
|
458 | def makelocalrepository(baseui, path, intents=None): | |
459 | """Create a local repository object. |
|
459 | """Create a local repository object. | |
460 |
|
460 | |||
461 | Given arguments needed to construct a local repository, this function |
|
461 | Given arguments needed to construct a local repository, this function | |
462 | performs various early repository loading functionality (such as |
|
462 | performs various early repository loading functionality (such as | |
463 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that |
|
463 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that | |
464 | the repository can be opened, derives a type suitable for representing |
|
464 | the repository can be opened, derives a type suitable for representing | |
465 | that repository, and returns an instance of it. |
|
465 | that repository, and returns an instance of it. | |
466 |
|
466 | |||
467 | The returned object conforms to the ``repository.completelocalrepository`` |
|
467 | The returned object conforms to the ``repository.completelocalrepository`` | |
468 | interface. |
|
468 | interface. | |
469 |
|
469 | |||
470 | The repository type is derived by calling a series of factory functions |
|
470 | The repository type is derived by calling a series of factory functions | |
471 | for each aspect/interface of the final repository. These are defined by |
|
471 | for each aspect/interface of the final repository. These are defined by | |
472 | ``REPO_INTERFACES``. |
|
472 | ``REPO_INTERFACES``. | |
473 |
|
473 | |||
474 | Each factory function is called to produce a type implementing a specific |
|
474 | Each factory function is called to produce a type implementing a specific | |
475 | interface. The cumulative list of returned types will be combined into a |
|
475 | interface. The cumulative list of returned types will be combined into a | |
476 | new type and that type will be instantiated to represent the local |
|
476 | new type and that type will be instantiated to represent the local | |
477 | repository. |
|
477 | repository. | |
478 |
|
478 | |||
479 | The factory functions each receive various state that may be consulted |
|
479 | The factory functions each receive various state that may be consulted | |
480 | as part of deriving a type. |
|
480 | as part of deriving a type. | |
481 |
|
481 | |||
482 | Extensions should wrap these factory functions to customize repository type |
|
482 | Extensions should wrap these factory functions to customize repository type | |
483 | creation. Note that an extension's wrapped function may be called even if |
|
483 | creation. Note that an extension's wrapped function may be called even if | |
484 | that extension is not loaded for the repo being constructed. Extensions |
|
484 | that extension is not loaded for the repo being constructed. Extensions | |
485 | should check if their ``__name__`` appears in the |
|
485 | should check if their ``__name__`` appears in the | |
486 | ``extensionmodulenames`` set passed to the factory function and no-op if |
|
486 | ``extensionmodulenames`` set passed to the factory function and no-op if | |
487 | not. |
|
487 | not. | |
488 | """ |
|
488 | """ | |
489 | ui = baseui.copy() |
|
489 | ui = baseui.copy() | |
490 | # Prevent copying repo configuration. |
|
490 | # Prevent copying repo configuration. | |
491 | ui.copy = baseui.copy |
|
491 | ui.copy = baseui.copy | |
492 |
|
492 | |||
493 | # Working directory VFS rooted at repository root. |
|
493 | # Working directory VFS rooted at repository root. | |
494 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
494 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
495 |
|
495 | |||
496 | # Main VFS for .hg/ directory. |
|
496 | # Main VFS for .hg/ directory. | |
497 | hgpath = wdirvfs.join(b'.hg') |
|
497 | hgpath = wdirvfs.join(b'.hg') | |
498 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) |
|
498 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) | |
499 |
|
499 | |||
500 | # The .hg/ path should exist and should be a directory. All other |
|
500 | # The .hg/ path should exist and should be a directory. All other | |
501 | # cases are errors. |
|
501 | # cases are errors. | |
502 | if not hgvfs.isdir(): |
|
502 | if not hgvfs.isdir(): | |
503 | try: |
|
503 | try: | |
504 | hgvfs.stat() |
|
504 | hgvfs.stat() | |
505 | except OSError as e: |
|
505 | except OSError as e: | |
506 | if e.errno != errno.ENOENT: |
|
506 | if e.errno != errno.ENOENT: | |
507 | raise |
|
507 | raise | |
508 |
|
508 | |||
509 | raise error.RepoError(_(b'repository %s not found') % path) |
|
509 | raise error.RepoError(_(b'repository %s not found') % path) | |
510 |
|
510 | |||
511 | # .hg/requires file contains a newline-delimited list of |
|
511 | # .hg/requires file contains a newline-delimited list of | |
512 | # features/capabilities the opener (us) must have in order to use |
|
512 | # features/capabilities the opener (us) must have in order to use | |
513 | # the repository. This file was introduced in Mercurial 0.9.2, |
|
513 | # the repository. This file was introduced in Mercurial 0.9.2, | |
514 | # which means very old repositories may not have one. We assume |
|
514 | # which means very old repositories may not have one. We assume | |
515 | # a missing file translates to no requirements. |
|
515 | # a missing file translates to no requirements. | |
516 | try: |
|
516 | try: | |
517 | requirements = set(hgvfs.read(b'requires').splitlines()) |
|
517 | requirements = set(hgvfs.read(b'requires').splitlines()) | |
518 | except IOError as e: |
|
518 | except IOError as e: | |
519 | if e.errno != errno.ENOENT: |
|
519 | if e.errno != errno.ENOENT: | |
520 | raise |
|
520 | raise | |
521 | requirements = set() |
|
521 | requirements = set() | |
522 |
|
522 | |||
523 | # The .hg/hgrc file may load extensions or contain config options |
|
523 | # The .hg/hgrc file may load extensions or contain config options | |
524 | # that influence repository construction. Attempt to load it and |
|
524 | # that influence repository construction. Attempt to load it and | |
525 | # process any new extensions that it may have pulled in. |
|
525 | # process any new extensions that it may have pulled in. | |
526 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
526 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
527 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
|
527 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) | |
528 | extensions.loadall(ui) |
|
528 | extensions.loadall(ui) | |
529 | extensions.populateui(ui) |
|
529 | extensions.populateui(ui) | |
530 |
|
530 | |||
531 | # Set of module names of extensions loaded for this repository. |
|
531 | # Set of module names of extensions loaded for this repository. | |
532 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} |
|
532 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} | |
533 |
|
533 | |||
534 | supportedrequirements = gathersupportedrequirements(ui) |
|
534 | supportedrequirements = gathersupportedrequirements(ui) | |
535 |
|
535 | |||
536 | # We first validate the requirements are known. |
|
536 | # We first validate the requirements are known. | |
537 | ensurerequirementsrecognized(requirements, supportedrequirements) |
|
537 | ensurerequirementsrecognized(requirements, supportedrequirements) | |
538 |
|
538 | |||
539 | # Then we validate that the known set is reasonable to use together. |
|
539 | # Then we validate that the known set is reasonable to use together. | |
540 | ensurerequirementscompatible(ui, requirements) |
|
540 | ensurerequirementscompatible(ui, requirements) | |
541 |
|
541 | |||
542 | # TODO there are unhandled edge cases related to opening repositories with |
|
542 | # TODO there are unhandled edge cases related to opening repositories with | |
543 | # shared storage. If storage is shared, we should also test for requirements |
|
543 | # shared storage. If storage is shared, we should also test for requirements | |
544 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in |
|
544 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in | |
545 | # that repo, as that repo may load extensions needed to open it. This is a |
|
545 | # that repo, as that repo may load extensions needed to open it. This is a | |
546 | # bit complicated because we don't want the other hgrc to overwrite settings |
|
546 | # bit complicated because we don't want the other hgrc to overwrite settings | |
547 | # in this hgrc. |
|
547 | # in this hgrc. | |
548 | # |
|
548 | # | |
549 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires |
|
549 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires | |
550 | # file when sharing repos. But if a requirement is added after the share is |
|
550 | # file when sharing repos. But if a requirement is added after the share is | |
551 | # performed, thereby introducing a new requirement for the opener, we may |
|
551 | # performed, thereby introducing a new requirement for the opener, we may | |
552 | # will not see that and could encounter a run-time error interacting with |
|
552 | # will not see that and could encounter a run-time error interacting with | |
553 | # that shared store since it has an unknown-to-us requirement. |
|
553 | # that shared store since it has an unknown-to-us requirement. | |
554 |
|
554 | |||
555 | # At this point, we know we should be capable of opening the repository. |
|
555 | # At this point, we know we should be capable of opening the repository. | |
556 | # Now get on with doing that. |
|
556 | # Now get on with doing that. | |
557 |
|
557 | |||
558 | features = set() |
|
558 | features = set() | |
559 |
|
559 | |||
560 | # The "store" part of the repository holds versioned data. How it is |
|
560 | # The "store" part of the repository holds versioned data. How it is | |
561 | # accessed is determined by various requirements. The ``shared`` or |
|
561 | # accessed is determined by various requirements. The ``shared`` or | |
562 | # ``relshared`` requirements indicate the store lives in the path contained |
|
562 | # ``relshared`` requirements indicate the store lives in the path contained | |
563 | # in the ``.hg/sharedpath`` file. This is an absolute path for |
|
563 | # in the ``.hg/sharedpath`` file. This is an absolute path for | |
564 | # ``shared`` and relative to ``.hg/`` for ``relshared``. |
|
564 | # ``shared`` and relative to ``.hg/`` for ``relshared``. | |
565 | if b'shared' in requirements or b'relshared' in requirements: |
|
565 | if b'shared' in requirements or b'relshared' in requirements: | |
566 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') |
|
566 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') | |
567 | if b'relshared' in requirements: |
|
567 | if b'relshared' in requirements: | |
568 | sharedpath = hgvfs.join(sharedpath) |
|
568 | sharedpath = hgvfs.join(sharedpath) | |
569 |
|
569 | |||
570 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) |
|
570 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) | |
571 |
|
571 | |||
572 | if not sharedvfs.exists(): |
|
572 | if not sharedvfs.exists(): | |
573 | raise error.RepoError( |
|
573 | raise error.RepoError( | |
574 | _(b'.hg/sharedpath points to nonexistent directory %s') |
|
574 | _(b'.hg/sharedpath points to nonexistent directory %s') | |
575 | % sharedvfs.base |
|
575 | % sharedvfs.base | |
576 | ) |
|
576 | ) | |
577 |
|
577 | |||
578 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) |
|
578 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) | |
579 |
|
579 | |||
580 | storebasepath = sharedvfs.base |
|
580 | storebasepath = sharedvfs.base | |
581 | cachepath = sharedvfs.join(b'cache') |
|
581 | cachepath = sharedvfs.join(b'cache') | |
582 | else: |
|
582 | else: | |
583 | storebasepath = hgvfs.base |
|
583 | storebasepath = hgvfs.base | |
584 | cachepath = hgvfs.join(b'cache') |
|
584 | cachepath = hgvfs.join(b'cache') | |
585 | wcachepath = hgvfs.join(b'wcache') |
|
585 | wcachepath = hgvfs.join(b'wcache') | |
586 |
|
586 | |||
587 | # The store has changed over time and the exact layout is dictated by |
|
587 | # The store has changed over time and the exact layout is dictated by | |
588 | # requirements. The store interface abstracts differences across all |
|
588 | # requirements. The store interface abstracts differences across all | |
589 | # of them. |
|
589 | # of them. | |
590 | store = makestore( |
|
590 | store = makestore( | |
591 | requirements, |
|
591 | requirements, | |
592 | storebasepath, |
|
592 | storebasepath, | |
593 | lambda base: vfsmod.vfs(base, cacheaudited=True), |
|
593 | lambda base: vfsmod.vfs(base, cacheaudited=True), | |
594 | ) |
|
594 | ) | |
595 | hgvfs.createmode = store.createmode |
|
595 | hgvfs.createmode = store.createmode | |
596 |
|
596 | |||
597 | storevfs = store.vfs |
|
597 | storevfs = store.vfs | |
598 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) |
|
598 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) | |
599 |
|
599 | |||
600 | # The cache vfs is used to manage cache files. |
|
600 | # The cache vfs is used to manage cache files. | |
601 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
601 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
602 | cachevfs.createmode = store.createmode |
|
602 | cachevfs.createmode = store.createmode | |
603 | # The cache vfs is used to manage cache files related to the working copy |
|
603 | # The cache vfs is used to manage cache files related to the working copy | |
604 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) |
|
604 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) | |
605 | wcachevfs.createmode = store.createmode |
|
605 | wcachevfs.createmode = store.createmode | |
606 |
|
606 | |||
607 | # Now resolve the type for the repository object. We do this by repeatedly |
|
607 | # Now resolve the type for the repository object. We do this by repeatedly | |
608 | # calling a factory function to produces types for specific aspects of the |
|
608 | # calling a factory function to produces types for specific aspects of the | |
609 | # repo's operation. The aggregate returned types are used as base classes |
|
609 | # repo's operation. The aggregate returned types are used as base classes | |
610 | # for a dynamically-derived type, which will represent our new repository. |
|
610 | # for a dynamically-derived type, which will represent our new repository. | |
611 |
|
611 | |||
612 | bases = [] |
|
612 | bases = [] | |
613 | extrastate = {} |
|
613 | extrastate = {} | |
614 |
|
614 | |||
615 | for iface, fn in REPO_INTERFACES: |
|
615 | for iface, fn in REPO_INTERFACES: | |
616 | # We pass all potentially useful state to give extensions tons of |
|
616 | # We pass all potentially useful state to give extensions tons of | |
617 | # flexibility. |
|
617 | # flexibility. | |
618 | typ = fn()( |
|
618 | typ = fn()( | |
619 | ui=ui, |
|
619 | ui=ui, | |
620 | intents=intents, |
|
620 | intents=intents, | |
621 | requirements=requirements, |
|
621 | requirements=requirements, | |
622 | features=features, |
|
622 | features=features, | |
623 | wdirvfs=wdirvfs, |
|
623 | wdirvfs=wdirvfs, | |
624 | hgvfs=hgvfs, |
|
624 | hgvfs=hgvfs, | |
625 | store=store, |
|
625 | store=store, | |
626 | storevfs=storevfs, |
|
626 | storevfs=storevfs, | |
627 | storeoptions=storevfs.options, |
|
627 | storeoptions=storevfs.options, | |
628 | cachevfs=cachevfs, |
|
628 | cachevfs=cachevfs, | |
629 | wcachevfs=wcachevfs, |
|
629 | wcachevfs=wcachevfs, | |
630 | extensionmodulenames=extensionmodulenames, |
|
630 | extensionmodulenames=extensionmodulenames, | |
631 | extrastate=extrastate, |
|
631 | extrastate=extrastate, | |
632 | baseclasses=bases, |
|
632 | baseclasses=bases, | |
633 | ) |
|
633 | ) | |
634 |
|
634 | |||
635 | if not isinstance(typ, type): |
|
635 | if not isinstance(typ, type): | |
636 | raise error.ProgrammingError( |
|
636 | raise error.ProgrammingError( | |
637 | b'unable to construct type for %s' % iface |
|
637 | b'unable to construct type for %s' % iface | |
638 | ) |
|
638 | ) | |
639 |
|
639 | |||
640 | bases.append(typ) |
|
640 | bases.append(typ) | |
641 |
|
641 | |||
642 | # type() allows you to use characters in type names that wouldn't be |
|
642 | # type() allows you to use characters in type names that wouldn't be | |
643 | # recognized as Python symbols in source code. We abuse that to add |
|
643 | # recognized as Python symbols in source code. We abuse that to add | |
644 | # rich information about our constructed repo. |
|
644 | # rich information about our constructed repo. | |
645 | name = pycompat.sysstr( |
|
645 | name = pycompat.sysstr( | |
646 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) |
|
646 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) | |
647 | ) |
|
647 | ) | |
648 |
|
648 | |||
649 | cls = type(name, tuple(bases), {}) |
|
649 | cls = type(name, tuple(bases), {}) | |
650 |
|
650 | |||
651 | return cls( |
|
651 | return cls( | |
652 | baseui=baseui, |
|
652 | baseui=baseui, | |
653 | ui=ui, |
|
653 | ui=ui, | |
654 | origroot=path, |
|
654 | origroot=path, | |
655 | wdirvfs=wdirvfs, |
|
655 | wdirvfs=wdirvfs, | |
656 | hgvfs=hgvfs, |
|
656 | hgvfs=hgvfs, | |
657 | requirements=requirements, |
|
657 | requirements=requirements, | |
658 | supportedrequirements=supportedrequirements, |
|
658 | supportedrequirements=supportedrequirements, | |
659 | sharedpath=storebasepath, |
|
659 | sharedpath=storebasepath, | |
660 | store=store, |
|
660 | store=store, | |
661 | cachevfs=cachevfs, |
|
661 | cachevfs=cachevfs, | |
662 | wcachevfs=wcachevfs, |
|
662 | wcachevfs=wcachevfs, | |
663 | features=features, |
|
663 | features=features, | |
664 | intents=intents, |
|
664 | intents=intents, | |
665 | ) |
|
665 | ) | |
666 |
|
666 | |||
667 |
|
667 | |||
668 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
668 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
669 | """Load hgrc files/content into a ui instance. |
|
669 | """Load hgrc files/content into a ui instance. | |
670 |
|
670 | |||
671 | This is called during repository opening to load any additional |
|
671 | This is called during repository opening to load any additional | |
672 | config files or settings relevant to the current repository. |
|
672 | config files or settings relevant to the current repository. | |
673 |
|
673 | |||
674 | Returns a bool indicating whether any additional configs were loaded. |
|
674 | Returns a bool indicating whether any additional configs were loaded. | |
675 |
|
675 | |||
676 | Extensions should monkeypatch this function to modify how per-repo |
|
676 | Extensions should monkeypatch this function to modify how per-repo | |
677 | configs are loaded. For example, an extension may wish to pull in |
|
677 | configs are loaded. For example, an extension may wish to pull in | |
678 | configs from alternate files or sources. |
|
678 | configs from alternate files or sources. | |
679 | """ |
|
679 | """ | |
680 | if not rcutil.use_repo_hgrc(): |
|
680 | if not rcutil.use_repo_hgrc(): | |
681 | return False |
|
681 | return False | |
682 | try: |
|
682 | try: | |
683 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
|
683 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
684 | return True |
|
684 | return True | |
685 | except IOError: |
|
685 | except IOError: | |
686 | return False |
|
686 | return False | |
687 |
|
687 | |||
688 |
|
688 | |||
689 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): |
|
689 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | |
690 | """Perform additional actions after .hg/hgrc is loaded. |
|
690 | """Perform additional actions after .hg/hgrc is loaded. | |
691 |
|
691 | |||
692 | This function is called during repository loading immediately after |
|
692 | This function is called during repository loading immediately after | |
693 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. |
|
693 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. | |
694 |
|
694 | |||
695 | The function can be used to validate configs, automatically add |
|
695 | The function can be used to validate configs, automatically add | |
696 | options (including extensions) based on requirements, etc. |
|
696 | options (including extensions) based on requirements, etc. | |
697 | """ |
|
697 | """ | |
698 |
|
698 | |||
699 | # Map of requirements to list of extensions to load automatically when |
|
699 | # Map of requirements to list of extensions to load automatically when | |
700 | # requirement is present. |
|
700 | # requirement is present. | |
701 | autoextensions = { |
|
701 | autoextensions = { | |
702 | b'largefiles': [b'largefiles'], |
|
702 | b'largefiles': [b'largefiles'], | |
703 | b'lfs': [b'lfs'], |
|
703 | b'lfs': [b'lfs'], | |
704 | } |
|
704 | } | |
705 |
|
705 | |||
706 | for requirement, names in sorted(autoextensions.items()): |
|
706 | for requirement, names in sorted(autoextensions.items()): | |
707 | if requirement not in requirements: |
|
707 | if requirement not in requirements: | |
708 | continue |
|
708 | continue | |
709 |
|
709 | |||
710 | for name in names: |
|
710 | for name in names: | |
711 | if not ui.hasconfig(b'extensions', name): |
|
711 | if not ui.hasconfig(b'extensions', name): | |
712 | ui.setconfig(b'extensions', name, b'', source=b'autoload') |
|
712 | ui.setconfig(b'extensions', name, b'', source=b'autoload') | |
713 |
|
713 | |||
714 |
|
714 | |||
715 | def gathersupportedrequirements(ui): |
|
715 | def gathersupportedrequirements(ui): | |
716 | """Determine the complete set of recognized requirements.""" |
|
716 | """Determine the complete set of recognized requirements.""" | |
717 | # Start with all requirements supported by this file. |
|
717 | # Start with all requirements supported by this file. | |
718 | supported = set(localrepository._basesupported) |
|
718 | supported = set(localrepository._basesupported) | |
719 |
|
719 | |||
720 | # Execute ``featuresetupfuncs`` entries if they belong to an extension |
|
720 | # Execute ``featuresetupfuncs`` entries if they belong to an extension | |
721 | # relevant to this ui instance. |
|
721 | # relevant to this ui instance. | |
722 | modules = {m.__name__ for n, m in extensions.extensions(ui)} |
|
722 | modules = {m.__name__ for n, m in extensions.extensions(ui)} | |
723 |
|
723 | |||
724 | for fn in featuresetupfuncs: |
|
724 | for fn in featuresetupfuncs: | |
725 | if fn.__module__ in modules: |
|
725 | if fn.__module__ in modules: | |
726 | fn(ui, supported) |
|
726 | fn(ui, supported) | |
727 |
|
727 | |||
728 | # Add derived requirements from registered compression engines. |
|
728 | # Add derived requirements from registered compression engines. | |
729 | for name in util.compengines: |
|
729 | for name in util.compengines: | |
730 | engine = util.compengines[name] |
|
730 | engine = util.compengines[name] | |
731 | if engine.available() and engine.revlogheader(): |
|
731 | if engine.available() and engine.revlogheader(): | |
732 | supported.add(b'exp-compression-%s' % name) |
|
732 | supported.add(b'exp-compression-%s' % name) | |
733 | if engine.name() == b'zstd': |
|
733 | if engine.name() == b'zstd': | |
734 | supported.add(b'revlog-compression-zstd') |
|
734 | supported.add(b'revlog-compression-zstd') | |
735 |
|
735 | |||
736 | return supported |
|
736 | return supported | |
737 |
|
737 | |||
738 |
|
738 | |||
739 | def ensurerequirementsrecognized(requirements, supported): |
|
739 | def ensurerequirementsrecognized(requirements, supported): | |
740 | """Validate that a set of local requirements is recognized. |
|
740 | """Validate that a set of local requirements is recognized. | |
741 |
|
741 | |||
742 | Receives a set of requirements. Raises an ``error.RepoError`` if there |
|
742 | Receives a set of requirements. Raises an ``error.RepoError`` if there | |
743 | exists any requirement in that set that currently loaded code doesn't |
|
743 | exists any requirement in that set that currently loaded code doesn't | |
744 | recognize. |
|
744 | recognize. | |
745 |
|
745 | |||
746 | Returns a set of supported requirements. |
|
746 | Returns a set of supported requirements. | |
747 | """ |
|
747 | """ | |
748 | missing = set() |
|
748 | missing = set() | |
749 |
|
749 | |||
750 | for requirement in requirements: |
|
750 | for requirement in requirements: | |
751 | if requirement in supported: |
|
751 | if requirement in supported: | |
752 | continue |
|
752 | continue | |
753 |
|
753 | |||
754 | if not requirement or not requirement[0:1].isalnum(): |
|
754 | if not requirement or not requirement[0:1].isalnum(): | |
755 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) |
|
755 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) | |
756 |
|
756 | |||
757 | missing.add(requirement) |
|
757 | missing.add(requirement) | |
758 |
|
758 | |||
759 | if missing: |
|
759 | if missing: | |
760 | raise error.RequirementError( |
|
760 | raise error.RequirementError( | |
761 | _(b'repository requires features unknown to this Mercurial: %s') |
|
761 | _(b'repository requires features unknown to this Mercurial: %s') | |
762 | % b' '.join(sorted(missing)), |
|
762 | % b' '.join(sorted(missing)), | |
763 | hint=_( |
|
763 | hint=_( | |
764 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' |
|
764 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' | |
765 | b'for more information' |
|
765 | b'for more information' | |
766 | ), |
|
766 | ), | |
767 | ) |
|
767 | ) | |
768 |
|
768 | |||
769 |
|
769 | |||
770 | def ensurerequirementscompatible(ui, requirements): |
|
770 | def ensurerequirementscompatible(ui, requirements): | |
771 | """Validates that a set of recognized requirements is mutually compatible. |
|
771 | """Validates that a set of recognized requirements is mutually compatible. | |
772 |
|
772 | |||
773 | Some requirements may not be compatible with others or require |
|
773 | Some requirements may not be compatible with others or require | |
774 | config options that aren't enabled. This function is called during |
|
774 | config options that aren't enabled. This function is called during | |
775 | repository opening to ensure that the set of requirements needed |
|
775 | repository opening to ensure that the set of requirements needed | |
776 | to open a repository is sane and compatible with config options. |
|
776 | to open a repository is sane and compatible with config options. | |
777 |
|
777 | |||
778 | Extensions can monkeypatch this function to perform additional |
|
778 | Extensions can monkeypatch this function to perform additional | |
779 | checking. |
|
779 | checking. | |
780 |
|
780 | |||
781 | ``error.RepoError`` should be raised on failure. |
|
781 | ``error.RepoError`` should be raised on failure. | |
782 | """ |
|
782 | """ | |
783 | if b'exp-sparse' in requirements and not sparse.enabled: |
|
783 | if b'exp-sparse' in requirements and not sparse.enabled: | |
784 | raise error.RepoError( |
|
784 | raise error.RepoError( | |
785 | _( |
|
785 | _( | |
786 | b'repository is using sparse feature but ' |
|
786 | b'repository is using sparse feature but ' | |
787 | b'sparse is not enabled; enable the ' |
|
787 | b'sparse is not enabled; enable the ' | |
788 | b'"sparse" extensions to access' |
|
788 | b'"sparse" extensions to access' | |
789 | ) |
|
789 | ) | |
790 | ) |
|
790 | ) | |
791 |
|
791 | |||
792 |
|
792 | |||
793 | def makestore(requirements, path, vfstype): |
|
793 | def makestore(requirements, path, vfstype): | |
794 | """Construct a storage object for a repository.""" |
|
794 | """Construct a storage object for a repository.""" | |
795 | if b'store' in requirements: |
|
795 | if b'store' in requirements: | |
796 | if b'fncache' in requirements: |
|
796 | if b'fncache' in requirements: | |
797 | return storemod.fncachestore( |
|
797 | return storemod.fncachestore( | |
798 | path, vfstype, b'dotencode' in requirements |
|
798 | path, vfstype, b'dotencode' in requirements | |
799 | ) |
|
799 | ) | |
800 |
|
800 | |||
801 | return storemod.encodedstore(path, vfstype) |
|
801 | return storemod.encodedstore(path, vfstype) | |
802 |
|
802 | |||
803 | return storemod.basicstore(path, vfstype) |
|
803 | return storemod.basicstore(path, vfstype) | |
804 |
|
804 | |||
805 |
|
805 | |||
806 | def resolvestorevfsoptions(ui, requirements, features): |
|
806 | def resolvestorevfsoptions(ui, requirements, features): | |
807 | """Resolve the options to pass to the store vfs opener. |
|
807 | """Resolve the options to pass to the store vfs opener. | |
808 |
|
808 | |||
809 | The returned dict is used to influence behavior of the storage layer. |
|
809 | The returned dict is used to influence behavior of the storage layer. | |
810 | """ |
|
810 | """ | |
811 | options = {} |
|
811 | options = {} | |
812 |
|
812 | |||
813 | if b'treemanifest' in requirements: |
|
813 | if b'treemanifest' in requirements: | |
814 | options[b'treemanifest'] = True |
|
814 | options[b'treemanifest'] = True | |
815 |
|
815 | |||
816 | # experimental config: format.manifestcachesize |
|
816 | # experimental config: format.manifestcachesize | |
817 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') |
|
817 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') | |
818 | if manifestcachesize is not None: |
|
818 | if manifestcachesize is not None: | |
819 | options[b'manifestcachesize'] = manifestcachesize |
|
819 | options[b'manifestcachesize'] = manifestcachesize | |
820 |
|
820 | |||
821 | # In the absence of another requirement superseding a revlog-related |
|
821 | # In the absence of another requirement superseding a revlog-related | |
822 | # requirement, we have to assume the repo is using revlog version 0. |
|
822 | # requirement, we have to assume the repo is using revlog version 0. | |
823 | # This revlog format is super old and we don't bother trying to parse |
|
823 | # This revlog format is super old and we don't bother trying to parse | |
824 | # opener options for it because those options wouldn't do anything |
|
824 | # opener options for it because those options wouldn't do anything | |
825 | # meaningful on such old repos. |
|
825 | # meaningful on such old repos. | |
826 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: |
|
826 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: | |
827 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) |
|
827 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) | |
828 | else: # explicitly mark repo as using revlogv0 |
|
828 | else: # explicitly mark repo as using revlogv0 | |
829 | options[b'revlogv0'] = True |
|
829 | options[b'revlogv0'] = True | |
830 |
|
830 | |||
831 | if COPIESSDC_REQUIREMENT in requirements: |
|
831 | if COPIESSDC_REQUIREMENT in requirements: | |
832 | options[b'copies-storage'] = b'changeset-sidedata' |
|
832 | options[b'copies-storage'] = b'changeset-sidedata' | |
833 | else: |
|
833 | else: | |
834 | writecopiesto = ui.config(b'experimental', b'copies.write-to') |
|
834 | writecopiesto = ui.config(b'experimental', b'copies.write-to') | |
835 | copiesextramode = (b'changeset-only', b'compatibility') |
|
835 | copiesextramode = (b'changeset-only', b'compatibility') | |
836 | if writecopiesto in copiesextramode: |
|
836 | if writecopiesto in copiesextramode: | |
837 | options[b'copies-storage'] = b'extra' |
|
837 | options[b'copies-storage'] = b'extra' | |
838 |
|
838 | |||
839 | return options |
|
839 | return options | |
840 |
|
840 | |||
841 |
|
841 | |||
842 | def resolverevlogstorevfsoptions(ui, requirements, features): |
|
842 | def resolverevlogstorevfsoptions(ui, requirements, features): | |
843 | """Resolve opener options specific to revlogs.""" |
|
843 | """Resolve opener options specific to revlogs.""" | |
844 |
|
844 | |||
845 | options = {} |
|
845 | options = {} | |
846 | options[b'flagprocessors'] = {} |
|
846 | options[b'flagprocessors'] = {} | |
847 |
|
847 | |||
848 | if b'revlogv1' in requirements: |
|
848 | if b'revlogv1' in requirements: | |
849 | options[b'revlogv1'] = True |
|
849 | options[b'revlogv1'] = True | |
850 | if REVLOGV2_REQUIREMENT in requirements: |
|
850 | if REVLOGV2_REQUIREMENT in requirements: | |
851 | options[b'revlogv2'] = True |
|
851 | options[b'revlogv2'] = True | |
852 |
|
852 | |||
853 | if b'generaldelta' in requirements: |
|
853 | if b'generaldelta' in requirements: | |
854 | options[b'generaldelta'] = True |
|
854 | options[b'generaldelta'] = True | |
855 |
|
855 | |||
856 | # experimental config: format.chunkcachesize |
|
856 | # experimental config: format.chunkcachesize | |
857 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') |
|
857 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') | |
858 | if chunkcachesize is not None: |
|
858 | if chunkcachesize is not None: | |
859 | options[b'chunkcachesize'] = chunkcachesize |
|
859 | options[b'chunkcachesize'] = chunkcachesize | |
860 |
|
860 | |||
861 | deltabothparents = ui.configbool( |
|
861 | deltabothparents = ui.configbool( | |
862 | b'storage', b'revlog.optimize-delta-parent-choice' |
|
862 | b'storage', b'revlog.optimize-delta-parent-choice' | |
863 | ) |
|
863 | ) | |
864 | options[b'deltabothparents'] = deltabothparents |
|
864 | options[b'deltabothparents'] = deltabothparents | |
865 |
|
865 | |||
866 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') |
|
866 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') | |
867 | lazydeltabase = False |
|
867 | lazydeltabase = False | |
868 | if lazydelta: |
|
868 | if lazydelta: | |
869 | lazydeltabase = ui.configbool( |
|
869 | lazydeltabase = ui.configbool( | |
870 | b'storage', b'revlog.reuse-external-delta-parent' |
|
870 | b'storage', b'revlog.reuse-external-delta-parent' | |
871 | ) |
|
871 | ) | |
872 | if lazydeltabase is None: |
|
872 | if lazydeltabase is None: | |
873 | lazydeltabase = not scmutil.gddeltaconfig(ui) |
|
873 | lazydeltabase = not scmutil.gddeltaconfig(ui) | |
874 | options[b'lazydelta'] = lazydelta |
|
874 | options[b'lazydelta'] = lazydelta | |
875 | options[b'lazydeltabase'] = lazydeltabase |
|
875 | options[b'lazydeltabase'] = lazydeltabase | |
876 |
|
876 | |||
877 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') |
|
877 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') | |
878 | if 0 <= chainspan: |
|
878 | if 0 <= chainspan: | |
879 | options[b'maxdeltachainspan'] = chainspan |
|
879 | options[b'maxdeltachainspan'] = chainspan | |
880 |
|
880 | |||
881 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') |
|
881 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') | |
882 | if mmapindexthreshold is not None: |
|
882 | if mmapindexthreshold is not None: | |
883 | options[b'mmapindexthreshold'] = mmapindexthreshold |
|
883 | options[b'mmapindexthreshold'] = mmapindexthreshold | |
884 |
|
884 | |||
885 | withsparseread = ui.configbool(b'experimental', b'sparse-read') |
|
885 | withsparseread = ui.configbool(b'experimental', b'sparse-read') | |
886 | srdensitythres = float( |
|
886 | srdensitythres = float( | |
887 | ui.config(b'experimental', b'sparse-read.density-threshold') |
|
887 | ui.config(b'experimental', b'sparse-read.density-threshold') | |
888 | ) |
|
888 | ) | |
889 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') |
|
889 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') | |
890 | options[b'with-sparse-read'] = withsparseread |
|
890 | options[b'with-sparse-read'] = withsparseread | |
891 | options[b'sparse-read-density-threshold'] = srdensitythres |
|
891 | options[b'sparse-read-density-threshold'] = srdensitythres | |
892 | options[b'sparse-read-min-gap-size'] = srmingapsize |
|
892 | options[b'sparse-read-min-gap-size'] = srmingapsize | |
893 |
|
893 | |||
894 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements |
|
894 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements | |
895 | options[b'sparse-revlog'] = sparserevlog |
|
895 | options[b'sparse-revlog'] = sparserevlog | |
896 | if sparserevlog: |
|
896 | if sparserevlog: | |
897 | options[b'generaldelta'] = True |
|
897 | options[b'generaldelta'] = True | |
898 |
|
898 | |||
899 | sidedata = SIDEDATA_REQUIREMENT in requirements |
|
899 | sidedata = SIDEDATA_REQUIREMENT in requirements | |
900 | options[b'side-data'] = sidedata |
|
900 | options[b'side-data'] = sidedata | |
901 |
|
901 | |||
902 | maxchainlen = None |
|
902 | maxchainlen = None | |
903 | if sparserevlog: |
|
903 | if sparserevlog: | |
904 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH |
|
904 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH | |
905 | # experimental config: format.maxchainlen |
|
905 | # experimental config: format.maxchainlen | |
906 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) |
|
906 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) | |
907 | if maxchainlen is not None: |
|
907 | if maxchainlen is not None: | |
908 | options[b'maxchainlen'] = maxchainlen |
|
908 | options[b'maxchainlen'] = maxchainlen | |
909 |
|
909 | |||
910 | for r in requirements: |
|
910 | for r in requirements: | |
911 | # we allow multiple compression engine requirement to co-exist because |
|
911 | # we allow multiple compression engine requirement to co-exist because | |
912 | # strickly speaking, revlog seems to support mixed compression style. |
|
912 | # strickly speaking, revlog seems to support mixed compression style. | |
913 | # |
|
913 | # | |
914 | # The compression used for new entries will be "the last one" |
|
914 | # The compression used for new entries will be "the last one" | |
915 | prefix = r.startswith |
|
915 | prefix = r.startswith | |
916 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): |
|
916 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): | |
917 | options[b'compengine'] = r.split(b'-', 2)[2] |
|
917 | options[b'compengine'] = r.split(b'-', 2)[2] | |
918 |
|
918 | |||
919 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') |
|
919 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') | |
920 | if options[b'zlib.level'] is not None: |
|
920 | if options[b'zlib.level'] is not None: | |
921 | if not (0 <= options[b'zlib.level'] <= 9): |
|
921 | if not (0 <= options[b'zlib.level'] <= 9): | |
922 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') |
|
922 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') | |
923 | raise error.Abort(msg % options[b'zlib.level']) |
|
923 | raise error.Abort(msg % options[b'zlib.level']) | |
924 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') |
|
924 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') | |
925 | if options[b'zstd.level'] is not None: |
|
925 | if options[b'zstd.level'] is not None: | |
926 | if not (0 <= options[b'zstd.level'] <= 22): |
|
926 | if not (0 <= options[b'zstd.level'] <= 22): | |
927 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') |
|
927 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') | |
928 | raise error.Abort(msg % options[b'zstd.level']) |
|
928 | raise error.Abort(msg % options[b'zstd.level']) | |
929 |
|
929 | |||
930 | if repository.NARROW_REQUIREMENT in requirements: |
|
930 | if repository.NARROW_REQUIREMENT in requirements: | |
931 | options[b'enableellipsis'] = True |
|
931 | options[b'enableellipsis'] = True | |
932 |
|
932 | |||
933 | if ui.configbool(b'experimental', b'rust.index'): |
|
933 | if ui.configbool(b'experimental', b'rust.index'): | |
934 | options[b'rust.index'] = True |
|
934 | options[b'rust.index'] = True | |
935 | if ui.configbool(b'experimental', b'exp-persistent-nodemap'): |
|
935 | if ui.configbool(b'experimental', b'exp-persistent-nodemap'): | |
936 | options[b'exp-persistent-nodemap'] = True |
|
936 | options[b'exp-persistent-nodemap'] = True | |
937 | if ui.configbool(b'experimental', b'exp-persistent-nodemap.mmap'): |
|
937 | if ui.configbool(b'experimental', b'exp-persistent-nodemap.mmap'): | |
938 | options[b'exp-persistent-nodemap.mmap'] = True |
|
938 | options[b'exp-persistent-nodemap.mmap'] = True | |
939 | if ui.configbool(b'devel', b'persistent-nodemap'): |
|
939 | if ui.configbool(b'devel', b'persistent-nodemap'): | |
940 | options[b'devel-force-nodemap'] = True |
|
940 | options[b'devel-force-nodemap'] = True | |
941 |
|
941 | |||
942 | return options |
|
942 | return options | |
943 |
|
943 | |||
944 |
|
944 | |||
945 | def makemain(**kwargs): |
|
945 | def makemain(**kwargs): | |
946 | """Produce a type conforming to ``ilocalrepositorymain``.""" |
|
946 | """Produce a type conforming to ``ilocalrepositorymain``.""" | |
947 | return localrepository |
|
947 | return localrepository | |
948 |
|
948 | |||
949 |
|
949 | |||
950 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
950 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
951 | class revlogfilestorage(object): |
|
951 | class revlogfilestorage(object): | |
952 | """File storage when using revlogs.""" |
|
952 | """File storage when using revlogs.""" | |
953 |
|
953 | |||
954 | def file(self, path): |
|
954 | def file(self, path): | |
955 | if path[0] == b'/': |
|
955 | if path[0] == b'/': | |
956 | path = path[1:] |
|
956 | path = path[1:] | |
957 |
|
957 | |||
958 | return filelog.filelog(self.svfs, path) |
|
958 | return filelog.filelog(self.svfs, path) | |
959 |
|
959 | |||
960 |
|
960 | |||
961 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
961 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
962 | class revlognarrowfilestorage(object): |
|
962 | class revlognarrowfilestorage(object): | |
963 | """File storage when using revlogs and narrow files.""" |
|
963 | """File storage when using revlogs and narrow files.""" | |
964 |
|
964 | |||
965 | def file(self, path): |
|
965 | def file(self, path): | |
966 | if path[0] == b'/': |
|
966 | if path[0] == b'/': | |
967 | path = path[1:] |
|
967 | path = path[1:] | |
968 |
|
968 | |||
969 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) |
|
969 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) | |
970 |
|
970 | |||
971 |
|
971 | |||
972 | def makefilestorage(requirements, features, **kwargs): |
|
972 | def makefilestorage(requirements, features, **kwargs): | |
973 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
|
973 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" | |
974 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) |
|
974 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) | |
975 | features.add(repository.REPO_FEATURE_STREAM_CLONE) |
|
975 | features.add(repository.REPO_FEATURE_STREAM_CLONE) | |
976 |
|
976 | |||
977 | if repository.NARROW_REQUIREMENT in requirements: |
|
977 | if repository.NARROW_REQUIREMENT in requirements: | |
978 | return revlognarrowfilestorage |
|
978 | return revlognarrowfilestorage | |
979 | else: |
|
979 | else: | |
980 | return revlogfilestorage |
|
980 | return revlogfilestorage | |
981 |
|
981 | |||
982 |
|
982 | |||
983 | # List of repository interfaces and factory functions for them. Each |
|
983 | # List of repository interfaces and factory functions for them. Each | |
984 | # will be called in order during ``makelocalrepository()`` to iteratively |
|
984 | # will be called in order during ``makelocalrepository()`` to iteratively | |
985 | # derive the final type for a local repository instance. We capture the |
|
985 | # derive the final type for a local repository instance. We capture the | |
986 | # function as a lambda so we don't hold a reference and the module-level |
|
986 | # function as a lambda so we don't hold a reference and the module-level | |
987 | # functions can be wrapped. |
|
987 | # functions can be wrapped. | |
988 | REPO_INTERFACES = [ |
|
988 | REPO_INTERFACES = [ | |
989 | (repository.ilocalrepositorymain, lambda: makemain), |
|
989 | (repository.ilocalrepositorymain, lambda: makemain), | |
990 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), |
|
990 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), | |
991 | ] |
|
991 | ] | |
992 |
|
992 | |||
993 |
|
993 | |||
994 | @interfaceutil.implementer(repository.ilocalrepositorymain) |
|
994 | @interfaceutil.implementer(repository.ilocalrepositorymain) | |
995 | class localrepository(object): |
|
995 | class localrepository(object): | |
996 | """Main class for representing local repositories. |
|
996 | """Main class for representing local repositories. | |
997 |
|
997 | |||
998 | All local repositories are instances of this class. |
|
998 | All local repositories are instances of this class. | |
999 |
|
999 | |||
1000 | Constructed on its own, instances of this class are not usable as |
|
1000 | Constructed on its own, instances of this class are not usable as | |
1001 | repository objects. To obtain a usable repository object, call |
|
1001 | repository objects. To obtain a usable repository object, call | |
1002 | ``hg.repository()``, ``localrepo.instance()``, or |
|
1002 | ``hg.repository()``, ``localrepo.instance()``, or | |
1003 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. |
|
1003 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. | |
1004 | ``instance()`` adds support for creating new repositories. |
|
1004 | ``instance()`` adds support for creating new repositories. | |
1005 | ``hg.repository()`` adds more extension integration, including calling |
|
1005 | ``hg.repository()`` adds more extension integration, including calling | |
1006 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be |
|
1006 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be | |
1007 | used. |
|
1007 | used. | |
1008 | """ |
|
1008 | """ | |
1009 |
|
1009 | |||
1010 | # obsolete experimental requirements: |
|
1010 | # obsolete experimental requirements: | |
1011 | # - manifestv2: An experimental new manifest format that allowed |
|
1011 | # - manifestv2: An experimental new manifest format that allowed | |
1012 | # for stem compression of long paths. Experiment ended up not |
|
1012 | # for stem compression of long paths. Experiment ended up not | |
1013 | # being successful (repository sizes went up due to worse delta |
|
1013 | # being successful (repository sizes went up due to worse delta | |
1014 | # chains), and the code was deleted in 4.6. |
|
1014 | # chains), and the code was deleted in 4.6. | |
1015 | supportedformats = { |
|
1015 | supportedformats = { | |
1016 | b'revlogv1', |
|
1016 | b'revlogv1', | |
1017 | b'generaldelta', |
|
1017 | b'generaldelta', | |
1018 | b'treemanifest', |
|
1018 | b'treemanifest', | |
1019 | COPIESSDC_REQUIREMENT, |
|
1019 | COPIESSDC_REQUIREMENT, | |
1020 | REVLOGV2_REQUIREMENT, |
|
1020 | REVLOGV2_REQUIREMENT, | |
1021 | SIDEDATA_REQUIREMENT, |
|
1021 | SIDEDATA_REQUIREMENT, | |
1022 | SPARSEREVLOG_REQUIREMENT, |
|
1022 | SPARSEREVLOG_REQUIREMENT, | |
1023 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, |
|
1023 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, | |
1024 | } |
|
1024 | } | |
1025 | _basesupported = supportedformats | { |
|
1025 | _basesupported = supportedformats | { | |
1026 | b'store', |
|
1026 | b'store', | |
1027 | b'fncache', |
|
1027 | b'fncache', | |
1028 | b'shared', |
|
1028 | b'shared', | |
1029 | b'relshared', |
|
1029 | b'relshared', | |
1030 | b'dotencode', |
|
1030 | b'dotencode', | |
1031 | b'exp-sparse', |
|
1031 | b'exp-sparse', | |
1032 | b'internal-phase', |
|
1032 | b'internal-phase', | |
1033 | } |
|
1033 | } | |
1034 |
|
1034 | |||
1035 | # list of prefix for file which can be written without 'wlock' |
|
1035 | # list of prefix for file which can be written without 'wlock' | |
1036 | # Extensions should extend this list when needed |
|
1036 | # Extensions should extend this list when needed | |
1037 | _wlockfreeprefix = { |
|
1037 | _wlockfreeprefix = { | |
1038 | # We migh consider requiring 'wlock' for the next |
|
1038 | # We migh consider requiring 'wlock' for the next | |
1039 | # two, but pretty much all the existing code assume |
|
1039 | # two, but pretty much all the existing code assume | |
1040 | # wlock is not needed so we keep them excluded for |
|
1040 | # wlock is not needed so we keep them excluded for | |
1041 | # now. |
|
1041 | # now. | |
1042 | b'hgrc', |
|
1042 | b'hgrc', | |
1043 | b'requires', |
|
1043 | b'requires', | |
1044 | # XXX cache is a complicatged business someone |
|
1044 | # XXX cache is a complicatged business someone | |
1045 | # should investigate this in depth at some point |
|
1045 | # should investigate this in depth at some point | |
1046 | b'cache/', |
|
1046 | b'cache/', | |
1047 | # XXX shouldn't be dirstate covered by the wlock? |
|
1047 | # XXX shouldn't be dirstate covered by the wlock? | |
1048 | b'dirstate', |
|
1048 | b'dirstate', | |
1049 | # XXX bisect was still a bit too messy at the time |
|
1049 | # XXX bisect was still a bit too messy at the time | |
1050 | # this changeset was introduced. Someone should fix |
|
1050 | # this changeset was introduced. Someone should fix | |
1051 | # the remainig bit and drop this line |
|
1051 | # the remainig bit and drop this line | |
1052 | b'bisect.state', |
|
1052 | b'bisect.state', | |
1053 | } |
|
1053 | } | |
1054 |
|
1054 | |||
1055 | def __init__( |
|
1055 | def __init__( | |
1056 | self, |
|
1056 | self, | |
1057 | baseui, |
|
1057 | baseui, | |
1058 | ui, |
|
1058 | ui, | |
1059 | origroot, |
|
1059 | origroot, | |
1060 | wdirvfs, |
|
1060 | wdirvfs, | |
1061 | hgvfs, |
|
1061 | hgvfs, | |
1062 | requirements, |
|
1062 | requirements, | |
1063 | supportedrequirements, |
|
1063 | supportedrequirements, | |
1064 | sharedpath, |
|
1064 | sharedpath, | |
1065 | store, |
|
1065 | store, | |
1066 | cachevfs, |
|
1066 | cachevfs, | |
1067 | wcachevfs, |
|
1067 | wcachevfs, | |
1068 | features, |
|
1068 | features, | |
1069 | intents=None, |
|
1069 | intents=None, | |
1070 | ): |
|
1070 | ): | |
1071 | """Create a new local repository instance. |
|
1071 | """Create a new local repository instance. | |
1072 |
|
1072 | |||
1073 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, |
|
1073 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, | |
1074 | or ``localrepo.makelocalrepository()`` for obtaining a new repository |
|
1074 | or ``localrepo.makelocalrepository()`` for obtaining a new repository | |
1075 | object. |
|
1075 | object. | |
1076 |
|
1076 | |||
1077 | Arguments: |
|
1077 | Arguments: | |
1078 |
|
1078 | |||
1079 | baseui |
|
1079 | baseui | |
1080 | ``ui.ui`` instance that ``ui`` argument was based off of. |
|
1080 | ``ui.ui`` instance that ``ui`` argument was based off of. | |
1081 |
|
1081 | |||
1082 | ui |
|
1082 | ui | |
1083 | ``ui.ui`` instance for use by the repository. |
|
1083 | ``ui.ui`` instance for use by the repository. | |
1084 |
|
1084 | |||
1085 | origroot |
|
1085 | origroot | |
1086 | ``bytes`` path to working directory root of this repository. |
|
1086 | ``bytes`` path to working directory root of this repository. | |
1087 |
|
1087 | |||
1088 | wdirvfs |
|
1088 | wdirvfs | |
1089 | ``vfs.vfs`` rooted at the working directory. |
|
1089 | ``vfs.vfs`` rooted at the working directory. | |
1090 |
|
1090 | |||
1091 | hgvfs |
|
1091 | hgvfs | |
1092 | ``vfs.vfs`` rooted at .hg/ |
|
1092 | ``vfs.vfs`` rooted at .hg/ | |
1093 |
|
1093 | |||
1094 | requirements |
|
1094 | requirements | |
1095 | ``set`` of bytestrings representing repository opening requirements. |
|
1095 | ``set`` of bytestrings representing repository opening requirements. | |
1096 |
|
1096 | |||
1097 | supportedrequirements |
|
1097 | supportedrequirements | |
1098 | ``set`` of bytestrings representing repository requirements that we |
|
1098 | ``set`` of bytestrings representing repository requirements that we | |
1099 | know how to open. May be a supetset of ``requirements``. |
|
1099 | know how to open. May be a supetset of ``requirements``. | |
1100 |
|
1100 | |||
1101 | sharedpath |
|
1101 | sharedpath | |
1102 | ``bytes`` Defining path to storage base directory. Points to a |
|
1102 | ``bytes`` Defining path to storage base directory. Points to a | |
1103 | ``.hg/`` directory somewhere. |
|
1103 | ``.hg/`` directory somewhere. | |
1104 |
|
1104 | |||
1105 | store |
|
1105 | store | |
1106 | ``store.basicstore`` (or derived) instance providing access to |
|
1106 | ``store.basicstore`` (or derived) instance providing access to | |
1107 | versioned storage. |
|
1107 | versioned storage. | |
1108 |
|
1108 | |||
1109 | cachevfs |
|
1109 | cachevfs | |
1110 | ``vfs.vfs`` used for cache files. |
|
1110 | ``vfs.vfs`` used for cache files. | |
1111 |
|
1111 | |||
1112 | wcachevfs |
|
1112 | wcachevfs | |
1113 | ``vfs.vfs`` used for cache files related to the working copy. |
|
1113 | ``vfs.vfs`` used for cache files related to the working copy. | |
1114 |
|
1114 | |||
1115 | features |
|
1115 | features | |
1116 | ``set`` of bytestrings defining features/capabilities of this |
|
1116 | ``set`` of bytestrings defining features/capabilities of this | |
1117 | instance. |
|
1117 | instance. | |
1118 |
|
1118 | |||
1119 | intents |
|
1119 | intents | |
1120 | ``set`` of system strings indicating what this repo will be used |
|
1120 | ``set`` of system strings indicating what this repo will be used | |
1121 | for. |
|
1121 | for. | |
1122 | """ |
|
1122 | """ | |
1123 | self.baseui = baseui |
|
1123 | self.baseui = baseui | |
1124 | self.ui = ui |
|
1124 | self.ui = ui | |
1125 | self.origroot = origroot |
|
1125 | self.origroot = origroot | |
1126 | # vfs rooted at working directory. |
|
1126 | # vfs rooted at working directory. | |
1127 | self.wvfs = wdirvfs |
|
1127 | self.wvfs = wdirvfs | |
1128 | self.root = wdirvfs.base |
|
1128 | self.root = wdirvfs.base | |
1129 | # vfs rooted at .hg/. Used to access most non-store paths. |
|
1129 | # vfs rooted at .hg/. Used to access most non-store paths. | |
1130 | self.vfs = hgvfs |
|
1130 | self.vfs = hgvfs | |
1131 | self.path = hgvfs.base |
|
1131 | self.path = hgvfs.base | |
1132 | self.requirements = requirements |
|
1132 | self.requirements = requirements | |
1133 | self.supported = supportedrequirements |
|
1133 | self.supported = supportedrequirements | |
1134 | self.sharedpath = sharedpath |
|
1134 | self.sharedpath = sharedpath | |
1135 | self.store = store |
|
1135 | self.store = store | |
1136 | self.cachevfs = cachevfs |
|
1136 | self.cachevfs = cachevfs | |
1137 | self.wcachevfs = wcachevfs |
|
1137 | self.wcachevfs = wcachevfs | |
1138 | self.features = features |
|
1138 | self.features = features | |
1139 |
|
1139 | |||
1140 | self.filtername = None |
|
1140 | self.filtername = None | |
1141 |
|
1141 | |||
1142 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1142 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1143 | b'devel', b'check-locks' |
|
1143 | b'devel', b'check-locks' | |
1144 | ): |
|
1144 | ): | |
1145 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
1145 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
1146 | # A list of callback to shape the phase if no data were found. |
|
1146 | # A list of callback to shape the phase if no data were found. | |
1147 | # Callback are in the form: func(repo, roots) --> processed root. |
|
1147 | # Callback are in the form: func(repo, roots) --> processed root. | |
1148 | # This list it to be filled by extension during repo setup |
|
1148 | # This list it to be filled by extension during repo setup | |
1149 | self._phasedefaults = [] |
|
1149 | self._phasedefaults = [] | |
1150 |
|
1150 | |||
1151 | color.setup(self.ui) |
|
1151 | color.setup(self.ui) | |
1152 |
|
1152 | |||
1153 | self.spath = self.store.path |
|
1153 | self.spath = self.store.path | |
1154 | self.svfs = self.store.vfs |
|
1154 | self.svfs = self.store.vfs | |
1155 | self.sjoin = self.store.join |
|
1155 | self.sjoin = self.store.join | |
1156 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1156 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1157 | b'devel', b'check-locks' |
|
1157 | b'devel', b'check-locks' | |
1158 | ): |
|
1158 | ): | |
1159 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs |
|
1159 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs | |
1160 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
1160 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
1161 | else: # standard vfs |
|
1161 | else: # standard vfs | |
1162 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
1162 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
1163 |
|
1163 | |||
1164 | self._dirstatevalidatewarned = False |
|
1164 | self._dirstatevalidatewarned = False | |
1165 |
|
1165 | |||
1166 | self._branchcaches = branchmap.BranchMapCache() |
|
1166 | self._branchcaches = branchmap.BranchMapCache() | |
1167 | self._revbranchcache = None |
|
1167 | self._revbranchcache = None | |
1168 | self._filterpats = {} |
|
1168 | self._filterpats = {} | |
1169 | self._datafilters = {} |
|
1169 | self._datafilters = {} | |
1170 | self._transref = self._lockref = self._wlockref = None |
|
1170 | self._transref = self._lockref = self._wlockref = None | |
1171 |
|
1171 | |||
1172 | # A cache for various files under .hg/ that tracks file changes, |
|
1172 | # A cache for various files under .hg/ that tracks file changes, | |
1173 | # (used by the filecache decorator) |
|
1173 | # (used by the filecache decorator) | |
1174 | # |
|
1174 | # | |
1175 | # Maps a property name to its util.filecacheentry |
|
1175 | # Maps a property name to its util.filecacheentry | |
1176 | self._filecache = {} |
|
1176 | self._filecache = {} | |
1177 |
|
1177 | |||
1178 | # hold sets of revision to be filtered |
|
1178 | # hold sets of revision to be filtered | |
1179 | # should be cleared when something might have changed the filter value: |
|
1179 | # should be cleared when something might have changed the filter value: | |
1180 | # - new changesets, |
|
1180 | # - new changesets, | |
1181 | # - phase change, |
|
1181 | # - phase change, | |
1182 | # - new obsolescence marker, |
|
1182 | # - new obsolescence marker, | |
1183 | # - working directory parent change, |
|
1183 | # - working directory parent change, | |
1184 | # - bookmark changes |
|
1184 | # - bookmark changes | |
1185 | self.filteredrevcache = {} |
|
1185 | self.filteredrevcache = {} | |
1186 |
|
1186 | |||
1187 | # post-dirstate-status hooks |
|
1187 | # post-dirstate-status hooks | |
1188 | self._postdsstatus = [] |
|
1188 | self._postdsstatus = [] | |
1189 |
|
1189 | |||
1190 | # generic mapping between names and nodes |
|
1190 | # generic mapping between names and nodes | |
1191 | self.names = namespaces.namespaces() |
|
1191 | self.names = namespaces.namespaces() | |
1192 |
|
1192 | |||
1193 | # Key to signature value. |
|
1193 | # Key to signature value. | |
1194 | self._sparsesignaturecache = {} |
|
1194 | self._sparsesignaturecache = {} | |
1195 | # Signature to cached matcher instance. |
|
1195 | # Signature to cached matcher instance. | |
1196 | self._sparsematchercache = {} |
|
1196 | self._sparsematchercache = {} | |
1197 |
|
1197 | |||
1198 | self._extrafilterid = repoview.extrafilter(ui) |
|
1198 | self._extrafilterid = repoview.extrafilter(ui) | |
1199 |
|
1199 | |||
1200 | self.filecopiesmode = None |
|
1200 | self.filecopiesmode = None | |
1201 | if COPIESSDC_REQUIREMENT in self.requirements: |
|
1201 | if COPIESSDC_REQUIREMENT in self.requirements: | |
1202 | self.filecopiesmode = b'changeset-sidedata' |
|
1202 | self.filecopiesmode = b'changeset-sidedata' | |
1203 |
|
1203 | |||
1204 | def _getvfsward(self, origfunc): |
|
1204 | def _getvfsward(self, origfunc): | |
1205 | """build a ward for self.vfs""" |
|
1205 | """build a ward for self.vfs""" | |
1206 | rref = weakref.ref(self) |
|
1206 | rref = weakref.ref(self) | |
1207 |
|
1207 | |||
1208 | def checkvfs(path, mode=None): |
|
1208 | def checkvfs(path, mode=None): | |
1209 | ret = origfunc(path, mode=mode) |
|
1209 | ret = origfunc(path, mode=mode) | |
1210 | repo = rref() |
|
1210 | repo = rref() | |
1211 | if ( |
|
1211 | if ( | |
1212 | repo is None |
|
1212 | repo is None | |
1213 | or not util.safehasattr(repo, b'_wlockref') |
|
1213 | or not util.safehasattr(repo, b'_wlockref') | |
1214 | or not util.safehasattr(repo, b'_lockref') |
|
1214 | or not util.safehasattr(repo, b'_lockref') | |
1215 | ): |
|
1215 | ): | |
1216 | return |
|
1216 | return | |
1217 | if mode in (None, b'r', b'rb'): |
|
1217 | if mode in (None, b'r', b'rb'): | |
1218 | return |
|
1218 | return | |
1219 | if path.startswith(repo.path): |
|
1219 | if path.startswith(repo.path): | |
1220 | # truncate name relative to the repository (.hg) |
|
1220 | # truncate name relative to the repository (.hg) | |
1221 | path = path[len(repo.path) + 1 :] |
|
1221 | path = path[len(repo.path) + 1 :] | |
1222 | if path.startswith(b'cache/'): |
|
1222 | if path.startswith(b'cache/'): | |
1223 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' |
|
1223 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' | |
1224 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") |
|
1224 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") | |
1225 | if path.startswith(b'journal.') or path.startswith(b'undo.'): |
|
1225 | if path.startswith(b'journal.') or path.startswith(b'undo.'): | |
1226 | # journal is covered by 'lock' |
|
1226 | # journal is covered by 'lock' | |
1227 | if repo._currentlock(repo._lockref) is None: |
|
1227 | if repo._currentlock(repo._lockref) is None: | |
1228 | repo.ui.develwarn( |
|
1228 | repo.ui.develwarn( | |
1229 | b'write with no lock: "%s"' % path, |
|
1229 | b'write with no lock: "%s"' % path, | |
1230 | stacklevel=3, |
|
1230 | stacklevel=3, | |
1231 | config=b'check-locks', |
|
1231 | config=b'check-locks', | |
1232 | ) |
|
1232 | ) | |
1233 | elif repo._currentlock(repo._wlockref) is None: |
|
1233 | elif repo._currentlock(repo._wlockref) is None: | |
1234 | # rest of vfs files are covered by 'wlock' |
|
1234 | # rest of vfs files are covered by 'wlock' | |
1235 | # |
|
1235 | # | |
1236 | # exclude special files |
|
1236 | # exclude special files | |
1237 | for prefix in self._wlockfreeprefix: |
|
1237 | for prefix in self._wlockfreeprefix: | |
1238 | if path.startswith(prefix): |
|
1238 | if path.startswith(prefix): | |
1239 | return |
|
1239 | return | |
1240 | repo.ui.develwarn( |
|
1240 | repo.ui.develwarn( | |
1241 | b'write with no wlock: "%s"' % path, |
|
1241 | b'write with no wlock: "%s"' % path, | |
1242 | stacklevel=3, |
|
1242 | stacklevel=3, | |
1243 | config=b'check-locks', |
|
1243 | config=b'check-locks', | |
1244 | ) |
|
1244 | ) | |
1245 | return ret |
|
1245 | return ret | |
1246 |
|
1246 | |||
1247 | return checkvfs |
|
1247 | return checkvfs | |
1248 |
|
1248 | |||
1249 | def _getsvfsward(self, origfunc): |
|
1249 | def _getsvfsward(self, origfunc): | |
1250 | """build a ward for self.svfs""" |
|
1250 | """build a ward for self.svfs""" | |
1251 | rref = weakref.ref(self) |
|
1251 | rref = weakref.ref(self) | |
1252 |
|
1252 | |||
1253 | def checksvfs(path, mode=None): |
|
1253 | def checksvfs(path, mode=None): | |
1254 | ret = origfunc(path, mode=mode) |
|
1254 | ret = origfunc(path, mode=mode) | |
1255 | repo = rref() |
|
1255 | repo = rref() | |
1256 | if repo is None or not util.safehasattr(repo, b'_lockref'): |
|
1256 | if repo is None or not util.safehasattr(repo, b'_lockref'): | |
1257 | return |
|
1257 | return | |
1258 | if mode in (None, b'r', b'rb'): |
|
1258 | if mode in (None, b'r', b'rb'): | |
1259 | return |
|
1259 | return | |
1260 | if path.startswith(repo.sharedpath): |
|
1260 | if path.startswith(repo.sharedpath): | |
1261 | # truncate name relative to the repository (.hg) |
|
1261 | # truncate name relative to the repository (.hg) | |
1262 | path = path[len(repo.sharedpath) + 1 :] |
|
1262 | path = path[len(repo.sharedpath) + 1 :] | |
1263 | if repo._currentlock(repo._lockref) is None: |
|
1263 | if repo._currentlock(repo._lockref) is None: | |
1264 | repo.ui.develwarn( |
|
1264 | repo.ui.develwarn( | |
1265 | b'write with no lock: "%s"' % path, stacklevel=4 |
|
1265 | b'write with no lock: "%s"' % path, stacklevel=4 | |
1266 | ) |
|
1266 | ) | |
1267 | return ret |
|
1267 | return ret | |
1268 |
|
1268 | |||
1269 | return checksvfs |
|
1269 | return checksvfs | |
1270 |
|
1270 | |||
1271 | def close(self): |
|
1271 | def close(self): | |
1272 | self._writecaches() |
|
1272 | self._writecaches() | |
1273 |
|
1273 | |||
1274 | def _writecaches(self): |
|
1274 | def _writecaches(self): | |
1275 | if self._revbranchcache: |
|
1275 | if self._revbranchcache: | |
1276 | self._revbranchcache.write() |
|
1276 | self._revbranchcache.write() | |
1277 |
|
1277 | |||
1278 | def _restrictcapabilities(self, caps): |
|
1278 | def _restrictcapabilities(self, caps): | |
1279 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): |
|
1279 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): | |
1280 | caps = set(caps) |
|
1280 | caps = set(caps) | |
1281 | capsblob = bundle2.encodecaps( |
|
1281 | capsblob = bundle2.encodecaps( | |
1282 | bundle2.getrepocaps(self, role=b'client') |
|
1282 | bundle2.getrepocaps(self, role=b'client') | |
1283 | ) |
|
1283 | ) | |
1284 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) |
|
1284 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) | |
1285 | return caps |
|
1285 | return caps | |
1286 |
|
1286 | |||
1287 | def _writerequirements(self): |
|
1287 | def _writerequirements(self): | |
1288 | scmutil.writerequires(self.vfs, self.requirements) |
|
1288 | scmutil.writerequires(self.vfs, self.requirements) | |
1289 |
|
1289 | |||
1290 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: |
|
1290 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: | |
1291 | # self -> auditor -> self._checknested -> self |
|
1291 | # self -> auditor -> self._checknested -> self | |
1292 |
|
1292 | |||
1293 | @property |
|
1293 | @property | |
1294 | def auditor(self): |
|
1294 | def auditor(self): | |
1295 | # This is only used by context.workingctx.match in order to |
|
1295 | # This is only used by context.workingctx.match in order to | |
1296 | # detect files in subrepos. |
|
1296 | # detect files in subrepos. | |
1297 | return pathutil.pathauditor(self.root, callback=self._checknested) |
|
1297 | return pathutil.pathauditor(self.root, callback=self._checknested) | |
1298 |
|
1298 | |||
1299 | @property |
|
1299 | @property | |
1300 | def nofsauditor(self): |
|
1300 | def nofsauditor(self): | |
1301 | # This is only used by context.basectx.match in order to detect |
|
1301 | # This is only used by context.basectx.match in order to detect | |
1302 | # files in subrepos. |
|
1302 | # files in subrepos. | |
1303 | return pathutil.pathauditor( |
|
1303 | return pathutil.pathauditor( | |
1304 | self.root, callback=self._checknested, realfs=False, cached=True |
|
1304 | self.root, callback=self._checknested, realfs=False, cached=True | |
1305 | ) |
|
1305 | ) | |
1306 |
|
1306 | |||
1307 | def _checknested(self, path): |
|
1307 | def _checknested(self, path): | |
1308 | """Determine if path is a legal nested repository.""" |
|
1308 | """Determine if path is a legal nested repository.""" | |
1309 | if not path.startswith(self.root): |
|
1309 | if not path.startswith(self.root): | |
1310 | return False |
|
1310 | return False | |
1311 | subpath = path[len(self.root) + 1 :] |
|
1311 | subpath = path[len(self.root) + 1 :] | |
1312 | normsubpath = util.pconvert(subpath) |
|
1312 | normsubpath = util.pconvert(subpath) | |
1313 |
|
1313 | |||
1314 | # XXX: Checking against the current working copy is wrong in |
|
1314 | # XXX: Checking against the current working copy is wrong in | |
1315 | # the sense that it can reject things like |
|
1315 | # the sense that it can reject things like | |
1316 | # |
|
1316 | # | |
1317 | # $ hg cat -r 10 sub/x.txt |
|
1317 | # $ hg cat -r 10 sub/x.txt | |
1318 | # |
|
1318 | # | |
1319 | # if sub/ is no longer a subrepository in the working copy |
|
1319 | # if sub/ is no longer a subrepository in the working copy | |
1320 | # parent revision. |
|
1320 | # parent revision. | |
1321 | # |
|
1321 | # | |
1322 | # However, it can of course also allow things that would have |
|
1322 | # However, it can of course also allow things that would have | |
1323 | # been rejected before, such as the above cat command if sub/ |
|
1323 | # been rejected before, such as the above cat command if sub/ | |
1324 | # is a subrepository now, but was a normal directory before. |
|
1324 | # is a subrepository now, but was a normal directory before. | |
1325 | # The old path auditor would have rejected by mistake since it |
|
1325 | # The old path auditor would have rejected by mistake since it | |
1326 | # panics when it sees sub/.hg/. |
|
1326 | # panics when it sees sub/.hg/. | |
1327 | # |
|
1327 | # | |
1328 | # All in all, checking against the working copy seems sensible |
|
1328 | # All in all, checking against the working copy seems sensible | |
1329 | # since we want to prevent access to nested repositories on |
|
1329 | # since we want to prevent access to nested repositories on | |
1330 | # the filesystem *now*. |
|
1330 | # the filesystem *now*. | |
1331 | ctx = self[None] |
|
1331 | ctx = self[None] | |
1332 | parts = util.splitpath(subpath) |
|
1332 | parts = util.splitpath(subpath) | |
1333 | while parts: |
|
1333 | while parts: | |
1334 | prefix = b'/'.join(parts) |
|
1334 | prefix = b'/'.join(parts) | |
1335 | if prefix in ctx.substate: |
|
1335 | if prefix in ctx.substate: | |
1336 | if prefix == normsubpath: |
|
1336 | if prefix == normsubpath: | |
1337 | return True |
|
1337 | return True | |
1338 | else: |
|
1338 | else: | |
1339 | sub = ctx.sub(prefix) |
|
1339 | sub = ctx.sub(prefix) | |
1340 | return sub.checknested(subpath[len(prefix) + 1 :]) |
|
1340 | return sub.checknested(subpath[len(prefix) + 1 :]) | |
1341 | else: |
|
1341 | else: | |
1342 | parts.pop() |
|
1342 | parts.pop() | |
1343 | return False |
|
1343 | return False | |
1344 |
|
1344 | |||
1345 | def peer(self): |
|
1345 | def peer(self): | |
1346 | return localpeer(self) # not cached to avoid reference cycle |
|
1346 | return localpeer(self) # not cached to avoid reference cycle | |
1347 |
|
1347 | |||
1348 | def unfiltered(self): |
|
1348 | def unfiltered(self): | |
1349 | """Return unfiltered version of the repository |
|
1349 | """Return unfiltered version of the repository | |
1350 |
|
1350 | |||
1351 | Intended to be overwritten by filtered repo.""" |
|
1351 | Intended to be overwritten by filtered repo.""" | |
1352 | return self |
|
1352 | return self | |
1353 |
|
1353 | |||
1354 | def filtered(self, name, visibilityexceptions=None): |
|
1354 | def filtered(self, name, visibilityexceptions=None): | |
1355 | """Return a filtered version of a repository |
|
1355 | """Return a filtered version of a repository | |
1356 |
|
1356 | |||
1357 | The `name` parameter is the identifier of the requested view. This |
|
1357 | The `name` parameter is the identifier of the requested view. This | |
1358 | will return a repoview object set "exactly" to the specified view. |
|
1358 | will return a repoview object set "exactly" to the specified view. | |
1359 |
|
1359 | |||
1360 | This function does not apply recursive filtering to a repository. For |
|
1360 | This function does not apply recursive filtering to a repository. For | |
1361 | example calling `repo.filtered("served")` will return a repoview using |
|
1361 | example calling `repo.filtered("served")` will return a repoview using | |
1362 | the "served" view, regardless of the initial view used by `repo`. |
|
1362 | the "served" view, regardless of the initial view used by `repo`. | |
1363 |
|
1363 | |||
1364 | In other word, there is always only one level of `repoview` "filtering". |
|
1364 | In other word, there is always only one level of `repoview` "filtering". | |
1365 | """ |
|
1365 | """ | |
1366 | if self._extrafilterid is not None and b'%' not in name: |
|
1366 | if self._extrafilterid is not None and b'%' not in name: | |
1367 | name = name + b'%' + self._extrafilterid |
|
1367 | name = name + b'%' + self._extrafilterid | |
1368 |
|
1368 | |||
1369 | cls = repoview.newtype(self.unfiltered().__class__) |
|
1369 | cls = repoview.newtype(self.unfiltered().__class__) | |
1370 | return cls(self, name, visibilityexceptions) |
|
1370 | return cls(self, name, visibilityexceptions) | |
1371 |
|
1371 | |||
1372 | @mixedrepostorecache( |
|
1372 | @mixedrepostorecache( | |
1373 | (b'bookmarks', b'plain'), |
|
1373 | (b'bookmarks', b'plain'), | |
1374 | (b'bookmarks.current', b'plain'), |
|
1374 | (b'bookmarks.current', b'plain'), | |
1375 | (b'bookmarks', b''), |
|
1375 | (b'bookmarks', b''), | |
1376 | (b'00changelog.i', b''), |
|
1376 | (b'00changelog.i', b''), | |
1377 | ) |
|
1377 | ) | |
1378 | def _bookmarks(self): |
|
1378 | def _bookmarks(self): | |
1379 | # Since the multiple files involved in the transaction cannot be |
|
1379 | # Since the multiple files involved in the transaction cannot be | |
1380 | # written atomically (with current repository format), there is a race |
|
1380 | # written atomically (with current repository format), there is a race | |
1381 | # condition here. |
|
1381 | # condition here. | |
1382 | # |
|
1382 | # | |
1383 | # 1) changelog content A is read |
|
1383 | # 1) changelog content A is read | |
1384 | # 2) outside transaction update changelog to content B |
|
1384 | # 2) outside transaction update changelog to content B | |
1385 | # 3) outside transaction update bookmark file referring to content B |
|
1385 | # 3) outside transaction update bookmark file referring to content B | |
1386 | # 4) bookmarks file content is read and filtered against changelog-A |
|
1386 | # 4) bookmarks file content is read and filtered against changelog-A | |
1387 | # |
|
1387 | # | |
1388 | # When this happens, bookmarks against nodes missing from A are dropped. |
|
1388 | # When this happens, bookmarks against nodes missing from A are dropped. | |
1389 | # |
|
1389 | # | |
1390 | # Having this happening during read is not great, but it become worse |
|
1390 | # Having this happening during read is not great, but it become worse | |
1391 | # when this happen during write because the bookmarks to the "unknown" |
|
1391 | # when this happen during write because the bookmarks to the "unknown" | |
1392 | # nodes will be dropped for good. However, writes happen within locks. |
|
1392 | # nodes will be dropped for good. However, writes happen within locks. | |
1393 | # This locking makes it possible to have a race free consistent read. |
|
1393 | # This locking makes it possible to have a race free consistent read. | |
1394 | # For this purpose data read from disc before locking are |
|
1394 | # For this purpose data read from disc before locking are | |
1395 | # "invalidated" right after the locks are taken. This invalidations are |
|
1395 | # "invalidated" right after the locks are taken. This invalidations are | |
1396 | # "light", the `filecache` mechanism keep the data in memory and will |
|
1396 | # "light", the `filecache` mechanism keep the data in memory and will | |
1397 | # reuse them if the underlying files did not changed. Not parsing the |
|
1397 | # reuse them if the underlying files did not changed. Not parsing the | |
1398 | # same data multiple times helps performances. |
|
1398 | # same data multiple times helps performances. | |
1399 | # |
|
1399 | # | |
1400 | # Unfortunately in the case describe above, the files tracked by the |
|
1400 | # Unfortunately in the case describe above, the files tracked by the | |
1401 | # bookmarks file cache might not have changed, but the in-memory |
|
1401 | # bookmarks file cache might not have changed, but the in-memory | |
1402 | # content is still "wrong" because we used an older changelog content |
|
1402 | # content is still "wrong" because we used an older changelog content | |
1403 | # to process the on-disk data. So after locking, the changelog would be |
|
1403 | # to process the on-disk data. So after locking, the changelog would be | |
1404 | # refreshed but `_bookmarks` would be preserved. |
|
1404 | # refreshed but `_bookmarks` would be preserved. | |
1405 | # Adding `00changelog.i` to the list of tracked file is not |
|
1405 | # Adding `00changelog.i` to the list of tracked file is not | |
1406 | # enough, because at the time we build the content for `_bookmarks` in |
|
1406 | # enough, because at the time we build the content for `_bookmarks` in | |
1407 | # (4), the changelog file has already diverged from the content used |
|
1407 | # (4), the changelog file has already diverged from the content used | |
1408 | # for loading `changelog` in (1) |
|
1408 | # for loading `changelog` in (1) | |
1409 | # |
|
1409 | # | |
1410 | # To prevent the issue, we force the changelog to be explicitly |
|
1410 | # To prevent the issue, we force the changelog to be explicitly | |
1411 | # reloaded while computing `_bookmarks`. The data race can still happen |
|
1411 | # reloaded while computing `_bookmarks`. The data race can still happen | |
1412 | # without the lock (with a narrower window), but it would no longer go |
|
1412 | # without the lock (with a narrower window), but it would no longer go | |
1413 | # undetected during the lock time refresh. |
|
1413 | # undetected during the lock time refresh. | |
1414 | # |
|
1414 | # | |
1415 | # The new schedule is as follow |
|
1415 | # The new schedule is as follow | |
1416 | # |
|
1416 | # | |
1417 | # 1) filecache logic detect that `_bookmarks` needs to be computed |
|
1417 | # 1) filecache logic detect that `_bookmarks` needs to be computed | |
1418 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) |
|
1418 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) | |
1419 | # 3) We force `changelog` filecache to be tested |
|
1419 | # 3) We force `changelog` filecache to be tested | |
1420 | # 4) cachestat for `changelog` are captured (for changelog) |
|
1420 | # 4) cachestat for `changelog` are captured (for changelog) | |
1421 | # 5) `_bookmarks` is computed and cached |
|
1421 | # 5) `_bookmarks` is computed and cached | |
1422 | # |
|
1422 | # | |
1423 | # The step in (3) ensure we have a changelog at least as recent as the |
|
1423 | # The step in (3) ensure we have a changelog at least as recent as the | |
1424 | # cache stat computed in (1). As a result at locking time: |
|
1424 | # cache stat computed in (1). As a result at locking time: | |
1425 | # * if the changelog did not changed since (1) -> we can reuse the data |
|
1425 | # * if the changelog did not changed since (1) -> we can reuse the data | |
1426 | # * otherwise -> the bookmarks get refreshed. |
|
1426 | # * otherwise -> the bookmarks get refreshed. | |
1427 | self._refreshchangelog() |
|
1427 | self._refreshchangelog() | |
1428 | return bookmarks.bmstore(self) |
|
1428 | return bookmarks.bmstore(self) | |
1429 |
|
1429 | |||
1430 | def _refreshchangelog(self): |
|
1430 | def _refreshchangelog(self): | |
1431 | """make sure the in memory changelog match the on-disk one""" |
|
1431 | """make sure the in memory changelog match the on-disk one""" | |
1432 | if 'changelog' in vars(self) and self.currenttransaction() is None: |
|
1432 | if 'changelog' in vars(self) and self.currenttransaction() is None: | |
1433 | del self.changelog |
|
1433 | del self.changelog | |
1434 |
|
1434 | |||
1435 | @property |
|
1435 | @property | |
1436 | def _activebookmark(self): |
|
1436 | def _activebookmark(self): | |
1437 | return self._bookmarks.active |
|
1437 | return self._bookmarks.active | |
1438 |
|
1438 | |||
1439 | # _phasesets depend on changelog. what we need is to call |
|
1439 | # _phasesets depend on changelog. what we need is to call | |
1440 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
1440 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
1441 | # can't be easily expressed in filecache mechanism. |
|
1441 | # can't be easily expressed in filecache mechanism. | |
1442 | @storecache(b'phaseroots', b'00changelog.i') |
|
1442 | @storecache(b'phaseroots', b'00changelog.i') | |
1443 | def _phasecache(self): |
|
1443 | def _phasecache(self): | |
1444 | return phases.phasecache(self, self._phasedefaults) |
|
1444 | return phases.phasecache(self, self._phasedefaults) | |
1445 |
|
1445 | |||
1446 | @storecache(b'obsstore') |
|
1446 | @storecache(b'obsstore') | |
1447 | def obsstore(self): |
|
1447 | def obsstore(self): | |
1448 | return obsolete.makestore(self.ui, self) |
|
1448 | return obsolete.makestore(self.ui, self) | |
1449 |
|
1449 | |||
1450 | @storecache(b'00changelog.i') |
|
1450 | @storecache(b'00changelog.i') | |
1451 | def changelog(self): |
|
1451 | def changelog(self): | |
1452 | return self.store.changelog(txnutil.mayhavepending(self.root)) |
|
1452 | return self.store.changelog(txnutil.mayhavepending(self.root)) | |
1453 |
|
1453 | |||
1454 | @storecache(b'00manifest.i') |
|
1454 | @storecache(b'00manifest.i') | |
1455 | def manifestlog(self): |
|
1455 | def manifestlog(self): | |
1456 | return self.store.manifestlog(self, self._storenarrowmatch) |
|
1456 | return self.store.manifestlog(self, self._storenarrowmatch) | |
1457 |
|
1457 | |||
1458 | @repofilecache(b'dirstate') |
|
1458 | @repofilecache(b'dirstate') | |
1459 | def dirstate(self): |
|
1459 | def dirstate(self): | |
1460 | return self._makedirstate() |
|
1460 | return self._makedirstate() | |
1461 |
|
1461 | |||
1462 | def _makedirstate(self): |
|
1462 | def _makedirstate(self): | |
1463 | """Extension point for wrapping the dirstate per-repo.""" |
|
1463 | """Extension point for wrapping the dirstate per-repo.""" | |
1464 | sparsematchfn = lambda: sparse.matcher(self) |
|
1464 | sparsematchfn = lambda: sparse.matcher(self) | |
1465 |
|
1465 | |||
1466 | return dirstate.dirstate( |
|
1466 | return dirstate.dirstate( | |
1467 | self.vfs, self.ui, self.root, self._dirstatevalidate, sparsematchfn |
|
1467 | self.vfs, self.ui, self.root, self._dirstatevalidate, sparsematchfn | |
1468 | ) |
|
1468 | ) | |
1469 |
|
1469 | |||
1470 | def _dirstatevalidate(self, node): |
|
1470 | def _dirstatevalidate(self, node): | |
1471 | try: |
|
1471 | try: | |
1472 | self.changelog.rev(node) |
|
1472 | self.changelog.rev(node) | |
1473 | return node |
|
1473 | return node | |
1474 | except error.LookupError: |
|
1474 | except error.LookupError: | |
1475 | if not self._dirstatevalidatewarned: |
|
1475 | if not self._dirstatevalidatewarned: | |
1476 | self._dirstatevalidatewarned = True |
|
1476 | self._dirstatevalidatewarned = True | |
1477 | self.ui.warn( |
|
1477 | self.ui.warn( | |
1478 | _(b"warning: ignoring unknown working parent %s!\n") |
|
1478 | _(b"warning: ignoring unknown working parent %s!\n") | |
1479 | % short(node) |
|
1479 | % short(node) | |
1480 | ) |
|
1480 | ) | |
1481 | return nullid |
|
1481 | return nullid | |
1482 |
|
1482 | |||
1483 | @storecache(narrowspec.FILENAME) |
|
1483 | @storecache(narrowspec.FILENAME) | |
1484 | def narrowpats(self): |
|
1484 | def narrowpats(self): | |
1485 | """matcher patterns for this repository's narrowspec |
|
1485 | """matcher patterns for this repository's narrowspec | |
1486 |
|
1486 | |||
1487 | A tuple of (includes, excludes). |
|
1487 | A tuple of (includes, excludes). | |
1488 | """ |
|
1488 | """ | |
1489 | return narrowspec.load(self) |
|
1489 | return narrowspec.load(self) | |
1490 |
|
1490 | |||
1491 | @storecache(narrowspec.FILENAME) |
|
1491 | @storecache(narrowspec.FILENAME) | |
1492 | def _storenarrowmatch(self): |
|
1492 | def _storenarrowmatch(self): | |
1493 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1493 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1494 | return matchmod.always() |
|
1494 | return matchmod.always() | |
1495 | include, exclude = self.narrowpats |
|
1495 | include, exclude = self.narrowpats | |
1496 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1496 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1497 |
|
1497 | |||
1498 | @storecache(narrowspec.FILENAME) |
|
1498 | @storecache(narrowspec.FILENAME) | |
1499 | def _narrowmatch(self): |
|
1499 | def _narrowmatch(self): | |
1500 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1500 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1501 | return matchmod.always() |
|
1501 | return matchmod.always() | |
1502 | narrowspec.checkworkingcopynarrowspec(self) |
|
1502 | narrowspec.checkworkingcopynarrowspec(self) | |
1503 | include, exclude = self.narrowpats |
|
1503 | include, exclude = self.narrowpats | |
1504 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1504 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1505 |
|
1505 | |||
1506 | def narrowmatch(self, match=None, includeexact=False): |
|
1506 | def narrowmatch(self, match=None, includeexact=False): | |
1507 | """matcher corresponding the the repo's narrowspec |
|
1507 | """matcher corresponding the the repo's narrowspec | |
1508 |
|
1508 | |||
1509 | If `match` is given, then that will be intersected with the narrow |
|
1509 | If `match` is given, then that will be intersected with the narrow | |
1510 | matcher. |
|
1510 | matcher. | |
1511 |
|
1511 | |||
1512 | If `includeexact` is True, then any exact matches from `match` will |
|
1512 | If `includeexact` is True, then any exact matches from `match` will | |
1513 | be included even if they're outside the narrowspec. |
|
1513 | be included even if they're outside the narrowspec. | |
1514 | """ |
|
1514 | """ | |
1515 | if match: |
|
1515 | if match: | |
1516 | if includeexact and not self._narrowmatch.always(): |
|
1516 | if includeexact and not self._narrowmatch.always(): | |
1517 | # do not exclude explicitly-specified paths so that they can |
|
1517 | # do not exclude explicitly-specified paths so that they can | |
1518 | # be warned later on |
|
1518 | # be warned later on | |
1519 | em = matchmod.exact(match.files()) |
|
1519 | em = matchmod.exact(match.files()) | |
1520 | nm = matchmod.unionmatcher([self._narrowmatch, em]) |
|
1520 | nm = matchmod.unionmatcher([self._narrowmatch, em]) | |
1521 | return matchmod.intersectmatchers(match, nm) |
|
1521 | return matchmod.intersectmatchers(match, nm) | |
1522 | return matchmod.intersectmatchers(match, self._narrowmatch) |
|
1522 | return matchmod.intersectmatchers(match, self._narrowmatch) | |
1523 | return self._narrowmatch |
|
1523 | return self._narrowmatch | |
1524 |
|
1524 | |||
1525 | def setnarrowpats(self, newincludes, newexcludes): |
|
1525 | def setnarrowpats(self, newincludes, newexcludes): | |
1526 | narrowspec.save(self, newincludes, newexcludes) |
|
1526 | narrowspec.save(self, newincludes, newexcludes) | |
1527 | self.invalidate(clearfilecache=True) |
|
1527 | self.invalidate(clearfilecache=True) | |
1528 |
|
1528 | |||
1529 | @unfilteredpropertycache |
|
1529 | @unfilteredpropertycache | |
1530 | def _quick_access_changeid_null(self): |
|
1530 | def _quick_access_changeid_null(self): | |
1531 | return { |
|
1531 | return { | |
1532 | b'null': (nullrev, nullid), |
|
1532 | b'null': (nullrev, nullid), | |
1533 | nullrev: (nullrev, nullid), |
|
1533 | nullrev: (nullrev, nullid), | |
1534 | nullid: (nullrev, nullid), |
|
1534 | nullid: (nullrev, nullid), | |
1535 | } |
|
1535 | } | |
1536 |
|
1536 | |||
1537 | @unfilteredpropertycache |
|
1537 | @unfilteredpropertycache | |
1538 | def _quick_access_changeid_wc(self): |
|
1538 | def _quick_access_changeid_wc(self): | |
1539 | # also fast path access to the working copy parents |
|
1539 | # also fast path access to the working copy parents | |
1540 | # however, only do it for filter that ensure wc is visible. |
|
1540 | # however, only do it for filter that ensure wc is visible. | |
1541 | quick = {} |
|
1541 | quick = {} | |
1542 | cl = self.unfiltered().changelog |
|
1542 | cl = self.unfiltered().changelog | |
1543 | for node in self.dirstate.parents(): |
|
1543 | for node in self.dirstate.parents(): | |
1544 | if node == nullid: |
|
1544 | if node == nullid: | |
1545 | continue |
|
1545 | continue | |
1546 | rev = cl.index.get_rev(node) |
|
1546 | rev = cl.index.get_rev(node) | |
1547 | if rev is None: |
|
1547 | if rev is None: | |
1548 | # unknown working copy parent case: |
|
1548 | # unknown working copy parent case: | |
1549 | # |
|
1549 | # | |
1550 | # skip the fast path and let higher code deal with it |
|
1550 | # skip the fast path and let higher code deal with it | |
1551 | continue |
|
1551 | continue | |
1552 | pair = (rev, node) |
|
1552 | pair = (rev, node) | |
1553 | quick[rev] = pair |
|
1553 | quick[rev] = pair | |
1554 | quick[node] = pair |
|
1554 | quick[node] = pair | |
1555 | # also add the parents of the parents |
|
1555 | # also add the parents of the parents | |
1556 | for r in cl.parentrevs(rev): |
|
1556 | for r in cl.parentrevs(rev): | |
1557 | if r == nullrev: |
|
1557 | if r == nullrev: | |
1558 | continue |
|
1558 | continue | |
1559 | n = cl.node(r) |
|
1559 | n = cl.node(r) | |
1560 | pair = (r, n) |
|
1560 | pair = (r, n) | |
1561 | quick[r] = pair |
|
1561 | quick[r] = pair | |
1562 | quick[n] = pair |
|
1562 | quick[n] = pair | |
1563 | p1node = self.dirstate.p1() |
|
1563 | p1node = self.dirstate.p1() | |
1564 | if p1node != nullid: |
|
1564 | if p1node != nullid: | |
1565 | quick[b'.'] = quick[p1node] |
|
1565 | quick[b'.'] = quick[p1node] | |
1566 | return quick |
|
1566 | return quick | |
1567 |
|
1567 | |||
1568 | @unfilteredmethod |
|
1568 | @unfilteredmethod | |
1569 | def _quick_access_changeid_invalidate(self): |
|
1569 | def _quick_access_changeid_invalidate(self): | |
1570 | if '_quick_access_changeid_wc' in vars(self): |
|
1570 | if '_quick_access_changeid_wc' in vars(self): | |
1571 | del self.__dict__['_quick_access_changeid_wc'] |
|
1571 | del self.__dict__['_quick_access_changeid_wc'] | |
1572 |
|
1572 | |||
1573 | @property |
|
1573 | @property | |
1574 | def _quick_access_changeid(self): |
|
1574 | def _quick_access_changeid(self): | |
1575 | """an helper dictionnary for __getitem__ calls |
|
1575 | """an helper dictionnary for __getitem__ calls | |
1576 |
|
1576 | |||
1577 | This contains a list of symbol we can recognise right away without |
|
1577 | This contains a list of symbol we can recognise right away without | |
1578 | further processing. |
|
1578 | further processing. | |
1579 | """ |
|
1579 | """ | |
1580 | mapping = self._quick_access_changeid_null |
|
1580 | mapping = self._quick_access_changeid_null | |
1581 | if self.filtername in repoview.filter_has_wc: |
|
1581 | if self.filtername in repoview.filter_has_wc: | |
1582 | mapping = mapping.copy() |
|
1582 | mapping = mapping.copy() | |
1583 | mapping.update(self._quick_access_changeid_wc) |
|
1583 | mapping.update(self._quick_access_changeid_wc) | |
1584 | return mapping |
|
1584 | return mapping | |
1585 |
|
1585 | |||
1586 | def __getitem__(self, changeid): |
|
1586 | def __getitem__(self, changeid): | |
1587 | # dealing with special cases |
|
1587 | # dealing with special cases | |
1588 | if changeid is None: |
|
1588 | if changeid is None: | |
1589 | return context.workingctx(self) |
|
1589 | return context.workingctx(self) | |
1590 | if isinstance(changeid, context.basectx): |
|
1590 | if isinstance(changeid, context.basectx): | |
1591 | return changeid |
|
1591 | return changeid | |
1592 |
|
1592 | |||
1593 | # dealing with multiple revisions |
|
1593 | # dealing with multiple revisions | |
1594 | if isinstance(changeid, slice): |
|
1594 | if isinstance(changeid, slice): | |
1595 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
1595 | # wdirrev isn't contiguous so the slice shouldn't include it | |
1596 | return [ |
|
1596 | return [ | |
1597 | self[i] |
|
1597 | self[i] | |
1598 | for i in pycompat.xrange(*changeid.indices(len(self))) |
|
1598 | for i in pycompat.xrange(*changeid.indices(len(self))) | |
1599 | if i not in self.changelog.filteredrevs |
|
1599 | if i not in self.changelog.filteredrevs | |
1600 | ] |
|
1600 | ] | |
1601 |
|
1601 | |||
1602 | # dealing with some special values |
|
1602 | # dealing with some special values | |
1603 | quick_access = self._quick_access_changeid.get(changeid) |
|
1603 | quick_access = self._quick_access_changeid.get(changeid) | |
1604 | if quick_access is not None: |
|
1604 | if quick_access is not None: | |
1605 | rev, node = quick_access |
|
1605 | rev, node = quick_access | |
1606 | return context.changectx(self, rev, node, maybe_filtered=False) |
|
1606 | return context.changectx(self, rev, node, maybe_filtered=False) | |
1607 | if changeid == b'tip': |
|
1607 | if changeid == b'tip': | |
1608 | node = self.changelog.tip() |
|
1608 | node = self.changelog.tip() | |
1609 | rev = self.changelog.rev(node) |
|
1609 | rev = self.changelog.rev(node) | |
1610 | return context.changectx(self, rev, node) |
|
1610 | return context.changectx(self, rev, node) | |
1611 |
|
1611 | |||
1612 | # dealing with arbitrary values |
|
1612 | # dealing with arbitrary values | |
1613 | try: |
|
1613 | try: | |
1614 | if isinstance(changeid, int): |
|
1614 | if isinstance(changeid, int): | |
1615 | node = self.changelog.node(changeid) |
|
1615 | node = self.changelog.node(changeid) | |
1616 | rev = changeid |
|
1616 | rev = changeid | |
1617 | elif changeid == b'.': |
|
1617 | elif changeid == b'.': | |
1618 | # this is a hack to delay/avoid loading obsmarkers |
|
1618 | # this is a hack to delay/avoid loading obsmarkers | |
1619 | # when we know that '.' won't be hidden |
|
1619 | # when we know that '.' won't be hidden | |
1620 | node = self.dirstate.p1() |
|
1620 | node = self.dirstate.p1() | |
1621 | rev = self.unfiltered().changelog.rev(node) |
|
1621 | rev = self.unfiltered().changelog.rev(node) | |
1622 | elif len(changeid) == 20: |
|
1622 | elif len(changeid) == 20: | |
1623 | try: |
|
1623 | try: | |
1624 | node = changeid |
|
1624 | node = changeid | |
1625 | rev = self.changelog.rev(changeid) |
|
1625 | rev = self.changelog.rev(changeid) | |
1626 | except error.FilteredLookupError: |
|
1626 | except error.FilteredLookupError: | |
1627 | changeid = hex(changeid) # for the error message |
|
1627 | changeid = hex(changeid) # for the error message | |
1628 | raise |
|
1628 | raise | |
1629 | except LookupError: |
|
1629 | except LookupError: | |
1630 | # check if it might have come from damaged dirstate |
|
1630 | # check if it might have come from damaged dirstate | |
1631 | # |
|
1631 | # | |
1632 | # XXX we could avoid the unfiltered if we had a recognizable |
|
1632 | # XXX we could avoid the unfiltered if we had a recognizable | |
1633 | # exception for filtered changeset access |
|
1633 | # exception for filtered changeset access | |
1634 | if ( |
|
1634 | if ( | |
1635 | self.local() |
|
1635 | self.local() | |
1636 | and changeid in self.unfiltered().dirstate.parents() |
|
1636 | and changeid in self.unfiltered().dirstate.parents() | |
1637 | ): |
|
1637 | ): | |
1638 | msg = _(b"working directory has unknown parent '%s'!") |
|
1638 | msg = _(b"working directory has unknown parent '%s'!") | |
1639 | raise error.Abort(msg % short(changeid)) |
|
1639 | raise error.Abort(msg % short(changeid)) | |
1640 | changeid = hex(changeid) # for the error message |
|
1640 | changeid = hex(changeid) # for the error message | |
1641 | raise |
|
1641 | raise | |
1642 |
|
1642 | |||
1643 | elif len(changeid) == 40: |
|
1643 | elif len(changeid) == 40: | |
1644 | node = bin(changeid) |
|
1644 | node = bin(changeid) | |
1645 | rev = self.changelog.rev(node) |
|
1645 | rev = self.changelog.rev(node) | |
1646 | else: |
|
1646 | else: | |
1647 | raise error.ProgrammingError( |
|
1647 | raise error.ProgrammingError( | |
1648 | b"unsupported changeid '%s' of type %s" |
|
1648 | b"unsupported changeid '%s' of type %s" | |
1649 | % (changeid, pycompat.bytestr(type(changeid))) |
|
1649 | % (changeid, pycompat.bytestr(type(changeid))) | |
1650 | ) |
|
1650 | ) | |
1651 |
|
1651 | |||
1652 | return context.changectx(self, rev, node) |
|
1652 | return context.changectx(self, rev, node) | |
1653 |
|
1653 | |||
1654 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
1654 | except (error.FilteredIndexError, error.FilteredLookupError): | |
1655 | raise error.FilteredRepoLookupError( |
|
1655 | raise error.FilteredRepoLookupError( | |
1656 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) |
|
1656 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) | |
1657 | ) |
|
1657 | ) | |
1658 | except (IndexError, LookupError): |
|
1658 | except (IndexError, LookupError): | |
1659 | raise error.RepoLookupError( |
|
1659 | raise error.RepoLookupError( | |
1660 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) |
|
1660 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) | |
1661 | ) |
|
1661 | ) | |
1662 | except error.WdirUnsupported: |
|
1662 | except error.WdirUnsupported: | |
1663 | return context.workingctx(self) |
|
1663 | return context.workingctx(self) | |
1664 |
|
1664 | |||
1665 | def __contains__(self, changeid): |
|
1665 | def __contains__(self, changeid): | |
1666 | """True if the given changeid exists |
|
1666 | """True if the given changeid exists | |
1667 |
|
1667 | |||
1668 | error.AmbiguousPrefixLookupError is raised if an ambiguous node |
|
1668 | error.AmbiguousPrefixLookupError is raised if an ambiguous node | |
1669 | specified. |
|
1669 | specified. | |
1670 | """ |
|
1670 | """ | |
1671 | try: |
|
1671 | try: | |
1672 | self[changeid] |
|
1672 | self[changeid] | |
1673 | return True |
|
1673 | return True | |
1674 | except error.RepoLookupError: |
|
1674 | except error.RepoLookupError: | |
1675 | return False |
|
1675 | return False | |
1676 |
|
1676 | |||
1677 | def __nonzero__(self): |
|
1677 | def __nonzero__(self): | |
1678 | return True |
|
1678 | return True | |
1679 |
|
1679 | |||
1680 | __bool__ = __nonzero__ |
|
1680 | __bool__ = __nonzero__ | |
1681 |
|
1681 | |||
1682 | def __len__(self): |
|
1682 | def __len__(self): | |
1683 | # no need to pay the cost of repoview.changelog |
|
1683 | # no need to pay the cost of repoview.changelog | |
1684 | unfi = self.unfiltered() |
|
1684 | unfi = self.unfiltered() | |
1685 | return len(unfi.changelog) |
|
1685 | return len(unfi.changelog) | |
1686 |
|
1686 | |||
1687 | def __iter__(self): |
|
1687 | def __iter__(self): | |
1688 | return iter(self.changelog) |
|
1688 | return iter(self.changelog) | |
1689 |
|
1689 | |||
1690 | def revs(self, expr, *args): |
|
1690 | def revs(self, expr, *args): | |
1691 | '''Find revisions matching a revset. |
|
1691 | '''Find revisions matching a revset. | |
1692 |
|
1692 | |||
1693 | The revset is specified as a string ``expr`` that may contain |
|
1693 | The revset is specified as a string ``expr`` that may contain | |
1694 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
1694 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
1695 |
|
1695 | |||
1696 | Revset aliases from the configuration are not expanded. To expand |
|
1696 | Revset aliases from the configuration are not expanded. To expand | |
1697 | user aliases, consider calling ``scmutil.revrange()`` or |
|
1697 | user aliases, consider calling ``scmutil.revrange()`` or | |
1698 | ``repo.anyrevs([expr], user=True)``. |
|
1698 | ``repo.anyrevs([expr], user=True)``. | |
1699 |
|
1699 | |||
1700 | Returns a smartset.abstractsmartset, which is a list-like interface |
|
1700 | Returns a smartset.abstractsmartset, which is a list-like interface | |
1701 | that contains integer revisions. |
|
1701 | that contains integer revisions. | |
1702 | ''' |
|
1702 | ''' | |
1703 | tree = revsetlang.spectree(expr, *args) |
|
1703 | tree = revsetlang.spectree(expr, *args) | |
1704 | return revset.makematcher(tree)(self) |
|
1704 | return revset.makematcher(tree)(self) | |
1705 |
|
1705 | |||
1706 | def set(self, expr, *args): |
|
1706 | def set(self, expr, *args): | |
1707 | '''Find revisions matching a revset and emit changectx instances. |
|
1707 | '''Find revisions matching a revset and emit changectx instances. | |
1708 |
|
1708 | |||
1709 | This is a convenience wrapper around ``revs()`` that iterates the |
|
1709 | This is a convenience wrapper around ``revs()`` that iterates the | |
1710 | result and is a generator of changectx instances. |
|
1710 | result and is a generator of changectx instances. | |
1711 |
|
1711 | |||
1712 | Revset aliases from the configuration are not expanded. To expand |
|
1712 | Revset aliases from the configuration are not expanded. To expand | |
1713 | user aliases, consider calling ``scmutil.revrange()``. |
|
1713 | user aliases, consider calling ``scmutil.revrange()``. | |
1714 | ''' |
|
1714 | ''' | |
1715 | for r in self.revs(expr, *args): |
|
1715 | for r in self.revs(expr, *args): | |
1716 | yield self[r] |
|
1716 | yield self[r] | |
1717 |
|
1717 | |||
1718 | def anyrevs(self, specs, user=False, localalias=None): |
|
1718 | def anyrevs(self, specs, user=False, localalias=None): | |
1719 | '''Find revisions matching one of the given revsets. |
|
1719 | '''Find revisions matching one of the given revsets. | |
1720 |
|
1720 | |||
1721 | Revset aliases from the configuration are not expanded by default. To |
|
1721 | Revset aliases from the configuration are not expanded by default. To | |
1722 | expand user aliases, specify ``user=True``. To provide some local |
|
1722 | expand user aliases, specify ``user=True``. To provide some local | |
1723 | definitions overriding user aliases, set ``localalias`` to |
|
1723 | definitions overriding user aliases, set ``localalias`` to | |
1724 | ``{name: definitionstring}``. |
|
1724 | ``{name: definitionstring}``. | |
1725 | ''' |
|
1725 | ''' | |
1726 | if specs == [b'null']: |
|
1726 | if specs == [b'null']: | |
1727 | return revset.baseset([nullrev]) |
|
1727 | return revset.baseset([nullrev]) | |
1728 | if specs == [b'.']: |
|
1728 | if specs == [b'.']: | |
1729 | quick_data = self._quick_access_changeid.get(b'.') |
|
1729 | quick_data = self._quick_access_changeid.get(b'.') | |
1730 | if quick_data is not None: |
|
1730 | if quick_data is not None: | |
1731 | return revset.baseset([quick_data[0]]) |
|
1731 | return revset.baseset([quick_data[0]]) | |
1732 | if user: |
|
1732 | if user: | |
1733 | m = revset.matchany( |
|
1733 | m = revset.matchany( | |
1734 | self.ui, |
|
1734 | self.ui, | |
1735 | specs, |
|
1735 | specs, | |
1736 | lookup=revset.lookupfn(self), |
|
1736 | lookup=revset.lookupfn(self), | |
1737 | localalias=localalias, |
|
1737 | localalias=localalias, | |
1738 | ) |
|
1738 | ) | |
1739 | else: |
|
1739 | else: | |
1740 | m = revset.matchany(None, specs, localalias=localalias) |
|
1740 | m = revset.matchany(None, specs, localalias=localalias) | |
1741 | return m(self) |
|
1741 | return m(self) | |
1742 |
|
1742 | |||
1743 | def url(self): |
|
1743 | def url(self): | |
1744 | return b'file:' + self.root |
|
1744 | return b'file:' + self.root | |
1745 |
|
1745 | |||
1746 | def hook(self, name, throw=False, **args): |
|
1746 | def hook(self, name, throw=False, **args): | |
1747 | """Call a hook, passing this repo instance. |
|
1747 | """Call a hook, passing this repo instance. | |
1748 |
|
1748 | |||
1749 | This a convenience method to aid invoking hooks. Extensions likely |
|
1749 | This a convenience method to aid invoking hooks. Extensions likely | |
1750 | won't call this unless they have registered a custom hook or are |
|
1750 | won't call this unless they have registered a custom hook or are | |
1751 | replacing code that is expected to call a hook. |
|
1751 | replacing code that is expected to call a hook. | |
1752 | """ |
|
1752 | """ | |
1753 | return hook.hook(self.ui, self, name, throw, **args) |
|
1753 | return hook.hook(self.ui, self, name, throw, **args) | |
1754 |
|
1754 | |||
1755 | @filteredpropertycache |
|
1755 | @filteredpropertycache | |
1756 | def _tagscache(self): |
|
1756 | def _tagscache(self): | |
1757 | '''Returns a tagscache object that contains various tags related |
|
1757 | '''Returns a tagscache object that contains various tags related | |
1758 | caches.''' |
|
1758 | caches.''' | |
1759 |
|
1759 | |||
1760 | # This simplifies its cache management by having one decorated |
|
1760 | # This simplifies its cache management by having one decorated | |
1761 | # function (this one) and the rest simply fetch things from it. |
|
1761 | # function (this one) and the rest simply fetch things from it. | |
1762 | class tagscache(object): |
|
1762 | class tagscache(object): | |
1763 | def __init__(self): |
|
1763 | def __init__(self): | |
1764 | # These two define the set of tags for this repository. tags |
|
1764 | # These two define the set of tags for this repository. tags | |
1765 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
1765 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
1766 | # 'local'. (Global tags are defined by .hgtags across all |
|
1766 | # 'local'. (Global tags are defined by .hgtags across all | |
1767 | # heads, and local tags are defined in .hg/localtags.) |
|
1767 | # heads, and local tags are defined in .hg/localtags.) | |
1768 | # They constitute the in-memory cache of tags. |
|
1768 | # They constitute the in-memory cache of tags. | |
1769 | self.tags = self.tagtypes = None |
|
1769 | self.tags = self.tagtypes = None | |
1770 |
|
1770 | |||
1771 | self.nodetagscache = self.tagslist = None |
|
1771 | self.nodetagscache = self.tagslist = None | |
1772 |
|
1772 | |||
1773 | cache = tagscache() |
|
1773 | cache = tagscache() | |
1774 | cache.tags, cache.tagtypes = self._findtags() |
|
1774 | cache.tags, cache.tagtypes = self._findtags() | |
1775 |
|
1775 | |||
1776 | return cache |
|
1776 | return cache | |
1777 |
|
1777 | |||
1778 | def tags(self): |
|
1778 | def tags(self): | |
1779 | '''return a mapping of tag to node''' |
|
1779 | '''return a mapping of tag to node''' | |
1780 | t = {} |
|
1780 | t = {} | |
1781 | if self.changelog.filteredrevs: |
|
1781 | if self.changelog.filteredrevs: | |
1782 | tags, tt = self._findtags() |
|
1782 | tags, tt = self._findtags() | |
1783 | else: |
|
1783 | else: | |
1784 | tags = self._tagscache.tags |
|
1784 | tags = self._tagscache.tags | |
1785 | rev = self.changelog.rev |
|
1785 | rev = self.changelog.rev | |
1786 | for k, v in pycompat.iteritems(tags): |
|
1786 | for k, v in pycompat.iteritems(tags): | |
1787 | try: |
|
1787 | try: | |
1788 | # ignore tags to unknown nodes |
|
1788 | # ignore tags to unknown nodes | |
1789 | rev(v) |
|
1789 | rev(v) | |
1790 | t[k] = v |
|
1790 | t[k] = v | |
1791 | except (error.LookupError, ValueError): |
|
1791 | except (error.LookupError, ValueError): | |
1792 | pass |
|
1792 | pass | |
1793 | return t |
|
1793 | return t | |
1794 |
|
1794 | |||
1795 | def _findtags(self): |
|
1795 | def _findtags(self): | |
1796 | '''Do the hard work of finding tags. Return a pair of dicts |
|
1796 | '''Do the hard work of finding tags. Return a pair of dicts | |
1797 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
1797 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
1798 | maps tag name to a string like \'global\' or \'local\'. |
|
1798 | maps tag name to a string like \'global\' or \'local\'. | |
1799 | Subclasses or extensions are free to add their own tags, but |
|
1799 | Subclasses or extensions are free to add their own tags, but | |
1800 | should be aware that the returned dicts will be retained for the |
|
1800 | should be aware that the returned dicts will be retained for the | |
1801 | duration of the localrepo object.''' |
|
1801 | duration of the localrepo object.''' | |
1802 |
|
1802 | |||
1803 | # XXX what tagtype should subclasses/extensions use? Currently |
|
1803 | # XXX what tagtype should subclasses/extensions use? Currently | |
1804 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
1804 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
1805 | # Should each extension invent its own tag type? Should there |
|
1805 | # Should each extension invent its own tag type? Should there | |
1806 | # be one tagtype for all such "virtual" tags? Or is the status |
|
1806 | # be one tagtype for all such "virtual" tags? Or is the status | |
1807 | # quo fine? |
|
1807 | # quo fine? | |
1808 |
|
1808 | |||
1809 | # map tag name to (node, hist) |
|
1809 | # map tag name to (node, hist) | |
1810 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
1810 | alltags = tagsmod.findglobaltags(self.ui, self) | |
1811 | # map tag name to tag type |
|
1811 | # map tag name to tag type | |
1812 | tagtypes = dict((tag, b'global') for tag in alltags) |
|
1812 | tagtypes = dict((tag, b'global') for tag in alltags) | |
1813 |
|
1813 | |||
1814 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
1814 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
1815 |
|
1815 | |||
1816 | # Build the return dicts. Have to re-encode tag names because |
|
1816 | # Build the return dicts. Have to re-encode tag names because | |
1817 | # the tags module always uses UTF-8 (in order not to lose info |
|
1817 | # the tags module always uses UTF-8 (in order not to lose info | |
1818 | # writing to the cache), but the rest of Mercurial wants them in |
|
1818 | # writing to the cache), but the rest of Mercurial wants them in | |
1819 | # local encoding. |
|
1819 | # local encoding. | |
1820 | tags = {} |
|
1820 | tags = {} | |
1821 | for (name, (node, hist)) in pycompat.iteritems(alltags): |
|
1821 | for (name, (node, hist)) in pycompat.iteritems(alltags): | |
1822 | if node != nullid: |
|
1822 | if node != nullid: | |
1823 | tags[encoding.tolocal(name)] = node |
|
1823 | tags[encoding.tolocal(name)] = node | |
1824 | tags[b'tip'] = self.changelog.tip() |
|
1824 | tags[b'tip'] = self.changelog.tip() | |
1825 | tagtypes = dict( |
|
1825 | tagtypes = dict( | |
1826 | [ |
|
1826 | [ | |
1827 | (encoding.tolocal(name), value) |
|
1827 | (encoding.tolocal(name), value) | |
1828 | for (name, value) in pycompat.iteritems(tagtypes) |
|
1828 | for (name, value) in pycompat.iteritems(tagtypes) | |
1829 | ] |
|
1829 | ] | |
1830 | ) |
|
1830 | ) | |
1831 | return (tags, tagtypes) |
|
1831 | return (tags, tagtypes) | |
1832 |
|
1832 | |||
1833 | def tagtype(self, tagname): |
|
1833 | def tagtype(self, tagname): | |
1834 | ''' |
|
1834 | ''' | |
1835 | return the type of the given tag. result can be: |
|
1835 | return the type of the given tag. result can be: | |
1836 |
|
1836 | |||
1837 | 'local' : a local tag |
|
1837 | 'local' : a local tag | |
1838 | 'global' : a global tag |
|
1838 | 'global' : a global tag | |
1839 | None : tag does not exist |
|
1839 | None : tag does not exist | |
1840 | ''' |
|
1840 | ''' | |
1841 |
|
1841 | |||
1842 | return self._tagscache.tagtypes.get(tagname) |
|
1842 | return self._tagscache.tagtypes.get(tagname) | |
1843 |
|
1843 | |||
1844 | def tagslist(self): |
|
1844 | def tagslist(self): | |
1845 | '''return a list of tags ordered by revision''' |
|
1845 | '''return a list of tags ordered by revision''' | |
1846 | if not self._tagscache.tagslist: |
|
1846 | if not self._tagscache.tagslist: | |
1847 | l = [] |
|
1847 | l = [] | |
1848 | for t, n in pycompat.iteritems(self.tags()): |
|
1848 | for t, n in pycompat.iteritems(self.tags()): | |
1849 | l.append((self.changelog.rev(n), t, n)) |
|
1849 | l.append((self.changelog.rev(n), t, n)) | |
1850 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
1850 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
1851 |
|
1851 | |||
1852 | return self._tagscache.tagslist |
|
1852 | return self._tagscache.tagslist | |
1853 |
|
1853 | |||
1854 | def nodetags(self, node): |
|
1854 | def nodetags(self, node): | |
1855 | '''return the tags associated with a node''' |
|
1855 | '''return the tags associated with a node''' | |
1856 | if not self._tagscache.nodetagscache: |
|
1856 | if not self._tagscache.nodetagscache: | |
1857 | nodetagscache = {} |
|
1857 | nodetagscache = {} | |
1858 | for t, n in pycompat.iteritems(self._tagscache.tags): |
|
1858 | for t, n in pycompat.iteritems(self._tagscache.tags): | |
1859 | nodetagscache.setdefault(n, []).append(t) |
|
1859 | nodetagscache.setdefault(n, []).append(t) | |
1860 | for tags in pycompat.itervalues(nodetagscache): |
|
1860 | for tags in pycompat.itervalues(nodetagscache): | |
1861 | tags.sort() |
|
1861 | tags.sort() | |
1862 | self._tagscache.nodetagscache = nodetagscache |
|
1862 | self._tagscache.nodetagscache = nodetagscache | |
1863 | return self._tagscache.nodetagscache.get(node, []) |
|
1863 | return self._tagscache.nodetagscache.get(node, []) | |
1864 |
|
1864 | |||
1865 | def nodebookmarks(self, node): |
|
1865 | def nodebookmarks(self, node): | |
1866 | """return the list of bookmarks pointing to the specified node""" |
|
1866 | """return the list of bookmarks pointing to the specified node""" | |
1867 | return self._bookmarks.names(node) |
|
1867 | return self._bookmarks.names(node) | |
1868 |
|
1868 | |||
1869 | def branchmap(self): |
|
1869 | def branchmap(self): | |
1870 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
1870 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
1871 | ordered by increasing revision number''' |
|
1871 | ordered by increasing revision number''' | |
1872 | return self._branchcaches[self] |
|
1872 | return self._branchcaches[self] | |
1873 |
|
1873 | |||
1874 | @unfilteredmethod |
|
1874 | @unfilteredmethod | |
1875 | def revbranchcache(self): |
|
1875 | def revbranchcache(self): | |
1876 | if not self._revbranchcache: |
|
1876 | if not self._revbranchcache: | |
1877 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
1877 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
1878 | return self._revbranchcache |
|
1878 | return self._revbranchcache | |
1879 |
|
1879 | |||
1880 | def branchtip(self, branch, ignoremissing=False): |
|
1880 | def branchtip(self, branch, ignoremissing=False): | |
1881 | '''return the tip node for a given branch |
|
1881 | '''return the tip node for a given branch | |
1882 |
|
1882 | |||
1883 | If ignoremissing is True, then this method will not raise an error. |
|
1883 | If ignoremissing is True, then this method will not raise an error. | |
1884 | This is helpful for callers that only expect None for a missing branch |
|
1884 | This is helpful for callers that only expect None for a missing branch | |
1885 | (e.g. namespace). |
|
1885 | (e.g. namespace). | |
1886 |
|
1886 | |||
1887 | ''' |
|
1887 | ''' | |
1888 | try: |
|
1888 | try: | |
1889 | return self.branchmap().branchtip(branch) |
|
1889 | return self.branchmap().branchtip(branch) | |
1890 | except KeyError: |
|
1890 | except KeyError: | |
1891 | if not ignoremissing: |
|
1891 | if not ignoremissing: | |
1892 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) |
|
1892 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) | |
1893 | else: |
|
1893 | else: | |
1894 | pass |
|
1894 | pass | |
1895 |
|
1895 | |||
1896 | def lookup(self, key): |
|
1896 | def lookup(self, key): | |
1897 | node = scmutil.revsymbol(self, key).node() |
|
1897 | node = scmutil.revsymbol(self, key).node() | |
1898 | if node is None: |
|
1898 | if node is None: | |
1899 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) |
|
1899 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) | |
1900 | return node |
|
1900 | return node | |
1901 |
|
1901 | |||
1902 | def lookupbranch(self, key): |
|
1902 | def lookupbranch(self, key): | |
1903 | if self.branchmap().hasbranch(key): |
|
1903 | if self.branchmap().hasbranch(key): | |
1904 | return key |
|
1904 | return key | |
1905 |
|
1905 | |||
1906 | return scmutil.revsymbol(self, key).branch() |
|
1906 | return scmutil.revsymbol(self, key).branch() | |
1907 |
|
1907 | |||
1908 | def known(self, nodes): |
|
1908 | def known(self, nodes): | |
1909 | cl = self.changelog |
|
1909 | cl = self.changelog | |
1910 | get_rev = cl.index.get_rev |
|
1910 | get_rev = cl.index.get_rev | |
1911 | filtered = cl.filteredrevs |
|
1911 | filtered = cl.filteredrevs | |
1912 | result = [] |
|
1912 | result = [] | |
1913 | for n in nodes: |
|
1913 | for n in nodes: | |
1914 | r = get_rev(n) |
|
1914 | r = get_rev(n) | |
1915 | resp = not (r is None or r in filtered) |
|
1915 | resp = not (r is None or r in filtered) | |
1916 | result.append(resp) |
|
1916 | result.append(resp) | |
1917 | return result |
|
1917 | return result | |
1918 |
|
1918 | |||
1919 | def local(self): |
|
1919 | def local(self): | |
1920 | return self |
|
1920 | return self | |
1921 |
|
1921 | |||
1922 | def publishing(self): |
|
1922 | def publishing(self): | |
1923 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1923 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1924 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1924 | # so that we don't finalize changes shared between users via ssh or nfs | |
1925 | return self.ui.configbool(b'phases', b'publish', untrusted=True) |
|
1925 | return self.ui.configbool(b'phases', b'publish', untrusted=True) | |
1926 |
|
1926 | |||
1927 | def cancopy(self): |
|
1927 | def cancopy(self): | |
1928 | # so statichttprepo's override of local() works |
|
1928 | # so statichttprepo's override of local() works | |
1929 | if not self.local(): |
|
1929 | if not self.local(): | |
1930 | return False |
|
1930 | return False | |
1931 | if not self.publishing(): |
|
1931 | if not self.publishing(): | |
1932 | return True |
|
1932 | return True | |
1933 | # if publishing we can't copy if there is filtered content |
|
1933 | # if publishing we can't copy if there is filtered content | |
1934 | return not self.filtered(b'visible').changelog.filteredrevs |
|
1934 | return not self.filtered(b'visible').changelog.filteredrevs | |
1935 |
|
1935 | |||
1936 | def shared(self): |
|
1936 | def shared(self): | |
1937 | '''the type of shared repository (None if not shared)''' |
|
1937 | '''the type of shared repository (None if not shared)''' | |
1938 | if self.sharedpath != self.path: |
|
1938 | if self.sharedpath != self.path: | |
1939 | return b'store' |
|
1939 | return b'store' | |
1940 | return None |
|
1940 | return None | |
1941 |
|
1941 | |||
1942 | def wjoin(self, f, *insidef): |
|
1942 | def wjoin(self, f, *insidef): | |
1943 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1943 | return self.vfs.reljoin(self.root, f, *insidef) | |
1944 |
|
1944 | |||
1945 | def setparents(self, p1, p2=nullid): |
|
1945 | def setparents(self, p1, p2=nullid): | |
1946 | self[None].setparents(p1, p2) |
|
1946 | self[None].setparents(p1, p2) | |
1947 | self._quick_access_changeid_invalidate() |
|
1947 | self._quick_access_changeid_invalidate() | |
1948 |
|
1948 | |||
1949 | def filectx(self, path, changeid=None, fileid=None, changectx=None): |
|
1949 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
1950 | """changeid must be a changeset revision, if specified. |
|
1950 | """changeid must be a changeset revision, if specified. | |
1951 | fileid can be a file revision or node.""" |
|
1951 | fileid can be a file revision or node.""" | |
1952 | return context.filectx( |
|
1952 | return context.filectx( | |
1953 | self, path, changeid, fileid, changectx=changectx |
|
1953 | self, path, changeid, fileid, changectx=changectx | |
1954 | ) |
|
1954 | ) | |
1955 |
|
1955 | |||
1956 | def getcwd(self): |
|
1956 | def getcwd(self): | |
1957 | return self.dirstate.getcwd() |
|
1957 | return self.dirstate.getcwd() | |
1958 |
|
1958 | |||
1959 | def pathto(self, f, cwd=None): |
|
1959 | def pathto(self, f, cwd=None): | |
1960 | return self.dirstate.pathto(f, cwd) |
|
1960 | return self.dirstate.pathto(f, cwd) | |
1961 |
|
1961 | |||
1962 | def _loadfilter(self, filter): |
|
1962 | def _loadfilter(self, filter): | |
1963 | if filter not in self._filterpats: |
|
1963 | if filter not in self._filterpats: | |
1964 | l = [] |
|
1964 | l = [] | |
1965 | for pat, cmd in self.ui.configitems(filter): |
|
1965 | for pat, cmd in self.ui.configitems(filter): | |
1966 | if cmd == b'!': |
|
1966 | if cmd == b'!': | |
1967 | continue |
|
1967 | continue | |
1968 | mf = matchmod.match(self.root, b'', [pat]) |
|
1968 | mf = matchmod.match(self.root, b'', [pat]) | |
1969 | fn = None |
|
1969 | fn = None | |
1970 | params = cmd |
|
1970 | params = cmd | |
1971 | for name, filterfn in pycompat.iteritems(self._datafilters): |
|
1971 | for name, filterfn in pycompat.iteritems(self._datafilters): | |
1972 | if cmd.startswith(name): |
|
1972 | if cmd.startswith(name): | |
1973 | fn = filterfn |
|
1973 | fn = filterfn | |
1974 | params = cmd[len(name) :].lstrip() |
|
1974 | params = cmd[len(name) :].lstrip() | |
1975 | break |
|
1975 | break | |
1976 | if not fn: |
|
1976 | if not fn: | |
1977 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1977 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1978 | fn.__name__ = 'commandfilter' |
|
1978 | fn.__name__ = 'commandfilter' | |
1979 | # Wrap old filters not supporting keyword arguments |
|
1979 | # Wrap old filters not supporting keyword arguments | |
1980 | if not pycompat.getargspec(fn)[2]: |
|
1980 | if not pycompat.getargspec(fn)[2]: | |
1981 | oldfn = fn |
|
1981 | oldfn = fn | |
1982 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) |
|
1982 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) | |
1983 | fn.__name__ = 'compat-' + oldfn.__name__ |
|
1983 | fn.__name__ = 'compat-' + oldfn.__name__ | |
1984 | l.append((mf, fn, params)) |
|
1984 | l.append((mf, fn, params)) | |
1985 | self._filterpats[filter] = l |
|
1985 | self._filterpats[filter] = l | |
1986 | return self._filterpats[filter] |
|
1986 | return self._filterpats[filter] | |
1987 |
|
1987 | |||
1988 | def _filter(self, filterpats, filename, data): |
|
1988 | def _filter(self, filterpats, filename, data): | |
1989 | for mf, fn, cmd in filterpats: |
|
1989 | for mf, fn, cmd in filterpats: | |
1990 | if mf(filename): |
|
1990 | if mf(filename): | |
1991 | self.ui.debug( |
|
1991 | self.ui.debug( | |
1992 | b"filtering %s through %s\n" |
|
1992 | b"filtering %s through %s\n" | |
1993 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) |
|
1993 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) | |
1994 | ) |
|
1994 | ) | |
1995 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1995 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1996 | break |
|
1996 | break | |
1997 |
|
1997 | |||
1998 | return data |
|
1998 | return data | |
1999 |
|
1999 | |||
2000 | @unfilteredpropertycache |
|
2000 | @unfilteredpropertycache | |
2001 | def _encodefilterpats(self): |
|
2001 | def _encodefilterpats(self): | |
2002 | return self._loadfilter(b'encode') |
|
2002 | return self._loadfilter(b'encode') | |
2003 |
|
2003 | |||
2004 | @unfilteredpropertycache |
|
2004 | @unfilteredpropertycache | |
2005 | def _decodefilterpats(self): |
|
2005 | def _decodefilterpats(self): | |
2006 | return self._loadfilter(b'decode') |
|
2006 | return self._loadfilter(b'decode') | |
2007 |
|
2007 | |||
2008 | def adddatafilter(self, name, filter): |
|
2008 | def adddatafilter(self, name, filter): | |
2009 | self._datafilters[name] = filter |
|
2009 | self._datafilters[name] = filter | |
2010 |
|
2010 | |||
2011 | def wread(self, filename): |
|
2011 | def wread(self, filename): | |
2012 | if self.wvfs.islink(filename): |
|
2012 | if self.wvfs.islink(filename): | |
2013 | data = self.wvfs.readlink(filename) |
|
2013 | data = self.wvfs.readlink(filename) | |
2014 | else: |
|
2014 | else: | |
2015 | data = self.wvfs.read(filename) |
|
2015 | data = self.wvfs.read(filename) | |
2016 | return self._filter(self._encodefilterpats, filename, data) |
|
2016 | return self._filter(self._encodefilterpats, filename, data) | |
2017 |
|
2017 | |||
2018 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
2018 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
2019 | """write ``data`` into ``filename`` in the working directory |
|
2019 | """write ``data`` into ``filename`` in the working directory | |
2020 |
|
2020 | |||
2021 | This returns length of written (maybe decoded) data. |
|
2021 | This returns length of written (maybe decoded) data. | |
2022 | """ |
|
2022 | """ | |
2023 | data = self._filter(self._decodefilterpats, filename, data) |
|
2023 | data = self._filter(self._decodefilterpats, filename, data) | |
2024 | if b'l' in flags: |
|
2024 | if b'l' in flags: | |
2025 | self.wvfs.symlink(data, filename) |
|
2025 | self.wvfs.symlink(data, filename) | |
2026 | else: |
|
2026 | else: | |
2027 | self.wvfs.write( |
|
2027 | self.wvfs.write( | |
2028 | filename, data, backgroundclose=backgroundclose, **kwargs |
|
2028 | filename, data, backgroundclose=backgroundclose, **kwargs | |
2029 | ) |
|
2029 | ) | |
2030 | if b'x' in flags: |
|
2030 | if b'x' in flags: | |
2031 | self.wvfs.setflags(filename, False, True) |
|
2031 | self.wvfs.setflags(filename, False, True) | |
2032 | else: |
|
2032 | else: | |
2033 | self.wvfs.setflags(filename, False, False) |
|
2033 | self.wvfs.setflags(filename, False, False) | |
2034 | return len(data) |
|
2034 | return len(data) | |
2035 |
|
2035 | |||
2036 | def wwritedata(self, filename, data): |
|
2036 | def wwritedata(self, filename, data): | |
2037 | return self._filter(self._decodefilterpats, filename, data) |
|
2037 | return self._filter(self._decodefilterpats, filename, data) | |
2038 |
|
2038 | |||
2039 | def currenttransaction(self): |
|
2039 | def currenttransaction(self): | |
2040 | """return the current transaction or None if non exists""" |
|
2040 | """return the current transaction or None if non exists""" | |
2041 | if self._transref: |
|
2041 | if self._transref: | |
2042 | tr = self._transref() |
|
2042 | tr = self._transref() | |
2043 | else: |
|
2043 | else: | |
2044 | tr = None |
|
2044 | tr = None | |
2045 |
|
2045 | |||
2046 | if tr and tr.running(): |
|
2046 | if tr and tr.running(): | |
2047 | return tr |
|
2047 | return tr | |
2048 | return None |
|
2048 | return None | |
2049 |
|
2049 | |||
2050 | def transaction(self, desc, report=None): |
|
2050 | def transaction(self, desc, report=None): | |
2051 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
2051 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
2052 | b'devel', b'check-locks' |
|
2052 | b'devel', b'check-locks' | |
2053 | ): |
|
2053 | ): | |
2054 | if self._currentlock(self._lockref) is None: |
|
2054 | if self._currentlock(self._lockref) is None: | |
2055 | raise error.ProgrammingError(b'transaction requires locking') |
|
2055 | raise error.ProgrammingError(b'transaction requires locking') | |
2056 | tr = self.currenttransaction() |
|
2056 | tr = self.currenttransaction() | |
2057 | if tr is not None: |
|
2057 | if tr is not None: | |
2058 | return tr.nest(name=desc) |
|
2058 | return tr.nest(name=desc) | |
2059 |
|
2059 | |||
2060 | # abort here if the journal already exists |
|
2060 | # abort here if the journal already exists | |
2061 | if self.svfs.exists(b"journal"): |
|
2061 | if self.svfs.exists(b"journal"): | |
2062 | raise error.RepoError( |
|
2062 | raise error.RepoError( | |
2063 | _(b"abandoned transaction found"), |
|
2063 | _(b"abandoned transaction found"), | |
2064 | hint=_(b"run 'hg recover' to clean up transaction"), |
|
2064 | hint=_(b"run 'hg recover' to clean up transaction"), | |
2065 | ) |
|
2065 | ) | |
2066 |
|
2066 | |||
2067 | idbase = b"%.40f#%f" % (random.random(), time.time()) |
|
2067 | idbase = b"%.40f#%f" % (random.random(), time.time()) | |
2068 | ha = hex(hashutil.sha1(idbase).digest()) |
|
2068 | ha = hex(hashutil.sha1(idbase).digest()) | |
2069 | txnid = b'TXN:' + ha |
|
2069 | txnid = b'TXN:' + ha | |
2070 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
2070 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
2071 |
|
2071 | |||
2072 | self._writejournal(desc) |
|
2072 | self._writejournal(desc) | |
2073 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
2073 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
2074 | if report: |
|
2074 | if report: | |
2075 | rp = report |
|
2075 | rp = report | |
2076 | else: |
|
2076 | else: | |
2077 | rp = self.ui.warn |
|
2077 | rp = self.ui.warn | |
2078 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ |
|
2078 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ | |
2079 | # we must avoid cyclic reference between repo and transaction. |
|
2079 | # we must avoid cyclic reference between repo and transaction. | |
2080 | reporef = weakref.ref(self) |
|
2080 | reporef = weakref.ref(self) | |
2081 | # Code to track tag movement |
|
2081 | # Code to track tag movement | |
2082 | # |
|
2082 | # | |
2083 | # Since tags are all handled as file content, it is actually quite hard |
|
2083 | # Since tags are all handled as file content, it is actually quite hard | |
2084 | # to track these movement from a code perspective. So we fallback to a |
|
2084 | # to track these movement from a code perspective. So we fallback to a | |
2085 | # tracking at the repository level. One could envision to track changes |
|
2085 | # tracking at the repository level. One could envision to track changes | |
2086 | # to the '.hgtags' file through changegroup apply but that fails to |
|
2086 | # to the '.hgtags' file through changegroup apply but that fails to | |
2087 | # cope with case where transaction expose new heads without changegroup |
|
2087 | # cope with case where transaction expose new heads without changegroup | |
2088 | # being involved (eg: phase movement). |
|
2088 | # being involved (eg: phase movement). | |
2089 | # |
|
2089 | # | |
2090 | # For now, We gate the feature behind a flag since this likely comes |
|
2090 | # For now, We gate the feature behind a flag since this likely comes | |
2091 | # with performance impacts. The current code run more often than needed |
|
2091 | # with performance impacts. The current code run more often than needed | |
2092 | # and do not use caches as much as it could. The current focus is on |
|
2092 | # and do not use caches as much as it could. The current focus is on | |
2093 | # the behavior of the feature so we disable it by default. The flag |
|
2093 | # the behavior of the feature so we disable it by default. The flag | |
2094 | # will be removed when we are happy with the performance impact. |
|
2094 | # will be removed when we are happy with the performance impact. | |
2095 | # |
|
2095 | # | |
2096 | # Once this feature is no longer experimental move the following |
|
2096 | # Once this feature is no longer experimental move the following | |
2097 | # documentation to the appropriate help section: |
|
2097 | # documentation to the appropriate help section: | |
2098 | # |
|
2098 | # | |
2099 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
2099 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
2100 | # tags (new or changed or deleted tags). In addition the details of |
|
2100 | # tags (new or changed or deleted tags). In addition the details of | |
2101 | # these changes are made available in a file at: |
|
2101 | # these changes are made available in a file at: | |
2102 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
2102 | # ``REPOROOT/.hg/changes/tags.changes``. | |
2103 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
2103 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
2104 | # might exist from a previous transaction even if no tag were touched |
|
2104 | # might exist from a previous transaction even if no tag were touched | |
2105 | # in this one. Changes are recorded in a line base format:: |
|
2105 | # in this one. Changes are recorded in a line base format:: | |
2106 | # |
|
2106 | # | |
2107 | # <action> <hex-node> <tag-name>\n |
|
2107 | # <action> <hex-node> <tag-name>\n | |
2108 | # |
|
2108 | # | |
2109 | # Actions are defined as follow: |
|
2109 | # Actions are defined as follow: | |
2110 | # "-R": tag is removed, |
|
2110 | # "-R": tag is removed, | |
2111 | # "+A": tag is added, |
|
2111 | # "+A": tag is added, | |
2112 | # "-M": tag is moved (old value), |
|
2112 | # "-M": tag is moved (old value), | |
2113 | # "+M": tag is moved (new value), |
|
2113 | # "+M": tag is moved (new value), | |
2114 | tracktags = lambda x: None |
|
2114 | tracktags = lambda x: None | |
2115 | # experimental config: experimental.hook-track-tags |
|
2115 | # experimental config: experimental.hook-track-tags | |
2116 | shouldtracktags = self.ui.configbool( |
|
2116 | shouldtracktags = self.ui.configbool( | |
2117 | b'experimental', b'hook-track-tags' |
|
2117 | b'experimental', b'hook-track-tags' | |
2118 | ) |
|
2118 | ) | |
2119 | if desc != b'strip' and shouldtracktags: |
|
2119 | if desc != b'strip' and shouldtracktags: | |
2120 | oldheads = self.changelog.headrevs() |
|
2120 | oldheads = self.changelog.headrevs() | |
2121 |
|
2121 | |||
2122 | def tracktags(tr2): |
|
2122 | def tracktags(tr2): | |
2123 | repo = reporef() |
|
2123 | repo = reporef() | |
2124 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
2124 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
2125 | newheads = repo.changelog.headrevs() |
|
2125 | newheads = repo.changelog.headrevs() | |
2126 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
2126 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
2127 | # notes: we compare lists here. |
|
2127 | # notes: we compare lists here. | |
2128 | # As we do it only once buiding set would not be cheaper |
|
2128 | # As we do it only once buiding set would not be cheaper | |
2129 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
2129 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
2130 | if changes: |
|
2130 | if changes: | |
2131 | tr2.hookargs[b'tag_moved'] = b'1' |
|
2131 | tr2.hookargs[b'tag_moved'] = b'1' | |
2132 | with repo.vfs( |
|
2132 | with repo.vfs( | |
2133 | b'changes/tags.changes', b'w', atomictemp=True |
|
2133 | b'changes/tags.changes', b'w', atomictemp=True | |
2134 | ) as changesfile: |
|
2134 | ) as changesfile: | |
2135 | # note: we do not register the file to the transaction |
|
2135 | # note: we do not register the file to the transaction | |
2136 | # because we needs it to still exist on the transaction |
|
2136 | # because we needs it to still exist on the transaction | |
2137 | # is close (for txnclose hooks) |
|
2137 | # is close (for txnclose hooks) | |
2138 | tagsmod.writediff(changesfile, changes) |
|
2138 | tagsmod.writediff(changesfile, changes) | |
2139 |
|
2139 | |||
2140 | def validate(tr2): |
|
2140 | def validate(tr2): | |
2141 | """will run pre-closing hooks""" |
|
2141 | """will run pre-closing hooks""" | |
2142 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
2142 | # XXX the transaction API is a bit lacking here so we take a hacky | |
2143 | # path for now |
|
2143 | # path for now | |
2144 | # |
|
2144 | # | |
2145 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
2145 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
2146 | # dict is copied before these run. In addition we needs the data |
|
2146 | # dict is copied before these run. In addition we needs the data | |
2147 | # available to in memory hooks too. |
|
2147 | # available to in memory hooks too. | |
2148 | # |
|
2148 | # | |
2149 | # Moreover, we also need to make sure this runs before txnclose |
|
2149 | # Moreover, we also need to make sure this runs before txnclose | |
2150 | # hooks and there is no "pending" mechanism that would execute |
|
2150 | # hooks and there is no "pending" mechanism that would execute | |
2151 | # logic only if hooks are about to run. |
|
2151 | # logic only if hooks are about to run. | |
2152 | # |
|
2152 | # | |
2153 | # Fixing this limitation of the transaction is also needed to track |
|
2153 | # Fixing this limitation of the transaction is also needed to track | |
2154 | # other families of changes (bookmarks, phases, obsolescence). |
|
2154 | # other families of changes (bookmarks, phases, obsolescence). | |
2155 | # |
|
2155 | # | |
2156 | # This will have to be fixed before we remove the experimental |
|
2156 | # This will have to be fixed before we remove the experimental | |
2157 | # gating. |
|
2157 | # gating. | |
2158 | tracktags(tr2) |
|
2158 | tracktags(tr2) | |
2159 | repo = reporef() |
|
2159 | repo = reporef() | |
2160 |
|
2160 | |||
2161 | singleheadopt = (b'experimental', b'single-head-per-branch') |
|
2161 | singleheadopt = (b'experimental', b'single-head-per-branch') | |
2162 | singlehead = repo.ui.configbool(*singleheadopt) |
|
2162 | singlehead = repo.ui.configbool(*singleheadopt) | |
2163 | if singlehead: |
|
2163 | if singlehead: | |
2164 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] |
|
2164 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] | |
2165 | accountclosed = singleheadsub.get( |
|
2165 | accountclosed = singleheadsub.get( | |
2166 | b"account-closed-heads", False |
|
2166 | b"account-closed-heads", False | |
2167 | ) |
|
2167 | ) | |
2168 | scmutil.enforcesinglehead(repo, tr2, desc, accountclosed) |
|
2168 | scmutil.enforcesinglehead(repo, tr2, desc, accountclosed) | |
2169 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): |
|
2169 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): | |
2170 | for name, (old, new) in sorted( |
|
2170 | for name, (old, new) in sorted( | |
2171 | tr.changes[b'bookmarks'].items() |
|
2171 | tr.changes[b'bookmarks'].items() | |
2172 | ): |
|
2172 | ): | |
2173 | args = tr.hookargs.copy() |
|
2173 | args = tr.hookargs.copy() | |
2174 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2174 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2175 | repo.hook( |
|
2175 | repo.hook( | |
2176 | b'pretxnclose-bookmark', |
|
2176 | b'pretxnclose-bookmark', | |
2177 | throw=True, |
|
2177 | throw=True, | |
2178 | **pycompat.strkwargs(args) |
|
2178 | **pycompat.strkwargs(args) | |
2179 | ) |
|
2179 | ) | |
2180 | if hook.hashook(repo.ui, b'pretxnclose-phase'): |
|
2180 | if hook.hashook(repo.ui, b'pretxnclose-phase'): | |
2181 | cl = repo.unfiltered().changelog |
|
2181 | cl = repo.unfiltered().changelog | |
2182 | for rev, (old, new) in tr.changes[b'phases'].items(): |
|
2182 | for rev, (old, new) in tr.changes[b'phases'].items(): | |
2183 | args = tr.hookargs.copy() |
|
2183 | args = tr.hookargs.copy() | |
2184 | node = hex(cl.node(rev)) |
|
2184 | node = hex(cl.node(rev)) | |
2185 | args.update(phases.preparehookargs(node, old, new)) |
|
2185 | args.update(phases.preparehookargs(node, old, new)) | |
2186 | repo.hook( |
|
2186 | repo.hook( | |
2187 | b'pretxnclose-phase', |
|
2187 | b'pretxnclose-phase', | |
2188 | throw=True, |
|
2188 | throw=True, | |
2189 | **pycompat.strkwargs(args) |
|
2189 | **pycompat.strkwargs(args) | |
2190 | ) |
|
2190 | ) | |
2191 |
|
2191 | |||
2192 | repo.hook( |
|
2192 | repo.hook( | |
2193 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) |
|
2193 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) | |
2194 | ) |
|
2194 | ) | |
2195 |
|
2195 | |||
2196 | def releasefn(tr, success): |
|
2196 | def releasefn(tr, success): | |
2197 | repo = reporef() |
|
2197 | repo = reporef() | |
2198 | if repo is None: |
|
2198 | if repo is None: | |
2199 | # If the repo has been GC'd (and this release function is being |
|
2199 | # If the repo has been GC'd (and this release function is being | |
2200 | # called from transaction.__del__), there's not much we can do, |
|
2200 | # called from transaction.__del__), there's not much we can do, | |
2201 | # so just leave the unfinished transaction there and let the |
|
2201 | # so just leave the unfinished transaction there and let the | |
2202 | # user run `hg recover`. |
|
2202 | # user run `hg recover`. | |
2203 | return |
|
2203 | return | |
2204 | if success: |
|
2204 | if success: | |
2205 | # this should be explicitly invoked here, because |
|
2205 | # this should be explicitly invoked here, because | |
2206 | # in-memory changes aren't written out at closing |
|
2206 | # in-memory changes aren't written out at closing | |
2207 | # transaction, if tr.addfilegenerator (via |
|
2207 | # transaction, if tr.addfilegenerator (via | |
2208 | # dirstate.write or so) isn't invoked while |
|
2208 | # dirstate.write or so) isn't invoked while | |
2209 | # transaction running |
|
2209 | # transaction running | |
2210 | repo.dirstate.write(None) |
|
2210 | repo.dirstate.write(None) | |
2211 | else: |
|
2211 | else: | |
2212 | # discard all changes (including ones already written |
|
2212 | # discard all changes (including ones already written | |
2213 | # out) in this transaction |
|
2213 | # out) in this transaction | |
2214 | narrowspec.restorebackup(self, b'journal.narrowspec') |
|
2214 | narrowspec.restorebackup(self, b'journal.narrowspec') | |
2215 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') |
|
2215 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') | |
2216 | repo.dirstate.restorebackup(None, b'journal.dirstate') |
|
2216 | repo.dirstate.restorebackup(None, b'journal.dirstate') | |
2217 |
|
2217 | |||
2218 | repo.invalidate(clearfilecache=True) |
|
2218 | repo.invalidate(clearfilecache=True) | |
2219 |
|
2219 | |||
2220 | tr = transaction.transaction( |
|
2220 | tr = transaction.transaction( | |
2221 | rp, |
|
2221 | rp, | |
2222 | self.svfs, |
|
2222 | self.svfs, | |
2223 | vfsmap, |
|
2223 | vfsmap, | |
2224 | b"journal", |
|
2224 | b"journal", | |
2225 | b"undo", |
|
2225 | b"undo", | |
2226 | aftertrans(renames), |
|
2226 | aftertrans(renames), | |
2227 | self.store.createmode, |
|
2227 | self.store.createmode, | |
2228 | validator=validate, |
|
2228 | validator=validate, | |
2229 | releasefn=releasefn, |
|
2229 | releasefn=releasefn, | |
2230 | checkambigfiles=_cachedfiles, |
|
2230 | checkambigfiles=_cachedfiles, | |
2231 | name=desc, |
|
2231 | name=desc, | |
2232 | ) |
|
2232 | ) | |
2233 | tr.changes[b'origrepolen'] = len(self) |
|
2233 | tr.changes[b'origrepolen'] = len(self) | |
2234 | tr.changes[b'obsmarkers'] = set() |
|
2234 | tr.changes[b'obsmarkers'] = set() | |
2235 | tr.changes[b'phases'] = {} |
|
2235 | tr.changes[b'phases'] = {} | |
2236 | tr.changes[b'bookmarks'] = {} |
|
2236 | tr.changes[b'bookmarks'] = {} | |
2237 |
|
2237 | |||
2238 | tr.hookargs[b'txnid'] = txnid |
|
2238 | tr.hookargs[b'txnid'] = txnid | |
2239 | tr.hookargs[b'txnname'] = desc |
|
2239 | tr.hookargs[b'txnname'] = desc | |
2240 | # note: writing the fncache only during finalize mean that the file is |
|
2240 | # note: writing the fncache only during finalize mean that the file is | |
2241 | # outdated when running hooks. As fncache is used for streaming clone, |
|
2241 | # outdated when running hooks. As fncache is used for streaming clone, | |
2242 | # this is not expected to break anything that happen during the hooks. |
|
2242 | # this is not expected to break anything that happen during the hooks. | |
2243 | tr.addfinalize(b'flush-fncache', self.store.write) |
|
2243 | tr.addfinalize(b'flush-fncache', self.store.write) | |
2244 |
|
2244 | |||
2245 | def txnclosehook(tr2): |
|
2245 | def txnclosehook(tr2): | |
2246 | """To be run if transaction is successful, will schedule a hook run |
|
2246 | """To be run if transaction is successful, will schedule a hook run | |
2247 | """ |
|
2247 | """ | |
2248 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
2248 | # Don't reference tr2 in hook() so we don't hold a reference. | |
2249 | # This reduces memory consumption when there are multiple |
|
2249 | # This reduces memory consumption when there are multiple | |
2250 | # transactions per lock. This can likely go away if issue5045 |
|
2250 | # transactions per lock. This can likely go away if issue5045 | |
2251 | # fixes the function accumulation. |
|
2251 | # fixes the function accumulation. | |
2252 | hookargs = tr2.hookargs |
|
2252 | hookargs = tr2.hookargs | |
2253 |
|
2253 | |||
2254 | def hookfunc(unused_success): |
|
2254 | def hookfunc(unused_success): | |
2255 | repo = reporef() |
|
2255 | repo = reporef() | |
2256 | if hook.hashook(repo.ui, b'txnclose-bookmark'): |
|
2256 | if hook.hashook(repo.ui, b'txnclose-bookmark'): | |
2257 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) |
|
2257 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) | |
2258 | for name, (old, new) in bmchanges: |
|
2258 | for name, (old, new) in bmchanges: | |
2259 | args = tr.hookargs.copy() |
|
2259 | args = tr.hookargs.copy() | |
2260 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2260 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2261 | repo.hook( |
|
2261 | repo.hook( | |
2262 | b'txnclose-bookmark', |
|
2262 | b'txnclose-bookmark', | |
2263 | throw=False, |
|
2263 | throw=False, | |
2264 | **pycompat.strkwargs(args) |
|
2264 | **pycompat.strkwargs(args) | |
2265 | ) |
|
2265 | ) | |
2266 |
|
2266 | |||
2267 | if hook.hashook(repo.ui, b'txnclose-phase'): |
|
2267 | if hook.hashook(repo.ui, b'txnclose-phase'): | |
2268 | cl = repo.unfiltered().changelog |
|
2268 | cl = repo.unfiltered().changelog | |
2269 | phasemv = sorted(tr.changes[b'phases'].items()) |
|
2269 | phasemv = sorted(tr.changes[b'phases'].items()) | |
2270 | for rev, (old, new) in phasemv: |
|
2270 | for rev, (old, new) in phasemv: | |
2271 | args = tr.hookargs.copy() |
|
2271 | args = tr.hookargs.copy() | |
2272 | node = hex(cl.node(rev)) |
|
2272 | node = hex(cl.node(rev)) | |
2273 | args.update(phases.preparehookargs(node, old, new)) |
|
2273 | args.update(phases.preparehookargs(node, old, new)) | |
2274 | repo.hook( |
|
2274 | repo.hook( | |
2275 | b'txnclose-phase', |
|
2275 | b'txnclose-phase', | |
2276 | throw=False, |
|
2276 | throw=False, | |
2277 | **pycompat.strkwargs(args) |
|
2277 | **pycompat.strkwargs(args) | |
2278 | ) |
|
2278 | ) | |
2279 |
|
2279 | |||
2280 | repo.hook( |
|
2280 | repo.hook( | |
2281 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) |
|
2281 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) | |
2282 | ) |
|
2282 | ) | |
2283 |
|
2283 | |||
2284 | reporef()._afterlock(hookfunc) |
|
2284 | reporef()._afterlock(hookfunc) | |
2285 |
|
2285 | |||
2286 | tr.addfinalize(b'txnclose-hook', txnclosehook) |
|
2286 | tr.addfinalize(b'txnclose-hook', txnclosehook) | |
2287 | # Include a leading "-" to make it happen before the transaction summary |
|
2287 | # Include a leading "-" to make it happen before the transaction summary | |
2288 | # reports registered via scmutil.registersummarycallback() whose names |
|
2288 | # reports registered via scmutil.registersummarycallback() whose names | |
2289 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
2289 | # are 00-txnreport etc. That way, the caches will be warm when the | |
2290 | # callbacks run. |
|
2290 | # callbacks run. | |
2291 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) |
|
2291 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) | |
2292 |
|
2292 | |||
2293 | def txnaborthook(tr2): |
|
2293 | def txnaborthook(tr2): | |
2294 | """To be run if transaction is aborted |
|
2294 | """To be run if transaction is aborted | |
2295 | """ |
|
2295 | """ | |
2296 | reporef().hook( |
|
2296 | reporef().hook( | |
2297 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) |
|
2297 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) | |
2298 | ) |
|
2298 | ) | |
2299 |
|
2299 | |||
2300 | tr.addabort(b'txnabort-hook', txnaborthook) |
|
2300 | tr.addabort(b'txnabort-hook', txnaborthook) | |
2301 | # avoid eager cache invalidation. in-memory data should be identical |
|
2301 | # avoid eager cache invalidation. in-memory data should be identical | |
2302 | # to stored data if transaction has no error. |
|
2302 | # to stored data if transaction has no error. | |
2303 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) |
|
2303 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) | |
2304 | self._transref = weakref.ref(tr) |
|
2304 | self._transref = weakref.ref(tr) | |
2305 | scmutil.registersummarycallback(self, tr, desc) |
|
2305 | scmutil.registersummarycallback(self, tr, desc) | |
2306 | return tr |
|
2306 | return tr | |
2307 |
|
2307 | |||
2308 | def _journalfiles(self): |
|
2308 | def _journalfiles(self): | |
2309 | return ( |
|
2309 | return ( | |
2310 | (self.svfs, b'journal'), |
|
2310 | (self.svfs, b'journal'), | |
2311 | (self.svfs, b'journal.narrowspec'), |
|
2311 | (self.svfs, b'journal.narrowspec'), | |
2312 | (self.vfs, b'journal.narrowspec.dirstate'), |
|
2312 | (self.vfs, b'journal.narrowspec.dirstate'), | |
2313 | (self.vfs, b'journal.dirstate'), |
|
2313 | (self.vfs, b'journal.dirstate'), | |
2314 | (self.vfs, b'journal.branch'), |
|
2314 | (self.vfs, b'journal.branch'), | |
2315 | (self.vfs, b'journal.desc'), |
|
2315 | (self.vfs, b'journal.desc'), | |
2316 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), |
|
2316 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), | |
2317 | (self.svfs, b'journal.phaseroots'), |
|
2317 | (self.svfs, b'journal.phaseroots'), | |
2318 | ) |
|
2318 | ) | |
2319 |
|
2319 | |||
2320 | def undofiles(self): |
|
2320 | def undofiles(self): | |
2321 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
2321 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
2322 |
|
2322 | |||
2323 | @unfilteredmethod |
|
2323 | @unfilteredmethod | |
2324 | def _writejournal(self, desc): |
|
2324 | def _writejournal(self, desc): | |
2325 | self.dirstate.savebackup(None, b'journal.dirstate') |
|
2325 | self.dirstate.savebackup(None, b'journal.dirstate') | |
2326 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') |
|
2326 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') | |
2327 | narrowspec.savebackup(self, b'journal.narrowspec') |
|
2327 | narrowspec.savebackup(self, b'journal.narrowspec') | |
2328 | self.vfs.write( |
|
2328 | self.vfs.write( | |
2329 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) |
|
2329 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) | |
2330 | ) |
|
2330 | ) | |
2331 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) |
|
2331 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) | |
2332 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2332 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2333 | bookmarksvfs.write( |
|
2333 | bookmarksvfs.write( | |
2334 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") |
|
2334 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") | |
2335 | ) |
|
2335 | ) | |
2336 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) |
|
2336 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) | |
2337 |
|
2337 | |||
2338 | def recover(self): |
|
2338 | def recover(self): | |
2339 | with self.lock(): |
|
2339 | with self.lock(): | |
2340 | if self.svfs.exists(b"journal"): |
|
2340 | if self.svfs.exists(b"journal"): | |
2341 | self.ui.status(_(b"rolling back interrupted transaction\n")) |
|
2341 | self.ui.status(_(b"rolling back interrupted transaction\n")) | |
2342 | vfsmap = { |
|
2342 | vfsmap = { | |
2343 | b'': self.svfs, |
|
2343 | b'': self.svfs, | |
2344 | b'plain': self.vfs, |
|
2344 | b'plain': self.vfs, | |
2345 | } |
|
2345 | } | |
2346 | transaction.rollback( |
|
2346 | transaction.rollback( | |
2347 | self.svfs, |
|
2347 | self.svfs, | |
2348 | vfsmap, |
|
2348 | vfsmap, | |
2349 | b"journal", |
|
2349 | b"journal", | |
2350 | self.ui.warn, |
|
2350 | self.ui.warn, | |
2351 | checkambigfiles=_cachedfiles, |
|
2351 | checkambigfiles=_cachedfiles, | |
2352 | ) |
|
2352 | ) | |
2353 | self.invalidate() |
|
2353 | self.invalidate() | |
2354 | return True |
|
2354 | return True | |
2355 | else: |
|
2355 | else: | |
2356 | self.ui.warn(_(b"no interrupted transaction available\n")) |
|
2356 | self.ui.warn(_(b"no interrupted transaction available\n")) | |
2357 | return False |
|
2357 | return False | |
2358 |
|
2358 | |||
2359 | def rollback(self, dryrun=False, force=False): |
|
2359 | def rollback(self, dryrun=False, force=False): | |
2360 | wlock = lock = dsguard = None |
|
2360 | wlock = lock = dsguard = None | |
2361 | try: |
|
2361 | try: | |
2362 | wlock = self.wlock() |
|
2362 | wlock = self.wlock() | |
2363 | lock = self.lock() |
|
2363 | lock = self.lock() | |
2364 | if self.svfs.exists(b"undo"): |
|
2364 | if self.svfs.exists(b"undo"): | |
2365 | dsguard = dirstateguard.dirstateguard(self, b'rollback') |
|
2365 | dsguard = dirstateguard.dirstateguard(self, b'rollback') | |
2366 |
|
2366 | |||
2367 | return self._rollback(dryrun, force, dsguard) |
|
2367 | return self._rollback(dryrun, force, dsguard) | |
2368 | else: |
|
2368 | else: | |
2369 | self.ui.warn(_(b"no rollback information available\n")) |
|
2369 | self.ui.warn(_(b"no rollback information available\n")) | |
2370 | return 1 |
|
2370 | return 1 | |
2371 | finally: |
|
2371 | finally: | |
2372 | release(dsguard, lock, wlock) |
|
2372 | release(dsguard, lock, wlock) | |
2373 |
|
2373 | |||
2374 | @unfilteredmethod # Until we get smarter cache management |
|
2374 | @unfilteredmethod # Until we get smarter cache management | |
2375 | def _rollback(self, dryrun, force, dsguard): |
|
2375 | def _rollback(self, dryrun, force, dsguard): | |
2376 | ui = self.ui |
|
2376 | ui = self.ui | |
2377 | try: |
|
2377 | try: | |
2378 | args = self.vfs.read(b'undo.desc').splitlines() |
|
2378 | args = self.vfs.read(b'undo.desc').splitlines() | |
2379 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
2379 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
2380 | if len(args) >= 3: |
|
2380 | if len(args) >= 3: | |
2381 | detail = args[2] |
|
2381 | detail = args[2] | |
2382 | oldtip = oldlen - 1 |
|
2382 | oldtip = oldlen - 1 | |
2383 |
|
2383 | |||
2384 | if detail and ui.verbose: |
|
2384 | if detail and ui.verbose: | |
2385 | msg = _( |
|
2385 | msg = _( | |
2386 | b'repository tip rolled back to revision %d' |
|
2386 | b'repository tip rolled back to revision %d' | |
2387 | b' (undo %s: %s)\n' |
|
2387 | b' (undo %s: %s)\n' | |
2388 | ) % (oldtip, desc, detail) |
|
2388 | ) % (oldtip, desc, detail) | |
2389 | else: |
|
2389 | else: | |
2390 | msg = _( |
|
2390 | msg = _( | |
2391 | b'repository tip rolled back to revision %d (undo %s)\n' |
|
2391 | b'repository tip rolled back to revision %d (undo %s)\n' | |
2392 | ) % (oldtip, desc) |
|
2392 | ) % (oldtip, desc) | |
2393 | except IOError: |
|
2393 | except IOError: | |
2394 | msg = _(b'rolling back unknown transaction\n') |
|
2394 | msg = _(b'rolling back unknown transaction\n') | |
2395 | desc = None |
|
2395 | desc = None | |
2396 |
|
2396 | |||
2397 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': |
|
2397 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': | |
2398 | raise error.Abort( |
|
2398 | raise error.Abort( | |
2399 | _( |
|
2399 | _( | |
2400 | b'rollback of last commit while not checked out ' |
|
2400 | b'rollback of last commit while not checked out ' | |
2401 | b'may lose data' |
|
2401 | b'may lose data' | |
2402 | ), |
|
2402 | ), | |
2403 | hint=_(b'use -f to force'), |
|
2403 | hint=_(b'use -f to force'), | |
2404 | ) |
|
2404 | ) | |
2405 |
|
2405 | |||
2406 | ui.status(msg) |
|
2406 | ui.status(msg) | |
2407 | if dryrun: |
|
2407 | if dryrun: | |
2408 | return 0 |
|
2408 | return 0 | |
2409 |
|
2409 | |||
2410 | parents = self.dirstate.parents() |
|
2410 | parents = self.dirstate.parents() | |
2411 | self.destroying() |
|
2411 | self.destroying() | |
2412 | vfsmap = {b'plain': self.vfs, b'': self.svfs} |
|
2412 | vfsmap = {b'plain': self.vfs, b'': self.svfs} | |
2413 | transaction.rollback( |
|
2413 | transaction.rollback( | |
2414 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles |
|
2414 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles | |
2415 | ) |
|
2415 | ) | |
2416 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2416 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2417 | if bookmarksvfs.exists(b'undo.bookmarks'): |
|
2417 | if bookmarksvfs.exists(b'undo.bookmarks'): | |
2418 | bookmarksvfs.rename( |
|
2418 | bookmarksvfs.rename( | |
2419 | b'undo.bookmarks', b'bookmarks', checkambig=True |
|
2419 | b'undo.bookmarks', b'bookmarks', checkambig=True | |
2420 | ) |
|
2420 | ) | |
2421 | if self.svfs.exists(b'undo.phaseroots'): |
|
2421 | if self.svfs.exists(b'undo.phaseroots'): | |
2422 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) |
|
2422 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) | |
2423 | self.invalidate() |
|
2423 | self.invalidate() | |
2424 |
|
2424 | |||
2425 | has_node = self.changelog.index.has_node |
|
2425 | has_node = self.changelog.index.has_node | |
2426 | parentgone = any(not has_node(p) for p in parents) |
|
2426 | parentgone = any(not has_node(p) for p in parents) | |
2427 | if parentgone: |
|
2427 | if parentgone: | |
2428 | # prevent dirstateguard from overwriting already restored one |
|
2428 | # prevent dirstateguard from overwriting already restored one | |
2429 | dsguard.close() |
|
2429 | dsguard.close() | |
2430 |
|
2430 | |||
2431 | narrowspec.restorebackup(self, b'undo.narrowspec') |
|
2431 | narrowspec.restorebackup(self, b'undo.narrowspec') | |
2432 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') |
|
2432 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') | |
2433 | self.dirstate.restorebackup(None, b'undo.dirstate') |
|
2433 | self.dirstate.restorebackup(None, b'undo.dirstate') | |
2434 | try: |
|
2434 | try: | |
2435 | branch = self.vfs.read(b'undo.branch') |
|
2435 | branch = self.vfs.read(b'undo.branch') | |
2436 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
2436 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
2437 | except IOError: |
|
2437 | except IOError: | |
2438 | ui.warn( |
|
2438 | ui.warn( | |
2439 | _( |
|
2439 | _( | |
2440 | b'named branch could not be reset: ' |
|
2440 | b'named branch could not be reset: ' | |
2441 | b'current branch is still \'%s\'\n' |
|
2441 | b'current branch is still \'%s\'\n' | |
2442 | ) |
|
2442 | ) | |
2443 | % self.dirstate.branch() |
|
2443 | % self.dirstate.branch() | |
2444 | ) |
|
2444 | ) | |
2445 |
|
2445 | |||
2446 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
2446 | parents = tuple([p.rev() for p in self[None].parents()]) | |
2447 | if len(parents) > 1: |
|
2447 | if len(parents) > 1: | |
2448 | ui.status( |
|
2448 | ui.status( | |
2449 | _( |
|
2449 | _( | |
2450 | b'working directory now based on ' |
|
2450 | b'working directory now based on ' | |
2451 | b'revisions %d and %d\n' |
|
2451 | b'revisions %d and %d\n' | |
2452 | ) |
|
2452 | ) | |
2453 | % parents |
|
2453 | % parents | |
2454 | ) |
|
2454 | ) | |
2455 | else: |
|
2455 | else: | |
2456 | ui.status( |
|
2456 | ui.status( | |
2457 | _(b'working directory now based on revision %d\n') % parents |
|
2457 | _(b'working directory now based on revision %d\n') % parents | |
2458 | ) |
|
2458 | ) | |
2459 | mergemod.mergestate.clean(self, self[b'.'].node()) |
|
2459 | mergemod.mergestate.clean(self, self[b'.'].node()) | |
2460 |
|
2460 | |||
2461 | # TODO: if we know which new heads may result from this rollback, pass |
|
2461 | # TODO: if we know which new heads may result from this rollback, pass | |
2462 | # them to destroy(), which will prevent the branchhead cache from being |
|
2462 | # them to destroy(), which will prevent the branchhead cache from being | |
2463 | # invalidated. |
|
2463 | # invalidated. | |
2464 | self.destroyed() |
|
2464 | self.destroyed() | |
2465 | return 0 |
|
2465 | return 0 | |
2466 |
|
2466 | |||
2467 | def _buildcacheupdater(self, newtransaction): |
|
2467 | def _buildcacheupdater(self, newtransaction): | |
2468 | """called during transaction to build the callback updating cache |
|
2468 | """called during transaction to build the callback updating cache | |
2469 |
|
2469 | |||
2470 | Lives on the repository to help extension who might want to augment |
|
2470 | Lives on the repository to help extension who might want to augment | |
2471 | this logic. For this purpose, the created transaction is passed to the |
|
2471 | this logic. For this purpose, the created transaction is passed to the | |
2472 | method. |
|
2472 | method. | |
2473 | """ |
|
2473 | """ | |
2474 | # we must avoid cyclic reference between repo and transaction. |
|
2474 | # we must avoid cyclic reference between repo and transaction. | |
2475 | reporef = weakref.ref(self) |
|
2475 | reporef = weakref.ref(self) | |
2476 |
|
2476 | |||
2477 | def updater(tr): |
|
2477 | def updater(tr): | |
2478 | repo = reporef() |
|
2478 | repo = reporef() | |
2479 | repo.updatecaches(tr) |
|
2479 | repo.updatecaches(tr) | |
2480 |
|
2480 | |||
2481 | return updater |
|
2481 | return updater | |
2482 |
|
2482 | |||
2483 | @unfilteredmethod |
|
2483 | @unfilteredmethod | |
2484 | def updatecaches(self, tr=None, full=False): |
|
2484 | def updatecaches(self, tr=None, full=False): | |
2485 | """warm appropriate caches |
|
2485 | """warm appropriate caches | |
2486 |
|
2486 | |||
2487 | If this function is called after a transaction closed. The transaction |
|
2487 | If this function is called after a transaction closed. The transaction | |
2488 | will be available in the 'tr' argument. This can be used to selectively |
|
2488 | will be available in the 'tr' argument. This can be used to selectively | |
2489 | update caches relevant to the changes in that transaction. |
|
2489 | update caches relevant to the changes in that transaction. | |
2490 |
|
2490 | |||
2491 | If 'full' is set, make sure all caches the function knows about have |
|
2491 | If 'full' is set, make sure all caches the function knows about have | |
2492 | up-to-date data. Even the ones usually loaded more lazily. |
|
2492 | up-to-date data. Even the ones usually loaded more lazily. | |
2493 | """ |
|
2493 | """ | |
2494 | if tr is not None and tr.hookargs.get(b'source') == b'strip': |
|
2494 | if tr is not None and tr.hookargs.get(b'source') == b'strip': | |
2495 | # During strip, many caches are invalid but |
|
2495 | # During strip, many caches are invalid but | |
2496 | # later call to `destroyed` will refresh them. |
|
2496 | # later call to `destroyed` will refresh them. | |
2497 | return |
|
2497 | return | |
2498 |
|
2498 | |||
2499 | if tr is None or tr.changes[b'origrepolen'] < len(self): |
|
2499 | if tr is None or tr.changes[b'origrepolen'] < len(self): | |
2500 | # accessing the 'ser ved' branchmap should refresh all the others, |
|
2500 | # accessing the 'ser ved' branchmap should refresh all the others, | |
2501 | self.ui.debug(b'updating the branch cache\n') |
|
2501 | self.ui.debug(b'updating the branch cache\n') | |
2502 | self.filtered(b'served').branchmap() |
|
2502 | self.filtered(b'served').branchmap() | |
2503 | self.filtered(b'served.hidden').branchmap() |
|
2503 | self.filtered(b'served.hidden').branchmap() | |
2504 |
|
2504 | |||
2505 | if full: |
|
2505 | if full: | |
2506 | unfi = self.unfiltered() |
|
2506 | unfi = self.unfiltered() | |
2507 | rbc = unfi.revbranchcache() |
|
2507 | rbc = unfi.revbranchcache() | |
2508 | for r in unfi.changelog: |
|
2508 | for r in unfi.changelog: | |
2509 | rbc.branchinfo(r) |
|
2509 | rbc.branchinfo(r) | |
2510 | rbc.write() |
|
2510 | rbc.write() | |
2511 |
|
2511 | |||
2512 | # ensure the working copy parents are in the manifestfulltextcache |
|
2512 | # ensure the working copy parents are in the manifestfulltextcache | |
2513 | for ctx in self[b'.'].parents(): |
|
2513 | for ctx in self[b'.'].parents(): | |
2514 | ctx.manifest() # accessing the manifest is enough |
|
2514 | ctx.manifest() # accessing the manifest is enough | |
2515 |
|
2515 | |||
2516 | # accessing fnode cache warms the cache |
|
2516 | # accessing fnode cache warms the cache | |
2517 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) |
|
2517 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) | |
2518 | # accessing tags warm the cache |
|
2518 | # accessing tags warm the cache | |
2519 | self.tags() |
|
2519 | self.tags() | |
2520 | self.filtered(b'served').tags() |
|
2520 | self.filtered(b'served').tags() | |
2521 |
|
2521 | |||
2522 | # The `full` arg is documented as updating even the lazily-loaded |
|
2522 | # The `full` arg is documented as updating even the lazily-loaded | |
2523 | # caches immediately, so we're forcing a write to cause these caches |
|
2523 | # caches immediately, so we're forcing a write to cause these caches | |
2524 | # to be warmed up even if they haven't explicitly been requested |
|
2524 | # to be warmed up even if they haven't explicitly been requested | |
2525 | # yet (if they've never been used by hg, they won't ever have been |
|
2525 | # yet (if they've never been used by hg, they won't ever have been | |
2526 | # written, even if they're a subset of another kind of cache that |
|
2526 | # written, even if they're a subset of another kind of cache that | |
2527 | # *has* been used). |
|
2527 | # *has* been used). | |
2528 | for filt in repoview.filtertable.keys(): |
|
2528 | for filt in repoview.filtertable.keys(): | |
2529 | filtered = self.filtered(filt) |
|
2529 | filtered = self.filtered(filt) | |
2530 | filtered.branchmap().write(filtered) |
|
2530 | filtered.branchmap().write(filtered) | |
2531 |
|
2531 | |||
2532 | def invalidatecaches(self): |
|
2532 | def invalidatecaches(self): | |
2533 |
|
2533 | |||
2534 | if '_tagscache' in vars(self): |
|
2534 | if '_tagscache' in vars(self): | |
2535 | # can't use delattr on proxy |
|
2535 | # can't use delattr on proxy | |
2536 | del self.__dict__['_tagscache'] |
|
2536 | del self.__dict__['_tagscache'] | |
2537 |
|
2537 | |||
2538 | self._branchcaches.clear() |
|
2538 | self._branchcaches.clear() | |
2539 | self.invalidatevolatilesets() |
|
2539 | self.invalidatevolatilesets() | |
2540 | self._sparsesignaturecache.clear() |
|
2540 | self._sparsesignaturecache.clear() | |
2541 |
|
2541 | |||
2542 | def invalidatevolatilesets(self): |
|
2542 | def invalidatevolatilesets(self): | |
2543 | self.filteredrevcache.clear() |
|
2543 | self.filteredrevcache.clear() | |
2544 | obsolete.clearobscaches(self) |
|
2544 | obsolete.clearobscaches(self) | |
2545 | self._quick_access_changeid_invalidate() |
|
2545 | self._quick_access_changeid_invalidate() | |
2546 |
|
2546 | |||
2547 | def invalidatedirstate(self): |
|
2547 | def invalidatedirstate(self): | |
2548 | '''Invalidates the dirstate, causing the next call to dirstate |
|
2548 | '''Invalidates the dirstate, causing the next call to dirstate | |
2549 | to check if it was modified since the last time it was read, |
|
2549 | to check if it was modified since the last time it was read, | |
2550 | rereading it if it has. |
|
2550 | rereading it if it has. | |
2551 |
|
2551 | |||
2552 | This is different to dirstate.invalidate() that it doesn't always |
|
2552 | This is different to dirstate.invalidate() that it doesn't always | |
2553 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
2553 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
2554 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
2554 | explicitly read the dirstate again (i.e. restoring it to a previous | |
2555 | known good state).''' |
|
2555 | known good state).''' | |
2556 | if hasunfilteredcache(self, 'dirstate'): |
|
2556 | if hasunfilteredcache(self, 'dirstate'): | |
2557 | for k in self.dirstate._filecache: |
|
2557 | for k in self.dirstate._filecache: | |
2558 | try: |
|
2558 | try: | |
2559 | delattr(self.dirstate, k) |
|
2559 | delattr(self.dirstate, k) | |
2560 | except AttributeError: |
|
2560 | except AttributeError: | |
2561 | pass |
|
2561 | pass | |
2562 | delattr(self.unfiltered(), 'dirstate') |
|
2562 | delattr(self.unfiltered(), 'dirstate') | |
2563 |
|
2563 | |||
2564 | def invalidate(self, clearfilecache=False): |
|
2564 | def invalidate(self, clearfilecache=False): | |
2565 | '''Invalidates both store and non-store parts other than dirstate |
|
2565 | '''Invalidates both store and non-store parts other than dirstate | |
2566 |
|
2566 | |||
2567 | If a transaction is running, invalidation of store is omitted, |
|
2567 | If a transaction is running, invalidation of store is omitted, | |
2568 | because discarding in-memory changes might cause inconsistency |
|
2568 | because discarding in-memory changes might cause inconsistency | |
2569 | (e.g. incomplete fncache causes unintentional failure, but |
|
2569 | (e.g. incomplete fncache causes unintentional failure, but | |
2570 | redundant one doesn't). |
|
2570 | redundant one doesn't). | |
2571 | ''' |
|
2571 | ''' | |
2572 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
2572 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
2573 | for k in list(self._filecache.keys()): |
|
2573 | for k in list(self._filecache.keys()): | |
2574 | # dirstate is invalidated separately in invalidatedirstate() |
|
2574 | # dirstate is invalidated separately in invalidatedirstate() | |
2575 | if k == b'dirstate': |
|
2575 | if k == b'dirstate': | |
2576 | continue |
|
2576 | continue | |
2577 | if ( |
|
2577 | if ( | |
2578 | k == b'changelog' |
|
2578 | k == b'changelog' | |
2579 | and self.currenttransaction() |
|
2579 | and self.currenttransaction() | |
2580 | and self.changelog._delayed |
|
2580 | and self.changelog._delayed | |
2581 | ): |
|
2581 | ): | |
2582 | # The changelog object may store unwritten revisions. We don't |
|
2582 | # The changelog object may store unwritten revisions. We don't | |
2583 | # want to lose them. |
|
2583 | # want to lose them. | |
2584 | # TODO: Solve the problem instead of working around it. |
|
2584 | # TODO: Solve the problem instead of working around it. | |
2585 | continue |
|
2585 | continue | |
2586 |
|
2586 | |||
2587 | if clearfilecache: |
|
2587 | if clearfilecache: | |
2588 | del self._filecache[k] |
|
2588 | del self._filecache[k] | |
2589 | try: |
|
2589 | try: | |
2590 | delattr(unfiltered, k) |
|
2590 | delattr(unfiltered, k) | |
2591 | except AttributeError: |
|
2591 | except AttributeError: | |
2592 | pass |
|
2592 | pass | |
2593 | self.invalidatecaches() |
|
2593 | self.invalidatecaches() | |
2594 | if not self.currenttransaction(): |
|
2594 | if not self.currenttransaction(): | |
2595 | # TODO: Changing contents of store outside transaction |
|
2595 | # TODO: Changing contents of store outside transaction | |
2596 | # causes inconsistency. We should make in-memory store |
|
2596 | # causes inconsistency. We should make in-memory store | |
2597 | # changes detectable, and abort if changed. |
|
2597 | # changes detectable, and abort if changed. | |
2598 | self.store.invalidatecaches() |
|
2598 | self.store.invalidatecaches() | |
2599 |
|
2599 | |||
2600 | def invalidateall(self): |
|
2600 | def invalidateall(self): | |
2601 | '''Fully invalidates both store and non-store parts, causing the |
|
2601 | '''Fully invalidates both store and non-store parts, causing the | |
2602 | subsequent operation to reread any outside changes.''' |
|
2602 | subsequent operation to reread any outside changes.''' | |
2603 | # extension should hook this to invalidate its caches |
|
2603 | # extension should hook this to invalidate its caches | |
2604 | self.invalidate() |
|
2604 | self.invalidate() | |
2605 | self.invalidatedirstate() |
|
2605 | self.invalidatedirstate() | |
2606 |
|
2606 | |||
2607 | @unfilteredmethod |
|
2607 | @unfilteredmethod | |
2608 | def _refreshfilecachestats(self, tr): |
|
2608 | def _refreshfilecachestats(self, tr): | |
2609 | """Reload stats of cached files so that they are flagged as valid""" |
|
2609 | """Reload stats of cached files so that they are flagged as valid""" | |
2610 | for k, ce in self._filecache.items(): |
|
2610 | for k, ce in self._filecache.items(): | |
2611 | k = pycompat.sysstr(k) |
|
2611 | k = pycompat.sysstr(k) | |
2612 | if k == 'dirstate' or k not in self.__dict__: |
|
2612 | if k == 'dirstate' or k not in self.__dict__: | |
2613 | continue |
|
2613 | continue | |
2614 | ce.refresh() |
|
2614 | ce.refresh() | |
2615 |
|
2615 | |||
2616 | def _lock( |
|
2616 | def _lock( | |
2617 | self, |
|
2617 | self, | |
2618 | vfs, |
|
2618 | vfs, | |
2619 | lockname, |
|
2619 | lockname, | |
2620 | wait, |
|
2620 | wait, | |
2621 | releasefn, |
|
2621 | releasefn, | |
2622 | acquirefn, |
|
2622 | acquirefn, | |
2623 | desc, |
|
2623 | desc, | |
2624 | inheritchecker=None, |
|
2624 | inheritchecker=None, | |
2625 | parentenvvar=None, |
|
2625 | parentenvvar=None, | |
2626 | ): |
|
2626 | ): | |
2627 | parentlock = None |
|
2627 | parentlock = None | |
2628 | # the contents of parentenvvar are used by the underlying lock to |
|
2628 | # the contents of parentenvvar are used by the underlying lock to | |
2629 | # determine whether it can be inherited |
|
2629 | # determine whether it can be inherited | |
2630 | if parentenvvar is not None: |
|
2630 | if parentenvvar is not None: | |
2631 | parentlock = encoding.environ.get(parentenvvar) |
|
2631 | parentlock = encoding.environ.get(parentenvvar) | |
2632 |
|
2632 | |||
2633 | timeout = 0 |
|
2633 | timeout = 0 | |
2634 | warntimeout = 0 |
|
2634 | warntimeout = 0 | |
2635 | if wait: |
|
2635 | if wait: | |
2636 | timeout = self.ui.configint(b"ui", b"timeout") |
|
2636 | timeout = self.ui.configint(b"ui", b"timeout") | |
2637 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") |
|
2637 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") | |
2638 | # internal config: ui.signal-safe-lock |
|
2638 | # internal config: ui.signal-safe-lock | |
2639 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') |
|
2639 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') | |
2640 |
|
2640 | |||
2641 | l = lockmod.trylock( |
|
2641 | l = lockmod.trylock( | |
2642 | self.ui, |
|
2642 | self.ui, | |
2643 | vfs, |
|
2643 | vfs, | |
2644 | lockname, |
|
2644 | lockname, | |
2645 | timeout, |
|
2645 | timeout, | |
2646 | warntimeout, |
|
2646 | warntimeout, | |
2647 | releasefn=releasefn, |
|
2647 | releasefn=releasefn, | |
2648 | acquirefn=acquirefn, |
|
2648 | acquirefn=acquirefn, | |
2649 | desc=desc, |
|
2649 | desc=desc, | |
2650 | inheritchecker=inheritchecker, |
|
2650 | inheritchecker=inheritchecker, | |
2651 | parentlock=parentlock, |
|
2651 | parentlock=parentlock, | |
2652 | signalsafe=signalsafe, |
|
2652 | signalsafe=signalsafe, | |
2653 | ) |
|
2653 | ) | |
2654 | return l |
|
2654 | return l | |
2655 |
|
2655 | |||
2656 | def _afterlock(self, callback): |
|
2656 | def _afterlock(self, callback): | |
2657 | """add a callback to be run when the repository is fully unlocked |
|
2657 | """add a callback to be run when the repository is fully unlocked | |
2658 |
|
2658 | |||
2659 | The callback will be executed when the outermost lock is released |
|
2659 | The callback will be executed when the outermost lock is released | |
2660 | (with wlock being higher level than 'lock').""" |
|
2660 | (with wlock being higher level than 'lock').""" | |
2661 | for ref in (self._wlockref, self._lockref): |
|
2661 | for ref in (self._wlockref, self._lockref): | |
2662 | l = ref and ref() |
|
2662 | l = ref and ref() | |
2663 | if l and l.held: |
|
2663 | if l and l.held: | |
2664 | l.postrelease.append(callback) |
|
2664 | l.postrelease.append(callback) | |
2665 | break |
|
2665 | break | |
2666 | else: # no lock have been found. |
|
2666 | else: # no lock have been found. | |
2667 | callback(True) |
|
2667 | callback(True) | |
2668 |
|
2668 | |||
2669 | def lock(self, wait=True): |
|
2669 | def lock(self, wait=True): | |
2670 | '''Lock the repository store (.hg/store) and return a weak reference |
|
2670 | '''Lock the repository store (.hg/store) and return a weak reference | |
2671 | to the lock. Use this before modifying the store (e.g. committing or |
|
2671 | to the lock. Use this before modifying the store (e.g. committing or | |
2672 | stripping). If you are opening a transaction, get a lock as well.) |
|
2672 | stripping). If you are opening a transaction, get a lock as well.) | |
2673 |
|
2673 | |||
2674 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2674 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2675 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2675 | 'wlock' first to avoid a dead-lock hazard.''' | |
2676 | l = self._currentlock(self._lockref) |
|
2676 | l = self._currentlock(self._lockref) | |
2677 | if l is not None: |
|
2677 | if l is not None: | |
2678 | l.lock() |
|
2678 | l.lock() | |
2679 | return l |
|
2679 | return l | |
2680 |
|
2680 | |||
2681 | l = self._lock( |
|
2681 | l = self._lock( | |
2682 | vfs=self.svfs, |
|
2682 | vfs=self.svfs, | |
2683 | lockname=b"lock", |
|
2683 | lockname=b"lock", | |
2684 | wait=wait, |
|
2684 | wait=wait, | |
2685 | releasefn=None, |
|
2685 | releasefn=None, | |
2686 | acquirefn=self.invalidate, |
|
2686 | acquirefn=self.invalidate, | |
2687 | desc=_(b'repository %s') % self.origroot, |
|
2687 | desc=_(b'repository %s') % self.origroot, | |
2688 | ) |
|
2688 | ) | |
2689 | self._lockref = weakref.ref(l) |
|
2689 | self._lockref = weakref.ref(l) | |
2690 | return l |
|
2690 | return l | |
2691 |
|
2691 | |||
2692 | def _wlockchecktransaction(self): |
|
2692 | def _wlockchecktransaction(self): | |
2693 | if self.currenttransaction() is not None: |
|
2693 | if self.currenttransaction() is not None: | |
2694 | raise error.LockInheritanceContractViolation( |
|
2694 | raise error.LockInheritanceContractViolation( | |
2695 | b'wlock cannot be inherited in the middle of a transaction' |
|
2695 | b'wlock cannot be inherited in the middle of a transaction' | |
2696 | ) |
|
2696 | ) | |
2697 |
|
2697 | |||
2698 | def wlock(self, wait=True): |
|
2698 | def wlock(self, wait=True): | |
2699 | '''Lock the non-store parts of the repository (everything under |
|
2699 | '''Lock the non-store parts of the repository (everything under | |
2700 | .hg except .hg/store) and return a weak reference to the lock. |
|
2700 | .hg except .hg/store) and return a weak reference to the lock. | |
2701 |
|
2701 | |||
2702 | Use this before modifying files in .hg. |
|
2702 | Use this before modifying files in .hg. | |
2703 |
|
2703 | |||
2704 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2704 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2705 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2705 | 'wlock' first to avoid a dead-lock hazard.''' | |
2706 | l = self._wlockref and self._wlockref() |
|
2706 | l = self._wlockref and self._wlockref() | |
2707 | if l is not None and l.held: |
|
2707 | if l is not None and l.held: | |
2708 | l.lock() |
|
2708 | l.lock() | |
2709 | return l |
|
2709 | return l | |
2710 |
|
2710 | |||
2711 | # We do not need to check for non-waiting lock acquisition. Such |
|
2711 | # We do not need to check for non-waiting lock acquisition. Such | |
2712 | # acquisition would not cause dead-lock as they would just fail. |
|
2712 | # acquisition would not cause dead-lock as they would just fail. | |
2713 | if wait and ( |
|
2713 | if wait and ( | |
2714 | self.ui.configbool(b'devel', b'all-warnings') |
|
2714 | self.ui.configbool(b'devel', b'all-warnings') | |
2715 | or self.ui.configbool(b'devel', b'check-locks') |
|
2715 | or self.ui.configbool(b'devel', b'check-locks') | |
2716 | ): |
|
2716 | ): | |
2717 | if self._currentlock(self._lockref) is not None: |
|
2717 | if self._currentlock(self._lockref) is not None: | |
2718 | self.ui.develwarn(b'"wlock" acquired after "lock"') |
|
2718 | self.ui.develwarn(b'"wlock" acquired after "lock"') | |
2719 |
|
2719 | |||
2720 | def unlock(): |
|
2720 | def unlock(): | |
2721 | if self.dirstate.pendingparentchange(): |
|
2721 | if self.dirstate.pendingparentchange(): | |
2722 | self.dirstate.invalidate() |
|
2722 | self.dirstate.invalidate() | |
2723 | else: |
|
2723 | else: | |
2724 | self.dirstate.write(None) |
|
2724 | self.dirstate.write(None) | |
2725 |
|
2725 | |||
2726 | self._filecache[b'dirstate'].refresh() |
|
2726 | self._filecache[b'dirstate'].refresh() | |
2727 |
|
2727 | |||
2728 | l = self._lock( |
|
2728 | l = self._lock( | |
2729 | self.vfs, |
|
2729 | self.vfs, | |
2730 | b"wlock", |
|
2730 | b"wlock", | |
2731 | wait, |
|
2731 | wait, | |
2732 | unlock, |
|
2732 | unlock, | |
2733 | self.invalidatedirstate, |
|
2733 | self.invalidatedirstate, | |
2734 | _(b'working directory of %s') % self.origroot, |
|
2734 | _(b'working directory of %s') % self.origroot, | |
2735 | inheritchecker=self._wlockchecktransaction, |
|
2735 | inheritchecker=self._wlockchecktransaction, | |
2736 | parentenvvar=b'HG_WLOCK_LOCKER', |
|
2736 | parentenvvar=b'HG_WLOCK_LOCKER', | |
2737 | ) |
|
2737 | ) | |
2738 | self._wlockref = weakref.ref(l) |
|
2738 | self._wlockref = weakref.ref(l) | |
2739 | return l |
|
2739 | return l | |
2740 |
|
2740 | |||
2741 | def _currentlock(self, lockref): |
|
2741 | def _currentlock(self, lockref): | |
2742 | """Returns the lock if it's held, or None if it's not.""" |
|
2742 | """Returns the lock if it's held, or None if it's not.""" | |
2743 | if lockref is None: |
|
2743 | if lockref is None: | |
2744 | return None |
|
2744 | return None | |
2745 | l = lockref() |
|
2745 | l = lockref() | |
2746 | if l is None or not l.held: |
|
2746 | if l is None or not l.held: | |
2747 | return None |
|
2747 | return None | |
2748 | return l |
|
2748 | return l | |
2749 |
|
2749 | |||
2750 | def currentwlock(self): |
|
2750 | def currentwlock(self): | |
2751 | """Returns the wlock if it's held, or None if it's not.""" |
|
2751 | """Returns the wlock if it's held, or None if it's not.""" | |
2752 | return self._currentlock(self._wlockref) |
|
2752 | return self._currentlock(self._wlockref) | |
2753 |
|
2753 | |||
2754 | def _filecommit( |
|
2754 | def _filecommit( | |
2755 | self, |
|
2755 | self, | |
2756 | fctx, |
|
2756 | fctx, | |
2757 | manifest1, |
|
2757 | manifest1, | |
2758 | manifest2, |
|
2758 | manifest2, | |
2759 | linkrev, |
|
2759 | linkrev, | |
2760 | tr, |
|
2760 | tr, | |
2761 | changelist, |
|
2761 | changelist, | |
2762 | includecopymeta, |
|
2762 | includecopymeta, | |
2763 | ): |
|
2763 | ): | |
2764 | """ |
|
2764 | """ | |
2765 | commit an individual file as part of a larger transaction |
|
2765 | commit an individual file as part of a larger transaction | |
2766 | """ |
|
2766 | """ | |
2767 |
|
2767 | |||
2768 | fname = fctx.path() |
|
2768 | fname = fctx.path() | |
2769 | fparent1 = manifest1.get(fname, nullid) |
|
2769 | fparent1 = manifest1.get(fname, nullid) | |
2770 | fparent2 = manifest2.get(fname, nullid) |
|
2770 | fparent2 = manifest2.get(fname, nullid) | |
2771 | if isinstance(fctx, context.filectx): |
|
2771 | if isinstance(fctx, context.filectx): | |
2772 | node = fctx.filenode() |
|
2772 | node = fctx.filenode() | |
2773 | if node in [fparent1, fparent2]: |
|
2773 | if node in [fparent1, fparent2]: | |
2774 | self.ui.debug(b'reusing %s filelog entry\n' % fname) |
|
2774 | self.ui.debug(b'reusing %s filelog entry\n' % fname) | |
2775 | if ( |
|
2775 | if ( | |
2776 | fparent1 != nullid |
|
2776 | fparent1 != nullid | |
2777 | and manifest1.flags(fname) != fctx.flags() |
|
2777 | and manifest1.flags(fname) != fctx.flags() | |
2778 | ) or ( |
|
2778 | ) or ( | |
2779 | fparent2 != nullid |
|
2779 | fparent2 != nullid | |
2780 | and manifest2.flags(fname) != fctx.flags() |
|
2780 | and manifest2.flags(fname) != fctx.flags() | |
2781 | ): |
|
2781 | ): | |
2782 | changelist.append(fname) |
|
2782 | changelist.append(fname) | |
2783 | return node |
|
2783 | return node | |
2784 |
|
2784 | |||
2785 | flog = self.file(fname) |
|
2785 | flog = self.file(fname) | |
2786 | meta = {} |
|
2786 | meta = {} | |
2787 | cfname = fctx.copysource() |
|
2787 | cfname = fctx.copysource() | |
2788 | if cfname and cfname != fname: |
|
2788 | if cfname and cfname != fname: | |
2789 | # Mark the new revision of this file as a copy of another |
|
2789 | # Mark the new revision of this file as a copy of another | |
2790 | # file. This copy data will effectively act as a parent |
|
2790 | # file. This copy data will effectively act as a parent | |
2791 | # of this new revision. If this is a merge, the first |
|
2791 | # of this new revision. If this is a merge, the first | |
2792 | # parent will be the nullid (meaning "look up the copy data") |
|
2792 | # parent will be the nullid (meaning "look up the copy data") | |
2793 | # and the second one will be the other parent. For example: |
|
2793 | # and the second one will be the other parent. For example: | |
2794 | # |
|
2794 | # | |
2795 | # 0 --- 1 --- 3 rev1 changes file foo |
|
2795 | # 0 --- 1 --- 3 rev1 changes file foo | |
2796 | # \ / rev2 renames foo to bar and changes it |
|
2796 | # \ / rev2 renames foo to bar and changes it | |
2797 | # \- 2 -/ rev3 should have bar with all changes and |
|
2797 | # \- 2 -/ rev3 should have bar with all changes and | |
2798 | # should record that bar descends from |
|
2798 | # should record that bar descends from | |
2799 | # bar in rev2 and foo in rev1 |
|
2799 | # bar in rev2 and foo in rev1 | |
2800 | # |
|
2800 | # | |
2801 | # this allows this merge to succeed: |
|
2801 | # this allows this merge to succeed: | |
2802 | # |
|
2802 | # | |
2803 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
2803 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
2804 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
2804 | # \ / merging rev3 and rev4 should use bar@rev2 | |
2805 | # \- 2 --- 4 as the merge base |
|
2805 | # \- 2 --- 4 as the merge base | |
2806 | # |
|
2806 | # | |
2807 |
|
2807 | |||
2808 | cnode = manifest1.get(cfname) |
|
2808 | cnode = manifest1.get(cfname) | |
2809 | newfparent = fparent2 |
|
2809 | newfparent = fparent2 | |
2810 |
|
2810 | |||
2811 | if manifest2: # branch merge |
|
2811 | if manifest2: # branch merge | |
2812 | if fparent2 == nullid or cnode is None: # copied on remote side |
|
2812 | if fparent2 == nullid or cnode is None: # copied on remote side | |
2813 | if cfname in manifest2: |
|
2813 | if cfname in manifest2: | |
2814 | cnode = manifest2[cfname] |
|
2814 | cnode = manifest2[cfname] | |
2815 | newfparent = fparent1 |
|
2815 | newfparent = fparent1 | |
2816 |
|
2816 | |||
2817 | # Here, we used to search backwards through history to try to find |
|
2817 | # Here, we used to search backwards through history to try to find | |
2818 | # where the file copy came from if the source of a copy was not in |
|
2818 | # where the file copy came from if the source of a copy was not in | |
2819 | # the parent directory. However, this doesn't actually make sense to |
|
2819 | # the parent directory. However, this doesn't actually make sense to | |
2820 | # do (what does a copy from something not in your working copy even |
|
2820 | # do (what does a copy from something not in your working copy even | |
2821 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
2821 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
2822 | # the user that copy information was dropped, so if they didn't |
|
2822 | # the user that copy information was dropped, so if they didn't | |
2823 | # expect this outcome it can be fixed, but this is the correct |
|
2823 | # expect this outcome it can be fixed, but this is the correct | |
2824 | # behavior in this circumstance. |
|
2824 | # behavior in this circumstance. | |
2825 |
|
2825 | |||
2826 | if cnode: |
|
2826 | if cnode: | |
2827 | self.ui.debug( |
|
2827 | self.ui.debug( | |
2828 | b" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)) |
|
2828 | b" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)) | |
2829 | ) |
|
2829 | ) | |
2830 | if includecopymeta: |
|
2830 | if includecopymeta: | |
2831 | meta[b"copy"] = cfname |
|
2831 | meta[b"copy"] = cfname | |
2832 | meta[b"copyrev"] = hex(cnode) |
|
2832 | meta[b"copyrev"] = hex(cnode) | |
2833 | fparent1, fparent2 = nullid, newfparent |
|
2833 | fparent1, fparent2 = nullid, newfparent | |
2834 | else: |
|
2834 | else: | |
2835 | self.ui.warn( |
|
2835 | self.ui.warn( | |
2836 | _( |
|
2836 | _( | |
2837 | b"warning: can't find ancestor for '%s' " |
|
2837 | b"warning: can't find ancestor for '%s' " | |
2838 | b"copied from '%s'!\n" |
|
2838 | b"copied from '%s'!\n" | |
2839 | ) |
|
2839 | ) | |
2840 | % (fname, cfname) |
|
2840 | % (fname, cfname) | |
2841 | ) |
|
2841 | ) | |
2842 |
|
2842 | |||
2843 | elif fparent1 == nullid: |
|
2843 | elif fparent1 == nullid: | |
2844 | fparent1, fparent2 = fparent2, nullid |
|
2844 | fparent1, fparent2 = fparent2, nullid | |
2845 | elif fparent2 != nullid: |
|
2845 | elif fparent2 != nullid: | |
2846 | # is one parent an ancestor of the other? |
|
2846 | # is one parent an ancestor of the other? | |
2847 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
2847 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
2848 | if fparent1 in fparentancestors: |
|
2848 | if fparent1 in fparentancestors: | |
2849 | fparent1, fparent2 = fparent2, nullid |
|
2849 | fparent1, fparent2 = fparent2, nullid | |
2850 | elif fparent2 in fparentancestors: |
|
2850 | elif fparent2 in fparentancestors: | |
2851 | fparent2 = nullid |
|
2851 | fparent2 = nullid | |
2852 |
|
2852 | |||
2853 | # is the file changed? |
|
2853 | # is the file changed? | |
2854 | text = fctx.data() |
|
2854 | text = fctx.data() | |
2855 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
2855 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
2856 | changelist.append(fname) |
|
2856 | changelist.append(fname) | |
2857 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
2857 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
2858 | # are just the flags changed during merge? |
|
2858 | # are just the flags changed during merge? | |
2859 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
2859 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
2860 | changelist.append(fname) |
|
2860 | changelist.append(fname) | |
2861 |
|
2861 | |||
2862 | return fparent1 |
|
2862 | return fparent1 | |
2863 |
|
2863 | |||
2864 | def checkcommitpatterns(self, wctx, match, status, fail): |
|
2864 | def checkcommitpatterns(self, wctx, match, status, fail): | |
2865 | """check for commit arguments that aren't committable""" |
|
2865 | """check for commit arguments that aren't committable""" | |
2866 | if match.isexact() or match.prefix(): |
|
2866 | if match.isexact() or match.prefix(): | |
2867 | matched = set(status.modified + status.added + status.removed) |
|
2867 | matched = set(status.modified + status.added + status.removed) | |
2868 |
|
2868 | |||
2869 | for f in match.files(): |
|
2869 | for f in match.files(): | |
2870 | f = self.dirstate.normalize(f) |
|
2870 | f = self.dirstate.normalize(f) | |
2871 | if f == b'.' or f in matched or f in wctx.substate: |
|
2871 | if f == b'.' or f in matched or f in wctx.substate: | |
2872 | continue |
|
2872 | continue | |
2873 | if f in status.deleted: |
|
2873 | if f in status.deleted: | |
2874 | fail(f, _(b'file not found!')) |
|
2874 | fail(f, _(b'file not found!')) | |
2875 | # Is it a directory that exists or used to exist? |
|
2875 | # Is it a directory that exists or used to exist? | |
2876 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): |
|
2876 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): | |
2877 | d = f + b'/' |
|
2877 | d = f + b'/' | |
2878 | for mf in matched: |
|
2878 | for mf in matched: | |
2879 | if mf.startswith(d): |
|
2879 | if mf.startswith(d): | |
2880 | break |
|
2880 | break | |
2881 | else: |
|
2881 | else: | |
2882 | fail(f, _(b"no match under directory!")) |
|
2882 | fail(f, _(b"no match under directory!")) | |
2883 | elif f not in self.dirstate: |
|
2883 | elif f not in self.dirstate: | |
2884 | fail(f, _(b"file not tracked!")) |
|
2884 | fail(f, _(b"file not tracked!")) | |
2885 |
|
2885 | |||
2886 | @unfilteredmethod |
|
2886 | @unfilteredmethod | |
2887 | def commit( |
|
2887 | def commit( | |
2888 | self, |
|
2888 | self, | |
2889 | text=b"", |
|
2889 | text=b"", | |
2890 | user=None, |
|
2890 | user=None, | |
2891 | date=None, |
|
2891 | date=None, | |
2892 | match=None, |
|
2892 | match=None, | |
2893 | force=False, |
|
2893 | force=False, | |
2894 | editor=None, |
|
2894 | editor=None, | |
2895 | extra=None, |
|
2895 | extra=None, | |
2896 | ): |
|
2896 | ): | |
2897 | """Add a new revision to current repository. |
|
2897 | """Add a new revision to current repository. | |
2898 |
|
2898 | |||
2899 | Revision information is gathered from the working directory, |
|
2899 | Revision information is gathered from the working directory, | |
2900 | match can be used to filter the committed files. If editor is |
|
2900 | match can be used to filter the committed files. If editor is | |
2901 | supplied, it is called to get a commit message. |
|
2901 | supplied, it is called to get a commit message. | |
2902 | """ |
|
2902 | """ | |
2903 | if extra is None: |
|
2903 | if extra is None: | |
2904 | extra = {} |
|
2904 | extra = {} | |
2905 |
|
2905 | |||
2906 | def fail(f, msg): |
|
2906 | def fail(f, msg): | |
2907 | raise error.Abort(b'%s: %s' % (f, msg)) |
|
2907 | raise error.Abort(b'%s: %s' % (f, msg)) | |
2908 |
|
2908 | |||
2909 | if not match: |
|
2909 | if not match: | |
2910 | match = matchmod.always() |
|
2910 | match = matchmod.always() | |
2911 |
|
2911 | |||
2912 | if not force: |
|
2912 | if not force: | |
2913 | match.bad = fail |
|
2913 | match.bad = fail | |
2914 |
|
2914 | |||
2915 | # lock() for recent changelog (see issue4368) |
|
2915 | # lock() for recent changelog (see issue4368) | |
2916 | with self.wlock(), self.lock(): |
|
2916 | with self.wlock(), self.lock(): | |
2917 | wctx = self[None] |
|
2917 | wctx = self[None] | |
2918 | merge = len(wctx.parents()) > 1 |
|
2918 | merge = len(wctx.parents()) > 1 | |
2919 |
|
2919 | |||
2920 | if not force and merge and not match.always(): |
|
2920 | if not force and merge and not match.always(): | |
2921 | raise error.Abort( |
|
2921 | raise error.Abort( | |
2922 | _( |
|
2922 | _( | |
2923 | b'cannot partially commit a merge ' |
|
2923 | b'cannot partially commit a merge ' | |
2924 | b'(do not specify files or patterns)' |
|
2924 | b'(do not specify files or patterns)' | |
2925 | ) |
|
2925 | ) | |
2926 | ) |
|
2926 | ) | |
2927 |
|
2927 | |||
2928 | status = self.status(match=match, clean=force) |
|
2928 | status = self.status(match=match, clean=force) | |
2929 | if force: |
|
2929 | if force: | |
2930 | status.modified.extend( |
|
2930 | status.modified.extend( | |
2931 | status.clean |
|
2931 | status.clean | |
2932 | ) # mq may commit clean files |
|
2932 | ) # mq may commit clean files | |
2933 |
|
2933 | |||
2934 | # check subrepos |
|
2934 | # check subrepos | |
2935 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
2935 | subs, commitsubs, newstate = subrepoutil.precommit( | |
2936 | self.ui, wctx, status, match, force=force |
|
2936 | self.ui, wctx, status, match, force=force | |
2937 | ) |
|
2937 | ) | |
2938 |
|
2938 | |||
2939 | # make sure all explicit patterns are matched |
|
2939 | # make sure all explicit patterns are matched | |
2940 | if not force: |
|
2940 | if not force: | |
2941 | self.checkcommitpatterns(wctx, match, status, fail) |
|
2941 | self.checkcommitpatterns(wctx, match, status, fail) | |
2942 |
|
2942 | |||
2943 | cctx = context.workingcommitctx( |
|
2943 | cctx = context.workingcommitctx( | |
2944 | self, status, text, user, date, extra |
|
2944 | self, status, text, user, date, extra | |
2945 | ) |
|
2945 | ) | |
2946 |
|
2946 | |||
2947 | ms = mergemod.mergestate.read(self) |
|
2947 | ms = mergemod.mergestate.read(self) | |
2948 | mergeutil.checkunresolved(ms) |
|
2948 | mergeutil.checkunresolved(ms) | |
2949 |
|
2949 | |||
2950 | # internal config: ui.allowemptycommit |
|
2950 | # internal config: ui.allowemptycommit | |
2951 | allowemptycommit = ( |
|
2951 | allowemptycommit = ( | |
2952 | wctx.branch() != wctx.p1().branch() |
|
2952 | wctx.branch() != wctx.p1().branch() | |
2953 | or extra.get(b'close') |
|
2953 | or extra.get(b'close') | |
2954 | or merge |
|
2954 | or merge | |
2955 | or cctx.files() |
|
2955 | or cctx.files() | |
2956 | or self.ui.configbool(b'ui', b'allowemptycommit') |
|
2956 | or self.ui.configbool(b'ui', b'allowemptycommit') | |
2957 | ) |
|
2957 | ) | |
2958 | if not allowemptycommit: |
|
2958 | if not allowemptycommit: | |
|
2959 | self.ui.debug(b'nothing to commit, clearing merge state\n') | |||
2959 | ms.reset() |
|
2960 | ms.reset() | |
2960 | return None |
|
2961 | return None | |
2961 |
|
2962 | |||
2962 | if merge and cctx.deleted(): |
|
2963 | if merge and cctx.deleted(): | |
2963 | raise error.Abort(_(b"cannot commit merge with missing files")) |
|
2964 | raise error.Abort(_(b"cannot commit merge with missing files")) | |
2964 |
|
2965 | |||
2965 | if editor: |
|
2966 | if editor: | |
2966 | cctx._text = editor(self, cctx, subs) |
|
2967 | cctx._text = editor(self, cctx, subs) | |
2967 | edited = text != cctx._text |
|
2968 | edited = text != cctx._text | |
2968 |
|
2969 | |||
2969 | # Save commit message in case this transaction gets rolled back |
|
2970 | # Save commit message in case this transaction gets rolled back | |
2970 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
2971 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
2971 | # the assumption that the user will use the same editor again. |
|
2972 | # the assumption that the user will use the same editor again. | |
2972 | msgfn = self.savecommitmessage(cctx._text) |
|
2973 | msgfn = self.savecommitmessage(cctx._text) | |
2973 |
|
2974 | |||
2974 | # commit subs and write new state |
|
2975 | # commit subs and write new state | |
2975 | if subs: |
|
2976 | if subs: | |
2976 | uipathfn = scmutil.getuipathfn(self) |
|
2977 | uipathfn = scmutil.getuipathfn(self) | |
2977 | for s in sorted(commitsubs): |
|
2978 | for s in sorted(commitsubs): | |
2978 | sub = wctx.sub(s) |
|
2979 | sub = wctx.sub(s) | |
2979 | self.ui.status( |
|
2980 | self.ui.status( | |
2980 | _(b'committing subrepository %s\n') |
|
2981 | _(b'committing subrepository %s\n') | |
2981 | % uipathfn(subrepoutil.subrelpath(sub)) |
|
2982 | % uipathfn(subrepoutil.subrelpath(sub)) | |
2982 | ) |
|
2983 | ) | |
2983 | sr = sub.commit(cctx._text, user, date) |
|
2984 | sr = sub.commit(cctx._text, user, date) | |
2984 | newstate[s] = (newstate[s][0], sr) |
|
2985 | newstate[s] = (newstate[s][0], sr) | |
2985 | subrepoutil.writestate(self, newstate) |
|
2986 | subrepoutil.writestate(self, newstate) | |
2986 |
|
2987 | |||
2987 | p1, p2 = self.dirstate.parents() |
|
2988 | p1, p2 = self.dirstate.parents() | |
2988 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or b'') |
|
2989 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or b'') | |
2989 | try: |
|
2990 | try: | |
2990 | self.hook( |
|
2991 | self.hook( | |
2991 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 |
|
2992 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 | |
2992 | ) |
|
2993 | ) | |
2993 | with self.transaction(b'commit'): |
|
2994 | with self.transaction(b'commit'): | |
2994 | ret = self.commitctx(cctx, True) |
|
2995 | ret = self.commitctx(cctx, True) | |
2995 | # update bookmarks, dirstate and mergestate |
|
2996 | # update bookmarks, dirstate and mergestate | |
2996 | bookmarks.update(self, [p1, p2], ret) |
|
2997 | bookmarks.update(self, [p1, p2], ret) | |
2997 | cctx.markcommitted(ret) |
|
2998 | cctx.markcommitted(ret) | |
2998 | ms.reset() |
|
2999 | ms.reset() | |
2999 | except: # re-raises |
|
3000 | except: # re-raises | |
3000 | if edited: |
|
3001 | if edited: | |
3001 | self.ui.write( |
|
3002 | self.ui.write( | |
3002 | _(b'note: commit message saved in %s\n') % msgfn |
|
3003 | _(b'note: commit message saved in %s\n') % msgfn | |
3003 | ) |
|
3004 | ) | |
3004 | raise |
|
3005 | raise | |
3005 |
|
3006 | |||
3006 | def commithook(unused_success): |
|
3007 | def commithook(unused_success): | |
3007 | # hack for command that use a temporary commit (eg: histedit) |
|
3008 | # hack for command that use a temporary commit (eg: histedit) | |
3008 | # temporary commit got stripped before hook release |
|
3009 | # temporary commit got stripped before hook release | |
3009 | if self.changelog.hasnode(ret): |
|
3010 | if self.changelog.hasnode(ret): | |
3010 | self.hook( |
|
3011 | self.hook( | |
3011 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 |
|
3012 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 | |
3012 | ) |
|
3013 | ) | |
3013 |
|
3014 | |||
3014 | self._afterlock(commithook) |
|
3015 | self._afterlock(commithook) | |
3015 | return ret |
|
3016 | return ret | |
3016 |
|
3017 | |||
3017 | @unfilteredmethod |
|
3018 | @unfilteredmethod | |
3018 | def commitctx(self, ctx, error=False, origctx=None): |
|
3019 | def commitctx(self, ctx, error=False, origctx=None): | |
3019 | """Add a new revision to current repository. |
|
3020 | """Add a new revision to current repository. | |
3020 | Revision information is passed via the context argument. |
|
3021 | Revision information is passed via the context argument. | |
3021 |
|
3022 | |||
3022 | ctx.files() should list all files involved in this commit, i.e. |
|
3023 | ctx.files() should list all files involved in this commit, i.e. | |
3023 | modified/added/removed files. On merge, it may be wider than the |
|
3024 | modified/added/removed files. On merge, it may be wider than the | |
3024 | ctx.files() to be committed, since any file nodes derived directly |
|
3025 | ctx.files() to be committed, since any file nodes derived directly | |
3025 | from p1 or p2 are excluded from the committed ctx.files(). |
|
3026 | from p1 or p2 are excluded from the committed ctx.files(). | |
3026 |
|
3027 | |||
3027 | origctx is for convert to work around the problem that bug |
|
3028 | origctx is for convert to work around the problem that bug | |
3028 | fixes to the files list in changesets change hashes. For |
|
3029 | fixes to the files list in changesets change hashes. For | |
3029 | convert to be the identity, it can pass an origctx and this |
|
3030 | convert to be the identity, it can pass an origctx and this | |
3030 | function will use the same files list when it makes sense to |
|
3031 | function will use the same files list when it makes sense to | |
3031 | do so. |
|
3032 | do so. | |
3032 | """ |
|
3033 | """ | |
3033 |
|
3034 | |||
3034 | p1, p2 = ctx.p1(), ctx.p2() |
|
3035 | p1, p2 = ctx.p1(), ctx.p2() | |
3035 | user = ctx.user() |
|
3036 | user = ctx.user() | |
3036 |
|
3037 | |||
3037 | if self.filecopiesmode == b'changeset-sidedata': |
|
3038 | if self.filecopiesmode == b'changeset-sidedata': | |
3038 | writechangesetcopy = True |
|
3039 | writechangesetcopy = True | |
3039 | writefilecopymeta = True |
|
3040 | writefilecopymeta = True | |
3040 | writecopiesto = None |
|
3041 | writecopiesto = None | |
3041 | else: |
|
3042 | else: | |
3042 | writecopiesto = self.ui.config(b'experimental', b'copies.write-to') |
|
3043 | writecopiesto = self.ui.config(b'experimental', b'copies.write-to') | |
3043 | writefilecopymeta = writecopiesto != b'changeset-only' |
|
3044 | writefilecopymeta = writecopiesto != b'changeset-only' | |
3044 | writechangesetcopy = writecopiesto in ( |
|
3045 | writechangesetcopy = writecopiesto in ( | |
3045 | b'changeset-only', |
|
3046 | b'changeset-only', | |
3046 | b'compatibility', |
|
3047 | b'compatibility', | |
3047 | ) |
|
3048 | ) | |
3048 | p1copies, p2copies = None, None |
|
3049 | p1copies, p2copies = None, None | |
3049 | if writechangesetcopy: |
|
3050 | if writechangesetcopy: | |
3050 | p1copies = ctx.p1copies() |
|
3051 | p1copies = ctx.p1copies() | |
3051 | p2copies = ctx.p2copies() |
|
3052 | p2copies = ctx.p2copies() | |
3052 | filesadded, filesremoved = None, None |
|
3053 | filesadded, filesremoved = None, None | |
3053 | with self.lock(), self.transaction(b"commit") as tr: |
|
3054 | with self.lock(), self.transaction(b"commit") as tr: | |
3054 | trp = weakref.proxy(tr) |
|
3055 | trp = weakref.proxy(tr) | |
3055 |
|
3056 | |||
3056 | if ctx.manifestnode(): |
|
3057 | if ctx.manifestnode(): | |
3057 | # reuse an existing manifest revision |
|
3058 | # reuse an existing manifest revision | |
3058 | self.ui.debug(b'reusing known manifest\n') |
|
3059 | self.ui.debug(b'reusing known manifest\n') | |
3059 | mn = ctx.manifestnode() |
|
3060 | mn = ctx.manifestnode() | |
3060 | files = ctx.files() |
|
3061 | files = ctx.files() | |
3061 | if writechangesetcopy: |
|
3062 | if writechangesetcopy: | |
3062 | filesadded = ctx.filesadded() |
|
3063 | filesadded = ctx.filesadded() | |
3063 | filesremoved = ctx.filesremoved() |
|
3064 | filesremoved = ctx.filesremoved() | |
3064 | elif ctx.files(): |
|
3065 | elif ctx.files(): | |
3065 | m1ctx = p1.manifestctx() |
|
3066 | m1ctx = p1.manifestctx() | |
3066 | m2ctx = p2.manifestctx() |
|
3067 | m2ctx = p2.manifestctx() | |
3067 | mctx = m1ctx.copy() |
|
3068 | mctx = m1ctx.copy() | |
3068 |
|
3069 | |||
3069 | m = mctx.read() |
|
3070 | m = mctx.read() | |
3070 | m1 = m1ctx.read() |
|
3071 | m1 = m1ctx.read() | |
3071 | m2 = m2ctx.read() |
|
3072 | m2 = m2ctx.read() | |
3072 |
|
3073 | |||
3073 | # check in files |
|
3074 | # check in files | |
3074 | added = [] |
|
3075 | added = [] | |
3075 | changed = [] |
|
3076 | changed = [] | |
3076 | removed = list(ctx.removed()) |
|
3077 | removed = list(ctx.removed()) | |
3077 | linkrev = len(self) |
|
3078 | linkrev = len(self) | |
3078 | self.ui.note(_(b"committing files:\n")) |
|
3079 | self.ui.note(_(b"committing files:\n")) | |
3079 | uipathfn = scmutil.getuipathfn(self) |
|
3080 | uipathfn = scmutil.getuipathfn(self) | |
3080 | for f in sorted(ctx.modified() + ctx.added()): |
|
3081 | for f in sorted(ctx.modified() + ctx.added()): | |
3081 | self.ui.note(uipathfn(f) + b"\n") |
|
3082 | self.ui.note(uipathfn(f) + b"\n") | |
3082 | try: |
|
3083 | try: | |
3083 | fctx = ctx[f] |
|
3084 | fctx = ctx[f] | |
3084 | if fctx is None: |
|
3085 | if fctx is None: | |
3085 | removed.append(f) |
|
3086 | removed.append(f) | |
3086 | else: |
|
3087 | else: | |
3087 | added.append(f) |
|
3088 | added.append(f) | |
3088 | m[f] = self._filecommit( |
|
3089 | m[f] = self._filecommit( | |
3089 | fctx, |
|
3090 | fctx, | |
3090 | m1, |
|
3091 | m1, | |
3091 | m2, |
|
3092 | m2, | |
3092 | linkrev, |
|
3093 | linkrev, | |
3093 | trp, |
|
3094 | trp, | |
3094 | changed, |
|
3095 | changed, | |
3095 | writefilecopymeta, |
|
3096 | writefilecopymeta, | |
3096 | ) |
|
3097 | ) | |
3097 | m.setflag(f, fctx.flags()) |
|
3098 | m.setflag(f, fctx.flags()) | |
3098 | except OSError: |
|
3099 | except OSError: | |
3099 | self.ui.warn( |
|
3100 | self.ui.warn( | |
3100 | _(b"trouble committing %s!\n") % uipathfn(f) |
|
3101 | _(b"trouble committing %s!\n") % uipathfn(f) | |
3101 | ) |
|
3102 | ) | |
3102 | raise |
|
3103 | raise | |
3103 | except IOError as inst: |
|
3104 | except IOError as inst: | |
3104 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
3105 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
3105 | if error or errcode and errcode != errno.ENOENT: |
|
3106 | if error or errcode and errcode != errno.ENOENT: | |
3106 | self.ui.warn( |
|
3107 | self.ui.warn( | |
3107 | _(b"trouble committing %s!\n") % uipathfn(f) |
|
3108 | _(b"trouble committing %s!\n") % uipathfn(f) | |
3108 | ) |
|
3109 | ) | |
3109 | raise |
|
3110 | raise | |
3110 |
|
3111 | |||
3111 | # update manifest |
|
3112 | # update manifest | |
3112 | removed = [f for f in removed if f in m1 or f in m2] |
|
3113 | removed = [f for f in removed if f in m1 or f in m2] | |
3113 | drop = sorted([f for f in removed if f in m]) |
|
3114 | drop = sorted([f for f in removed if f in m]) | |
3114 | for f in drop: |
|
3115 | for f in drop: | |
3115 | del m[f] |
|
3116 | del m[f] | |
3116 | if p2.rev() != nullrev: |
|
3117 | if p2.rev() != nullrev: | |
3117 |
|
3118 | |||
3118 | @util.cachefunc |
|
3119 | @util.cachefunc | |
3119 | def mas(): |
|
3120 | def mas(): | |
3120 | p1n = p1.node() |
|
3121 | p1n = p1.node() | |
3121 | p2n = p2.node() |
|
3122 | p2n = p2.node() | |
3122 | cahs = self.changelog.commonancestorsheads(p1n, p2n) |
|
3123 | cahs = self.changelog.commonancestorsheads(p1n, p2n) | |
3123 | if not cahs: |
|
3124 | if not cahs: | |
3124 | cahs = [nullrev] |
|
3125 | cahs = [nullrev] | |
3125 | return [self[r].manifest() for r in cahs] |
|
3126 | return [self[r].manifest() for r in cahs] | |
3126 |
|
3127 | |||
3127 | def deletionfromparent(f): |
|
3128 | def deletionfromparent(f): | |
3128 | # When a file is removed relative to p1 in a merge, this |
|
3129 | # When a file is removed relative to p1 in a merge, this | |
3129 | # function determines whether the absence is due to a |
|
3130 | # function determines whether the absence is due to a | |
3130 | # deletion from a parent, or whether the merge commit |
|
3131 | # deletion from a parent, or whether the merge commit | |
3131 | # itself deletes the file. We decide this by doing a |
|
3132 | # itself deletes the file. We decide this by doing a | |
3132 | # simplified three way merge of the manifest entry for |
|
3133 | # simplified three way merge of the manifest entry for | |
3133 | # the file. There are two ways we decide the merge |
|
3134 | # the file. There are two ways we decide the merge | |
3134 | # itself didn't delete a file: |
|
3135 | # itself didn't delete a file: | |
3135 | # - neither parent (nor the merge) contain the file |
|
3136 | # - neither parent (nor the merge) contain the file | |
3136 | # - exactly one parent contains the file, and that |
|
3137 | # - exactly one parent contains the file, and that | |
3137 | # parent has the same filelog entry as the merge |
|
3138 | # parent has the same filelog entry as the merge | |
3138 | # ancestor (or all of them if there two). In other |
|
3139 | # ancestor (or all of them if there two). In other | |
3139 | # words, that parent left the file unchanged while the |
|
3140 | # words, that parent left the file unchanged while the | |
3140 | # other one deleted it. |
|
3141 | # other one deleted it. | |
3141 | # One way to think about this is that deleting a file is |
|
3142 | # One way to think about this is that deleting a file is | |
3142 | # similar to emptying it, so the list of changed files |
|
3143 | # similar to emptying it, so the list of changed files | |
3143 | # should be similar either way. The computation |
|
3144 | # should be similar either way. The computation | |
3144 | # described above is not done directly in _filecommit |
|
3145 | # described above is not done directly in _filecommit | |
3145 | # when creating the list of changed files, however |
|
3146 | # when creating the list of changed files, however | |
3146 | # it does something very similar by comparing filelog |
|
3147 | # it does something very similar by comparing filelog | |
3147 | # nodes. |
|
3148 | # nodes. | |
3148 | if f in m1: |
|
3149 | if f in m1: | |
3149 | return f not in m2 and all( |
|
3150 | return f not in m2 and all( | |
3150 | f in ma and ma.find(f) == m1.find(f) |
|
3151 | f in ma and ma.find(f) == m1.find(f) | |
3151 | for ma in mas() |
|
3152 | for ma in mas() | |
3152 | ) |
|
3153 | ) | |
3153 | elif f in m2: |
|
3154 | elif f in m2: | |
3154 | return all( |
|
3155 | return all( | |
3155 | f in ma and ma.find(f) == m2.find(f) |
|
3156 | f in ma and ma.find(f) == m2.find(f) | |
3156 | for ma in mas() |
|
3157 | for ma in mas() | |
3157 | ) |
|
3158 | ) | |
3158 | else: |
|
3159 | else: | |
3159 | return True |
|
3160 | return True | |
3160 |
|
3161 | |||
3161 | removed = [f for f in removed if not deletionfromparent(f)] |
|
3162 | removed = [f for f in removed if not deletionfromparent(f)] | |
3162 |
|
3163 | |||
3163 | files = changed + removed |
|
3164 | files = changed + removed | |
3164 | md = None |
|
3165 | md = None | |
3165 | if not files: |
|
3166 | if not files: | |
3166 | # if no "files" actually changed in terms of the changelog, |
|
3167 | # if no "files" actually changed in terms of the changelog, | |
3167 | # try hard to detect unmodified manifest entry so that the |
|
3168 | # try hard to detect unmodified manifest entry so that the | |
3168 | # exact same commit can be reproduced later on convert. |
|
3169 | # exact same commit can be reproduced later on convert. | |
3169 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) |
|
3170 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) | |
3170 | if not files and md: |
|
3171 | if not files and md: | |
3171 | self.ui.debug( |
|
3172 | self.ui.debug( | |
3172 | b'not reusing manifest (no file change in ' |
|
3173 | b'not reusing manifest (no file change in ' | |
3173 | b'changelog, but manifest differs)\n' |
|
3174 | b'changelog, but manifest differs)\n' | |
3174 | ) |
|
3175 | ) | |
3175 | if files or md: |
|
3176 | if files or md: | |
3176 | self.ui.note(_(b"committing manifest\n")) |
|
3177 | self.ui.note(_(b"committing manifest\n")) | |
3177 | # we're using narrowmatch here since it's already applied at |
|
3178 | # we're using narrowmatch here since it's already applied at | |
3178 | # other stages (such as dirstate.walk), so we're already |
|
3179 | # other stages (such as dirstate.walk), so we're already | |
3179 | # ignoring things outside of narrowspec in most cases. The |
|
3180 | # ignoring things outside of narrowspec in most cases. The | |
3180 | # one case where we might have files outside the narrowspec |
|
3181 | # one case where we might have files outside the narrowspec | |
3181 | # at this point is merges, and we already error out in the |
|
3182 | # at this point is merges, and we already error out in the | |
3182 | # case where the merge has files outside of the narrowspec, |
|
3183 | # case where the merge has files outside of the narrowspec, | |
3183 | # so this is safe. |
|
3184 | # so this is safe. | |
3184 | mn = mctx.write( |
|
3185 | mn = mctx.write( | |
3185 | trp, |
|
3186 | trp, | |
3186 | linkrev, |
|
3187 | linkrev, | |
3187 | p1.manifestnode(), |
|
3188 | p1.manifestnode(), | |
3188 | p2.manifestnode(), |
|
3189 | p2.manifestnode(), | |
3189 | added, |
|
3190 | added, | |
3190 | drop, |
|
3191 | drop, | |
3191 | match=self.narrowmatch(), |
|
3192 | match=self.narrowmatch(), | |
3192 | ) |
|
3193 | ) | |
3193 |
|
3194 | |||
3194 | if writechangesetcopy: |
|
3195 | if writechangesetcopy: | |
3195 | filesadded = [ |
|
3196 | filesadded = [ | |
3196 | f for f in changed if not (f in m1 or f in m2) |
|
3197 | f for f in changed if not (f in m1 or f in m2) | |
3197 | ] |
|
3198 | ] | |
3198 | filesremoved = removed |
|
3199 | filesremoved = removed | |
3199 | else: |
|
3200 | else: | |
3200 | self.ui.debug( |
|
3201 | self.ui.debug( | |
3201 | b'reusing manifest from p1 (listed files ' |
|
3202 | b'reusing manifest from p1 (listed files ' | |
3202 | b'actually unchanged)\n' |
|
3203 | b'actually unchanged)\n' | |
3203 | ) |
|
3204 | ) | |
3204 | mn = p1.manifestnode() |
|
3205 | mn = p1.manifestnode() | |
3205 | else: |
|
3206 | else: | |
3206 | self.ui.debug(b'reusing manifest from p1 (no file change)\n') |
|
3207 | self.ui.debug(b'reusing manifest from p1 (no file change)\n') | |
3207 | mn = p1.manifestnode() |
|
3208 | mn = p1.manifestnode() | |
3208 | files = [] |
|
3209 | files = [] | |
3209 |
|
3210 | |||
3210 | if writecopiesto == b'changeset-only': |
|
3211 | if writecopiesto == b'changeset-only': | |
3211 | # If writing only to changeset extras, use None to indicate that |
|
3212 | # If writing only to changeset extras, use None to indicate that | |
3212 | # no entry should be written. If writing to both, write an empty |
|
3213 | # no entry should be written. If writing to both, write an empty | |
3213 | # entry to prevent the reader from falling back to reading |
|
3214 | # entry to prevent the reader from falling back to reading | |
3214 | # filelogs. |
|
3215 | # filelogs. | |
3215 | p1copies = p1copies or None |
|
3216 | p1copies = p1copies or None | |
3216 | p2copies = p2copies or None |
|
3217 | p2copies = p2copies or None | |
3217 | filesadded = filesadded or None |
|
3218 | filesadded = filesadded or None | |
3218 | filesremoved = filesremoved or None |
|
3219 | filesremoved = filesremoved or None | |
3219 |
|
3220 | |||
3220 | if origctx and origctx.manifestnode() == mn: |
|
3221 | if origctx and origctx.manifestnode() == mn: | |
3221 | files = origctx.files() |
|
3222 | files = origctx.files() | |
3222 |
|
3223 | |||
3223 | # update changelog |
|
3224 | # update changelog | |
3224 | self.ui.note(_(b"committing changelog\n")) |
|
3225 | self.ui.note(_(b"committing changelog\n")) | |
3225 | self.changelog.delayupdate(tr) |
|
3226 | self.changelog.delayupdate(tr) | |
3226 | n = self.changelog.add( |
|
3227 | n = self.changelog.add( | |
3227 | mn, |
|
3228 | mn, | |
3228 | files, |
|
3229 | files, | |
3229 | ctx.description(), |
|
3230 | ctx.description(), | |
3230 | trp, |
|
3231 | trp, | |
3231 | p1.node(), |
|
3232 | p1.node(), | |
3232 | p2.node(), |
|
3233 | p2.node(), | |
3233 | user, |
|
3234 | user, | |
3234 | ctx.date(), |
|
3235 | ctx.date(), | |
3235 | ctx.extra().copy(), |
|
3236 | ctx.extra().copy(), | |
3236 | p1copies, |
|
3237 | p1copies, | |
3237 | p2copies, |
|
3238 | p2copies, | |
3238 | filesadded, |
|
3239 | filesadded, | |
3239 | filesremoved, |
|
3240 | filesremoved, | |
3240 | ) |
|
3241 | ) | |
3241 | xp1, xp2 = p1.hex(), p2 and p2.hex() or b'' |
|
3242 | xp1, xp2 = p1.hex(), p2 and p2.hex() or b'' | |
3242 | self.hook( |
|
3243 | self.hook( | |
3243 | b'pretxncommit', |
|
3244 | b'pretxncommit', | |
3244 | throw=True, |
|
3245 | throw=True, | |
3245 | node=hex(n), |
|
3246 | node=hex(n), | |
3246 | parent1=xp1, |
|
3247 | parent1=xp1, | |
3247 | parent2=xp2, |
|
3248 | parent2=xp2, | |
3248 | ) |
|
3249 | ) | |
3249 | # set the new commit is proper phase |
|
3250 | # set the new commit is proper phase | |
3250 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
3251 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
3251 | if targetphase: |
|
3252 | if targetphase: | |
3252 | # retract boundary do not alter parent changeset. |
|
3253 | # retract boundary do not alter parent changeset. | |
3253 | # if a parent have higher the resulting phase will |
|
3254 | # if a parent have higher the resulting phase will | |
3254 | # be compliant anyway |
|
3255 | # be compliant anyway | |
3255 | # |
|
3256 | # | |
3256 | # if minimal phase was 0 we don't need to retract anything |
|
3257 | # if minimal phase was 0 we don't need to retract anything | |
3257 | phases.registernew(self, tr, targetphase, [n]) |
|
3258 | phases.registernew(self, tr, targetphase, [n]) | |
3258 | return n |
|
3259 | return n | |
3259 |
|
3260 | |||
3260 | @unfilteredmethod |
|
3261 | @unfilteredmethod | |
3261 | def destroying(self): |
|
3262 | def destroying(self): | |
3262 | '''Inform the repository that nodes are about to be destroyed. |
|
3263 | '''Inform the repository that nodes are about to be destroyed. | |
3263 | Intended for use by strip and rollback, so there's a common |
|
3264 | Intended for use by strip and rollback, so there's a common | |
3264 | place for anything that has to be done before destroying history. |
|
3265 | place for anything that has to be done before destroying history. | |
3265 |
|
3266 | |||
3266 | This is mostly useful for saving state that is in memory and waiting |
|
3267 | This is mostly useful for saving state that is in memory and waiting | |
3267 | to be flushed when the current lock is released. Because a call to |
|
3268 | to be flushed when the current lock is released. Because a call to | |
3268 | destroyed is imminent, the repo will be invalidated causing those |
|
3269 | destroyed is imminent, the repo will be invalidated causing those | |
3269 | changes to stay in memory (waiting for the next unlock), or vanish |
|
3270 | changes to stay in memory (waiting for the next unlock), or vanish | |
3270 | completely. |
|
3271 | completely. | |
3271 | ''' |
|
3272 | ''' | |
3272 | # When using the same lock to commit and strip, the phasecache is left |
|
3273 | # When using the same lock to commit and strip, the phasecache is left | |
3273 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
3274 | # dirty after committing. Then when we strip, the repo is invalidated, | |
3274 | # causing those changes to disappear. |
|
3275 | # causing those changes to disappear. | |
3275 | if '_phasecache' in vars(self): |
|
3276 | if '_phasecache' in vars(self): | |
3276 | self._phasecache.write() |
|
3277 | self._phasecache.write() | |
3277 |
|
3278 | |||
3278 | @unfilteredmethod |
|
3279 | @unfilteredmethod | |
3279 | def destroyed(self): |
|
3280 | def destroyed(self): | |
3280 | '''Inform the repository that nodes have been destroyed. |
|
3281 | '''Inform the repository that nodes have been destroyed. | |
3281 | Intended for use by strip and rollback, so there's a common |
|
3282 | Intended for use by strip and rollback, so there's a common | |
3282 | place for anything that has to be done after destroying history. |
|
3283 | place for anything that has to be done after destroying history. | |
3283 | ''' |
|
3284 | ''' | |
3284 | # When one tries to: |
|
3285 | # When one tries to: | |
3285 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
3286 | # 1) destroy nodes thus calling this method (e.g. strip) | |
3286 | # 2) use phasecache somewhere (e.g. commit) |
|
3287 | # 2) use phasecache somewhere (e.g. commit) | |
3287 | # |
|
3288 | # | |
3288 | # then 2) will fail because the phasecache contains nodes that were |
|
3289 | # then 2) will fail because the phasecache contains nodes that were | |
3289 | # removed. We can either remove phasecache from the filecache, |
|
3290 | # removed. We can either remove phasecache from the filecache, | |
3290 | # causing it to reload next time it is accessed, or simply filter |
|
3291 | # causing it to reload next time it is accessed, or simply filter | |
3291 | # the removed nodes now and write the updated cache. |
|
3292 | # the removed nodes now and write the updated cache. | |
3292 | self._phasecache.filterunknown(self) |
|
3293 | self._phasecache.filterunknown(self) | |
3293 | self._phasecache.write() |
|
3294 | self._phasecache.write() | |
3294 |
|
3295 | |||
3295 | # refresh all repository caches |
|
3296 | # refresh all repository caches | |
3296 | self.updatecaches() |
|
3297 | self.updatecaches() | |
3297 |
|
3298 | |||
3298 | # Ensure the persistent tag cache is updated. Doing it now |
|
3299 | # Ensure the persistent tag cache is updated. Doing it now | |
3299 | # means that the tag cache only has to worry about destroyed |
|
3300 | # means that the tag cache only has to worry about destroyed | |
3300 | # heads immediately after a strip/rollback. That in turn |
|
3301 | # heads immediately after a strip/rollback. That in turn | |
3301 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
3302 | # guarantees that "cachetip == currenttip" (comparing both rev | |
3302 | # and node) always means no nodes have been added or destroyed. |
|
3303 | # and node) always means no nodes have been added or destroyed. | |
3303 |
|
3304 | |||
3304 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
3305 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
3305 | # head, refresh the tag cache, then immediately add a new head. |
|
3306 | # head, refresh the tag cache, then immediately add a new head. | |
3306 | # But I think doing it this way is necessary for the "instant |
|
3307 | # But I think doing it this way is necessary for the "instant | |
3307 | # tag cache retrieval" case to work. |
|
3308 | # tag cache retrieval" case to work. | |
3308 | self.invalidate() |
|
3309 | self.invalidate() | |
3309 |
|
3310 | |||
3310 | def status( |
|
3311 | def status( | |
3311 | self, |
|
3312 | self, | |
3312 | node1=b'.', |
|
3313 | node1=b'.', | |
3313 | node2=None, |
|
3314 | node2=None, | |
3314 | match=None, |
|
3315 | match=None, | |
3315 | ignored=False, |
|
3316 | ignored=False, | |
3316 | clean=False, |
|
3317 | clean=False, | |
3317 | unknown=False, |
|
3318 | unknown=False, | |
3318 | listsubrepos=False, |
|
3319 | listsubrepos=False, | |
3319 | ): |
|
3320 | ): | |
3320 | '''a convenience method that calls node1.status(node2)''' |
|
3321 | '''a convenience method that calls node1.status(node2)''' | |
3321 | return self[node1].status( |
|
3322 | return self[node1].status( | |
3322 | node2, match, ignored, clean, unknown, listsubrepos |
|
3323 | node2, match, ignored, clean, unknown, listsubrepos | |
3323 | ) |
|
3324 | ) | |
3324 |
|
3325 | |||
3325 | def addpostdsstatus(self, ps): |
|
3326 | def addpostdsstatus(self, ps): | |
3326 | """Add a callback to run within the wlock, at the point at which status |
|
3327 | """Add a callback to run within the wlock, at the point at which status | |
3327 | fixups happen. |
|
3328 | fixups happen. | |
3328 |
|
3329 | |||
3329 | On status completion, callback(wctx, status) will be called with the |
|
3330 | On status completion, callback(wctx, status) will be called with the | |
3330 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
3331 | wlock held, unless the dirstate has changed from underneath or the wlock | |
3331 | couldn't be grabbed. |
|
3332 | couldn't be grabbed. | |
3332 |
|
3333 | |||
3333 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
3334 | Callbacks should not capture and use a cached copy of the dirstate -- | |
3334 | it might change in the meanwhile. Instead, they should access the |
|
3335 | it might change in the meanwhile. Instead, they should access the | |
3335 | dirstate via wctx.repo().dirstate. |
|
3336 | dirstate via wctx.repo().dirstate. | |
3336 |
|
3337 | |||
3337 | This list is emptied out after each status run -- extensions should |
|
3338 | This list is emptied out after each status run -- extensions should | |
3338 | make sure it adds to this list each time dirstate.status is called. |
|
3339 | make sure it adds to this list each time dirstate.status is called. | |
3339 | Extensions should also make sure they don't call this for statuses |
|
3340 | Extensions should also make sure they don't call this for statuses | |
3340 | that don't involve the dirstate. |
|
3341 | that don't involve the dirstate. | |
3341 | """ |
|
3342 | """ | |
3342 |
|
3343 | |||
3343 | # The list is located here for uniqueness reasons -- it is actually |
|
3344 | # The list is located here for uniqueness reasons -- it is actually | |
3344 | # managed by the workingctx, but that isn't unique per-repo. |
|
3345 | # managed by the workingctx, but that isn't unique per-repo. | |
3345 | self._postdsstatus.append(ps) |
|
3346 | self._postdsstatus.append(ps) | |
3346 |
|
3347 | |||
3347 | def postdsstatus(self): |
|
3348 | def postdsstatus(self): | |
3348 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
3349 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
3349 | return self._postdsstatus |
|
3350 | return self._postdsstatus | |
3350 |
|
3351 | |||
3351 | def clearpostdsstatus(self): |
|
3352 | def clearpostdsstatus(self): | |
3352 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
3353 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
3353 | del self._postdsstatus[:] |
|
3354 | del self._postdsstatus[:] | |
3354 |
|
3355 | |||
3355 | def heads(self, start=None): |
|
3356 | def heads(self, start=None): | |
3356 | if start is None: |
|
3357 | if start is None: | |
3357 | cl = self.changelog |
|
3358 | cl = self.changelog | |
3358 | headrevs = reversed(cl.headrevs()) |
|
3359 | headrevs = reversed(cl.headrevs()) | |
3359 | return [cl.node(rev) for rev in headrevs] |
|
3360 | return [cl.node(rev) for rev in headrevs] | |
3360 |
|
3361 | |||
3361 | heads = self.changelog.heads(start) |
|
3362 | heads = self.changelog.heads(start) | |
3362 | # sort the output in rev descending order |
|
3363 | # sort the output in rev descending order | |
3363 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
3364 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
3364 |
|
3365 | |||
3365 | def branchheads(self, branch=None, start=None, closed=False): |
|
3366 | def branchheads(self, branch=None, start=None, closed=False): | |
3366 | '''return a (possibly filtered) list of heads for the given branch |
|
3367 | '''return a (possibly filtered) list of heads for the given branch | |
3367 |
|
3368 | |||
3368 | Heads are returned in topological order, from newest to oldest. |
|
3369 | Heads are returned in topological order, from newest to oldest. | |
3369 | If branch is None, use the dirstate branch. |
|
3370 | If branch is None, use the dirstate branch. | |
3370 | If start is not None, return only heads reachable from start. |
|
3371 | If start is not None, return only heads reachable from start. | |
3371 | If closed is True, return heads that are marked as closed as well. |
|
3372 | If closed is True, return heads that are marked as closed as well. | |
3372 | ''' |
|
3373 | ''' | |
3373 | if branch is None: |
|
3374 | if branch is None: | |
3374 | branch = self[None].branch() |
|
3375 | branch = self[None].branch() | |
3375 | branches = self.branchmap() |
|
3376 | branches = self.branchmap() | |
3376 | if not branches.hasbranch(branch): |
|
3377 | if not branches.hasbranch(branch): | |
3377 | return [] |
|
3378 | return [] | |
3378 | # the cache returns heads ordered lowest to highest |
|
3379 | # the cache returns heads ordered lowest to highest | |
3379 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
3380 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
3380 | if start is not None: |
|
3381 | if start is not None: | |
3381 | # filter out the heads that cannot be reached from startrev |
|
3382 | # filter out the heads that cannot be reached from startrev | |
3382 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
3383 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
3383 | bheads = [h for h in bheads if h in fbheads] |
|
3384 | bheads = [h for h in bheads if h in fbheads] | |
3384 | return bheads |
|
3385 | return bheads | |
3385 |
|
3386 | |||
3386 | def branches(self, nodes): |
|
3387 | def branches(self, nodes): | |
3387 | if not nodes: |
|
3388 | if not nodes: | |
3388 | nodes = [self.changelog.tip()] |
|
3389 | nodes = [self.changelog.tip()] | |
3389 | b = [] |
|
3390 | b = [] | |
3390 | for n in nodes: |
|
3391 | for n in nodes: | |
3391 | t = n |
|
3392 | t = n | |
3392 | while True: |
|
3393 | while True: | |
3393 | p = self.changelog.parents(n) |
|
3394 | p = self.changelog.parents(n) | |
3394 | if p[1] != nullid or p[0] == nullid: |
|
3395 | if p[1] != nullid or p[0] == nullid: | |
3395 | b.append((t, n, p[0], p[1])) |
|
3396 | b.append((t, n, p[0], p[1])) | |
3396 | break |
|
3397 | break | |
3397 | n = p[0] |
|
3398 | n = p[0] | |
3398 | return b |
|
3399 | return b | |
3399 |
|
3400 | |||
3400 | def between(self, pairs): |
|
3401 | def between(self, pairs): | |
3401 | r = [] |
|
3402 | r = [] | |
3402 |
|
3403 | |||
3403 | for top, bottom in pairs: |
|
3404 | for top, bottom in pairs: | |
3404 | n, l, i = top, [], 0 |
|
3405 | n, l, i = top, [], 0 | |
3405 | f = 1 |
|
3406 | f = 1 | |
3406 |
|
3407 | |||
3407 | while n != bottom and n != nullid: |
|
3408 | while n != bottom and n != nullid: | |
3408 | p = self.changelog.parents(n)[0] |
|
3409 | p = self.changelog.parents(n)[0] | |
3409 | if i == f: |
|
3410 | if i == f: | |
3410 | l.append(n) |
|
3411 | l.append(n) | |
3411 | f = f * 2 |
|
3412 | f = f * 2 | |
3412 | n = p |
|
3413 | n = p | |
3413 | i += 1 |
|
3414 | i += 1 | |
3414 |
|
3415 | |||
3415 | r.append(l) |
|
3416 | r.append(l) | |
3416 |
|
3417 | |||
3417 | return r |
|
3418 | return r | |
3418 |
|
3419 | |||
3419 | def checkpush(self, pushop): |
|
3420 | def checkpush(self, pushop): | |
3420 | """Extensions can override this function if additional checks have |
|
3421 | """Extensions can override this function if additional checks have | |
3421 | to be performed before pushing, or call it if they override push |
|
3422 | to be performed before pushing, or call it if they override push | |
3422 | command. |
|
3423 | command. | |
3423 | """ |
|
3424 | """ | |
3424 |
|
3425 | |||
3425 | @unfilteredpropertycache |
|
3426 | @unfilteredpropertycache | |
3426 | def prepushoutgoinghooks(self): |
|
3427 | def prepushoutgoinghooks(self): | |
3427 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
3428 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
3428 | methods, which are called before pushing changesets. |
|
3429 | methods, which are called before pushing changesets. | |
3429 | """ |
|
3430 | """ | |
3430 | return util.hooks() |
|
3431 | return util.hooks() | |
3431 |
|
3432 | |||
3432 | def pushkey(self, namespace, key, old, new): |
|
3433 | def pushkey(self, namespace, key, old, new): | |
3433 | try: |
|
3434 | try: | |
3434 | tr = self.currenttransaction() |
|
3435 | tr = self.currenttransaction() | |
3435 | hookargs = {} |
|
3436 | hookargs = {} | |
3436 | if tr is not None: |
|
3437 | if tr is not None: | |
3437 | hookargs.update(tr.hookargs) |
|
3438 | hookargs.update(tr.hookargs) | |
3438 | hookargs = pycompat.strkwargs(hookargs) |
|
3439 | hookargs = pycompat.strkwargs(hookargs) | |
3439 | hookargs['namespace'] = namespace |
|
3440 | hookargs['namespace'] = namespace | |
3440 | hookargs['key'] = key |
|
3441 | hookargs['key'] = key | |
3441 | hookargs['old'] = old |
|
3442 | hookargs['old'] = old | |
3442 | hookargs['new'] = new |
|
3443 | hookargs['new'] = new | |
3443 | self.hook(b'prepushkey', throw=True, **hookargs) |
|
3444 | self.hook(b'prepushkey', throw=True, **hookargs) | |
3444 | except error.HookAbort as exc: |
|
3445 | except error.HookAbort as exc: | |
3445 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) |
|
3446 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) | |
3446 | if exc.hint: |
|
3447 | if exc.hint: | |
3447 | self.ui.write_err(_(b"(%s)\n") % exc.hint) |
|
3448 | self.ui.write_err(_(b"(%s)\n") % exc.hint) | |
3448 | return False |
|
3449 | return False | |
3449 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) |
|
3450 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) | |
3450 | ret = pushkey.push(self, namespace, key, old, new) |
|
3451 | ret = pushkey.push(self, namespace, key, old, new) | |
3451 |
|
3452 | |||
3452 | def runhook(unused_success): |
|
3453 | def runhook(unused_success): | |
3453 | self.hook( |
|
3454 | self.hook( | |
3454 | b'pushkey', |
|
3455 | b'pushkey', | |
3455 | namespace=namespace, |
|
3456 | namespace=namespace, | |
3456 | key=key, |
|
3457 | key=key, | |
3457 | old=old, |
|
3458 | old=old, | |
3458 | new=new, |
|
3459 | new=new, | |
3459 | ret=ret, |
|
3460 | ret=ret, | |
3460 | ) |
|
3461 | ) | |
3461 |
|
3462 | |||
3462 | self._afterlock(runhook) |
|
3463 | self._afterlock(runhook) | |
3463 | return ret |
|
3464 | return ret | |
3464 |
|
3465 | |||
3465 | def listkeys(self, namespace): |
|
3466 | def listkeys(self, namespace): | |
3466 | self.hook(b'prelistkeys', throw=True, namespace=namespace) |
|
3467 | self.hook(b'prelistkeys', throw=True, namespace=namespace) | |
3467 | self.ui.debug(b'listing keys for "%s"\n' % namespace) |
|
3468 | self.ui.debug(b'listing keys for "%s"\n' % namespace) | |
3468 | values = pushkey.list(self, namespace) |
|
3469 | values = pushkey.list(self, namespace) | |
3469 | self.hook(b'listkeys', namespace=namespace, values=values) |
|
3470 | self.hook(b'listkeys', namespace=namespace, values=values) | |
3470 | return values |
|
3471 | return values | |
3471 |
|
3472 | |||
3472 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
3473 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
3473 | '''used to test argument passing over the wire''' |
|
3474 | '''used to test argument passing over the wire''' | |
3474 | return b"%s %s %s %s %s" % ( |
|
3475 | return b"%s %s %s %s %s" % ( | |
3475 | one, |
|
3476 | one, | |
3476 | two, |
|
3477 | two, | |
3477 | pycompat.bytestr(three), |
|
3478 | pycompat.bytestr(three), | |
3478 | pycompat.bytestr(four), |
|
3479 | pycompat.bytestr(four), | |
3479 | pycompat.bytestr(five), |
|
3480 | pycompat.bytestr(five), | |
3480 | ) |
|
3481 | ) | |
3481 |
|
3482 | |||
3482 | def savecommitmessage(self, text): |
|
3483 | def savecommitmessage(self, text): | |
3483 | fp = self.vfs(b'last-message.txt', b'wb') |
|
3484 | fp = self.vfs(b'last-message.txt', b'wb') | |
3484 | try: |
|
3485 | try: | |
3485 | fp.write(text) |
|
3486 | fp.write(text) | |
3486 | finally: |
|
3487 | finally: | |
3487 | fp.close() |
|
3488 | fp.close() | |
3488 | return self.pathto(fp.name[len(self.root) + 1 :]) |
|
3489 | return self.pathto(fp.name[len(self.root) + 1 :]) | |
3489 |
|
3490 | |||
3490 |
|
3491 | |||
3491 | # used to avoid circular references so destructors work |
|
3492 | # used to avoid circular references so destructors work | |
3492 | def aftertrans(files): |
|
3493 | def aftertrans(files): | |
3493 | renamefiles = [tuple(t) for t in files] |
|
3494 | renamefiles = [tuple(t) for t in files] | |
3494 |
|
3495 | |||
3495 | def a(): |
|
3496 | def a(): | |
3496 | for vfs, src, dest in renamefiles: |
|
3497 | for vfs, src, dest in renamefiles: | |
3497 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
3498 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
3498 | # leaving both src and dest on disk. delete dest to make sure |
|
3499 | # leaving both src and dest on disk. delete dest to make sure | |
3499 | # the rename couldn't be such a no-op. |
|
3500 | # the rename couldn't be such a no-op. | |
3500 | vfs.tryunlink(dest) |
|
3501 | vfs.tryunlink(dest) | |
3501 | try: |
|
3502 | try: | |
3502 | vfs.rename(src, dest) |
|
3503 | vfs.rename(src, dest) | |
3503 | except OSError: # journal file does not yet exist |
|
3504 | except OSError: # journal file does not yet exist | |
3504 | pass |
|
3505 | pass | |
3505 |
|
3506 | |||
3506 | return a |
|
3507 | return a | |
3507 |
|
3508 | |||
3508 |
|
3509 | |||
3509 | def undoname(fn): |
|
3510 | def undoname(fn): | |
3510 | base, name = os.path.split(fn) |
|
3511 | base, name = os.path.split(fn) | |
3511 | assert name.startswith(b'journal') |
|
3512 | assert name.startswith(b'journal') | |
3512 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) |
|
3513 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) | |
3513 |
|
3514 | |||
3514 |
|
3515 | |||
3515 | def instance(ui, path, create, intents=None, createopts=None): |
|
3516 | def instance(ui, path, create, intents=None, createopts=None): | |
3516 | localpath = util.urllocalpath(path) |
|
3517 | localpath = util.urllocalpath(path) | |
3517 | if create: |
|
3518 | if create: | |
3518 | createrepository(ui, localpath, createopts=createopts) |
|
3519 | createrepository(ui, localpath, createopts=createopts) | |
3519 |
|
3520 | |||
3520 | return makelocalrepository(ui, localpath, intents=intents) |
|
3521 | return makelocalrepository(ui, localpath, intents=intents) | |
3521 |
|
3522 | |||
3522 |
|
3523 | |||
3523 | def islocal(path): |
|
3524 | def islocal(path): | |
3524 | return True |
|
3525 | return True | |
3525 |
|
3526 | |||
3526 |
|
3527 | |||
3527 | def defaultcreateopts(ui, createopts=None): |
|
3528 | def defaultcreateopts(ui, createopts=None): | |
3528 | """Populate the default creation options for a repository. |
|
3529 | """Populate the default creation options for a repository. | |
3529 |
|
3530 | |||
3530 | A dictionary of explicitly requested creation options can be passed |
|
3531 | A dictionary of explicitly requested creation options can be passed | |
3531 | in. Missing keys will be populated. |
|
3532 | in. Missing keys will be populated. | |
3532 | """ |
|
3533 | """ | |
3533 | createopts = dict(createopts or {}) |
|
3534 | createopts = dict(createopts or {}) | |
3534 |
|
3535 | |||
3535 | if b'backend' not in createopts: |
|
3536 | if b'backend' not in createopts: | |
3536 | # experimental config: storage.new-repo-backend |
|
3537 | # experimental config: storage.new-repo-backend | |
3537 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') |
|
3538 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') | |
3538 |
|
3539 | |||
3539 | return createopts |
|
3540 | return createopts | |
3540 |
|
3541 | |||
3541 |
|
3542 | |||
3542 | def newreporequirements(ui, createopts): |
|
3543 | def newreporequirements(ui, createopts): | |
3543 | """Determine the set of requirements for a new local repository. |
|
3544 | """Determine the set of requirements for a new local repository. | |
3544 |
|
3545 | |||
3545 | Extensions can wrap this function to specify custom requirements for |
|
3546 | Extensions can wrap this function to specify custom requirements for | |
3546 | new repositories. |
|
3547 | new repositories. | |
3547 | """ |
|
3548 | """ | |
3548 | # If the repo is being created from a shared repository, we copy |
|
3549 | # If the repo is being created from a shared repository, we copy | |
3549 | # its requirements. |
|
3550 | # its requirements. | |
3550 | if b'sharedrepo' in createopts: |
|
3551 | if b'sharedrepo' in createopts: | |
3551 | requirements = set(createopts[b'sharedrepo'].requirements) |
|
3552 | requirements = set(createopts[b'sharedrepo'].requirements) | |
3552 | if createopts.get(b'sharedrelative'): |
|
3553 | if createopts.get(b'sharedrelative'): | |
3553 | requirements.add(b'relshared') |
|
3554 | requirements.add(b'relshared') | |
3554 | else: |
|
3555 | else: | |
3555 | requirements.add(b'shared') |
|
3556 | requirements.add(b'shared') | |
3556 |
|
3557 | |||
3557 | return requirements |
|
3558 | return requirements | |
3558 |
|
3559 | |||
3559 | if b'backend' not in createopts: |
|
3560 | if b'backend' not in createopts: | |
3560 | raise error.ProgrammingError( |
|
3561 | raise error.ProgrammingError( | |
3561 | b'backend key not present in createopts; ' |
|
3562 | b'backend key not present in createopts; ' | |
3562 | b'was defaultcreateopts() called?' |
|
3563 | b'was defaultcreateopts() called?' | |
3563 | ) |
|
3564 | ) | |
3564 |
|
3565 | |||
3565 | if createopts[b'backend'] != b'revlogv1': |
|
3566 | if createopts[b'backend'] != b'revlogv1': | |
3566 | raise error.Abort( |
|
3567 | raise error.Abort( | |
3567 | _( |
|
3568 | _( | |
3568 | b'unable to determine repository requirements for ' |
|
3569 | b'unable to determine repository requirements for ' | |
3569 | b'storage backend: %s' |
|
3570 | b'storage backend: %s' | |
3570 | ) |
|
3571 | ) | |
3571 | % createopts[b'backend'] |
|
3572 | % createopts[b'backend'] | |
3572 | ) |
|
3573 | ) | |
3573 |
|
3574 | |||
3574 | requirements = {b'revlogv1'} |
|
3575 | requirements = {b'revlogv1'} | |
3575 | if ui.configbool(b'format', b'usestore'): |
|
3576 | if ui.configbool(b'format', b'usestore'): | |
3576 | requirements.add(b'store') |
|
3577 | requirements.add(b'store') | |
3577 | if ui.configbool(b'format', b'usefncache'): |
|
3578 | if ui.configbool(b'format', b'usefncache'): | |
3578 | requirements.add(b'fncache') |
|
3579 | requirements.add(b'fncache') | |
3579 | if ui.configbool(b'format', b'dotencode'): |
|
3580 | if ui.configbool(b'format', b'dotencode'): | |
3580 | requirements.add(b'dotencode') |
|
3581 | requirements.add(b'dotencode') | |
3581 |
|
3582 | |||
3582 | compengines = ui.configlist(b'format', b'revlog-compression') |
|
3583 | compengines = ui.configlist(b'format', b'revlog-compression') | |
3583 | for compengine in compengines: |
|
3584 | for compengine in compengines: | |
3584 | if compengine in util.compengines: |
|
3585 | if compengine in util.compengines: | |
3585 | break |
|
3586 | break | |
3586 | else: |
|
3587 | else: | |
3587 | raise error.Abort( |
|
3588 | raise error.Abort( | |
3588 | _( |
|
3589 | _( | |
3589 | b'compression engines %s defined by ' |
|
3590 | b'compression engines %s defined by ' | |
3590 | b'format.revlog-compression not available' |
|
3591 | b'format.revlog-compression not available' | |
3591 | ) |
|
3592 | ) | |
3592 | % b', '.join(b'"%s"' % e for e in compengines), |
|
3593 | % b', '.join(b'"%s"' % e for e in compengines), | |
3593 | hint=_( |
|
3594 | hint=_( | |
3594 | b'run "hg debuginstall" to list available ' |
|
3595 | b'run "hg debuginstall" to list available ' | |
3595 | b'compression engines' |
|
3596 | b'compression engines' | |
3596 | ), |
|
3597 | ), | |
3597 | ) |
|
3598 | ) | |
3598 |
|
3599 | |||
3599 | # zlib is the historical default and doesn't need an explicit requirement. |
|
3600 | # zlib is the historical default and doesn't need an explicit requirement. | |
3600 | if compengine == b'zstd': |
|
3601 | if compengine == b'zstd': | |
3601 | requirements.add(b'revlog-compression-zstd') |
|
3602 | requirements.add(b'revlog-compression-zstd') | |
3602 | elif compengine != b'zlib': |
|
3603 | elif compengine != b'zlib': | |
3603 | requirements.add(b'exp-compression-%s' % compengine) |
|
3604 | requirements.add(b'exp-compression-%s' % compengine) | |
3604 |
|
3605 | |||
3605 | if scmutil.gdinitconfig(ui): |
|
3606 | if scmutil.gdinitconfig(ui): | |
3606 | requirements.add(b'generaldelta') |
|
3607 | requirements.add(b'generaldelta') | |
3607 | if ui.configbool(b'format', b'sparse-revlog'): |
|
3608 | if ui.configbool(b'format', b'sparse-revlog'): | |
3608 | requirements.add(SPARSEREVLOG_REQUIREMENT) |
|
3609 | requirements.add(SPARSEREVLOG_REQUIREMENT) | |
3609 |
|
3610 | |||
3610 | # experimental config: format.exp-use-side-data |
|
3611 | # experimental config: format.exp-use-side-data | |
3611 | if ui.configbool(b'format', b'exp-use-side-data'): |
|
3612 | if ui.configbool(b'format', b'exp-use-side-data'): | |
3612 | requirements.add(SIDEDATA_REQUIREMENT) |
|
3613 | requirements.add(SIDEDATA_REQUIREMENT) | |
3613 | # experimental config: format.exp-use-copies-side-data-changeset |
|
3614 | # experimental config: format.exp-use-copies-side-data-changeset | |
3614 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): |
|
3615 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): | |
3615 | requirements.add(SIDEDATA_REQUIREMENT) |
|
3616 | requirements.add(SIDEDATA_REQUIREMENT) | |
3616 | requirements.add(COPIESSDC_REQUIREMENT) |
|
3617 | requirements.add(COPIESSDC_REQUIREMENT) | |
3617 | if ui.configbool(b'experimental', b'treemanifest'): |
|
3618 | if ui.configbool(b'experimental', b'treemanifest'): | |
3618 | requirements.add(b'treemanifest') |
|
3619 | requirements.add(b'treemanifest') | |
3619 |
|
3620 | |||
3620 | revlogv2 = ui.config(b'experimental', b'revlogv2') |
|
3621 | revlogv2 = ui.config(b'experimental', b'revlogv2') | |
3621 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': |
|
3622 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': | |
3622 | requirements.remove(b'revlogv1') |
|
3623 | requirements.remove(b'revlogv1') | |
3623 | # generaldelta is implied by revlogv2. |
|
3624 | # generaldelta is implied by revlogv2. | |
3624 | requirements.discard(b'generaldelta') |
|
3625 | requirements.discard(b'generaldelta') | |
3625 | requirements.add(REVLOGV2_REQUIREMENT) |
|
3626 | requirements.add(REVLOGV2_REQUIREMENT) | |
3626 | # experimental config: format.internal-phase |
|
3627 | # experimental config: format.internal-phase | |
3627 | if ui.configbool(b'format', b'internal-phase'): |
|
3628 | if ui.configbool(b'format', b'internal-phase'): | |
3628 | requirements.add(b'internal-phase') |
|
3629 | requirements.add(b'internal-phase') | |
3629 |
|
3630 | |||
3630 | if createopts.get(b'narrowfiles'): |
|
3631 | if createopts.get(b'narrowfiles'): | |
3631 | requirements.add(repository.NARROW_REQUIREMENT) |
|
3632 | requirements.add(repository.NARROW_REQUIREMENT) | |
3632 |
|
3633 | |||
3633 | if createopts.get(b'lfs'): |
|
3634 | if createopts.get(b'lfs'): | |
3634 | requirements.add(b'lfs') |
|
3635 | requirements.add(b'lfs') | |
3635 |
|
3636 | |||
3636 | if ui.configbool(b'format', b'bookmarks-in-store'): |
|
3637 | if ui.configbool(b'format', b'bookmarks-in-store'): | |
3637 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) |
|
3638 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) | |
3638 |
|
3639 | |||
3639 | return requirements |
|
3640 | return requirements | |
3640 |
|
3641 | |||
3641 |
|
3642 | |||
3642 | def filterknowncreateopts(ui, createopts): |
|
3643 | def filterknowncreateopts(ui, createopts): | |
3643 | """Filters a dict of repo creation options against options that are known. |
|
3644 | """Filters a dict of repo creation options against options that are known. | |
3644 |
|
3645 | |||
3645 | Receives a dict of repo creation options and returns a dict of those |
|
3646 | Receives a dict of repo creation options and returns a dict of those | |
3646 | options that we don't know how to handle. |
|
3647 | options that we don't know how to handle. | |
3647 |
|
3648 | |||
3648 | This function is called as part of repository creation. If the |
|
3649 | This function is called as part of repository creation. If the | |
3649 | returned dict contains any items, repository creation will not |
|
3650 | returned dict contains any items, repository creation will not | |
3650 | be allowed, as it means there was a request to create a repository |
|
3651 | be allowed, as it means there was a request to create a repository | |
3651 | with options not recognized by loaded code. |
|
3652 | with options not recognized by loaded code. | |
3652 |
|
3653 | |||
3653 | Extensions can wrap this function to filter out creation options |
|
3654 | Extensions can wrap this function to filter out creation options | |
3654 | they know how to handle. |
|
3655 | they know how to handle. | |
3655 | """ |
|
3656 | """ | |
3656 | known = { |
|
3657 | known = { | |
3657 | b'backend', |
|
3658 | b'backend', | |
3658 | b'lfs', |
|
3659 | b'lfs', | |
3659 | b'narrowfiles', |
|
3660 | b'narrowfiles', | |
3660 | b'sharedrepo', |
|
3661 | b'sharedrepo', | |
3661 | b'sharedrelative', |
|
3662 | b'sharedrelative', | |
3662 | b'shareditems', |
|
3663 | b'shareditems', | |
3663 | b'shallowfilestore', |
|
3664 | b'shallowfilestore', | |
3664 | } |
|
3665 | } | |
3665 |
|
3666 | |||
3666 | return {k: v for k, v in createopts.items() if k not in known} |
|
3667 | return {k: v for k, v in createopts.items() if k not in known} | |
3667 |
|
3668 | |||
3668 |
|
3669 | |||
3669 | def createrepository(ui, path, createopts=None): |
|
3670 | def createrepository(ui, path, createopts=None): | |
3670 | """Create a new repository in a vfs. |
|
3671 | """Create a new repository in a vfs. | |
3671 |
|
3672 | |||
3672 | ``path`` path to the new repo's working directory. |
|
3673 | ``path`` path to the new repo's working directory. | |
3673 | ``createopts`` options for the new repository. |
|
3674 | ``createopts`` options for the new repository. | |
3674 |
|
3675 | |||
3675 | The following keys for ``createopts`` are recognized: |
|
3676 | The following keys for ``createopts`` are recognized: | |
3676 |
|
3677 | |||
3677 | backend |
|
3678 | backend | |
3678 | The storage backend to use. |
|
3679 | The storage backend to use. | |
3679 | lfs |
|
3680 | lfs | |
3680 | Repository will be created with ``lfs`` requirement. The lfs extension |
|
3681 | Repository will be created with ``lfs`` requirement. The lfs extension | |
3681 | will automatically be loaded when the repository is accessed. |
|
3682 | will automatically be loaded when the repository is accessed. | |
3682 | narrowfiles |
|
3683 | narrowfiles | |
3683 | Set up repository to support narrow file storage. |
|
3684 | Set up repository to support narrow file storage. | |
3684 | sharedrepo |
|
3685 | sharedrepo | |
3685 | Repository object from which storage should be shared. |
|
3686 | Repository object from which storage should be shared. | |
3686 | sharedrelative |
|
3687 | sharedrelative | |
3687 | Boolean indicating if the path to the shared repo should be |
|
3688 | Boolean indicating if the path to the shared repo should be | |
3688 | stored as relative. By default, the pointer to the "parent" repo |
|
3689 | stored as relative. By default, the pointer to the "parent" repo | |
3689 | is stored as an absolute path. |
|
3690 | is stored as an absolute path. | |
3690 | shareditems |
|
3691 | shareditems | |
3691 | Set of items to share to the new repository (in addition to storage). |
|
3692 | Set of items to share to the new repository (in addition to storage). | |
3692 | shallowfilestore |
|
3693 | shallowfilestore | |
3693 | Indicates that storage for files should be shallow (not all ancestor |
|
3694 | Indicates that storage for files should be shallow (not all ancestor | |
3694 | revisions are known). |
|
3695 | revisions are known). | |
3695 | """ |
|
3696 | """ | |
3696 | createopts = defaultcreateopts(ui, createopts=createopts) |
|
3697 | createopts = defaultcreateopts(ui, createopts=createopts) | |
3697 |
|
3698 | |||
3698 | unknownopts = filterknowncreateopts(ui, createopts) |
|
3699 | unknownopts = filterknowncreateopts(ui, createopts) | |
3699 |
|
3700 | |||
3700 | if not isinstance(unknownopts, dict): |
|
3701 | if not isinstance(unknownopts, dict): | |
3701 | raise error.ProgrammingError( |
|
3702 | raise error.ProgrammingError( | |
3702 | b'filterknowncreateopts() did not return a dict' |
|
3703 | b'filterknowncreateopts() did not return a dict' | |
3703 | ) |
|
3704 | ) | |
3704 |
|
3705 | |||
3705 | if unknownopts: |
|
3706 | if unknownopts: | |
3706 | raise error.Abort( |
|
3707 | raise error.Abort( | |
3707 | _( |
|
3708 | _( | |
3708 | b'unable to create repository because of unknown ' |
|
3709 | b'unable to create repository because of unknown ' | |
3709 | b'creation option: %s' |
|
3710 | b'creation option: %s' | |
3710 | ) |
|
3711 | ) | |
3711 | % b', '.join(sorted(unknownopts)), |
|
3712 | % b', '.join(sorted(unknownopts)), | |
3712 | hint=_(b'is a required extension not loaded?'), |
|
3713 | hint=_(b'is a required extension not loaded?'), | |
3713 | ) |
|
3714 | ) | |
3714 |
|
3715 | |||
3715 | requirements = newreporequirements(ui, createopts=createopts) |
|
3716 | requirements = newreporequirements(ui, createopts=createopts) | |
3716 |
|
3717 | |||
3717 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
3718 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
3718 |
|
3719 | |||
3719 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
|
3720 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | |
3720 | if hgvfs.exists(): |
|
3721 | if hgvfs.exists(): | |
3721 | raise error.RepoError(_(b'repository %s already exists') % path) |
|
3722 | raise error.RepoError(_(b'repository %s already exists') % path) | |
3722 |
|
3723 | |||
3723 | if b'sharedrepo' in createopts: |
|
3724 | if b'sharedrepo' in createopts: | |
3724 | sharedpath = createopts[b'sharedrepo'].sharedpath |
|
3725 | sharedpath = createopts[b'sharedrepo'].sharedpath | |
3725 |
|
3726 | |||
3726 | if createopts.get(b'sharedrelative'): |
|
3727 | if createopts.get(b'sharedrelative'): | |
3727 | try: |
|
3728 | try: | |
3728 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) |
|
3729 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) | |
3729 | except (IOError, ValueError) as e: |
|
3730 | except (IOError, ValueError) as e: | |
3730 | # ValueError is raised on Windows if the drive letters differ |
|
3731 | # ValueError is raised on Windows if the drive letters differ | |
3731 | # on each path. |
|
3732 | # on each path. | |
3732 | raise error.Abort( |
|
3733 | raise error.Abort( | |
3733 | _(b'cannot calculate relative path'), |
|
3734 | _(b'cannot calculate relative path'), | |
3734 | hint=stringutil.forcebytestr(e), |
|
3735 | hint=stringutil.forcebytestr(e), | |
3735 | ) |
|
3736 | ) | |
3736 |
|
3737 | |||
3737 | if not wdirvfs.exists(): |
|
3738 | if not wdirvfs.exists(): | |
3738 | wdirvfs.makedirs() |
|
3739 | wdirvfs.makedirs() | |
3739 |
|
3740 | |||
3740 | hgvfs.makedir(notindexed=True) |
|
3741 | hgvfs.makedir(notindexed=True) | |
3741 | if b'sharedrepo' not in createopts: |
|
3742 | if b'sharedrepo' not in createopts: | |
3742 | hgvfs.mkdir(b'cache') |
|
3743 | hgvfs.mkdir(b'cache') | |
3743 | hgvfs.mkdir(b'wcache') |
|
3744 | hgvfs.mkdir(b'wcache') | |
3744 |
|
3745 | |||
3745 | if b'store' in requirements and b'sharedrepo' not in createopts: |
|
3746 | if b'store' in requirements and b'sharedrepo' not in createopts: | |
3746 | hgvfs.mkdir(b'store') |
|
3747 | hgvfs.mkdir(b'store') | |
3747 |
|
3748 | |||
3748 | # We create an invalid changelog outside the store so very old |
|
3749 | # We create an invalid changelog outside the store so very old | |
3749 | # Mercurial versions (which didn't know about the requirements |
|
3750 | # Mercurial versions (which didn't know about the requirements | |
3750 | # file) encounter an error on reading the changelog. This |
|
3751 | # file) encounter an error on reading the changelog. This | |
3751 | # effectively locks out old clients and prevents them from |
|
3752 | # effectively locks out old clients and prevents them from | |
3752 | # mucking with a repo in an unknown format. |
|
3753 | # mucking with a repo in an unknown format. | |
3753 | # |
|
3754 | # | |
3754 | # The revlog header has version 2, which won't be recognized by |
|
3755 | # The revlog header has version 2, which won't be recognized by | |
3755 | # such old clients. |
|
3756 | # such old clients. | |
3756 | hgvfs.append( |
|
3757 | hgvfs.append( | |
3757 | b'00changelog.i', |
|
3758 | b'00changelog.i', | |
3758 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' |
|
3759 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' | |
3759 | b'layout', |
|
3760 | b'layout', | |
3760 | ) |
|
3761 | ) | |
3761 |
|
3762 | |||
3762 | scmutil.writerequires(hgvfs, requirements) |
|
3763 | scmutil.writerequires(hgvfs, requirements) | |
3763 |
|
3764 | |||
3764 | # Write out file telling readers where to find the shared store. |
|
3765 | # Write out file telling readers where to find the shared store. | |
3765 | if b'sharedrepo' in createopts: |
|
3766 | if b'sharedrepo' in createopts: | |
3766 | hgvfs.write(b'sharedpath', sharedpath) |
|
3767 | hgvfs.write(b'sharedpath', sharedpath) | |
3767 |
|
3768 | |||
3768 | if createopts.get(b'shareditems'): |
|
3769 | if createopts.get(b'shareditems'): | |
3769 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' |
|
3770 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' | |
3770 | hgvfs.write(b'shared', shared) |
|
3771 | hgvfs.write(b'shared', shared) | |
3771 |
|
3772 | |||
3772 |
|
3773 | |||
3773 | def poisonrepository(repo): |
|
3774 | def poisonrepository(repo): | |
3774 | """Poison a repository instance so it can no longer be used.""" |
|
3775 | """Poison a repository instance so it can no longer be used.""" | |
3775 | # Perform any cleanup on the instance. |
|
3776 | # Perform any cleanup on the instance. | |
3776 | repo.close() |
|
3777 | repo.close() | |
3777 |
|
3778 | |||
3778 | # Our strategy is to replace the type of the object with one that |
|
3779 | # Our strategy is to replace the type of the object with one that | |
3779 | # has all attribute lookups result in error. |
|
3780 | # has all attribute lookups result in error. | |
3780 | # |
|
3781 | # | |
3781 | # But we have to allow the close() method because some constructors |
|
3782 | # But we have to allow the close() method because some constructors | |
3782 | # of repos call close() on repo references. |
|
3783 | # of repos call close() on repo references. | |
3783 | class poisonedrepository(object): |
|
3784 | class poisonedrepository(object): | |
3784 | def __getattribute__(self, item): |
|
3785 | def __getattribute__(self, item): | |
3785 | if item == 'close': |
|
3786 | if item == 'close': | |
3786 | return object.__getattribute__(self, item) |
|
3787 | return object.__getattribute__(self, item) | |
3787 |
|
3788 | |||
3788 | raise error.ProgrammingError( |
|
3789 | raise error.ProgrammingError( | |
3789 | b'repo instances should not be used after unshare' |
|
3790 | b'repo instances should not be used after unshare' | |
3790 | ) |
|
3791 | ) | |
3791 |
|
3792 | |||
3792 | def close(self): |
|
3793 | def close(self): | |
3793 | pass |
|
3794 | pass | |
3794 |
|
3795 | |||
3795 | # We may have a repoview, which intercepts __setattr__. So be sure |
|
3796 | # We may have a repoview, which intercepts __setattr__. So be sure | |
3796 | # we operate at the lowest level possible. |
|
3797 | # we operate at the lowest level possible. | |
3797 | object.__setattr__(repo, '__class__', poisonedrepository) |
|
3798 | object.__setattr__(repo, '__class__', poisonedrepository) |
@@ -1,913 +1,914 b'' | |||||
1 | $ cat >> $HGRCPATH <<EOF |
|
1 | $ cat >> $HGRCPATH <<EOF | |
2 | > [extdiff] |
|
2 | > [extdiff] | |
3 | > # for portability: |
|
3 | > # for portability: | |
4 | > pdiff = sh "$RUNTESTDIR/pdiff" |
|
4 | > pdiff = sh "$RUNTESTDIR/pdiff" | |
5 | > EOF |
|
5 | > EOF | |
6 |
|
6 | |||
7 | Create a repo with some stuff in it: |
|
7 | Create a repo with some stuff in it: | |
8 |
|
8 | |||
9 | $ hg init a |
|
9 | $ hg init a | |
10 | $ cd a |
|
10 | $ cd a | |
11 | $ echo a > a |
|
11 | $ echo a > a | |
12 | $ echo a > d |
|
12 | $ echo a > d | |
13 | $ echo a > e |
|
13 | $ echo a > e | |
14 | $ hg ci -qAm0 |
|
14 | $ hg ci -qAm0 | |
15 | $ echo b > a |
|
15 | $ echo b > a | |
16 | $ hg ci -m1 -u bar |
|
16 | $ hg ci -m1 -u bar | |
17 | $ hg mv a b |
|
17 | $ hg mv a b | |
18 | $ hg ci -m2 |
|
18 | $ hg ci -m2 | |
19 | $ hg cp b c |
|
19 | $ hg cp b c | |
20 | $ hg ci -m3 -u baz |
|
20 | $ hg ci -m3 -u baz | |
21 | $ echo b > d |
|
21 | $ echo b > d | |
22 | $ echo f > e |
|
22 | $ echo f > e | |
23 | $ hg ci -m4 |
|
23 | $ hg ci -m4 | |
24 | $ hg up -q 3 |
|
24 | $ hg up -q 3 | |
25 | $ echo b > e |
|
25 | $ echo b > e | |
26 | $ hg branch -q stable |
|
26 | $ hg branch -q stable | |
27 | $ hg ci -m5 |
|
27 | $ hg ci -m5 | |
28 | $ hg merge -q default --tool internal:local # for conflicts in e, choose 5 and ignore 4 |
|
28 | $ hg merge -q default --tool internal:local # for conflicts in e, choose 5 and ignore 4 | |
29 | $ hg branch -q default |
|
29 | $ hg branch -q default | |
30 | $ hg ci -m6 |
|
30 | $ hg ci -m6 | |
31 | $ hg phase --public 3 |
|
31 | $ hg phase --public 3 | |
32 | $ hg phase --force --secret 6 |
|
32 | $ hg phase --force --secret 6 | |
33 |
|
33 | |||
34 | $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n' |
|
34 | $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n' | |
35 | @ test@6.secret: 6 |
|
35 | @ test@6.secret: 6 | |
36 | |\ |
|
36 | |\ | |
37 | | o test@5.draft: 5 |
|
37 | | o test@5.draft: 5 | |
38 | | | |
|
38 | | | | |
39 | o | test@4.draft: 4 |
|
39 | o | test@4.draft: 4 | |
40 | |/ |
|
40 | |/ | |
41 | o baz@3.public: 3 |
|
41 | o baz@3.public: 3 | |
42 | | |
|
42 | | | |
43 | o test@2.public: 2 |
|
43 | o test@2.public: 2 | |
44 | | |
|
44 | | | |
45 | o bar@1.public: 1 |
|
45 | o bar@1.public: 1 | |
46 | | |
|
46 | | | |
47 | o test@0.public: 0 |
|
47 | o test@0.public: 0 | |
48 |
|
48 | |||
49 | Test --base for grafting the merge of 4 from the perspective of 5, thus only getting the change to d |
|
49 | Test --base for grafting the merge of 4 from the perspective of 5, thus only getting the change to d | |
50 |
|
50 | |||
51 | $ hg up -cqr 3 |
|
51 | $ hg up -cqr 3 | |
52 | $ hg graft -r 6 --base 5 |
|
52 | $ hg graft -r 6 --base 5 | |
53 | grafting 6:25a2b029d3ae "6" (tip) |
|
53 | grafting 6:25a2b029d3ae "6" (tip) | |
54 | merging e |
|
54 | merging e | |
55 | $ hg st --change . |
|
55 | $ hg st --change . | |
56 | M d |
|
56 | M d | |
57 |
|
57 | |||
58 | $ hg -q strip . --config extensions.strip= |
|
58 | $ hg -q strip . --config extensions.strip= | |
59 |
|
59 | |||
60 | Test --base for collapsing changesets 2 and 3, thus getting both b and c |
|
60 | Test --base for collapsing changesets 2 and 3, thus getting both b and c | |
61 |
|
61 | |||
62 | $ hg up -cqr 0 |
|
62 | $ hg up -cqr 0 | |
63 | $ hg graft -r 3 --base 1 |
|
63 | $ hg graft -r 3 --base 1 | |
64 | grafting 3:4c60f11aa304 "3" |
|
64 | grafting 3:4c60f11aa304 "3" | |
65 | merging a and b to b |
|
65 | merging a and b to b | |
66 | merging a and c to c |
|
66 | merging a and c to c | |
67 | $ hg st --change . |
|
67 | $ hg st --change . | |
68 | A b |
|
68 | A b | |
69 | A c |
|
69 | A c | |
70 | R a |
|
70 | R a | |
71 |
|
71 | |||
72 | $ hg -q strip . --config extensions.strip= |
|
72 | $ hg -q strip . --config extensions.strip= | |
73 |
|
73 | |||
74 | Specifying child as --base revision fails safely (perhaps slightly confusing, but consistent) |
|
74 | Specifying child as --base revision fails safely (perhaps slightly confusing, but consistent) | |
75 |
|
75 | |||
76 | $ hg graft -r 2 --base 3 |
|
76 | $ hg graft -r 2 --base 3 | |
77 | grafting 2:5c095ad7e90f "2" |
|
77 | grafting 2:5c095ad7e90f "2" | |
78 | note: possible conflict - c was deleted and renamed to: |
|
78 | note: possible conflict - c was deleted and renamed to: | |
79 | a |
|
79 | a | |
80 | note: graft of 2:5c095ad7e90f created no changes to commit |
|
80 | note: graft of 2:5c095ad7e90f created no changes to commit | |
81 |
|
81 | |||
82 | Can't continue without starting: |
|
82 | Can't continue without starting: | |
83 |
|
83 | |||
84 | $ hg -q up -cr tip |
|
84 | $ hg -q up -cr tip | |
85 | $ hg rm -q e |
|
85 | $ hg rm -q e | |
86 | $ hg graft --continue |
|
86 | $ hg graft --continue | |
87 | abort: no graft in progress |
|
87 | abort: no graft in progress | |
88 | [255] |
|
88 | [255] | |
89 | $ hg revert -r . -q e |
|
89 | $ hg revert -r . -q e | |
90 |
|
90 | |||
91 | Need to specify a rev: |
|
91 | Need to specify a rev: | |
92 |
|
92 | |||
93 | $ hg graft |
|
93 | $ hg graft | |
94 | abort: no revisions specified |
|
94 | abort: no revisions specified | |
95 | [255] |
|
95 | [255] | |
96 |
|
96 | |||
97 | Can't graft ancestor: |
|
97 | Can't graft ancestor: | |
98 |
|
98 | |||
99 | $ hg graft 1 2 |
|
99 | $ hg graft 1 2 | |
100 | skipping ancestor revision 1:5d205f8b35b6 |
|
100 | skipping ancestor revision 1:5d205f8b35b6 | |
101 | skipping ancestor revision 2:5c095ad7e90f |
|
101 | skipping ancestor revision 2:5c095ad7e90f | |
102 | [255] |
|
102 | [255] | |
103 |
|
103 | |||
104 | Specify revisions with -r: |
|
104 | Specify revisions with -r: | |
105 |
|
105 | |||
106 | $ hg graft -r 1 -r 2 |
|
106 | $ hg graft -r 1 -r 2 | |
107 | skipping ancestor revision 1:5d205f8b35b6 |
|
107 | skipping ancestor revision 1:5d205f8b35b6 | |
108 | skipping ancestor revision 2:5c095ad7e90f |
|
108 | skipping ancestor revision 2:5c095ad7e90f | |
109 | [255] |
|
109 | [255] | |
110 |
|
110 | |||
111 | $ hg graft -r 1 2 |
|
111 | $ hg graft -r 1 2 | |
112 | warning: inconsistent use of --rev might give unexpected revision ordering! |
|
112 | warning: inconsistent use of --rev might give unexpected revision ordering! | |
113 | skipping ancestor revision 2:5c095ad7e90f |
|
113 | skipping ancestor revision 2:5c095ad7e90f | |
114 | skipping ancestor revision 1:5d205f8b35b6 |
|
114 | skipping ancestor revision 1:5d205f8b35b6 | |
115 | [255] |
|
115 | [255] | |
116 |
|
116 | |||
117 | Conflicting date/user options: |
|
117 | Conflicting date/user options: | |
118 |
|
118 | |||
119 | $ hg up -q 0 |
|
119 | $ hg up -q 0 | |
120 | $ hg graft -U --user foo 2 |
|
120 | $ hg graft -U --user foo 2 | |
121 | abort: cannot specify both --user and --currentuser |
|
121 | abort: cannot specify both --user and --currentuser | |
122 | [255] |
|
122 | [255] | |
123 | $ hg graft -D --date '0 0' 2 |
|
123 | $ hg graft -D --date '0 0' 2 | |
124 | abort: cannot specify both --date and --currentdate |
|
124 | abort: cannot specify both --date and --currentdate | |
125 | [255] |
|
125 | [255] | |
126 |
|
126 | |||
127 | Can't graft with dirty wd: |
|
127 | Can't graft with dirty wd: | |
128 |
|
128 | |||
129 | $ hg up -q 0 |
|
129 | $ hg up -q 0 | |
130 | $ echo foo > a |
|
130 | $ echo foo > a | |
131 | $ hg graft 1 |
|
131 | $ hg graft 1 | |
132 | abort: uncommitted changes |
|
132 | abort: uncommitted changes | |
133 | [255] |
|
133 | [255] | |
134 | $ hg revert a |
|
134 | $ hg revert a | |
135 |
|
135 | |||
136 | Graft a rename: |
|
136 | Graft a rename: | |
137 | (this also tests that editor is invoked if '--edit' is specified) |
|
137 | (this also tests that editor is invoked if '--edit' is specified) | |
138 |
|
138 | |||
139 | $ hg status --rev "2^1" --rev 2 |
|
139 | $ hg status --rev "2^1" --rev 2 | |
140 | A b |
|
140 | A b | |
141 | R a |
|
141 | R a | |
142 | $ HGEDITOR=cat hg graft 2 -u foo --edit |
|
142 | $ HGEDITOR=cat hg graft 2 -u foo --edit | |
143 | grafting 2:5c095ad7e90f "2" |
|
143 | grafting 2:5c095ad7e90f "2" | |
144 | merging a and b to b |
|
144 | merging a and b to b | |
145 | 2 |
|
145 | 2 | |
146 |
|
146 | |||
147 |
|
147 | |||
148 | HG: Enter commit message. Lines beginning with 'HG:' are removed. |
|
148 | HG: Enter commit message. Lines beginning with 'HG:' are removed. | |
149 | HG: Leave message empty to abort commit. |
|
149 | HG: Leave message empty to abort commit. | |
150 | HG: -- |
|
150 | HG: -- | |
151 | HG: user: foo |
|
151 | HG: user: foo | |
152 | HG: branch 'default' |
|
152 | HG: branch 'default' | |
153 | HG: added b |
|
153 | HG: added b | |
154 | HG: removed a |
|
154 | HG: removed a | |
155 | $ hg export tip --git |
|
155 | $ hg export tip --git | |
156 | # HG changeset patch |
|
156 | # HG changeset patch | |
157 | # User foo |
|
157 | # User foo | |
158 | # Date 0 0 |
|
158 | # Date 0 0 | |
159 | # Thu Jan 01 00:00:00 1970 +0000 |
|
159 | # Thu Jan 01 00:00:00 1970 +0000 | |
160 | # Node ID ef0ef43d49e79e81ddafdc7997401ba0041efc82 |
|
160 | # Node ID ef0ef43d49e79e81ddafdc7997401ba0041efc82 | |
161 | # Parent 68795b066622ca79a25816a662041d8f78f3cd9e |
|
161 | # Parent 68795b066622ca79a25816a662041d8f78f3cd9e | |
162 | 2 |
|
162 | 2 | |
163 |
|
163 | |||
164 | diff --git a/a b/b |
|
164 | diff --git a/a b/b | |
165 | rename from a |
|
165 | rename from a | |
166 | rename to b |
|
166 | rename to b | |
167 |
|
167 | |||
168 | Look for extra:source |
|
168 | Look for extra:source | |
169 |
|
169 | |||
170 | $ hg log --debug -r tip |
|
170 | $ hg log --debug -r tip | |
171 | changeset: 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82 |
|
171 | changeset: 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82 | |
172 | tag: tip |
|
172 | tag: tip | |
173 | phase: draft |
|
173 | phase: draft | |
174 | parent: 0:68795b066622ca79a25816a662041d8f78f3cd9e |
|
174 | parent: 0:68795b066622ca79a25816a662041d8f78f3cd9e | |
175 | parent: -1:0000000000000000000000000000000000000000 |
|
175 | parent: -1:0000000000000000000000000000000000000000 | |
176 | manifest: 7:e59b6b228f9cbf9903d5e9abf996e083a1f533eb |
|
176 | manifest: 7:e59b6b228f9cbf9903d5e9abf996e083a1f533eb | |
177 | user: foo |
|
177 | user: foo | |
178 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
178 | date: Thu Jan 01 00:00:00 1970 +0000 | |
179 | files+: b |
|
179 | files+: b | |
180 | files-: a |
|
180 | files-: a | |
181 | extra: branch=default |
|
181 | extra: branch=default | |
182 | extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4 |
|
182 | extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4 | |
183 | description: |
|
183 | description: | |
184 | 2 |
|
184 | 2 | |
185 |
|
185 | |||
186 |
|
186 | |||
187 |
|
187 | |||
188 | Graft out of order, skipping a merge and a duplicate |
|
188 | Graft out of order, skipping a merge and a duplicate | |
189 | (this also tests that editor is not invoked if '--edit' is not specified) |
|
189 | (this also tests that editor is not invoked if '--edit' is not specified) | |
190 |
|
190 | |||
191 | $ hg graft 1 5 4 3 'merge()' 2 -n |
|
191 | $ hg graft 1 5 4 3 'merge()' 2 -n | |
192 | skipping ungraftable merge revision 6 |
|
192 | skipping ungraftable merge revision 6 | |
193 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) |
|
193 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) | |
194 | grafting 1:5d205f8b35b6 "1" |
|
194 | grafting 1:5d205f8b35b6 "1" | |
195 | grafting 5:97f8bfe72746 "5" |
|
195 | grafting 5:97f8bfe72746 "5" | |
196 | grafting 4:9c233e8e184d "4" |
|
196 | grafting 4:9c233e8e184d "4" | |
197 | grafting 3:4c60f11aa304 "3" |
|
197 | grafting 3:4c60f11aa304 "3" | |
198 |
|
198 | |||
199 | $ HGEDITOR=cat hg graft 1 5 'merge()' 2 --debug |
|
199 | $ HGEDITOR=cat hg graft 1 5 'merge()' 2 --debug | |
200 | skipping ungraftable merge revision 6 |
|
200 | skipping ungraftable merge revision 6 | |
201 | scanning for duplicate grafts |
|
201 | scanning for duplicate grafts | |
202 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) |
|
202 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) | |
203 | grafting 1:5d205f8b35b6 "1" |
|
203 | grafting 1:5d205f8b35b6 "1" | |
204 | unmatched files in local: |
|
204 | unmatched files in local: | |
205 | b |
|
205 | b | |
206 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): |
|
206 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): | |
207 | on local side: |
|
207 | on local side: | |
208 | src: 'a' -> dst: 'b' * |
|
208 | src: 'a' -> dst: 'b' * | |
209 | checking for directory renames |
|
209 | checking for directory renames | |
210 | resolving manifests |
|
210 | resolving manifests | |
211 | branchmerge: True, force: True, partial: False |
|
211 | branchmerge: True, force: True, partial: False | |
212 | ancestor: 68795b066622, local: ef0ef43d49e7+, remote: 5d205f8b35b6 |
|
212 | ancestor: 68795b066622, local: ef0ef43d49e7+, remote: 5d205f8b35b6 | |
213 | preserving b for resolve of b |
|
213 | preserving b for resolve of b | |
214 | starting 4 threads for background file closing (?) |
|
214 | starting 4 threads for background file closing (?) | |
215 | b: local copied/moved from a -> m (premerge) |
|
215 | b: local copied/moved from a -> m (premerge) | |
216 | picked tool ':merge' for b (binary False symlink False changedelete False) |
|
216 | picked tool ':merge' for b (binary False symlink False changedelete False) | |
217 | merging b and a to b |
|
217 | merging b and a to b | |
218 | my b@ef0ef43d49e7+ other a@5d205f8b35b6 ancestor a@68795b066622 |
|
218 | my b@ef0ef43d49e7+ other a@5d205f8b35b6 ancestor a@68795b066622 | |
219 | premerge successful |
|
219 | premerge successful | |
220 | committing files: |
|
220 | committing files: | |
221 | b |
|
221 | b | |
222 | committing manifest |
|
222 | committing manifest | |
223 | committing changelog |
|
223 | committing changelog | |
224 | updating the branch cache |
|
224 | updating the branch cache | |
225 | grafting 5:97f8bfe72746 "5" |
|
225 | grafting 5:97f8bfe72746 "5" | |
226 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): |
|
226 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): | |
227 | on local side: |
|
227 | on local side: | |
228 | src: 'c' -> dst: 'b' |
|
228 | src: 'c' -> dst: 'b' | |
229 | checking for directory renames |
|
229 | checking for directory renames | |
230 | resolving manifests |
|
230 | resolving manifests | |
231 | branchmerge: True, force: True, partial: False |
|
231 | branchmerge: True, force: True, partial: False | |
232 | ancestor: 4c60f11aa304, local: 6b9e5368ca4e+, remote: 97f8bfe72746 |
|
232 | ancestor: 4c60f11aa304, local: 6b9e5368ca4e+, remote: 97f8bfe72746 | |
233 | e: remote is newer -> g |
|
233 | e: remote is newer -> g | |
234 | getting e |
|
234 | getting e | |
235 | committing files: |
|
235 | committing files: | |
236 | e |
|
236 | e | |
237 | committing manifest |
|
237 | committing manifest | |
238 | committing changelog |
|
238 | committing changelog | |
239 | updating the branch cache |
|
239 | updating the branch cache | |
240 | $ HGEDITOR=cat hg graft 4 3 --log --debug |
|
240 | $ HGEDITOR=cat hg graft 4 3 --log --debug | |
241 | scanning for duplicate grafts |
|
241 | scanning for duplicate grafts | |
242 | grafting 4:9c233e8e184d "4" |
|
242 | grafting 4:9c233e8e184d "4" | |
243 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): |
|
243 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): | |
244 | on local side: |
|
244 | on local side: | |
245 | src: 'c' -> dst: 'b' |
|
245 | src: 'c' -> dst: 'b' | |
246 | checking for directory renames |
|
246 | checking for directory renames | |
247 | resolving manifests |
|
247 | resolving manifests | |
248 | branchmerge: True, force: True, partial: False |
|
248 | branchmerge: True, force: True, partial: False | |
249 | ancestor: 4c60f11aa304, local: 1905859650ec+, remote: 9c233e8e184d |
|
249 | ancestor: 4c60f11aa304, local: 1905859650ec+, remote: 9c233e8e184d | |
250 | preserving e for resolve of e |
|
250 | preserving e for resolve of e | |
251 | d: remote is newer -> g |
|
251 | d: remote is newer -> g | |
252 | getting d |
|
252 | getting d | |
253 | e: versions differ -> m (premerge) |
|
253 | e: versions differ -> m (premerge) | |
254 | picked tool ':merge' for e (binary False symlink False changedelete False) |
|
254 | picked tool ':merge' for e (binary False symlink False changedelete False) | |
255 | merging e |
|
255 | merging e | |
256 | my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304 |
|
256 | my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304 | |
257 | e: versions differ -> m (merge) |
|
257 | e: versions differ -> m (merge) | |
258 | picked tool ':merge' for e (binary False symlink False changedelete False) |
|
258 | picked tool ':merge' for e (binary False symlink False changedelete False) | |
259 | my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304 |
|
259 | my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304 | |
260 | warning: conflicts while merging e! (edit, then use 'hg resolve --mark') |
|
260 | warning: conflicts while merging e! (edit, then use 'hg resolve --mark') | |
261 | abort: unresolved conflicts, can't continue |
|
261 | abort: unresolved conflicts, can't continue | |
262 | (use 'hg resolve' and 'hg graft --continue') |
|
262 | (use 'hg resolve' and 'hg graft --continue') | |
263 | [255] |
|
263 | [255] | |
264 |
|
264 | |||
265 | Summary should mention graft: |
|
265 | Summary should mention graft: | |
266 |
|
266 | |||
267 | $ hg summary |grep graft |
|
267 | $ hg summary |grep graft | |
268 | commit: 2 modified, 2 unknown, 1 unresolved (graft in progress) |
|
268 | commit: 2 modified, 2 unknown, 1 unresolved (graft in progress) | |
269 |
|
269 | |||
270 | Using status to get more context |
|
270 | Using status to get more context | |
271 |
|
271 | |||
272 | $ hg status --verbose |
|
272 | $ hg status --verbose | |
273 | M d |
|
273 | M d | |
274 | M e |
|
274 | M e | |
275 | ? a.orig |
|
275 | ? a.orig | |
276 | ? e.orig |
|
276 | ? e.orig | |
277 | # The repository is in an unfinished *graft* state. |
|
277 | # The repository is in an unfinished *graft* state. | |
278 |
|
278 | |||
279 | # Unresolved merge conflicts: |
|
279 | # Unresolved merge conflicts: | |
280 | # |
|
280 | # | |
281 | # e |
|
281 | # e | |
282 | # |
|
282 | # | |
283 | # To mark files as resolved: hg resolve --mark FILE |
|
283 | # To mark files as resolved: hg resolve --mark FILE | |
284 |
|
284 | |||
285 | # To continue: hg graft --continue |
|
285 | # To continue: hg graft --continue | |
286 | # To abort: hg graft --abort |
|
286 | # To abort: hg graft --abort | |
287 | # To stop: hg graft --stop |
|
287 | # To stop: hg graft --stop | |
288 |
|
288 | |||
289 |
|
289 | |||
290 | Commit while interrupted should fail: |
|
290 | Commit while interrupted should fail: | |
291 |
|
291 | |||
292 | $ hg ci -m 'commit interrupted graft' |
|
292 | $ hg ci -m 'commit interrupted graft' | |
293 | abort: graft in progress |
|
293 | abort: graft in progress | |
294 | (use 'hg graft --continue' or 'hg graft --stop' to stop) |
|
294 | (use 'hg graft --continue' or 'hg graft --stop' to stop) | |
295 | [255] |
|
295 | [255] | |
296 |
|
296 | |||
297 | Abort the graft and try committing: |
|
297 | Abort the graft and try committing: | |
298 |
|
298 | |||
299 | $ hg up -C . |
|
299 | $ hg up -C . | |
300 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
300 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
301 | $ echo c >> e |
|
301 | $ echo c >> e | |
302 | $ hg ci -mtest |
|
302 | $ hg ci -mtest | |
303 |
|
303 | |||
304 | $ hg strip . --config extensions.strip= |
|
304 | $ hg strip . --config extensions.strip= | |
305 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
305 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
306 | saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob) |
|
306 | saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob) | |
307 |
|
307 | |||
308 | Graft again: |
|
308 | Graft again: | |
309 |
|
309 | |||
310 | $ hg graft 1 5 4 3 'merge()' 2 |
|
310 | $ hg graft 1 5 4 3 'merge()' 2 | |
311 | skipping ungraftable merge revision 6 |
|
311 | skipping ungraftable merge revision 6 | |
312 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) |
|
312 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) | |
313 | skipping revision 1:5d205f8b35b6 (already grafted to 8:6b9e5368ca4e) |
|
313 | skipping revision 1:5d205f8b35b6 (already grafted to 8:6b9e5368ca4e) | |
314 | skipping revision 5:97f8bfe72746 (already grafted to 9:1905859650ec) |
|
314 | skipping revision 5:97f8bfe72746 (already grafted to 9:1905859650ec) | |
315 | grafting 4:9c233e8e184d "4" |
|
315 | grafting 4:9c233e8e184d "4" | |
316 | merging e |
|
316 | merging e | |
317 | warning: conflicts while merging e! (edit, then use 'hg resolve --mark') |
|
317 | warning: conflicts while merging e! (edit, then use 'hg resolve --mark') | |
318 | abort: unresolved conflicts, can't continue |
|
318 | abort: unresolved conflicts, can't continue | |
319 | (use 'hg resolve' and 'hg graft --continue') |
|
319 | (use 'hg resolve' and 'hg graft --continue') | |
320 | [255] |
|
320 | [255] | |
321 |
|
321 | |||
322 | Continue without resolve should fail: |
|
322 | Continue without resolve should fail: | |
323 |
|
323 | |||
324 | $ hg graft -c |
|
324 | $ hg graft -c | |
325 | grafting 4:9c233e8e184d "4" |
|
325 | grafting 4:9c233e8e184d "4" | |
326 | abort: unresolved merge conflicts (see 'hg help resolve') |
|
326 | abort: unresolved merge conflicts (see 'hg help resolve') | |
327 | [255] |
|
327 | [255] | |
328 |
|
328 | |||
329 | Fix up: |
|
329 | Fix up: | |
330 |
|
330 | |||
331 | $ echo b > e |
|
331 | $ echo b > e | |
332 | $ hg resolve -m e |
|
332 | $ hg resolve -m e | |
333 | (no more unresolved files) |
|
333 | (no more unresolved files) | |
334 | continue: hg graft --continue |
|
334 | continue: hg graft --continue | |
335 |
|
335 | |||
336 | Continue with a revision should fail: |
|
336 | Continue with a revision should fail: | |
337 |
|
337 | |||
338 | $ hg graft -c 6 |
|
338 | $ hg graft -c 6 | |
339 | abort: can't specify --continue and revisions |
|
339 | abort: can't specify --continue and revisions | |
340 | [255] |
|
340 | [255] | |
341 |
|
341 | |||
342 | $ hg graft -c -r 6 |
|
342 | $ hg graft -c -r 6 | |
343 | abort: can't specify --continue and revisions |
|
343 | abort: can't specify --continue and revisions | |
344 | [255] |
|
344 | [255] | |
345 |
|
345 | |||
346 | Continue for real, clobber usernames |
|
346 | Continue for real, clobber usernames | |
347 |
|
347 | |||
348 | $ hg graft -c -U |
|
348 | $ hg graft -c -U | |
349 | grafting 4:9c233e8e184d "4" |
|
349 | grafting 4:9c233e8e184d "4" | |
350 | grafting 3:4c60f11aa304 "3" |
|
350 | grafting 3:4c60f11aa304 "3" | |
351 |
|
351 | |||
352 | Compare with original: |
|
352 | Compare with original: | |
353 |
|
353 | |||
354 | $ hg diff -r 6 |
|
354 | $ hg diff -r 6 | |
355 | $ hg status --rev 0:. -C |
|
355 | $ hg status --rev 0:. -C | |
356 | M d |
|
356 | M d | |
357 | M e |
|
357 | M e | |
358 | A b |
|
358 | A b | |
359 | a |
|
359 | a | |
360 | A c |
|
360 | A c | |
361 | a |
|
361 | a | |
362 | R a |
|
362 | R a | |
363 |
|
363 | |||
364 | View graph: |
|
364 | View graph: | |
365 |
|
365 | |||
366 | $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n' |
|
366 | $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n' | |
367 | @ test@11.draft: 3 |
|
367 | @ test@11.draft: 3 | |
368 | | |
|
368 | | | |
369 | o test@10.draft: 4 |
|
369 | o test@10.draft: 4 | |
370 | | |
|
370 | | | |
371 | o test@9.draft: 5 |
|
371 | o test@9.draft: 5 | |
372 | | |
|
372 | | | |
373 | o bar@8.draft: 1 |
|
373 | o bar@8.draft: 1 | |
374 | | |
|
374 | | | |
375 | o foo@7.draft: 2 |
|
375 | o foo@7.draft: 2 | |
376 | | |
|
376 | | | |
377 | | o test@6.secret: 6 |
|
377 | | o test@6.secret: 6 | |
378 | | |\ |
|
378 | | |\ | |
379 | | | o test@5.draft: 5 |
|
379 | | | o test@5.draft: 5 | |
380 | | | | |
|
380 | | | | | |
381 | | o | test@4.draft: 4 |
|
381 | | o | test@4.draft: 4 | |
382 | | |/ |
|
382 | | |/ | |
383 | | o baz@3.public: 3 |
|
383 | | o baz@3.public: 3 | |
384 | | | |
|
384 | | | | |
385 | | o test@2.public: 2 |
|
385 | | o test@2.public: 2 | |
386 | | | |
|
386 | | | | |
387 | | o bar@1.public: 1 |
|
387 | | o bar@1.public: 1 | |
388 | |/ |
|
388 | |/ | |
389 | o test@0.public: 0 |
|
389 | o test@0.public: 0 | |
390 |
|
390 | |||
391 | Graft again onto another branch should preserve the original source |
|
391 | Graft again onto another branch should preserve the original source | |
392 | $ hg up -q 0 |
|
392 | $ hg up -q 0 | |
393 | $ echo 'g'>g |
|
393 | $ echo 'g'>g | |
394 | $ hg add g |
|
394 | $ hg add g | |
395 | $ hg ci -m 7 |
|
395 | $ hg ci -m 7 | |
396 | created new head |
|
396 | created new head | |
397 | $ hg graft 7 |
|
397 | $ hg graft 7 | |
398 | grafting 7:ef0ef43d49e7 "2" |
|
398 | grafting 7:ef0ef43d49e7 "2" | |
399 |
|
399 | |||
400 | $ hg log -r 7 --template '{rev}:{node}\n' |
|
400 | $ hg log -r 7 --template '{rev}:{node}\n' | |
401 | 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82 |
|
401 | 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82 | |
402 | $ hg log -r 2 --template '{rev}:{node}\n' |
|
402 | $ hg log -r 2 --template '{rev}:{node}\n' | |
403 | 2:5c095ad7e90f871700f02dd1fa5012cb4498a2d4 |
|
403 | 2:5c095ad7e90f871700f02dd1fa5012cb4498a2d4 | |
404 |
|
404 | |||
405 | $ hg log --debug -r tip |
|
405 | $ hg log --debug -r tip | |
406 | changeset: 13:7a4785234d87ec1aa420ed6b11afe40fa73e12a9 |
|
406 | changeset: 13:7a4785234d87ec1aa420ed6b11afe40fa73e12a9 | |
407 | tag: tip |
|
407 | tag: tip | |
408 | phase: draft |
|
408 | phase: draft | |
409 | parent: 12:b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f |
|
409 | parent: 12:b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f | |
410 | parent: -1:0000000000000000000000000000000000000000 |
|
410 | parent: -1:0000000000000000000000000000000000000000 | |
411 | manifest: 13:dc313617b8c32457c0d589e0dbbedfe71f3cd637 |
|
411 | manifest: 13:dc313617b8c32457c0d589e0dbbedfe71f3cd637 | |
412 | user: foo |
|
412 | user: foo | |
413 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
413 | date: Thu Jan 01 00:00:00 1970 +0000 | |
414 | files+: b |
|
414 | files+: b | |
415 | files-: a |
|
415 | files-: a | |
416 | extra: branch=default |
|
416 | extra: branch=default | |
417 | extra: intermediate-source=ef0ef43d49e79e81ddafdc7997401ba0041efc82 |
|
417 | extra: intermediate-source=ef0ef43d49e79e81ddafdc7997401ba0041efc82 | |
418 | extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4 |
|
418 | extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4 | |
419 | description: |
|
419 | description: | |
420 | 2 |
|
420 | 2 | |
421 |
|
421 | |||
422 |
|
422 | |||
423 | Disallow grafting an already grafted cset onto its original branch |
|
423 | Disallow grafting an already grafted cset onto its original branch | |
424 | $ hg up -q 6 |
|
424 | $ hg up -q 6 | |
425 | $ hg graft 7 |
|
425 | $ hg graft 7 | |
426 | skipping already grafted revision 7:ef0ef43d49e7 (was grafted from 2:5c095ad7e90f) |
|
426 | skipping already grafted revision 7:ef0ef43d49e7 (was grafted from 2:5c095ad7e90f) | |
427 | [255] |
|
427 | [255] | |
428 |
|
428 | |||
429 | $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 |
|
429 | $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 | |
430 | --- */hg-5c095ad7e90f.patch * (glob) |
|
430 | --- */hg-5c095ad7e90f.patch * (glob) | |
431 | +++ */hg-7a4785234d87.patch * (glob) |
|
431 | +++ */hg-7a4785234d87.patch * (glob) | |
432 | @@ -1,18 +1,18 @@ |
|
432 | @@ -1,18 +1,18 @@ | |
433 | # HG changeset patch |
|
433 | # HG changeset patch | |
434 | -# User test |
|
434 | -# User test | |
435 | +# User foo |
|
435 | +# User foo | |
436 | # Date 0 0 |
|
436 | # Date 0 0 | |
437 | # Thu Jan 01 00:00:00 1970 +0000 |
|
437 | # Thu Jan 01 00:00:00 1970 +0000 | |
438 | -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4 |
|
438 | -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4 | |
439 | -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04 |
|
439 | -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04 | |
440 | +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9 |
|
440 | +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9 | |
441 | +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f |
|
441 | +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f | |
442 | 2 |
|
442 | 2 | |
443 |
|
443 | |||
444 | -diff -r 5d205f8b35b6 -r 5c095ad7e90f a |
|
444 | -diff -r 5d205f8b35b6 -r 5c095ad7e90f a | |
445 | +diff -r b592ea63bb0c -r 7a4785234d87 a |
|
445 | +diff -r b592ea63bb0c -r 7a4785234d87 a | |
446 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
446 | --- a/a Thu Jan 01 00:00:00 1970 +0000 | |
447 | +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
447 | +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
448 | @@ -1,1 +0,0 @@ |
|
448 | @@ -1,1 +0,0 @@ | |
449 | --b |
|
449 | --b | |
450 | -diff -r 5d205f8b35b6 -r 5c095ad7e90f b |
|
450 | -diff -r 5d205f8b35b6 -r 5c095ad7e90f b | |
451 | +-a |
|
451 | +-a | |
452 | +diff -r b592ea63bb0c -r 7a4785234d87 b |
|
452 | +diff -r b592ea63bb0c -r 7a4785234d87 b | |
453 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
453 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
454 | +++ b/b Thu Jan 01 00:00:00 1970 +0000 |
|
454 | +++ b/b Thu Jan 01 00:00:00 1970 +0000 | |
455 | @@ -0,0 +1,1 @@ |
|
455 | @@ -0,0 +1,1 @@ | |
456 | -+b |
|
456 | -+b | |
457 | ++a |
|
457 | ++a | |
458 | [1] |
|
458 | [1] | |
459 |
|
459 | |||
460 | $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 -X . |
|
460 | $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 -X . | |
461 | --- */hg-5c095ad7e90f.patch * (glob) |
|
461 | --- */hg-5c095ad7e90f.patch * (glob) | |
462 | +++ */hg-7a4785234d87.patch * (glob) |
|
462 | +++ */hg-7a4785234d87.patch * (glob) | |
463 | @@ -1,8 +1,8 @@ |
|
463 | @@ -1,8 +1,8 @@ | |
464 | # HG changeset patch |
|
464 | # HG changeset patch | |
465 | -# User test |
|
465 | -# User test | |
466 | +# User foo |
|
466 | +# User foo | |
467 | # Date 0 0 |
|
467 | # Date 0 0 | |
468 | # Thu Jan 01 00:00:00 1970 +0000 |
|
468 | # Thu Jan 01 00:00:00 1970 +0000 | |
469 | -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4 |
|
469 | -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4 | |
470 | -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04 |
|
470 | -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04 | |
471 | +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9 |
|
471 | +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9 | |
472 | +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f |
|
472 | +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f | |
473 | 2 |
|
473 | 2 | |
474 |
|
474 | |||
475 | [1] |
|
475 | [1] | |
476 |
|
476 | |||
477 | Disallow grafting already grafted csets with the same origin onto each other |
|
477 | Disallow grafting already grafted csets with the same origin onto each other | |
478 | $ hg up -q 13 |
|
478 | $ hg up -q 13 | |
479 | $ hg graft 2 |
|
479 | $ hg graft 2 | |
480 | skipping revision 2:5c095ad7e90f (already grafted to 13:7a4785234d87) |
|
480 | skipping revision 2:5c095ad7e90f (already grafted to 13:7a4785234d87) | |
481 | [255] |
|
481 | [255] | |
482 | $ hg graft 7 |
|
482 | $ hg graft 7 | |
483 | skipping already grafted revision 7:ef0ef43d49e7 (13:7a4785234d87 also has origin 2:5c095ad7e90f) |
|
483 | skipping already grafted revision 7:ef0ef43d49e7 (13:7a4785234d87 also has origin 2:5c095ad7e90f) | |
484 | [255] |
|
484 | [255] | |
485 |
|
485 | |||
486 | $ hg up -q 7 |
|
486 | $ hg up -q 7 | |
487 | $ hg graft 2 |
|
487 | $ hg graft 2 | |
488 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) |
|
488 | skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7) | |
489 | [255] |
|
489 | [255] | |
490 | $ hg graft tip |
|
490 | $ hg graft tip | |
491 | skipping already grafted revision 13:7a4785234d87 (7:ef0ef43d49e7 also has origin 2:5c095ad7e90f) |
|
491 | skipping already grafted revision 13:7a4785234d87 (7:ef0ef43d49e7 also has origin 2:5c095ad7e90f) | |
492 | [255] |
|
492 | [255] | |
493 |
|
493 | |||
494 | Graft with --log |
|
494 | Graft with --log | |
495 |
|
495 | |||
496 | $ hg up -Cq 1 |
|
496 | $ hg up -Cq 1 | |
497 | $ hg graft 3 --log -u foo |
|
497 | $ hg graft 3 --log -u foo | |
498 | grafting 3:4c60f11aa304 "3" |
|
498 | grafting 3:4c60f11aa304 "3" | |
499 | $ hg log --template '{rev}:{node|short} {parents} {desc}\n' -r tip |
|
499 | $ hg log --template '{rev}:{node|short} {parents} {desc}\n' -r tip | |
500 | 14:0c921c65ef1e 1:5d205f8b35b6 3 |
|
500 | 14:0c921c65ef1e 1:5d205f8b35b6 3 | |
501 | (grafted from 4c60f11aa304a54ae1c199feb94e7fc771e51ed8) |
|
501 | (grafted from 4c60f11aa304a54ae1c199feb94e7fc771e51ed8) | |
502 |
|
502 | |||
503 | Resolve conflicted graft |
|
503 | Resolve conflicted graft | |
504 | $ hg up -q 0 |
|
504 | $ hg up -q 0 | |
505 | $ echo b > a |
|
505 | $ echo b > a | |
506 | $ hg ci -m 8 |
|
506 | $ hg ci -m 8 | |
507 | created new head |
|
507 | created new head | |
508 | $ echo c > a |
|
508 | $ echo c > a | |
509 | $ hg ci -m 9 |
|
509 | $ hg ci -m 9 | |
510 | $ hg graft 1 --tool internal:fail |
|
510 | $ hg graft 1 --tool internal:fail | |
511 | grafting 1:5d205f8b35b6 "1" |
|
511 | grafting 1:5d205f8b35b6 "1" | |
512 | abort: unresolved conflicts, can't continue |
|
512 | abort: unresolved conflicts, can't continue | |
513 | (use 'hg resolve' and 'hg graft --continue') |
|
513 | (use 'hg resolve' and 'hg graft --continue') | |
514 | [255] |
|
514 | [255] | |
515 | $ hg resolve --all |
|
515 | $ hg resolve --all | |
516 | merging a |
|
516 | merging a | |
517 | warning: conflicts while merging a! (edit, then use 'hg resolve --mark') |
|
517 | warning: conflicts while merging a! (edit, then use 'hg resolve --mark') | |
518 | [1] |
|
518 | [1] | |
519 | $ cat a |
|
519 | $ cat a | |
520 | <<<<<<< local: aaa4406d4f0a - test: 9 |
|
520 | <<<<<<< local: aaa4406d4f0a - test: 9 | |
521 | c |
|
521 | c | |
522 | ======= |
|
522 | ======= | |
523 | b |
|
523 | b | |
524 | >>>>>>> graft: 5d205f8b35b6 - bar: 1 |
|
524 | >>>>>>> graft: 5d205f8b35b6 - bar: 1 | |
525 | $ echo b > a |
|
525 | $ echo b > a | |
526 | $ hg resolve -m a |
|
526 | $ hg resolve -m a | |
527 | (no more unresolved files) |
|
527 | (no more unresolved files) | |
528 | continue: hg graft --continue |
|
528 | continue: hg graft --continue | |
529 | $ hg graft -c |
|
529 | $ hg graft -c | |
530 | grafting 1:5d205f8b35b6 "1" |
|
530 | grafting 1:5d205f8b35b6 "1" | |
531 | $ hg export tip --git |
|
531 | $ hg export tip --git | |
532 | # HG changeset patch |
|
532 | # HG changeset patch | |
533 | # User bar |
|
533 | # User bar | |
534 | # Date 0 0 |
|
534 | # Date 0 0 | |
535 | # Thu Jan 01 00:00:00 1970 +0000 |
|
535 | # Thu Jan 01 00:00:00 1970 +0000 | |
536 | # Node ID f67661df0c4804d301f064f332b57e7d5ddaf2be |
|
536 | # Node ID f67661df0c4804d301f064f332b57e7d5ddaf2be | |
537 | # Parent aaa4406d4f0ae9befd6e58c82ec63706460cbca6 |
|
537 | # Parent aaa4406d4f0ae9befd6e58c82ec63706460cbca6 | |
538 | 1 |
|
538 | 1 | |
539 |
|
539 | |||
540 | diff --git a/a b/a |
|
540 | diff --git a/a b/a | |
541 | --- a/a |
|
541 | --- a/a | |
542 | +++ b/a |
|
542 | +++ b/a | |
543 | @@ -1,1 +1,1 @@ |
|
543 | @@ -1,1 +1,1 @@ | |
544 | -c |
|
544 | -c | |
545 | +b |
|
545 | +b | |
546 |
|
546 | |||
547 | Resolve conflicted graft with rename |
|
547 | Resolve conflicted graft with rename | |
548 | $ echo c > a |
|
548 | $ echo c > a | |
549 | $ hg ci -m 10 |
|
549 | $ hg ci -m 10 | |
550 | $ hg graft 2 --tool internal:fail |
|
550 | $ hg graft 2 --tool internal:fail | |
551 | grafting 2:5c095ad7e90f "2" |
|
551 | grafting 2:5c095ad7e90f "2" | |
552 | abort: unresolved conflicts, can't continue |
|
552 | abort: unresolved conflicts, can't continue | |
553 | (use 'hg resolve' and 'hg graft --continue') |
|
553 | (use 'hg resolve' and 'hg graft --continue') | |
554 | [255] |
|
554 | [255] | |
555 | $ hg resolve --all |
|
555 | $ hg resolve --all | |
556 | merging a and b to b |
|
556 | merging a and b to b | |
557 | (no more unresolved files) |
|
557 | (no more unresolved files) | |
558 | continue: hg graft --continue |
|
558 | continue: hg graft --continue | |
559 | $ hg graft -c |
|
559 | $ hg graft -c | |
560 | grafting 2:5c095ad7e90f "2" |
|
560 | grafting 2:5c095ad7e90f "2" | |
561 | $ hg export tip --git |
|
561 | $ hg export tip --git | |
562 | # HG changeset patch |
|
562 | # HG changeset patch | |
563 | # User test |
|
563 | # User test | |
564 | # Date 0 0 |
|
564 | # Date 0 0 | |
565 | # Thu Jan 01 00:00:00 1970 +0000 |
|
565 | # Thu Jan 01 00:00:00 1970 +0000 | |
566 | # Node ID 9627f653b421c61fc1ea4c4e366745070fa3d2bc |
|
566 | # Node ID 9627f653b421c61fc1ea4c4e366745070fa3d2bc | |
567 | # Parent ee295f490a40b97f3d18dd4c4f1c8936c233b612 |
|
567 | # Parent ee295f490a40b97f3d18dd4c4f1c8936c233b612 | |
568 | 2 |
|
568 | 2 | |
569 |
|
569 | |||
570 | diff --git a/a b/b |
|
570 | diff --git a/a b/b | |
571 | rename from a |
|
571 | rename from a | |
572 | rename to b |
|
572 | rename to b | |
573 |
|
573 | |||
574 | Test simple origin(), with and without args |
|
574 | Test simple origin(), with and without args | |
575 | $ hg log -r 'origin()' |
|
575 | $ hg log -r 'origin()' | |
576 | changeset: 1:5d205f8b35b6 |
|
576 | changeset: 1:5d205f8b35b6 | |
577 | user: bar |
|
577 | user: bar | |
578 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
578 | date: Thu Jan 01 00:00:00 1970 +0000 | |
579 | summary: 1 |
|
579 | summary: 1 | |
580 |
|
580 | |||
581 | changeset: 2:5c095ad7e90f |
|
581 | changeset: 2:5c095ad7e90f | |
582 | user: test |
|
582 | user: test | |
583 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
583 | date: Thu Jan 01 00:00:00 1970 +0000 | |
584 | summary: 2 |
|
584 | summary: 2 | |
585 |
|
585 | |||
586 | changeset: 3:4c60f11aa304 |
|
586 | changeset: 3:4c60f11aa304 | |
587 | user: baz |
|
587 | user: baz | |
588 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
588 | date: Thu Jan 01 00:00:00 1970 +0000 | |
589 | summary: 3 |
|
589 | summary: 3 | |
590 |
|
590 | |||
591 | changeset: 4:9c233e8e184d |
|
591 | changeset: 4:9c233e8e184d | |
592 | user: test |
|
592 | user: test | |
593 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
593 | date: Thu Jan 01 00:00:00 1970 +0000 | |
594 | summary: 4 |
|
594 | summary: 4 | |
595 |
|
595 | |||
596 | changeset: 5:97f8bfe72746 |
|
596 | changeset: 5:97f8bfe72746 | |
597 | branch: stable |
|
597 | branch: stable | |
598 | parent: 3:4c60f11aa304 |
|
598 | parent: 3:4c60f11aa304 | |
599 | user: test |
|
599 | user: test | |
600 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
600 | date: Thu Jan 01 00:00:00 1970 +0000 | |
601 | summary: 5 |
|
601 | summary: 5 | |
602 |
|
602 | |||
603 | $ hg log -r 'origin(7)' |
|
603 | $ hg log -r 'origin(7)' | |
604 | changeset: 2:5c095ad7e90f |
|
604 | changeset: 2:5c095ad7e90f | |
605 | user: test |
|
605 | user: test | |
606 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
606 | date: Thu Jan 01 00:00:00 1970 +0000 | |
607 | summary: 2 |
|
607 | summary: 2 | |
608 |
|
608 | |||
609 | Now transplant a graft to test following through copies |
|
609 | Now transplant a graft to test following through copies | |
610 | $ hg up -q 0 |
|
610 | $ hg up -q 0 | |
611 | $ hg branch -q dev |
|
611 | $ hg branch -q dev | |
612 | $ hg ci -qm "dev branch" |
|
612 | $ hg ci -qm "dev branch" | |
613 | $ hg --config extensions.transplant= transplant -q 7 |
|
613 | $ hg --config extensions.transplant= transplant -q 7 | |
614 | $ hg log -r 'origin(.)' |
|
614 | $ hg log -r 'origin(.)' | |
615 | changeset: 2:5c095ad7e90f |
|
615 | changeset: 2:5c095ad7e90f | |
616 | user: test |
|
616 | user: test | |
617 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
617 | date: Thu Jan 01 00:00:00 1970 +0000 | |
618 | summary: 2 |
|
618 | summary: 2 | |
619 |
|
619 | |||
620 | Test that the graft and transplant markers in extra are converted, allowing |
|
620 | Test that the graft and transplant markers in extra are converted, allowing | |
621 | origin() to still work. Note that these recheck the immediately preceeding two |
|
621 | origin() to still work. Note that these recheck the immediately preceeding two | |
622 | tests. |
|
622 | tests. | |
623 | $ hg --quiet --config extensions.convert= --config convert.hg.saverev=True convert . ../converted |
|
623 | $ hg --quiet --config extensions.convert= --config convert.hg.saverev=True convert . ../converted | |
624 |
|
624 | |||
625 | The graft case |
|
625 | The graft case | |
626 | $ hg -R ../converted log -r 7 --template "{rev}: {node}\n{join(extras, '\n')}\n" |
|
626 | $ hg -R ../converted log -r 7 --template "{rev}: {node}\n{join(extras, '\n')}\n" | |
627 | 7: 7ae846e9111fc8f57745634250c7b9ac0a60689b |
|
627 | 7: 7ae846e9111fc8f57745634250c7b9ac0a60689b | |
628 | branch=default |
|
628 | branch=default | |
629 | convert_revision=ef0ef43d49e79e81ddafdc7997401ba0041efc82 |
|
629 | convert_revision=ef0ef43d49e79e81ddafdc7997401ba0041efc82 | |
630 | source=e0213322b2c1a5d5d236c74e79666441bee67a7d |
|
630 | source=e0213322b2c1a5d5d236c74e79666441bee67a7d | |
631 | $ hg -R ../converted log -r 'origin(7)' |
|
631 | $ hg -R ../converted log -r 'origin(7)' | |
632 | changeset: 2:e0213322b2c1 |
|
632 | changeset: 2:e0213322b2c1 | |
633 | user: test |
|
633 | user: test | |
634 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
634 | date: Thu Jan 01 00:00:00 1970 +0000 | |
635 | summary: 2 |
|
635 | summary: 2 | |
636 |
|
636 | |||
637 | Test that template correctly expands more than one 'extra' (issue4362), and that |
|
637 | Test that template correctly expands more than one 'extra' (issue4362), and that | |
638 | 'intermediate-source' is converted. |
|
638 | 'intermediate-source' is converted. | |
639 | $ hg -R ../converted log -r 13 --template "{extras % ' Extra: {extra}\n'}" |
|
639 | $ hg -R ../converted log -r 13 --template "{extras % ' Extra: {extra}\n'}" | |
640 | Extra: branch=default |
|
640 | Extra: branch=default | |
641 | Extra: convert_revision=7a4785234d87ec1aa420ed6b11afe40fa73e12a9 |
|
641 | Extra: convert_revision=7a4785234d87ec1aa420ed6b11afe40fa73e12a9 | |
642 | Extra: intermediate-source=7ae846e9111fc8f57745634250c7b9ac0a60689b |
|
642 | Extra: intermediate-source=7ae846e9111fc8f57745634250c7b9ac0a60689b | |
643 | Extra: source=e0213322b2c1a5d5d236c74e79666441bee67a7d |
|
643 | Extra: source=e0213322b2c1a5d5d236c74e79666441bee67a7d | |
644 |
|
644 | |||
645 | The transplant case |
|
645 | The transplant case | |
646 | $ hg -R ../converted log -r tip --template "{rev}: {node}\n{join(extras, '\n')}\n" |
|
646 | $ hg -R ../converted log -r tip --template "{rev}: {node}\n{join(extras, '\n')}\n" | |
647 | 21: fbb6c5cc81002f2b4b49c9d731404688bcae5ade |
|
647 | 21: fbb6c5cc81002f2b4b49c9d731404688bcae5ade | |
648 | branch=dev |
|
648 | branch=dev | |
649 | convert_revision=7e61b508e709a11d28194a5359bc3532d910af21 |
|
649 | convert_revision=7e61b508e709a11d28194a5359bc3532d910af21 | |
650 | transplant_source=z\xe8F\xe9\x11\x1f\xc8\xf5wEcBP\xc7\xb9\xac\n`h\x9b |
|
650 | transplant_source=z\xe8F\xe9\x11\x1f\xc8\xf5wEcBP\xc7\xb9\xac\n`h\x9b | |
651 | $ hg -R ../converted log -r 'origin(tip)' |
|
651 | $ hg -R ../converted log -r 'origin(tip)' | |
652 | changeset: 2:e0213322b2c1 |
|
652 | changeset: 2:e0213322b2c1 | |
653 | user: test |
|
653 | user: test | |
654 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
654 | date: Thu Jan 01 00:00:00 1970 +0000 | |
655 | summary: 2 |
|
655 | summary: 2 | |
656 |
|
656 | |||
657 |
|
657 | |||
658 | Test simple destination |
|
658 | Test simple destination | |
659 | $ hg log -r 'destination()' |
|
659 | $ hg log -r 'destination()' | |
660 | changeset: 7:ef0ef43d49e7 |
|
660 | changeset: 7:ef0ef43d49e7 | |
661 | parent: 0:68795b066622 |
|
661 | parent: 0:68795b066622 | |
662 | user: foo |
|
662 | user: foo | |
663 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
663 | date: Thu Jan 01 00:00:00 1970 +0000 | |
664 | summary: 2 |
|
664 | summary: 2 | |
665 |
|
665 | |||
666 | changeset: 8:6b9e5368ca4e |
|
666 | changeset: 8:6b9e5368ca4e | |
667 | user: bar |
|
667 | user: bar | |
668 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
668 | date: Thu Jan 01 00:00:00 1970 +0000 | |
669 | summary: 1 |
|
669 | summary: 1 | |
670 |
|
670 | |||
671 | changeset: 9:1905859650ec |
|
671 | changeset: 9:1905859650ec | |
672 | user: test |
|
672 | user: test | |
673 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
673 | date: Thu Jan 01 00:00:00 1970 +0000 | |
674 | summary: 5 |
|
674 | summary: 5 | |
675 |
|
675 | |||
676 | changeset: 10:52dc0b4c6907 |
|
676 | changeset: 10:52dc0b4c6907 | |
677 | user: test |
|
677 | user: test | |
678 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
678 | date: Thu Jan 01 00:00:00 1970 +0000 | |
679 | summary: 4 |
|
679 | summary: 4 | |
680 |
|
680 | |||
681 | changeset: 11:882b35362a6b |
|
681 | changeset: 11:882b35362a6b | |
682 | user: test |
|
682 | user: test | |
683 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
683 | date: Thu Jan 01 00:00:00 1970 +0000 | |
684 | summary: 3 |
|
684 | summary: 3 | |
685 |
|
685 | |||
686 | changeset: 13:7a4785234d87 |
|
686 | changeset: 13:7a4785234d87 | |
687 | user: foo |
|
687 | user: foo | |
688 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
688 | date: Thu Jan 01 00:00:00 1970 +0000 | |
689 | summary: 2 |
|
689 | summary: 2 | |
690 |
|
690 | |||
691 | changeset: 14:0c921c65ef1e |
|
691 | changeset: 14:0c921c65ef1e | |
692 | parent: 1:5d205f8b35b6 |
|
692 | parent: 1:5d205f8b35b6 | |
693 | user: foo |
|
693 | user: foo | |
694 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
694 | date: Thu Jan 01 00:00:00 1970 +0000 | |
695 | summary: 3 |
|
695 | summary: 3 | |
696 |
|
696 | |||
697 | changeset: 17:f67661df0c48 |
|
697 | changeset: 17:f67661df0c48 | |
698 | user: bar |
|
698 | user: bar | |
699 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
699 | date: Thu Jan 01 00:00:00 1970 +0000 | |
700 | summary: 1 |
|
700 | summary: 1 | |
701 |
|
701 | |||
702 | changeset: 19:9627f653b421 |
|
702 | changeset: 19:9627f653b421 | |
703 | user: test |
|
703 | user: test | |
704 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
704 | date: Thu Jan 01 00:00:00 1970 +0000 | |
705 | summary: 2 |
|
705 | summary: 2 | |
706 |
|
706 | |||
707 | changeset: 21:7e61b508e709 |
|
707 | changeset: 21:7e61b508e709 | |
708 | branch: dev |
|
708 | branch: dev | |
709 | tag: tip |
|
709 | tag: tip | |
710 | user: foo |
|
710 | user: foo | |
711 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
711 | date: Thu Jan 01 00:00:00 1970 +0000 | |
712 | summary: 2 |
|
712 | summary: 2 | |
713 |
|
713 | |||
714 | $ hg log -r 'destination(2)' |
|
714 | $ hg log -r 'destination(2)' | |
715 | changeset: 7:ef0ef43d49e7 |
|
715 | changeset: 7:ef0ef43d49e7 | |
716 | parent: 0:68795b066622 |
|
716 | parent: 0:68795b066622 | |
717 | user: foo |
|
717 | user: foo | |
718 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
718 | date: Thu Jan 01 00:00:00 1970 +0000 | |
719 | summary: 2 |
|
719 | summary: 2 | |
720 |
|
720 | |||
721 | changeset: 13:7a4785234d87 |
|
721 | changeset: 13:7a4785234d87 | |
722 | user: foo |
|
722 | user: foo | |
723 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
723 | date: Thu Jan 01 00:00:00 1970 +0000 | |
724 | summary: 2 |
|
724 | summary: 2 | |
725 |
|
725 | |||
726 | changeset: 19:9627f653b421 |
|
726 | changeset: 19:9627f653b421 | |
727 | user: test |
|
727 | user: test | |
728 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
728 | date: Thu Jan 01 00:00:00 1970 +0000 | |
729 | summary: 2 |
|
729 | summary: 2 | |
730 |
|
730 | |||
731 | changeset: 21:7e61b508e709 |
|
731 | changeset: 21:7e61b508e709 | |
732 | branch: dev |
|
732 | branch: dev | |
733 | tag: tip |
|
733 | tag: tip | |
734 | user: foo |
|
734 | user: foo | |
735 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
735 | date: Thu Jan 01 00:00:00 1970 +0000 | |
736 | summary: 2 |
|
736 | summary: 2 | |
737 |
|
737 | |||
738 | Transplants of grafts can find a destination... |
|
738 | Transplants of grafts can find a destination... | |
739 | $ hg log -r 'destination(7)' |
|
739 | $ hg log -r 'destination(7)' | |
740 | changeset: 21:7e61b508e709 |
|
740 | changeset: 21:7e61b508e709 | |
741 | branch: dev |
|
741 | branch: dev | |
742 | tag: tip |
|
742 | tag: tip | |
743 | user: foo |
|
743 | user: foo | |
744 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
744 | date: Thu Jan 01 00:00:00 1970 +0000 | |
745 | summary: 2 |
|
745 | summary: 2 | |
746 |
|
746 | |||
747 | ... grafts of grafts unfortunately can't |
|
747 | ... grafts of grafts unfortunately can't | |
748 | $ hg graft -q 13 --debug |
|
748 | $ hg graft -q 13 --debug | |
749 | scanning for duplicate grafts |
|
749 | scanning for duplicate grafts | |
750 | grafting 13:7a4785234d87 "2" |
|
750 | grafting 13:7a4785234d87 "2" | |
751 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): |
|
751 | all copies found (* = to merge, ! = divergent, % = renamed and deleted): | |
752 | on local side: |
|
752 | on local side: | |
753 | src: 'a' -> dst: 'b' * |
|
753 | src: 'a' -> dst: 'b' * | |
754 | on remote side: |
|
754 | on remote side: | |
755 | src: 'a' -> dst: 'b' * |
|
755 | src: 'a' -> dst: 'b' * | |
756 | checking for directory renames |
|
756 | checking for directory renames | |
757 | resolving manifests |
|
757 | resolving manifests | |
758 | branchmerge: True, force: True, partial: False |
|
758 | branchmerge: True, force: True, partial: False | |
759 | ancestor: b592ea63bb0c, local: 7e61b508e709+, remote: 7a4785234d87 |
|
759 | ancestor: b592ea63bb0c, local: 7e61b508e709+, remote: 7a4785234d87 | |
760 | starting 4 threads for background file closing (?) |
|
760 | starting 4 threads for background file closing (?) | |
|
761 | nothing to commit, clearing merge state | |||
761 | note: graft of 13:7a4785234d87 created no changes to commit |
|
762 | note: graft of 13:7a4785234d87 created no changes to commit | |
762 | $ hg log -r 'destination(13)' |
|
763 | $ hg log -r 'destination(13)' | |
763 | All copies of a cset |
|
764 | All copies of a cset | |
764 | $ hg log -r 'origin(13) or destination(origin(13))' |
|
765 | $ hg log -r 'origin(13) or destination(origin(13))' | |
765 | changeset: 2:5c095ad7e90f |
|
766 | changeset: 2:5c095ad7e90f | |
766 | user: test |
|
767 | user: test | |
767 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
768 | date: Thu Jan 01 00:00:00 1970 +0000 | |
768 | summary: 2 |
|
769 | summary: 2 | |
769 |
|
770 | |||
770 | changeset: 7:ef0ef43d49e7 |
|
771 | changeset: 7:ef0ef43d49e7 | |
771 | parent: 0:68795b066622 |
|
772 | parent: 0:68795b066622 | |
772 | user: foo |
|
773 | user: foo | |
773 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
774 | date: Thu Jan 01 00:00:00 1970 +0000 | |
774 | summary: 2 |
|
775 | summary: 2 | |
775 |
|
776 | |||
776 | changeset: 13:7a4785234d87 |
|
777 | changeset: 13:7a4785234d87 | |
777 | user: foo |
|
778 | user: foo | |
778 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
779 | date: Thu Jan 01 00:00:00 1970 +0000 | |
779 | summary: 2 |
|
780 | summary: 2 | |
780 |
|
781 | |||
781 | changeset: 19:9627f653b421 |
|
782 | changeset: 19:9627f653b421 | |
782 | user: test |
|
783 | user: test | |
783 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
784 | date: Thu Jan 01 00:00:00 1970 +0000 | |
784 | summary: 2 |
|
785 | summary: 2 | |
785 |
|
786 | |||
786 | changeset: 21:7e61b508e709 |
|
787 | changeset: 21:7e61b508e709 | |
787 | branch: dev |
|
788 | branch: dev | |
788 | tag: tip |
|
789 | tag: tip | |
789 | user: foo |
|
790 | user: foo | |
790 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
791 | date: Thu Jan 01 00:00:00 1970 +0000 | |
791 | summary: 2 |
|
792 | summary: 2 | |
792 |
|
793 | |||
793 |
|
794 | |||
794 | graft skips ancestors |
|
795 | graft skips ancestors | |
795 |
|
796 | |||
796 | $ hg graft 21 3 |
|
797 | $ hg graft 21 3 | |
797 | skipping ancestor revision 21:7e61b508e709 |
|
798 | skipping ancestor revision 21:7e61b508e709 | |
798 | grafting 3:4c60f11aa304 "3" |
|
799 | grafting 3:4c60f11aa304 "3" | |
799 | merging b and c to c |
|
800 | merging b and c to c | |
800 |
|
801 | |||
801 | graft with --force (still doesn't graft merges) |
|
802 | graft with --force (still doesn't graft merges) | |
802 |
|
803 | |||
803 | $ hg graft 19 0 6 |
|
804 | $ hg graft 19 0 6 | |
804 | skipping ungraftable merge revision 6 |
|
805 | skipping ungraftable merge revision 6 | |
805 | skipping ancestor revision 0:68795b066622 |
|
806 | skipping ancestor revision 0:68795b066622 | |
806 | grafting 19:9627f653b421 "2" |
|
807 | grafting 19:9627f653b421 "2" | |
807 | merging b |
|
808 | merging b | |
808 | note: graft of 19:9627f653b421 created no changes to commit |
|
809 | note: graft of 19:9627f653b421 created no changes to commit | |
809 | $ hg graft 19 0 6 --force |
|
810 | $ hg graft 19 0 6 --force | |
810 | skipping ungraftable merge revision 6 |
|
811 | skipping ungraftable merge revision 6 | |
811 | grafting 19:9627f653b421 "2" |
|
812 | grafting 19:9627f653b421 "2" | |
812 | merging b |
|
813 | merging b | |
813 | note: graft of 19:9627f653b421 created no changes to commit |
|
814 | note: graft of 19:9627f653b421 created no changes to commit | |
814 | grafting 0:68795b066622 "0" |
|
815 | grafting 0:68795b066622 "0" | |
815 |
|
816 | |||
816 | graft --force after backout. Do the backout with graft too, to make |
|
817 | graft --force after backout. Do the backout with graft too, to make | |
817 | sure we support issue6248. |
|
818 | sure we support issue6248. | |
818 |
|
819 | |||
819 | $ echo abc > a |
|
820 | $ echo abc > a | |
820 | $ hg ci -m 24 |
|
821 | $ hg ci -m 24 | |
821 | $ hg graft --base . -r ".^" --no-commit |
|
822 | $ hg graft --base . -r ".^" --no-commit | |
822 | grafting 23:b1cac6de36a9 "0" |
|
823 | grafting 23:b1cac6de36a9 "0" | |
823 | $ hg commit -m 'Backed out changeset 2e7ea477be26' |
|
824 | $ hg commit -m 'Backed out changeset 2e7ea477be26' | |
824 | $ hg graft 24 |
|
825 | $ hg graft 24 | |
825 | skipping ancestor revision 24:2e7ea477be26 |
|
826 | skipping ancestor revision 24:2e7ea477be26 | |
826 | [255] |
|
827 | [255] | |
827 | $ hg graft 24 --force |
|
828 | $ hg graft 24 --force | |
828 | grafting 24:2e7ea477be26 "24" |
|
829 | grafting 24:2e7ea477be26 "24" | |
829 | merging a |
|
830 | merging a | |
830 | $ cat a |
|
831 | $ cat a | |
831 | abc |
|
832 | abc | |
832 |
|
833 | |||
833 | graft --continue after --force |
|
834 | graft --continue after --force | |
834 |
|
835 | |||
835 | $ echo def > a |
|
836 | $ echo def > a | |
836 | $ hg ci -m 27 |
|
837 | $ hg ci -m 27 | |
837 | $ hg graft 24 --force --tool internal:fail |
|
838 | $ hg graft 24 --force --tool internal:fail | |
838 | grafting 24:2e7ea477be26 "24" |
|
839 | grafting 24:2e7ea477be26 "24" | |
839 | abort: unresolved conflicts, can't continue |
|
840 | abort: unresolved conflicts, can't continue | |
840 | (use 'hg resolve' and 'hg graft --continue') |
|
841 | (use 'hg resolve' and 'hg graft --continue') | |
841 | [255] |
|
842 | [255] | |
842 | $ hg resolve --all |
|
843 | $ hg resolve --all | |
843 | merging a |
|
844 | merging a | |
844 | warning: conflicts while merging a! (edit, then use 'hg resolve --mark') |
|
845 | warning: conflicts while merging a! (edit, then use 'hg resolve --mark') | |
845 | [1] |
|
846 | [1] | |
846 | $ echo abc > a |
|
847 | $ echo abc > a | |
847 | $ hg resolve -m a |
|
848 | $ hg resolve -m a | |
848 | (no more unresolved files) |
|
849 | (no more unresolved files) | |
849 | continue: hg graft --continue |
|
850 | continue: hg graft --continue | |
850 | $ hg graft -c |
|
851 | $ hg graft -c | |
851 | grafting 24:2e7ea477be26 "24" |
|
852 | grafting 24:2e7ea477be26 "24" | |
852 | $ cat a |
|
853 | $ cat a | |
853 | abc |
|
854 | abc | |
854 |
|
855 | |||
855 | Continue testing same origin policy, using revision numbers from test above |
|
856 | Continue testing same origin policy, using revision numbers from test above | |
856 | but do some destructive editing of the repo: |
|
857 | but do some destructive editing of the repo: | |
857 |
|
858 | |||
858 | $ hg up -qC 7 |
|
859 | $ hg up -qC 7 | |
859 | $ hg tag -l -r 13 tmp |
|
860 | $ hg tag -l -r 13 tmp | |
860 | $ hg --config extensions.strip= strip 2 |
|
861 | $ hg --config extensions.strip= strip 2 | |
861 | saved backup bundle to $TESTTMP/a/.hg/strip-backup/5c095ad7e90f-d323a1e4-backup.hg |
|
862 | saved backup bundle to $TESTTMP/a/.hg/strip-backup/5c095ad7e90f-d323a1e4-backup.hg | |
862 | $ hg graft tmp |
|
863 | $ hg graft tmp | |
863 | skipping already grafted revision 8:7a4785234d87 (2:ef0ef43d49e7 also has unknown origin 5c095ad7e90f) |
|
864 | skipping already grafted revision 8:7a4785234d87 (2:ef0ef43d49e7 also has unknown origin 5c095ad7e90f) | |
864 | [255] |
|
865 | [255] | |
865 |
|
866 | |||
866 | Empty graft |
|
867 | Empty graft | |
867 |
|
868 | |||
868 | $ hg up -qr 22 |
|
869 | $ hg up -qr 22 | |
869 | $ hg tag -f something |
|
870 | $ hg tag -f something | |
870 | $ hg graft -qr 23 |
|
871 | $ hg graft -qr 23 | |
871 | $ hg graft -f 23 |
|
872 | $ hg graft -f 23 | |
872 | grafting 23:72d9c7c75bcc "24" |
|
873 | grafting 23:72d9c7c75bcc "24" | |
873 | note: graft of 23:72d9c7c75bcc created no changes to commit |
|
874 | note: graft of 23:72d9c7c75bcc created no changes to commit | |
874 |
|
875 | |||
875 | $ cd .. |
|
876 | $ cd .. | |
876 |
|
877 | |||
877 | Graft to duplicate a commit |
|
878 | Graft to duplicate a commit | |
878 |
|
879 | |||
879 | $ hg init graftsibling |
|
880 | $ hg init graftsibling | |
880 | $ cd graftsibling |
|
881 | $ cd graftsibling | |
881 | $ touch a |
|
882 | $ touch a | |
882 | $ hg commit -qAm a |
|
883 | $ hg commit -qAm a | |
883 | $ touch b |
|
884 | $ touch b | |
884 | $ hg commit -qAm b |
|
885 | $ hg commit -qAm b | |
885 | $ hg log -G -T '{rev}\n' |
|
886 | $ hg log -G -T '{rev}\n' | |
886 | @ 1 |
|
887 | @ 1 | |
887 | | |
|
888 | | | |
888 | o 0 |
|
889 | o 0 | |
889 |
|
890 | |||
890 | $ hg up -q 0 |
|
891 | $ hg up -q 0 | |
891 | $ hg graft -r 1 |
|
892 | $ hg graft -r 1 | |
892 | grafting 1:0e067c57feba "b" (tip) |
|
893 | grafting 1:0e067c57feba "b" (tip) | |
893 | $ hg log -G -T '{rev}\n' |
|
894 | $ hg log -G -T '{rev}\n' | |
894 | @ 2 |
|
895 | @ 2 | |
895 | | |
|
896 | | | |
896 | | o 1 |
|
897 | | o 1 | |
897 | |/ |
|
898 | |/ | |
898 | o 0 |
|
899 | o 0 | |
899 |
|
900 | |||
900 | Graft to duplicate a commit twice |
|
901 | Graft to duplicate a commit twice | |
901 |
|
902 | |||
902 | $ hg up -q 0 |
|
903 | $ hg up -q 0 | |
903 | $ hg graft -r 2 |
|
904 | $ hg graft -r 2 | |
904 | grafting 2:044ec77f6389 "b" (tip) |
|
905 | grafting 2:044ec77f6389 "b" (tip) | |
905 | $ hg log -G -T '{rev}\n' |
|
906 | $ hg log -G -T '{rev}\n' | |
906 | @ 3 |
|
907 | @ 3 | |
907 | | |
|
908 | | | |
908 | | o 2 |
|
909 | | o 2 | |
909 | |/ |
|
910 | |/ | |
910 | | o 1 |
|
911 | | o 1 | |
911 | |/ |
|
912 | |/ | |
912 | o 0 |
|
913 | o 0 | |
913 |
|
914 |
General Comments 0
You need to be logged in to leave comments.
Login now