Show More
@@ -1,3117 +1,3126 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 hashlib |
|
11 | import hashlib | |
12 | import os |
|
12 | import os | |
13 | import random |
|
13 | import random | |
14 | import sys |
|
14 | import sys | |
15 | import time |
|
15 | import time | |
16 | import weakref |
|
16 | import weakref | |
17 |
|
17 | |||
18 | from .i18n import _ |
|
18 | from .i18n import _ | |
19 | from .node import ( |
|
19 | from .node import ( | |
20 | bin, |
|
20 | bin, | |
21 | hex, |
|
21 | hex, | |
22 | nullid, |
|
22 | nullid, | |
23 | nullrev, |
|
23 | nullrev, | |
24 | short, |
|
24 | short, | |
25 | ) |
|
25 | ) | |
26 | from . import ( |
|
26 | from . import ( | |
27 | bookmarks, |
|
27 | bookmarks, | |
28 | branchmap, |
|
28 | branchmap, | |
29 | bundle2, |
|
29 | bundle2, | |
30 | changegroup, |
|
30 | changegroup, | |
31 | changelog, |
|
31 | changelog, | |
32 | color, |
|
32 | color, | |
33 | context, |
|
33 | context, | |
34 | dirstate, |
|
34 | dirstate, | |
35 | dirstateguard, |
|
35 | dirstateguard, | |
36 | discovery, |
|
36 | discovery, | |
37 | encoding, |
|
37 | encoding, | |
38 | error, |
|
38 | error, | |
39 | exchange, |
|
39 | exchange, | |
40 | extensions, |
|
40 | extensions, | |
41 | filelog, |
|
41 | filelog, | |
42 | hook, |
|
42 | hook, | |
43 | lock as lockmod, |
|
43 | lock as lockmod, | |
44 | manifest, |
|
44 | manifest, | |
45 | match as matchmod, |
|
45 | match as matchmod, | |
46 | merge as mergemod, |
|
46 | merge as mergemod, | |
47 | mergeutil, |
|
47 | mergeutil, | |
48 | namespaces, |
|
48 | namespaces, | |
49 | narrowspec, |
|
49 | narrowspec, | |
50 | obsolete, |
|
50 | obsolete, | |
51 | pathutil, |
|
51 | pathutil, | |
52 | phases, |
|
52 | phases, | |
53 | pushkey, |
|
53 | pushkey, | |
54 | pycompat, |
|
54 | pycompat, | |
55 | repository, |
|
55 | repository, | |
56 | repoview, |
|
56 | repoview, | |
57 | revset, |
|
57 | revset, | |
58 | revsetlang, |
|
58 | revsetlang, | |
59 | scmutil, |
|
59 | scmutil, | |
60 | sparse, |
|
60 | sparse, | |
61 | store as storemod, |
|
61 | store as storemod, | |
62 | subrepoutil, |
|
62 | subrepoutil, | |
63 | tags as tagsmod, |
|
63 | tags as tagsmod, | |
64 | transaction, |
|
64 | transaction, | |
65 | txnutil, |
|
65 | txnutil, | |
66 | util, |
|
66 | util, | |
67 | vfs as vfsmod, |
|
67 | vfs as vfsmod, | |
68 | ) |
|
68 | ) | |
69 | from .utils import ( |
|
69 | from .utils import ( | |
70 | interfaceutil, |
|
70 | interfaceutil, | |
71 | procutil, |
|
71 | procutil, | |
72 | stringutil, |
|
72 | stringutil, | |
73 | ) |
|
73 | ) | |
74 |
|
74 | |||
75 | from .revlogutils import ( |
|
75 | from .revlogutils import ( | |
76 | constants as revlogconst, |
|
76 | constants as revlogconst, | |
77 | ) |
|
77 | ) | |
78 |
|
78 | |||
79 | release = lockmod.release |
|
79 | release = lockmod.release | |
80 | urlerr = util.urlerr |
|
80 | urlerr = util.urlerr | |
81 | urlreq = util.urlreq |
|
81 | urlreq = util.urlreq | |
82 |
|
82 | |||
83 | # set of (path, vfs-location) tuples. vfs-location is: |
|
83 | # set of (path, vfs-location) tuples. vfs-location is: | |
84 | # - 'plain for vfs relative paths |
|
84 | # - 'plain for vfs relative paths | |
85 | # - '' for svfs relative paths |
|
85 | # - '' for svfs relative paths | |
86 | _cachedfiles = set() |
|
86 | _cachedfiles = set() | |
87 |
|
87 | |||
88 | class _basefilecache(scmutil.filecache): |
|
88 | class _basefilecache(scmutil.filecache): | |
89 | """All filecache usage on repo are done for logic that should be unfiltered |
|
89 | """All filecache usage on repo are done for logic that should be unfiltered | |
90 | """ |
|
90 | """ | |
91 | def __get__(self, repo, type=None): |
|
91 | def __get__(self, repo, type=None): | |
92 | if repo is None: |
|
92 | if repo is None: | |
93 | return self |
|
93 | return self | |
94 | # proxy to unfiltered __dict__ since filtered repo has no entry |
|
94 | # proxy to unfiltered __dict__ since filtered repo has no entry | |
95 | unfi = repo.unfiltered() |
|
95 | unfi = repo.unfiltered() | |
96 | try: |
|
96 | try: | |
97 | return unfi.__dict__[self.sname] |
|
97 | return unfi.__dict__[self.sname] | |
98 | except KeyError: |
|
98 | except KeyError: | |
99 | pass |
|
99 | pass | |
100 | return super(_basefilecache, self).__get__(unfi, type) |
|
100 | return super(_basefilecache, self).__get__(unfi, type) | |
101 |
|
101 | |||
102 | def set(self, repo, value): |
|
102 | def set(self, repo, value): | |
103 | return super(_basefilecache, self).set(repo.unfiltered(), value) |
|
103 | return super(_basefilecache, self).set(repo.unfiltered(), value) | |
104 |
|
104 | |||
105 | class repofilecache(_basefilecache): |
|
105 | class repofilecache(_basefilecache): | |
106 | """filecache for files in .hg but outside of .hg/store""" |
|
106 | """filecache for files in .hg but outside of .hg/store""" | |
107 | def __init__(self, *paths): |
|
107 | def __init__(self, *paths): | |
108 | super(repofilecache, self).__init__(*paths) |
|
108 | super(repofilecache, self).__init__(*paths) | |
109 | for path in paths: |
|
109 | for path in paths: | |
110 | _cachedfiles.add((path, 'plain')) |
|
110 | _cachedfiles.add((path, 'plain')) | |
111 |
|
111 | |||
112 | def join(self, obj, fname): |
|
112 | def join(self, obj, fname): | |
113 | return obj.vfs.join(fname) |
|
113 | return obj.vfs.join(fname) | |
114 |
|
114 | |||
115 | class storecache(_basefilecache): |
|
115 | class storecache(_basefilecache): | |
116 | """filecache for files in the store""" |
|
116 | """filecache for files in the store""" | |
117 | def __init__(self, *paths): |
|
117 | def __init__(self, *paths): | |
118 | super(storecache, self).__init__(*paths) |
|
118 | super(storecache, self).__init__(*paths) | |
119 | for path in paths: |
|
119 | for path in paths: | |
120 | _cachedfiles.add((path, '')) |
|
120 | _cachedfiles.add((path, '')) | |
121 |
|
121 | |||
122 | def join(self, obj, fname): |
|
122 | def join(self, obj, fname): | |
123 | return obj.sjoin(fname) |
|
123 | return obj.sjoin(fname) | |
124 |
|
124 | |||
125 | def isfilecached(repo, name): |
|
125 | def isfilecached(repo, name): | |
126 | """check if a repo has already cached "name" filecache-ed property |
|
126 | """check if a repo has already cached "name" filecache-ed property | |
127 |
|
127 | |||
128 | This returns (cachedobj-or-None, iscached) tuple. |
|
128 | This returns (cachedobj-or-None, iscached) tuple. | |
129 | """ |
|
129 | """ | |
130 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
130 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
131 | if not cacheentry: |
|
131 | if not cacheentry: | |
132 | return None, False |
|
132 | return None, False | |
133 | return cacheentry.obj, True |
|
133 | return cacheentry.obj, True | |
134 |
|
134 | |||
135 | class unfilteredpropertycache(util.propertycache): |
|
135 | class unfilteredpropertycache(util.propertycache): | |
136 | """propertycache that apply to unfiltered repo only""" |
|
136 | """propertycache that apply to unfiltered repo only""" | |
137 |
|
137 | |||
138 | def __get__(self, repo, type=None): |
|
138 | def __get__(self, repo, type=None): | |
139 | unfi = repo.unfiltered() |
|
139 | unfi = repo.unfiltered() | |
140 | if unfi is repo: |
|
140 | if unfi is repo: | |
141 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
141 | return super(unfilteredpropertycache, self).__get__(unfi) | |
142 | return getattr(unfi, self.name) |
|
142 | return getattr(unfi, self.name) | |
143 |
|
143 | |||
144 | class filteredpropertycache(util.propertycache): |
|
144 | class filteredpropertycache(util.propertycache): | |
145 | """propertycache that must take filtering in account""" |
|
145 | """propertycache that must take filtering in account""" | |
146 |
|
146 | |||
147 | def cachevalue(self, obj, value): |
|
147 | def cachevalue(self, obj, value): | |
148 | object.__setattr__(obj, self.name, value) |
|
148 | object.__setattr__(obj, self.name, value) | |
149 |
|
149 | |||
150 |
|
150 | |||
151 | def hasunfilteredcache(repo, name): |
|
151 | def hasunfilteredcache(repo, name): | |
152 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
152 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
153 | return name in vars(repo.unfiltered()) |
|
153 | return name in vars(repo.unfiltered()) | |
154 |
|
154 | |||
155 | def unfilteredmethod(orig): |
|
155 | def unfilteredmethod(orig): | |
156 | """decorate method that always need to be run on unfiltered version""" |
|
156 | """decorate method that always need to be run on unfiltered version""" | |
157 | def wrapper(repo, *args, **kwargs): |
|
157 | def wrapper(repo, *args, **kwargs): | |
158 | return orig(repo.unfiltered(), *args, **kwargs) |
|
158 | return orig(repo.unfiltered(), *args, **kwargs) | |
159 | return wrapper |
|
159 | return wrapper | |
160 |
|
160 | |||
161 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
161 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
162 | 'unbundle'} |
|
162 | 'unbundle'} | |
163 | legacycaps = moderncaps.union({'changegroupsubset'}) |
|
163 | legacycaps = moderncaps.union({'changegroupsubset'}) | |
164 |
|
164 | |||
165 | @interfaceutil.implementer(repository.ipeercommandexecutor) |
|
165 | @interfaceutil.implementer(repository.ipeercommandexecutor) | |
166 | class localcommandexecutor(object): |
|
166 | class localcommandexecutor(object): | |
167 | def __init__(self, peer): |
|
167 | def __init__(self, peer): | |
168 | self._peer = peer |
|
168 | self._peer = peer | |
169 | self._sent = False |
|
169 | self._sent = False | |
170 | self._closed = False |
|
170 | self._closed = False | |
171 |
|
171 | |||
172 | def __enter__(self): |
|
172 | def __enter__(self): | |
173 | return self |
|
173 | return self | |
174 |
|
174 | |||
175 | def __exit__(self, exctype, excvalue, exctb): |
|
175 | def __exit__(self, exctype, excvalue, exctb): | |
176 | self.close() |
|
176 | self.close() | |
177 |
|
177 | |||
178 | def callcommand(self, command, args): |
|
178 | def callcommand(self, command, args): | |
179 | if self._sent: |
|
179 | if self._sent: | |
180 | raise error.ProgrammingError('callcommand() cannot be used after ' |
|
180 | raise error.ProgrammingError('callcommand() cannot be used after ' | |
181 | 'sendcommands()') |
|
181 | 'sendcommands()') | |
182 |
|
182 | |||
183 | if self._closed: |
|
183 | if self._closed: | |
184 | raise error.ProgrammingError('callcommand() cannot be used after ' |
|
184 | raise error.ProgrammingError('callcommand() cannot be used after ' | |
185 | 'close()') |
|
185 | 'close()') | |
186 |
|
186 | |||
187 | # We don't need to support anything fancy. Just call the named |
|
187 | # We don't need to support anything fancy. Just call the named | |
188 | # method on the peer and return a resolved future. |
|
188 | # method on the peer and return a resolved future. | |
189 | fn = getattr(self._peer, pycompat.sysstr(command)) |
|
189 | fn = getattr(self._peer, pycompat.sysstr(command)) | |
190 |
|
190 | |||
191 | f = pycompat.futures.Future() |
|
191 | f = pycompat.futures.Future() | |
192 |
|
192 | |||
193 | try: |
|
193 | try: | |
194 | result = fn(**pycompat.strkwargs(args)) |
|
194 | result = fn(**pycompat.strkwargs(args)) | |
195 | except Exception: |
|
195 | except Exception: | |
196 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) |
|
196 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) | |
197 | else: |
|
197 | else: | |
198 | f.set_result(result) |
|
198 | f.set_result(result) | |
199 |
|
199 | |||
200 | return f |
|
200 | return f | |
201 |
|
201 | |||
202 | def sendcommands(self): |
|
202 | def sendcommands(self): | |
203 | self._sent = True |
|
203 | self._sent = True | |
204 |
|
204 | |||
205 | def close(self): |
|
205 | def close(self): | |
206 | self._closed = True |
|
206 | self._closed = True | |
207 |
|
207 | |||
208 | @interfaceutil.implementer(repository.ipeercommands) |
|
208 | @interfaceutil.implementer(repository.ipeercommands) | |
209 | class localpeer(repository.peer): |
|
209 | class localpeer(repository.peer): | |
210 | '''peer for a local repo; reflects only the most recent API''' |
|
210 | '''peer for a local repo; reflects only the most recent API''' | |
211 |
|
211 | |||
212 | def __init__(self, repo, caps=None): |
|
212 | def __init__(self, repo, caps=None): | |
213 | super(localpeer, self).__init__() |
|
213 | super(localpeer, self).__init__() | |
214 |
|
214 | |||
215 | if caps is None: |
|
215 | if caps is None: | |
216 | caps = moderncaps.copy() |
|
216 | caps = moderncaps.copy() | |
217 | self._repo = repo.filtered('served') |
|
217 | self._repo = repo.filtered('served') | |
218 | self.ui = repo.ui |
|
218 | self.ui = repo.ui | |
219 | self._caps = repo._restrictcapabilities(caps) |
|
219 | self._caps = repo._restrictcapabilities(caps) | |
220 |
|
220 | |||
221 | # Begin of _basepeer interface. |
|
221 | # Begin of _basepeer interface. | |
222 |
|
222 | |||
223 | def url(self): |
|
223 | def url(self): | |
224 | return self._repo.url() |
|
224 | return self._repo.url() | |
225 |
|
225 | |||
226 | def local(self): |
|
226 | def local(self): | |
227 | return self._repo |
|
227 | return self._repo | |
228 |
|
228 | |||
229 | def peer(self): |
|
229 | def peer(self): | |
230 | return self |
|
230 | return self | |
231 |
|
231 | |||
232 | def canpush(self): |
|
232 | def canpush(self): | |
233 | return True |
|
233 | return True | |
234 |
|
234 | |||
235 | def close(self): |
|
235 | def close(self): | |
236 | self._repo.close() |
|
236 | self._repo.close() | |
237 |
|
237 | |||
238 | # End of _basepeer interface. |
|
238 | # End of _basepeer interface. | |
239 |
|
239 | |||
240 | # Begin of _basewirecommands interface. |
|
240 | # Begin of _basewirecommands interface. | |
241 |
|
241 | |||
242 | def branchmap(self): |
|
242 | def branchmap(self): | |
243 | return self._repo.branchmap() |
|
243 | return self._repo.branchmap() | |
244 |
|
244 | |||
245 | def capabilities(self): |
|
245 | def capabilities(self): | |
246 | return self._caps |
|
246 | return self._caps | |
247 |
|
247 | |||
248 | def clonebundles(self): |
|
248 | def clonebundles(self): | |
249 | return self._repo.tryread('clonebundles.manifest') |
|
249 | return self._repo.tryread('clonebundles.manifest') | |
250 |
|
250 | |||
251 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
251 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
252 | """Used to test argument passing over the wire""" |
|
252 | """Used to test argument passing over the wire""" | |
253 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
253 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
254 | pycompat.bytestr(four), |
|
254 | pycompat.bytestr(four), | |
255 | pycompat.bytestr(five)) |
|
255 | pycompat.bytestr(five)) | |
256 |
|
256 | |||
257 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
257 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
258 | **kwargs): |
|
258 | **kwargs): | |
259 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
259 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, | |
260 | common=common, bundlecaps=bundlecaps, |
|
260 | common=common, bundlecaps=bundlecaps, | |
261 | **kwargs)[1] |
|
261 | **kwargs)[1] | |
262 | cb = util.chunkbuffer(chunks) |
|
262 | cb = util.chunkbuffer(chunks) | |
263 |
|
263 | |||
264 | if exchange.bundle2requested(bundlecaps): |
|
264 | if exchange.bundle2requested(bundlecaps): | |
265 | # When requesting a bundle2, getbundle returns a stream to make the |
|
265 | # When requesting a bundle2, getbundle returns a stream to make the | |
266 | # wire level function happier. We need to build a proper object |
|
266 | # wire level function happier. We need to build a proper object | |
267 | # from it in local peer. |
|
267 | # from it in local peer. | |
268 | return bundle2.getunbundler(self.ui, cb) |
|
268 | return bundle2.getunbundler(self.ui, cb) | |
269 | else: |
|
269 | else: | |
270 | return changegroup.getunbundler('01', cb, None) |
|
270 | return changegroup.getunbundler('01', cb, None) | |
271 |
|
271 | |||
272 | def heads(self): |
|
272 | def heads(self): | |
273 | return self._repo.heads() |
|
273 | return self._repo.heads() | |
274 |
|
274 | |||
275 | def known(self, nodes): |
|
275 | def known(self, nodes): | |
276 | return self._repo.known(nodes) |
|
276 | return self._repo.known(nodes) | |
277 |
|
277 | |||
278 | def listkeys(self, namespace): |
|
278 | def listkeys(self, namespace): | |
279 | return self._repo.listkeys(namespace) |
|
279 | return self._repo.listkeys(namespace) | |
280 |
|
280 | |||
281 | def lookup(self, key): |
|
281 | def lookup(self, key): | |
282 | return self._repo.lookup(key) |
|
282 | return self._repo.lookup(key) | |
283 |
|
283 | |||
284 | def pushkey(self, namespace, key, old, new): |
|
284 | def pushkey(self, namespace, key, old, new): | |
285 | return self._repo.pushkey(namespace, key, old, new) |
|
285 | return self._repo.pushkey(namespace, key, old, new) | |
286 |
|
286 | |||
287 | def stream_out(self): |
|
287 | def stream_out(self): | |
288 | raise error.Abort(_('cannot perform stream clone against local ' |
|
288 | raise error.Abort(_('cannot perform stream clone against local ' | |
289 | 'peer')) |
|
289 | 'peer')) | |
290 |
|
290 | |||
291 | def unbundle(self, bundle, heads, url): |
|
291 | def unbundle(self, bundle, heads, url): | |
292 | """apply a bundle on a repo |
|
292 | """apply a bundle on a repo | |
293 |
|
293 | |||
294 | This function handles the repo locking itself.""" |
|
294 | This function handles the repo locking itself.""" | |
295 | try: |
|
295 | try: | |
296 | try: |
|
296 | try: | |
297 | bundle = exchange.readbundle(self.ui, bundle, None) |
|
297 | bundle = exchange.readbundle(self.ui, bundle, None) | |
298 | ret = exchange.unbundle(self._repo, bundle, heads, 'push', url) |
|
298 | ret = exchange.unbundle(self._repo, bundle, heads, 'push', url) | |
299 | if util.safehasattr(ret, 'getchunks'): |
|
299 | if util.safehasattr(ret, 'getchunks'): | |
300 | # This is a bundle20 object, turn it into an unbundler. |
|
300 | # This is a bundle20 object, turn it into an unbundler. | |
301 | # This little dance should be dropped eventually when the |
|
301 | # This little dance should be dropped eventually when the | |
302 | # API is finally improved. |
|
302 | # API is finally improved. | |
303 | stream = util.chunkbuffer(ret.getchunks()) |
|
303 | stream = util.chunkbuffer(ret.getchunks()) | |
304 | ret = bundle2.getunbundler(self.ui, stream) |
|
304 | ret = bundle2.getunbundler(self.ui, stream) | |
305 | return ret |
|
305 | return ret | |
306 | except Exception as exc: |
|
306 | except Exception as exc: | |
307 | # If the exception contains output salvaged from a bundle2 |
|
307 | # If the exception contains output salvaged from a bundle2 | |
308 | # reply, we need to make sure it is printed before continuing |
|
308 | # reply, we need to make sure it is printed before continuing | |
309 | # to fail. So we build a bundle2 with such output and consume |
|
309 | # to fail. So we build a bundle2 with such output and consume | |
310 | # it directly. |
|
310 | # it directly. | |
311 | # |
|
311 | # | |
312 | # This is not very elegant but allows a "simple" solution for |
|
312 | # This is not very elegant but allows a "simple" solution for | |
313 | # issue4594 |
|
313 | # issue4594 | |
314 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
314 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
315 | if output: |
|
315 | if output: | |
316 | bundler = bundle2.bundle20(self._repo.ui) |
|
316 | bundler = bundle2.bundle20(self._repo.ui) | |
317 | for out in output: |
|
317 | for out in output: | |
318 | bundler.addpart(out) |
|
318 | bundler.addpart(out) | |
319 | stream = util.chunkbuffer(bundler.getchunks()) |
|
319 | stream = util.chunkbuffer(bundler.getchunks()) | |
320 | b = bundle2.getunbundler(self.ui, stream) |
|
320 | b = bundle2.getunbundler(self.ui, stream) | |
321 | bundle2.processbundle(self._repo, b) |
|
321 | bundle2.processbundle(self._repo, b) | |
322 | raise |
|
322 | raise | |
323 | except error.PushRaced as exc: |
|
323 | except error.PushRaced as exc: | |
324 | raise error.ResponseError(_('push failed:'), |
|
324 | raise error.ResponseError(_('push failed:'), | |
325 | stringutil.forcebytestr(exc)) |
|
325 | stringutil.forcebytestr(exc)) | |
326 |
|
326 | |||
327 | # End of _basewirecommands interface. |
|
327 | # End of _basewirecommands interface. | |
328 |
|
328 | |||
329 | # Begin of peer interface. |
|
329 | # Begin of peer interface. | |
330 |
|
330 | |||
331 | def commandexecutor(self): |
|
331 | def commandexecutor(self): | |
332 | return localcommandexecutor(self) |
|
332 | return localcommandexecutor(self) | |
333 |
|
333 | |||
334 | # End of peer interface. |
|
334 | # End of peer interface. | |
335 |
|
335 | |||
336 | @interfaceutil.implementer(repository.ipeerlegacycommands) |
|
336 | @interfaceutil.implementer(repository.ipeerlegacycommands) | |
337 | class locallegacypeer(localpeer): |
|
337 | class locallegacypeer(localpeer): | |
338 | '''peer extension which implements legacy methods too; used for tests with |
|
338 | '''peer extension which implements legacy methods too; used for tests with | |
339 | restricted capabilities''' |
|
339 | restricted capabilities''' | |
340 |
|
340 | |||
341 | def __init__(self, repo): |
|
341 | def __init__(self, repo): | |
342 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
342 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
343 |
|
343 | |||
344 | # Begin of baselegacywirecommands interface. |
|
344 | # Begin of baselegacywirecommands interface. | |
345 |
|
345 | |||
346 | def between(self, pairs): |
|
346 | def between(self, pairs): | |
347 | return self._repo.between(pairs) |
|
347 | return self._repo.between(pairs) | |
348 |
|
348 | |||
349 | def branches(self, nodes): |
|
349 | def branches(self, nodes): | |
350 | return self._repo.branches(nodes) |
|
350 | return self._repo.branches(nodes) | |
351 |
|
351 | |||
352 | def changegroup(self, nodes, source): |
|
352 | def changegroup(self, nodes, source): | |
353 | outgoing = discovery.outgoing(self._repo, missingroots=nodes, |
|
353 | outgoing = discovery.outgoing(self._repo, missingroots=nodes, | |
354 | missingheads=self._repo.heads()) |
|
354 | missingheads=self._repo.heads()) | |
355 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
355 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
356 |
|
356 | |||
357 | def changegroupsubset(self, bases, heads, source): |
|
357 | def changegroupsubset(self, bases, heads, source): | |
358 | outgoing = discovery.outgoing(self._repo, missingroots=bases, |
|
358 | outgoing = discovery.outgoing(self._repo, missingroots=bases, | |
359 | missingheads=heads) |
|
359 | missingheads=heads) | |
360 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
360 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
361 |
|
361 | |||
362 | # End of baselegacywirecommands interface. |
|
362 | # End of baselegacywirecommands interface. | |
363 |
|
363 | |||
364 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
364 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
365 | # clients. |
|
365 | # clients. | |
366 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.1' |
|
366 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.1' | |
367 |
|
367 | |||
368 | # A repository with the sparserevlog feature will have delta chains that |
|
368 | # A repository with the sparserevlog feature will have delta chains that | |
369 | # can spread over a larger span. Sparse reading cuts these large spans into |
|
369 | # can spread over a larger span. Sparse reading cuts these large spans into | |
370 | # pieces, so that each piece isn't too big. |
|
370 | # pieces, so that each piece isn't too big. | |
371 | # Without the sparserevlog capability, reading from the repository could use |
|
371 | # Without the sparserevlog capability, reading from the repository could use | |
372 | # huge amounts of memory, because the whole span would be read at once, |
|
372 | # huge amounts of memory, because the whole span would be read at once, | |
373 | # including all the intermediate revisions that aren't pertinent for the chain. |
|
373 | # including all the intermediate revisions that aren't pertinent for the chain. | |
374 | # This is why once a repository has enabled sparse-read, it becomes required. |
|
374 | # This is why once a repository has enabled sparse-read, it becomes required. | |
375 | SPARSEREVLOG_REQUIREMENT = 'sparserevlog' |
|
375 | SPARSEREVLOG_REQUIREMENT = 'sparserevlog' | |
376 |
|
376 | |||
377 | # Functions receiving (ui, features) that extensions can register to impact |
|
377 | # Functions receiving (ui, features) that extensions can register to impact | |
378 | # the ability to load repositories with custom requirements. Only |
|
378 | # the ability to load repositories with custom requirements. Only | |
379 | # functions defined in loaded extensions are called. |
|
379 | # functions defined in loaded extensions are called. | |
380 | # |
|
380 | # | |
381 | # The function receives a set of requirement strings that the repository |
|
381 | # The function receives a set of requirement strings that the repository | |
382 | # is capable of opening. Functions will typically add elements to the |
|
382 | # is capable of opening. Functions will typically add elements to the | |
383 | # set to reflect that the extension knows how to handle that requirements. |
|
383 | # set to reflect that the extension knows how to handle that requirements. | |
384 | featuresetupfuncs = set() |
|
384 | featuresetupfuncs = set() | |
385 |
|
385 | |||
386 | def makelocalrepository(baseui, path, intents=None): |
|
386 | def makelocalrepository(baseui, path, intents=None): | |
387 | """Create a local repository object. |
|
387 | """Create a local repository object. | |
388 |
|
388 | |||
389 | Given arguments needed to construct a local repository, this function |
|
389 | Given arguments needed to construct a local repository, this function | |
390 | performs various early repository loading functionality (such as |
|
390 | performs various early repository loading functionality (such as | |
391 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that |
|
391 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that | |
392 | the repository can be opened, derives a type suitable for representing |
|
392 | the repository can be opened, derives a type suitable for representing | |
393 | that repository, and returns an instance of it. |
|
393 | that repository, and returns an instance of it. | |
394 |
|
394 | |||
395 | The returned object conforms to the ``repository.completelocalrepository`` |
|
395 | The returned object conforms to the ``repository.completelocalrepository`` | |
396 | interface. |
|
396 | interface. | |
397 |
|
397 | |||
398 | The repository type is derived by calling a series of factory functions |
|
398 | The repository type is derived by calling a series of factory functions | |
399 | for each aspect/interface of the final repository. These are defined by |
|
399 | for each aspect/interface of the final repository. These are defined by | |
400 | ``REPO_INTERFACES``. |
|
400 | ``REPO_INTERFACES``. | |
401 |
|
401 | |||
402 | Each factory function is called to produce a type implementing a specific |
|
402 | Each factory function is called to produce a type implementing a specific | |
403 | interface. The cumulative list of returned types will be combined into a |
|
403 | interface. The cumulative list of returned types will be combined into a | |
404 | new type and that type will be instantiated to represent the local |
|
404 | new type and that type will be instantiated to represent the local | |
405 | repository. |
|
405 | repository. | |
406 |
|
406 | |||
407 | The factory functions each receive various state that may be consulted |
|
407 | The factory functions each receive various state that may be consulted | |
408 | as part of deriving a type. |
|
408 | as part of deriving a type. | |
409 |
|
409 | |||
410 | Extensions should wrap these factory functions to customize repository type |
|
410 | Extensions should wrap these factory functions to customize repository type | |
411 | creation. Note that an extension's wrapped function may be called even if |
|
411 | creation. Note that an extension's wrapped function may be called even if | |
412 | that extension is not loaded for the repo being constructed. Extensions |
|
412 | that extension is not loaded for the repo being constructed. Extensions | |
413 | should check if their ``__name__`` appears in the |
|
413 | should check if their ``__name__`` appears in the | |
414 | ``extensionmodulenames`` set passed to the factory function and no-op if |
|
414 | ``extensionmodulenames`` set passed to the factory function and no-op if | |
415 | not. |
|
415 | not. | |
416 | """ |
|
416 | """ | |
417 | ui = baseui.copy() |
|
417 | ui = baseui.copy() | |
418 | # Prevent copying repo configuration. |
|
418 | # Prevent copying repo configuration. | |
419 | ui.copy = baseui.copy |
|
419 | ui.copy = baseui.copy | |
420 |
|
420 | |||
421 | # Working directory VFS rooted at repository root. |
|
421 | # Working directory VFS rooted at repository root. | |
422 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
422 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
423 |
|
423 | |||
424 | # Main VFS for .hg/ directory. |
|
424 | # Main VFS for .hg/ directory. | |
425 | hgpath = wdirvfs.join(b'.hg') |
|
425 | hgpath = wdirvfs.join(b'.hg') | |
426 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) |
|
426 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) | |
427 |
|
427 | |||
428 | # The .hg/ path should exist and should be a directory. All other |
|
428 | # The .hg/ path should exist and should be a directory. All other | |
429 | # cases are errors. |
|
429 | # cases are errors. | |
430 | if not hgvfs.isdir(): |
|
430 | if not hgvfs.isdir(): | |
431 | try: |
|
431 | try: | |
432 | hgvfs.stat() |
|
432 | hgvfs.stat() | |
433 | except OSError as e: |
|
433 | except OSError as e: | |
434 | if e.errno != errno.ENOENT: |
|
434 | if e.errno != errno.ENOENT: | |
435 | raise |
|
435 | raise | |
436 |
|
436 | |||
437 | raise error.RepoError(_(b'repository %s not found') % path) |
|
437 | raise error.RepoError(_(b'repository %s not found') % path) | |
438 |
|
438 | |||
439 | # .hg/requires file contains a newline-delimited list of |
|
439 | # .hg/requires file contains a newline-delimited list of | |
440 | # features/capabilities the opener (us) must have in order to use |
|
440 | # features/capabilities the opener (us) must have in order to use | |
441 | # the repository. This file was introduced in Mercurial 0.9.2, |
|
441 | # the repository. This file was introduced in Mercurial 0.9.2, | |
442 | # which means very old repositories may not have one. We assume |
|
442 | # which means very old repositories may not have one. We assume | |
443 | # a missing file translates to no requirements. |
|
443 | # a missing file translates to no requirements. | |
444 | try: |
|
444 | try: | |
445 | requirements = set(hgvfs.read(b'requires').splitlines()) |
|
445 | requirements = set(hgvfs.read(b'requires').splitlines()) | |
446 | except IOError as e: |
|
446 | except IOError as e: | |
447 | if e.errno != errno.ENOENT: |
|
447 | if e.errno != errno.ENOENT: | |
448 | raise |
|
448 | raise | |
449 | requirements = set() |
|
449 | requirements = set() | |
450 |
|
450 | |||
451 | # The .hg/hgrc file may load extensions or contain config options |
|
451 | # The .hg/hgrc file may load extensions or contain config options | |
452 | # that influence repository construction. Attempt to load it and |
|
452 | # that influence repository construction. Attempt to load it and | |
453 | # process any new extensions that it may have pulled in. |
|
453 | # process any new extensions that it may have pulled in. | |
454 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
454 | if loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
455 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
|
455 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) | |
456 | extensions.loadall(ui) |
|
456 | extensions.loadall(ui) | |
457 | extensions.populateui(ui) |
|
457 | extensions.populateui(ui) | |
458 |
|
458 | |||
459 | # Set of module names of extensions loaded for this repository. |
|
459 | # Set of module names of extensions loaded for this repository. | |
460 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} |
|
460 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} | |
461 |
|
461 | |||
462 | supportedrequirements = gathersupportedrequirements(ui) |
|
462 | supportedrequirements = gathersupportedrequirements(ui) | |
463 |
|
463 | |||
464 | # We first validate the requirements are known. |
|
464 | # We first validate the requirements are known. | |
465 | ensurerequirementsrecognized(requirements, supportedrequirements) |
|
465 | ensurerequirementsrecognized(requirements, supportedrequirements) | |
466 |
|
466 | |||
467 | # Then we validate that the known set is reasonable to use together. |
|
467 | # Then we validate that the known set is reasonable to use together. | |
468 | ensurerequirementscompatible(ui, requirements) |
|
468 | ensurerequirementscompatible(ui, requirements) | |
469 |
|
469 | |||
470 | # TODO there are unhandled edge cases related to opening repositories with |
|
470 | # TODO there are unhandled edge cases related to opening repositories with | |
471 | # shared storage. If storage is shared, we should also test for requirements |
|
471 | # shared storage. If storage is shared, we should also test for requirements | |
472 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in |
|
472 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in | |
473 | # that repo, as that repo may load extensions needed to open it. This is a |
|
473 | # that repo, as that repo may load extensions needed to open it. This is a | |
474 | # bit complicated because we don't want the other hgrc to overwrite settings |
|
474 | # bit complicated because we don't want the other hgrc to overwrite settings | |
475 | # in this hgrc. |
|
475 | # in this hgrc. | |
476 | # |
|
476 | # | |
477 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires |
|
477 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires | |
478 | # file when sharing repos. But if a requirement is added after the share is |
|
478 | # file when sharing repos. But if a requirement is added after the share is | |
479 | # performed, thereby introducing a new requirement for the opener, we may |
|
479 | # performed, thereby introducing a new requirement for the opener, we may | |
480 | # will not see that and could encounter a run-time error interacting with |
|
480 | # will not see that and could encounter a run-time error interacting with | |
481 | # that shared store since it has an unknown-to-us requirement. |
|
481 | # that shared store since it has an unknown-to-us requirement. | |
482 |
|
482 | |||
483 | # At this point, we know we should be capable of opening the repository. |
|
483 | # At this point, we know we should be capable of opening the repository. | |
484 | # Now get on with doing that. |
|
484 | # Now get on with doing that. | |
485 |
|
485 | |||
486 | features = set() |
|
486 | features = set() | |
487 |
|
487 | |||
488 | # The "store" part of the repository holds versioned data. How it is |
|
488 | # The "store" part of the repository holds versioned data. How it is | |
489 | # accessed is determined by various requirements. The ``shared`` or |
|
489 | # accessed is determined by various requirements. The ``shared`` or | |
490 | # ``relshared`` requirements indicate the store lives in the path contained |
|
490 | # ``relshared`` requirements indicate the store lives in the path contained | |
491 | # in the ``.hg/sharedpath`` file. This is an absolute path for |
|
491 | # in the ``.hg/sharedpath`` file. This is an absolute path for | |
492 | # ``shared`` and relative to ``.hg/`` for ``relshared``. |
|
492 | # ``shared`` and relative to ``.hg/`` for ``relshared``. | |
493 | if b'shared' in requirements or b'relshared' in requirements: |
|
493 | if b'shared' in requirements or b'relshared' in requirements: | |
494 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') |
|
494 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') | |
495 | if b'relshared' in requirements: |
|
495 | if b'relshared' in requirements: | |
496 | sharedpath = hgvfs.join(sharedpath) |
|
496 | sharedpath = hgvfs.join(sharedpath) | |
497 |
|
497 | |||
498 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) |
|
498 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) | |
499 |
|
499 | |||
500 | if not sharedvfs.exists(): |
|
500 | if not sharedvfs.exists(): | |
501 | raise error.RepoError(_(b'.hg/sharedpath points to nonexistent ' |
|
501 | raise error.RepoError(_(b'.hg/sharedpath points to nonexistent ' | |
502 | b'directory %s') % sharedvfs.base) |
|
502 | b'directory %s') % sharedvfs.base) | |
503 |
|
503 | |||
504 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) |
|
504 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) | |
505 |
|
505 | |||
506 | storebasepath = sharedvfs.base |
|
506 | storebasepath = sharedvfs.base | |
507 | cachepath = sharedvfs.join(b'cache') |
|
507 | cachepath = sharedvfs.join(b'cache') | |
508 | else: |
|
508 | else: | |
509 | storebasepath = hgvfs.base |
|
509 | storebasepath = hgvfs.base | |
510 | cachepath = hgvfs.join(b'cache') |
|
510 | cachepath = hgvfs.join(b'cache') | |
511 | wcachepath = hgvfs.join(b'wcache') |
|
511 | wcachepath = hgvfs.join(b'wcache') | |
512 |
|
512 | |||
513 |
|
513 | |||
514 | # The store has changed over time and the exact layout is dictated by |
|
514 | # The store has changed over time and the exact layout is dictated by | |
515 | # requirements. The store interface abstracts differences across all |
|
515 | # requirements. The store interface abstracts differences across all | |
516 | # of them. |
|
516 | # of them. | |
517 | store = makestore(requirements, storebasepath, |
|
517 | store = makestore(requirements, storebasepath, | |
518 | lambda base: vfsmod.vfs(base, cacheaudited=True)) |
|
518 | lambda base: vfsmod.vfs(base, cacheaudited=True)) | |
519 | hgvfs.createmode = store.createmode |
|
519 | hgvfs.createmode = store.createmode | |
520 |
|
520 | |||
521 | storevfs = store.vfs |
|
521 | storevfs = store.vfs | |
522 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) |
|
522 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) | |
523 |
|
523 | |||
524 | # The cache vfs is used to manage cache files. |
|
524 | # The cache vfs is used to manage cache files. | |
525 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
525 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
526 | cachevfs.createmode = store.createmode |
|
526 | cachevfs.createmode = store.createmode | |
527 | # The cache vfs is used to manage cache files related to the working copy |
|
527 | # The cache vfs is used to manage cache files related to the working copy | |
528 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) |
|
528 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) | |
529 | wcachevfs.createmode = store.createmode |
|
529 | wcachevfs.createmode = store.createmode | |
530 |
|
530 | |||
531 | # Now resolve the type for the repository object. We do this by repeatedly |
|
531 | # Now resolve the type for the repository object. We do this by repeatedly | |
532 | # calling a factory function to produces types for specific aspects of the |
|
532 | # calling a factory function to produces types for specific aspects of the | |
533 | # repo's operation. The aggregate returned types are used as base classes |
|
533 | # repo's operation. The aggregate returned types are used as base classes | |
534 | # for a dynamically-derived type, which will represent our new repository. |
|
534 | # for a dynamically-derived type, which will represent our new repository. | |
535 |
|
535 | |||
536 | bases = [] |
|
536 | bases = [] | |
537 | extrastate = {} |
|
537 | extrastate = {} | |
538 |
|
538 | |||
539 | for iface, fn in REPO_INTERFACES: |
|
539 | for iface, fn in REPO_INTERFACES: | |
540 | # We pass all potentially useful state to give extensions tons of |
|
540 | # We pass all potentially useful state to give extensions tons of | |
541 | # flexibility. |
|
541 | # flexibility. | |
542 | typ = fn()(ui=ui, |
|
542 | typ = fn()(ui=ui, | |
543 | intents=intents, |
|
543 | intents=intents, | |
544 | requirements=requirements, |
|
544 | requirements=requirements, | |
545 | features=features, |
|
545 | features=features, | |
546 | wdirvfs=wdirvfs, |
|
546 | wdirvfs=wdirvfs, | |
547 | hgvfs=hgvfs, |
|
547 | hgvfs=hgvfs, | |
548 | store=store, |
|
548 | store=store, | |
549 | storevfs=storevfs, |
|
549 | storevfs=storevfs, | |
550 | storeoptions=storevfs.options, |
|
550 | storeoptions=storevfs.options, | |
551 | cachevfs=cachevfs, |
|
551 | cachevfs=cachevfs, | |
552 | wcachevfs=wcachevfs, |
|
552 | wcachevfs=wcachevfs, | |
553 | extensionmodulenames=extensionmodulenames, |
|
553 | extensionmodulenames=extensionmodulenames, | |
554 | extrastate=extrastate, |
|
554 | extrastate=extrastate, | |
555 | baseclasses=bases) |
|
555 | baseclasses=bases) | |
556 |
|
556 | |||
557 | if not isinstance(typ, type): |
|
557 | if not isinstance(typ, type): | |
558 | raise error.ProgrammingError('unable to construct type for %s' % |
|
558 | raise error.ProgrammingError('unable to construct type for %s' % | |
559 | iface) |
|
559 | iface) | |
560 |
|
560 | |||
561 | bases.append(typ) |
|
561 | bases.append(typ) | |
562 |
|
562 | |||
563 | # type() allows you to use characters in type names that wouldn't be |
|
563 | # type() allows you to use characters in type names that wouldn't be | |
564 | # recognized as Python symbols in source code. We abuse that to add |
|
564 | # recognized as Python symbols in source code. We abuse that to add | |
565 | # rich information about our constructed repo. |
|
565 | # rich information about our constructed repo. | |
566 | name = pycompat.sysstr(b'derivedrepo:%s<%s>' % ( |
|
566 | name = pycompat.sysstr(b'derivedrepo:%s<%s>' % ( | |
567 | wdirvfs.base, |
|
567 | wdirvfs.base, | |
568 | b','.join(sorted(requirements)))) |
|
568 | b','.join(sorted(requirements)))) | |
569 |
|
569 | |||
570 | cls = type(name, tuple(bases), {}) |
|
570 | cls = type(name, tuple(bases), {}) | |
571 |
|
571 | |||
572 | return cls( |
|
572 | return cls( | |
573 | baseui=baseui, |
|
573 | baseui=baseui, | |
574 | ui=ui, |
|
574 | ui=ui, | |
575 | origroot=path, |
|
575 | origroot=path, | |
576 | wdirvfs=wdirvfs, |
|
576 | wdirvfs=wdirvfs, | |
577 | hgvfs=hgvfs, |
|
577 | hgvfs=hgvfs, | |
578 | requirements=requirements, |
|
578 | requirements=requirements, | |
579 | supportedrequirements=supportedrequirements, |
|
579 | supportedrequirements=supportedrequirements, | |
580 | sharedpath=storebasepath, |
|
580 | sharedpath=storebasepath, | |
581 | store=store, |
|
581 | store=store, | |
582 | cachevfs=cachevfs, |
|
582 | cachevfs=cachevfs, | |
583 | wcachevfs=wcachevfs, |
|
583 | wcachevfs=wcachevfs, | |
584 | features=features, |
|
584 | features=features, | |
585 | intents=intents) |
|
585 | intents=intents) | |
586 |
|
586 | |||
587 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): |
|
587 | def loadhgrc(ui, wdirvfs, hgvfs, requirements): | |
588 | """Load hgrc files/content into a ui instance. |
|
588 | """Load hgrc files/content into a ui instance. | |
589 |
|
589 | |||
590 | This is called during repository opening to load any additional |
|
590 | This is called during repository opening to load any additional | |
591 | config files or settings relevant to the current repository. |
|
591 | config files or settings relevant to the current repository. | |
592 |
|
592 | |||
593 | Returns a bool indicating whether any additional configs were loaded. |
|
593 | Returns a bool indicating whether any additional configs were loaded. | |
594 |
|
594 | |||
595 | Extensions should monkeypatch this function to modify how per-repo |
|
595 | Extensions should monkeypatch this function to modify how per-repo | |
596 | configs are loaded. For example, an extension may wish to pull in |
|
596 | configs are loaded. For example, an extension may wish to pull in | |
597 | configs from alternate files or sources. |
|
597 | configs from alternate files or sources. | |
598 | """ |
|
598 | """ | |
599 | try: |
|
599 | try: | |
600 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
|
600 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
601 | return True |
|
601 | return True | |
602 | except IOError: |
|
602 | except IOError: | |
603 | return False |
|
603 | return False | |
604 |
|
604 | |||
605 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): |
|
605 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | |
606 | """Perform additional actions after .hg/hgrc is loaded. |
|
606 | """Perform additional actions after .hg/hgrc is loaded. | |
607 |
|
607 | |||
608 | This function is called during repository loading immediately after |
|
608 | This function is called during repository loading immediately after | |
609 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. |
|
609 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. | |
610 |
|
610 | |||
611 | The function can be used to validate configs, automatically add |
|
611 | The function can be used to validate configs, automatically add | |
612 | options (including extensions) based on requirements, etc. |
|
612 | options (including extensions) based on requirements, etc. | |
613 | """ |
|
613 | """ | |
614 |
|
614 | |||
615 | # Map of requirements to list of extensions to load automatically when |
|
615 | # Map of requirements to list of extensions to load automatically when | |
616 | # requirement is present. |
|
616 | # requirement is present. | |
617 | autoextensions = { |
|
617 | autoextensions = { | |
618 | b'largefiles': [b'largefiles'], |
|
618 | b'largefiles': [b'largefiles'], | |
619 | b'lfs': [b'lfs'], |
|
619 | b'lfs': [b'lfs'], | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 | for requirement, names in sorted(autoextensions.items()): |
|
622 | for requirement, names in sorted(autoextensions.items()): | |
623 | if requirement not in requirements: |
|
623 | if requirement not in requirements: | |
624 | continue |
|
624 | continue | |
625 |
|
625 | |||
626 | for name in names: |
|
626 | for name in names: | |
627 | if not ui.hasconfig(b'extensions', name): |
|
627 | if not ui.hasconfig(b'extensions', name): | |
628 | ui.setconfig(b'extensions', name, b'', source='autoload') |
|
628 | ui.setconfig(b'extensions', name, b'', source='autoload') | |
629 |
|
629 | |||
630 | def gathersupportedrequirements(ui): |
|
630 | def gathersupportedrequirements(ui): | |
631 | """Determine the complete set of recognized requirements.""" |
|
631 | """Determine the complete set of recognized requirements.""" | |
632 | # Start with all requirements supported by this file. |
|
632 | # Start with all requirements supported by this file. | |
633 | supported = set(localrepository._basesupported) |
|
633 | supported = set(localrepository._basesupported) | |
634 |
|
634 | |||
635 | # Execute ``featuresetupfuncs`` entries if they belong to an extension |
|
635 | # Execute ``featuresetupfuncs`` entries if they belong to an extension | |
636 | # relevant to this ui instance. |
|
636 | # relevant to this ui instance. | |
637 | modules = {m.__name__ for n, m in extensions.extensions(ui)} |
|
637 | modules = {m.__name__ for n, m in extensions.extensions(ui)} | |
638 |
|
638 | |||
639 | for fn in featuresetupfuncs: |
|
639 | for fn in featuresetupfuncs: | |
640 | if fn.__module__ in modules: |
|
640 | if fn.__module__ in modules: | |
641 | fn(ui, supported) |
|
641 | fn(ui, supported) | |
642 |
|
642 | |||
643 | # Add derived requirements from registered compression engines. |
|
643 | # Add derived requirements from registered compression engines. | |
644 | for name in util.compengines: |
|
644 | for name in util.compengines: | |
645 | engine = util.compengines[name] |
|
645 | engine = util.compengines[name] | |
646 | if engine.available() and engine.revlogheader(): |
|
646 | if engine.available() and engine.revlogheader(): | |
647 | supported.add(b'exp-compression-%s' % name) |
|
647 | supported.add(b'exp-compression-%s' % name) | |
|
648 | if engine.name() == 'zstd': | |||
|
649 | supported.add(b'revlog-compression-zstd') | |||
648 |
|
650 | |||
649 | return supported |
|
651 | return supported | |
650 |
|
652 | |||
651 | def ensurerequirementsrecognized(requirements, supported): |
|
653 | def ensurerequirementsrecognized(requirements, supported): | |
652 | """Validate that a set of local requirements is recognized. |
|
654 | """Validate that a set of local requirements is recognized. | |
653 |
|
655 | |||
654 | Receives a set of requirements. Raises an ``error.RepoError`` if there |
|
656 | Receives a set of requirements. Raises an ``error.RepoError`` if there | |
655 | exists any requirement in that set that currently loaded code doesn't |
|
657 | exists any requirement in that set that currently loaded code doesn't | |
656 | recognize. |
|
658 | recognize. | |
657 |
|
659 | |||
658 | Returns a set of supported requirements. |
|
660 | Returns a set of supported requirements. | |
659 | """ |
|
661 | """ | |
660 | missing = set() |
|
662 | missing = set() | |
661 |
|
663 | |||
662 | for requirement in requirements: |
|
664 | for requirement in requirements: | |
663 | if requirement in supported: |
|
665 | if requirement in supported: | |
664 | continue |
|
666 | continue | |
665 |
|
667 | |||
666 | if not requirement or not requirement[0:1].isalnum(): |
|
668 | if not requirement or not requirement[0:1].isalnum(): | |
667 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) |
|
669 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) | |
668 |
|
670 | |||
669 | missing.add(requirement) |
|
671 | missing.add(requirement) | |
670 |
|
672 | |||
671 | if missing: |
|
673 | if missing: | |
672 | raise error.RequirementError( |
|
674 | raise error.RequirementError( | |
673 | _(b'repository requires features unknown to this Mercurial: %s') % |
|
675 | _(b'repository requires features unknown to this Mercurial: %s') % | |
674 | b' '.join(sorted(missing)), |
|
676 | b' '.join(sorted(missing)), | |
675 | hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement ' |
|
677 | hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement ' | |
676 | b'for more information')) |
|
678 | b'for more information')) | |
677 |
|
679 | |||
678 | def ensurerequirementscompatible(ui, requirements): |
|
680 | def ensurerequirementscompatible(ui, requirements): | |
679 | """Validates that a set of recognized requirements is mutually compatible. |
|
681 | """Validates that a set of recognized requirements is mutually compatible. | |
680 |
|
682 | |||
681 | Some requirements may not be compatible with others or require |
|
683 | Some requirements may not be compatible with others or require | |
682 | config options that aren't enabled. This function is called during |
|
684 | config options that aren't enabled. This function is called during | |
683 | repository opening to ensure that the set of requirements needed |
|
685 | repository opening to ensure that the set of requirements needed | |
684 | to open a repository is sane and compatible with config options. |
|
686 | to open a repository is sane and compatible with config options. | |
685 |
|
687 | |||
686 | Extensions can monkeypatch this function to perform additional |
|
688 | Extensions can monkeypatch this function to perform additional | |
687 | checking. |
|
689 | checking. | |
688 |
|
690 | |||
689 | ``error.RepoError`` should be raised on failure. |
|
691 | ``error.RepoError`` should be raised on failure. | |
690 | """ |
|
692 | """ | |
691 | if b'exp-sparse' in requirements and not sparse.enabled: |
|
693 | if b'exp-sparse' in requirements and not sparse.enabled: | |
692 | raise error.RepoError(_(b'repository is using sparse feature but ' |
|
694 | raise error.RepoError(_(b'repository is using sparse feature but ' | |
693 | b'sparse is not enabled; enable the ' |
|
695 | b'sparse is not enabled; enable the ' | |
694 | b'"sparse" extensions to access')) |
|
696 | b'"sparse" extensions to access')) | |
695 |
|
697 | |||
696 | def makestore(requirements, path, vfstype): |
|
698 | def makestore(requirements, path, vfstype): | |
697 | """Construct a storage object for a repository.""" |
|
699 | """Construct a storage object for a repository.""" | |
698 | if b'store' in requirements: |
|
700 | if b'store' in requirements: | |
699 | if b'fncache' in requirements: |
|
701 | if b'fncache' in requirements: | |
700 | return storemod.fncachestore(path, vfstype, |
|
702 | return storemod.fncachestore(path, vfstype, | |
701 | b'dotencode' in requirements) |
|
703 | b'dotencode' in requirements) | |
702 |
|
704 | |||
703 | return storemod.encodedstore(path, vfstype) |
|
705 | return storemod.encodedstore(path, vfstype) | |
704 |
|
706 | |||
705 | return storemod.basicstore(path, vfstype) |
|
707 | return storemod.basicstore(path, vfstype) | |
706 |
|
708 | |||
707 | def resolvestorevfsoptions(ui, requirements, features): |
|
709 | def resolvestorevfsoptions(ui, requirements, features): | |
708 | """Resolve the options to pass to the store vfs opener. |
|
710 | """Resolve the options to pass to the store vfs opener. | |
709 |
|
711 | |||
710 | The returned dict is used to influence behavior of the storage layer. |
|
712 | The returned dict is used to influence behavior of the storage layer. | |
711 | """ |
|
713 | """ | |
712 | options = {} |
|
714 | options = {} | |
713 |
|
715 | |||
714 | if b'treemanifest' in requirements: |
|
716 | if b'treemanifest' in requirements: | |
715 | options[b'treemanifest'] = True |
|
717 | options[b'treemanifest'] = True | |
716 |
|
718 | |||
717 | # experimental config: format.manifestcachesize |
|
719 | # experimental config: format.manifestcachesize | |
718 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') |
|
720 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') | |
719 | if manifestcachesize is not None: |
|
721 | if manifestcachesize is not None: | |
720 | options[b'manifestcachesize'] = manifestcachesize |
|
722 | options[b'manifestcachesize'] = manifestcachesize | |
721 |
|
723 | |||
722 | # In the absence of another requirement superseding a revlog-related |
|
724 | # In the absence of another requirement superseding a revlog-related | |
723 | # requirement, we have to assume the repo is using revlog version 0. |
|
725 | # requirement, we have to assume the repo is using revlog version 0. | |
724 | # This revlog format is super old and we don't bother trying to parse |
|
726 | # This revlog format is super old and we don't bother trying to parse | |
725 | # opener options for it because those options wouldn't do anything |
|
727 | # opener options for it because those options wouldn't do anything | |
726 | # meaningful on such old repos. |
|
728 | # meaningful on such old repos. | |
727 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: |
|
729 | if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements: | |
728 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) |
|
730 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) | |
729 |
|
731 | |||
730 | return options |
|
732 | return options | |
731 |
|
733 | |||
732 | def resolverevlogstorevfsoptions(ui, requirements, features): |
|
734 | def resolverevlogstorevfsoptions(ui, requirements, features): | |
733 | """Resolve opener options specific to revlogs.""" |
|
735 | """Resolve opener options specific to revlogs.""" | |
734 |
|
736 | |||
735 | options = {} |
|
737 | options = {} | |
736 | options[b'flagprocessors'] = {} |
|
738 | options[b'flagprocessors'] = {} | |
737 |
|
739 | |||
738 | if b'revlogv1' in requirements: |
|
740 | if b'revlogv1' in requirements: | |
739 | options[b'revlogv1'] = True |
|
741 | options[b'revlogv1'] = True | |
740 | if REVLOGV2_REQUIREMENT in requirements: |
|
742 | if REVLOGV2_REQUIREMENT in requirements: | |
741 | options[b'revlogv2'] = True |
|
743 | options[b'revlogv2'] = True | |
742 |
|
744 | |||
743 | if b'generaldelta' in requirements: |
|
745 | if b'generaldelta' in requirements: | |
744 | options[b'generaldelta'] = True |
|
746 | options[b'generaldelta'] = True | |
745 |
|
747 | |||
746 | # experimental config: format.chunkcachesize |
|
748 | # experimental config: format.chunkcachesize | |
747 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') |
|
749 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') | |
748 | if chunkcachesize is not None: |
|
750 | if chunkcachesize is not None: | |
749 | options[b'chunkcachesize'] = chunkcachesize |
|
751 | options[b'chunkcachesize'] = chunkcachesize | |
750 |
|
752 | |||
751 | deltabothparents = ui.configbool(b'storage', |
|
753 | deltabothparents = ui.configbool(b'storage', | |
752 | b'revlog.optimize-delta-parent-choice') |
|
754 | b'revlog.optimize-delta-parent-choice') | |
753 | options[b'deltabothparents'] = deltabothparents |
|
755 | options[b'deltabothparents'] = deltabothparents | |
754 |
|
756 | |||
755 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') |
|
757 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') | |
756 | lazydeltabase = False |
|
758 | lazydeltabase = False | |
757 | if lazydelta: |
|
759 | if lazydelta: | |
758 | lazydeltabase = ui.configbool(b'storage', |
|
760 | lazydeltabase = ui.configbool(b'storage', | |
759 | b'revlog.reuse-external-delta-parent') |
|
761 | b'revlog.reuse-external-delta-parent') | |
760 | if lazydeltabase is None: |
|
762 | if lazydeltabase is None: | |
761 | lazydeltabase = not scmutil.gddeltaconfig(ui) |
|
763 | lazydeltabase = not scmutil.gddeltaconfig(ui) | |
762 | options[b'lazydelta'] = lazydelta |
|
764 | options[b'lazydelta'] = lazydelta | |
763 | options[b'lazydeltabase'] = lazydeltabase |
|
765 | options[b'lazydeltabase'] = lazydeltabase | |
764 |
|
766 | |||
765 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') |
|
767 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') | |
766 | if 0 <= chainspan: |
|
768 | if 0 <= chainspan: | |
767 | options[b'maxdeltachainspan'] = chainspan |
|
769 | options[b'maxdeltachainspan'] = chainspan | |
768 |
|
770 | |||
769 | mmapindexthreshold = ui.configbytes(b'experimental', |
|
771 | mmapindexthreshold = ui.configbytes(b'experimental', | |
770 | b'mmapindexthreshold') |
|
772 | b'mmapindexthreshold') | |
771 | if mmapindexthreshold is not None: |
|
773 | if mmapindexthreshold is not None: | |
772 | options[b'mmapindexthreshold'] = mmapindexthreshold |
|
774 | options[b'mmapindexthreshold'] = mmapindexthreshold | |
773 |
|
775 | |||
774 | withsparseread = ui.configbool(b'experimental', b'sparse-read') |
|
776 | withsparseread = ui.configbool(b'experimental', b'sparse-read') | |
775 | srdensitythres = float(ui.config(b'experimental', |
|
777 | srdensitythres = float(ui.config(b'experimental', | |
776 | b'sparse-read.density-threshold')) |
|
778 | b'sparse-read.density-threshold')) | |
777 | srmingapsize = ui.configbytes(b'experimental', |
|
779 | srmingapsize = ui.configbytes(b'experimental', | |
778 | b'sparse-read.min-gap-size') |
|
780 | b'sparse-read.min-gap-size') | |
779 | options[b'with-sparse-read'] = withsparseread |
|
781 | options[b'with-sparse-read'] = withsparseread | |
780 | options[b'sparse-read-density-threshold'] = srdensitythres |
|
782 | options[b'sparse-read-density-threshold'] = srdensitythres | |
781 | options[b'sparse-read-min-gap-size'] = srmingapsize |
|
783 | options[b'sparse-read-min-gap-size'] = srmingapsize | |
782 |
|
784 | |||
783 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements |
|
785 | sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements | |
784 | options[b'sparse-revlog'] = sparserevlog |
|
786 | options[b'sparse-revlog'] = sparserevlog | |
785 | if sparserevlog: |
|
787 | if sparserevlog: | |
786 | options[b'generaldelta'] = True |
|
788 | options[b'generaldelta'] = True | |
787 |
|
789 | |||
788 | maxchainlen = None |
|
790 | maxchainlen = None | |
789 | if sparserevlog: |
|
791 | if sparserevlog: | |
790 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH |
|
792 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH | |
791 | # experimental config: format.maxchainlen |
|
793 | # experimental config: format.maxchainlen | |
792 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) |
|
794 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) | |
793 | if maxchainlen is not None: |
|
795 | if maxchainlen is not None: | |
794 | options[b'maxchainlen'] = maxchainlen |
|
796 | options[b'maxchainlen'] = maxchainlen | |
795 |
|
797 | |||
796 | for r in requirements: |
|
798 | for r in requirements: | |
797 | if r.startswith(b'exp-compression-'): |
|
799 | # we allow multiple compression engine requirement to co-exist because | |
798 | options[b'compengine'] = r[len(b'exp-compression-'):] |
|
800 | # strickly speaking, revlog seems to support mixed compression style. | |
|
801 | # | |||
|
802 | # The compression used for new entries will be "the last one" | |||
|
803 | prefix = r.startswith | |||
|
804 | if prefix('revlog-compression-') or prefix('exp-compression-'): | |||
|
805 | options[b'compengine'] = r.split('-', 2)[2] | |||
799 |
|
806 | |||
800 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') |
|
807 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') | |
801 | if options[b'zlib.level'] is not None: |
|
808 | if options[b'zlib.level'] is not None: | |
802 | if not (0 <= options[b'zlib.level'] <= 9): |
|
809 | if not (0 <= options[b'zlib.level'] <= 9): | |
803 | msg = _('invalid value for `storage.revlog.zlib.level` config: %d') |
|
810 | msg = _('invalid value for `storage.revlog.zlib.level` config: %d') | |
804 | raise error.Abort(msg % options[b'zlib.level']) |
|
811 | raise error.Abort(msg % options[b'zlib.level']) | |
805 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') |
|
812 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') | |
806 | if options[b'zstd.level'] is not None: |
|
813 | if options[b'zstd.level'] is not None: | |
807 | if not (0 <= options[b'zstd.level'] <= 22): |
|
814 | if not (0 <= options[b'zstd.level'] <= 22): | |
808 | msg = _('invalid value for `storage.revlog.zstd.level` config: %d') |
|
815 | msg = _('invalid value for `storage.revlog.zstd.level` config: %d') | |
809 | raise error.Abort(msg % options[b'zstd.level']) |
|
816 | raise error.Abort(msg % options[b'zstd.level']) | |
810 |
|
817 | |||
811 | if repository.NARROW_REQUIREMENT in requirements: |
|
818 | if repository.NARROW_REQUIREMENT in requirements: | |
812 | options[b'enableellipsis'] = True |
|
819 | options[b'enableellipsis'] = True | |
813 |
|
820 | |||
814 | return options |
|
821 | return options | |
815 |
|
822 | |||
816 | def makemain(**kwargs): |
|
823 | def makemain(**kwargs): | |
817 | """Produce a type conforming to ``ilocalrepositorymain``.""" |
|
824 | """Produce a type conforming to ``ilocalrepositorymain``.""" | |
818 | return localrepository |
|
825 | return localrepository | |
819 |
|
826 | |||
820 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
827 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
821 | class revlogfilestorage(object): |
|
828 | class revlogfilestorage(object): | |
822 | """File storage when using revlogs.""" |
|
829 | """File storage when using revlogs.""" | |
823 |
|
830 | |||
824 | def file(self, path): |
|
831 | def file(self, path): | |
825 | if path[0] == b'/': |
|
832 | if path[0] == b'/': | |
826 | path = path[1:] |
|
833 | path = path[1:] | |
827 |
|
834 | |||
828 | return filelog.filelog(self.svfs, path) |
|
835 | return filelog.filelog(self.svfs, path) | |
829 |
|
836 | |||
830 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
837 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
831 | class revlognarrowfilestorage(object): |
|
838 | class revlognarrowfilestorage(object): | |
832 | """File storage when using revlogs and narrow files.""" |
|
839 | """File storage when using revlogs and narrow files.""" | |
833 |
|
840 | |||
834 | def file(self, path): |
|
841 | def file(self, path): | |
835 | if path[0] == b'/': |
|
842 | if path[0] == b'/': | |
836 | path = path[1:] |
|
843 | path = path[1:] | |
837 |
|
844 | |||
838 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) |
|
845 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) | |
839 |
|
846 | |||
840 | def makefilestorage(requirements, features, **kwargs): |
|
847 | def makefilestorage(requirements, features, **kwargs): | |
841 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
|
848 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" | |
842 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) |
|
849 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) | |
843 | features.add(repository.REPO_FEATURE_STREAM_CLONE) |
|
850 | features.add(repository.REPO_FEATURE_STREAM_CLONE) | |
844 |
|
851 | |||
845 | if repository.NARROW_REQUIREMENT in requirements: |
|
852 | if repository.NARROW_REQUIREMENT in requirements: | |
846 | return revlognarrowfilestorage |
|
853 | return revlognarrowfilestorage | |
847 | else: |
|
854 | else: | |
848 | return revlogfilestorage |
|
855 | return revlogfilestorage | |
849 |
|
856 | |||
850 | # List of repository interfaces and factory functions for them. Each |
|
857 | # List of repository interfaces and factory functions for them. Each | |
851 | # will be called in order during ``makelocalrepository()`` to iteratively |
|
858 | # will be called in order during ``makelocalrepository()`` to iteratively | |
852 | # derive the final type for a local repository instance. We capture the |
|
859 | # derive the final type for a local repository instance. We capture the | |
853 | # function as a lambda so we don't hold a reference and the module-level |
|
860 | # function as a lambda so we don't hold a reference and the module-level | |
854 | # functions can be wrapped. |
|
861 | # functions can be wrapped. | |
855 | REPO_INTERFACES = [ |
|
862 | REPO_INTERFACES = [ | |
856 | (repository.ilocalrepositorymain, lambda: makemain), |
|
863 | (repository.ilocalrepositorymain, lambda: makemain), | |
857 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), |
|
864 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), | |
858 | ] |
|
865 | ] | |
859 |
|
866 | |||
860 | @interfaceutil.implementer(repository.ilocalrepositorymain) |
|
867 | @interfaceutil.implementer(repository.ilocalrepositorymain) | |
861 | class localrepository(object): |
|
868 | class localrepository(object): | |
862 | """Main class for representing local repositories. |
|
869 | """Main class for representing local repositories. | |
863 |
|
870 | |||
864 | All local repositories are instances of this class. |
|
871 | All local repositories are instances of this class. | |
865 |
|
872 | |||
866 | Constructed on its own, instances of this class are not usable as |
|
873 | Constructed on its own, instances of this class are not usable as | |
867 | repository objects. To obtain a usable repository object, call |
|
874 | repository objects. To obtain a usable repository object, call | |
868 | ``hg.repository()``, ``localrepo.instance()``, or |
|
875 | ``hg.repository()``, ``localrepo.instance()``, or | |
869 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. |
|
876 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. | |
870 | ``instance()`` adds support for creating new repositories. |
|
877 | ``instance()`` adds support for creating new repositories. | |
871 | ``hg.repository()`` adds more extension integration, including calling |
|
878 | ``hg.repository()`` adds more extension integration, including calling | |
872 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be |
|
879 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be | |
873 | used. |
|
880 | used. | |
874 | """ |
|
881 | """ | |
875 |
|
882 | |||
876 | # obsolete experimental requirements: |
|
883 | # obsolete experimental requirements: | |
877 | # - manifestv2: An experimental new manifest format that allowed |
|
884 | # - manifestv2: An experimental new manifest format that allowed | |
878 | # for stem compression of long paths. Experiment ended up not |
|
885 | # for stem compression of long paths. Experiment ended up not | |
879 | # being successful (repository sizes went up due to worse delta |
|
886 | # being successful (repository sizes went up due to worse delta | |
880 | # chains), and the code was deleted in 4.6. |
|
887 | # chains), and the code was deleted in 4.6. | |
881 | supportedformats = { |
|
888 | supportedformats = { | |
882 | 'revlogv1', |
|
889 | 'revlogv1', | |
883 | 'generaldelta', |
|
890 | 'generaldelta', | |
884 | 'treemanifest', |
|
891 | 'treemanifest', | |
885 | REVLOGV2_REQUIREMENT, |
|
892 | REVLOGV2_REQUIREMENT, | |
886 | SPARSEREVLOG_REQUIREMENT, |
|
893 | SPARSEREVLOG_REQUIREMENT, | |
887 | } |
|
894 | } | |
888 | _basesupported = supportedformats | { |
|
895 | _basesupported = supportedformats | { | |
889 | 'store', |
|
896 | 'store', | |
890 | 'fncache', |
|
897 | 'fncache', | |
891 | 'shared', |
|
898 | 'shared', | |
892 | 'relshared', |
|
899 | 'relshared', | |
893 | 'dotencode', |
|
900 | 'dotencode', | |
894 | 'exp-sparse', |
|
901 | 'exp-sparse', | |
895 | 'internal-phase' |
|
902 | 'internal-phase' | |
896 | } |
|
903 | } | |
897 |
|
904 | |||
898 | # list of prefix for file which can be written without 'wlock' |
|
905 | # list of prefix for file which can be written without 'wlock' | |
899 | # Extensions should extend this list when needed |
|
906 | # Extensions should extend this list when needed | |
900 | _wlockfreeprefix = { |
|
907 | _wlockfreeprefix = { | |
901 | # We migh consider requiring 'wlock' for the next |
|
908 | # We migh consider requiring 'wlock' for the next | |
902 | # two, but pretty much all the existing code assume |
|
909 | # two, but pretty much all the existing code assume | |
903 | # wlock is not needed so we keep them excluded for |
|
910 | # wlock is not needed so we keep them excluded for | |
904 | # now. |
|
911 | # now. | |
905 | 'hgrc', |
|
912 | 'hgrc', | |
906 | 'requires', |
|
913 | 'requires', | |
907 | # XXX cache is a complicatged business someone |
|
914 | # XXX cache is a complicatged business someone | |
908 | # should investigate this in depth at some point |
|
915 | # should investigate this in depth at some point | |
909 | 'cache/', |
|
916 | 'cache/', | |
910 | # XXX shouldn't be dirstate covered by the wlock? |
|
917 | # XXX shouldn't be dirstate covered by the wlock? | |
911 | 'dirstate', |
|
918 | 'dirstate', | |
912 | # XXX bisect was still a bit too messy at the time |
|
919 | # XXX bisect was still a bit too messy at the time | |
913 | # this changeset was introduced. Someone should fix |
|
920 | # this changeset was introduced. Someone should fix | |
914 | # the remainig bit and drop this line |
|
921 | # the remainig bit and drop this line | |
915 | 'bisect.state', |
|
922 | 'bisect.state', | |
916 | } |
|
923 | } | |
917 |
|
924 | |||
918 | def __init__(self, baseui, ui, origroot, wdirvfs, hgvfs, requirements, |
|
925 | def __init__(self, baseui, ui, origroot, wdirvfs, hgvfs, requirements, | |
919 | supportedrequirements, sharedpath, store, cachevfs, wcachevfs, |
|
926 | supportedrequirements, sharedpath, store, cachevfs, wcachevfs, | |
920 | features, intents=None): |
|
927 | features, intents=None): | |
921 | """Create a new local repository instance. |
|
928 | """Create a new local repository instance. | |
922 |
|
929 | |||
923 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, |
|
930 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, | |
924 | or ``localrepo.makelocalrepository()`` for obtaining a new repository |
|
931 | or ``localrepo.makelocalrepository()`` for obtaining a new repository | |
925 | object. |
|
932 | object. | |
926 |
|
933 | |||
927 | Arguments: |
|
934 | Arguments: | |
928 |
|
935 | |||
929 | baseui |
|
936 | baseui | |
930 | ``ui.ui`` instance that ``ui`` argument was based off of. |
|
937 | ``ui.ui`` instance that ``ui`` argument was based off of. | |
931 |
|
938 | |||
932 | ui |
|
939 | ui | |
933 | ``ui.ui`` instance for use by the repository. |
|
940 | ``ui.ui`` instance for use by the repository. | |
934 |
|
941 | |||
935 | origroot |
|
942 | origroot | |
936 | ``bytes`` path to working directory root of this repository. |
|
943 | ``bytes`` path to working directory root of this repository. | |
937 |
|
944 | |||
938 | wdirvfs |
|
945 | wdirvfs | |
939 | ``vfs.vfs`` rooted at the working directory. |
|
946 | ``vfs.vfs`` rooted at the working directory. | |
940 |
|
947 | |||
941 | hgvfs |
|
948 | hgvfs | |
942 | ``vfs.vfs`` rooted at .hg/ |
|
949 | ``vfs.vfs`` rooted at .hg/ | |
943 |
|
950 | |||
944 | requirements |
|
951 | requirements | |
945 | ``set`` of bytestrings representing repository opening requirements. |
|
952 | ``set`` of bytestrings representing repository opening requirements. | |
946 |
|
953 | |||
947 | supportedrequirements |
|
954 | supportedrequirements | |
948 | ``set`` of bytestrings representing repository requirements that we |
|
955 | ``set`` of bytestrings representing repository requirements that we | |
949 | know how to open. May be a supetset of ``requirements``. |
|
956 | know how to open. May be a supetset of ``requirements``. | |
950 |
|
957 | |||
951 | sharedpath |
|
958 | sharedpath | |
952 | ``bytes`` Defining path to storage base directory. Points to a |
|
959 | ``bytes`` Defining path to storage base directory. Points to a | |
953 | ``.hg/`` directory somewhere. |
|
960 | ``.hg/`` directory somewhere. | |
954 |
|
961 | |||
955 | store |
|
962 | store | |
956 | ``store.basicstore`` (or derived) instance providing access to |
|
963 | ``store.basicstore`` (or derived) instance providing access to | |
957 | versioned storage. |
|
964 | versioned storage. | |
958 |
|
965 | |||
959 | cachevfs |
|
966 | cachevfs | |
960 | ``vfs.vfs`` used for cache files. |
|
967 | ``vfs.vfs`` used for cache files. | |
961 |
|
968 | |||
962 | wcachevfs |
|
969 | wcachevfs | |
963 | ``vfs.vfs`` used for cache files related to the working copy. |
|
970 | ``vfs.vfs`` used for cache files related to the working copy. | |
964 |
|
971 | |||
965 | features |
|
972 | features | |
966 | ``set`` of bytestrings defining features/capabilities of this |
|
973 | ``set`` of bytestrings defining features/capabilities of this | |
967 | instance. |
|
974 | instance. | |
968 |
|
975 | |||
969 | intents |
|
976 | intents | |
970 | ``set`` of system strings indicating what this repo will be used |
|
977 | ``set`` of system strings indicating what this repo will be used | |
971 | for. |
|
978 | for. | |
972 | """ |
|
979 | """ | |
973 | self.baseui = baseui |
|
980 | self.baseui = baseui | |
974 | self.ui = ui |
|
981 | self.ui = ui | |
975 | self.origroot = origroot |
|
982 | self.origroot = origroot | |
976 | # vfs rooted at working directory. |
|
983 | # vfs rooted at working directory. | |
977 | self.wvfs = wdirvfs |
|
984 | self.wvfs = wdirvfs | |
978 | self.root = wdirvfs.base |
|
985 | self.root = wdirvfs.base | |
979 | # vfs rooted at .hg/. Used to access most non-store paths. |
|
986 | # vfs rooted at .hg/. Used to access most non-store paths. | |
980 | self.vfs = hgvfs |
|
987 | self.vfs = hgvfs | |
981 | self.path = hgvfs.base |
|
988 | self.path = hgvfs.base | |
982 | self.requirements = requirements |
|
989 | self.requirements = requirements | |
983 | self.supported = supportedrequirements |
|
990 | self.supported = supportedrequirements | |
984 | self.sharedpath = sharedpath |
|
991 | self.sharedpath = sharedpath | |
985 | self.store = store |
|
992 | self.store = store | |
986 | self.cachevfs = cachevfs |
|
993 | self.cachevfs = cachevfs | |
987 | self.wcachevfs = wcachevfs |
|
994 | self.wcachevfs = wcachevfs | |
988 | self.features = features |
|
995 | self.features = features | |
989 |
|
996 | |||
990 | self.filtername = None |
|
997 | self.filtername = None | |
991 |
|
998 | |||
992 | if (self.ui.configbool('devel', 'all-warnings') or |
|
999 | if (self.ui.configbool('devel', 'all-warnings') or | |
993 | self.ui.configbool('devel', 'check-locks')): |
|
1000 | self.ui.configbool('devel', 'check-locks')): | |
994 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
1001 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
995 | # A list of callback to shape the phase if no data were found. |
|
1002 | # A list of callback to shape the phase if no data were found. | |
996 | # Callback are in the form: func(repo, roots) --> processed root. |
|
1003 | # Callback are in the form: func(repo, roots) --> processed root. | |
997 | # This list it to be filled by extension during repo setup |
|
1004 | # This list it to be filled by extension during repo setup | |
998 | self._phasedefaults = [] |
|
1005 | self._phasedefaults = [] | |
999 |
|
1006 | |||
1000 | color.setup(self.ui) |
|
1007 | color.setup(self.ui) | |
1001 |
|
1008 | |||
1002 | self.spath = self.store.path |
|
1009 | self.spath = self.store.path | |
1003 | self.svfs = self.store.vfs |
|
1010 | self.svfs = self.store.vfs | |
1004 | self.sjoin = self.store.join |
|
1011 | self.sjoin = self.store.join | |
1005 | if (self.ui.configbool('devel', 'all-warnings') or |
|
1012 | if (self.ui.configbool('devel', 'all-warnings') or | |
1006 | self.ui.configbool('devel', 'check-locks')): |
|
1013 | self.ui.configbool('devel', 'check-locks')): | |
1007 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs |
|
1014 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs | |
1008 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
1015 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
1009 | else: # standard vfs |
|
1016 | else: # standard vfs | |
1010 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
1017 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
1011 |
|
1018 | |||
1012 | self._dirstatevalidatewarned = False |
|
1019 | self._dirstatevalidatewarned = False | |
1013 |
|
1020 | |||
1014 | self._branchcaches = branchmap.BranchMapCache() |
|
1021 | self._branchcaches = branchmap.BranchMapCache() | |
1015 | self._revbranchcache = None |
|
1022 | self._revbranchcache = None | |
1016 | self._filterpats = {} |
|
1023 | self._filterpats = {} | |
1017 | self._datafilters = {} |
|
1024 | self._datafilters = {} | |
1018 | self._transref = self._lockref = self._wlockref = None |
|
1025 | self._transref = self._lockref = self._wlockref = None | |
1019 |
|
1026 | |||
1020 | # A cache for various files under .hg/ that tracks file changes, |
|
1027 | # A cache for various files under .hg/ that tracks file changes, | |
1021 | # (used by the filecache decorator) |
|
1028 | # (used by the filecache decorator) | |
1022 | # |
|
1029 | # | |
1023 | # Maps a property name to its util.filecacheentry |
|
1030 | # Maps a property name to its util.filecacheentry | |
1024 | self._filecache = {} |
|
1031 | self._filecache = {} | |
1025 |
|
1032 | |||
1026 | # hold sets of revision to be filtered |
|
1033 | # hold sets of revision to be filtered | |
1027 | # should be cleared when something might have changed the filter value: |
|
1034 | # should be cleared when something might have changed the filter value: | |
1028 | # - new changesets, |
|
1035 | # - new changesets, | |
1029 | # - phase change, |
|
1036 | # - phase change, | |
1030 | # - new obsolescence marker, |
|
1037 | # - new obsolescence marker, | |
1031 | # - working directory parent change, |
|
1038 | # - working directory parent change, | |
1032 | # - bookmark changes |
|
1039 | # - bookmark changes | |
1033 | self.filteredrevcache = {} |
|
1040 | self.filteredrevcache = {} | |
1034 |
|
1041 | |||
1035 | # post-dirstate-status hooks |
|
1042 | # post-dirstate-status hooks | |
1036 | self._postdsstatus = [] |
|
1043 | self._postdsstatus = [] | |
1037 |
|
1044 | |||
1038 | # generic mapping between names and nodes |
|
1045 | # generic mapping between names and nodes | |
1039 | self.names = namespaces.namespaces() |
|
1046 | self.names = namespaces.namespaces() | |
1040 |
|
1047 | |||
1041 | # Key to signature value. |
|
1048 | # Key to signature value. | |
1042 | self._sparsesignaturecache = {} |
|
1049 | self._sparsesignaturecache = {} | |
1043 | # Signature to cached matcher instance. |
|
1050 | # Signature to cached matcher instance. | |
1044 | self._sparsematchercache = {} |
|
1051 | self._sparsematchercache = {} | |
1045 |
|
1052 | |||
1046 | def _getvfsward(self, origfunc): |
|
1053 | def _getvfsward(self, origfunc): | |
1047 | """build a ward for self.vfs""" |
|
1054 | """build a ward for self.vfs""" | |
1048 | rref = weakref.ref(self) |
|
1055 | rref = weakref.ref(self) | |
1049 | def checkvfs(path, mode=None): |
|
1056 | def checkvfs(path, mode=None): | |
1050 | ret = origfunc(path, mode=mode) |
|
1057 | ret = origfunc(path, mode=mode) | |
1051 | repo = rref() |
|
1058 | repo = rref() | |
1052 | if (repo is None |
|
1059 | if (repo is None | |
1053 | or not util.safehasattr(repo, '_wlockref') |
|
1060 | or not util.safehasattr(repo, '_wlockref') | |
1054 | or not util.safehasattr(repo, '_lockref')): |
|
1061 | or not util.safehasattr(repo, '_lockref')): | |
1055 | return |
|
1062 | return | |
1056 | if mode in (None, 'r', 'rb'): |
|
1063 | if mode in (None, 'r', 'rb'): | |
1057 | return |
|
1064 | return | |
1058 | if path.startswith(repo.path): |
|
1065 | if path.startswith(repo.path): | |
1059 | # truncate name relative to the repository (.hg) |
|
1066 | # truncate name relative to the repository (.hg) | |
1060 | path = path[len(repo.path) + 1:] |
|
1067 | path = path[len(repo.path) + 1:] | |
1061 | if path.startswith('cache/'): |
|
1068 | if path.startswith('cache/'): | |
1062 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' |
|
1069 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' | |
1063 | repo.ui.develwarn(msg % path, stacklevel=3, config="cache-vfs") |
|
1070 | repo.ui.develwarn(msg % path, stacklevel=3, config="cache-vfs") | |
1064 | if path.startswith('journal.') or path.startswith('undo.'): |
|
1071 | if path.startswith('journal.') or path.startswith('undo.'): | |
1065 | # journal is covered by 'lock' |
|
1072 | # journal is covered by 'lock' | |
1066 | if repo._currentlock(repo._lockref) is None: |
|
1073 | if repo._currentlock(repo._lockref) is None: | |
1067 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
1074 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
1068 | stacklevel=3, config='check-locks') |
|
1075 | stacklevel=3, config='check-locks') | |
1069 | elif repo._currentlock(repo._wlockref) is None: |
|
1076 | elif repo._currentlock(repo._wlockref) is None: | |
1070 | # rest of vfs files are covered by 'wlock' |
|
1077 | # rest of vfs files are covered by 'wlock' | |
1071 | # |
|
1078 | # | |
1072 | # exclude special files |
|
1079 | # exclude special files | |
1073 | for prefix in self._wlockfreeprefix: |
|
1080 | for prefix in self._wlockfreeprefix: | |
1074 | if path.startswith(prefix): |
|
1081 | if path.startswith(prefix): | |
1075 | return |
|
1082 | return | |
1076 | repo.ui.develwarn('write with no wlock: "%s"' % path, |
|
1083 | repo.ui.develwarn('write with no wlock: "%s"' % path, | |
1077 | stacklevel=3, config='check-locks') |
|
1084 | stacklevel=3, config='check-locks') | |
1078 | return ret |
|
1085 | return ret | |
1079 | return checkvfs |
|
1086 | return checkvfs | |
1080 |
|
1087 | |||
1081 | def _getsvfsward(self, origfunc): |
|
1088 | def _getsvfsward(self, origfunc): | |
1082 | """build a ward for self.svfs""" |
|
1089 | """build a ward for self.svfs""" | |
1083 | rref = weakref.ref(self) |
|
1090 | rref = weakref.ref(self) | |
1084 | def checksvfs(path, mode=None): |
|
1091 | def checksvfs(path, mode=None): | |
1085 | ret = origfunc(path, mode=mode) |
|
1092 | ret = origfunc(path, mode=mode) | |
1086 | repo = rref() |
|
1093 | repo = rref() | |
1087 | if repo is None or not util.safehasattr(repo, '_lockref'): |
|
1094 | if repo is None or not util.safehasattr(repo, '_lockref'): | |
1088 | return |
|
1095 | return | |
1089 | if mode in (None, 'r', 'rb'): |
|
1096 | if mode in (None, 'r', 'rb'): | |
1090 | return |
|
1097 | return | |
1091 | if path.startswith(repo.sharedpath): |
|
1098 | if path.startswith(repo.sharedpath): | |
1092 | # truncate name relative to the repository (.hg) |
|
1099 | # truncate name relative to the repository (.hg) | |
1093 | path = path[len(repo.sharedpath) + 1:] |
|
1100 | path = path[len(repo.sharedpath) + 1:] | |
1094 | if repo._currentlock(repo._lockref) is None: |
|
1101 | if repo._currentlock(repo._lockref) is None: | |
1095 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
1102 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
1096 | stacklevel=4) |
|
1103 | stacklevel=4) | |
1097 | return ret |
|
1104 | return ret | |
1098 | return checksvfs |
|
1105 | return checksvfs | |
1099 |
|
1106 | |||
1100 | def close(self): |
|
1107 | def close(self): | |
1101 | self._writecaches() |
|
1108 | self._writecaches() | |
1102 |
|
1109 | |||
1103 | def _writecaches(self): |
|
1110 | def _writecaches(self): | |
1104 | if self._revbranchcache: |
|
1111 | if self._revbranchcache: | |
1105 | self._revbranchcache.write() |
|
1112 | self._revbranchcache.write() | |
1106 |
|
1113 | |||
1107 | def _restrictcapabilities(self, caps): |
|
1114 | def _restrictcapabilities(self, caps): | |
1108 | if self.ui.configbool('experimental', 'bundle2-advertise'): |
|
1115 | if self.ui.configbool('experimental', 'bundle2-advertise'): | |
1109 | caps = set(caps) |
|
1116 | caps = set(caps) | |
1110 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, |
|
1117 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, | |
1111 | role='client')) |
|
1118 | role='client')) | |
1112 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
1119 | caps.add('bundle2=' + urlreq.quote(capsblob)) | |
1113 | return caps |
|
1120 | return caps | |
1114 |
|
1121 | |||
1115 | def _writerequirements(self): |
|
1122 | def _writerequirements(self): | |
1116 | scmutil.writerequires(self.vfs, self.requirements) |
|
1123 | scmutil.writerequires(self.vfs, self.requirements) | |
1117 |
|
1124 | |||
1118 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: |
|
1125 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: | |
1119 | # self -> auditor -> self._checknested -> self |
|
1126 | # self -> auditor -> self._checknested -> self | |
1120 |
|
1127 | |||
1121 | @property |
|
1128 | @property | |
1122 | def auditor(self): |
|
1129 | def auditor(self): | |
1123 | # This is only used by context.workingctx.match in order to |
|
1130 | # This is only used by context.workingctx.match in order to | |
1124 | # detect files in subrepos. |
|
1131 | # detect files in subrepos. | |
1125 | return pathutil.pathauditor(self.root, callback=self._checknested) |
|
1132 | return pathutil.pathauditor(self.root, callback=self._checknested) | |
1126 |
|
1133 | |||
1127 | @property |
|
1134 | @property | |
1128 | def nofsauditor(self): |
|
1135 | def nofsauditor(self): | |
1129 | # This is only used by context.basectx.match in order to detect |
|
1136 | # This is only used by context.basectx.match in order to detect | |
1130 | # files in subrepos. |
|
1137 | # files in subrepos. | |
1131 | return pathutil.pathauditor(self.root, callback=self._checknested, |
|
1138 | return pathutil.pathauditor(self.root, callback=self._checknested, | |
1132 | realfs=False, cached=True) |
|
1139 | realfs=False, cached=True) | |
1133 |
|
1140 | |||
1134 | def _checknested(self, path): |
|
1141 | def _checknested(self, path): | |
1135 | """Determine if path is a legal nested repository.""" |
|
1142 | """Determine if path is a legal nested repository.""" | |
1136 | if not path.startswith(self.root): |
|
1143 | if not path.startswith(self.root): | |
1137 | return False |
|
1144 | return False | |
1138 | subpath = path[len(self.root) + 1:] |
|
1145 | subpath = path[len(self.root) + 1:] | |
1139 | normsubpath = util.pconvert(subpath) |
|
1146 | normsubpath = util.pconvert(subpath) | |
1140 |
|
1147 | |||
1141 | # XXX: Checking against the current working copy is wrong in |
|
1148 | # XXX: Checking against the current working copy is wrong in | |
1142 | # the sense that it can reject things like |
|
1149 | # the sense that it can reject things like | |
1143 | # |
|
1150 | # | |
1144 | # $ hg cat -r 10 sub/x.txt |
|
1151 | # $ hg cat -r 10 sub/x.txt | |
1145 | # |
|
1152 | # | |
1146 | # if sub/ is no longer a subrepository in the working copy |
|
1153 | # if sub/ is no longer a subrepository in the working copy | |
1147 | # parent revision. |
|
1154 | # parent revision. | |
1148 | # |
|
1155 | # | |
1149 | # However, it can of course also allow things that would have |
|
1156 | # However, it can of course also allow things that would have | |
1150 | # been rejected before, such as the above cat command if sub/ |
|
1157 | # been rejected before, such as the above cat command if sub/ | |
1151 | # is a subrepository now, but was a normal directory before. |
|
1158 | # is a subrepository now, but was a normal directory before. | |
1152 | # The old path auditor would have rejected by mistake since it |
|
1159 | # The old path auditor would have rejected by mistake since it | |
1153 | # panics when it sees sub/.hg/. |
|
1160 | # panics when it sees sub/.hg/. | |
1154 | # |
|
1161 | # | |
1155 | # All in all, checking against the working copy seems sensible |
|
1162 | # All in all, checking against the working copy seems sensible | |
1156 | # since we want to prevent access to nested repositories on |
|
1163 | # since we want to prevent access to nested repositories on | |
1157 | # the filesystem *now*. |
|
1164 | # the filesystem *now*. | |
1158 | ctx = self[None] |
|
1165 | ctx = self[None] | |
1159 | parts = util.splitpath(subpath) |
|
1166 | parts = util.splitpath(subpath) | |
1160 | while parts: |
|
1167 | while parts: | |
1161 | prefix = '/'.join(parts) |
|
1168 | prefix = '/'.join(parts) | |
1162 | if prefix in ctx.substate: |
|
1169 | if prefix in ctx.substate: | |
1163 | if prefix == normsubpath: |
|
1170 | if prefix == normsubpath: | |
1164 | return True |
|
1171 | return True | |
1165 | else: |
|
1172 | else: | |
1166 | sub = ctx.sub(prefix) |
|
1173 | sub = ctx.sub(prefix) | |
1167 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
1174 | return sub.checknested(subpath[len(prefix) + 1:]) | |
1168 | else: |
|
1175 | else: | |
1169 | parts.pop() |
|
1176 | parts.pop() | |
1170 | return False |
|
1177 | return False | |
1171 |
|
1178 | |||
1172 | def peer(self): |
|
1179 | def peer(self): | |
1173 | return localpeer(self) # not cached to avoid reference cycle |
|
1180 | return localpeer(self) # not cached to avoid reference cycle | |
1174 |
|
1181 | |||
1175 | def unfiltered(self): |
|
1182 | def unfiltered(self): | |
1176 | """Return unfiltered version of the repository |
|
1183 | """Return unfiltered version of the repository | |
1177 |
|
1184 | |||
1178 | Intended to be overwritten by filtered repo.""" |
|
1185 | Intended to be overwritten by filtered repo.""" | |
1179 | return self |
|
1186 | return self | |
1180 |
|
1187 | |||
1181 | def filtered(self, name, visibilityexceptions=None): |
|
1188 | def filtered(self, name, visibilityexceptions=None): | |
1182 | """Return a filtered version of a repository |
|
1189 | """Return a filtered version of a repository | |
1183 |
|
1190 | |||
1184 | The `name` parameter is the identifier of the requested view. This |
|
1191 | The `name` parameter is the identifier of the requested view. This | |
1185 | will return a repoview object set "exactly" to the specified view. |
|
1192 | will return a repoview object set "exactly" to the specified view. | |
1186 |
|
1193 | |||
1187 | This function does not apply recursive filtering to a repository. For |
|
1194 | This function does not apply recursive filtering to a repository. For | |
1188 | example calling `repo.filtered("served")` will return a repoview using |
|
1195 | example calling `repo.filtered("served")` will return a repoview using | |
1189 | the "served" view, regardless of the initial view used by `repo`. |
|
1196 | the "served" view, regardless of the initial view used by `repo`. | |
1190 |
|
1197 | |||
1191 | In other word, there is always only one level of `repoview` "filtering". |
|
1198 | In other word, there is always only one level of `repoview` "filtering". | |
1192 | """ |
|
1199 | """ | |
1193 | cls = repoview.newtype(self.unfiltered().__class__) |
|
1200 | cls = repoview.newtype(self.unfiltered().__class__) | |
1194 | return cls(self, name, visibilityexceptions) |
|
1201 | return cls(self, name, visibilityexceptions) | |
1195 |
|
1202 | |||
1196 | @repofilecache('bookmarks', 'bookmarks.current') |
|
1203 | @repofilecache('bookmarks', 'bookmarks.current') | |
1197 | def _bookmarks(self): |
|
1204 | def _bookmarks(self): | |
1198 | return bookmarks.bmstore(self) |
|
1205 | return bookmarks.bmstore(self) | |
1199 |
|
1206 | |||
1200 | @property |
|
1207 | @property | |
1201 | def _activebookmark(self): |
|
1208 | def _activebookmark(self): | |
1202 | return self._bookmarks.active |
|
1209 | return self._bookmarks.active | |
1203 |
|
1210 | |||
1204 | # _phasesets depend on changelog. what we need is to call |
|
1211 | # _phasesets depend on changelog. what we need is to call | |
1205 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
1212 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
1206 | # can't be easily expressed in filecache mechanism. |
|
1213 | # can't be easily expressed in filecache mechanism. | |
1207 | @storecache('phaseroots', '00changelog.i') |
|
1214 | @storecache('phaseroots', '00changelog.i') | |
1208 | def _phasecache(self): |
|
1215 | def _phasecache(self): | |
1209 | return phases.phasecache(self, self._phasedefaults) |
|
1216 | return phases.phasecache(self, self._phasedefaults) | |
1210 |
|
1217 | |||
1211 | @storecache('obsstore') |
|
1218 | @storecache('obsstore') | |
1212 | def obsstore(self): |
|
1219 | def obsstore(self): | |
1213 | return obsolete.makestore(self.ui, self) |
|
1220 | return obsolete.makestore(self.ui, self) | |
1214 |
|
1221 | |||
1215 | @storecache('00changelog.i') |
|
1222 | @storecache('00changelog.i') | |
1216 | def changelog(self): |
|
1223 | def changelog(self): | |
1217 | return changelog.changelog(self.svfs, |
|
1224 | return changelog.changelog(self.svfs, | |
1218 | trypending=txnutil.mayhavepending(self.root)) |
|
1225 | trypending=txnutil.mayhavepending(self.root)) | |
1219 |
|
1226 | |||
1220 | @storecache('00manifest.i') |
|
1227 | @storecache('00manifest.i') | |
1221 | def manifestlog(self): |
|
1228 | def manifestlog(self): | |
1222 | rootstore = manifest.manifestrevlog(self.svfs) |
|
1229 | rootstore = manifest.manifestrevlog(self.svfs) | |
1223 | return manifest.manifestlog(self.svfs, self, rootstore, |
|
1230 | return manifest.manifestlog(self.svfs, self, rootstore, | |
1224 | self._storenarrowmatch) |
|
1231 | self._storenarrowmatch) | |
1225 |
|
1232 | |||
1226 | @repofilecache('dirstate') |
|
1233 | @repofilecache('dirstate') | |
1227 | def dirstate(self): |
|
1234 | def dirstate(self): | |
1228 | return self._makedirstate() |
|
1235 | return self._makedirstate() | |
1229 |
|
1236 | |||
1230 | def _makedirstate(self): |
|
1237 | def _makedirstate(self): | |
1231 | """Extension point for wrapping the dirstate per-repo.""" |
|
1238 | """Extension point for wrapping the dirstate per-repo.""" | |
1232 | sparsematchfn = lambda: sparse.matcher(self) |
|
1239 | sparsematchfn = lambda: sparse.matcher(self) | |
1233 |
|
1240 | |||
1234 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
1241 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
1235 | self._dirstatevalidate, sparsematchfn) |
|
1242 | self._dirstatevalidate, sparsematchfn) | |
1236 |
|
1243 | |||
1237 | def _dirstatevalidate(self, node): |
|
1244 | def _dirstatevalidate(self, node): | |
1238 | try: |
|
1245 | try: | |
1239 | self.changelog.rev(node) |
|
1246 | self.changelog.rev(node) | |
1240 | return node |
|
1247 | return node | |
1241 | except error.LookupError: |
|
1248 | except error.LookupError: | |
1242 | if not self._dirstatevalidatewarned: |
|
1249 | if not self._dirstatevalidatewarned: | |
1243 | self._dirstatevalidatewarned = True |
|
1250 | self._dirstatevalidatewarned = True | |
1244 | self.ui.warn(_("warning: ignoring unknown" |
|
1251 | self.ui.warn(_("warning: ignoring unknown" | |
1245 | " working parent %s!\n") % short(node)) |
|
1252 | " working parent %s!\n") % short(node)) | |
1246 | return nullid |
|
1253 | return nullid | |
1247 |
|
1254 | |||
1248 | @storecache(narrowspec.FILENAME) |
|
1255 | @storecache(narrowspec.FILENAME) | |
1249 | def narrowpats(self): |
|
1256 | def narrowpats(self): | |
1250 | """matcher patterns for this repository's narrowspec |
|
1257 | """matcher patterns for this repository's narrowspec | |
1251 |
|
1258 | |||
1252 | A tuple of (includes, excludes). |
|
1259 | A tuple of (includes, excludes). | |
1253 | """ |
|
1260 | """ | |
1254 | return narrowspec.load(self) |
|
1261 | return narrowspec.load(self) | |
1255 |
|
1262 | |||
1256 | @storecache(narrowspec.FILENAME) |
|
1263 | @storecache(narrowspec.FILENAME) | |
1257 | def _storenarrowmatch(self): |
|
1264 | def _storenarrowmatch(self): | |
1258 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1265 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1259 | return matchmod.always() |
|
1266 | return matchmod.always() | |
1260 | include, exclude = self.narrowpats |
|
1267 | include, exclude = self.narrowpats | |
1261 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1268 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1262 |
|
1269 | |||
1263 | @storecache(narrowspec.FILENAME) |
|
1270 | @storecache(narrowspec.FILENAME) | |
1264 | def _narrowmatch(self): |
|
1271 | def _narrowmatch(self): | |
1265 | if repository.NARROW_REQUIREMENT not in self.requirements: |
|
1272 | if repository.NARROW_REQUIREMENT not in self.requirements: | |
1266 | return matchmod.always() |
|
1273 | return matchmod.always() | |
1267 | narrowspec.checkworkingcopynarrowspec(self) |
|
1274 | narrowspec.checkworkingcopynarrowspec(self) | |
1268 | include, exclude = self.narrowpats |
|
1275 | include, exclude = self.narrowpats | |
1269 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1276 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1270 |
|
1277 | |||
1271 | def narrowmatch(self, match=None, includeexact=False): |
|
1278 | def narrowmatch(self, match=None, includeexact=False): | |
1272 | """matcher corresponding the the repo's narrowspec |
|
1279 | """matcher corresponding the the repo's narrowspec | |
1273 |
|
1280 | |||
1274 | If `match` is given, then that will be intersected with the narrow |
|
1281 | If `match` is given, then that will be intersected with the narrow | |
1275 | matcher. |
|
1282 | matcher. | |
1276 |
|
1283 | |||
1277 | If `includeexact` is True, then any exact matches from `match` will |
|
1284 | If `includeexact` is True, then any exact matches from `match` will | |
1278 | be included even if they're outside the narrowspec. |
|
1285 | be included even if they're outside the narrowspec. | |
1279 | """ |
|
1286 | """ | |
1280 | if match: |
|
1287 | if match: | |
1281 | if includeexact and not self._narrowmatch.always(): |
|
1288 | if includeexact and not self._narrowmatch.always(): | |
1282 | # do not exclude explicitly-specified paths so that they can |
|
1289 | # do not exclude explicitly-specified paths so that they can | |
1283 | # be warned later on |
|
1290 | # be warned later on | |
1284 | em = matchmod.exact(match.files()) |
|
1291 | em = matchmod.exact(match.files()) | |
1285 | nm = matchmod.unionmatcher([self._narrowmatch, em]) |
|
1292 | nm = matchmod.unionmatcher([self._narrowmatch, em]) | |
1286 | return matchmod.intersectmatchers(match, nm) |
|
1293 | return matchmod.intersectmatchers(match, nm) | |
1287 | return matchmod.intersectmatchers(match, self._narrowmatch) |
|
1294 | return matchmod.intersectmatchers(match, self._narrowmatch) | |
1288 | return self._narrowmatch |
|
1295 | return self._narrowmatch | |
1289 |
|
1296 | |||
1290 | def setnarrowpats(self, newincludes, newexcludes): |
|
1297 | def setnarrowpats(self, newincludes, newexcludes): | |
1291 | narrowspec.save(self, newincludes, newexcludes) |
|
1298 | narrowspec.save(self, newincludes, newexcludes) | |
1292 | self.invalidate(clearfilecache=True) |
|
1299 | self.invalidate(clearfilecache=True) | |
1293 |
|
1300 | |||
1294 | def __getitem__(self, changeid): |
|
1301 | def __getitem__(self, changeid): | |
1295 | if changeid is None: |
|
1302 | if changeid is None: | |
1296 | return context.workingctx(self) |
|
1303 | return context.workingctx(self) | |
1297 | if isinstance(changeid, context.basectx): |
|
1304 | if isinstance(changeid, context.basectx): | |
1298 | return changeid |
|
1305 | return changeid | |
1299 | if isinstance(changeid, slice): |
|
1306 | if isinstance(changeid, slice): | |
1300 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
1307 | # wdirrev isn't contiguous so the slice shouldn't include it | |
1301 | return [self[i] |
|
1308 | return [self[i] | |
1302 | for i in pycompat.xrange(*changeid.indices(len(self))) |
|
1309 | for i in pycompat.xrange(*changeid.indices(len(self))) | |
1303 | if i not in self.changelog.filteredrevs] |
|
1310 | if i not in self.changelog.filteredrevs] | |
1304 | try: |
|
1311 | try: | |
1305 | if isinstance(changeid, int): |
|
1312 | if isinstance(changeid, int): | |
1306 | node = self.changelog.node(changeid) |
|
1313 | node = self.changelog.node(changeid) | |
1307 | rev = changeid |
|
1314 | rev = changeid | |
1308 | elif changeid == 'null': |
|
1315 | elif changeid == 'null': | |
1309 | node = nullid |
|
1316 | node = nullid | |
1310 | rev = nullrev |
|
1317 | rev = nullrev | |
1311 | elif changeid == 'tip': |
|
1318 | elif changeid == 'tip': | |
1312 | node = self.changelog.tip() |
|
1319 | node = self.changelog.tip() | |
1313 | rev = self.changelog.rev(node) |
|
1320 | rev = self.changelog.rev(node) | |
1314 | elif changeid == '.': |
|
1321 | elif changeid == '.': | |
1315 | # this is a hack to delay/avoid loading obsmarkers |
|
1322 | # this is a hack to delay/avoid loading obsmarkers | |
1316 | # when we know that '.' won't be hidden |
|
1323 | # when we know that '.' won't be hidden | |
1317 | node = self.dirstate.p1() |
|
1324 | node = self.dirstate.p1() | |
1318 | rev = self.unfiltered().changelog.rev(node) |
|
1325 | rev = self.unfiltered().changelog.rev(node) | |
1319 | elif len(changeid) == 20: |
|
1326 | elif len(changeid) == 20: | |
1320 | try: |
|
1327 | try: | |
1321 | node = changeid |
|
1328 | node = changeid | |
1322 | rev = self.changelog.rev(changeid) |
|
1329 | rev = self.changelog.rev(changeid) | |
1323 | except error.FilteredLookupError: |
|
1330 | except error.FilteredLookupError: | |
1324 | changeid = hex(changeid) # for the error message |
|
1331 | changeid = hex(changeid) # for the error message | |
1325 | raise |
|
1332 | raise | |
1326 | except LookupError: |
|
1333 | except LookupError: | |
1327 | # check if it might have come from damaged dirstate |
|
1334 | # check if it might have come from damaged dirstate | |
1328 | # |
|
1335 | # | |
1329 | # XXX we could avoid the unfiltered if we had a recognizable |
|
1336 | # XXX we could avoid the unfiltered if we had a recognizable | |
1330 | # exception for filtered changeset access |
|
1337 | # exception for filtered changeset access | |
1331 | if (self.local() |
|
1338 | if (self.local() | |
1332 | and changeid in self.unfiltered().dirstate.parents()): |
|
1339 | and changeid in self.unfiltered().dirstate.parents()): | |
1333 | msg = _("working directory has unknown parent '%s'!") |
|
1340 | msg = _("working directory has unknown parent '%s'!") | |
1334 | raise error.Abort(msg % short(changeid)) |
|
1341 | raise error.Abort(msg % short(changeid)) | |
1335 | changeid = hex(changeid) # for the error message |
|
1342 | changeid = hex(changeid) # for the error message | |
1336 | raise |
|
1343 | raise | |
1337 |
|
1344 | |||
1338 | elif len(changeid) == 40: |
|
1345 | elif len(changeid) == 40: | |
1339 | node = bin(changeid) |
|
1346 | node = bin(changeid) | |
1340 | rev = self.changelog.rev(node) |
|
1347 | rev = self.changelog.rev(node) | |
1341 | else: |
|
1348 | else: | |
1342 | raise error.ProgrammingError( |
|
1349 | raise error.ProgrammingError( | |
1343 | "unsupported changeid '%s' of type %s" % |
|
1350 | "unsupported changeid '%s' of type %s" % | |
1344 | (changeid, type(changeid))) |
|
1351 | (changeid, type(changeid))) | |
1345 |
|
1352 | |||
1346 | return context.changectx(self, rev, node) |
|
1353 | return context.changectx(self, rev, node) | |
1347 |
|
1354 | |||
1348 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
1355 | except (error.FilteredIndexError, error.FilteredLookupError): | |
1349 | raise error.FilteredRepoLookupError(_("filtered revision '%s'") |
|
1356 | raise error.FilteredRepoLookupError(_("filtered revision '%s'") | |
1350 | % pycompat.bytestr(changeid)) |
|
1357 | % pycompat.bytestr(changeid)) | |
1351 | except (IndexError, LookupError): |
|
1358 | except (IndexError, LookupError): | |
1352 | raise error.RepoLookupError( |
|
1359 | raise error.RepoLookupError( | |
1353 | _("unknown revision '%s'") % pycompat.bytestr(changeid)) |
|
1360 | _("unknown revision '%s'") % pycompat.bytestr(changeid)) | |
1354 | except error.WdirUnsupported: |
|
1361 | except error.WdirUnsupported: | |
1355 | return context.workingctx(self) |
|
1362 | return context.workingctx(self) | |
1356 |
|
1363 | |||
1357 | def __contains__(self, changeid): |
|
1364 | def __contains__(self, changeid): | |
1358 | """True if the given changeid exists |
|
1365 | """True if the given changeid exists | |
1359 |
|
1366 | |||
1360 | error.AmbiguousPrefixLookupError is raised if an ambiguous node |
|
1367 | error.AmbiguousPrefixLookupError is raised if an ambiguous node | |
1361 | specified. |
|
1368 | specified. | |
1362 | """ |
|
1369 | """ | |
1363 | try: |
|
1370 | try: | |
1364 | self[changeid] |
|
1371 | self[changeid] | |
1365 | return True |
|
1372 | return True | |
1366 | except error.RepoLookupError: |
|
1373 | except error.RepoLookupError: | |
1367 | return False |
|
1374 | return False | |
1368 |
|
1375 | |||
1369 | def __nonzero__(self): |
|
1376 | def __nonzero__(self): | |
1370 | return True |
|
1377 | return True | |
1371 |
|
1378 | |||
1372 | __bool__ = __nonzero__ |
|
1379 | __bool__ = __nonzero__ | |
1373 |
|
1380 | |||
1374 | def __len__(self): |
|
1381 | def __len__(self): | |
1375 | # no need to pay the cost of repoview.changelog |
|
1382 | # no need to pay the cost of repoview.changelog | |
1376 | unfi = self.unfiltered() |
|
1383 | unfi = self.unfiltered() | |
1377 | return len(unfi.changelog) |
|
1384 | return len(unfi.changelog) | |
1378 |
|
1385 | |||
1379 | def __iter__(self): |
|
1386 | def __iter__(self): | |
1380 | return iter(self.changelog) |
|
1387 | return iter(self.changelog) | |
1381 |
|
1388 | |||
1382 | def revs(self, expr, *args): |
|
1389 | def revs(self, expr, *args): | |
1383 | '''Find revisions matching a revset. |
|
1390 | '''Find revisions matching a revset. | |
1384 |
|
1391 | |||
1385 | The revset is specified as a string ``expr`` that may contain |
|
1392 | The revset is specified as a string ``expr`` that may contain | |
1386 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
1393 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
1387 |
|
1394 | |||
1388 | Revset aliases from the configuration are not expanded. To expand |
|
1395 | Revset aliases from the configuration are not expanded. To expand | |
1389 | user aliases, consider calling ``scmutil.revrange()`` or |
|
1396 | user aliases, consider calling ``scmutil.revrange()`` or | |
1390 | ``repo.anyrevs([expr], user=True)``. |
|
1397 | ``repo.anyrevs([expr], user=True)``. | |
1391 |
|
1398 | |||
1392 | Returns a revset.abstractsmartset, which is a list-like interface |
|
1399 | Returns a revset.abstractsmartset, which is a list-like interface | |
1393 | that contains integer revisions. |
|
1400 | that contains integer revisions. | |
1394 | ''' |
|
1401 | ''' | |
1395 | tree = revsetlang.spectree(expr, *args) |
|
1402 | tree = revsetlang.spectree(expr, *args) | |
1396 | return revset.makematcher(tree)(self) |
|
1403 | return revset.makematcher(tree)(self) | |
1397 |
|
1404 | |||
1398 | def set(self, expr, *args): |
|
1405 | def set(self, expr, *args): | |
1399 | '''Find revisions matching a revset and emit changectx instances. |
|
1406 | '''Find revisions matching a revset and emit changectx instances. | |
1400 |
|
1407 | |||
1401 | This is a convenience wrapper around ``revs()`` that iterates the |
|
1408 | This is a convenience wrapper around ``revs()`` that iterates the | |
1402 | result and is a generator of changectx instances. |
|
1409 | result and is a generator of changectx instances. | |
1403 |
|
1410 | |||
1404 | Revset aliases from the configuration are not expanded. To expand |
|
1411 | Revset aliases from the configuration are not expanded. To expand | |
1405 | user aliases, consider calling ``scmutil.revrange()``. |
|
1412 | user aliases, consider calling ``scmutil.revrange()``. | |
1406 | ''' |
|
1413 | ''' | |
1407 | for r in self.revs(expr, *args): |
|
1414 | for r in self.revs(expr, *args): | |
1408 | yield self[r] |
|
1415 | yield self[r] | |
1409 |
|
1416 | |||
1410 | def anyrevs(self, specs, user=False, localalias=None): |
|
1417 | def anyrevs(self, specs, user=False, localalias=None): | |
1411 | '''Find revisions matching one of the given revsets. |
|
1418 | '''Find revisions matching one of the given revsets. | |
1412 |
|
1419 | |||
1413 | Revset aliases from the configuration are not expanded by default. To |
|
1420 | Revset aliases from the configuration are not expanded by default. To | |
1414 | expand user aliases, specify ``user=True``. To provide some local |
|
1421 | expand user aliases, specify ``user=True``. To provide some local | |
1415 | definitions overriding user aliases, set ``localalias`` to |
|
1422 | definitions overriding user aliases, set ``localalias`` to | |
1416 | ``{name: definitionstring}``. |
|
1423 | ``{name: definitionstring}``. | |
1417 | ''' |
|
1424 | ''' | |
1418 | if user: |
|
1425 | if user: | |
1419 | m = revset.matchany(self.ui, specs, |
|
1426 | m = revset.matchany(self.ui, specs, | |
1420 | lookup=revset.lookupfn(self), |
|
1427 | lookup=revset.lookupfn(self), | |
1421 | localalias=localalias) |
|
1428 | localalias=localalias) | |
1422 | else: |
|
1429 | else: | |
1423 | m = revset.matchany(None, specs, localalias=localalias) |
|
1430 | m = revset.matchany(None, specs, localalias=localalias) | |
1424 | return m(self) |
|
1431 | return m(self) | |
1425 |
|
1432 | |||
1426 | def url(self): |
|
1433 | def url(self): | |
1427 | return 'file:' + self.root |
|
1434 | return 'file:' + self.root | |
1428 |
|
1435 | |||
1429 | def hook(self, name, throw=False, **args): |
|
1436 | def hook(self, name, throw=False, **args): | |
1430 | """Call a hook, passing this repo instance. |
|
1437 | """Call a hook, passing this repo instance. | |
1431 |
|
1438 | |||
1432 | This a convenience method to aid invoking hooks. Extensions likely |
|
1439 | This a convenience method to aid invoking hooks. Extensions likely | |
1433 | won't call this unless they have registered a custom hook or are |
|
1440 | won't call this unless they have registered a custom hook or are | |
1434 | replacing code that is expected to call a hook. |
|
1441 | replacing code that is expected to call a hook. | |
1435 | """ |
|
1442 | """ | |
1436 | return hook.hook(self.ui, self, name, throw, **args) |
|
1443 | return hook.hook(self.ui, self, name, throw, **args) | |
1437 |
|
1444 | |||
1438 | @filteredpropertycache |
|
1445 | @filteredpropertycache | |
1439 | def _tagscache(self): |
|
1446 | def _tagscache(self): | |
1440 | '''Returns a tagscache object that contains various tags related |
|
1447 | '''Returns a tagscache object that contains various tags related | |
1441 | caches.''' |
|
1448 | caches.''' | |
1442 |
|
1449 | |||
1443 | # This simplifies its cache management by having one decorated |
|
1450 | # This simplifies its cache management by having one decorated | |
1444 | # function (this one) and the rest simply fetch things from it. |
|
1451 | # function (this one) and the rest simply fetch things from it. | |
1445 | class tagscache(object): |
|
1452 | class tagscache(object): | |
1446 | def __init__(self): |
|
1453 | def __init__(self): | |
1447 | # These two define the set of tags for this repository. tags |
|
1454 | # These two define the set of tags for this repository. tags | |
1448 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
1455 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
1449 | # 'local'. (Global tags are defined by .hgtags across all |
|
1456 | # 'local'. (Global tags are defined by .hgtags across all | |
1450 | # heads, and local tags are defined in .hg/localtags.) |
|
1457 | # heads, and local tags are defined in .hg/localtags.) | |
1451 | # They constitute the in-memory cache of tags. |
|
1458 | # They constitute the in-memory cache of tags. | |
1452 | self.tags = self.tagtypes = None |
|
1459 | self.tags = self.tagtypes = None | |
1453 |
|
1460 | |||
1454 | self.nodetagscache = self.tagslist = None |
|
1461 | self.nodetagscache = self.tagslist = None | |
1455 |
|
1462 | |||
1456 | cache = tagscache() |
|
1463 | cache = tagscache() | |
1457 | cache.tags, cache.tagtypes = self._findtags() |
|
1464 | cache.tags, cache.tagtypes = self._findtags() | |
1458 |
|
1465 | |||
1459 | return cache |
|
1466 | return cache | |
1460 |
|
1467 | |||
1461 | def tags(self): |
|
1468 | def tags(self): | |
1462 | '''return a mapping of tag to node''' |
|
1469 | '''return a mapping of tag to node''' | |
1463 | t = {} |
|
1470 | t = {} | |
1464 | if self.changelog.filteredrevs: |
|
1471 | if self.changelog.filteredrevs: | |
1465 | tags, tt = self._findtags() |
|
1472 | tags, tt = self._findtags() | |
1466 | else: |
|
1473 | else: | |
1467 | tags = self._tagscache.tags |
|
1474 | tags = self._tagscache.tags | |
1468 | rev = self.changelog.rev |
|
1475 | rev = self.changelog.rev | |
1469 | for k, v in tags.iteritems(): |
|
1476 | for k, v in tags.iteritems(): | |
1470 | try: |
|
1477 | try: | |
1471 | # ignore tags to unknown nodes |
|
1478 | # ignore tags to unknown nodes | |
1472 | rev(v) |
|
1479 | rev(v) | |
1473 | t[k] = v |
|
1480 | t[k] = v | |
1474 | except (error.LookupError, ValueError): |
|
1481 | except (error.LookupError, ValueError): | |
1475 | pass |
|
1482 | pass | |
1476 | return t |
|
1483 | return t | |
1477 |
|
1484 | |||
1478 | def _findtags(self): |
|
1485 | def _findtags(self): | |
1479 | '''Do the hard work of finding tags. Return a pair of dicts |
|
1486 | '''Do the hard work of finding tags. Return a pair of dicts | |
1480 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
1487 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
1481 | maps tag name to a string like \'global\' or \'local\'. |
|
1488 | maps tag name to a string like \'global\' or \'local\'. | |
1482 | Subclasses or extensions are free to add their own tags, but |
|
1489 | Subclasses or extensions are free to add their own tags, but | |
1483 | should be aware that the returned dicts will be retained for the |
|
1490 | should be aware that the returned dicts will be retained for the | |
1484 | duration of the localrepo object.''' |
|
1491 | duration of the localrepo object.''' | |
1485 |
|
1492 | |||
1486 | # XXX what tagtype should subclasses/extensions use? Currently |
|
1493 | # XXX what tagtype should subclasses/extensions use? Currently | |
1487 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
1494 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
1488 | # Should each extension invent its own tag type? Should there |
|
1495 | # Should each extension invent its own tag type? Should there | |
1489 | # be one tagtype for all such "virtual" tags? Or is the status |
|
1496 | # be one tagtype for all such "virtual" tags? Or is the status | |
1490 | # quo fine? |
|
1497 | # quo fine? | |
1491 |
|
1498 | |||
1492 |
|
1499 | |||
1493 | # map tag name to (node, hist) |
|
1500 | # map tag name to (node, hist) | |
1494 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
1501 | alltags = tagsmod.findglobaltags(self.ui, self) | |
1495 | # map tag name to tag type |
|
1502 | # map tag name to tag type | |
1496 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
1503 | tagtypes = dict((tag, 'global') for tag in alltags) | |
1497 |
|
1504 | |||
1498 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
1505 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
1499 |
|
1506 | |||
1500 | # Build the return dicts. Have to re-encode tag names because |
|
1507 | # Build the return dicts. Have to re-encode tag names because | |
1501 | # the tags module always uses UTF-8 (in order not to lose info |
|
1508 | # the tags module always uses UTF-8 (in order not to lose info | |
1502 | # writing to the cache), but the rest of Mercurial wants them in |
|
1509 | # writing to the cache), but the rest of Mercurial wants them in | |
1503 | # local encoding. |
|
1510 | # local encoding. | |
1504 | tags = {} |
|
1511 | tags = {} | |
1505 | for (name, (node, hist)) in alltags.iteritems(): |
|
1512 | for (name, (node, hist)) in alltags.iteritems(): | |
1506 | if node != nullid: |
|
1513 | if node != nullid: | |
1507 | tags[encoding.tolocal(name)] = node |
|
1514 | tags[encoding.tolocal(name)] = node | |
1508 | tags['tip'] = self.changelog.tip() |
|
1515 | tags['tip'] = self.changelog.tip() | |
1509 | tagtypes = dict([(encoding.tolocal(name), value) |
|
1516 | tagtypes = dict([(encoding.tolocal(name), value) | |
1510 | for (name, value) in tagtypes.iteritems()]) |
|
1517 | for (name, value) in tagtypes.iteritems()]) | |
1511 | return (tags, tagtypes) |
|
1518 | return (tags, tagtypes) | |
1512 |
|
1519 | |||
1513 | def tagtype(self, tagname): |
|
1520 | def tagtype(self, tagname): | |
1514 | ''' |
|
1521 | ''' | |
1515 | return the type of the given tag. result can be: |
|
1522 | return the type of the given tag. result can be: | |
1516 |
|
1523 | |||
1517 | 'local' : a local tag |
|
1524 | 'local' : a local tag | |
1518 | 'global' : a global tag |
|
1525 | 'global' : a global tag | |
1519 | None : tag does not exist |
|
1526 | None : tag does not exist | |
1520 | ''' |
|
1527 | ''' | |
1521 |
|
1528 | |||
1522 | return self._tagscache.tagtypes.get(tagname) |
|
1529 | return self._tagscache.tagtypes.get(tagname) | |
1523 |
|
1530 | |||
1524 | def tagslist(self): |
|
1531 | def tagslist(self): | |
1525 | '''return a list of tags ordered by revision''' |
|
1532 | '''return a list of tags ordered by revision''' | |
1526 | if not self._tagscache.tagslist: |
|
1533 | if not self._tagscache.tagslist: | |
1527 | l = [] |
|
1534 | l = [] | |
1528 | for t, n in self.tags().iteritems(): |
|
1535 | for t, n in self.tags().iteritems(): | |
1529 | l.append((self.changelog.rev(n), t, n)) |
|
1536 | l.append((self.changelog.rev(n), t, n)) | |
1530 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
1537 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
1531 |
|
1538 | |||
1532 | return self._tagscache.tagslist |
|
1539 | return self._tagscache.tagslist | |
1533 |
|
1540 | |||
1534 | def nodetags(self, node): |
|
1541 | def nodetags(self, node): | |
1535 | '''return the tags associated with a node''' |
|
1542 | '''return the tags associated with a node''' | |
1536 | if not self._tagscache.nodetagscache: |
|
1543 | if not self._tagscache.nodetagscache: | |
1537 | nodetagscache = {} |
|
1544 | nodetagscache = {} | |
1538 | for t, n in self._tagscache.tags.iteritems(): |
|
1545 | for t, n in self._tagscache.tags.iteritems(): | |
1539 | nodetagscache.setdefault(n, []).append(t) |
|
1546 | nodetagscache.setdefault(n, []).append(t) | |
1540 | for tags in nodetagscache.itervalues(): |
|
1547 | for tags in nodetagscache.itervalues(): | |
1541 | tags.sort() |
|
1548 | tags.sort() | |
1542 | self._tagscache.nodetagscache = nodetagscache |
|
1549 | self._tagscache.nodetagscache = nodetagscache | |
1543 | return self._tagscache.nodetagscache.get(node, []) |
|
1550 | return self._tagscache.nodetagscache.get(node, []) | |
1544 |
|
1551 | |||
1545 | def nodebookmarks(self, node): |
|
1552 | def nodebookmarks(self, node): | |
1546 | """return the list of bookmarks pointing to the specified node""" |
|
1553 | """return the list of bookmarks pointing to the specified node""" | |
1547 | return self._bookmarks.names(node) |
|
1554 | return self._bookmarks.names(node) | |
1548 |
|
1555 | |||
1549 | def branchmap(self): |
|
1556 | def branchmap(self): | |
1550 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
1557 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
1551 | ordered by increasing revision number''' |
|
1558 | ordered by increasing revision number''' | |
1552 | return self._branchcaches[self] |
|
1559 | return self._branchcaches[self] | |
1553 |
|
1560 | |||
1554 | @unfilteredmethod |
|
1561 | @unfilteredmethod | |
1555 | def revbranchcache(self): |
|
1562 | def revbranchcache(self): | |
1556 | if not self._revbranchcache: |
|
1563 | if not self._revbranchcache: | |
1557 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
1564 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
1558 | return self._revbranchcache |
|
1565 | return self._revbranchcache | |
1559 |
|
1566 | |||
1560 | def branchtip(self, branch, ignoremissing=False): |
|
1567 | def branchtip(self, branch, ignoremissing=False): | |
1561 | '''return the tip node for a given branch |
|
1568 | '''return the tip node for a given branch | |
1562 |
|
1569 | |||
1563 | If ignoremissing is True, then this method will not raise an error. |
|
1570 | If ignoremissing is True, then this method will not raise an error. | |
1564 | This is helpful for callers that only expect None for a missing branch |
|
1571 | This is helpful for callers that only expect None for a missing branch | |
1565 | (e.g. namespace). |
|
1572 | (e.g. namespace). | |
1566 |
|
1573 | |||
1567 | ''' |
|
1574 | ''' | |
1568 | try: |
|
1575 | try: | |
1569 | return self.branchmap().branchtip(branch) |
|
1576 | return self.branchmap().branchtip(branch) | |
1570 | except KeyError: |
|
1577 | except KeyError: | |
1571 | if not ignoremissing: |
|
1578 | if not ignoremissing: | |
1572 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
1579 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
1573 | else: |
|
1580 | else: | |
1574 | pass |
|
1581 | pass | |
1575 |
|
1582 | |||
1576 | def lookup(self, key): |
|
1583 | def lookup(self, key): | |
1577 | node = scmutil.revsymbol(self, key).node() |
|
1584 | node = scmutil.revsymbol(self, key).node() | |
1578 | if node is None: |
|
1585 | if node is None: | |
1579 | raise error.RepoLookupError(_("unknown revision '%s'") % key) |
|
1586 | raise error.RepoLookupError(_("unknown revision '%s'") % key) | |
1580 | return node |
|
1587 | return node | |
1581 |
|
1588 | |||
1582 | def lookupbranch(self, key): |
|
1589 | def lookupbranch(self, key): | |
1583 | if self.branchmap().hasbranch(key): |
|
1590 | if self.branchmap().hasbranch(key): | |
1584 | return key |
|
1591 | return key | |
1585 |
|
1592 | |||
1586 | return scmutil.revsymbol(self, key).branch() |
|
1593 | return scmutil.revsymbol(self, key).branch() | |
1587 |
|
1594 | |||
1588 | def known(self, nodes): |
|
1595 | def known(self, nodes): | |
1589 | cl = self.changelog |
|
1596 | cl = self.changelog | |
1590 | nm = cl.nodemap |
|
1597 | nm = cl.nodemap | |
1591 | filtered = cl.filteredrevs |
|
1598 | filtered = cl.filteredrevs | |
1592 | result = [] |
|
1599 | result = [] | |
1593 | for n in nodes: |
|
1600 | for n in nodes: | |
1594 | r = nm.get(n) |
|
1601 | r = nm.get(n) | |
1595 | resp = not (r is None or r in filtered) |
|
1602 | resp = not (r is None or r in filtered) | |
1596 | result.append(resp) |
|
1603 | result.append(resp) | |
1597 | return result |
|
1604 | return result | |
1598 |
|
1605 | |||
1599 | def local(self): |
|
1606 | def local(self): | |
1600 | return self |
|
1607 | return self | |
1601 |
|
1608 | |||
1602 | def publishing(self): |
|
1609 | def publishing(self): | |
1603 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1610 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1604 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1611 | # so that we don't finalize changes shared between users via ssh or nfs | |
1605 | return self.ui.configbool('phases', 'publish', untrusted=True) |
|
1612 | return self.ui.configbool('phases', 'publish', untrusted=True) | |
1606 |
|
1613 | |||
1607 | def cancopy(self): |
|
1614 | def cancopy(self): | |
1608 | # so statichttprepo's override of local() works |
|
1615 | # so statichttprepo's override of local() works | |
1609 | if not self.local(): |
|
1616 | if not self.local(): | |
1610 | return False |
|
1617 | return False | |
1611 | if not self.publishing(): |
|
1618 | if not self.publishing(): | |
1612 | return True |
|
1619 | return True | |
1613 | # if publishing we can't copy if there is filtered content |
|
1620 | # if publishing we can't copy if there is filtered content | |
1614 | return not self.filtered('visible').changelog.filteredrevs |
|
1621 | return not self.filtered('visible').changelog.filteredrevs | |
1615 |
|
1622 | |||
1616 | def shared(self): |
|
1623 | def shared(self): | |
1617 | '''the type of shared repository (None if not shared)''' |
|
1624 | '''the type of shared repository (None if not shared)''' | |
1618 | if self.sharedpath != self.path: |
|
1625 | if self.sharedpath != self.path: | |
1619 | return 'store' |
|
1626 | return 'store' | |
1620 | return None |
|
1627 | return None | |
1621 |
|
1628 | |||
1622 | def wjoin(self, f, *insidef): |
|
1629 | def wjoin(self, f, *insidef): | |
1623 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1630 | return self.vfs.reljoin(self.root, f, *insidef) | |
1624 |
|
1631 | |||
1625 | def setparents(self, p1, p2=nullid): |
|
1632 | def setparents(self, p1, p2=nullid): | |
1626 | with self.dirstate.parentchange(): |
|
1633 | with self.dirstate.parentchange(): | |
1627 | copies = self.dirstate.setparents(p1, p2) |
|
1634 | copies = self.dirstate.setparents(p1, p2) | |
1628 | pctx = self[p1] |
|
1635 | pctx = self[p1] | |
1629 | if copies: |
|
1636 | if copies: | |
1630 | # Adjust copy records, the dirstate cannot do it, it |
|
1637 | # Adjust copy records, the dirstate cannot do it, it | |
1631 | # requires access to parents manifests. Preserve them |
|
1638 | # requires access to parents manifests. Preserve them | |
1632 | # only for entries added to first parent. |
|
1639 | # only for entries added to first parent. | |
1633 | for f in copies: |
|
1640 | for f in copies: | |
1634 | if f not in pctx and copies[f] in pctx: |
|
1641 | if f not in pctx and copies[f] in pctx: | |
1635 | self.dirstate.copy(copies[f], f) |
|
1642 | self.dirstate.copy(copies[f], f) | |
1636 | if p2 == nullid: |
|
1643 | if p2 == nullid: | |
1637 | for f, s in sorted(self.dirstate.copies().items()): |
|
1644 | for f, s in sorted(self.dirstate.copies().items()): | |
1638 | if f not in pctx and s not in pctx: |
|
1645 | if f not in pctx and s not in pctx: | |
1639 | self.dirstate.copy(None, f) |
|
1646 | self.dirstate.copy(None, f) | |
1640 |
|
1647 | |||
1641 | def filectx(self, path, changeid=None, fileid=None, changectx=None): |
|
1648 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
1642 | """changeid must be a changeset revision, if specified. |
|
1649 | """changeid must be a changeset revision, if specified. | |
1643 | fileid can be a file revision or node.""" |
|
1650 | fileid can be a file revision or node.""" | |
1644 | return context.filectx(self, path, changeid, fileid, |
|
1651 | return context.filectx(self, path, changeid, fileid, | |
1645 | changectx=changectx) |
|
1652 | changectx=changectx) | |
1646 |
|
1653 | |||
1647 | def getcwd(self): |
|
1654 | def getcwd(self): | |
1648 | return self.dirstate.getcwd() |
|
1655 | return self.dirstate.getcwd() | |
1649 |
|
1656 | |||
1650 | def pathto(self, f, cwd=None): |
|
1657 | def pathto(self, f, cwd=None): | |
1651 | return self.dirstate.pathto(f, cwd) |
|
1658 | return self.dirstate.pathto(f, cwd) | |
1652 |
|
1659 | |||
1653 | def _loadfilter(self, filter): |
|
1660 | def _loadfilter(self, filter): | |
1654 | if filter not in self._filterpats: |
|
1661 | if filter not in self._filterpats: | |
1655 | l = [] |
|
1662 | l = [] | |
1656 | for pat, cmd in self.ui.configitems(filter): |
|
1663 | for pat, cmd in self.ui.configitems(filter): | |
1657 | if cmd == '!': |
|
1664 | if cmd == '!': | |
1658 | continue |
|
1665 | continue | |
1659 | mf = matchmod.match(self.root, '', [pat]) |
|
1666 | mf = matchmod.match(self.root, '', [pat]) | |
1660 | fn = None |
|
1667 | fn = None | |
1661 | params = cmd |
|
1668 | params = cmd | |
1662 | for name, filterfn in self._datafilters.iteritems(): |
|
1669 | for name, filterfn in self._datafilters.iteritems(): | |
1663 | if cmd.startswith(name): |
|
1670 | if cmd.startswith(name): | |
1664 | fn = filterfn |
|
1671 | fn = filterfn | |
1665 | params = cmd[len(name):].lstrip() |
|
1672 | params = cmd[len(name):].lstrip() | |
1666 | break |
|
1673 | break | |
1667 | if not fn: |
|
1674 | if not fn: | |
1668 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1675 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1669 | # Wrap old filters not supporting keyword arguments |
|
1676 | # Wrap old filters not supporting keyword arguments | |
1670 | if not pycompat.getargspec(fn)[2]: |
|
1677 | if not pycompat.getargspec(fn)[2]: | |
1671 | oldfn = fn |
|
1678 | oldfn = fn | |
1672 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
1679 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
1673 | l.append((mf, fn, params)) |
|
1680 | l.append((mf, fn, params)) | |
1674 | self._filterpats[filter] = l |
|
1681 | self._filterpats[filter] = l | |
1675 | return self._filterpats[filter] |
|
1682 | return self._filterpats[filter] | |
1676 |
|
1683 | |||
1677 | def _filter(self, filterpats, filename, data): |
|
1684 | def _filter(self, filterpats, filename, data): | |
1678 | for mf, fn, cmd in filterpats: |
|
1685 | for mf, fn, cmd in filterpats: | |
1679 | if mf(filename): |
|
1686 | if mf(filename): | |
1680 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
1687 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
1681 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1688 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1682 | break |
|
1689 | break | |
1683 |
|
1690 | |||
1684 | return data |
|
1691 | return data | |
1685 |
|
1692 | |||
1686 | @unfilteredpropertycache |
|
1693 | @unfilteredpropertycache | |
1687 | def _encodefilterpats(self): |
|
1694 | def _encodefilterpats(self): | |
1688 | return self._loadfilter('encode') |
|
1695 | return self._loadfilter('encode') | |
1689 |
|
1696 | |||
1690 | @unfilteredpropertycache |
|
1697 | @unfilteredpropertycache | |
1691 | def _decodefilterpats(self): |
|
1698 | def _decodefilterpats(self): | |
1692 | return self._loadfilter('decode') |
|
1699 | return self._loadfilter('decode') | |
1693 |
|
1700 | |||
1694 | def adddatafilter(self, name, filter): |
|
1701 | def adddatafilter(self, name, filter): | |
1695 | self._datafilters[name] = filter |
|
1702 | self._datafilters[name] = filter | |
1696 |
|
1703 | |||
1697 | def wread(self, filename): |
|
1704 | def wread(self, filename): | |
1698 | if self.wvfs.islink(filename): |
|
1705 | if self.wvfs.islink(filename): | |
1699 | data = self.wvfs.readlink(filename) |
|
1706 | data = self.wvfs.readlink(filename) | |
1700 | else: |
|
1707 | else: | |
1701 | data = self.wvfs.read(filename) |
|
1708 | data = self.wvfs.read(filename) | |
1702 | return self._filter(self._encodefilterpats, filename, data) |
|
1709 | return self._filter(self._encodefilterpats, filename, data) | |
1703 |
|
1710 | |||
1704 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
1711 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
1705 | """write ``data`` into ``filename`` in the working directory |
|
1712 | """write ``data`` into ``filename`` in the working directory | |
1706 |
|
1713 | |||
1707 | This returns length of written (maybe decoded) data. |
|
1714 | This returns length of written (maybe decoded) data. | |
1708 | """ |
|
1715 | """ | |
1709 | data = self._filter(self._decodefilterpats, filename, data) |
|
1716 | data = self._filter(self._decodefilterpats, filename, data) | |
1710 | if 'l' in flags: |
|
1717 | if 'l' in flags: | |
1711 | self.wvfs.symlink(data, filename) |
|
1718 | self.wvfs.symlink(data, filename) | |
1712 | else: |
|
1719 | else: | |
1713 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, |
|
1720 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, | |
1714 | **kwargs) |
|
1721 | **kwargs) | |
1715 | if 'x' in flags: |
|
1722 | if 'x' in flags: | |
1716 | self.wvfs.setflags(filename, False, True) |
|
1723 | self.wvfs.setflags(filename, False, True) | |
1717 | else: |
|
1724 | else: | |
1718 | self.wvfs.setflags(filename, False, False) |
|
1725 | self.wvfs.setflags(filename, False, False) | |
1719 | return len(data) |
|
1726 | return len(data) | |
1720 |
|
1727 | |||
1721 | def wwritedata(self, filename, data): |
|
1728 | def wwritedata(self, filename, data): | |
1722 | return self._filter(self._decodefilterpats, filename, data) |
|
1729 | return self._filter(self._decodefilterpats, filename, data) | |
1723 |
|
1730 | |||
1724 | def currenttransaction(self): |
|
1731 | def currenttransaction(self): | |
1725 | """return the current transaction or None if non exists""" |
|
1732 | """return the current transaction or None if non exists""" | |
1726 | if self._transref: |
|
1733 | if self._transref: | |
1727 | tr = self._transref() |
|
1734 | tr = self._transref() | |
1728 | else: |
|
1735 | else: | |
1729 | tr = None |
|
1736 | tr = None | |
1730 |
|
1737 | |||
1731 | if tr and tr.running(): |
|
1738 | if tr and tr.running(): | |
1732 | return tr |
|
1739 | return tr | |
1733 | return None |
|
1740 | return None | |
1734 |
|
1741 | |||
1735 | def transaction(self, desc, report=None): |
|
1742 | def transaction(self, desc, report=None): | |
1736 | if (self.ui.configbool('devel', 'all-warnings') |
|
1743 | if (self.ui.configbool('devel', 'all-warnings') | |
1737 | or self.ui.configbool('devel', 'check-locks')): |
|
1744 | or self.ui.configbool('devel', 'check-locks')): | |
1738 | if self._currentlock(self._lockref) is None: |
|
1745 | if self._currentlock(self._lockref) is None: | |
1739 | raise error.ProgrammingError('transaction requires locking') |
|
1746 | raise error.ProgrammingError('transaction requires locking') | |
1740 | tr = self.currenttransaction() |
|
1747 | tr = self.currenttransaction() | |
1741 | if tr is not None: |
|
1748 | if tr is not None: | |
1742 | return tr.nest(name=desc) |
|
1749 | return tr.nest(name=desc) | |
1743 |
|
1750 | |||
1744 | # abort here if the journal already exists |
|
1751 | # abort here if the journal already exists | |
1745 | if self.svfs.exists("journal"): |
|
1752 | if self.svfs.exists("journal"): | |
1746 | raise error.RepoError( |
|
1753 | raise error.RepoError( | |
1747 | _("abandoned transaction found"), |
|
1754 | _("abandoned transaction found"), | |
1748 | hint=_("run 'hg recover' to clean up transaction")) |
|
1755 | hint=_("run 'hg recover' to clean up transaction")) | |
1749 |
|
1756 | |||
1750 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
1757 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
1751 | ha = hex(hashlib.sha1(idbase).digest()) |
|
1758 | ha = hex(hashlib.sha1(idbase).digest()) | |
1752 | txnid = 'TXN:' + ha |
|
1759 | txnid = 'TXN:' + ha | |
1753 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
1760 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
1754 |
|
1761 | |||
1755 | self._writejournal(desc) |
|
1762 | self._writejournal(desc) | |
1756 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
1763 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
1757 | if report: |
|
1764 | if report: | |
1758 | rp = report |
|
1765 | rp = report | |
1759 | else: |
|
1766 | else: | |
1760 | rp = self.ui.warn |
|
1767 | rp = self.ui.warn | |
1761 | vfsmap = {'plain': self.vfs, 'store': self.svfs} # root of .hg/ |
|
1768 | vfsmap = {'plain': self.vfs, 'store': self.svfs} # root of .hg/ | |
1762 | # we must avoid cyclic reference between repo and transaction. |
|
1769 | # we must avoid cyclic reference between repo and transaction. | |
1763 | reporef = weakref.ref(self) |
|
1770 | reporef = weakref.ref(self) | |
1764 | # Code to track tag movement |
|
1771 | # Code to track tag movement | |
1765 | # |
|
1772 | # | |
1766 | # Since tags are all handled as file content, it is actually quite hard |
|
1773 | # Since tags are all handled as file content, it is actually quite hard | |
1767 | # to track these movement from a code perspective. So we fallback to a |
|
1774 | # to track these movement from a code perspective. So we fallback to a | |
1768 | # tracking at the repository level. One could envision to track changes |
|
1775 | # tracking at the repository level. One could envision to track changes | |
1769 | # to the '.hgtags' file through changegroup apply but that fails to |
|
1776 | # to the '.hgtags' file through changegroup apply but that fails to | |
1770 | # cope with case where transaction expose new heads without changegroup |
|
1777 | # cope with case where transaction expose new heads without changegroup | |
1771 | # being involved (eg: phase movement). |
|
1778 | # being involved (eg: phase movement). | |
1772 | # |
|
1779 | # | |
1773 | # For now, We gate the feature behind a flag since this likely comes |
|
1780 | # For now, We gate the feature behind a flag since this likely comes | |
1774 | # with performance impacts. The current code run more often than needed |
|
1781 | # with performance impacts. The current code run more often than needed | |
1775 | # and do not use caches as much as it could. The current focus is on |
|
1782 | # and do not use caches as much as it could. The current focus is on | |
1776 | # the behavior of the feature so we disable it by default. The flag |
|
1783 | # the behavior of the feature so we disable it by default. The flag | |
1777 | # will be removed when we are happy with the performance impact. |
|
1784 | # will be removed when we are happy with the performance impact. | |
1778 | # |
|
1785 | # | |
1779 | # Once this feature is no longer experimental move the following |
|
1786 | # Once this feature is no longer experimental move the following | |
1780 | # documentation to the appropriate help section: |
|
1787 | # documentation to the appropriate help section: | |
1781 | # |
|
1788 | # | |
1782 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
1789 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
1783 | # tags (new or changed or deleted tags). In addition the details of |
|
1790 | # tags (new or changed or deleted tags). In addition the details of | |
1784 | # these changes are made available in a file at: |
|
1791 | # these changes are made available in a file at: | |
1785 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
1792 | # ``REPOROOT/.hg/changes/tags.changes``. | |
1786 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
1793 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
1787 | # might exist from a previous transaction even if no tag were touched |
|
1794 | # might exist from a previous transaction even if no tag were touched | |
1788 | # in this one. Changes are recorded in a line base format:: |
|
1795 | # in this one. Changes are recorded in a line base format:: | |
1789 | # |
|
1796 | # | |
1790 | # <action> <hex-node> <tag-name>\n |
|
1797 | # <action> <hex-node> <tag-name>\n | |
1791 | # |
|
1798 | # | |
1792 | # Actions are defined as follow: |
|
1799 | # Actions are defined as follow: | |
1793 | # "-R": tag is removed, |
|
1800 | # "-R": tag is removed, | |
1794 | # "+A": tag is added, |
|
1801 | # "+A": tag is added, | |
1795 | # "-M": tag is moved (old value), |
|
1802 | # "-M": tag is moved (old value), | |
1796 | # "+M": tag is moved (new value), |
|
1803 | # "+M": tag is moved (new value), | |
1797 | tracktags = lambda x: None |
|
1804 | tracktags = lambda x: None | |
1798 | # experimental config: experimental.hook-track-tags |
|
1805 | # experimental config: experimental.hook-track-tags | |
1799 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') |
|
1806 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') | |
1800 | if desc != 'strip' and shouldtracktags: |
|
1807 | if desc != 'strip' and shouldtracktags: | |
1801 | oldheads = self.changelog.headrevs() |
|
1808 | oldheads = self.changelog.headrevs() | |
1802 | def tracktags(tr2): |
|
1809 | def tracktags(tr2): | |
1803 | repo = reporef() |
|
1810 | repo = reporef() | |
1804 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1811 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
1805 | newheads = repo.changelog.headrevs() |
|
1812 | newheads = repo.changelog.headrevs() | |
1806 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1813 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
1807 | # notes: we compare lists here. |
|
1814 | # notes: we compare lists here. | |
1808 | # As we do it only once buiding set would not be cheaper |
|
1815 | # As we do it only once buiding set would not be cheaper | |
1809 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1816 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
1810 | if changes: |
|
1817 | if changes: | |
1811 | tr2.hookargs['tag_moved'] = '1' |
|
1818 | tr2.hookargs['tag_moved'] = '1' | |
1812 | with repo.vfs('changes/tags.changes', 'w', |
|
1819 | with repo.vfs('changes/tags.changes', 'w', | |
1813 | atomictemp=True) as changesfile: |
|
1820 | atomictemp=True) as changesfile: | |
1814 | # note: we do not register the file to the transaction |
|
1821 | # note: we do not register the file to the transaction | |
1815 | # because we needs it to still exist on the transaction |
|
1822 | # because we needs it to still exist on the transaction | |
1816 | # is close (for txnclose hooks) |
|
1823 | # is close (for txnclose hooks) | |
1817 | tagsmod.writediff(changesfile, changes) |
|
1824 | tagsmod.writediff(changesfile, changes) | |
1818 | def validate(tr2): |
|
1825 | def validate(tr2): | |
1819 | """will run pre-closing hooks""" |
|
1826 | """will run pre-closing hooks""" | |
1820 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1827 | # XXX the transaction API is a bit lacking here so we take a hacky | |
1821 | # path for now |
|
1828 | # path for now | |
1822 | # |
|
1829 | # | |
1823 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1830 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
1824 | # dict is copied before these run. In addition we needs the data |
|
1831 | # dict is copied before these run. In addition we needs the data | |
1825 | # available to in memory hooks too. |
|
1832 | # available to in memory hooks too. | |
1826 | # |
|
1833 | # | |
1827 | # Moreover, we also need to make sure this runs before txnclose |
|
1834 | # Moreover, we also need to make sure this runs before txnclose | |
1828 | # hooks and there is no "pending" mechanism that would execute |
|
1835 | # hooks and there is no "pending" mechanism that would execute | |
1829 | # logic only if hooks are about to run. |
|
1836 | # logic only if hooks are about to run. | |
1830 | # |
|
1837 | # | |
1831 | # Fixing this limitation of the transaction is also needed to track |
|
1838 | # Fixing this limitation of the transaction is also needed to track | |
1832 | # other families of changes (bookmarks, phases, obsolescence). |
|
1839 | # other families of changes (bookmarks, phases, obsolescence). | |
1833 | # |
|
1840 | # | |
1834 | # This will have to be fixed before we remove the experimental |
|
1841 | # This will have to be fixed before we remove the experimental | |
1835 | # gating. |
|
1842 | # gating. | |
1836 | tracktags(tr2) |
|
1843 | tracktags(tr2) | |
1837 | repo = reporef() |
|
1844 | repo = reporef() | |
1838 | if repo.ui.configbool('experimental', 'single-head-per-branch'): |
|
1845 | if repo.ui.configbool('experimental', 'single-head-per-branch'): | |
1839 | scmutil.enforcesinglehead(repo, tr2, desc) |
|
1846 | scmutil.enforcesinglehead(repo, tr2, desc) | |
1840 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): |
|
1847 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): | |
1841 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): |
|
1848 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): | |
1842 | args = tr.hookargs.copy() |
|
1849 | args = tr.hookargs.copy() | |
1843 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1850 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1844 | repo.hook('pretxnclose-bookmark', throw=True, |
|
1851 | repo.hook('pretxnclose-bookmark', throw=True, | |
1845 | **pycompat.strkwargs(args)) |
|
1852 | **pycompat.strkwargs(args)) | |
1846 | if hook.hashook(repo.ui, 'pretxnclose-phase'): |
|
1853 | if hook.hashook(repo.ui, 'pretxnclose-phase'): | |
1847 | cl = repo.unfiltered().changelog |
|
1854 | cl = repo.unfiltered().changelog | |
1848 | for rev, (old, new) in tr.changes['phases'].items(): |
|
1855 | for rev, (old, new) in tr.changes['phases'].items(): | |
1849 | args = tr.hookargs.copy() |
|
1856 | args = tr.hookargs.copy() | |
1850 | node = hex(cl.node(rev)) |
|
1857 | node = hex(cl.node(rev)) | |
1851 | args.update(phases.preparehookargs(node, old, new)) |
|
1858 | args.update(phases.preparehookargs(node, old, new)) | |
1852 | repo.hook('pretxnclose-phase', throw=True, |
|
1859 | repo.hook('pretxnclose-phase', throw=True, | |
1853 | **pycompat.strkwargs(args)) |
|
1860 | **pycompat.strkwargs(args)) | |
1854 |
|
1861 | |||
1855 | repo.hook('pretxnclose', throw=True, |
|
1862 | repo.hook('pretxnclose', throw=True, | |
1856 | **pycompat.strkwargs(tr.hookargs)) |
|
1863 | **pycompat.strkwargs(tr.hookargs)) | |
1857 | def releasefn(tr, success): |
|
1864 | def releasefn(tr, success): | |
1858 | repo = reporef() |
|
1865 | repo = reporef() | |
1859 | if success: |
|
1866 | if success: | |
1860 | # this should be explicitly invoked here, because |
|
1867 | # this should be explicitly invoked here, because | |
1861 | # in-memory changes aren't written out at closing |
|
1868 | # in-memory changes aren't written out at closing | |
1862 | # transaction, if tr.addfilegenerator (via |
|
1869 | # transaction, if tr.addfilegenerator (via | |
1863 | # dirstate.write or so) isn't invoked while |
|
1870 | # dirstate.write or so) isn't invoked while | |
1864 | # transaction running |
|
1871 | # transaction running | |
1865 | repo.dirstate.write(None) |
|
1872 | repo.dirstate.write(None) | |
1866 | else: |
|
1873 | else: | |
1867 | # discard all changes (including ones already written |
|
1874 | # discard all changes (including ones already written | |
1868 | # out) in this transaction |
|
1875 | # out) in this transaction | |
1869 | narrowspec.restorebackup(self, 'journal.narrowspec') |
|
1876 | narrowspec.restorebackup(self, 'journal.narrowspec') | |
1870 | narrowspec.restorewcbackup(self, 'journal.narrowspec.dirstate') |
|
1877 | narrowspec.restorewcbackup(self, 'journal.narrowspec.dirstate') | |
1871 | repo.dirstate.restorebackup(None, 'journal.dirstate') |
|
1878 | repo.dirstate.restorebackup(None, 'journal.dirstate') | |
1872 |
|
1879 | |||
1873 | repo.invalidate(clearfilecache=True) |
|
1880 | repo.invalidate(clearfilecache=True) | |
1874 |
|
1881 | |||
1875 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1882 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1876 | "journal", |
|
1883 | "journal", | |
1877 | "undo", |
|
1884 | "undo", | |
1878 | aftertrans(renames), |
|
1885 | aftertrans(renames), | |
1879 | self.store.createmode, |
|
1886 | self.store.createmode, | |
1880 | validator=validate, |
|
1887 | validator=validate, | |
1881 | releasefn=releasefn, |
|
1888 | releasefn=releasefn, | |
1882 | checkambigfiles=_cachedfiles, |
|
1889 | checkambigfiles=_cachedfiles, | |
1883 | name=desc) |
|
1890 | name=desc) | |
1884 | tr.changes['origrepolen'] = len(self) |
|
1891 | tr.changes['origrepolen'] = len(self) | |
1885 | tr.changes['obsmarkers'] = set() |
|
1892 | tr.changes['obsmarkers'] = set() | |
1886 | tr.changes['phases'] = {} |
|
1893 | tr.changes['phases'] = {} | |
1887 | tr.changes['bookmarks'] = {} |
|
1894 | tr.changes['bookmarks'] = {} | |
1888 |
|
1895 | |||
1889 | tr.hookargs['txnid'] = txnid |
|
1896 | tr.hookargs['txnid'] = txnid | |
1890 | tr.hookargs['txnname'] = desc |
|
1897 | tr.hookargs['txnname'] = desc | |
1891 | # note: writing the fncache only during finalize mean that the file is |
|
1898 | # note: writing the fncache only during finalize mean that the file is | |
1892 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1899 | # outdated when running hooks. As fncache is used for streaming clone, | |
1893 | # this is not expected to break anything that happen during the hooks. |
|
1900 | # this is not expected to break anything that happen during the hooks. | |
1894 | tr.addfinalize('flush-fncache', self.store.write) |
|
1901 | tr.addfinalize('flush-fncache', self.store.write) | |
1895 | def txnclosehook(tr2): |
|
1902 | def txnclosehook(tr2): | |
1896 | """To be run if transaction is successful, will schedule a hook run |
|
1903 | """To be run if transaction is successful, will schedule a hook run | |
1897 | """ |
|
1904 | """ | |
1898 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1905 | # Don't reference tr2 in hook() so we don't hold a reference. | |
1899 | # This reduces memory consumption when there are multiple |
|
1906 | # This reduces memory consumption when there are multiple | |
1900 | # transactions per lock. This can likely go away if issue5045 |
|
1907 | # transactions per lock. This can likely go away if issue5045 | |
1901 | # fixes the function accumulation. |
|
1908 | # fixes the function accumulation. | |
1902 | hookargs = tr2.hookargs |
|
1909 | hookargs = tr2.hookargs | |
1903 |
|
1910 | |||
1904 | def hookfunc(): |
|
1911 | def hookfunc(): | |
1905 | repo = reporef() |
|
1912 | repo = reporef() | |
1906 | if hook.hashook(repo.ui, 'txnclose-bookmark'): |
|
1913 | if hook.hashook(repo.ui, 'txnclose-bookmark'): | |
1907 | bmchanges = sorted(tr.changes['bookmarks'].items()) |
|
1914 | bmchanges = sorted(tr.changes['bookmarks'].items()) | |
1908 | for name, (old, new) in bmchanges: |
|
1915 | for name, (old, new) in bmchanges: | |
1909 | args = tr.hookargs.copy() |
|
1916 | args = tr.hookargs.copy() | |
1910 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1917 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1911 | repo.hook('txnclose-bookmark', throw=False, |
|
1918 | repo.hook('txnclose-bookmark', throw=False, | |
1912 | **pycompat.strkwargs(args)) |
|
1919 | **pycompat.strkwargs(args)) | |
1913 |
|
1920 | |||
1914 | if hook.hashook(repo.ui, 'txnclose-phase'): |
|
1921 | if hook.hashook(repo.ui, 'txnclose-phase'): | |
1915 | cl = repo.unfiltered().changelog |
|
1922 | cl = repo.unfiltered().changelog | |
1916 | phasemv = sorted(tr.changes['phases'].items()) |
|
1923 | phasemv = sorted(tr.changes['phases'].items()) | |
1917 | for rev, (old, new) in phasemv: |
|
1924 | for rev, (old, new) in phasemv: | |
1918 | args = tr.hookargs.copy() |
|
1925 | args = tr.hookargs.copy() | |
1919 | node = hex(cl.node(rev)) |
|
1926 | node = hex(cl.node(rev)) | |
1920 | args.update(phases.preparehookargs(node, old, new)) |
|
1927 | args.update(phases.preparehookargs(node, old, new)) | |
1921 | repo.hook('txnclose-phase', throw=False, |
|
1928 | repo.hook('txnclose-phase', throw=False, | |
1922 | **pycompat.strkwargs(args)) |
|
1929 | **pycompat.strkwargs(args)) | |
1923 |
|
1930 | |||
1924 | repo.hook('txnclose', throw=False, |
|
1931 | repo.hook('txnclose', throw=False, | |
1925 | **pycompat.strkwargs(hookargs)) |
|
1932 | **pycompat.strkwargs(hookargs)) | |
1926 | reporef()._afterlock(hookfunc) |
|
1933 | reporef()._afterlock(hookfunc) | |
1927 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1934 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1928 | # Include a leading "-" to make it happen before the transaction summary |
|
1935 | # Include a leading "-" to make it happen before the transaction summary | |
1929 | # reports registered via scmutil.registersummarycallback() whose names |
|
1936 | # reports registered via scmutil.registersummarycallback() whose names | |
1930 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
1937 | # are 00-txnreport etc. That way, the caches will be warm when the | |
1931 | # callbacks run. |
|
1938 | # callbacks run. | |
1932 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) |
|
1939 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) | |
1933 | def txnaborthook(tr2): |
|
1940 | def txnaborthook(tr2): | |
1934 | """To be run if transaction is aborted |
|
1941 | """To be run if transaction is aborted | |
1935 | """ |
|
1942 | """ | |
1936 | reporef().hook('txnabort', throw=False, |
|
1943 | reporef().hook('txnabort', throw=False, | |
1937 | **pycompat.strkwargs(tr2.hookargs)) |
|
1944 | **pycompat.strkwargs(tr2.hookargs)) | |
1938 | tr.addabort('txnabort-hook', txnaborthook) |
|
1945 | tr.addabort('txnabort-hook', txnaborthook) | |
1939 | # avoid eager cache invalidation. in-memory data should be identical |
|
1946 | # avoid eager cache invalidation. in-memory data should be identical | |
1940 | # to stored data if transaction has no error. |
|
1947 | # to stored data if transaction has no error. | |
1941 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1948 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1942 | self._transref = weakref.ref(tr) |
|
1949 | self._transref = weakref.ref(tr) | |
1943 | scmutil.registersummarycallback(self, tr, desc) |
|
1950 | scmutil.registersummarycallback(self, tr, desc) | |
1944 | return tr |
|
1951 | return tr | |
1945 |
|
1952 | |||
1946 | def _journalfiles(self): |
|
1953 | def _journalfiles(self): | |
1947 | return ((self.svfs, 'journal'), |
|
1954 | return ((self.svfs, 'journal'), | |
1948 | (self.svfs, 'journal.narrowspec'), |
|
1955 | (self.svfs, 'journal.narrowspec'), | |
1949 | (self.vfs, 'journal.narrowspec.dirstate'), |
|
1956 | (self.vfs, 'journal.narrowspec.dirstate'), | |
1950 | (self.vfs, 'journal.dirstate'), |
|
1957 | (self.vfs, 'journal.dirstate'), | |
1951 | (self.vfs, 'journal.branch'), |
|
1958 | (self.vfs, 'journal.branch'), | |
1952 | (self.vfs, 'journal.desc'), |
|
1959 | (self.vfs, 'journal.desc'), | |
1953 | (self.vfs, 'journal.bookmarks'), |
|
1960 | (self.vfs, 'journal.bookmarks'), | |
1954 | (self.svfs, 'journal.phaseroots')) |
|
1961 | (self.svfs, 'journal.phaseroots')) | |
1955 |
|
1962 | |||
1956 | def undofiles(self): |
|
1963 | def undofiles(self): | |
1957 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1964 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1958 |
|
1965 | |||
1959 | @unfilteredmethod |
|
1966 | @unfilteredmethod | |
1960 | def _writejournal(self, desc): |
|
1967 | def _writejournal(self, desc): | |
1961 | self.dirstate.savebackup(None, 'journal.dirstate') |
|
1968 | self.dirstate.savebackup(None, 'journal.dirstate') | |
1962 | narrowspec.savewcbackup(self, 'journal.narrowspec.dirstate') |
|
1969 | narrowspec.savewcbackup(self, 'journal.narrowspec.dirstate') | |
1963 | narrowspec.savebackup(self, 'journal.narrowspec') |
|
1970 | narrowspec.savebackup(self, 'journal.narrowspec') | |
1964 | self.vfs.write("journal.branch", |
|
1971 | self.vfs.write("journal.branch", | |
1965 | encoding.fromlocal(self.dirstate.branch())) |
|
1972 | encoding.fromlocal(self.dirstate.branch())) | |
1966 | self.vfs.write("journal.desc", |
|
1973 | self.vfs.write("journal.desc", | |
1967 | "%d\n%s\n" % (len(self), desc)) |
|
1974 | "%d\n%s\n" % (len(self), desc)) | |
1968 | self.vfs.write("journal.bookmarks", |
|
1975 | self.vfs.write("journal.bookmarks", | |
1969 | self.vfs.tryread("bookmarks")) |
|
1976 | self.vfs.tryread("bookmarks")) | |
1970 | self.svfs.write("journal.phaseroots", |
|
1977 | self.svfs.write("journal.phaseroots", | |
1971 | self.svfs.tryread("phaseroots")) |
|
1978 | self.svfs.tryread("phaseroots")) | |
1972 |
|
1979 | |||
1973 | def recover(self): |
|
1980 | def recover(self): | |
1974 | with self.lock(): |
|
1981 | with self.lock(): | |
1975 | if self.svfs.exists("journal"): |
|
1982 | if self.svfs.exists("journal"): | |
1976 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1983 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1977 | vfsmap = {'': self.svfs, |
|
1984 | vfsmap = {'': self.svfs, | |
1978 | 'plain': self.vfs,} |
|
1985 | 'plain': self.vfs,} | |
1979 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1986 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1980 | self.ui.warn, |
|
1987 | self.ui.warn, | |
1981 | checkambigfiles=_cachedfiles) |
|
1988 | checkambigfiles=_cachedfiles) | |
1982 | self.invalidate() |
|
1989 | self.invalidate() | |
1983 | return True |
|
1990 | return True | |
1984 | else: |
|
1991 | else: | |
1985 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1992 | self.ui.warn(_("no interrupted transaction available\n")) | |
1986 | return False |
|
1993 | return False | |
1987 |
|
1994 | |||
1988 | def rollback(self, dryrun=False, force=False): |
|
1995 | def rollback(self, dryrun=False, force=False): | |
1989 | wlock = lock = dsguard = None |
|
1996 | wlock = lock = dsguard = None | |
1990 | try: |
|
1997 | try: | |
1991 | wlock = self.wlock() |
|
1998 | wlock = self.wlock() | |
1992 | lock = self.lock() |
|
1999 | lock = self.lock() | |
1993 | if self.svfs.exists("undo"): |
|
2000 | if self.svfs.exists("undo"): | |
1994 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
2001 | dsguard = dirstateguard.dirstateguard(self, 'rollback') | |
1995 |
|
2002 | |||
1996 | return self._rollback(dryrun, force, dsguard) |
|
2003 | return self._rollback(dryrun, force, dsguard) | |
1997 | else: |
|
2004 | else: | |
1998 | self.ui.warn(_("no rollback information available\n")) |
|
2005 | self.ui.warn(_("no rollback information available\n")) | |
1999 | return 1 |
|
2006 | return 1 | |
2000 | finally: |
|
2007 | finally: | |
2001 | release(dsguard, lock, wlock) |
|
2008 | release(dsguard, lock, wlock) | |
2002 |
|
2009 | |||
2003 | @unfilteredmethod # Until we get smarter cache management |
|
2010 | @unfilteredmethod # Until we get smarter cache management | |
2004 | def _rollback(self, dryrun, force, dsguard): |
|
2011 | def _rollback(self, dryrun, force, dsguard): | |
2005 | ui = self.ui |
|
2012 | ui = self.ui | |
2006 | try: |
|
2013 | try: | |
2007 | args = self.vfs.read('undo.desc').splitlines() |
|
2014 | args = self.vfs.read('undo.desc').splitlines() | |
2008 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
2015 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
2009 | if len(args) >= 3: |
|
2016 | if len(args) >= 3: | |
2010 | detail = args[2] |
|
2017 | detail = args[2] | |
2011 | oldtip = oldlen - 1 |
|
2018 | oldtip = oldlen - 1 | |
2012 |
|
2019 | |||
2013 | if detail and ui.verbose: |
|
2020 | if detail and ui.verbose: | |
2014 | msg = (_('repository tip rolled back to revision %d' |
|
2021 | msg = (_('repository tip rolled back to revision %d' | |
2015 | ' (undo %s: %s)\n') |
|
2022 | ' (undo %s: %s)\n') | |
2016 | % (oldtip, desc, detail)) |
|
2023 | % (oldtip, desc, detail)) | |
2017 | else: |
|
2024 | else: | |
2018 | msg = (_('repository tip rolled back to revision %d' |
|
2025 | msg = (_('repository tip rolled back to revision %d' | |
2019 | ' (undo %s)\n') |
|
2026 | ' (undo %s)\n') | |
2020 | % (oldtip, desc)) |
|
2027 | % (oldtip, desc)) | |
2021 | except IOError: |
|
2028 | except IOError: | |
2022 | msg = _('rolling back unknown transaction\n') |
|
2029 | msg = _('rolling back unknown transaction\n') | |
2023 | desc = None |
|
2030 | desc = None | |
2024 |
|
2031 | |||
2025 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
2032 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
2026 | raise error.Abort( |
|
2033 | raise error.Abort( | |
2027 | _('rollback of last commit while not checked out ' |
|
2034 | _('rollback of last commit while not checked out ' | |
2028 | 'may lose data'), hint=_('use -f to force')) |
|
2035 | 'may lose data'), hint=_('use -f to force')) | |
2029 |
|
2036 | |||
2030 | ui.status(msg) |
|
2037 | ui.status(msg) | |
2031 | if dryrun: |
|
2038 | if dryrun: | |
2032 | return 0 |
|
2039 | return 0 | |
2033 |
|
2040 | |||
2034 | parents = self.dirstate.parents() |
|
2041 | parents = self.dirstate.parents() | |
2035 | self.destroying() |
|
2042 | self.destroying() | |
2036 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
2043 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
2037 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, |
|
2044 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, | |
2038 | checkambigfiles=_cachedfiles) |
|
2045 | checkambigfiles=_cachedfiles) | |
2039 | if self.vfs.exists('undo.bookmarks'): |
|
2046 | if self.vfs.exists('undo.bookmarks'): | |
2040 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
2047 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) | |
2041 | if self.svfs.exists('undo.phaseroots'): |
|
2048 | if self.svfs.exists('undo.phaseroots'): | |
2042 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
2049 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) | |
2043 | self.invalidate() |
|
2050 | self.invalidate() | |
2044 |
|
2051 | |||
2045 | parentgone = any(p not in self.changelog.nodemap for p in parents) |
|
2052 | parentgone = any(p not in self.changelog.nodemap for p in parents) | |
2046 | if parentgone: |
|
2053 | if parentgone: | |
2047 | # prevent dirstateguard from overwriting already restored one |
|
2054 | # prevent dirstateguard from overwriting already restored one | |
2048 | dsguard.close() |
|
2055 | dsguard.close() | |
2049 |
|
2056 | |||
2050 | narrowspec.restorebackup(self, 'undo.narrowspec') |
|
2057 | narrowspec.restorebackup(self, 'undo.narrowspec') | |
2051 | narrowspec.restorewcbackup(self, 'undo.narrowspec.dirstate') |
|
2058 | narrowspec.restorewcbackup(self, 'undo.narrowspec.dirstate') | |
2052 | self.dirstate.restorebackup(None, 'undo.dirstate') |
|
2059 | self.dirstate.restorebackup(None, 'undo.dirstate') | |
2053 | try: |
|
2060 | try: | |
2054 | branch = self.vfs.read('undo.branch') |
|
2061 | branch = self.vfs.read('undo.branch') | |
2055 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
2062 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
2056 | except IOError: |
|
2063 | except IOError: | |
2057 | ui.warn(_('named branch could not be reset: ' |
|
2064 | ui.warn(_('named branch could not be reset: ' | |
2058 | 'current branch is still \'%s\'\n') |
|
2065 | 'current branch is still \'%s\'\n') | |
2059 | % self.dirstate.branch()) |
|
2066 | % self.dirstate.branch()) | |
2060 |
|
2067 | |||
2061 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
2068 | parents = tuple([p.rev() for p in self[None].parents()]) | |
2062 | if len(parents) > 1: |
|
2069 | if len(parents) > 1: | |
2063 | ui.status(_('working directory now based on ' |
|
2070 | ui.status(_('working directory now based on ' | |
2064 | 'revisions %d and %d\n') % parents) |
|
2071 | 'revisions %d and %d\n') % parents) | |
2065 | else: |
|
2072 | else: | |
2066 | ui.status(_('working directory now based on ' |
|
2073 | ui.status(_('working directory now based on ' | |
2067 | 'revision %d\n') % parents) |
|
2074 | 'revision %d\n') % parents) | |
2068 | mergemod.mergestate.clean(self, self['.'].node()) |
|
2075 | mergemod.mergestate.clean(self, self['.'].node()) | |
2069 |
|
2076 | |||
2070 | # TODO: if we know which new heads may result from this rollback, pass |
|
2077 | # TODO: if we know which new heads may result from this rollback, pass | |
2071 | # them to destroy(), which will prevent the branchhead cache from being |
|
2078 | # them to destroy(), which will prevent the branchhead cache from being | |
2072 | # invalidated. |
|
2079 | # invalidated. | |
2073 | self.destroyed() |
|
2080 | self.destroyed() | |
2074 | return 0 |
|
2081 | return 0 | |
2075 |
|
2082 | |||
2076 | def _buildcacheupdater(self, newtransaction): |
|
2083 | def _buildcacheupdater(self, newtransaction): | |
2077 | """called during transaction to build the callback updating cache |
|
2084 | """called during transaction to build the callback updating cache | |
2078 |
|
2085 | |||
2079 | Lives on the repository to help extension who might want to augment |
|
2086 | Lives on the repository to help extension who might want to augment | |
2080 | this logic. For this purpose, the created transaction is passed to the |
|
2087 | this logic. For this purpose, the created transaction is passed to the | |
2081 | method. |
|
2088 | method. | |
2082 | """ |
|
2089 | """ | |
2083 | # we must avoid cyclic reference between repo and transaction. |
|
2090 | # we must avoid cyclic reference between repo and transaction. | |
2084 | reporef = weakref.ref(self) |
|
2091 | reporef = weakref.ref(self) | |
2085 | def updater(tr): |
|
2092 | def updater(tr): | |
2086 | repo = reporef() |
|
2093 | repo = reporef() | |
2087 | repo.updatecaches(tr) |
|
2094 | repo.updatecaches(tr) | |
2088 | return updater |
|
2095 | return updater | |
2089 |
|
2096 | |||
2090 | @unfilteredmethod |
|
2097 | @unfilteredmethod | |
2091 | def updatecaches(self, tr=None, full=False): |
|
2098 | def updatecaches(self, tr=None, full=False): | |
2092 | """warm appropriate caches |
|
2099 | """warm appropriate caches | |
2093 |
|
2100 | |||
2094 | If this function is called after a transaction closed. The transaction |
|
2101 | If this function is called after a transaction closed. The transaction | |
2095 | will be available in the 'tr' argument. This can be used to selectively |
|
2102 | will be available in the 'tr' argument. This can be used to selectively | |
2096 | update caches relevant to the changes in that transaction. |
|
2103 | update caches relevant to the changes in that transaction. | |
2097 |
|
2104 | |||
2098 | If 'full' is set, make sure all caches the function knows about have |
|
2105 | If 'full' is set, make sure all caches the function knows about have | |
2099 | up-to-date data. Even the ones usually loaded more lazily. |
|
2106 | up-to-date data. Even the ones usually loaded more lazily. | |
2100 | """ |
|
2107 | """ | |
2101 | if tr is not None and tr.hookargs.get('source') == 'strip': |
|
2108 | if tr is not None and tr.hookargs.get('source') == 'strip': | |
2102 | # During strip, many caches are invalid but |
|
2109 | # During strip, many caches are invalid but | |
2103 | # later call to `destroyed` will refresh them. |
|
2110 | # later call to `destroyed` will refresh them. | |
2104 | return |
|
2111 | return | |
2105 |
|
2112 | |||
2106 | if tr is None or tr.changes['origrepolen'] < len(self): |
|
2113 | if tr is None or tr.changes['origrepolen'] < len(self): | |
2107 | # accessing the 'ser ved' branchmap should refresh all the others, |
|
2114 | # accessing the 'ser ved' branchmap should refresh all the others, | |
2108 | self.ui.debug('updating the branch cache\n') |
|
2115 | self.ui.debug('updating the branch cache\n') | |
2109 | self.filtered('served').branchmap() |
|
2116 | self.filtered('served').branchmap() | |
2110 | self.filtered('served.hidden').branchmap() |
|
2117 | self.filtered('served.hidden').branchmap() | |
2111 |
|
2118 | |||
2112 | if full: |
|
2119 | if full: | |
2113 | unfi = self.unfiltered() |
|
2120 | unfi = self.unfiltered() | |
2114 | rbc = unfi.revbranchcache() |
|
2121 | rbc = unfi.revbranchcache() | |
2115 | for r in unfi.changelog: |
|
2122 | for r in unfi.changelog: | |
2116 | rbc.branchinfo(r) |
|
2123 | rbc.branchinfo(r) | |
2117 | rbc.write() |
|
2124 | rbc.write() | |
2118 |
|
2125 | |||
2119 | # ensure the working copy parents are in the manifestfulltextcache |
|
2126 | # ensure the working copy parents are in the manifestfulltextcache | |
2120 | for ctx in self['.'].parents(): |
|
2127 | for ctx in self['.'].parents(): | |
2121 | ctx.manifest() # accessing the manifest is enough |
|
2128 | ctx.manifest() # accessing the manifest is enough | |
2122 |
|
2129 | |||
2123 | # accessing tags warm the cache |
|
2130 | # accessing tags warm the cache | |
2124 | self.tags() |
|
2131 | self.tags() | |
2125 | self.filtered('served').tags() |
|
2132 | self.filtered('served').tags() | |
2126 |
|
2133 | |||
2127 | def invalidatecaches(self): |
|
2134 | def invalidatecaches(self): | |
2128 |
|
2135 | |||
2129 | if r'_tagscache' in vars(self): |
|
2136 | if r'_tagscache' in vars(self): | |
2130 | # can't use delattr on proxy |
|
2137 | # can't use delattr on proxy | |
2131 | del self.__dict__[r'_tagscache'] |
|
2138 | del self.__dict__[r'_tagscache'] | |
2132 |
|
2139 | |||
2133 | self._branchcaches.clear() |
|
2140 | self._branchcaches.clear() | |
2134 | self.invalidatevolatilesets() |
|
2141 | self.invalidatevolatilesets() | |
2135 | self._sparsesignaturecache.clear() |
|
2142 | self._sparsesignaturecache.clear() | |
2136 |
|
2143 | |||
2137 | def invalidatevolatilesets(self): |
|
2144 | def invalidatevolatilesets(self): | |
2138 | self.filteredrevcache.clear() |
|
2145 | self.filteredrevcache.clear() | |
2139 | obsolete.clearobscaches(self) |
|
2146 | obsolete.clearobscaches(self) | |
2140 |
|
2147 | |||
2141 | def invalidatedirstate(self): |
|
2148 | def invalidatedirstate(self): | |
2142 | '''Invalidates the dirstate, causing the next call to dirstate |
|
2149 | '''Invalidates the dirstate, causing the next call to dirstate | |
2143 | to check if it was modified since the last time it was read, |
|
2150 | to check if it was modified since the last time it was read, | |
2144 | rereading it if it has. |
|
2151 | rereading it if it has. | |
2145 |
|
2152 | |||
2146 | This is different to dirstate.invalidate() that it doesn't always |
|
2153 | This is different to dirstate.invalidate() that it doesn't always | |
2147 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
2154 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
2148 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
2155 | explicitly read the dirstate again (i.e. restoring it to a previous | |
2149 | known good state).''' |
|
2156 | known good state).''' | |
2150 | if hasunfilteredcache(self, r'dirstate'): |
|
2157 | if hasunfilteredcache(self, r'dirstate'): | |
2151 | for k in self.dirstate._filecache: |
|
2158 | for k in self.dirstate._filecache: | |
2152 | try: |
|
2159 | try: | |
2153 | delattr(self.dirstate, k) |
|
2160 | delattr(self.dirstate, k) | |
2154 | except AttributeError: |
|
2161 | except AttributeError: | |
2155 | pass |
|
2162 | pass | |
2156 | delattr(self.unfiltered(), r'dirstate') |
|
2163 | delattr(self.unfiltered(), r'dirstate') | |
2157 |
|
2164 | |||
2158 | def invalidate(self, clearfilecache=False): |
|
2165 | def invalidate(self, clearfilecache=False): | |
2159 | '''Invalidates both store and non-store parts other than dirstate |
|
2166 | '''Invalidates both store and non-store parts other than dirstate | |
2160 |
|
2167 | |||
2161 | If a transaction is running, invalidation of store is omitted, |
|
2168 | If a transaction is running, invalidation of store is omitted, | |
2162 | because discarding in-memory changes might cause inconsistency |
|
2169 | because discarding in-memory changes might cause inconsistency | |
2163 | (e.g. incomplete fncache causes unintentional failure, but |
|
2170 | (e.g. incomplete fncache causes unintentional failure, but | |
2164 | redundant one doesn't). |
|
2171 | redundant one doesn't). | |
2165 | ''' |
|
2172 | ''' | |
2166 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
2173 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
2167 | for k in list(self._filecache.keys()): |
|
2174 | for k in list(self._filecache.keys()): | |
2168 | # dirstate is invalidated separately in invalidatedirstate() |
|
2175 | # dirstate is invalidated separately in invalidatedirstate() | |
2169 | if k == 'dirstate': |
|
2176 | if k == 'dirstate': | |
2170 | continue |
|
2177 | continue | |
2171 | if (k == 'changelog' and |
|
2178 | if (k == 'changelog' and | |
2172 | self.currenttransaction() and |
|
2179 | self.currenttransaction() and | |
2173 | self.changelog._delayed): |
|
2180 | self.changelog._delayed): | |
2174 | # The changelog object may store unwritten revisions. We don't |
|
2181 | # The changelog object may store unwritten revisions. We don't | |
2175 | # want to lose them. |
|
2182 | # want to lose them. | |
2176 | # TODO: Solve the problem instead of working around it. |
|
2183 | # TODO: Solve the problem instead of working around it. | |
2177 | continue |
|
2184 | continue | |
2178 |
|
2185 | |||
2179 | if clearfilecache: |
|
2186 | if clearfilecache: | |
2180 | del self._filecache[k] |
|
2187 | del self._filecache[k] | |
2181 | try: |
|
2188 | try: | |
2182 | delattr(unfiltered, k) |
|
2189 | delattr(unfiltered, k) | |
2183 | except AttributeError: |
|
2190 | except AttributeError: | |
2184 | pass |
|
2191 | pass | |
2185 | self.invalidatecaches() |
|
2192 | self.invalidatecaches() | |
2186 | if not self.currenttransaction(): |
|
2193 | if not self.currenttransaction(): | |
2187 | # TODO: Changing contents of store outside transaction |
|
2194 | # TODO: Changing contents of store outside transaction | |
2188 | # causes inconsistency. We should make in-memory store |
|
2195 | # causes inconsistency. We should make in-memory store | |
2189 | # changes detectable, and abort if changed. |
|
2196 | # changes detectable, and abort if changed. | |
2190 | self.store.invalidatecaches() |
|
2197 | self.store.invalidatecaches() | |
2191 |
|
2198 | |||
2192 | def invalidateall(self): |
|
2199 | def invalidateall(self): | |
2193 | '''Fully invalidates both store and non-store parts, causing the |
|
2200 | '''Fully invalidates both store and non-store parts, causing the | |
2194 | subsequent operation to reread any outside changes.''' |
|
2201 | subsequent operation to reread any outside changes.''' | |
2195 | # extension should hook this to invalidate its caches |
|
2202 | # extension should hook this to invalidate its caches | |
2196 | self.invalidate() |
|
2203 | self.invalidate() | |
2197 | self.invalidatedirstate() |
|
2204 | self.invalidatedirstate() | |
2198 |
|
2205 | |||
2199 | @unfilteredmethod |
|
2206 | @unfilteredmethod | |
2200 | def _refreshfilecachestats(self, tr): |
|
2207 | def _refreshfilecachestats(self, tr): | |
2201 | """Reload stats of cached files so that they are flagged as valid""" |
|
2208 | """Reload stats of cached files so that they are flagged as valid""" | |
2202 | for k, ce in self._filecache.items(): |
|
2209 | for k, ce in self._filecache.items(): | |
2203 | k = pycompat.sysstr(k) |
|
2210 | k = pycompat.sysstr(k) | |
2204 | if k == r'dirstate' or k not in self.__dict__: |
|
2211 | if k == r'dirstate' or k not in self.__dict__: | |
2205 | continue |
|
2212 | continue | |
2206 | ce.refresh() |
|
2213 | ce.refresh() | |
2207 |
|
2214 | |||
2208 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
2215 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
2209 | inheritchecker=None, parentenvvar=None): |
|
2216 | inheritchecker=None, parentenvvar=None): | |
2210 | parentlock = None |
|
2217 | parentlock = None | |
2211 | # the contents of parentenvvar are used by the underlying lock to |
|
2218 | # the contents of parentenvvar are used by the underlying lock to | |
2212 | # determine whether it can be inherited |
|
2219 | # determine whether it can be inherited | |
2213 | if parentenvvar is not None: |
|
2220 | if parentenvvar is not None: | |
2214 | parentlock = encoding.environ.get(parentenvvar) |
|
2221 | parentlock = encoding.environ.get(parentenvvar) | |
2215 |
|
2222 | |||
2216 | timeout = 0 |
|
2223 | timeout = 0 | |
2217 | warntimeout = 0 |
|
2224 | warntimeout = 0 | |
2218 | if wait: |
|
2225 | if wait: | |
2219 | timeout = self.ui.configint("ui", "timeout") |
|
2226 | timeout = self.ui.configint("ui", "timeout") | |
2220 | warntimeout = self.ui.configint("ui", "timeout.warn") |
|
2227 | warntimeout = self.ui.configint("ui", "timeout.warn") | |
2221 | # internal config: ui.signal-safe-lock |
|
2228 | # internal config: ui.signal-safe-lock | |
2222 | signalsafe = self.ui.configbool('ui', 'signal-safe-lock') |
|
2229 | signalsafe = self.ui.configbool('ui', 'signal-safe-lock') | |
2223 |
|
2230 | |||
2224 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, |
|
2231 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, | |
2225 | releasefn=releasefn, |
|
2232 | releasefn=releasefn, | |
2226 | acquirefn=acquirefn, desc=desc, |
|
2233 | acquirefn=acquirefn, desc=desc, | |
2227 | inheritchecker=inheritchecker, |
|
2234 | inheritchecker=inheritchecker, | |
2228 | parentlock=parentlock, |
|
2235 | parentlock=parentlock, | |
2229 | signalsafe=signalsafe) |
|
2236 | signalsafe=signalsafe) | |
2230 | return l |
|
2237 | return l | |
2231 |
|
2238 | |||
2232 | def _afterlock(self, callback): |
|
2239 | def _afterlock(self, callback): | |
2233 | """add a callback to be run when the repository is fully unlocked |
|
2240 | """add a callback to be run when the repository is fully unlocked | |
2234 |
|
2241 | |||
2235 | The callback will be executed when the outermost lock is released |
|
2242 | The callback will be executed when the outermost lock is released | |
2236 | (with wlock being higher level than 'lock').""" |
|
2243 | (with wlock being higher level than 'lock').""" | |
2237 | for ref in (self._wlockref, self._lockref): |
|
2244 | for ref in (self._wlockref, self._lockref): | |
2238 | l = ref and ref() |
|
2245 | l = ref and ref() | |
2239 | if l and l.held: |
|
2246 | if l and l.held: | |
2240 | l.postrelease.append(callback) |
|
2247 | l.postrelease.append(callback) | |
2241 | break |
|
2248 | break | |
2242 | else: # no lock have been found. |
|
2249 | else: # no lock have been found. | |
2243 | callback() |
|
2250 | callback() | |
2244 |
|
2251 | |||
2245 | def lock(self, wait=True): |
|
2252 | def lock(self, wait=True): | |
2246 | '''Lock the repository store (.hg/store) and return a weak reference |
|
2253 | '''Lock the repository store (.hg/store) and return a weak reference | |
2247 | to the lock. Use this before modifying the store (e.g. committing or |
|
2254 | to the lock. Use this before modifying the store (e.g. committing or | |
2248 | stripping). If you are opening a transaction, get a lock as well.) |
|
2255 | stripping). If you are opening a transaction, get a lock as well.) | |
2249 |
|
2256 | |||
2250 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2257 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2251 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2258 | 'wlock' first to avoid a dead-lock hazard.''' | |
2252 | l = self._currentlock(self._lockref) |
|
2259 | l = self._currentlock(self._lockref) | |
2253 | if l is not None: |
|
2260 | if l is not None: | |
2254 | l.lock() |
|
2261 | l.lock() | |
2255 | return l |
|
2262 | return l | |
2256 |
|
2263 | |||
2257 | l = self._lock(vfs=self.svfs, |
|
2264 | l = self._lock(vfs=self.svfs, | |
2258 | lockname="lock", |
|
2265 | lockname="lock", | |
2259 | wait=wait, |
|
2266 | wait=wait, | |
2260 | releasefn=None, |
|
2267 | releasefn=None, | |
2261 | acquirefn=self.invalidate, |
|
2268 | acquirefn=self.invalidate, | |
2262 | desc=_('repository %s') % self.origroot) |
|
2269 | desc=_('repository %s') % self.origroot) | |
2263 | self._lockref = weakref.ref(l) |
|
2270 | self._lockref = weakref.ref(l) | |
2264 | return l |
|
2271 | return l | |
2265 |
|
2272 | |||
2266 | def _wlockchecktransaction(self): |
|
2273 | def _wlockchecktransaction(self): | |
2267 | if self.currenttransaction() is not None: |
|
2274 | if self.currenttransaction() is not None: | |
2268 | raise error.LockInheritanceContractViolation( |
|
2275 | raise error.LockInheritanceContractViolation( | |
2269 | 'wlock cannot be inherited in the middle of a transaction') |
|
2276 | 'wlock cannot be inherited in the middle of a transaction') | |
2270 |
|
2277 | |||
2271 | def wlock(self, wait=True): |
|
2278 | def wlock(self, wait=True): | |
2272 | '''Lock the non-store parts of the repository (everything under |
|
2279 | '''Lock the non-store parts of the repository (everything under | |
2273 | .hg except .hg/store) and return a weak reference to the lock. |
|
2280 | .hg except .hg/store) and return a weak reference to the lock. | |
2274 |
|
2281 | |||
2275 | Use this before modifying files in .hg. |
|
2282 | Use this before modifying files in .hg. | |
2276 |
|
2283 | |||
2277 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2284 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2278 | 'wlock' first to avoid a dead-lock hazard.''' |
|
2285 | 'wlock' first to avoid a dead-lock hazard.''' | |
2279 | l = self._wlockref and self._wlockref() |
|
2286 | l = self._wlockref and self._wlockref() | |
2280 | if l is not None and l.held: |
|
2287 | if l is not None and l.held: | |
2281 | l.lock() |
|
2288 | l.lock() | |
2282 | return l |
|
2289 | return l | |
2283 |
|
2290 | |||
2284 | # We do not need to check for non-waiting lock acquisition. Such |
|
2291 | # We do not need to check for non-waiting lock acquisition. Such | |
2285 | # acquisition would not cause dead-lock as they would just fail. |
|
2292 | # acquisition would not cause dead-lock as they would just fail. | |
2286 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
2293 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
2287 | or self.ui.configbool('devel', 'check-locks')): |
|
2294 | or self.ui.configbool('devel', 'check-locks')): | |
2288 | if self._currentlock(self._lockref) is not None: |
|
2295 | if self._currentlock(self._lockref) is not None: | |
2289 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
2296 | self.ui.develwarn('"wlock" acquired after "lock"') | |
2290 |
|
2297 | |||
2291 | def unlock(): |
|
2298 | def unlock(): | |
2292 | if self.dirstate.pendingparentchange(): |
|
2299 | if self.dirstate.pendingparentchange(): | |
2293 | self.dirstate.invalidate() |
|
2300 | self.dirstate.invalidate() | |
2294 | else: |
|
2301 | else: | |
2295 | self.dirstate.write(None) |
|
2302 | self.dirstate.write(None) | |
2296 |
|
2303 | |||
2297 | self._filecache['dirstate'].refresh() |
|
2304 | self._filecache['dirstate'].refresh() | |
2298 |
|
2305 | |||
2299 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
2306 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
2300 | self.invalidatedirstate, _('working directory of %s') % |
|
2307 | self.invalidatedirstate, _('working directory of %s') % | |
2301 | self.origroot, |
|
2308 | self.origroot, | |
2302 | inheritchecker=self._wlockchecktransaction, |
|
2309 | inheritchecker=self._wlockchecktransaction, | |
2303 | parentenvvar='HG_WLOCK_LOCKER') |
|
2310 | parentenvvar='HG_WLOCK_LOCKER') | |
2304 | self._wlockref = weakref.ref(l) |
|
2311 | self._wlockref = weakref.ref(l) | |
2305 | return l |
|
2312 | return l | |
2306 |
|
2313 | |||
2307 | def _currentlock(self, lockref): |
|
2314 | def _currentlock(self, lockref): | |
2308 | """Returns the lock if it's held, or None if it's not.""" |
|
2315 | """Returns the lock if it's held, or None if it's not.""" | |
2309 | if lockref is None: |
|
2316 | if lockref is None: | |
2310 | return None |
|
2317 | return None | |
2311 | l = lockref() |
|
2318 | l = lockref() | |
2312 | if l is None or not l.held: |
|
2319 | if l is None or not l.held: | |
2313 | return None |
|
2320 | return None | |
2314 | return l |
|
2321 | return l | |
2315 |
|
2322 | |||
2316 | def currentwlock(self): |
|
2323 | def currentwlock(self): | |
2317 | """Returns the wlock if it's held, or None if it's not.""" |
|
2324 | """Returns the wlock if it's held, or None if it's not.""" | |
2318 | return self._currentlock(self._wlockref) |
|
2325 | return self._currentlock(self._wlockref) | |
2319 |
|
2326 | |||
2320 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
2327 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
2321 | """ |
|
2328 | """ | |
2322 | commit an individual file as part of a larger transaction |
|
2329 | commit an individual file as part of a larger transaction | |
2323 | """ |
|
2330 | """ | |
2324 |
|
2331 | |||
2325 | fname = fctx.path() |
|
2332 | fname = fctx.path() | |
2326 | fparent1 = manifest1.get(fname, nullid) |
|
2333 | fparent1 = manifest1.get(fname, nullid) | |
2327 | fparent2 = manifest2.get(fname, nullid) |
|
2334 | fparent2 = manifest2.get(fname, nullid) | |
2328 | if isinstance(fctx, context.filectx): |
|
2335 | if isinstance(fctx, context.filectx): | |
2329 | node = fctx.filenode() |
|
2336 | node = fctx.filenode() | |
2330 | if node in [fparent1, fparent2]: |
|
2337 | if node in [fparent1, fparent2]: | |
2331 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
2338 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
2332 | if manifest1.flags(fname) != fctx.flags(): |
|
2339 | if manifest1.flags(fname) != fctx.flags(): | |
2333 | changelist.append(fname) |
|
2340 | changelist.append(fname) | |
2334 | return node |
|
2341 | return node | |
2335 |
|
2342 | |||
2336 | flog = self.file(fname) |
|
2343 | flog = self.file(fname) | |
2337 | meta = {} |
|
2344 | meta = {} | |
2338 | cfname = fctx.copysource() |
|
2345 | cfname = fctx.copysource() | |
2339 | if cfname and cfname != fname: |
|
2346 | if cfname and cfname != fname: | |
2340 | # Mark the new revision of this file as a copy of another |
|
2347 | # Mark the new revision of this file as a copy of another | |
2341 | # file. This copy data will effectively act as a parent |
|
2348 | # file. This copy data will effectively act as a parent | |
2342 | # of this new revision. If this is a merge, the first |
|
2349 | # of this new revision. If this is a merge, the first | |
2343 | # parent will be the nullid (meaning "look up the copy data") |
|
2350 | # parent will be the nullid (meaning "look up the copy data") | |
2344 | # and the second one will be the other parent. For example: |
|
2351 | # and the second one will be the other parent. For example: | |
2345 | # |
|
2352 | # | |
2346 | # 0 --- 1 --- 3 rev1 changes file foo |
|
2353 | # 0 --- 1 --- 3 rev1 changes file foo | |
2347 | # \ / rev2 renames foo to bar and changes it |
|
2354 | # \ / rev2 renames foo to bar and changes it | |
2348 | # \- 2 -/ rev3 should have bar with all changes and |
|
2355 | # \- 2 -/ rev3 should have bar with all changes and | |
2349 | # should record that bar descends from |
|
2356 | # should record that bar descends from | |
2350 | # bar in rev2 and foo in rev1 |
|
2357 | # bar in rev2 and foo in rev1 | |
2351 | # |
|
2358 | # | |
2352 | # this allows this merge to succeed: |
|
2359 | # this allows this merge to succeed: | |
2353 | # |
|
2360 | # | |
2354 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
2361 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
2355 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
2362 | # \ / merging rev3 and rev4 should use bar@rev2 | |
2356 | # \- 2 --- 4 as the merge base |
|
2363 | # \- 2 --- 4 as the merge base | |
2357 | # |
|
2364 | # | |
2358 |
|
2365 | |||
2359 | cnode = manifest1.get(cfname) |
|
2366 | cnode = manifest1.get(cfname) | |
2360 | newfparent = fparent2 |
|
2367 | newfparent = fparent2 | |
2361 |
|
2368 | |||
2362 | if manifest2: # branch merge |
|
2369 | if manifest2: # branch merge | |
2363 | if fparent2 == nullid or cnode is None: # copied on remote side |
|
2370 | if fparent2 == nullid or cnode is None: # copied on remote side | |
2364 | if cfname in manifest2: |
|
2371 | if cfname in manifest2: | |
2365 | cnode = manifest2[cfname] |
|
2372 | cnode = manifest2[cfname] | |
2366 | newfparent = fparent1 |
|
2373 | newfparent = fparent1 | |
2367 |
|
2374 | |||
2368 | # Here, we used to search backwards through history to try to find |
|
2375 | # Here, we used to search backwards through history to try to find | |
2369 | # where the file copy came from if the source of a copy was not in |
|
2376 | # where the file copy came from if the source of a copy was not in | |
2370 | # the parent directory. However, this doesn't actually make sense to |
|
2377 | # the parent directory. However, this doesn't actually make sense to | |
2371 | # do (what does a copy from something not in your working copy even |
|
2378 | # do (what does a copy from something not in your working copy even | |
2372 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
2379 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
2373 | # the user that copy information was dropped, so if they didn't |
|
2380 | # the user that copy information was dropped, so if they didn't | |
2374 | # expect this outcome it can be fixed, but this is the correct |
|
2381 | # expect this outcome it can be fixed, but this is the correct | |
2375 | # behavior in this circumstance. |
|
2382 | # behavior in this circumstance. | |
2376 |
|
2383 | |||
2377 | if cnode: |
|
2384 | if cnode: | |
2378 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(cnode))) |
|
2385 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(cnode))) | |
2379 | meta["copy"] = cfname |
|
2386 | meta["copy"] = cfname | |
2380 | meta["copyrev"] = hex(cnode) |
|
2387 | meta["copyrev"] = hex(cnode) | |
2381 | fparent1, fparent2 = nullid, newfparent |
|
2388 | fparent1, fparent2 = nullid, newfparent | |
2382 | else: |
|
2389 | else: | |
2383 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
2390 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
2384 | "copied from '%s'!\n") % (fname, cfname)) |
|
2391 | "copied from '%s'!\n") % (fname, cfname)) | |
2385 |
|
2392 | |||
2386 | elif fparent1 == nullid: |
|
2393 | elif fparent1 == nullid: | |
2387 | fparent1, fparent2 = fparent2, nullid |
|
2394 | fparent1, fparent2 = fparent2, nullid | |
2388 | elif fparent2 != nullid: |
|
2395 | elif fparent2 != nullid: | |
2389 | # is one parent an ancestor of the other? |
|
2396 | # is one parent an ancestor of the other? | |
2390 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
2397 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
2391 | if fparent1 in fparentancestors: |
|
2398 | if fparent1 in fparentancestors: | |
2392 | fparent1, fparent2 = fparent2, nullid |
|
2399 | fparent1, fparent2 = fparent2, nullid | |
2393 | elif fparent2 in fparentancestors: |
|
2400 | elif fparent2 in fparentancestors: | |
2394 | fparent2 = nullid |
|
2401 | fparent2 = nullid | |
2395 |
|
2402 | |||
2396 | # is the file changed? |
|
2403 | # is the file changed? | |
2397 | text = fctx.data() |
|
2404 | text = fctx.data() | |
2398 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
2405 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
2399 | changelist.append(fname) |
|
2406 | changelist.append(fname) | |
2400 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
2407 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
2401 | # are just the flags changed during merge? |
|
2408 | # are just the flags changed during merge? | |
2402 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
2409 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
2403 | changelist.append(fname) |
|
2410 | changelist.append(fname) | |
2404 |
|
2411 | |||
2405 | return fparent1 |
|
2412 | return fparent1 | |
2406 |
|
2413 | |||
2407 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
2414 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): | |
2408 | """check for commit arguments that aren't committable""" |
|
2415 | """check for commit arguments that aren't committable""" | |
2409 | if match.isexact() or match.prefix(): |
|
2416 | if match.isexact() or match.prefix(): | |
2410 | matched = set(status.modified + status.added + status.removed) |
|
2417 | matched = set(status.modified + status.added + status.removed) | |
2411 |
|
2418 | |||
2412 | for f in match.files(): |
|
2419 | for f in match.files(): | |
2413 | f = self.dirstate.normalize(f) |
|
2420 | f = self.dirstate.normalize(f) | |
2414 | if f == '.' or f in matched or f in wctx.substate: |
|
2421 | if f == '.' or f in matched or f in wctx.substate: | |
2415 | continue |
|
2422 | continue | |
2416 | if f in status.deleted: |
|
2423 | if f in status.deleted: | |
2417 | fail(f, _('file not found!')) |
|
2424 | fail(f, _('file not found!')) | |
2418 | if f in vdirs: # visited directory |
|
2425 | if f in vdirs: # visited directory | |
2419 | d = f + '/' |
|
2426 | d = f + '/' | |
2420 | for mf in matched: |
|
2427 | for mf in matched: | |
2421 | if mf.startswith(d): |
|
2428 | if mf.startswith(d): | |
2422 | break |
|
2429 | break | |
2423 | else: |
|
2430 | else: | |
2424 | fail(f, _("no match under directory!")) |
|
2431 | fail(f, _("no match under directory!")) | |
2425 | elif f not in self.dirstate: |
|
2432 | elif f not in self.dirstate: | |
2426 | fail(f, _("file not tracked!")) |
|
2433 | fail(f, _("file not tracked!")) | |
2427 |
|
2434 | |||
2428 | @unfilteredmethod |
|
2435 | @unfilteredmethod | |
2429 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
2436 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
2430 | editor=False, extra=None): |
|
2437 | editor=False, extra=None): | |
2431 | """Add a new revision to current repository. |
|
2438 | """Add a new revision to current repository. | |
2432 |
|
2439 | |||
2433 | Revision information is gathered from the working directory, |
|
2440 | Revision information is gathered from the working directory, | |
2434 | match can be used to filter the committed files. If editor is |
|
2441 | match can be used to filter the committed files. If editor is | |
2435 | supplied, it is called to get a commit message. |
|
2442 | supplied, it is called to get a commit message. | |
2436 | """ |
|
2443 | """ | |
2437 | if extra is None: |
|
2444 | if extra is None: | |
2438 | extra = {} |
|
2445 | extra = {} | |
2439 |
|
2446 | |||
2440 | def fail(f, msg): |
|
2447 | def fail(f, msg): | |
2441 | raise error.Abort('%s: %s' % (f, msg)) |
|
2448 | raise error.Abort('%s: %s' % (f, msg)) | |
2442 |
|
2449 | |||
2443 | if not match: |
|
2450 | if not match: | |
2444 | match = matchmod.always() |
|
2451 | match = matchmod.always() | |
2445 |
|
2452 | |||
2446 | if not force: |
|
2453 | if not force: | |
2447 | vdirs = [] |
|
2454 | vdirs = [] | |
2448 | match.explicitdir = vdirs.append |
|
2455 | match.explicitdir = vdirs.append | |
2449 | match.bad = fail |
|
2456 | match.bad = fail | |
2450 |
|
2457 | |||
2451 | # lock() for recent changelog (see issue4368) |
|
2458 | # lock() for recent changelog (see issue4368) | |
2452 | with self.wlock(), self.lock(): |
|
2459 | with self.wlock(), self.lock(): | |
2453 | wctx = self[None] |
|
2460 | wctx = self[None] | |
2454 | merge = len(wctx.parents()) > 1 |
|
2461 | merge = len(wctx.parents()) > 1 | |
2455 |
|
2462 | |||
2456 | if not force and merge and not match.always(): |
|
2463 | if not force and merge and not match.always(): | |
2457 | raise error.Abort(_('cannot partially commit a merge ' |
|
2464 | raise error.Abort(_('cannot partially commit a merge ' | |
2458 | '(do not specify files or patterns)')) |
|
2465 | '(do not specify files or patterns)')) | |
2459 |
|
2466 | |||
2460 | status = self.status(match=match, clean=force) |
|
2467 | status = self.status(match=match, clean=force) | |
2461 | if force: |
|
2468 | if force: | |
2462 | status.modified.extend(status.clean) # mq may commit clean files |
|
2469 | status.modified.extend(status.clean) # mq may commit clean files | |
2463 |
|
2470 | |||
2464 | # check subrepos |
|
2471 | # check subrepos | |
2465 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
2472 | subs, commitsubs, newstate = subrepoutil.precommit( | |
2466 | self.ui, wctx, status, match, force=force) |
|
2473 | self.ui, wctx, status, match, force=force) | |
2467 |
|
2474 | |||
2468 | # make sure all explicit patterns are matched |
|
2475 | # make sure all explicit patterns are matched | |
2469 | if not force: |
|
2476 | if not force: | |
2470 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
2477 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) | |
2471 |
|
2478 | |||
2472 | cctx = context.workingcommitctx(self, status, |
|
2479 | cctx = context.workingcommitctx(self, status, | |
2473 | text, user, date, extra) |
|
2480 | text, user, date, extra) | |
2474 |
|
2481 | |||
2475 | # internal config: ui.allowemptycommit |
|
2482 | # internal config: ui.allowemptycommit | |
2476 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
2483 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
2477 | or extra.get('close') or merge or cctx.files() |
|
2484 | or extra.get('close') or merge or cctx.files() | |
2478 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
2485 | or self.ui.configbool('ui', 'allowemptycommit')) | |
2479 | if not allowemptycommit: |
|
2486 | if not allowemptycommit: | |
2480 | return None |
|
2487 | return None | |
2481 |
|
2488 | |||
2482 | if merge and cctx.deleted(): |
|
2489 | if merge and cctx.deleted(): | |
2483 | raise error.Abort(_("cannot commit merge with missing files")) |
|
2490 | raise error.Abort(_("cannot commit merge with missing files")) | |
2484 |
|
2491 | |||
2485 | ms = mergemod.mergestate.read(self) |
|
2492 | ms = mergemod.mergestate.read(self) | |
2486 | mergeutil.checkunresolved(ms) |
|
2493 | mergeutil.checkunresolved(ms) | |
2487 |
|
2494 | |||
2488 | if editor: |
|
2495 | if editor: | |
2489 | cctx._text = editor(self, cctx, subs) |
|
2496 | cctx._text = editor(self, cctx, subs) | |
2490 | edited = (text != cctx._text) |
|
2497 | edited = (text != cctx._text) | |
2491 |
|
2498 | |||
2492 | # Save commit message in case this transaction gets rolled back |
|
2499 | # Save commit message in case this transaction gets rolled back | |
2493 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
2500 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
2494 | # the assumption that the user will use the same editor again. |
|
2501 | # the assumption that the user will use the same editor again. | |
2495 | msgfn = self.savecommitmessage(cctx._text) |
|
2502 | msgfn = self.savecommitmessage(cctx._text) | |
2496 |
|
2503 | |||
2497 | # commit subs and write new state |
|
2504 | # commit subs and write new state | |
2498 | if subs: |
|
2505 | if subs: | |
2499 | uipathfn = scmutil.getuipathfn(self) |
|
2506 | uipathfn = scmutil.getuipathfn(self) | |
2500 | for s in sorted(commitsubs): |
|
2507 | for s in sorted(commitsubs): | |
2501 | sub = wctx.sub(s) |
|
2508 | sub = wctx.sub(s) | |
2502 | self.ui.status(_('committing subrepository %s\n') % |
|
2509 | self.ui.status(_('committing subrepository %s\n') % | |
2503 | uipathfn(subrepoutil.subrelpath(sub))) |
|
2510 | uipathfn(subrepoutil.subrelpath(sub))) | |
2504 | sr = sub.commit(cctx._text, user, date) |
|
2511 | sr = sub.commit(cctx._text, user, date) | |
2505 | newstate[s] = (newstate[s][0], sr) |
|
2512 | newstate[s] = (newstate[s][0], sr) | |
2506 | subrepoutil.writestate(self, newstate) |
|
2513 | subrepoutil.writestate(self, newstate) | |
2507 |
|
2514 | |||
2508 | p1, p2 = self.dirstate.parents() |
|
2515 | p1, p2 = self.dirstate.parents() | |
2509 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
2516 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
2510 | try: |
|
2517 | try: | |
2511 | self.hook("precommit", throw=True, parent1=hookp1, |
|
2518 | self.hook("precommit", throw=True, parent1=hookp1, | |
2512 | parent2=hookp2) |
|
2519 | parent2=hookp2) | |
2513 | with self.transaction('commit'): |
|
2520 | with self.transaction('commit'): | |
2514 | ret = self.commitctx(cctx, True) |
|
2521 | ret = self.commitctx(cctx, True) | |
2515 | # update bookmarks, dirstate and mergestate |
|
2522 | # update bookmarks, dirstate and mergestate | |
2516 | bookmarks.update(self, [p1, p2], ret) |
|
2523 | bookmarks.update(self, [p1, p2], ret) | |
2517 | cctx.markcommitted(ret) |
|
2524 | cctx.markcommitted(ret) | |
2518 | ms.reset() |
|
2525 | ms.reset() | |
2519 | except: # re-raises |
|
2526 | except: # re-raises | |
2520 | if edited: |
|
2527 | if edited: | |
2521 | self.ui.write( |
|
2528 | self.ui.write( | |
2522 | _('note: commit message saved in %s\n') % msgfn) |
|
2529 | _('note: commit message saved in %s\n') % msgfn) | |
2523 | raise |
|
2530 | raise | |
2524 |
|
2531 | |||
2525 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
2532 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
2526 | # hack for command that use a temporary commit (eg: histedit) |
|
2533 | # hack for command that use a temporary commit (eg: histedit) | |
2527 | # temporary commit got stripped before hook release |
|
2534 | # temporary commit got stripped before hook release | |
2528 | if self.changelog.hasnode(ret): |
|
2535 | if self.changelog.hasnode(ret): | |
2529 | self.hook("commit", node=node, parent1=parent1, |
|
2536 | self.hook("commit", node=node, parent1=parent1, | |
2530 | parent2=parent2) |
|
2537 | parent2=parent2) | |
2531 | self._afterlock(commithook) |
|
2538 | self._afterlock(commithook) | |
2532 | return ret |
|
2539 | return ret | |
2533 |
|
2540 | |||
2534 | @unfilteredmethod |
|
2541 | @unfilteredmethod | |
2535 | def commitctx(self, ctx, error=False): |
|
2542 | def commitctx(self, ctx, error=False): | |
2536 | """Add a new revision to current repository. |
|
2543 | """Add a new revision to current repository. | |
2537 | Revision information is passed via the context argument. |
|
2544 | Revision information is passed via the context argument. | |
2538 |
|
2545 | |||
2539 | ctx.files() should list all files involved in this commit, i.e. |
|
2546 | ctx.files() should list all files involved in this commit, i.e. | |
2540 | modified/added/removed files. On merge, it may be wider than the |
|
2547 | modified/added/removed files. On merge, it may be wider than the | |
2541 | ctx.files() to be committed, since any file nodes derived directly |
|
2548 | ctx.files() to be committed, since any file nodes derived directly | |
2542 | from p1 or p2 are excluded from the committed ctx.files(). |
|
2549 | from p1 or p2 are excluded from the committed ctx.files(). | |
2543 | """ |
|
2550 | """ | |
2544 |
|
2551 | |||
2545 | p1, p2 = ctx.p1(), ctx.p2() |
|
2552 | p1, p2 = ctx.p1(), ctx.p2() | |
2546 | user = ctx.user() |
|
2553 | user = ctx.user() | |
2547 |
|
2554 | |||
2548 | with self.lock(), self.transaction("commit") as tr: |
|
2555 | with self.lock(), self.transaction("commit") as tr: | |
2549 | trp = weakref.proxy(tr) |
|
2556 | trp = weakref.proxy(tr) | |
2550 |
|
2557 | |||
2551 | if ctx.manifestnode(): |
|
2558 | if ctx.manifestnode(): | |
2552 | # reuse an existing manifest revision |
|
2559 | # reuse an existing manifest revision | |
2553 | self.ui.debug('reusing known manifest\n') |
|
2560 | self.ui.debug('reusing known manifest\n') | |
2554 | mn = ctx.manifestnode() |
|
2561 | mn = ctx.manifestnode() | |
2555 | files = ctx.files() |
|
2562 | files = ctx.files() | |
2556 | elif ctx.files(): |
|
2563 | elif ctx.files(): | |
2557 | m1ctx = p1.manifestctx() |
|
2564 | m1ctx = p1.manifestctx() | |
2558 | m2ctx = p2.manifestctx() |
|
2565 | m2ctx = p2.manifestctx() | |
2559 | mctx = m1ctx.copy() |
|
2566 | mctx = m1ctx.copy() | |
2560 |
|
2567 | |||
2561 | m = mctx.read() |
|
2568 | m = mctx.read() | |
2562 | m1 = m1ctx.read() |
|
2569 | m1 = m1ctx.read() | |
2563 | m2 = m2ctx.read() |
|
2570 | m2 = m2ctx.read() | |
2564 |
|
2571 | |||
2565 | # check in files |
|
2572 | # check in files | |
2566 | added = [] |
|
2573 | added = [] | |
2567 | changed = [] |
|
2574 | changed = [] | |
2568 | removed = list(ctx.removed()) |
|
2575 | removed = list(ctx.removed()) | |
2569 | linkrev = len(self) |
|
2576 | linkrev = len(self) | |
2570 | self.ui.note(_("committing files:\n")) |
|
2577 | self.ui.note(_("committing files:\n")) | |
2571 | uipathfn = scmutil.getuipathfn(self) |
|
2578 | uipathfn = scmutil.getuipathfn(self) | |
2572 | for f in sorted(ctx.modified() + ctx.added()): |
|
2579 | for f in sorted(ctx.modified() + ctx.added()): | |
2573 | self.ui.note(uipathfn(f) + "\n") |
|
2580 | self.ui.note(uipathfn(f) + "\n") | |
2574 | try: |
|
2581 | try: | |
2575 | fctx = ctx[f] |
|
2582 | fctx = ctx[f] | |
2576 | if fctx is None: |
|
2583 | if fctx is None: | |
2577 | removed.append(f) |
|
2584 | removed.append(f) | |
2578 | else: |
|
2585 | else: | |
2579 | added.append(f) |
|
2586 | added.append(f) | |
2580 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
2587 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
2581 | trp, changed) |
|
2588 | trp, changed) | |
2582 | m.setflag(f, fctx.flags()) |
|
2589 | m.setflag(f, fctx.flags()) | |
2583 | except OSError: |
|
2590 | except OSError: | |
2584 | self.ui.warn(_("trouble committing %s!\n") % |
|
2591 | self.ui.warn(_("trouble committing %s!\n") % | |
2585 | uipathfn(f)) |
|
2592 | uipathfn(f)) | |
2586 | raise |
|
2593 | raise | |
2587 | except IOError as inst: |
|
2594 | except IOError as inst: | |
2588 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
2595 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
2589 | if error or errcode and errcode != errno.ENOENT: |
|
2596 | if error or errcode and errcode != errno.ENOENT: | |
2590 | self.ui.warn(_("trouble committing %s!\n") % |
|
2597 | self.ui.warn(_("trouble committing %s!\n") % | |
2591 | uipathfn(f)) |
|
2598 | uipathfn(f)) | |
2592 | raise |
|
2599 | raise | |
2593 |
|
2600 | |||
2594 | # update manifest |
|
2601 | # update manifest | |
2595 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
2602 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
2596 | drop = [f for f in removed if f in m] |
|
2603 | drop = [f for f in removed if f in m] | |
2597 | for f in drop: |
|
2604 | for f in drop: | |
2598 | del m[f] |
|
2605 | del m[f] | |
2599 | files = changed + removed |
|
2606 | files = changed + removed | |
2600 | md = None |
|
2607 | md = None | |
2601 | if not files: |
|
2608 | if not files: | |
2602 | # if no "files" actually changed in terms of the changelog, |
|
2609 | # if no "files" actually changed in terms of the changelog, | |
2603 | # try hard to detect unmodified manifest entry so that the |
|
2610 | # try hard to detect unmodified manifest entry so that the | |
2604 | # exact same commit can be reproduced later on convert. |
|
2611 | # exact same commit can be reproduced later on convert. | |
2605 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) |
|
2612 | md = m1.diff(m, scmutil.matchfiles(self, ctx.files())) | |
2606 | if not files and md: |
|
2613 | if not files and md: | |
2607 | self.ui.debug('not reusing manifest (no file change in ' |
|
2614 | self.ui.debug('not reusing manifest (no file change in ' | |
2608 | 'changelog, but manifest differs)\n') |
|
2615 | 'changelog, but manifest differs)\n') | |
2609 | if files or md: |
|
2616 | if files or md: | |
2610 | self.ui.note(_("committing manifest\n")) |
|
2617 | self.ui.note(_("committing manifest\n")) | |
2611 | # we're using narrowmatch here since it's already applied at |
|
2618 | # we're using narrowmatch here since it's already applied at | |
2612 | # other stages (such as dirstate.walk), so we're already |
|
2619 | # other stages (such as dirstate.walk), so we're already | |
2613 | # ignoring things outside of narrowspec in most cases. The |
|
2620 | # ignoring things outside of narrowspec in most cases. The | |
2614 | # one case where we might have files outside the narrowspec |
|
2621 | # one case where we might have files outside the narrowspec | |
2615 | # at this point is merges, and we already error out in the |
|
2622 | # at this point is merges, and we already error out in the | |
2616 | # case where the merge has files outside of the narrowspec, |
|
2623 | # case where the merge has files outside of the narrowspec, | |
2617 | # so this is safe. |
|
2624 | # so this is safe. | |
2618 | mn = mctx.write(trp, linkrev, |
|
2625 | mn = mctx.write(trp, linkrev, | |
2619 | p1.manifestnode(), p2.manifestnode(), |
|
2626 | p1.manifestnode(), p2.manifestnode(), | |
2620 | added, drop, match=self.narrowmatch()) |
|
2627 | added, drop, match=self.narrowmatch()) | |
2621 | else: |
|
2628 | else: | |
2622 | self.ui.debug('reusing manifest form p1 (listed files ' |
|
2629 | self.ui.debug('reusing manifest form p1 (listed files ' | |
2623 | 'actually unchanged)\n') |
|
2630 | 'actually unchanged)\n') | |
2624 | mn = p1.manifestnode() |
|
2631 | mn = p1.manifestnode() | |
2625 | else: |
|
2632 | else: | |
2626 | self.ui.debug('reusing manifest from p1 (no file change)\n') |
|
2633 | self.ui.debug('reusing manifest from p1 (no file change)\n') | |
2627 | mn = p1.manifestnode() |
|
2634 | mn = p1.manifestnode() | |
2628 | files = [] |
|
2635 | files = [] | |
2629 |
|
2636 | |||
2630 | # update changelog |
|
2637 | # update changelog | |
2631 | self.ui.note(_("committing changelog\n")) |
|
2638 | self.ui.note(_("committing changelog\n")) | |
2632 | self.changelog.delayupdate(tr) |
|
2639 | self.changelog.delayupdate(tr) | |
2633 | n = self.changelog.add(mn, files, ctx.description(), |
|
2640 | n = self.changelog.add(mn, files, ctx.description(), | |
2634 | trp, p1.node(), p2.node(), |
|
2641 | trp, p1.node(), p2.node(), | |
2635 | user, ctx.date(), ctx.extra().copy()) |
|
2642 | user, ctx.date(), ctx.extra().copy()) | |
2636 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
2643 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
2637 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
2644 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
2638 | parent2=xp2) |
|
2645 | parent2=xp2) | |
2639 | # set the new commit is proper phase |
|
2646 | # set the new commit is proper phase | |
2640 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
2647 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
2641 | if targetphase: |
|
2648 | if targetphase: | |
2642 | # retract boundary do not alter parent changeset. |
|
2649 | # retract boundary do not alter parent changeset. | |
2643 | # if a parent have higher the resulting phase will |
|
2650 | # if a parent have higher the resulting phase will | |
2644 | # be compliant anyway |
|
2651 | # be compliant anyway | |
2645 | # |
|
2652 | # | |
2646 | # if minimal phase was 0 we don't need to retract anything |
|
2653 | # if minimal phase was 0 we don't need to retract anything | |
2647 | phases.registernew(self, tr, targetphase, [n]) |
|
2654 | phases.registernew(self, tr, targetphase, [n]) | |
2648 | return n |
|
2655 | return n | |
2649 |
|
2656 | |||
2650 | @unfilteredmethod |
|
2657 | @unfilteredmethod | |
2651 | def destroying(self): |
|
2658 | def destroying(self): | |
2652 | '''Inform the repository that nodes are about to be destroyed. |
|
2659 | '''Inform the repository that nodes are about to be destroyed. | |
2653 | Intended for use by strip and rollback, so there's a common |
|
2660 | Intended for use by strip and rollback, so there's a common | |
2654 | place for anything that has to be done before destroying history. |
|
2661 | place for anything that has to be done before destroying history. | |
2655 |
|
2662 | |||
2656 | This is mostly useful for saving state that is in memory and waiting |
|
2663 | This is mostly useful for saving state that is in memory and waiting | |
2657 | to be flushed when the current lock is released. Because a call to |
|
2664 | to be flushed when the current lock is released. Because a call to | |
2658 | destroyed is imminent, the repo will be invalidated causing those |
|
2665 | destroyed is imminent, the repo will be invalidated causing those | |
2659 | changes to stay in memory (waiting for the next unlock), or vanish |
|
2666 | changes to stay in memory (waiting for the next unlock), or vanish | |
2660 | completely. |
|
2667 | completely. | |
2661 | ''' |
|
2668 | ''' | |
2662 | # When using the same lock to commit and strip, the phasecache is left |
|
2669 | # When using the same lock to commit and strip, the phasecache is left | |
2663 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
2670 | # dirty after committing. Then when we strip, the repo is invalidated, | |
2664 | # causing those changes to disappear. |
|
2671 | # causing those changes to disappear. | |
2665 | if '_phasecache' in vars(self): |
|
2672 | if '_phasecache' in vars(self): | |
2666 | self._phasecache.write() |
|
2673 | self._phasecache.write() | |
2667 |
|
2674 | |||
2668 | @unfilteredmethod |
|
2675 | @unfilteredmethod | |
2669 | def destroyed(self): |
|
2676 | def destroyed(self): | |
2670 | '''Inform the repository that nodes have been destroyed. |
|
2677 | '''Inform the repository that nodes have been destroyed. | |
2671 | Intended for use by strip and rollback, so there's a common |
|
2678 | Intended for use by strip and rollback, so there's a common | |
2672 | place for anything that has to be done after destroying history. |
|
2679 | place for anything that has to be done after destroying history. | |
2673 | ''' |
|
2680 | ''' | |
2674 | # When one tries to: |
|
2681 | # When one tries to: | |
2675 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
2682 | # 1) destroy nodes thus calling this method (e.g. strip) | |
2676 | # 2) use phasecache somewhere (e.g. commit) |
|
2683 | # 2) use phasecache somewhere (e.g. commit) | |
2677 | # |
|
2684 | # | |
2678 | # then 2) will fail because the phasecache contains nodes that were |
|
2685 | # then 2) will fail because the phasecache contains nodes that were | |
2679 | # removed. We can either remove phasecache from the filecache, |
|
2686 | # removed. We can either remove phasecache from the filecache, | |
2680 | # causing it to reload next time it is accessed, or simply filter |
|
2687 | # causing it to reload next time it is accessed, or simply filter | |
2681 | # the removed nodes now and write the updated cache. |
|
2688 | # the removed nodes now and write the updated cache. | |
2682 | self._phasecache.filterunknown(self) |
|
2689 | self._phasecache.filterunknown(self) | |
2683 | self._phasecache.write() |
|
2690 | self._phasecache.write() | |
2684 |
|
2691 | |||
2685 | # refresh all repository caches |
|
2692 | # refresh all repository caches | |
2686 | self.updatecaches() |
|
2693 | self.updatecaches() | |
2687 |
|
2694 | |||
2688 | # Ensure the persistent tag cache is updated. Doing it now |
|
2695 | # Ensure the persistent tag cache is updated. Doing it now | |
2689 | # means that the tag cache only has to worry about destroyed |
|
2696 | # means that the tag cache only has to worry about destroyed | |
2690 | # heads immediately after a strip/rollback. That in turn |
|
2697 | # heads immediately after a strip/rollback. That in turn | |
2691 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
2698 | # guarantees that "cachetip == currenttip" (comparing both rev | |
2692 | # and node) always means no nodes have been added or destroyed. |
|
2699 | # and node) always means no nodes have been added or destroyed. | |
2693 |
|
2700 | |||
2694 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
2701 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
2695 | # head, refresh the tag cache, then immediately add a new head. |
|
2702 | # head, refresh the tag cache, then immediately add a new head. | |
2696 | # But I think doing it this way is necessary for the "instant |
|
2703 | # But I think doing it this way is necessary for the "instant | |
2697 | # tag cache retrieval" case to work. |
|
2704 | # tag cache retrieval" case to work. | |
2698 | self.invalidate() |
|
2705 | self.invalidate() | |
2699 |
|
2706 | |||
2700 | def status(self, node1='.', node2=None, match=None, |
|
2707 | def status(self, node1='.', node2=None, match=None, | |
2701 | ignored=False, clean=False, unknown=False, |
|
2708 | ignored=False, clean=False, unknown=False, | |
2702 | listsubrepos=False): |
|
2709 | listsubrepos=False): | |
2703 | '''a convenience method that calls node1.status(node2)''' |
|
2710 | '''a convenience method that calls node1.status(node2)''' | |
2704 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
2711 | return self[node1].status(node2, match, ignored, clean, unknown, | |
2705 | listsubrepos) |
|
2712 | listsubrepos) | |
2706 |
|
2713 | |||
2707 | def addpostdsstatus(self, ps): |
|
2714 | def addpostdsstatus(self, ps): | |
2708 | """Add a callback to run within the wlock, at the point at which status |
|
2715 | """Add a callback to run within the wlock, at the point at which status | |
2709 | fixups happen. |
|
2716 | fixups happen. | |
2710 |
|
2717 | |||
2711 | On status completion, callback(wctx, status) will be called with the |
|
2718 | On status completion, callback(wctx, status) will be called with the | |
2712 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
2719 | wlock held, unless the dirstate has changed from underneath or the wlock | |
2713 | couldn't be grabbed. |
|
2720 | couldn't be grabbed. | |
2714 |
|
2721 | |||
2715 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
2722 | Callbacks should not capture and use a cached copy of the dirstate -- | |
2716 | it might change in the meanwhile. Instead, they should access the |
|
2723 | it might change in the meanwhile. Instead, they should access the | |
2717 | dirstate via wctx.repo().dirstate. |
|
2724 | dirstate via wctx.repo().dirstate. | |
2718 |
|
2725 | |||
2719 | This list is emptied out after each status run -- extensions should |
|
2726 | This list is emptied out after each status run -- extensions should | |
2720 | make sure it adds to this list each time dirstate.status is called. |
|
2727 | make sure it adds to this list each time dirstate.status is called. | |
2721 | Extensions should also make sure they don't call this for statuses |
|
2728 | Extensions should also make sure they don't call this for statuses | |
2722 | that don't involve the dirstate. |
|
2729 | that don't involve the dirstate. | |
2723 | """ |
|
2730 | """ | |
2724 |
|
2731 | |||
2725 | # The list is located here for uniqueness reasons -- it is actually |
|
2732 | # The list is located here for uniqueness reasons -- it is actually | |
2726 | # managed by the workingctx, but that isn't unique per-repo. |
|
2733 | # managed by the workingctx, but that isn't unique per-repo. | |
2727 | self._postdsstatus.append(ps) |
|
2734 | self._postdsstatus.append(ps) | |
2728 |
|
2735 | |||
2729 | def postdsstatus(self): |
|
2736 | def postdsstatus(self): | |
2730 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
2737 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
2731 | return self._postdsstatus |
|
2738 | return self._postdsstatus | |
2732 |
|
2739 | |||
2733 | def clearpostdsstatus(self): |
|
2740 | def clearpostdsstatus(self): | |
2734 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
2741 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
2735 | del self._postdsstatus[:] |
|
2742 | del self._postdsstatus[:] | |
2736 |
|
2743 | |||
2737 | def heads(self, start=None): |
|
2744 | def heads(self, start=None): | |
2738 | if start is None: |
|
2745 | if start is None: | |
2739 | cl = self.changelog |
|
2746 | cl = self.changelog | |
2740 | headrevs = reversed(cl.headrevs()) |
|
2747 | headrevs = reversed(cl.headrevs()) | |
2741 | return [cl.node(rev) for rev in headrevs] |
|
2748 | return [cl.node(rev) for rev in headrevs] | |
2742 |
|
2749 | |||
2743 | heads = self.changelog.heads(start) |
|
2750 | heads = self.changelog.heads(start) | |
2744 | # sort the output in rev descending order |
|
2751 | # sort the output in rev descending order | |
2745 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
2752 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
2746 |
|
2753 | |||
2747 | def branchheads(self, branch=None, start=None, closed=False): |
|
2754 | def branchheads(self, branch=None, start=None, closed=False): | |
2748 | '''return a (possibly filtered) list of heads for the given branch |
|
2755 | '''return a (possibly filtered) list of heads for the given branch | |
2749 |
|
2756 | |||
2750 | Heads are returned in topological order, from newest to oldest. |
|
2757 | Heads are returned in topological order, from newest to oldest. | |
2751 | If branch is None, use the dirstate branch. |
|
2758 | If branch is None, use the dirstate branch. | |
2752 | If start is not None, return only heads reachable from start. |
|
2759 | If start is not None, return only heads reachable from start. | |
2753 | If closed is True, return heads that are marked as closed as well. |
|
2760 | If closed is True, return heads that are marked as closed as well. | |
2754 | ''' |
|
2761 | ''' | |
2755 | if branch is None: |
|
2762 | if branch is None: | |
2756 | branch = self[None].branch() |
|
2763 | branch = self[None].branch() | |
2757 | branches = self.branchmap() |
|
2764 | branches = self.branchmap() | |
2758 | if not branches.hasbranch(branch): |
|
2765 | if not branches.hasbranch(branch): | |
2759 | return [] |
|
2766 | return [] | |
2760 | # the cache returns heads ordered lowest to highest |
|
2767 | # the cache returns heads ordered lowest to highest | |
2761 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
2768 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
2762 | if start is not None: |
|
2769 | if start is not None: | |
2763 | # filter out the heads that cannot be reached from startrev |
|
2770 | # filter out the heads that cannot be reached from startrev | |
2764 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
2771 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
2765 | bheads = [h for h in bheads if h in fbheads] |
|
2772 | bheads = [h for h in bheads if h in fbheads] | |
2766 | return bheads |
|
2773 | return bheads | |
2767 |
|
2774 | |||
2768 | def branches(self, nodes): |
|
2775 | def branches(self, nodes): | |
2769 | if not nodes: |
|
2776 | if not nodes: | |
2770 | nodes = [self.changelog.tip()] |
|
2777 | nodes = [self.changelog.tip()] | |
2771 | b = [] |
|
2778 | b = [] | |
2772 | for n in nodes: |
|
2779 | for n in nodes: | |
2773 | t = n |
|
2780 | t = n | |
2774 | while True: |
|
2781 | while True: | |
2775 | p = self.changelog.parents(n) |
|
2782 | p = self.changelog.parents(n) | |
2776 | if p[1] != nullid or p[0] == nullid: |
|
2783 | if p[1] != nullid or p[0] == nullid: | |
2777 | b.append((t, n, p[0], p[1])) |
|
2784 | b.append((t, n, p[0], p[1])) | |
2778 | break |
|
2785 | break | |
2779 | n = p[0] |
|
2786 | n = p[0] | |
2780 | return b |
|
2787 | return b | |
2781 |
|
2788 | |||
2782 | def between(self, pairs): |
|
2789 | def between(self, pairs): | |
2783 | r = [] |
|
2790 | r = [] | |
2784 |
|
2791 | |||
2785 | for top, bottom in pairs: |
|
2792 | for top, bottom in pairs: | |
2786 | n, l, i = top, [], 0 |
|
2793 | n, l, i = top, [], 0 | |
2787 | f = 1 |
|
2794 | f = 1 | |
2788 |
|
2795 | |||
2789 | while n != bottom and n != nullid: |
|
2796 | while n != bottom and n != nullid: | |
2790 | p = self.changelog.parents(n)[0] |
|
2797 | p = self.changelog.parents(n)[0] | |
2791 | if i == f: |
|
2798 | if i == f: | |
2792 | l.append(n) |
|
2799 | l.append(n) | |
2793 | f = f * 2 |
|
2800 | f = f * 2 | |
2794 | n = p |
|
2801 | n = p | |
2795 | i += 1 |
|
2802 | i += 1 | |
2796 |
|
2803 | |||
2797 | r.append(l) |
|
2804 | r.append(l) | |
2798 |
|
2805 | |||
2799 | return r |
|
2806 | return r | |
2800 |
|
2807 | |||
2801 | def checkpush(self, pushop): |
|
2808 | def checkpush(self, pushop): | |
2802 | """Extensions can override this function if additional checks have |
|
2809 | """Extensions can override this function if additional checks have | |
2803 | to be performed before pushing, or call it if they override push |
|
2810 | to be performed before pushing, or call it if they override push | |
2804 | command. |
|
2811 | command. | |
2805 | """ |
|
2812 | """ | |
2806 |
|
2813 | |||
2807 | @unfilteredpropertycache |
|
2814 | @unfilteredpropertycache | |
2808 | def prepushoutgoinghooks(self): |
|
2815 | def prepushoutgoinghooks(self): | |
2809 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
2816 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
2810 | methods, which are called before pushing changesets. |
|
2817 | methods, which are called before pushing changesets. | |
2811 | """ |
|
2818 | """ | |
2812 | return util.hooks() |
|
2819 | return util.hooks() | |
2813 |
|
2820 | |||
2814 | def pushkey(self, namespace, key, old, new): |
|
2821 | def pushkey(self, namespace, key, old, new): | |
2815 | try: |
|
2822 | try: | |
2816 | tr = self.currenttransaction() |
|
2823 | tr = self.currenttransaction() | |
2817 | hookargs = {} |
|
2824 | hookargs = {} | |
2818 | if tr is not None: |
|
2825 | if tr is not None: | |
2819 | hookargs.update(tr.hookargs) |
|
2826 | hookargs.update(tr.hookargs) | |
2820 | hookargs = pycompat.strkwargs(hookargs) |
|
2827 | hookargs = pycompat.strkwargs(hookargs) | |
2821 | hookargs[r'namespace'] = namespace |
|
2828 | hookargs[r'namespace'] = namespace | |
2822 | hookargs[r'key'] = key |
|
2829 | hookargs[r'key'] = key | |
2823 | hookargs[r'old'] = old |
|
2830 | hookargs[r'old'] = old | |
2824 | hookargs[r'new'] = new |
|
2831 | hookargs[r'new'] = new | |
2825 | self.hook('prepushkey', throw=True, **hookargs) |
|
2832 | self.hook('prepushkey', throw=True, **hookargs) | |
2826 | except error.HookAbort as exc: |
|
2833 | except error.HookAbort as exc: | |
2827 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
2834 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
2828 | if exc.hint: |
|
2835 | if exc.hint: | |
2829 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
2836 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
2830 | return False |
|
2837 | return False | |
2831 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
2838 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
2832 | ret = pushkey.push(self, namespace, key, old, new) |
|
2839 | ret = pushkey.push(self, namespace, key, old, new) | |
2833 | def runhook(): |
|
2840 | def runhook(): | |
2834 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2841 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
2835 | ret=ret) |
|
2842 | ret=ret) | |
2836 | self._afterlock(runhook) |
|
2843 | self._afterlock(runhook) | |
2837 | return ret |
|
2844 | return ret | |
2838 |
|
2845 | |||
2839 | def listkeys(self, namespace): |
|
2846 | def listkeys(self, namespace): | |
2840 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2847 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
2841 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
2848 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
2842 | values = pushkey.list(self, namespace) |
|
2849 | values = pushkey.list(self, namespace) | |
2843 | self.hook('listkeys', namespace=namespace, values=values) |
|
2850 | self.hook('listkeys', namespace=namespace, values=values) | |
2844 | return values |
|
2851 | return values | |
2845 |
|
2852 | |||
2846 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2853 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
2847 | '''used to test argument passing over the wire''' |
|
2854 | '''used to test argument passing over the wire''' | |
2848 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
2855 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
2849 | pycompat.bytestr(four), |
|
2856 | pycompat.bytestr(four), | |
2850 | pycompat.bytestr(five)) |
|
2857 | pycompat.bytestr(five)) | |
2851 |
|
2858 | |||
2852 | def savecommitmessage(self, text): |
|
2859 | def savecommitmessage(self, text): | |
2853 | fp = self.vfs('last-message.txt', 'wb') |
|
2860 | fp = self.vfs('last-message.txt', 'wb') | |
2854 | try: |
|
2861 | try: | |
2855 | fp.write(text) |
|
2862 | fp.write(text) | |
2856 | finally: |
|
2863 | finally: | |
2857 | fp.close() |
|
2864 | fp.close() | |
2858 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
2865 | return self.pathto(fp.name[len(self.root) + 1:]) | |
2859 |
|
2866 | |||
2860 | # used to avoid circular references so destructors work |
|
2867 | # used to avoid circular references so destructors work | |
2861 | def aftertrans(files): |
|
2868 | def aftertrans(files): | |
2862 | renamefiles = [tuple(t) for t in files] |
|
2869 | renamefiles = [tuple(t) for t in files] | |
2863 | def a(): |
|
2870 | def a(): | |
2864 | for vfs, src, dest in renamefiles: |
|
2871 | for vfs, src, dest in renamefiles: | |
2865 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
2872 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
2866 | # leaving both src and dest on disk. delete dest to make sure |
|
2873 | # leaving both src and dest on disk. delete dest to make sure | |
2867 | # the rename couldn't be such a no-op. |
|
2874 | # the rename couldn't be such a no-op. | |
2868 | vfs.tryunlink(dest) |
|
2875 | vfs.tryunlink(dest) | |
2869 | try: |
|
2876 | try: | |
2870 | vfs.rename(src, dest) |
|
2877 | vfs.rename(src, dest) | |
2871 | except OSError: # journal file does not yet exist |
|
2878 | except OSError: # journal file does not yet exist | |
2872 | pass |
|
2879 | pass | |
2873 | return a |
|
2880 | return a | |
2874 |
|
2881 | |||
2875 | def undoname(fn): |
|
2882 | def undoname(fn): | |
2876 | base, name = os.path.split(fn) |
|
2883 | base, name = os.path.split(fn) | |
2877 | assert name.startswith('journal') |
|
2884 | assert name.startswith('journal') | |
2878 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2885 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
2879 |
|
2886 | |||
2880 | def instance(ui, path, create, intents=None, createopts=None): |
|
2887 | def instance(ui, path, create, intents=None, createopts=None): | |
2881 | localpath = util.urllocalpath(path) |
|
2888 | localpath = util.urllocalpath(path) | |
2882 | if create: |
|
2889 | if create: | |
2883 | createrepository(ui, localpath, createopts=createopts) |
|
2890 | createrepository(ui, localpath, createopts=createopts) | |
2884 |
|
2891 | |||
2885 | return makelocalrepository(ui, localpath, intents=intents) |
|
2892 | return makelocalrepository(ui, localpath, intents=intents) | |
2886 |
|
2893 | |||
2887 | def islocal(path): |
|
2894 | def islocal(path): | |
2888 | return True |
|
2895 | return True | |
2889 |
|
2896 | |||
2890 | def defaultcreateopts(ui, createopts=None): |
|
2897 | def defaultcreateopts(ui, createopts=None): | |
2891 | """Populate the default creation options for a repository. |
|
2898 | """Populate the default creation options for a repository. | |
2892 |
|
2899 | |||
2893 | A dictionary of explicitly requested creation options can be passed |
|
2900 | A dictionary of explicitly requested creation options can be passed | |
2894 | in. Missing keys will be populated. |
|
2901 | in. Missing keys will be populated. | |
2895 | """ |
|
2902 | """ | |
2896 | createopts = dict(createopts or {}) |
|
2903 | createopts = dict(createopts or {}) | |
2897 |
|
2904 | |||
2898 | if 'backend' not in createopts: |
|
2905 | if 'backend' not in createopts: | |
2899 | # experimental config: storage.new-repo-backend |
|
2906 | # experimental config: storage.new-repo-backend | |
2900 | createopts['backend'] = ui.config('storage', 'new-repo-backend') |
|
2907 | createopts['backend'] = ui.config('storage', 'new-repo-backend') | |
2901 |
|
2908 | |||
2902 | return createopts |
|
2909 | return createopts | |
2903 |
|
2910 | |||
2904 | def newreporequirements(ui, createopts): |
|
2911 | def newreporequirements(ui, createopts): | |
2905 | """Determine the set of requirements for a new local repository. |
|
2912 | """Determine the set of requirements for a new local repository. | |
2906 |
|
2913 | |||
2907 | Extensions can wrap this function to specify custom requirements for |
|
2914 | Extensions can wrap this function to specify custom requirements for | |
2908 | new repositories. |
|
2915 | new repositories. | |
2909 | """ |
|
2916 | """ | |
2910 | # If the repo is being created from a shared repository, we copy |
|
2917 | # If the repo is being created from a shared repository, we copy | |
2911 | # its requirements. |
|
2918 | # its requirements. | |
2912 | if 'sharedrepo' in createopts: |
|
2919 | if 'sharedrepo' in createopts: | |
2913 | requirements = set(createopts['sharedrepo'].requirements) |
|
2920 | requirements = set(createopts['sharedrepo'].requirements) | |
2914 | if createopts.get('sharedrelative'): |
|
2921 | if createopts.get('sharedrelative'): | |
2915 | requirements.add('relshared') |
|
2922 | requirements.add('relshared') | |
2916 | else: |
|
2923 | else: | |
2917 | requirements.add('shared') |
|
2924 | requirements.add('shared') | |
2918 |
|
2925 | |||
2919 | return requirements |
|
2926 | return requirements | |
2920 |
|
2927 | |||
2921 | if 'backend' not in createopts: |
|
2928 | if 'backend' not in createopts: | |
2922 | raise error.ProgrammingError('backend key not present in createopts; ' |
|
2929 | raise error.ProgrammingError('backend key not present in createopts; ' | |
2923 | 'was defaultcreateopts() called?') |
|
2930 | 'was defaultcreateopts() called?') | |
2924 |
|
2931 | |||
2925 | if createopts['backend'] != 'revlogv1': |
|
2932 | if createopts['backend'] != 'revlogv1': | |
2926 | raise error.Abort(_('unable to determine repository requirements for ' |
|
2933 | raise error.Abort(_('unable to determine repository requirements for ' | |
2927 | 'storage backend: %s') % createopts['backend']) |
|
2934 | 'storage backend: %s') % createopts['backend']) | |
2928 |
|
2935 | |||
2929 | requirements = {'revlogv1'} |
|
2936 | requirements = {'revlogv1'} | |
2930 | if ui.configbool('format', 'usestore'): |
|
2937 | if ui.configbool('format', 'usestore'): | |
2931 | requirements.add('store') |
|
2938 | requirements.add('store') | |
2932 | if ui.configbool('format', 'usefncache'): |
|
2939 | if ui.configbool('format', 'usefncache'): | |
2933 | requirements.add('fncache') |
|
2940 | requirements.add('fncache') | |
2934 | if ui.configbool('format', 'dotencode'): |
|
2941 | if ui.configbool('format', 'dotencode'): | |
2935 | requirements.add('dotencode') |
|
2942 | requirements.add('dotencode') | |
2936 |
|
2943 | |||
2937 | compengine = ui.config('format', 'revlog-compression') |
|
2944 | compengine = ui.config('format', 'revlog-compression') | |
2938 | if compengine not in util.compengines: |
|
2945 | if compengine not in util.compengines: | |
2939 | raise error.Abort(_('compression engine %s defined by ' |
|
2946 | raise error.Abort(_('compression engine %s defined by ' | |
2940 | 'format.revlog-compression not available') % |
|
2947 | 'format.revlog-compression not available') % | |
2941 | compengine, |
|
2948 | compengine, | |
2942 | hint=_('run "hg debuginstall" to list available ' |
|
2949 | hint=_('run "hg debuginstall" to list available ' | |
2943 | 'compression engines')) |
|
2950 | 'compression engines')) | |
2944 |
|
2951 | |||
2945 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2952 | # zlib is the historical default and doesn't need an explicit requirement. | |
2946 |
if compengine |
|
2953 | elif compengine == 'zstd': | |
|
2954 | requirements.add('revlog-compression-zstd') | |||
|
2955 | elif compengine != 'zlib': | |||
2947 | requirements.add('exp-compression-%s' % compengine) |
|
2956 | requirements.add('exp-compression-%s' % compengine) | |
2948 |
|
2957 | |||
2949 | if scmutil.gdinitconfig(ui): |
|
2958 | if scmutil.gdinitconfig(ui): | |
2950 | requirements.add('generaldelta') |
|
2959 | requirements.add('generaldelta') | |
2951 | if ui.configbool('format', 'sparse-revlog'): |
|
2960 | if ui.configbool('format', 'sparse-revlog'): | |
2952 | requirements.add(SPARSEREVLOG_REQUIREMENT) |
|
2961 | requirements.add(SPARSEREVLOG_REQUIREMENT) | |
2953 | if ui.configbool('experimental', 'treemanifest'): |
|
2962 | if ui.configbool('experimental', 'treemanifest'): | |
2954 | requirements.add('treemanifest') |
|
2963 | requirements.add('treemanifest') | |
2955 |
|
2964 | |||
2956 | revlogv2 = ui.config('experimental', 'revlogv2') |
|
2965 | revlogv2 = ui.config('experimental', 'revlogv2') | |
2957 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': |
|
2966 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': | |
2958 | requirements.remove('revlogv1') |
|
2967 | requirements.remove('revlogv1') | |
2959 | # generaldelta is implied by revlogv2. |
|
2968 | # generaldelta is implied by revlogv2. | |
2960 | requirements.discard('generaldelta') |
|
2969 | requirements.discard('generaldelta') | |
2961 | requirements.add(REVLOGV2_REQUIREMENT) |
|
2970 | requirements.add(REVLOGV2_REQUIREMENT) | |
2962 | # experimental config: format.internal-phase |
|
2971 | # experimental config: format.internal-phase | |
2963 | if ui.configbool('format', 'internal-phase'): |
|
2972 | if ui.configbool('format', 'internal-phase'): | |
2964 | requirements.add('internal-phase') |
|
2973 | requirements.add('internal-phase') | |
2965 |
|
2974 | |||
2966 | if createopts.get('narrowfiles'): |
|
2975 | if createopts.get('narrowfiles'): | |
2967 | requirements.add(repository.NARROW_REQUIREMENT) |
|
2976 | requirements.add(repository.NARROW_REQUIREMENT) | |
2968 |
|
2977 | |||
2969 | if createopts.get('lfs'): |
|
2978 | if createopts.get('lfs'): | |
2970 | requirements.add('lfs') |
|
2979 | requirements.add('lfs') | |
2971 |
|
2980 | |||
2972 | return requirements |
|
2981 | return requirements | |
2973 |
|
2982 | |||
2974 | def filterknowncreateopts(ui, createopts): |
|
2983 | def filterknowncreateopts(ui, createopts): | |
2975 | """Filters a dict of repo creation options against options that are known. |
|
2984 | """Filters a dict of repo creation options against options that are known. | |
2976 |
|
2985 | |||
2977 | Receives a dict of repo creation options and returns a dict of those |
|
2986 | Receives a dict of repo creation options and returns a dict of those | |
2978 | options that we don't know how to handle. |
|
2987 | options that we don't know how to handle. | |
2979 |
|
2988 | |||
2980 | This function is called as part of repository creation. If the |
|
2989 | This function is called as part of repository creation. If the | |
2981 | returned dict contains any items, repository creation will not |
|
2990 | returned dict contains any items, repository creation will not | |
2982 | be allowed, as it means there was a request to create a repository |
|
2991 | be allowed, as it means there was a request to create a repository | |
2983 | with options not recognized by loaded code. |
|
2992 | with options not recognized by loaded code. | |
2984 |
|
2993 | |||
2985 | Extensions can wrap this function to filter out creation options |
|
2994 | Extensions can wrap this function to filter out creation options | |
2986 | they know how to handle. |
|
2995 | they know how to handle. | |
2987 | """ |
|
2996 | """ | |
2988 | known = { |
|
2997 | known = { | |
2989 | 'backend', |
|
2998 | 'backend', | |
2990 | 'lfs', |
|
2999 | 'lfs', | |
2991 | 'narrowfiles', |
|
3000 | 'narrowfiles', | |
2992 | 'sharedrepo', |
|
3001 | 'sharedrepo', | |
2993 | 'sharedrelative', |
|
3002 | 'sharedrelative', | |
2994 | 'shareditems', |
|
3003 | 'shareditems', | |
2995 | 'shallowfilestore', |
|
3004 | 'shallowfilestore', | |
2996 | } |
|
3005 | } | |
2997 |
|
3006 | |||
2998 | return {k: v for k, v in createopts.items() if k not in known} |
|
3007 | return {k: v for k, v in createopts.items() if k not in known} | |
2999 |
|
3008 | |||
3000 | def createrepository(ui, path, createopts=None): |
|
3009 | def createrepository(ui, path, createopts=None): | |
3001 | """Create a new repository in a vfs. |
|
3010 | """Create a new repository in a vfs. | |
3002 |
|
3011 | |||
3003 | ``path`` path to the new repo's working directory. |
|
3012 | ``path`` path to the new repo's working directory. | |
3004 | ``createopts`` options for the new repository. |
|
3013 | ``createopts`` options for the new repository. | |
3005 |
|
3014 | |||
3006 | The following keys for ``createopts`` are recognized: |
|
3015 | The following keys for ``createopts`` are recognized: | |
3007 |
|
3016 | |||
3008 | backend |
|
3017 | backend | |
3009 | The storage backend to use. |
|
3018 | The storage backend to use. | |
3010 | lfs |
|
3019 | lfs | |
3011 | Repository will be created with ``lfs`` requirement. The lfs extension |
|
3020 | Repository will be created with ``lfs`` requirement. The lfs extension | |
3012 | will automatically be loaded when the repository is accessed. |
|
3021 | will automatically be loaded when the repository is accessed. | |
3013 | narrowfiles |
|
3022 | narrowfiles | |
3014 | Set up repository to support narrow file storage. |
|
3023 | Set up repository to support narrow file storage. | |
3015 | sharedrepo |
|
3024 | sharedrepo | |
3016 | Repository object from which storage should be shared. |
|
3025 | Repository object from which storage should be shared. | |
3017 | sharedrelative |
|
3026 | sharedrelative | |
3018 | Boolean indicating if the path to the shared repo should be |
|
3027 | Boolean indicating if the path to the shared repo should be | |
3019 | stored as relative. By default, the pointer to the "parent" repo |
|
3028 | stored as relative. By default, the pointer to the "parent" repo | |
3020 | is stored as an absolute path. |
|
3029 | is stored as an absolute path. | |
3021 | shareditems |
|
3030 | shareditems | |
3022 | Set of items to share to the new repository (in addition to storage). |
|
3031 | Set of items to share to the new repository (in addition to storage). | |
3023 | shallowfilestore |
|
3032 | shallowfilestore | |
3024 | Indicates that storage for files should be shallow (not all ancestor |
|
3033 | Indicates that storage for files should be shallow (not all ancestor | |
3025 | revisions are known). |
|
3034 | revisions are known). | |
3026 | """ |
|
3035 | """ | |
3027 | createopts = defaultcreateopts(ui, createopts=createopts) |
|
3036 | createopts = defaultcreateopts(ui, createopts=createopts) | |
3028 |
|
3037 | |||
3029 | unknownopts = filterknowncreateopts(ui, createopts) |
|
3038 | unknownopts = filterknowncreateopts(ui, createopts) | |
3030 |
|
3039 | |||
3031 | if not isinstance(unknownopts, dict): |
|
3040 | if not isinstance(unknownopts, dict): | |
3032 | raise error.ProgrammingError('filterknowncreateopts() did not return ' |
|
3041 | raise error.ProgrammingError('filterknowncreateopts() did not return ' | |
3033 | 'a dict') |
|
3042 | 'a dict') | |
3034 |
|
3043 | |||
3035 | if unknownopts: |
|
3044 | if unknownopts: | |
3036 | raise error.Abort(_('unable to create repository because of unknown ' |
|
3045 | raise error.Abort(_('unable to create repository because of unknown ' | |
3037 | 'creation option: %s') % |
|
3046 | 'creation option: %s') % | |
3038 | ', '.join(sorted(unknownopts)), |
|
3047 | ', '.join(sorted(unknownopts)), | |
3039 | hint=_('is a required extension not loaded?')) |
|
3048 | hint=_('is a required extension not loaded?')) | |
3040 |
|
3049 | |||
3041 | requirements = newreporequirements(ui, createopts=createopts) |
|
3050 | requirements = newreporequirements(ui, createopts=createopts) | |
3042 |
|
3051 | |||
3043 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
3052 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
3044 |
|
3053 | |||
3045 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
|
3054 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | |
3046 | if hgvfs.exists(): |
|
3055 | if hgvfs.exists(): | |
3047 | raise error.RepoError(_('repository %s already exists') % path) |
|
3056 | raise error.RepoError(_('repository %s already exists') % path) | |
3048 |
|
3057 | |||
3049 | if 'sharedrepo' in createopts: |
|
3058 | if 'sharedrepo' in createopts: | |
3050 | sharedpath = createopts['sharedrepo'].sharedpath |
|
3059 | sharedpath = createopts['sharedrepo'].sharedpath | |
3051 |
|
3060 | |||
3052 | if createopts.get('sharedrelative'): |
|
3061 | if createopts.get('sharedrelative'): | |
3053 | try: |
|
3062 | try: | |
3054 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) |
|
3063 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) | |
3055 | except (IOError, ValueError) as e: |
|
3064 | except (IOError, ValueError) as e: | |
3056 | # ValueError is raised on Windows if the drive letters differ |
|
3065 | # ValueError is raised on Windows if the drive letters differ | |
3057 | # on each path. |
|
3066 | # on each path. | |
3058 | raise error.Abort(_('cannot calculate relative path'), |
|
3067 | raise error.Abort(_('cannot calculate relative path'), | |
3059 | hint=stringutil.forcebytestr(e)) |
|
3068 | hint=stringutil.forcebytestr(e)) | |
3060 |
|
3069 | |||
3061 | if not wdirvfs.exists(): |
|
3070 | if not wdirvfs.exists(): | |
3062 | wdirvfs.makedirs() |
|
3071 | wdirvfs.makedirs() | |
3063 |
|
3072 | |||
3064 | hgvfs.makedir(notindexed=True) |
|
3073 | hgvfs.makedir(notindexed=True) | |
3065 | if 'sharedrepo' not in createopts: |
|
3074 | if 'sharedrepo' not in createopts: | |
3066 | hgvfs.mkdir(b'cache') |
|
3075 | hgvfs.mkdir(b'cache') | |
3067 | hgvfs.mkdir(b'wcache') |
|
3076 | hgvfs.mkdir(b'wcache') | |
3068 |
|
3077 | |||
3069 | if b'store' in requirements and 'sharedrepo' not in createopts: |
|
3078 | if b'store' in requirements and 'sharedrepo' not in createopts: | |
3070 | hgvfs.mkdir(b'store') |
|
3079 | hgvfs.mkdir(b'store') | |
3071 |
|
3080 | |||
3072 | # We create an invalid changelog outside the store so very old |
|
3081 | # We create an invalid changelog outside the store so very old | |
3073 | # Mercurial versions (which didn't know about the requirements |
|
3082 | # Mercurial versions (which didn't know about the requirements | |
3074 | # file) encounter an error on reading the changelog. This |
|
3083 | # file) encounter an error on reading the changelog. This | |
3075 | # effectively locks out old clients and prevents them from |
|
3084 | # effectively locks out old clients and prevents them from | |
3076 | # mucking with a repo in an unknown format. |
|
3085 | # mucking with a repo in an unknown format. | |
3077 | # |
|
3086 | # | |
3078 | # The revlog header has version 2, which won't be recognized by |
|
3087 | # The revlog header has version 2, which won't be recognized by | |
3079 | # such old clients. |
|
3088 | # such old clients. | |
3080 | hgvfs.append(b'00changelog.i', |
|
3089 | hgvfs.append(b'00changelog.i', | |
3081 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' |
|
3090 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' | |
3082 | b'layout') |
|
3091 | b'layout') | |
3083 |
|
3092 | |||
3084 | scmutil.writerequires(hgvfs, requirements) |
|
3093 | scmutil.writerequires(hgvfs, requirements) | |
3085 |
|
3094 | |||
3086 | # Write out file telling readers where to find the shared store. |
|
3095 | # Write out file telling readers where to find the shared store. | |
3087 | if 'sharedrepo' in createopts: |
|
3096 | if 'sharedrepo' in createopts: | |
3088 | hgvfs.write(b'sharedpath', sharedpath) |
|
3097 | hgvfs.write(b'sharedpath', sharedpath) | |
3089 |
|
3098 | |||
3090 | if createopts.get('shareditems'): |
|
3099 | if createopts.get('shareditems'): | |
3091 | shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n' |
|
3100 | shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n' | |
3092 | hgvfs.write(b'shared', shared) |
|
3101 | hgvfs.write(b'shared', shared) | |
3093 |
|
3102 | |||
3094 | def poisonrepository(repo): |
|
3103 | def poisonrepository(repo): | |
3095 | """Poison a repository instance so it can no longer be used.""" |
|
3104 | """Poison a repository instance so it can no longer be used.""" | |
3096 | # Perform any cleanup on the instance. |
|
3105 | # Perform any cleanup on the instance. | |
3097 | repo.close() |
|
3106 | repo.close() | |
3098 |
|
3107 | |||
3099 | # Our strategy is to replace the type of the object with one that |
|
3108 | # Our strategy is to replace the type of the object with one that | |
3100 | # has all attribute lookups result in error. |
|
3109 | # has all attribute lookups result in error. | |
3101 | # |
|
3110 | # | |
3102 | # But we have to allow the close() method because some constructors |
|
3111 | # But we have to allow the close() method because some constructors | |
3103 | # of repos call close() on repo references. |
|
3112 | # of repos call close() on repo references. | |
3104 | class poisonedrepository(object): |
|
3113 | class poisonedrepository(object): | |
3105 | def __getattribute__(self, item): |
|
3114 | def __getattribute__(self, item): | |
3106 | if item == r'close': |
|
3115 | if item == r'close': | |
3107 | return object.__getattribute__(self, item) |
|
3116 | return object.__getattribute__(self, item) | |
3108 |
|
3117 | |||
3109 | raise error.ProgrammingError('repo instances should not be used ' |
|
3118 | raise error.ProgrammingError('repo instances should not be used ' | |
3110 | 'after unshare') |
|
3119 | 'after unshare') | |
3111 |
|
3120 | |||
3112 | def close(self): |
|
3121 | def close(self): | |
3113 | pass |
|
3122 | pass | |
3114 |
|
3123 | |||
3115 | # We may have a repoview, which intercepts __setattr__. So be sure |
|
3124 | # We may have a repoview, which intercepts __setattr__. So be sure | |
3116 | # we operate at the lowest level possible. |
|
3125 | # we operate at the lowest level possible. | |
3117 | object.__setattr__(repo, r'__class__', poisonedrepository) |
|
3126 | object.__setattr__(repo, r'__class__', poisonedrepository) |
@@ -1,949 +1,955 b'' | |||||
1 | # upgrade.py - functions for in place upgrade of Mercurial repository |
|
1 | # upgrade.py - functions for in place upgrade of Mercurial repository | |
2 | # |
|
2 | # | |
3 | # Copyright (c) 2016-present, Gregory Szorc |
|
3 | # Copyright (c) 2016-present, Gregory Szorc | |
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 stat |
|
10 | import stat | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import ( |
|
13 | from . import ( | |
14 | changelog, |
|
14 | changelog, | |
15 | error, |
|
15 | error, | |
16 | filelog, |
|
16 | filelog, | |
17 | hg, |
|
17 | hg, | |
18 | localrepo, |
|
18 | localrepo, | |
19 | manifest, |
|
19 | manifest, | |
20 | pycompat, |
|
20 | pycompat, | |
21 | revlog, |
|
21 | revlog, | |
22 | scmutil, |
|
22 | scmutil, | |
23 | util, |
|
23 | util, | |
24 | vfs as vfsmod, |
|
24 | vfs as vfsmod, | |
25 | ) |
|
25 | ) | |
26 |
|
26 | |||
27 | def requiredsourcerequirements(repo): |
|
27 | def requiredsourcerequirements(repo): | |
28 | """Obtain requirements required to be present to upgrade a repo. |
|
28 | """Obtain requirements required to be present to upgrade a repo. | |
29 |
|
29 | |||
30 | An upgrade will not be allowed if the repository doesn't have the |
|
30 | An upgrade will not be allowed if the repository doesn't have the | |
31 | requirements returned by this function. |
|
31 | requirements returned by this function. | |
32 | """ |
|
32 | """ | |
33 | return { |
|
33 | return { | |
34 | # Introduced in Mercurial 0.9.2. |
|
34 | # Introduced in Mercurial 0.9.2. | |
35 | 'revlogv1', |
|
35 | 'revlogv1', | |
36 | # Introduced in Mercurial 0.9.2. |
|
36 | # Introduced in Mercurial 0.9.2. | |
37 | 'store', |
|
37 | 'store', | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | def blocksourcerequirements(repo): |
|
40 | def blocksourcerequirements(repo): | |
41 | """Obtain requirements that will prevent an upgrade from occurring. |
|
41 | """Obtain requirements that will prevent an upgrade from occurring. | |
42 |
|
42 | |||
43 | An upgrade cannot be performed if the source repository contains a |
|
43 | An upgrade cannot be performed if the source repository contains a | |
44 | requirements in the returned set. |
|
44 | requirements in the returned set. | |
45 | """ |
|
45 | """ | |
46 | return { |
|
46 | return { | |
47 | # The upgrade code does not yet support these experimental features. |
|
47 | # The upgrade code does not yet support these experimental features. | |
48 | # This is an artificial limitation. |
|
48 | # This is an artificial limitation. | |
49 | 'treemanifest', |
|
49 | 'treemanifest', | |
50 | # This was a precursor to generaldelta and was never enabled by default. |
|
50 | # This was a precursor to generaldelta and was never enabled by default. | |
51 | # It should (hopefully) not exist in the wild. |
|
51 | # It should (hopefully) not exist in the wild. | |
52 | 'parentdelta', |
|
52 | 'parentdelta', | |
53 | # Upgrade should operate on the actual store, not the shared link. |
|
53 | # Upgrade should operate on the actual store, not the shared link. | |
54 | 'shared', |
|
54 | 'shared', | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | def supportremovedrequirements(repo): |
|
57 | def supportremovedrequirements(repo): | |
58 | """Obtain requirements that can be removed during an upgrade. |
|
58 | """Obtain requirements that can be removed during an upgrade. | |
59 |
|
59 | |||
60 | If an upgrade were to create a repository that dropped a requirement, |
|
60 | If an upgrade were to create a repository that dropped a requirement, | |
61 | the dropped requirement must appear in the returned set for the upgrade |
|
61 | the dropped requirement must appear in the returned set for the upgrade | |
62 | to be allowed. |
|
62 | to be allowed. | |
63 | """ |
|
63 | """ | |
64 | return { |
|
64 | return { | |
65 | localrepo.SPARSEREVLOG_REQUIREMENT, |
|
65 | localrepo.SPARSEREVLOG_REQUIREMENT, | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | def supporteddestrequirements(repo): |
|
68 | def supporteddestrequirements(repo): | |
69 | """Obtain requirements that upgrade supports in the destination. |
|
69 | """Obtain requirements that upgrade supports in the destination. | |
70 |
|
70 | |||
71 | If the result of the upgrade would create requirements not in this set, |
|
71 | If the result of the upgrade would create requirements not in this set, | |
72 | the upgrade is disallowed. |
|
72 | the upgrade is disallowed. | |
73 |
|
73 | |||
74 | Extensions should monkeypatch this to add their custom requirements. |
|
74 | Extensions should monkeypatch this to add their custom requirements. | |
75 | """ |
|
75 | """ | |
76 | return { |
|
76 | return { | |
77 | 'dotencode', |
|
77 | 'dotencode', | |
78 | 'fncache', |
|
78 | 'fncache', | |
79 | 'generaldelta', |
|
79 | 'generaldelta', | |
80 | 'revlogv1', |
|
80 | 'revlogv1', | |
81 | 'store', |
|
81 | 'store', | |
82 | localrepo.SPARSEREVLOG_REQUIREMENT, |
|
82 | localrepo.SPARSEREVLOG_REQUIREMENT, | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | def allowednewrequirements(repo): |
|
85 | def allowednewrequirements(repo): | |
86 | """Obtain requirements that can be added to a repository during upgrade. |
|
86 | """Obtain requirements that can be added to a repository during upgrade. | |
87 |
|
87 | |||
88 | This is used to disallow proposed requirements from being added when |
|
88 | This is used to disallow proposed requirements from being added when | |
89 | they weren't present before. |
|
89 | they weren't present before. | |
90 |
|
90 | |||
91 | We use a list of allowed requirement additions instead of a list of known |
|
91 | We use a list of allowed requirement additions instead of a list of known | |
92 | bad additions because the whitelist approach is safer and will prevent |
|
92 | bad additions because the whitelist approach is safer and will prevent | |
93 | future, unknown requirements from accidentally being added. |
|
93 | future, unknown requirements from accidentally being added. | |
94 | """ |
|
94 | """ | |
95 | return { |
|
95 | return { | |
96 | 'dotencode', |
|
96 | 'dotencode', | |
97 | 'fncache', |
|
97 | 'fncache', | |
98 | 'generaldelta', |
|
98 | 'generaldelta', | |
99 | localrepo.SPARSEREVLOG_REQUIREMENT, |
|
99 | localrepo.SPARSEREVLOG_REQUIREMENT, | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | def preservedrequirements(repo): |
|
102 | def preservedrequirements(repo): | |
103 | return set() |
|
103 | return set() | |
104 |
|
104 | |||
105 | deficiency = 'deficiency' |
|
105 | deficiency = 'deficiency' | |
106 | optimisation = 'optimization' |
|
106 | optimisation = 'optimization' | |
107 |
|
107 | |||
108 | class improvement(object): |
|
108 | class improvement(object): | |
109 | """Represents an improvement that can be made as part of an upgrade. |
|
109 | """Represents an improvement that can be made as part of an upgrade. | |
110 |
|
110 | |||
111 | The following attributes are defined on each instance: |
|
111 | The following attributes are defined on each instance: | |
112 |
|
112 | |||
113 | name |
|
113 | name | |
114 | Machine-readable string uniquely identifying this improvement. It |
|
114 | Machine-readable string uniquely identifying this improvement. It | |
115 | will be mapped to an action later in the upgrade process. |
|
115 | will be mapped to an action later in the upgrade process. | |
116 |
|
116 | |||
117 | type |
|
117 | type | |
118 | Either ``deficiency`` or ``optimisation``. A deficiency is an obvious |
|
118 | Either ``deficiency`` or ``optimisation``. A deficiency is an obvious | |
119 | problem. An optimization is an action (sometimes optional) that |
|
119 | problem. An optimization is an action (sometimes optional) that | |
120 | can be taken to further improve the state of the repository. |
|
120 | can be taken to further improve the state of the repository. | |
121 |
|
121 | |||
122 | description |
|
122 | description | |
123 | Message intended for humans explaining the improvement in more detail, |
|
123 | Message intended for humans explaining the improvement in more detail, | |
124 | including the implications of it. For ``deficiency`` types, should be |
|
124 | including the implications of it. For ``deficiency`` types, should be | |
125 | worded in the present tense. For ``optimisation`` types, should be |
|
125 | worded in the present tense. For ``optimisation`` types, should be | |
126 | worded in the future tense. |
|
126 | worded in the future tense. | |
127 |
|
127 | |||
128 | upgrademessage |
|
128 | upgrademessage | |
129 | Message intended for humans explaining what an upgrade addressing this |
|
129 | Message intended for humans explaining what an upgrade addressing this | |
130 | issue will do. Should be worded in the future tense. |
|
130 | issue will do. Should be worded in the future tense. | |
131 | """ |
|
131 | """ | |
132 | def __init__(self, name, type, description, upgrademessage): |
|
132 | def __init__(self, name, type, description, upgrademessage): | |
133 | self.name = name |
|
133 | self.name = name | |
134 | self.type = type |
|
134 | self.type = type | |
135 | self.description = description |
|
135 | self.description = description | |
136 | self.upgrademessage = upgrademessage |
|
136 | self.upgrademessage = upgrademessage | |
137 |
|
137 | |||
138 | def __eq__(self, other): |
|
138 | def __eq__(self, other): | |
139 | if not isinstance(other, improvement): |
|
139 | if not isinstance(other, improvement): | |
140 | # This is what python tell use to do |
|
140 | # This is what python tell use to do | |
141 | return NotImplemented |
|
141 | return NotImplemented | |
142 | return self.name == other.name |
|
142 | return self.name == other.name | |
143 |
|
143 | |||
144 | def __ne__(self, other): |
|
144 | def __ne__(self, other): | |
145 | return not (self == other) |
|
145 | return not (self == other) | |
146 |
|
146 | |||
147 | def __hash__(self): |
|
147 | def __hash__(self): | |
148 | return hash(self.name) |
|
148 | return hash(self.name) | |
149 |
|
149 | |||
150 | allformatvariant = [] |
|
150 | allformatvariant = [] | |
151 |
|
151 | |||
152 | def registerformatvariant(cls): |
|
152 | def registerformatvariant(cls): | |
153 | allformatvariant.append(cls) |
|
153 | allformatvariant.append(cls) | |
154 | return cls |
|
154 | return cls | |
155 |
|
155 | |||
156 | class formatvariant(improvement): |
|
156 | class formatvariant(improvement): | |
157 | """an improvement subclass dedicated to repository format""" |
|
157 | """an improvement subclass dedicated to repository format""" | |
158 | type = deficiency |
|
158 | type = deficiency | |
159 | ### The following attributes should be defined for each class: |
|
159 | ### The following attributes should be defined for each class: | |
160 |
|
160 | |||
161 | # machine-readable string uniquely identifying this improvement. it will be |
|
161 | # machine-readable string uniquely identifying this improvement. it will be | |
162 | # mapped to an action later in the upgrade process. |
|
162 | # mapped to an action later in the upgrade process. | |
163 | name = None |
|
163 | name = None | |
164 |
|
164 | |||
165 | # message intended for humans explaining the improvement in more detail, |
|
165 | # message intended for humans explaining the improvement in more detail, | |
166 | # including the implications of it ``deficiency`` types, should be worded |
|
166 | # including the implications of it ``deficiency`` types, should be worded | |
167 | # in the present tense. |
|
167 | # in the present tense. | |
168 | description = None |
|
168 | description = None | |
169 |
|
169 | |||
170 | # message intended for humans explaining what an upgrade addressing this |
|
170 | # message intended for humans explaining what an upgrade addressing this | |
171 | # issue will do. should be worded in the future tense. |
|
171 | # issue will do. should be worded in the future tense. | |
172 | upgrademessage = None |
|
172 | upgrademessage = None | |
173 |
|
173 | |||
174 | # value of current Mercurial default for new repository |
|
174 | # value of current Mercurial default for new repository | |
175 | default = None |
|
175 | default = None | |
176 |
|
176 | |||
177 | def __init__(self): |
|
177 | def __init__(self): | |
178 | raise NotImplementedError() |
|
178 | raise NotImplementedError() | |
179 |
|
179 | |||
180 | @staticmethod |
|
180 | @staticmethod | |
181 | def fromrepo(repo): |
|
181 | def fromrepo(repo): | |
182 | """current value of the variant in the repository""" |
|
182 | """current value of the variant in the repository""" | |
183 | raise NotImplementedError() |
|
183 | raise NotImplementedError() | |
184 |
|
184 | |||
185 | @staticmethod |
|
185 | @staticmethod | |
186 | def fromconfig(repo): |
|
186 | def fromconfig(repo): | |
187 | """current value of the variant in the configuration""" |
|
187 | """current value of the variant in the configuration""" | |
188 | raise NotImplementedError() |
|
188 | raise NotImplementedError() | |
189 |
|
189 | |||
190 | class requirementformatvariant(formatvariant): |
|
190 | class requirementformatvariant(formatvariant): | |
191 | """formatvariant based on a 'requirement' name. |
|
191 | """formatvariant based on a 'requirement' name. | |
192 |
|
192 | |||
193 | Many format variant are controlled by a 'requirement'. We define a small |
|
193 | Many format variant are controlled by a 'requirement'. We define a small | |
194 | subclass to factor the code. |
|
194 | subclass to factor the code. | |
195 | """ |
|
195 | """ | |
196 |
|
196 | |||
197 | # the requirement that control this format variant |
|
197 | # the requirement that control this format variant | |
198 | _requirement = None |
|
198 | _requirement = None | |
199 |
|
199 | |||
200 | @staticmethod |
|
200 | @staticmethod | |
201 | def _newreporequirements(ui): |
|
201 | def _newreporequirements(ui): | |
202 | return localrepo.newreporequirements( |
|
202 | return localrepo.newreporequirements( | |
203 | ui, localrepo.defaultcreateopts(ui)) |
|
203 | ui, localrepo.defaultcreateopts(ui)) | |
204 |
|
204 | |||
205 | @classmethod |
|
205 | @classmethod | |
206 | def fromrepo(cls, repo): |
|
206 | def fromrepo(cls, repo): | |
207 | assert cls._requirement is not None |
|
207 | assert cls._requirement is not None | |
208 | return cls._requirement in repo.requirements |
|
208 | return cls._requirement in repo.requirements | |
209 |
|
209 | |||
210 | @classmethod |
|
210 | @classmethod | |
211 | def fromconfig(cls, repo): |
|
211 | def fromconfig(cls, repo): | |
212 | assert cls._requirement is not None |
|
212 | assert cls._requirement is not None | |
213 | return cls._requirement in cls._newreporequirements(repo.ui) |
|
213 | return cls._requirement in cls._newreporequirements(repo.ui) | |
214 |
|
214 | |||
215 | @registerformatvariant |
|
215 | @registerformatvariant | |
216 | class fncache(requirementformatvariant): |
|
216 | class fncache(requirementformatvariant): | |
217 | name = 'fncache' |
|
217 | name = 'fncache' | |
218 |
|
218 | |||
219 | _requirement = 'fncache' |
|
219 | _requirement = 'fncache' | |
220 |
|
220 | |||
221 | default = True |
|
221 | default = True | |
222 |
|
222 | |||
223 | description = _('long and reserved filenames may not work correctly; ' |
|
223 | description = _('long and reserved filenames may not work correctly; ' | |
224 | 'repository performance is sub-optimal') |
|
224 | 'repository performance is sub-optimal') | |
225 |
|
225 | |||
226 | upgrademessage = _('repository will be more resilient to storing ' |
|
226 | upgrademessage = _('repository will be more resilient to storing ' | |
227 | 'certain paths and performance of certain ' |
|
227 | 'certain paths and performance of certain ' | |
228 | 'operations should be improved') |
|
228 | 'operations should be improved') | |
229 |
|
229 | |||
230 | @registerformatvariant |
|
230 | @registerformatvariant | |
231 | class dotencode(requirementformatvariant): |
|
231 | class dotencode(requirementformatvariant): | |
232 | name = 'dotencode' |
|
232 | name = 'dotencode' | |
233 |
|
233 | |||
234 | _requirement = 'dotencode' |
|
234 | _requirement = 'dotencode' | |
235 |
|
235 | |||
236 | default = True |
|
236 | default = True | |
237 |
|
237 | |||
238 | description = _('storage of filenames beginning with a period or ' |
|
238 | description = _('storage of filenames beginning with a period or ' | |
239 | 'space may not work correctly') |
|
239 | 'space may not work correctly') | |
240 |
|
240 | |||
241 | upgrademessage = _('repository will be better able to store files ' |
|
241 | upgrademessage = _('repository will be better able to store files ' | |
242 | 'beginning with a space or period') |
|
242 | 'beginning with a space or period') | |
243 |
|
243 | |||
244 | @registerformatvariant |
|
244 | @registerformatvariant | |
245 | class generaldelta(requirementformatvariant): |
|
245 | class generaldelta(requirementformatvariant): | |
246 | name = 'generaldelta' |
|
246 | name = 'generaldelta' | |
247 |
|
247 | |||
248 | _requirement = 'generaldelta' |
|
248 | _requirement = 'generaldelta' | |
249 |
|
249 | |||
250 | default = True |
|
250 | default = True | |
251 |
|
251 | |||
252 | description = _('deltas within internal storage are unable to ' |
|
252 | description = _('deltas within internal storage are unable to ' | |
253 | 'choose optimal revisions; repository is larger and ' |
|
253 | 'choose optimal revisions; repository is larger and ' | |
254 | 'slower than it could be; interaction with other ' |
|
254 | 'slower than it could be; interaction with other ' | |
255 | 'repositories may require extra network and CPU ' |
|
255 | 'repositories may require extra network and CPU ' | |
256 | 'resources, making "hg push" and "hg pull" slower') |
|
256 | 'resources, making "hg push" and "hg pull" slower') | |
257 |
|
257 | |||
258 | upgrademessage = _('repository storage will be able to create ' |
|
258 | upgrademessage = _('repository storage will be able to create ' | |
259 | 'optimal deltas; new repository data will be ' |
|
259 | 'optimal deltas; new repository data will be ' | |
260 | 'smaller and read times should decrease; ' |
|
260 | 'smaller and read times should decrease; ' | |
261 | 'interacting with other repositories using this ' |
|
261 | 'interacting with other repositories using this ' | |
262 | 'storage model should require less network and ' |
|
262 | 'storage model should require less network and ' | |
263 | 'CPU resources, making "hg push" and "hg pull" ' |
|
263 | 'CPU resources, making "hg push" and "hg pull" ' | |
264 | 'faster') |
|
264 | 'faster') | |
265 |
|
265 | |||
266 | @registerformatvariant |
|
266 | @registerformatvariant | |
267 | class sparserevlog(requirementformatvariant): |
|
267 | class sparserevlog(requirementformatvariant): | |
268 | name = 'sparserevlog' |
|
268 | name = 'sparserevlog' | |
269 |
|
269 | |||
270 | _requirement = localrepo.SPARSEREVLOG_REQUIREMENT |
|
270 | _requirement = localrepo.SPARSEREVLOG_REQUIREMENT | |
271 |
|
271 | |||
272 | default = True |
|
272 | default = True | |
273 |
|
273 | |||
274 | description = _('in order to limit disk reading and memory usage on older ' |
|
274 | description = _('in order to limit disk reading and memory usage on older ' | |
275 | 'version, the span of a delta chain from its root to its ' |
|
275 | 'version, the span of a delta chain from its root to its ' | |
276 | 'end is limited, whatever the relevant data in this span. ' |
|
276 | 'end is limited, whatever the relevant data in this span. ' | |
277 | 'This can severly limit Mercurial ability to build good ' |
|
277 | 'This can severly limit Mercurial ability to build good ' | |
278 | 'chain of delta resulting is much more storage space being ' |
|
278 | 'chain of delta resulting is much more storage space being ' | |
279 | 'taken and limit reusability of on disk delta during ' |
|
279 | 'taken and limit reusability of on disk delta during ' | |
280 | 'exchange.' |
|
280 | 'exchange.' | |
281 | ) |
|
281 | ) | |
282 |
|
282 | |||
283 | upgrademessage = _('Revlog supports delta chain with more unused data ' |
|
283 | upgrademessage = _('Revlog supports delta chain with more unused data ' | |
284 | 'between payload. These gaps will be skipped at read ' |
|
284 | 'between payload. These gaps will be skipped at read ' | |
285 | 'time. This allows for better delta chains, making a ' |
|
285 | 'time. This allows for better delta chains, making a ' | |
286 | 'better compression and faster exchange with server.') |
|
286 | 'better compression and faster exchange with server.') | |
287 |
|
287 | |||
288 | @registerformatvariant |
|
288 | @registerformatvariant | |
289 | class removecldeltachain(formatvariant): |
|
289 | class removecldeltachain(formatvariant): | |
290 | name = 'plain-cl-delta' |
|
290 | name = 'plain-cl-delta' | |
291 |
|
291 | |||
292 | default = True |
|
292 | default = True | |
293 |
|
293 | |||
294 | description = _('changelog storage is using deltas instead of ' |
|
294 | description = _('changelog storage is using deltas instead of ' | |
295 | 'raw entries; changelog reading and any ' |
|
295 | 'raw entries; changelog reading and any ' | |
296 | 'operation relying on changelog data are slower ' |
|
296 | 'operation relying on changelog data are slower ' | |
297 | 'than they could be') |
|
297 | 'than they could be') | |
298 |
|
298 | |||
299 | upgrademessage = _('changelog storage will be reformated to ' |
|
299 | upgrademessage = _('changelog storage will be reformated to ' | |
300 | 'store raw entries; changelog reading will be ' |
|
300 | 'store raw entries; changelog reading will be ' | |
301 | 'faster; changelog size may be reduced') |
|
301 | 'faster; changelog size may be reduced') | |
302 |
|
302 | |||
303 | @staticmethod |
|
303 | @staticmethod | |
304 | def fromrepo(repo): |
|
304 | def fromrepo(repo): | |
305 | # Mercurial 4.0 changed changelogs to not use delta chains. Search for |
|
305 | # Mercurial 4.0 changed changelogs to not use delta chains. Search for | |
306 | # changelogs with deltas. |
|
306 | # changelogs with deltas. | |
307 | cl = repo.changelog |
|
307 | cl = repo.changelog | |
308 | chainbase = cl.chainbase |
|
308 | chainbase = cl.chainbase | |
309 | return all(rev == chainbase(rev) for rev in cl) |
|
309 | return all(rev == chainbase(rev) for rev in cl) | |
310 |
|
310 | |||
311 | @staticmethod |
|
311 | @staticmethod | |
312 | def fromconfig(repo): |
|
312 | def fromconfig(repo): | |
313 | return True |
|
313 | return True | |
314 |
|
314 | |||
315 | @registerformatvariant |
|
315 | @registerformatvariant | |
316 | class compressionengine(formatvariant): |
|
316 | class compressionengine(formatvariant): | |
317 | name = 'compression' |
|
317 | name = 'compression' | |
318 | default = 'zlib' |
|
318 | default = 'zlib' | |
319 |
|
319 | |||
320 | description = _('Compresion algorithm used to compress data. ' |
|
320 | description = _('Compresion algorithm used to compress data. ' | |
321 | 'Some engine are faster than other') |
|
321 | 'Some engine are faster than other') | |
322 |
|
322 | |||
323 | upgrademessage = _('revlog content will be recompressed with the new ' |
|
323 | upgrademessage = _('revlog content will be recompressed with the new ' | |
324 | 'algorithm.') |
|
324 | 'algorithm.') | |
325 |
|
325 | |||
326 | @classmethod |
|
326 | @classmethod | |
327 | def fromrepo(cls, repo): |
|
327 | def fromrepo(cls, repo): | |
|
328 | # we allow multiple compression engine requirement to co-exist because | |||
|
329 | # strickly speaking, revlog seems to support mixed compression style. | |||
|
330 | # | |||
|
331 | # The compression used for new entries will be "the last one" | |||
|
332 | compression = 'zlib' | |||
328 | for req in repo.requirements: |
|
333 | for req in repo.requirements: | |
329 |
|
|
334 | prefix = req.startswith | |
330 | return req.split('-', 2)[2] |
|
335 | if prefix('revlog-compression-') or prefix('exp-compression-'): | |
331 | return 'zlib' |
|
336 | compression = req.split('-', 2)[2] | |
|
337 | return compression | |||
332 |
|
338 | |||
333 | @classmethod |
|
339 | @classmethod | |
334 | def fromconfig(cls, repo): |
|
340 | def fromconfig(cls, repo): | |
335 | return repo.ui.config('format', 'revlog-compression') |
|
341 | return repo.ui.config('format', 'revlog-compression') | |
336 |
|
342 | |||
337 | @registerformatvariant |
|
343 | @registerformatvariant | |
338 | class compressionlevel(formatvariant): |
|
344 | class compressionlevel(formatvariant): | |
339 | name = 'compression-level' |
|
345 | name = 'compression-level' | |
340 | default = 'default' |
|
346 | default = 'default' | |
341 |
|
347 | |||
342 | description = _('compression level') |
|
348 | description = _('compression level') | |
343 |
|
349 | |||
344 | upgrademessage = _('revlog content will be recompressed') |
|
350 | upgrademessage = _('revlog content will be recompressed') | |
345 |
|
351 | |||
346 | @classmethod |
|
352 | @classmethod | |
347 | def fromrepo(cls, repo): |
|
353 | def fromrepo(cls, repo): | |
348 | comp = compressionengine.fromrepo(repo) |
|
354 | comp = compressionengine.fromrepo(repo) | |
349 | level = None |
|
355 | level = None | |
350 | if comp == 'zlib': |
|
356 | if comp == 'zlib': | |
351 | level = repo.ui.configint('storage', 'revlog.zlib.level') |
|
357 | level = repo.ui.configint('storage', 'revlog.zlib.level') | |
352 | elif comp == 'zstd': |
|
358 | elif comp == 'zstd': | |
353 | level = repo.ui.configint('storage', 'revlog.zstd.level') |
|
359 | level = repo.ui.configint('storage', 'revlog.zstd.level') | |
354 | if level is None: |
|
360 | if level is None: | |
355 | return 'default' |
|
361 | return 'default' | |
356 | return bytes(level) |
|
362 | return bytes(level) | |
357 |
|
363 | |||
358 | @classmethod |
|
364 | @classmethod | |
359 | def fromconfig(cls, repo): |
|
365 | def fromconfig(cls, repo): | |
360 | comp = compressionengine.fromconfig(repo) |
|
366 | comp = compressionengine.fromconfig(repo) | |
361 | level = None |
|
367 | level = None | |
362 | if comp == 'zlib': |
|
368 | if comp == 'zlib': | |
363 | level = repo.ui.configint('storage', 'revlog.zlib.level') |
|
369 | level = repo.ui.configint('storage', 'revlog.zlib.level') | |
364 | elif comp == 'zstd': |
|
370 | elif comp == 'zstd': | |
365 | level = repo.ui.configint('storage', 'revlog.zstd.level') |
|
371 | level = repo.ui.configint('storage', 'revlog.zstd.level') | |
366 | if level is None: |
|
372 | if level is None: | |
367 | return 'default' |
|
373 | return 'default' | |
368 | return bytes(level) |
|
374 | return bytes(level) | |
369 |
|
375 | |||
370 | def finddeficiencies(repo): |
|
376 | def finddeficiencies(repo): | |
371 | """returns a list of deficiencies that the repo suffer from""" |
|
377 | """returns a list of deficiencies that the repo suffer from""" | |
372 | deficiencies = [] |
|
378 | deficiencies = [] | |
373 |
|
379 | |||
374 | # We could detect lack of revlogv1 and store here, but they were added |
|
380 | # We could detect lack of revlogv1 and store here, but they were added | |
375 | # in 0.9.2 and we don't support upgrading repos without these |
|
381 | # in 0.9.2 and we don't support upgrading repos without these | |
376 | # requirements, so let's not bother. |
|
382 | # requirements, so let's not bother. | |
377 |
|
383 | |||
378 | for fv in allformatvariant: |
|
384 | for fv in allformatvariant: | |
379 | if not fv.fromrepo(repo): |
|
385 | if not fv.fromrepo(repo): | |
380 | deficiencies.append(fv) |
|
386 | deficiencies.append(fv) | |
381 |
|
387 | |||
382 | return deficiencies |
|
388 | return deficiencies | |
383 |
|
389 | |||
384 | # search without '-' to support older form on newer client. |
|
390 | # search without '-' to support older form on newer client. | |
385 | # |
|
391 | # | |
386 | # We don't enforce backward compatibility for debug command so this |
|
392 | # We don't enforce backward compatibility for debug command so this | |
387 | # might eventually be dropped. However, having to use two different |
|
393 | # might eventually be dropped. However, having to use two different | |
388 | # forms in script when comparing result is anoying enough to add |
|
394 | # forms in script when comparing result is anoying enough to add | |
389 | # backward compatibility for a while. |
|
395 | # backward compatibility for a while. | |
390 | legacy_opts_map = { |
|
396 | legacy_opts_map = { | |
391 | 'redeltaparent': 're-delta-parent', |
|
397 | 'redeltaparent': 're-delta-parent', | |
392 | 'redeltamultibase': 're-delta-multibase', |
|
398 | 'redeltamultibase': 're-delta-multibase', | |
393 | 'redeltaall': 're-delta-all', |
|
399 | 'redeltaall': 're-delta-all', | |
394 | 'redeltafulladd': 're-delta-fulladd', |
|
400 | 'redeltafulladd': 're-delta-fulladd', | |
395 | } |
|
401 | } | |
396 |
|
402 | |||
397 | def findoptimizations(repo): |
|
403 | def findoptimizations(repo): | |
398 | """Determine optimisation that could be used during upgrade""" |
|
404 | """Determine optimisation that could be used during upgrade""" | |
399 | # These are unconditionally added. There is logic later that figures out |
|
405 | # These are unconditionally added. There is logic later that figures out | |
400 | # which ones to apply. |
|
406 | # which ones to apply. | |
401 | optimizations = [] |
|
407 | optimizations = [] | |
402 |
|
408 | |||
403 | optimizations.append(improvement( |
|
409 | optimizations.append(improvement( | |
404 | name='re-delta-parent', |
|
410 | name='re-delta-parent', | |
405 | type=optimisation, |
|
411 | type=optimisation, | |
406 | description=_('deltas within internal storage will be recalculated to ' |
|
412 | description=_('deltas within internal storage will be recalculated to ' | |
407 | 'choose an optimal base revision where this was not ' |
|
413 | 'choose an optimal base revision where this was not ' | |
408 | 'already done; the size of the repository may shrink and ' |
|
414 | 'already done; the size of the repository may shrink and ' | |
409 | 'various operations may become faster; the first time ' |
|
415 | 'various operations may become faster; the first time ' | |
410 | 'this optimization is performed could slow down upgrade ' |
|
416 | 'this optimization is performed could slow down upgrade ' | |
411 | 'execution considerably; subsequent invocations should ' |
|
417 | 'execution considerably; subsequent invocations should ' | |
412 | 'not run noticeably slower'), |
|
418 | 'not run noticeably slower'), | |
413 | upgrademessage=_('deltas within internal storage will choose a new ' |
|
419 | upgrademessage=_('deltas within internal storage will choose a new ' | |
414 | 'base revision if needed'))) |
|
420 | 'base revision if needed'))) | |
415 |
|
421 | |||
416 | optimizations.append(improvement( |
|
422 | optimizations.append(improvement( | |
417 | name='re-delta-multibase', |
|
423 | name='re-delta-multibase', | |
418 | type=optimisation, |
|
424 | type=optimisation, | |
419 | description=_('deltas within internal storage will be recalculated ' |
|
425 | description=_('deltas within internal storage will be recalculated ' | |
420 | 'against multiple base revision and the smallest ' |
|
426 | 'against multiple base revision and the smallest ' | |
421 | 'difference will be used; the size of the repository may ' |
|
427 | 'difference will be used; the size of the repository may ' | |
422 | 'shrink significantly when there are many merges; this ' |
|
428 | 'shrink significantly when there are many merges; this ' | |
423 | 'optimization will slow down execution in proportion to ' |
|
429 | 'optimization will slow down execution in proportion to ' | |
424 | 'the number of merges in the repository and the amount ' |
|
430 | 'the number of merges in the repository and the amount ' | |
425 | 'of files in the repository; this slow down should not ' |
|
431 | 'of files in the repository; this slow down should not ' | |
426 | 'be significant unless there are tens of thousands of ' |
|
432 | 'be significant unless there are tens of thousands of ' | |
427 | 'files and thousands of merges'), |
|
433 | 'files and thousands of merges'), | |
428 | upgrademessage=_('deltas within internal storage will choose an ' |
|
434 | upgrademessage=_('deltas within internal storage will choose an ' | |
429 | 'optimal delta by computing deltas against multiple ' |
|
435 | 'optimal delta by computing deltas against multiple ' | |
430 | 'parents; may slow down execution time ' |
|
436 | 'parents; may slow down execution time ' | |
431 | 'significantly'))) |
|
437 | 'significantly'))) | |
432 |
|
438 | |||
433 | optimizations.append(improvement( |
|
439 | optimizations.append(improvement( | |
434 | name='re-delta-all', |
|
440 | name='re-delta-all', | |
435 | type=optimisation, |
|
441 | type=optimisation, | |
436 | description=_('deltas within internal storage will always be ' |
|
442 | description=_('deltas within internal storage will always be ' | |
437 | 'recalculated without reusing prior deltas; this will ' |
|
443 | 'recalculated without reusing prior deltas; this will ' | |
438 | 'likely make execution run several times slower; this ' |
|
444 | 'likely make execution run several times slower; this ' | |
439 | 'optimization is typically not needed'), |
|
445 | 'optimization is typically not needed'), | |
440 | upgrademessage=_('deltas within internal storage will be fully ' |
|
446 | upgrademessage=_('deltas within internal storage will be fully ' | |
441 | 'recomputed; this will likely drastically slow down ' |
|
447 | 'recomputed; this will likely drastically slow down ' | |
442 | 'execution time'))) |
|
448 | 'execution time'))) | |
443 |
|
449 | |||
444 | optimizations.append(improvement( |
|
450 | optimizations.append(improvement( | |
445 | name='re-delta-fulladd', |
|
451 | name='re-delta-fulladd', | |
446 | type=optimisation, |
|
452 | type=optimisation, | |
447 | description=_('every revision will be re-added as if it was new ' |
|
453 | description=_('every revision will be re-added as if it was new ' | |
448 | 'content. It will go through the full storage ' |
|
454 | 'content. It will go through the full storage ' | |
449 | 'mechanism giving extensions a chance to process it ' |
|
455 | 'mechanism giving extensions a chance to process it ' | |
450 | '(eg. lfs). This is similar to "re-delta-all" but even ' |
|
456 | '(eg. lfs). This is similar to "re-delta-all" but even ' | |
451 | 'slower since more logic is involved.'), |
|
457 | 'slower since more logic is involved.'), | |
452 | upgrademessage=_('each revision will be added as new content to the ' |
|
458 | upgrademessage=_('each revision will be added as new content to the ' | |
453 | 'internal storage; this will likely drastically slow ' |
|
459 | 'internal storage; this will likely drastically slow ' | |
454 | 'down execution time, but some extensions might need ' |
|
460 | 'down execution time, but some extensions might need ' | |
455 | 'it'))) |
|
461 | 'it'))) | |
456 |
|
462 | |||
457 | return optimizations |
|
463 | return optimizations | |
458 |
|
464 | |||
459 | def determineactions(repo, deficiencies, sourcereqs, destreqs): |
|
465 | def determineactions(repo, deficiencies, sourcereqs, destreqs): | |
460 | """Determine upgrade actions that will be performed. |
|
466 | """Determine upgrade actions that will be performed. | |
461 |
|
467 | |||
462 | Given a list of improvements as returned by ``finddeficiencies`` and |
|
468 | Given a list of improvements as returned by ``finddeficiencies`` and | |
463 | ``findoptimizations``, determine the list of upgrade actions that |
|
469 | ``findoptimizations``, determine the list of upgrade actions that | |
464 | will be performed. |
|
470 | will be performed. | |
465 |
|
471 | |||
466 | The role of this function is to filter improvements if needed, apply |
|
472 | The role of this function is to filter improvements if needed, apply | |
467 | recommended optimizations from the improvements list that make sense, |
|
473 | recommended optimizations from the improvements list that make sense, | |
468 | etc. |
|
474 | etc. | |
469 |
|
475 | |||
470 | Returns a list of action names. |
|
476 | Returns a list of action names. | |
471 | """ |
|
477 | """ | |
472 | newactions = [] |
|
478 | newactions = [] | |
473 |
|
479 | |||
474 | knownreqs = supporteddestrequirements(repo) |
|
480 | knownreqs = supporteddestrequirements(repo) | |
475 |
|
481 | |||
476 | for d in deficiencies: |
|
482 | for d in deficiencies: | |
477 | name = d.name |
|
483 | name = d.name | |
478 |
|
484 | |||
479 | # If the action is a requirement that doesn't show up in the |
|
485 | # If the action is a requirement that doesn't show up in the | |
480 | # destination requirements, prune the action. |
|
486 | # destination requirements, prune the action. | |
481 | if name in knownreqs and name not in destreqs: |
|
487 | if name in knownreqs and name not in destreqs: | |
482 | continue |
|
488 | continue | |
483 |
|
489 | |||
484 | newactions.append(d) |
|
490 | newactions.append(d) | |
485 |
|
491 | |||
486 | # FUTURE consider adding some optimizations here for certain transitions. |
|
492 | # FUTURE consider adding some optimizations here for certain transitions. | |
487 | # e.g. adding generaldelta could schedule parent redeltas. |
|
493 | # e.g. adding generaldelta could schedule parent redeltas. | |
488 |
|
494 | |||
489 | return newactions |
|
495 | return newactions | |
490 |
|
496 | |||
491 | def _revlogfrompath(repo, path): |
|
497 | def _revlogfrompath(repo, path): | |
492 | """Obtain a revlog from a repo path. |
|
498 | """Obtain a revlog from a repo path. | |
493 |
|
499 | |||
494 | An instance of the appropriate class is returned. |
|
500 | An instance of the appropriate class is returned. | |
495 | """ |
|
501 | """ | |
496 | if path == '00changelog.i': |
|
502 | if path == '00changelog.i': | |
497 | return changelog.changelog(repo.svfs) |
|
503 | return changelog.changelog(repo.svfs) | |
498 | elif path.endswith('00manifest.i'): |
|
504 | elif path.endswith('00manifest.i'): | |
499 | mandir = path[:-len('00manifest.i')] |
|
505 | mandir = path[:-len('00manifest.i')] | |
500 | return manifest.manifestrevlog(repo.svfs, tree=mandir) |
|
506 | return manifest.manifestrevlog(repo.svfs, tree=mandir) | |
501 | else: |
|
507 | else: | |
502 | #reverse of "/".join(("data", path + ".i")) |
|
508 | #reverse of "/".join(("data", path + ".i")) | |
503 | return filelog.filelog(repo.svfs, path[5:-2]) |
|
509 | return filelog.filelog(repo.svfs, path[5:-2]) | |
504 |
|
510 | |||
505 | def _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents): |
|
511 | def _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, forcedeltabothparents): | |
506 | """Copy revlogs between 2 repos.""" |
|
512 | """Copy revlogs between 2 repos.""" | |
507 | revcount = 0 |
|
513 | revcount = 0 | |
508 | srcsize = 0 |
|
514 | srcsize = 0 | |
509 | srcrawsize = 0 |
|
515 | srcrawsize = 0 | |
510 | dstsize = 0 |
|
516 | dstsize = 0 | |
511 | fcount = 0 |
|
517 | fcount = 0 | |
512 | frevcount = 0 |
|
518 | frevcount = 0 | |
513 | fsrcsize = 0 |
|
519 | fsrcsize = 0 | |
514 | frawsize = 0 |
|
520 | frawsize = 0 | |
515 | fdstsize = 0 |
|
521 | fdstsize = 0 | |
516 | mcount = 0 |
|
522 | mcount = 0 | |
517 | mrevcount = 0 |
|
523 | mrevcount = 0 | |
518 | msrcsize = 0 |
|
524 | msrcsize = 0 | |
519 | mrawsize = 0 |
|
525 | mrawsize = 0 | |
520 | mdstsize = 0 |
|
526 | mdstsize = 0 | |
521 | crevcount = 0 |
|
527 | crevcount = 0 | |
522 | csrcsize = 0 |
|
528 | csrcsize = 0 | |
523 | crawsize = 0 |
|
529 | crawsize = 0 | |
524 | cdstsize = 0 |
|
530 | cdstsize = 0 | |
525 |
|
531 | |||
526 | # Perform a pass to collect metadata. This validates we can open all |
|
532 | # Perform a pass to collect metadata. This validates we can open all | |
527 | # source files and allows a unified progress bar to be displayed. |
|
533 | # source files and allows a unified progress bar to be displayed. | |
528 | for unencoded, encoded, size in srcrepo.store.walk(): |
|
534 | for unencoded, encoded, size in srcrepo.store.walk(): | |
529 | if unencoded.endswith('.d'): |
|
535 | if unencoded.endswith('.d'): | |
530 | continue |
|
536 | continue | |
531 |
|
537 | |||
532 | rl = _revlogfrompath(srcrepo, unencoded) |
|
538 | rl = _revlogfrompath(srcrepo, unencoded) | |
533 |
|
539 | |||
534 | info = rl.storageinfo(exclusivefiles=True, revisionscount=True, |
|
540 | info = rl.storageinfo(exclusivefiles=True, revisionscount=True, | |
535 | trackedsize=True, storedsize=True) |
|
541 | trackedsize=True, storedsize=True) | |
536 |
|
542 | |||
537 | revcount += info['revisionscount'] or 0 |
|
543 | revcount += info['revisionscount'] or 0 | |
538 | datasize = info['storedsize'] or 0 |
|
544 | datasize = info['storedsize'] or 0 | |
539 | rawsize = info['trackedsize'] or 0 |
|
545 | rawsize = info['trackedsize'] or 0 | |
540 |
|
546 | |||
541 | srcsize += datasize |
|
547 | srcsize += datasize | |
542 | srcrawsize += rawsize |
|
548 | srcrawsize += rawsize | |
543 |
|
549 | |||
544 | # This is for the separate progress bars. |
|
550 | # This is for the separate progress bars. | |
545 | if isinstance(rl, changelog.changelog): |
|
551 | if isinstance(rl, changelog.changelog): | |
546 | crevcount += len(rl) |
|
552 | crevcount += len(rl) | |
547 | csrcsize += datasize |
|
553 | csrcsize += datasize | |
548 | crawsize += rawsize |
|
554 | crawsize += rawsize | |
549 | elif isinstance(rl, manifest.manifestrevlog): |
|
555 | elif isinstance(rl, manifest.manifestrevlog): | |
550 | mcount += 1 |
|
556 | mcount += 1 | |
551 | mrevcount += len(rl) |
|
557 | mrevcount += len(rl) | |
552 | msrcsize += datasize |
|
558 | msrcsize += datasize | |
553 | mrawsize += rawsize |
|
559 | mrawsize += rawsize | |
554 | elif isinstance(rl, filelog.filelog): |
|
560 | elif isinstance(rl, filelog.filelog): | |
555 | fcount += 1 |
|
561 | fcount += 1 | |
556 | frevcount += len(rl) |
|
562 | frevcount += len(rl) | |
557 | fsrcsize += datasize |
|
563 | fsrcsize += datasize | |
558 | frawsize += rawsize |
|
564 | frawsize += rawsize | |
559 | else: |
|
565 | else: | |
560 | error.ProgrammingError('unknown revlog type') |
|
566 | error.ProgrammingError('unknown revlog type') | |
561 |
|
567 | |||
562 | if not revcount: |
|
568 | if not revcount: | |
563 | return |
|
569 | return | |
564 |
|
570 | |||
565 | ui.write(_('migrating %d total revisions (%d in filelogs, %d in manifests, ' |
|
571 | ui.write(_('migrating %d total revisions (%d in filelogs, %d in manifests, ' | |
566 | '%d in changelog)\n') % |
|
572 | '%d in changelog)\n') % | |
567 | (revcount, frevcount, mrevcount, crevcount)) |
|
573 | (revcount, frevcount, mrevcount, crevcount)) | |
568 | ui.write(_('migrating %s in store; %s tracked data\n') % ( |
|
574 | ui.write(_('migrating %s in store; %s tracked data\n') % ( | |
569 | (util.bytecount(srcsize), util.bytecount(srcrawsize)))) |
|
575 | (util.bytecount(srcsize), util.bytecount(srcrawsize)))) | |
570 |
|
576 | |||
571 | # Used to keep track of progress. |
|
577 | # Used to keep track of progress. | |
572 | progress = None |
|
578 | progress = None | |
573 | def oncopiedrevision(rl, rev, node): |
|
579 | def oncopiedrevision(rl, rev, node): | |
574 | progress.increment() |
|
580 | progress.increment() | |
575 |
|
581 | |||
576 | # Do the actual copying. |
|
582 | # Do the actual copying. | |
577 | # FUTURE this operation can be farmed off to worker processes. |
|
583 | # FUTURE this operation can be farmed off to worker processes. | |
578 | seen = set() |
|
584 | seen = set() | |
579 | for unencoded, encoded, size in srcrepo.store.walk(): |
|
585 | for unencoded, encoded, size in srcrepo.store.walk(): | |
580 | if unencoded.endswith('.d'): |
|
586 | if unencoded.endswith('.d'): | |
581 | continue |
|
587 | continue | |
582 |
|
588 | |||
583 | oldrl = _revlogfrompath(srcrepo, unencoded) |
|
589 | oldrl = _revlogfrompath(srcrepo, unencoded) | |
584 | newrl = _revlogfrompath(dstrepo, unencoded) |
|
590 | newrl = _revlogfrompath(dstrepo, unencoded) | |
585 |
|
591 | |||
586 | if isinstance(oldrl, changelog.changelog) and 'c' not in seen: |
|
592 | if isinstance(oldrl, changelog.changelog) and 'c' not in seen: | |
587 | ui.write(_('finished migrating %d manifest revisions across %d ' |
|
593 | ui.write(_('finished migrating %d manifest revisions across %d ' | |
588 | 'manifests; change in size: %s\n') % |
|
594 | 'manifests; change in size: %s\n') % | |
589 | (mrevcount, mcount, util.bytecount(mdstsize - msrcsize))) |
|
595 | (mrevcount, mcount, util.bytecount(mdstsize - msrcsize))) | |
590 |
|
596 | |||
591 | ui.write(_('migrating changelog containing %d revisions ' |
|
597 | ui.write(_('migrating changelog containing %d revisions ' | |
592 | '(%s in store; %s tracked data)\n') % |
|
598 | '(%s in store; %s tracked data)\n') % | |
593 | (crevcount, util.bytecount(csrcsize), |
|
599 | (crevcount, util.bytecount(csrcsize), | |
594 | util.bytecount(crawsize))) |
|
600 | util.bytecount(crawsize))) | |
595 | seen.add('c') |
|
601 | seen.add('c') | |
596 | progress = srcrepo.ui.makeprogress(_('changelog revisions'), |
|
602 | progress = srcrepo.ui.makeprogress(_('changelog revisions'), | |
597 | total=crevcount) |
|
603 | total=crevcount) | |
598 | elif isinstance(oldrl, manifest.manifestrevlog) and 'm' not in seen: |
|
604 | elif isinstance(oldrl, manifest.manifestrevlog) and 'm' not in seen: | |
599 | ui.write(_('finished migrating %d filelog revisions across %d ' |
|
605 | ui.write(_('finished migrating %d filelog revisions across %d ' | |
600 | 'filelogs; change in size: %s\n') % |
|
606 | 'filelogs; change in size: %s\n') % | |
601 | (frevcount, fcount, util.bytecount(fdstsize - fsrcsize))) |
|
607 | (frevcount, fcount, util.bytecount(fdstsize - fsrcsize))) | |
602 |
|
608 | |||
603 | ui.write(_('migrating %d manifests containing %d revisions ' |
|
609 | ui.write(_('migrating %d manifests containing %d revisions ' | |
604 | '(%s in store; %s tracked data)\n') % |
|
610 | '(%s in store; %s tracked data)\n') % | |
605 | (mcount, mrevcount, util.bytecount(msrcsize), |
|
611 | (mcount, mrevcount, util.bytecount(msrcsize), | |
606 | util.bytecount(mrawsize))) |
|
612 | util.bytecount(mrawsize))) | |
607 | seen.add('m') |
|
613 | seen.add('m') | |
608 | if progress: |
|
614 | if progress: | |
609 | progress.complete() |
|
615 | progress.complete() | |
610 | progress = srcrepo.ui.makeprogress(_('manifest revisions'), |
|
616 | progress = srcrepo.ui.makeprogress(_('manifest revisions'), | |
611 | total=mrevcount) |
|
617 | total=mrevcount) | |
612 | elif 'f' not in seen: |
|
618 | elif 'f' not in seen: | |
613 | ui.write(_('migrating %d filelogs containing %d revisions ' |
|
619 | ui.write(_('migrating %d filelogs containing %d revisions ' | |
614 | '(%s in store; %s tracked data)\n') % |
|
620 | '(%s in store; %s tracked data)\n') % | |
615 | (fcount, frevcount, util.bytecount(fsrcsize), |
|
621 | (fcount, frevcount, util.bytecount(fsrcsize), | |
616 | util.bytecount(frawsize))) |
|
622 | util.bytecount(frawsize))) | |
617 | seen.add('f') |
|
623 | seen.add('f') | |
618 | if progress: |
|
624 | if progress: | |
619 | progress.complete() |
|
625 | progress.complete() | |
620 | progress = srcrepo.ui.makeprogress(_('file revisions'), |
|
626 | progress = srcrepo.ui.makeprogress(_('file revisions'), | |
621 | total=frevcount) |
|
627 | total=frevcount) | |
622 |
|
628 | |||
623 |
|
629 | |||
624 | ui.note(_('cloning %d revisions from %s\n') % (len(oldrl), unencoded)) |
|
630 | ui.note(_('cloning %d revisions from %s\n') % (len(oldrl), unencoded)) | |
625 | oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision, |
|
631 | oldrl.clone(tr, newrl, addrevisioncb=oncopiedrevision, | |
626 | deltareuse=deltareuse, |
|
632 | deltareuse=deltareuse, | |
627 | forcedeltabothparents=forcedeltabothparents) |
|
633 | forcedeltabothparents=forcedeltabothparents) | |
628 |
|
634 | |||
629 | info = newrl.storageinfo(storedsize=True) |
|
635 | info = newrl.storageinfo(storedsize=True) | |
630 | datasize = info['storedsize'] or 0 |
|
636 | datasize = info['storedsize'] or 0 | |
631 |
|
637 | |||
632 | dstsize += datasize |
|
638 | dstsize += datasize | |
633 |
|
639 | |||
634 | if isinstance(newrl, changelog.changelog): |
|
640 | if isinstance(newrl, changelog.changelog): | |
635 | cdstsize += datasize |
|
641 | cdstsize += datasize | |
636 | elif isinstance(newrl, manifest.manifestrevlog): |
|
642 | elif isinstance(newrl, manifest.manifestrevlog): | |
637 | mdstsize += datasize |
|
643 | mdstsize += datasize | |
638 | else: |
|
644 | else: | |
639 | fdstsize += datasize |
|
645 | fdstsize += datasize | |
640 |
|
646 | |||
641 | progress.complete() |
|
647 | progress.complete() | |
642 |
|
648 | |||
643 | ui.write(_('finished migrating %d changelog revisions; change in size: ' |
|
649 | ui.write(_('finished migrating %d changelog revisions; change in size: ' | |
644 | '%s\n') % (crevcount, util.bytecount(cdstsize - csrcsize))) |
|
650 | '%s\n') % (crevcount, util.bytecount(cdstsize - csrcsize))) | |
645 |
|
651 | |||
646 | ui.write(_('finished migrating %d total revisions; total change in store ' |
|
652 | ui.write(_('finished migrating %d total revisions; total change in store ' | |
647 | 'size: %s\n') % (revcount, util.bytecount(dstsize - srcsize))) |
|
653 | 'size: %s\n') % (revcount, util.bytecount(dstsize - srcsize))) | |
648 |
|
654 | |||
649 | def _filterstorefile(srcrepo, dstrepo, requirements, path, mode, st): |
|
655 | def _filterstorefile(srcrepo, dstrepo, requirements, path, mode, st): | |
650 | """Determine whether to copy a store file during upgrade. |
|
656 | """Determine whether to copy a store file during upgrade. | |
651 |
|
657 | |||
652 | This function is called when migrating store files from ``srcrepo`` to |
|
658 | This function is called when migrating store files from ``srcrepo`` to | |
653 | ``dstrepo`` as part of upgrading a repository. |
|
659 | ``dstrepo`` as part of upgrading a repository. | |
654 |
|
660 | |||
655 | Args: |
|
661 | Args: | |
656 | srcrepo: repo we are copying from |
|
662 | srcrepo: repo we are copying from | |
657 | dstrepo: repo we are copying to |
|
663 | dstrepo: repo we are copying to | |
658 | requirements: set of requirements for ``dstrepo`` |
|
664 | requirements: set of requirements for ``dstrepo`` | |
659 | path: store file being examined |
|
665 | path: store file being examined | |
660 | mode: the ``ST_MODE`` file type of ``path`` |
|
666 | mode: the ``ST_MODE`` file type of ``path`` | |
661 | st: ``stat`` data structure for ``path`` |
|
667 | st: ``stat`` data structure for ``path`` | |
662 |
|
668 | |||
663 | Function should return ``True`` if the file is to be copied. |
|
669 | Function should return ``True`` if the file is to be copied. | |
664 | """ |
|
670 | """ | |
665 | # Skip revlogs. |
|
671 | # Skip revlogs. | |
666 | if path.endswith(('.i', '.d')): |
|
672 | if path.endswith(('.i', '.d')): | |
667 | return False |
|
673 | return False | |
668 | # Skip transaction related files. |
|
674 | # Skip transaction related files. | |
669 | if path.startswith('undo'): |
|
675 | if path.startswith('undo'): | |
670 | return False |
|
676 | return False | |
671 | # Only copy regular files. |
|
677 | # Only copy regular files. | |
672 | if mode != stat.S_IFREG: |
|
678 | if mode != stat.S_IFREG: | |
673 | return False |
|
679 | return False | |
674 | # Skip other skipped files. |
|
680 | # Skip other skipped files. | |
675 | if path in ('lock', 'fncache'): |
|
681 | if path in ('lock', 'fncache'): | |
676 | return False |
|
682 | return False | |
677 |
|
683 | |||
678 | return True |
|
684 | return True | |
679 |
|
685 | |||
680 | def _finishdatamigration(ui, srcrepo, dstrepo, requirements): |
|
686 | def _finishdatamigration(ui, srcrepo, dstrepo, requirements): | |
681 | """Hook point for extensions to perform additional actions during upgrade. |
|
687 | """Hook point for extensions to perform additional actions during upgrade. | |
682 |
|
688 | |||
683 | This function is called after revlogs and store files have been copied but |
|
689 | This function is called after revlogs and store files have been copied but | |
684 | before the new store is swapped into the original location. |
|
690 | before the new store is swapped into the original location. | |
685 | """ |
|
691 | """ | |
686 |
|
692 | |||
687 | def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions): |
|
693 | def _upgraderepo(ui, srcrepo, dstrepo, requirements, actions): | |
688 | """Do the low-level work of upgrading a repository. |
|
694 | """Do the low-level work of upgrading a repository. | |
689 |
|
695 | |||
690 | The upgrade is effectively performed as a copy between a source |
|
696 | The upgrade is effectively performed as a copy between a source | |
691 | repository and a temporary destination repository. |
|
697 | repository and a temporary destination repository. | |
692 |
|
698 | |||
693 | The source repository is unmodified for as long as possible so the |
|
699 | The source repository is unmodified for as long as possible so the | |
694 | upgrade can abort at any time without causing loss of service for |
|
700 | upgrade can abort at any time without causing loss of service for | |
695 | readers and without corrupting the source repository. |
|
701 | readers and without corrupting the source repository. | |
696 | """ |
|
702 | """ | |
697 | assert srcrepo.currentwlock() |
|
703 | assert srcrepo.currentwlock() | |
698 | assert dstrepo.currentwlock() |
|
704 | assert dstrepo.currentwlock() | |
699 |
|
705 | |||
700 | ui.write(_('(it is safe to interrupt this process any time before ' |
|
706 | ui.write(_('(it is safe to interrupt this process any time before ' | |
701 | 'data migration completes)\n')) |
|
707 | 'data migration completes)\n')) | |
702 |
|
708 | |||
703 | if 're-delta-all' in actions: |
|
709 | if 're-delta-all' in actions: | |
704 | deltareuse = revlog.revlog.DELTAREUSENEVER |
|
710 | deltareuse = revlog.revlog.DELTAREUSENEVER | |
705 | elif 're-delta-parent' in actions: |
|
711 | elif 're-delta-parent' in actions: | |
706 | deltareuse = revlog.revlog.DELTAREUSESAMEREVS |
|
712 | deltareuse = revlog.revlog.DELTAREUSESAMEREVS | |
707 | elif 're-delta-multibase' in actions: |
|
713 | elif 're-delta-multibase' in actions: | |
708 | deltareuse = revlog.revlog.DELTAREUSESAMEREVS |
|
714 | deltareuse = revlog.revlog.DELTAREUSESAMEREVS | |
709 | elif 're-delta-fulladd' in actions: |
|
715 | elif 're-delta-fulladd' in actions: | |
710 | deltareuse = revlog.revlog.DELTAREUSEFULLADD |
|
716 | deltareuse = revlog.revlog.DELTAREUSEFULLADD | |
711 | else: |
|
717 | else: | |
712 | deltareuse = revlog.revlog.DELTAREUSEALWAYS |
|
718 | deltareuse = revlog.revlog.DELTAREUSEALWAYS | |
713 |
|
719 | |||
714 | with dstrepo.transaction('upgrade') as tr: |
|
720 | with dstrepo.transaction('upgrade') as tr: | |
715 | _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, |
|
721 | _copyrevlogs(ui, srcrepo, dstrepo, tr, deltareuse, | |
716 | 're-delta-multibase' in actions) |
|
722 | 're-delta-multibase' in actions) | |
717 |
|
723 | |||
718 | # Now copy other files in the store directory. |
|
724 | # Now copy other files in the store directory. | |
719 | # The sorted() makes execution deterministic. |
|
725 | # The sorted() makes execution deterministic. | |
720 | for p, kind, st in sorted(srcrepo.store.vfs.readdir('', stat=True)): |
|
726 | for p, kind, st in sorted(srcrepo.store.vfs.readdir('', stat=True)): | |
721 | if not _filterstorefile(srcrepo, dstrepo, requirements, |
|
727 | if not _filterstorefile(srcrepo, dstrepo, requirements, | |
722 | p, kind, st): |
|
728 | p, kind, st): | |
723 | continue |
|
729 | continue | |
724 |
|
730 | |||
725 | srcrepo.ui.write(_('copying %s\n') % p) |
|
731 | srcrepo.ui.write(_('copying %s\n') % p) | |
726 | src = srcrepo.store.rawvfs.join(p) |
|
732 | src = srcrepo.store.rawvfs.join(p) | |
727 | dst = dstrepo.store.rawvfs.join(p) |
|
733 | dst = dstrepo.store.rawvfs.join(p) | |
728 | util.copyfile(src, dst, copystat=True) |
|
734 | util.copyfile(src, dst, copystat=True) | |
729 |
|
735 | |||
730 | _finishdatamigration(ui, srcrepo, dstrepo, requirements) |
|
736 | _finishdatamigration(ui, srcrepo, dstrepo, requirements) | |
731 |
|
737 | |||
732 | ui.write(_('data fully migrated to temporary repository\n')) |
|
738 | ui.write(_('data fully migrated to temporary repository\n')) | |
733 |
|
739 | |||
734 | backuppath = pycompat.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path) |
|
740 | backuppath = pycompat.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path) | |
735 | backupvfs = vfsmod.vfs(backuppath) |
|
741 | backupvfs = vfsmod.vfs(backuppath) | |
736 |
|
742 | |||
737 | # Make a backup of requires file first, as it is the first to be modified. |
|
743 | # Make a backup of requires file first, as it is the first to be modified. | |
738 | util.copyfile(srcrepo.vfs.join('requires'), backupvfs.join('requires')) |
|
744 | util.copyfile(srcrepo.vfs.join('requires'), backupvfs.join('requires')) | |
739 |
|
745 | |||
740 | # We install an arbitrary requirement that clients must not support |
|
746 | # We install an arbitrary requirement that clients must not support | |
741 | # as a mechanism to lock out new clients during the data swap. This is |
|
747 | # as a mechanism to lock out new clients during the data swap. This is | |
742 | # better than allowing a client to continue while the repository is in |
|
748 | # better than allowing a client to continue while the repository is in | |
743 | # an inconsistent state. |
|
749 | # an inconsistent state. | |
744 | ui.write(_('marking source repository as being upgraded; clients will be ' |
|
750 | ui.write(_('marking source repository as being upgraded; clients will be ' | |
745 | 'unable to read from repository\n')) |
|
751 | 'unable to read from repository\n')) | |
746 | scmutil.writerequires(srcrepo.vfs, |
|
752 | scmutil.writerequires(srcrepo.vfs, | |
747 | srcrepo.requirements | {'upgradeinprogress'}) |
|
753 | srcrepo.requirements | {'upgradeinprogress'}) | |
748 |
|
754 | |||
749 | ui.write(_('starting in-place swap of repository data\n')) |
|
755 | ui.write(_('starting in-place swap of repository data\n')) | |
750 | ui.write(_('replaced files will be backed up at %s\n') % |
|
756 | ui.write(_('replaced files will be backed up at %s\n') % | |
751 | backuppath) |
|
757 | backuppath) | |
752 |
|
758 | |||
753 | # Now swap in the new store directory. Doing it as a rename should make |
|
759 | # Now swap in the new store directory. Doing it as a rename should make | |
754 | # the operation nearly instantaneous and atomic (at least in well-behaved |
|
760 | # the operation nearly instantaneous and atomic (at least in well-behaved | |
755 | # environments). |
|
761 | # environments). | |
756 | ui.write(_('replacing store...\n')) |
|
762 | ui.write(_('replacing store...\n')) | |
757 | tstart = util.timer() |
|
763 | tstart = util.timer() | |
758 | util.rename(srcrepo.spath, backupvfs.join('store')) |
|
764 | util.rename(srcrepo.spath, backupvfs.join('store')) | |
759 | util.rename(dstrepo.spath, srcrepo.spath) |
|
765 | util.rename(dstrepo.spath, srcrepo.spath) | |
760 | elapsed = util.timer() - tstart |
|
766 | elapsed = util.timer() - tstart | |
761 | ui.write(_('store replacement complete; repository was inconsistent for ' |
|
767 | ui.write(_('store replacement complete; repository was inconsistent for ' | |
762 | '%0.1fs\n') % elapsed) |
|
768 | '%0.1fs\n') % elapsed) | |
763 |
|
769 | |||
764 | # We first write the requirements file. Any new requirements will lock |
|
770 | # We first write the requirements file. Any new requirements will lock | |
765 | # out legacy clients. |
|
771 | # out legacy clients. | |
766 | ui.write(_('finalizing requirements file and making repository readable ' |
|
772 | ui.write(_('finalizing requirements file and making repository readable ' | |
767 | 'again\n')) |
|
773 | 'again\n')) | |
768 | scmutil.writerequires(srcrepo.vfs, requirements) |
|
774 | scmutil.writerequires(srcrepo.vfs, requirements) | |
769 |
|
775 | |||
770 | # The lock file from the old store won't be removed because nothing has a |
|
776 | # The lock file from the old store won't be removed because nothing has a | |
771 | # reference to its new location. So clean it up manually. Alternatively, we |
|
777 | # reference to its new location. So clean it up manually. Alternatively, we | |
772 | # could update srcrepo.svfs and other variables to point to the new |
|
778 | # could update srcrepo.svfs and other variables to point to the new | |
773 | # location. This is simpler. |
|
779 | # location. This is simpler. | |
774 | backupvfs.unlink('store/lock') |
|
780 | backupvfs.unlink('store/lock') | |
775 |
|
781 | |||
776 | return backuppath |
|
782 | return backuppath | |
777 |
|
783 | |||
778 | def upgraderepo(ui, repo, run=False, optimize=None, backup=True): |
|
784 | def upgraderepo(ui, repo, run=False, optimize=None, backup=True): | |
779 | """Upgrade a repository in place.""" |
|
785 | """Upgrade a repository in place.""" | |
780 | if optimize is None: |
|
786 | if optimize is None: | |
781 | optimize = [] |
|
787 | optimize = [] | |
782 | optimize = set(legacy_opts_map.get(o, o) for o in optimize) |
|
788 | optimize = set(legacy_opts_map.get(o, o) for o in optimize) | |
783 | repo = repo.unfiltered() |
|
789 | repo = repo.unfiltered() | |
784 |
|
790 | |||
785 | # Ensure the repository can be upgraded. |
|
791 | # Ensure the repository can be upgraded. | |
786 | missingreqs = requiredsourcerequirements(repo) - repo.requirements |
|
792 | missingreqs = requiredsourcerequirements(repo) - repo.requirements | |
787 | if missingreqs: |
|
793 | if missingreqs: | |
788 | raise error.Abort(_('cannot upgrade repository; requirement ' |
|
794 | raise error.Abort(_('cannot upgrade repository; requirement ' | |
789 | 'missing: %s') % _(', ').join(sorted(missingreqs))) |
|
795 | 'missing: %s') % _(', ').join(sorted(missingreqs))) | |
790 |
|
796 | |||
791 | blockedreqs = blocksourcerequirements(repo) & repo.requirements |
|
797 | blockedreqs = blocksourcerequirements(repo) & repo.requirements | |
792 | if blockedreqs: |
|
798 | if blockedreqs: | |
793 | raise error.Abort(_('cannot upgrade repository; unsupported source ' |
|
799 | raise error.Abort(_('cannot upgrade repository; unsupported source ' | |
794 | 'requirement: %s') % |
|
800 | 'requirement: %s') % | |
795 | _(', ').join(sorted(blockedreqs))) |
|
801 | _(', ').join(sorted(blockedreqs))) | |
796 |
|
802 | |||
797 | # FUTURE there is potentially a need to control the wanted requirements via |
|
803 | # FUTURE there is potentially a need to control the wanted requirements via | |
798 | # command arguments or via an extension hook point. |
|
804 | # command arguments or via an extension hook point. | |
799 | newreqs = localrepo.newreporequirements( |
|
805 | newreqs = localrepo.newreporequirements( | |
800 | repo.ui, localrepo.defaultcreateopts(repo.ui)) |
|
806 | repo.ui, localrepo.defaultcreateopts(repo.ui)) | |
801 | newreqs.update(preservedrequirements(repo)) |
|
807 | newreqs.update(preservedrequirements(repo)) | |
802 |
|
808 | |||
803 | noremovereqs = (repo.requirements - newreqs - |
|
809 | noremovereqs = (repo.requirements - newreqs - | |
804 | supportremovedrequirements(repo)) |
|
810 | supportremovedrequirements(repo)) | |
805 | if noremovereqs: |
|
811 | if noremovereqs: | |
806 | raise error.Abort(_('cannot upgrade repository; requirement would be ' |
|
812 | raise error.Abort(_('cannot upgrade repository; requirement would be ' | |
807 | 'removed: %s') % _(', ').join(sorted(noremovereqs))) |
|
813 | 'removed: %s') % _(', ').join(sorted(noremovereqs))) | |
808 |
|
814 | |||
809 | noaddreqs = (newreqs - repo.requirements - |
|
815 | noaddreqs = (newreqs - repo.requirements - | |
810 | allowednewrequirements(repo)) |
|
816 | allowednewrequirements(repo)) | |
811 | if noaddreqs: |
|
817 | if noaddreqs: | |
812 | raise error.Abort(_('cannot upgrade repository; do not support adding ' |
|
818 | raise error.Abort(_('cannot upgrade repository; do not support adding ' | |
813 | 'requirement: %s') % |
|
819 | 'requirement: %s') % | |
814 | _(', ').join(sorted(noaddreqs))) |
|
820 | _(', ').join(sorted(noaddreqs))) | |
815 |
|
821 | |||
816 | unsupportedreqs = newreqs - supporteddestrequirements(repo) |
|
822 | unsupportedreqs = newreqs - supporteddestrequirements(repo) | |
817 | if unsupportedreqs: |
|
823 | if unsupportedreqs: | |
818 | raise error.Abort(_('cannot upgrade repository; do not support ' |
|
824 | raise error.Abort(_('cannot upgrade repository; do not support ' | |
819 | 'destination requirement: %s') % |
|
825 | 'destination requirement: %s') % | |
820 | _(', ').join(sorted(unsupportedreqs))) |
|
826 | _(', ').join(sorted(unsupportedreqs))) | |
821 |
|
827 | |||
822 | # Find and validate all improvements that can be made. |
|
828 | # Find and validate all improvements that can be made. | |
823 | alloptimizations = findoptimizations(repo) |
|
829 | alloptimizations = findoptimizations(repo) | |
824 |
|
830 | |||
825 | # Apply and Validate arguments. |
|
831 | # Apply and Validate arguments. | |
826 | optimizations = [] |
|
832 | optimizations = [] | |
827 | for o in alloptimizations: |
|
833 | for o in alloptimizations: | |
828 | if o.name in optimize: |
|
834 | if o.name in optimize: | |
829 | optimizations.append(o) |
|
835 | optimizations.append(o) | |
830 | optimize.discard(o.name) |
|
836 | optimize.discard(o.name) | |
831 |
|
837 | |||
832 | if optimize: # anything left is unknown |
|
838 | if optimize: # anything left is unknown | |
833 | raise error.Abort(_('unknown optimization action requested: %s') % |
|
839 | raise error.Abort(_('unknown optimization action requested: %s') % | |
834 | ', '.join(sorted(optimize)), |
|
840 | ', '.join(sorted(optimize)), | |
835 | hint=_('run without arguments to see valid ' |
|
841 | hint=_('run without arguments to see valid ' | |
836 | 'optimizations')) |
|
842 | 'optimizations')) | |
837 |
|
843 | |||
838 | deficiencies = finddeficiencies(repo) |
|
844 | deficiencies = finddeficiencies(repo) | |
839 | actions = determineactions(repo, deficiencies, repo.requirements, newreqs) |
|
845 | actions = determineactions(repo, deficiencies, repo.requirements, newreqs) | |
840 | actions.extend(o for o in sorted(optimizations) |
|
846 | actions.extend(o for o in sorted(optimizations) | |
841 | # determineactions could have added optimisation |
|
847 | # determineactions could have added optimisation | |
842 | if o not in actions) |
|
848 | if o not in actions) | |
843 |
|
849 | |||
844 | def printrequirements(): |
|
850 | def printrequirements(): | |
845 | ui.write(_('requirements\n')) |
|
851 | ui.write(_('requirements\n')) | |
846 | ui.write(_(' preserved: %s\n') % |
|
852 | ui.write(_(' preserved: %s\n') % | |
847 | _(', ').join(sorted(newreqs & repo.requirements))) |
|
853 | _(', ').join(sorted(newreqs & repo.requirements))) | |
848 |
|
854 | |||
849 | if repo.requirements - newreqs: |
|
855 | if repo.requirements - newreqs: | |
850 | ui.write(_(' removed: %s\n') % |
|
856 | ui.write(_(' removed: %s\n') % | |
851 | _(', ').join(sorted(repo.requirements - newreqs))) |
|
857 | _(', ').join(sorted(repo.requirements - newreqs))) | |
852 |
|
858 | |||
853 | if newreqs - repo.requirements: |
|
859 | if newreqs - repo.requirements: | |
854 | ui.write(_(' added: %s\n') % |
|
860 | ui.write(_(' added: %s\n') % | |
855 | _(', ').join(sorted(newreqs - repo.requirements))) |
|
861 | _(', ').join(sorted(newreqs - repo.requirements))) | |
856 |
|
862 | |||
857 | ui.write('\n') |
|
863 | ui.write('\n') | |
858 |
|
864 | |||
859 | def printupgradeactions(): |
|
865 | def printupgradeactions(): | |
860 | for a in actions: |
|
866 | for a in actions: | |
861 | ui.write('%s\n %s\n\n' % (a.name, a.upgrademessage)) |
|
867 | ui.write('%s\n %s\n\n' % (a.name, a.upgrademessage)) | |
862 |
|
868 | |||
863 | if not run: |
|
869 | if not run: | |
864 | fromconfig = [] |
|
870 | fromconfig = [] | |
865 | onlydefault = [] |
|
871 | onlydefault = [] | |
866 |
|
872 | |||
867 | for d in deficiencies: |
|
873 | for d in deficiencies: | |
868 | if d.fromconfig(repo): |
|
874 | if d.fromconfig(repo): | |
869 | fromconfig.append(d) |
|
875 | fromconfig.append(d) | |
870 | elif d.default: |
|
876 | elif d.default: | |
871 | onlydefault.append(d) |
|
877 | onlydefault.append(d) | |
872 |
|
878 | |||
873 | if fromconfig or onlydefault: |
|
879 | if fromconfig or onlydefault: | |
874 |
|
880 | |||
875 | if fromconfig: |
|
881 | if fromconfig: | |
876 | ui.write(_('repository lacks features recommended by ' |
|
882 | ui.write(_('repository lacks features recommended by ' | |
877 | 'current config options:\n\n')) |
|
883 | 'current config options:\n\n')) | |
878 | for i in fromconfig: |
|
884 | for i in fromconfig: | |
879 | ui.write('%s\n %s\n\n' % (i.name, i.description)) |
|
885 | ui.write('%s\n %s\n\n' % (i.name, i.description)) | |
880 |
|
886 | |||
881 | if onlydefault: |
|
887 | if onlydefault: | |
882 | ui.write(_('repository lacks features used by the default ' |
|
888 | ui.write(_('repository lacks features used by the default ' | |
883 | 'config options:\n\n')) |
|
889 | 'config options:\n\n')) | |
884 | for i in onlydefault: |
|
890 | for i in onlydefault: | |
885 | ui.write('%s\n %s\n\n' % (i.name, i.description)) |
|
891 | ui.write('%s\n %s\n\n' % (i.name, i.description)) | |
886 |
|
892 | |||
887 | ui.write('\n') |
|
893 | ui.write('\n') | |
888 | else: |
|
894 | else: | |
889 | ui.write(_('(no feature deficiencies found in existing ' |
|
895 | ui.write(_('(no feature deficiencies found in existing ' | |
890 | 'repository)\n')) |
|
896 | 'repository)\n')) | |
891 |
|
897 | |||
892 | ui.write(_('performing an upgrade with "--run" will make the following ' |
|
898 | ui.write(_('performing an upgrade with "--run" will make the following ' | |
893 | 'changes:\n\n')) |
|
899 | 'changes:\n\n')) | |
894 |
|
900 | |||
895 | printrequirements() |
|
901 | printrequirements() | |
896 | printupgradeactions() |
|
902 | printupgradeactions() | |
897 |
|
903 | |||
898 | unusedoptimize = [i for i in alloptimizations if i not in actions] |
|
904 | unusedoptimize = [i for i in alloptimizations if i not in actions] | |
899 |
|
905 | |||
900 | if unusedoptimize: |
|
906 | if unusedoptimize: | |
901 | ui.write(_('additional optimizations are available by specifying ' |
|
907 | ui.write(_('additional optimizations are available by specifying ' | |
902 | '"--optimize <name>":\n\n')) |
|
908 | '"--optimize <name>":\n\n')) | |
903 | for i in unusedoptimize: |
|
909 | for i in unusedoptimize: | |
904 | ui.write(_('%s\n %s\n\n') % (i.name, i.description)) |
|
910 | ui.write(_('%s\n %s\n\n') % (i.name, i.description)) | |
905 | return |
|
911 | return | |
906 |
|
912 | |||
907 | # Else we're in the run=true case. |
|
913 | # Else we're in the run=true case. | |
908 | ui.write(_('upgrade will perform the following actions:\n\n')) |
|
914 | ui.write(_('upgrade will perform the following actions:\n\n')) | |
909 | printrequirements() |
|
915 | printrequirements() | |
910 | printupgradeactions() |
|
916 | printupgradeactions() | |
911 |
|
917 | |||
912 | upgradeactions = [a.name for a in actions] |
|
918 | upgradeactions = [a.name for a in actions] | |
913 |
|
919 | |||
914 | ui.write(_('beginning upgrade...\n')) |
|
920 | ui.write(_('beginning upgrade...\n')) | |
915 | with repo.wlock(), repo.lock(): |
|
921 | with repo.wlock(), repo.lock(): | |
916 | ui.write(_('repository locked and read-only\n')) |
|
922 | ui.write(_('repository locked and read-only\n')) | |
917 | # Our strategy for upgrading the repository is to create a new, |
|
923 | # Our strategy for upgrading the repository is to create a new, | |
918 | # temporary repository, write data to it, then do a swap of the |
|
924 | # temporary repository, write data to it, then do a swap of the | |
919 | # data. There are less heavyweight ways to do this, but it is easier |
|
925 | # data. There are less heavyweight ways to do this, but it is easier | |
920 | # to create a new repo object than to instantiate all the components |
|
926 | # to create a new repo object than to instantiate all the components | |
921 | # (like the store) separately. |
|
927 | # (like the store) separately. | |
922 | tmppath = pycompat.mkdtemp(prefix='upgrade.', dir=repo.path) |
|
928 | tmppath = pycompat.mkdtemp(prefix='upgrade.', dir=repo.path) | |
923 | backuppath = None |
|
929 | backuppath = None | |
924 | try: |
|
930 | try: | |
925 | ui.write(_('creating temporary repository to stage migrated ' |
|
931 | ui.write(_('creating temporary repository to stage migrated ' | |
926 | 'data: %s\n') % tmppath) |
|
932 | 'data: %s\n') % tmppath) | |
927 |
|
933 | |||
928 | # clone ui without using ui.copy because repo.ui is protected |
|
934 | # clone ui without using ui.copy because repo.ui is protected | |
929 | repoui = repo.ui.__class__(repo.ui) |
|
935 | repoui = repo.ui.__class__(repo.ui) | |
930 | dstrepo = hg.repository(repoui, path=tmppath, create=True) |
|
936 | dstrepo = hg.repository(repoui, path=tmppath, create=True) | |
931 |
|
937 | |||
932 | with dstrepo.wlock(), dstrepo.lock(): |
|
938 | with dstrepo.wlock(), dstrepo.lock(): | |
933 | backuppath = _upgraderepo(ui, repo, dstrepo, newreqs, |
|
939 | backuppath = _upgraderepo(ui, repo, dstrepo, newreqs, | |
934 | upgradeactions) |
|
940 | upgradeactions) | |
935 | if not (backup or backuppath is None): |
|
941 | if not (backup or backuppath is None): | |
936 | ui.write(_('removing old repository content%s\n') % backuppath) |
|
942 | ui.write(_('removing old repository content%s\n') % backuppath) | |
937 | repo.vfs.rmtree(backuppath, forcibly=True) |
|
943 | repo.vfs.rmtree(backuppath, forcibly=True) | |
938 | backuppath = None |
|
944 | backuppath = None | |
939 |
|
945 | |||
940 | finally: |
|
946 | finally: | |
941 | ui.write(_('removing temporary repository %s\n') % tmppath) |
|
947 | ui.write(_('removing temporary repository %s\n') % tmppath) | |
942 | repo.vfs.rmtree(tmppath, forcibly=True) |
|
948 | repo.vfs.rmtree(tmppath, forcibly=True) | |
943 |
|
949 | |||
944 | if backuppath: |
|
950 | if backuppath: | |
945 | ui.warn(_('copy of old repository backed up at %s\n') % |
|
951 | ui.warn(_('copy of old repository backed up at %s\n') % | |
946 | backuppath) |
|
952 | backuppath) | |
947 | ui.warn(_('the old repository will not be deleted; remove ' |
|
953 | ui.warn(_('the old repository will not be deleted; remove ' | |
948 | 'it to free up disk space once the upgraded ' |
|
954 | 'it to free up disk space once the upgraded ' | |
949 | 'repository is verified\n')) |
|
955 | 'repository is verified\n')) |
@@ -1,195 +1,195 b'' | |||||
1 | A new repository uses zlib storage, which doesn't need a requirement |
|
1 | A new repository uses zlib storage, which doesn't need a requirement | |
2 |
|
2 | |||
3 | $ hg init default |
|
3 | $ hg init default | |
4 | $ cd default |
|
4 | $ cd default | |
5 | $ cat .hg/requires |
|
5 | $ cat .hg/requires | |
6 | dotencode |
|
6 | dotencode | |
7 | fncache |
|
7 | fncache | |
8 | generaldelta |
|
8 | generaldelta | |
9 | revlogv1 |
|
9 | revlogv1 | |
10 | sparserevlog |
|
10 | sparserevlog | |
11 | store |
|
11 | store | |
12 | testonly-simplestore (reposimplestore !) |
|
12 | testonly-simplestore (reposimplestore !) | |
13 |
|
13 | |||
14 | $ touch foo |
|
14 | $ touch foo | |
15 | $ hg -q commit -A -m 'initial commit with a lot of repeated repeated repeated text to trigger compression' |
|
15 | $ hg -q commit -A -m 'initial commit with a lot of repeated repeated repeated text to trigger compression' | |
16 | $ hg debugrevlog -c | grep 0x78 |
|
16 | $ hg debugrevlog -c | grep 0x78 | |
17 | 0x78 (x) : 1 (100.00%) |
|
17 | 0x78 (x) : 1 (100.00%) | |
18 | 0x78 (x) : 110 (100.00%) |
|
18 | 0x78 (x) : 110 (100.00%) | |
19 |
|
19 | |||
20 | $ cd .. |
|
20 | $ cd .. | |
21 |
|
21 | |||
22 | Unknown compression engine to format.compression aborts |
|
22 | Unknown compression engine to format.compression aborts | |
23 |
|
23 | |||
24 | $ hg --config format.revlog-compression=unknown init unknown |
|
24 | $ hg --config format.revlog-compression=unknown init unknown | |
25 | abort: compression engine unknown defined by format.revlog-compression not available |
|
25 | abort: compression engine unknown defined by format.revlog-compression not available | |
26 | (run "hg debuginstall" to list available compression engines) |
|
26 | (run "hg debuginstall" to list available compression engines) | |
27 | [255] |
|
27 | [255] | |
28 |
|
28 | |||
29 | A requirement specifying an unknown compression engine results in bail |
|
29 | A requirement specifying an unknown compression engine results in bail | |
30 |
|
30 | |||
31 | $ hg init unknownrequirement |
|
31 | $ hg init unknownrequirement | |
32 | $ cd unknownrequirement |
|
32 | $ cd unknownrequirement | |
33 | $ echo exp-compression-unknown >> .hg/requires |
|
33 | $ echo exp-compression-unknown >> .hg/requires | |
34 | $ hg log |
|
34 | $ hg log | |
35 | abort: repository requires features unknown to this Mercurial: exp-compression-unknown! |
|
35 | abort: repository requires features unknown to this Mercurial: exp-compression-unknown! | |
36 | (see https://mercurial-scm.org/wiki/MissingRequirement for more information) |
|
36 | (see https://mercurial-scm.org/wiki/MissingRequirement for more information) | |
37 | [255] |
|
37 | [255] | |
38 |
|
38 | |||
39 | $ cd .. |
|
39 | $ cd .. | |
40 |
|
40 | |||
41 | #if zstd |
|
41 | #if zstd | |
42 |
|
42 | |||
43 | $ hg --config format.revlog-compression=zstd init zstd |
|
43 | $ hg --config format.revlog-compression=zstd init zstd | |
44 | $ cd zstd |
|
44 | $ cd zstd | |
45 | $ cat .hg/requires |
|
45 | $ cat .hg/requires | |
46 | dotencode |
|
46 | dotencode | |
47 | exp-compression-zstd |
|
|||
48 | fncache |
|
47 | fncache | |
49 | generaldelta |
|
48 | generaldelta | |
|
49 | revlog-compression-zstd | |||
50 | revlogv1 |
|
50 | revlogv1 | |
51 | sparserevlog |
|
51 | sparserevlog | |
52 | store |
|
52 | store | |
53 | testonly-simplestore (reposimplestore !) |
|
53 | testonly-simplestore (reposimplestore !) | |
54 |
|
54 | |||
55 | $ touch foo |
|
55 | $ touch foo | |
56 | $ hg -q commit -A -m 'initial commit with a lot of repeated repeated repeated text' |
|
56 | $ hg -q commit -A -m 'initial commit with a lot of repeated repeated repeated text' | |
57 |
|
57 | |||
58 | $ hg debugrevlog -c | grep 0x28 |
|
58 | $ hg debugrevlog -c | grep 0x28 | |
59 | 0x28 : 1 (100.00%) |
|
59 | 0x28 : 1 (100.00%) | |
60 | 0x28 : 98 (100.00%) |
|
60 | 0x28 : 98 (100.00%) | |
61 |
|
61 | |||
62 | $ cd .. |
|
62 | $ cd .. | |
63 |
|
63 | |||
64 | Specifying a new format.compression on an existing repo won't introduce data |
|
64 | Specifying a new format.compression on an existing repo won't introduce data | |
65 | with that engine or a requirement |
|
65 | with that engine or a requirement | |
66 |
|
66 | |||
67 | $ cd default |
|
67 | $ cd default | |
68 | $ touch bar |
|
68 | $ touch bar | |
69 | $ hg --config format.revlog-compression=zstd -q commit -A -m 'add bar with a lot of repeated repeated repeated text' |
|
69 | $ hg --config format.revlog-compression=zstd -q commit -A -m 'add bar with a lot of repeated repeated repeated text' | |
70 |
|
70 | |||
71 | $ cat .hg/requires |
|
71 | $ cat .hg/requires | |
72 | dotencode |
|
72 | dotencode | |
73 | fncache |
|
73 | fncache | |
74 | generaldelta |
|
74 | generaldelta | |
75 | revlogv1 |
|
75 | revlogv1 | |
76 | sparserevlog |
|
76 | sparserevlog | |
77 | store |
|
77 | store | |
78 | testonly-simplestore (reposimplestore !) |
|
78 | testonly-simplestore (reposimplestore !) | |
79 |
|
79 | |||
80 | $ hg debugrevlog -c | grep 0x78 |
|
80 | $ hg debugrevlog -c | grep 0x78 | |
81 | 0x78 (x) : 2 (100.00%) |
|
81 | 0x78 (x) : 2 (100.00%) | |
82 | 0x78 (x) : 199 (100.00%) |
|
82 | 0x78 (x) : 199 (100.00%) | |
83 |
|
83 | |||
84 | #endif |
|
84 | #endif | |
85 |
|
85 | |||
86 | checking zlib options |
|
86 | checking zlib options | |
87 | ===================== |
|
87 | ===================== | |
88 |
|
88 | |||
89 | $ hg init zlib-level-default |
|
89 | $ hg init zlib-level-default | |
90 | $ hg init zlib-level-1 |
|
90 | $ hg init zlib-level-1 | |
91 | $ cat << EOF >> zlib-level-1/.hg/hgrc |
|
91 | $ cat << EOF >> zlib-level-1/.hg/hgrc | |
92 | > [storage] |
|
92 | > [storage] | |
93 | > revlog.zlib.level=1 |
|
93 | > revlog.zlib.level=1 | |
94 | > EOF |
|
94 | > EOF | |
95 | $ hg init zlib-level-9 |
|
95 | $ hg init zlib-level-9 | |
96 | $ cat << EOF >> zlib-level-9/.hg/hgrc |
|
96 | $ cat << EOF >> zlib-level-9/.hg/hgrc | |
97 | > [storage] |
|
97 | > [storage] | |
98 | > revlog.zlib.level=9 |
|
98 | > revlog.zlib.level=9 | |
99 | > EOF |
|
99 | > EOF | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | $ commitone() { |
|
102 | $ commitone() { | |
103 | > repo=$1 |
|
103 | > repo=$1 | |
104 | > cp $RUNTESTDIR/bundles/issue4438-r1.hg $repo/a |
|
104 | > cp $RUNTESTDIR/bundles/issue4438-r1.hg $repo/a | |
105 | > hg -R $repo add $repo/a |
|
105 | > hg -R $repo add $repo/a | |
106 | > hg -R $repo commit -m some-commit |
|
106 | > hg -R $repo commit -m some-commit | |
107 | > } |
|
107 | > } | |
108 |
|
108 | |||
109 | $ for repo in zlib-level-default zlib-level-1 zlib-level-9; do |
|
109 | $ for repo in zlib-level-default zlib-level-1 zlib-level-9; do | |
110 | > commitone $repo |
|
110 | > commitone $repo | |
111 | > done |
|
111 | > done | |
112 |
|
112 | |||
113 | $ $RUNTESTDIR/f -s */.hg/store/data/* |
|
113 | $ $RUNTESTDIR/f -s */.hg/store/data/* | |
114 | zlib-level-1/.hg/store/data/a.i: size=4146 |
|
114 | zlib-level-1/.hg/store/data/a.i: size=4146 | |
115 | zlib-level-9/.hg/store/data/a.i: size=4138 |
|
115 | zlib-level-9/.hg/store/data/a.i: size=4138 | |
116 | zlib-level-default/.hg/store/data/a.i: size=4138 |
|
116 | zlib-level-default/.hg/store/data/a.i: size=4138 | |
117 |
|
117 | |||
118 | Test error cases |
|
118 | Test error cases | |
119 |
|
119 | |||
120 | $ hg init zlib-level-invalid |
|
120 | $ hg init zlib-level-invalid | |
121 | $ cat << EOF >> zlib-level-invalid/.hg/hgrc |
|
121 | $ cat << EOF >> zlib-level-invalid/.hg/hgrc | |
122 | > [storage] |
|
122 | > [storage] | |
123 | > revlog.zlib.level=foobar |
|
123 | > revlog.zlib.level=foobar | |
124 | > EOF |
|
124 | > EOF | |
125 | $ commitone zlib-level-invalid |
|
125 | $ commitone zlib-level-invalid | |
126 | abort: storage.revlog.zlib.level is not a valid integer ('foobar') |
|
126 | abort: storage.revlog.zlib.level is not a valid integer ('foobar') | |
127 | abort: storage.revlog.zlib.level is not a valid integer ('foobar') |
|
127 | abort: storage.revlog.zlib.level is not a valid integer ('foobar') | |
128 | [255] |
|
128 | [255] | |
129 |
|
129 | |||
130 | $ hg init zlib-level-out-of-range |
|
130 | $ hg init zlib-level-out-of-range | |
131 | $ cat << EOF >> zlib-level-out-of-range/.hg/hgrc |
|
131 | $ cat << EOF >> zlib-level-out-of-range/.hg/hgrc | |
132 | > [storage] |
|
132 | > [storage] | |
133 | > revlog.zlib.level=42 |
|
133 | > revlog.zlib.level=42 | |
134 | > EOF |
|
134 | > EOF | |
135 |
|
135 | |||
136 | $ commitone zlib-level-out-of-range |
|
136 | $ commitone zlib-level-out-of-range | |
137 | abort: invalid value for `storage.revlog.zlib.level` config: 42 |
|
137 | abort: invalid value for `storage.revlog.zlib.level` config: 42 | |
138 | abort: invalid value for `storage.revlog.zlib.level` config: 42 |
|
138 | abort: invalid value for `storage.revlog.zlib.level` config: 42 | |
139 | [255] |
|
139 | [255] | |
140 |
|
140 | |||
141 | checking zstd options |
|
141 | checking zstd options | |
142 | ===================== |
|
142 | ===================== | |
143 |
|
143 | |||
144 | $ hg init zstd-level-default --config format.revlog-compression=zstd |
|
144 | $ hg init zstd-level-default --config format.revlog-compression=zstd | |
145 | $ hg init zstd-level-1 --config format.revlog-compression=zstd |
|
145 | $ hg init zstd-level-1 --config format.revlog-compression=zstd | |
146 | $ cat << EOF >> zstd-level-1/.hg/hgrc |
|
146 | $ cat << EOF >> zstd-level-1/.hg/hgrc | |
147 | > [storage] |
|
147 | > [storage] | |
148 | > revlog.zstd.level=1 |
|
148 | > revlog.zstd.level=1 | |
149 | > EOF |
|
149 | > EOF | |
150 | $ hg init zstd-level-22 --config format.revlog-compression=zstd |
|
150 | $ hg init zstd-level-22 --config format.revlog-compression=zstd | |
151 | $ cat << EOF >> zstd-level-22/.hg/hgrc |
|
151 | $ cat << EOF >> zstd-level-22/.hg/hgrc | |
152 | > [storage] |
|
152 | > [storage] | |
153 | > revlog.zstd.level=22 |
|
153 | > revlog.zstd.level=22 | |
154 | > EOF |
|
154 | > EOF | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | $ commitone() { |
|
157 | $ commitone() { | |
158 | > repo=$1 |
|
158 | > repo=$1 | |
159 | > cp $RUNTESTDIR/bundles/issue4438-r1.hg $repo/a |
|
159 | > cp $RUNTESTDIR/bundles/issue4438-r1.hg $repo/a | |
160 | > hg -R $repo add $repo/a |
|
160 | > hg -R $repo add $repo/a | |
161 | > hg -R $repo commit -m some-commit |
|
161 | > hg -R $repo commit -m some-commit | |
162 | > } |
|
162 | > } | |
163 |
|
163 | |||
164 | $ for repo in zstd-level-default zstd-level-1 zstd-level-22; do |
|
164 | $ for repo in zstd-level-default zstd-level-1 zstd-level-22; do | |
165 | > commitone $repo |
|
165 | > commitone $repo | |
166 | > done |
|
166 | > done | |
167 |
|
167 | |||
168 | $ $RUNTESTDIR/f -s zstd-*/.hg/store/data/* |
|
168 | $ $RUNTESTDIR/f -s zstd-*/.hg/store/data/* | |
169 | zstd-level-1/.hg/store/data/a.i: size=4097 |
|
169 | zstd-level-1/.hg/store/data/a.i: size=4097 | |
170 | zstd-level-22/.hg/store/data/a.i: size=4091 |
|
170 | zstd-level-22/.hg/store/data/a.i: size=4091 | |
171 | zstd-level-default/.hg/store/data/a.i: size=4094 |
|
171 | zstd-level-default/.hg/store/data/a.i: size=4094 | |
172 |
|
172 | |||
173 | Test error cases |
|
173 | Test error cases | |
174 |
|
174 | |||
175 | $ hg init zstd-level-invalid --config format.revlog-compression=zstd |
|
175 | $ hg init zstd-level-invalid --config format.revlog-compression=zstd | |
176 | $ cat << EOF >> zstd-level-invalid/.hg/hgrc |
|
176 | $ cat << EOF >> zstd-level-invalid/.hg/hgrc | |
177 | > [storage] |
|
177 | > [storage] | |
178 | > revlog.zstd.level=foobar |
|
178 | > revlog.zstd.level=foobar | |
179 | > EOF |
|
179 | > EOF | |
180 | $ commitone zstd-level-invalid |
|
180 | $ commitone zstd-level-invalid | |
181 | abort: storage.revlog.zstd.level is not a valid integer ('foobar') |
|
181 | abort: storage.revlog.zstd.level is not a valid integer ('foobar') | |
182 | abort: storage.revlog.zstd.level is not a valid integer ('foobar') |
|
182 | abort: storage.revlog.zstd.level is not a valid integer ('foobar') | |
183 | [255] |
|
183 | [255] | |
184 |
|
184 | |||
185 | $ hg init zstd-level-out-of-range --config format.revlog-compression=zstd |
|
185 | $ hg init zstd-level-out-of-range --config format.revlog-compression=zstd | |
186 | $ cat << EOF >> zstd-level-out-of-range/.hg/hgrc |
|
186 | $ cat << EOF >> zstd-level-out-of-range/.hg/hgrc | |
187 | > [storage] |
|
187 | > [storage] | |
188 | > revlog.zstd.level=42 |
|
188 | > revlog.zstd.level=42 | |
189 | > EOF |
|
189 | > EOF | |
190 |
|
190 | |||
191 | $ commitone zstd-level-out-of-range |
|
191 | $ commitone zstd-level-out-of-range | |
192 | abort: invalid value for `storage.revlog.zstd.level` config: 42 |
|
192 | abort: invalid value for `storage.revlog.zstd.level` config: 42 | |
193 | abort: invalid value for `storage.revlog.zstd.level` config: 42 |
|
193 | abort: invalid value for `storage.revlog.zstd.level` config: 42 | |
194 | [255] |
|
194 | [255] | |
195 |
|
195 |
General Comments 0
You need to be logged in to leave comments.
Login now