Show More
@@ -1,2332 +1,2332 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 time |
|
14 | import time | |
15 | import weakref |
|
15 | import weakref | |
16 |
|
16 | |||
17 | from .i18n import _ |
|
17 | from .i18n import _ | |
18 | from .node import ( |
|
18 | from .node import ( | |
19 | hex, |
|
19 | hex, | |
20 | nullid, |
|
20 | nullid, | |
21 | short, |
|
21 | short, | |
22 | ) |
|
22 | ) | |
23 | from . import ( |
|
23 | from . import ( | |
24 | bookmarks, |
|
24 | bookmarks, | |
25 | branchmap, |
|
25 | branchmap, | |
26 | bundle2, |
|
26 | bundle2, | |
27 | changegroup, |
|
27 | changegroup, | |
28 | changelog, |
|
28 | changelog, | |
29 | color, |
|
29 | color, | |
30 | context, |
|
30 | context, | |
31 | dirstate, |
|
31 | dirstate, | |
32 | dirstateguard, |
|
32 | dirstateguard, | |
33 | discovery, |
|
33 | discovery, | |
34 | encoding, |
|
34 | encoding, | |
35 | error, |
|
35 | error, | |
36 | exchange, |
|
36 | exchange, | |
37 | extensions, |
|
37 | extensions, | |
38 | filelog, |
|
38 | filelog, | |
39 | hook, |
|
39 | hook, | |
40 | lock as lockmod, |
|
40 | lock as lockmod, | |
41 | manifest, |
|
41 | manifest, | |
42 | match as matchmod, |
|
42 | match as matchmod, | |
43 | merge as mergemod, |
|
43 | merge as mergemod, | |
44 | mergeutil, |
|
44 | mergeutil, | |
45 | namespaces, |
|
45 | namespaces, | |
46 | narrowspec, |
|
46 | narrowspec, | |
47 | obsolete, |
|
47 | obsolete, | |
48 | pathutil, |
|
48 | pathutil, | |
49 | peer, |
|
49 | peer, | |
50 | phases, |
|
50 | phases, | |
51 | pushkey, |
|
51 | pushkey, | |
52 | pycompat, |
|
52 | pycompat, | |
53 | repository, |
|
53 | repository, | |
54 | repoview, |
|
54 | repoview, | |
55 | revset, |
|
55 | revset, | |
56 | revsetlang, |
|
56 | revsetlang, | |
57 | scmutil, |
|
57 | scmutil, | |
58 | sparse, |
|
58 | sparse, | |
59 | store, |
|
59 | store, | |
60 | subrepoutil, |
|
60 | subrepoutil, | |
61 | tags as tagsmod, |
|
61 | tags as tagsmod, | |
62 | transaction, |
|
62 | transaction, | |
63 | txnutil, |
|
63 | txnutil, | |
64 | util, |
|
64 | util, | |
65 | vfs as vfsmod, |
|
65 | vfs as vfsmod, | |
66 | ) |
|
66 | ) | |
67 | from .utils import ( |
|
67 | from .utils import ( | |
68 | procutil, |
|
68 | procutil, | |
69 | stringutil, |
|
69 | stringutil, | |
70 | ) |
|
70 | ) | |
71 |
|
71 | |||
72 | release = lockmod.release |
|
72 | release = lockmod.release | |
73 | urlerr = util.urlerr |
|
73 | urlerr = util.urlerr | |
74 | urlreq = util.urlreq |
|
74 | urlreq = util.urlreq | |
75 |
|
75 | |||
76 | # set of (path, vfs-location) tuples. vfs-location is: |
|
76 | # set of (path, vfs-location) tuples. vfs-location is: | |
77 | # - 'plain for vfs relative paths |
|
77 | # - 'plain for vfs relative paths | |
78 | # - '' for svfs relative paths |
|
78 | # - '' for svfs relative paths | |
79 | _cachedfiles = set() |
|
79 | _cachedfiles = set() | |
80 |
|
80 | |||
81 | class _basefilecache(scmutil.filecache): |
|
81 | class _basefilecache(scmutil.filecache): | |
82 | """All filecache usage on repo are done for logic that should be unfiltered |
|
82 | """All filecache usage on repo are done for logic that should be unfiltered | |
83 | """ |
|
83 | """ | |
84 | def __get__(self, repo, type=None): |
|
84 | def __get__(self, repo, type=None): | |
85 | if repo is None: |
|
85 | if repo is None: | |
86 | return self |
|
86 | return self | |
87 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) |
|
87 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) | |
88 | def __set__(self, repo, value): |
|
88 | def __set__(self, repo, value): | |
89 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) |
|
89 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) | |
90 | def __delete__(self, repo): |
|
90 | def __delete__(self, repo): | |
91 | return super(_basefilecache, self).__delete__(repo.unfiltered()) |
|
91 | return super(_basefilecache, self).__delete__(repo.unfiltered()) | |
92 |
|
92 | |||
93 | class repofilecache(_basefilecache): |
|
93 | class repofilecache(_basefilecache): | |
94 | """filecache for files in .hg but outside of .hg/store""" |
|
94 | """filecache for files in .hg but outside of .hg/store""" | |
95 | def __init__(self, *paths): |
|
95 | def __init__(self, *paths): | |
96 | super(repofilecache, self).__init__(*paths) |
|
96 | super(repofilecache, self).__init__(*paths) | |
97 | for path in paths: |
|
97 | for path in paths: | |
98 | _cachedfiles.add((path, 'plain')) |
|
98 | _cachedfiles.add((path, 'plain')) | |
99 |
|
99 | |||
100 | def join(self, obj, fname): |
|
100 | def join(self, obj, fname): | |
101 | return obj.vfs.join(fname) |
|
101 | return obj.vfs.join(fname) | |
102 |
|
102 | |||
103 | class storecache(_basefilecache): |
|
103 | class storecache(_basefilecache): | |
104 | """filecache for files in the store""" |
|
104 | """filecache for files in the store""" | |
105 | def __init__(self, *paths): |
|
105 | def __init__(self, *paths): | |
106 | super(storecache, self).__init__(*paths) |
|
106 | super(storecache, self).__init__(*paths) | |
107 | for path in paths: |
|
107 | for path in paths: | |
108 | _cachedfiles.add((path, '')) |
|
108 | _cachedfiles.add((path, '')) | |
109 |
|
109 | |||
110 | def join(self, obj, fname): |
|
110 | def join(self, obj, fname): | |
111 | return obj.sjoin(fname) |
|
111 | return obj.sjoin(fname) | |
112 |
|
112 | |||
113 | def isfilecached(repo, name): |
|
113 | def isfilecached(repo, name): | |
114 | """check if a repo has already cached "name" filecache-ed property |
|
114 | """check if a repo has already cached "name" filecache-ed property | |
115 |
|
115 | |||
116 | This returns (cachedobj-or-None, iscached) tuple. |
|
116 | This returns (cachedobj-or-None, iscached) tuple. | |
117 | """ |
|
117 | """ | |
118 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
118 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
119 | if not cacheentry: |
|
119 | if not cacheentry: | |
120 | return None, False |
|
120 | return None, False | |
121 | return cacheentry.obj, True |
|
121 | return cacheentry.obj, True | |
122 |
|
122 | |||
123 | class unfilteredpropertycache(util.propertycache): |
|
123 | class unfilteredpropertycache(util.propertycache): | |
124 | """propertycache that apply to unfiltered repo only""" |
|
124 | """propertycache that apply to unfiltered repo only""" | |
125 |
|
125 | |||
126 | def __get__(self, repo, type=None): |
|
126 | def __get__(self, repo, type=None): | |
127 | unfi = repo.unfiltered() |
|
127 | unfi = repo.unfiltered() | |
128 | if unfi is repo: |
|
128 | if unfi is repo: | |
129 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
129 | return super(unfilteredpropertycache, self).__get__(unfi) | |
130 | return getattr(unfi, self.name) |
|
130 | return getattr(unfi, self.name) | |
131 |
|
131 | |||
132 | class filteredpropertycache(util.propertycache): |
|
132 | class filteredpropertycache(util.propertycache): | |
133 | """propertycache that must take filtering in account""" |
|
133 | """propertycache that must take filtering in account""" | |
134 |
|
134 | |||
135 | def cachevalue(self, obj, value): |
|
135 | def cachevalue(self, obj, value): | |
136 | object.__setattr__(obj, self.name, value) |
|
136 | object.__setattr__(obj, self.name, value) | |
137 |
|
137 | |||
138 |
|
138 | |||
139 | def hasunfilteredcache(repo, name): |
|
139 | def hasunfilteredcache(repo, name): | |
140 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
140 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
141 | return name in vars(repo.unfiltered()) |
|
141 | return name in vars(repo.unfiltered()) | |
142 |
|
142 | |||
143 | def unfilteredmethod(orig): |
|
143 | def unfilteredmethod(orig): | |
144 | """decorate method that always need to be run on unfiltered version""" |
|
144 | """decorate method that always need to be run on unfiltered version""" | |
145 | def wrapper(repo, *args, **kwargs): |
|
145 | def wrapper(repo, *args, **kwargs): | |
146 | return orig(repo.unfiltered(), *args, **kwargs) |
|
146 | return orig(repo.unfiltered(), *args, **kwargs) | |
147 | return wrapper |
|
147 | return wrapper | |
148 |
|
148 | |||
149 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
149 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
150 | 'unbundle'} |
|
150 | 'unbundle'} | |
151 | legacycaps = moderncaps.union({'changegroupsubset'}) |
|
151 | legacycaps = moderncaps.union({'changegroupsubset'}) | |
152 |
|
152 | |||
153 | class localpeer(repository.peer): |
|
153 | class localpeer(repository.peer): | |
154 | '''peer for a local repo; reflects only the most recent API''' |
|
154 | '''peer for a local repo; reflects only the most recent API''' | |
155 |
|
155 | |||
156 | def __init__(self, repo, caps=None): |
|
156 | def __init__(self, repo, caps=None): | |
157 | super(localpeer, self).__init__() |
|
157 | super(localpeer, self).__init__() | |
158 |
|
158 | |||
159 | if caps is None: |
|
159 | if caps is None: | |
160 | caps = moderncaps.copy() |
|
160 | caps = moderncaps.copy() | |
161 | self._repo = repo.filtered('served') |
|
161 | self._repo = repo.filtered('served') | |
162 | self._ui = repo.ui |
|
162 | self._ui = repo.ui | |
163 | self._caps = repo._restrictcapabilities(caps) |
|
163 | self._caps = repo._restrictcapabilities(caps) | |
164 |
|
164 | |||
165 | # Begin of _basepeer interface. |
|
165 | # Begin of _basepeer interface. | |
166 |
|
166 | |||
167 | @util.propertycache |
|
167 | @util.propertycache | |
168 | def ui(self): |
|
168 | def ui(self): | |
169 | return self._ui |
|
169 | return self._ui | |
170 |
|
170 | |||
171 | def url(self): |
|
171 | def url(self): | |
172 | return self._repo.url() |
|
172 | return self._repo.url() | |
173 |
|
173 | |||
174 | def local(self): |
|
174 | def local(self): | |
175 | return self._repo |
|
175 | return self._repo | |
176 |
|
176 | |||
177 | def peer(self): |
|
177 | def peer(self): | |
178 | return self |
|
178 | return self | |
179 |
|
179 | |||
180 | def canpush(self): |
|
180 | def canpush(self): | |
181 | return True |
|
181 | return True | |
182 |
|
182 | |||
183 | def close(self): |
|
183 | def close(self): | |
184 | self._repo.close() |
|
184 | self._repo.close() | |
185 |
|
185 | |||
186 | # End of _basepeer interface. |
|
186 | # End of _basepeer interface. | |
187 |
|
187 | |||
188 | # Begin of _basewirecommands interface. |
|
188 | # Begin of _basewirecommands interface. | |
189 |
|
189 | |||
190 | def branchmap(self): |
|
190 | def branchmap(self): | |
191 | return self._repo.branchmap() |
|
191 | return self._repo.branchmap() | |
192 |
|
192 | |||
193 | def capabilities(self): |
|
193 | def capabilities(self): | |
194 | return self._caps |
|
194 | return self._caps | |
195 |
|
195 | |||
196 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
196 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
197 | """Used to test argument passing over the wire""" |
|
197 | """Used to test argument passing over the wire""" | |
198 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
198 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
199 | pycompat.bytestr(four), |
|
199 | pycompat.bytestr(four), | |
200 | pycompat.bytestr(five)) |
|
200 | pycompat.bytestr(five)) | |
201 |
|
201 | |||
202 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
202 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
203 | **kwargs): |
|
203 | **kwargs): | |
204 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
204 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, | |
205 | common=common, bundlecaps=bundlecaps, |
|
205 | common=common, bundlecaps=bundlecaps, | |
206 | **kwargs)[1] |
|
206 | **kwargs)[1] | |
207 | cb = util.chunkbuffer(chunks) |
|
207 | cb = util.chunkbuffer(chunks) | |
208 |
|
208 | |||
209 | if exchange.bundle2requested(bundlecaps): |
|
209 | if exchange.bundle2requested(bundlecaps): | |
210 | # When requesting a bundle2, getbundle returns a stream to make the |
|
210 | # When requesting a bundle2, getbundle returns a stream to make the | |
211 | # wire level function happier. We need to build a proper object |
|
211 | # wire level function happier. We need to build a proper object | |
212 | # from it in local peer. |
|
212 | # from it in local peer. | |
213 | return bundle2.getunbundler(self.ui, cb) |
|
213 | return bundle2.getunbundler(self.ui, cb) | |
214 | else: |
|
214 | else: | |
215 | return changegroup.getunbundler('01', cb, None) |
|
215 | return changegroup.getunbundler('01', cb, None) | |
216 |
|
216 | |||
217 | def heads(self): |
|
217 | def heads(self): | |
218 | return self._repo.heads() |
|
218 | return self._repo.heads() | |
219 |
|
219 | |||
220 | def known(self, nodes): |
|
220 | def known(self, nodes): | |
221 | return self._repo.known(nodes) |
|
221 | return self._repo.known(nodes) | |
222 |
|
222 | |||
223 | def listkeys(self, namespace): |
|
223 | def listkeys(self, namespace): | |
224 | return self._repo.listkeys(namespace) |
|
224 | return self._repo.listkeys(namespace) | |
225 |
|
225 | |||
226 | def lookup(self, key): |
|
226 | def lookup(self, key): | |
227 | return self._repo.lookup(key) |
|
227 | return self._repo.lookup(key) | |
228 |
|
228 | |||
229 | def pushkey(self, namespace, key, old, new): |
|
229 | def pushkey(self, namespace, key, old, new): | |
230 | return self._repo.pushkey(namespace, key, old, new) |
|
230 | return self._repo.pushkey(namespace, key, old, new) | |
231 |
|
231 | |||
232 | def stream_out(self): |
|
232 | def stream_out(self): | |
233 | raise error.Abort(_('cannot perform stream clone against local ' |
|
233 | raise error.Abort(_('cannot perform stream clone against local ' | |
234 | 'peer')) |
|
234 | 'peer')) | |
235 |
|
235 | |||
236 | def unbundle(self, cg, heads, url): |
|
236 | def unbundle(self, cg, heads, url): | |
237 | """apply a bundle on a repo |
|
237 | """apply a bundle on a repo | |
238 |
|
238 | |||
239 | This function handles the repo locking itself.""" |
|
239 | This function handles the repo locking itself.""" | |
240 | try: |
|
240 | try: | |
241 | try: |
|
241 | try: | |
242 | cg = exchange.readbundle(self.ui, cg, None) |
|
242 | cg = exchange.readbundle(self.ui, cg, None) | |
243 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
243 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) | |
244 | if util.safehasattr(ret, 'getchunks'): |
|
244 | if util.safehasattr(ret, 'getchunks'): | |
245 | # This is a bundle20 object, turn it into an unbundler. |
|
245 | # This is a bundle20 object, turn it into an unbundler. | |
246 | # This little dance should be dropped eventually when the |
|
246 | # This little dance should be dropped eventually when the | |
247 | # API is finally improved. |
|
247 | # API is finally improved. | |
248 | stream = util.chunkbuffer(ret.getchunks()) |
|
248 | stream = util.chunkbuffer(ret.getchunks()) | |
249 | ret = bundle2.getunbundler(self.ui, stream) |
|
249 | ret = bundle2.getunbundler(self.ui, stream) | |
250 | return ret |
|
250 | return ret | |
251 | except Exception as exc: |
|
251 | except Exception as exc: | |
252 | # If the exception contains output salvaged from a bundle2 |
|
252 | # If the exception contains output salvaged from a bundle2 | |
253 | # reply, we need to make sure it is printed before continuing |
|
253 | # reply, we need to make sure it is printed before continuing | |
254 | # to fail. So we build a bundle2 with such output and consume |
|
254 | # to fail. So we build a bundle2 with such output and consume | |
255 | # it directly. |
|
255 | # it directly. | |
256 | # |
|
256 | # | |
257 | # This is not very elegant but allows a "simple" solution for |
|
257 | # This is not very elegant but allows a "simple" solution for | |
258 | # issue4594 |
|
258 | # issue4594 | |
259 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
259 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
260 | if output: |
|
260 | if output: | |
261 | bundler = bundle2.bundle20(self._repo.ui) |
|
261 | bundler = bundle2.bundle20(self._repo.ui) | |
262 | for out in output: |
|
262 | for out in output: | |
263 | bundler.addpart(out) |
|
263 | bundler.addpart(out) | |
264 | stream = util.chunkbuffer(bundler.getchunks()) |
|
264 | stream = util.chunkbuffer(bundler.getchunks()) | |
265 | b = bundle2.getunbundler(self.ui, stream) |
|
265 | b = bundle2.getunbundler(self.ui, stream) | |
266 | bundle2.processbundle(self._repo, b) |
|
266 | bundle2.processbundle(self._repo, b) | |
267 | raise |
|
267 | raise | |
268 | except error.PushRaced as exc: |
|
268 | except error.PushRaced as exc: | |
269 | raise error.ResponseError(_('push failed:'), |
|
269 | raise error.ResponseError(_('push failed:'), | |
270 | stringutil.forcebytestr(exc)) |
|
270 | stringutil.forcebytestr(exc)) | |
271 |
|
271 | |||
272 | # End of _basewirecommands interface. |
|
272 | # End of _basewirecommands interface. | |
273 |
|
273 | |||
274 | # Begin of peer interface. |
|
274 | # Begin of peer interface. | |
275 |
|
275 | |||
276 | def iterbatch(self): |
|
276 | def iterbatch(self): | |
277 | return peer.localiterbatcher(self) |
|
277 | return peer.localiterbatcher(self) | |
278 |
|
278 | |||
279 | # End of peer interface. |
|
279 | # End of peer interface. | |
280 |
|
280 | |||
281 | class locallegacypeer(repository.legacypeer, localpeer): |
|
281 | class locallegacypeer(repository.legacypeer, localpeer): | |
282 | '''peer extension which implements legacy methods too; used for tests with |
|
282 | '''peer extension which implements legacy methods too; used for tests with | |
283 | restricted capabilities''' |
|
283 | restricted capabilities''' | |
284 |
|
284 | |||
285 | def __init__(self, repo): |
|
285 | def __init__(self, repo): | |
286 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
286 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
287 |
|
287 | |||
288 | # Begin of baselegacywirecommands interface. |
|
288 | # Begin of baselegacywirecommands interface. | |
289 |
|
289 | |||
290 | def between(self, pairs): |
|
290 | def between(self, pairs): | |
291 | return self._repo.between(pairs) |
|
291 | return self._repo.between(pairs) | |
292 |
|
292 | |||
293 | def branches(self, nodes): |
|
293 | def branches(self, nodes): | |
294 | return self._repo.branches(nodes) |
|
294 | return self._repo.branches(nodes) | |
295 |
|
295 | |||
296 | def changegroup(self, basenodes, source): |
|
296 | def changegroup(self, basenodes, source): | |
297 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, |
|
297 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, | |
298 | missingheads=self._repo.heads()) |
|
298 | missingheads=self._repo.heads()) | |
299 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
299 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
300 |
|
300 | |||
301 | def changegroupsubset(self, bases, heads, source): |
|
301 | def changegroupsubset(self, bases, heads, source): | |
302 | outgoing = discovery.outgoing(self._repo, missingroots=bases, |
|
302 | outgoing = discovery.outgoing(self._repo, missingroots=bases, | |
303 | missingheads=heads) |
|
303 | missingheads=heads) | |
304 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
304 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
305 |
|
305 | |||
306 | # End of baselegacywirecommands interface. |
|
306 | # End of baselegacywirecommands interface. | |
307 |
|
307 | |||
308 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
308 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
309 | # clients. |
|
309 | # clients. | |
310 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' |
|
310 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' | |
311 |
|
311 | |||
312 | # Functions receiving (ui, features) that extensions can register to impact |
|
312 | # Functions receiving (ui, features) that extensions can register to impact | |
313 | # the ability to load repositories with custom requirements. Only |
|
313 | # the ability to load repositories with custom requirements. Only | |
314 | # functions defined in loaded extensions are called. |
|
314 | # functions defined in loaded extensions are called. | |
315 | # |
|
315 | # | |
316 | # The function receives a set of requirement strings that the repository |
|
316 | # The function receives a set of requirement strings that the repository | |
317 | # is capable of opening. Functions will typically add elements to the |
|
317 | # is capable of opening. Functions will typically add elements to the | |
318 | # set to reflect that the extension knows how to handle that requirements. |
|
318 | # set to reflect that the extension knows how to handle that requirements. | |
319 | featuresetupfuncs = set() |
|
319 | featuresetupfuncs = set() | |
320 |
|
320 | |||
321 | class localrepository(object): |
|
321 | class localrepository(object): | |
322 |
|
322 | |||
323 | # obsolete experimental requirements: |
|
323 | # obsolete experimental requirements: | |
324 | # - manifestv2: An experimental new manifest format that allowed |
|
324 | # - manifestv2: An experimental new manifest format that allowed | |
325 | # for stem compression of long paths. Experiment ended up not |
|
325 | # for stem compression of long paths. Experiment ended up not | |
326 | # being successful (repository sizes went up due to worse delta |
|
326 | # being successful (repository sizes went up due to worse delta | |
327 | # chains), and the code was deleted in 4.6. |
|
327 | # chains), and the code was deleted in 4.6. | |
328 | supportedformats = { |
|
328 | supportedformats = { | |
329 | 'revlogv1', |
|
329 | 'revlogv1', | |
330 | 'generaldelta', |
|
330 | 'generaldelta', | |
331 | 'treemanifest', |
|
331 | 'treemanifest', | |
332 | REVLOGV2_REQUIREMENT, |
|
332 | REVLOGV2_REQUIREMENT, | |
333 | } |
|
333 | } | |
334 | _basesupported = supportedformats | { |
|
334 | _basesupported = supportedformats | { | |
335 | 'store', |
|
335 | 'store', | |
336 | 'fncache', |
|
336 | 'fncache', | |
337 | 'shared', |
|
337 | 'shared', | |
338 | 'relshared', |
|
338 | 'relshared', | |
339 | 'dotencode', |
|
339 | 'dotencode', | |
340 | 'exp-sparse', |
|
340 | 'exp-sparse', | |
341 | } |
|
341 | } | |
342 | openerreqs = { |
|
342 | openerreqs = { | |
343 | 'revlogv1', |
|
343 | 'revlogv1', | |
344 | 'generaldelta', |
|
344 | 'generaldelta', | |
345 | 'treemanifest', |
|
345 | 'treemanifest', | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | # list of prefix for file which can be written without 'wlock' |
|
348 | # list of prefix for file which can be written without 'wlock' | |
349 | # Extensions should extend this list when needed |
|
349 | # Extensions should extend this list when needed | |
350 | _wlockfreeprefix = { |
|
350 | _wlockfreeprefix = { | |
351 | # We migh consider requiring 'wlock' for the next |
|
351 | # We migh consider requiring 'wlock' for the next | |
352 | # two, but pretty much all the existing code assume |
|
352 | # two, but pretty much all the existing code assume | |
353 | # wlock is not needed so we keep them excluded for |
|
353 | # wlock is not needed so we keep them excluded for | |
354 | # now. |
|
354 | # now. | |
355 | 'hgrc', |
|
355 | 'hgrc', | |
356 | 'requires', |
|
356 | 'requires', | |
357 | # XXX cache is a complicatged business someone |
|
357 | # XXX cache is a complicatged business someone | |
358 | # should investigate this in depth at some point |
|
358 | # should investigate this in depth at some point | |
359 | 'cache/', |
|
359 | 'cache/', | |
360 | # XXX shouldn't be dirstate covered by the wlock? |
|
360 | # XXX shouldn't be dirstate covered by the wlock? | |
361 | 'dirstate', |
|
361 | 'dirstate', | |
362 | # XXX bisect was still a bit too messy at the time |
|
362 | # XXX bisect was still a bit too messy at the time | |
363 | # this changeset was introduced. Someone should fix |
|
363 | # this changeset was introduced. Someone should fix | |
364 | # the remainig bit and drop this line |
|
364 | # the remainig bit and drop this line | |
365 | 'bisect.state', |
|
365 | 'bisect.state', | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | def __init__(self, baseui, path, create=False): |
|
368 | def __init__(self, baseui, path, create=False): | |
369 | self.requirements = set() |
|
369 | self.requirements = set() | |
370 | self.filtername = None |
|
370 | self.filtername = None | |
371 | # wvfs: rooted at the repository root, used to access the working copy |
|
371 | # wvfs: rooted at the repository root, used to access the working copy | |
372 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
372 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
373 | # vfs: rooted at .hg, used to access repo files outside of .hg/store |
|
373 | # vfs: rooted at .hg, used to access repo files outside of .hg/store | |
374 | self.vfs = None |
|
374 | self.vfs = None | |
375 | # svfs: usually rooted at .hg/store, used to access repository history |
|
375 | # svfs: usually rooted at .hg/store, used to access repository history | |
376 | # If this is a shared repository, this vfs may point to another |
|
376 | # If this is a shared repository, this vfs may point to another | |
377 | # repository's .hg/store directory. |
|
377 | # repository's .hg/store directory. | |
378 | self.svfs = None |
|
378 | self.svfs = None | |
379 | self.root = self.wvfs.base |
|
379 | self.root = self.wvfs.base | |
380 | self.path = self.wvfs.join(".hg") |
|
380 | self.path = self.wvfs.join(".hg") | |
381 | self.origroot = path |
|
381 | self.origroot = path | |
382 | # This is only used by context.workingctx.match in order to |
|
382 | # This is only used by context.workingctx.match in order to | |
383 | # detect files in subrepos. |
|
383 | # detect files in subrepos. | |
384 | self.auditor = pathutil.pathauditor( |
|
384 | self.auditor = pathutil.pathauditor( | |
385 | self.root, callback=self._checknested) |
|
385 | self.root, callback=self._checknested) | |
386 | # This is only used by context.basectx.match in order to detect |
|
386 | # This is only used by context.basectx.match in order to detect | |
387 | # files in subrepos. |
|
387 | # files in subrepos. | |
388 | self.nofsauditor = pathutil.pathauditor( |
|
388 | self.nofsauditor = pathutil.pathauditor( | |
389 | self.root, callback=self._checknested, realfs=False, cached=True) |
|
389 | self.root, callback=self._checknested, realfs=False, cached=True) | |
390 | self.baseui = baseui |
|
390 | self.baseui = baseui | |
391 | self.ui = baseui.copy() |
|
391 | self.ui = baseui.copy() | |
392 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
392 | self.ui.copy = baseui.copy # prevent copying repo configuration | |
393 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) |
|
393 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) | |
394 | if (self.ui.configbool('devel', 'all-warnings') or |
|
394 | if (self.ui.configbool('devel', 'all-warnings') or | |
395 | self.ui.configbool('devel', 'check-locks')): |
|
395 | self.ui.configbool('devel', 'check-locks')): | |
396 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
396 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
397 | # A list of callback to shape the phase if no data were found. |
|
397 | # A list of callback to shape the phase if no data were found. | |
398 | # Callback are in the form: func(repo, roots) --> processed root. |
|
398 | # Callback are in the form: func(repo, roots) --> processed root. | |
399 | # This list it to be filled by extension during repo setup |
|
399 | # This list it to be filled by extension during repo setup | |
400 | self._phasedefaults = [] |
|
400 | self._phasedefaults = [] | |
401 | try: |
|
401 | try: | |
402 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) |
|
402 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) | |
403 | self._loadextensions() |
|
403 | self._loadextensions() | |
404 | except IOError: |
|
404 | except IOError: | |
405 | pass |
|
405 | pass | |
406 |
|
406 | |||
407 | if featuresetupfuncs: |
|
407 | if featuresetupfuncs: | |
408 | self.supported = set(self._basesupported) # use private copy |
|
408 | self.supported = set(self._basesupported) # use private copy | |
409 | extmods = set(m.__name__ for n, m |
|
409 | extmods = set(m.__name__ for n, m | |
410 | in extensions.extensions(self.ui)) |
|
410 | in extensions.extensions(self.ui)) | |
411 | for setupfunc in featuresetupfuncs: |
|
411 | for setupfunc in featuresetupfuncs: | |
412 | if setupfunc.__module__ in extmods: |
|
412 | if setupfunc.__module__ in extmods: | |
413 | setupfunc(self.ui, self.supported) |
|
413 | setupfunc(self.ui, self.supported) | |
414 | else: |
|
414 | else: | |
415 | self.supported = self._basesupported |
|
415 | self.supported = self._basesupported | |
416 | color.setup(self.ui) |
|
416 | color.setup(self.ui) | |
417 |
|
417 | |||
418 | # Add compression engines. |
|
418 | # Add compression engines. | |
419 | for name in util.compengines: |
|
419 | for name in util.compengines: | |
420 | engine = util.compengines[name] |
|
420 | engine = util.compengines[name] | |
421 | if engine.revlogheader(): |
|
421 | if engine.revlogheader(): | |
422 | self.supported.add('exp-compression-%s' % name) |
|
422 | self.supported.add('exp-compression-%s' % name) | |
423 |
|
423 | |||
424 | if not self.vfs.isdir(): |
|
424 | if not self.vfs.isdir(): | |
425 | if create: |
|
425 | if create: | |
426 | self.requirements = newreporequirements(self) |
|
426 | self.requirements = newreporequirements(self) | |
427 |
|
427 | |||
428 | if not self.wvfs.exists(): |
|
428 | if not self.wvfs.exists(): | |
429 | self.wvfs.makedirs() |
|
429 | self.wvfs.makedirs() | |
430 | self.vfs.makedir(notindexed=True) |
|
430 | self.vfs.makedir(notindexed=True) | |
431 |
|
431 | |||
432 | if 'store' in self.requirements: |
|
432 | if 'store' in self.requirements: | |
433 | self.vfs.mkdir("store") |
|
433 | self.vfs.mkdir("store") | |
434 |
|
434 | |||
435 | # create an invalid changelog |
|
435 | # create an invalid changelog | |
436 | self.vfs.append( |
|
436 | self.vfs.append( | |
437 | "00changelog.i", |
|
437 | "00changelog.i", | |
438 | '\0\0\0\2' # represents revlogv2 |
|
438 | '\0\0\0\2' # represents revlogv2 | |
439 | ' dummy changelog to prevent using the old repo layout' |
|
439 | ' dummy changelog to prevent using the old repo layout' | |
440 | ) |
|
440 | ) | |
441 | else: |
|
441 | else: | |
442 | raise error.RepoError(_("repository %s not found") % path) |
|
442 | raise error.RepoError(_("repository %s not found") % path) | |
443 | elif create: |
|
443 | elif create: | |
444 | raise error.RepoError(_("repository %s already exists") % path) |
|
444 | raise error.RepoError(_("repository %s already exists") % path) | |
445 | else: |
|
445 | else: | |
446 | try: |
|
446 | try: | |
447 | self.requirements = scmutil.readrequires( |
|
447 | self.requirements = scmutil.readrequires( | |
448 | self.vfs, self.supported) |
|
448 | self.vfs, self.supported) | |
449 | except IOError as inst: |
|
449 | except IOError as inst: | |
450 | if inst.errno != errno.ENOENT: |
|
450 | if inst.errno != errno.ENOENT: | |
451 | raise |
|
451 | raise | |
452 |
|
452 | |||
453 | cachepath = self.vfs.join('cache') |
|
453 | cachepath = self.vfs.join('cache') | |
454 | self.sharedpath = self.path |
|
454 | self.sharedpath = self.path | |
455 | try: |
|
455 | try: | |
456 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') |
|
456 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') | |
457 | if 'relshared' in self.requirements: |
|
457 | if 'relshared' in self.requirements: | |
458 | sharedpath = self.vfs.join(sharedpath) |
|
458 | sharedpath = self.vfs.join(sharedpath) | |
459 | vfs = vfsmod.vfs(sharedpath, realpath=True) |
|
459 | vfs = vfsmod.vfs(sharedpath, realpath=True) | |
460 | cachepath = vfs.join('cache') |
|
460 | cachepath = vfs.join('cache') | |
461 | s = vfs.base |
|
461 | s = vfs.base | |
462 | if not vfs.exists(): |
|
462 | if not vfs.exists(): | |
463 | raise error.RepoError( |
|
463 | raise error.RepoError( | |
464 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
464 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
465 | self.sharedpath = s |
|
465 | self.sharedpath = s | |
466 | except IOError as inst: |
|
466 | except IOError as inst: | |
467 | if inst.errno != errno.ENOENT: |
|
467 | if inst.errno != errno.ENOENT: | |
468 | raise |
|
468 | raise | |
469 |
|
469 | |||
470 | if 'exp-sparse' in self.requirements and not sparse.enabled: |
|
470 | if 'exp-sparse' in self.requirements and not sparse.enabled: | |
471 | raise error.RepoError(_('repository is using sparse feature but ' |
|
471 | raise error.RepoError(_('repository is using sparse feature but ' | |
472 | 'sparse is not enabled; enable the ' |
|
472 | 'sparse is not enabled; enable the ' | |
473 | '"sparse" extensions to access')) |
|
473 | '"sparse" extensions to access')) | |
474 |
|
474 | |||
475 | self.store = store.store( |
|
475 | self.store = store.store( | |
476 | self.requirements, self.sharedpath, |
|
476 | self.requirements, self.sharedpath, | |
477 | lambda base: vfsmod.vfs(base, cacheaudited=True)) |
|
477 | lambda base: vfsmod.vfs(base, cacheaudited=True)) | |
478 | self.spath = self.store.path |
|
478 | self.spath = self.store.path | |
479 | self.svfs = self.store.vfs |
|
479 | self.svfs = self.store.vfs | |
480 | self.sjoin = self.store.join |
|
480 | self.sjoin = self.store.join | |
481 | self.vfs.createmode = self.store.createmode |
|
481 | self.vfs.createmode = self.store.createmode | |
482 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
482 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
483 | self.cachevfs.createmode = self.store.createmode |
|
483 | self.cachevfs.createmode = self.store.createmode | |
484 | if (self.ui.configbool('devel', 'all-warnings') or |
|
484 | if (self.ui.configbool('devel', 'all-warnings') or | |
485 | self.ui.configbool('devel', 'check-locks')): |
|
485 | self.ui.configbool('devel', 'check-locks')): | |
486 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs |
|
486 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs | |
487 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
487 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
488 | else: # standard vfs |
|
488 | else: # standard vfs | |
489 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
489 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
490 | self._applyopenerreqs() |
|
490 | self._applyopenerreqs() | |
491 | if create: |
|
491 | if create: | |
492 | self._writerequirements() |
|
492 | self._writerequirements() | |
493 |
|
493 | |||
494 | self._dirstatevalidatewarned = False |
|
494 | self._dirstatevalidatewarned = False | |
495 |
|
495 | |||
496 | self._branchcaches = {} |
|
496 | self._branchcaches = {} | |
497 | self._revbranchcache = None |
|
497 | self._revbranchcache = None | |
498 | self.filterpats = {} |
|
498 | self._filterpats = {} | |
499 | self._datafilters = {} |
|
499 | self._datafilters = {} | |
500 | self._transref = self._lockref = self._wlockref = None |
|
500 | self._transref = self._lockref = self._wlockref = None | |
501 |
|
501 | |||
502 | # A cache for various files under .hg/ that tracks file changes, |
|
502 | # A cache for various files under .hg/ that tracks file changes, | |
503 | # (used by the filecache decorator) |
|
503 | # (used by the filecache decorator) | |
504 | # |
|
504 | # | |
505 | # Maps a property name to its util.filecacheentry |
|
505 | # Maps a property name to its util.filecacheentry | |
506 | self._filecache = {} |
|
506 | self._filecache = {} | |
507 |
|
507 | |||
508 | # hold sets of revision to be filtered |
|
508 | # hold sets of revision to be filtered | |
509 | # should be cleared when something might have changed the filter value: |
|
509 | # should be cleared when something might have changed the filter value: | |
510 | # - new changesets, |
|
510 | # - new changesets, | |
511 | # - phase change, |
|
511 | # - phase change, | |
512 | # - new obsolescence marker, |
|
512 | # - new obsolescence marker, | |
513 | # - working directory parent change, |
|
513 | # - working directory parent change, | |
514 | # - bookmark changes |
|
514 | # - bookmark changes | |
515 | self.filteredrevcache = {} |
|
515 | self.filteredrevcache = {} | |
516 |
|
516 | |||
517 | # post-dirstate-status hooks |
|
517 | # post-dirstate-status hooks | |
518 | self._postdsstatus = [] |
|
518 | self._postdsstatus = [] | |
519 |
|
519 | |||
520 | # generic mapping between names and nodes |
|
520 | # generic mapping between names and nodes | |
521 | self.names = namespaces.namespaces() |
|
521 | self.names = namespaces.namespaces() | |
522 |
|
522 | |||
523 | # Key to signature value. |
|
523 | # Key to signature value. | |
524 | self._sparsesignaturecache = {} |
|
524 | self._sparsesignaturecache = {} | |
525 | # Signature to cached matcher instance. |
|
525 | # Signature to cached matcher instance. | |
526 | self._sparsematchercache = {} |
|
526 | self._sparsematchercache = {} | |
527 |
|
527 | |||
528 | def _getvfsward(self, origfunc): |
|
528 | def _getvfsward(self, origfunc): | |
529 | """build a ward for self.vfs""" |
|
529 | """build a ward for self.vfs""" | |
530 | rref = weakref.ref(self) |
|
530 | rref = weakref.ref(self) | |
531 | def checkvfs(path, mode=None): |
|
531 | def checkvfs(path, mode=None): | |
532 | ret = origfunc(path, mode=mode) |
|
532 | ret = origfunc(path, mode=mode) | |
533 | repo = rref() |
|
533 | repo = rref() | |
534 | if (repo is None |
|
534 | if (repo is None | |
535 | or not util.safehasattr(repo, '_wlockref') |
|
535 | or not util.safehasattr(repo, '_wlockref') | |
536 | or not util.safehasattr(repo, '_lockref')): |
|
536 | or not util.safehasattr(repo, '_lockref')): | |
537 | return |
|
537 | return | |
538 | if mode in (None, 'r', 'rb'): |
|
538 | if mode in (None, 'r', 'rb'): | |
539 | return |
|
539 | return | |
540 | if path.startswith(repo.path): |
|
540 | if path.startswith(repo.path): | |
541 | # truncate name relative to the repository (.hg) |
|
541 | # truncate name relative to the repository (.hg) | |
542 | path = path[len(repo.path) + 1:] |
|
542 | path = path[len(repo.path) + 1:] | |
543 | if path.startswith('cache/'): |
|
543 | if path.startswith('cache/'): | |
544 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' |
|
544 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' | |
545 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") |
|
545 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") | |
546 | if path.startswith('journal.'): |
|
546 | if path.startswith('journal.'): | |
547 | # journal is covered by 'lock' |
|
547 | # journal is covered by 'lock' | |
548 | if repo._currentlock(repo._lockref) is None: |
|
548 | if repo._currentlock(repo._lockref) is None: | |
549 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
549 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
550 | stacklevel=2, config='check-locks') |
|
550 | stacklevel=2, config='check-locks') | |
551 | elif repo._currentlock(repo._wlockref) is None: |
|
551 | elif repo._currentlock(repo._wlockref) is None: | |
552 | # rest of vfs files are covered by 'wlock' |
|
552 | # rest of vfs files are covered by 'wlock' | |
553 | # |
|
553 | # | |
554 | # exclude special files |
|
554 | # exclude special files | |
555 | for prefix in self._wlockfreeprefix: |
|
555 | for prefix in self._wlockfreeprefix: | |
556 | if path.startswith(prefix): |
|
556 | if path.startswith(prefix): | |
557 | return |
|
557 | return | |
558 | repo.ui.develwarn('write with no wlock: "%s"' % path, |
|
558 | repo.ui.develwarn('write with no wlock: "%s"' % path, | |
559 | stacklevel=2, config='check-locks') |
|
559 | stacklevel=2, config='check-locks') | |
560 | return ret |
|
560 | return ret | |
561 | return checkvfs |
|
561 | return checkvfs | |
562 |
|
562 | |||
563 | def _getsvfsward(self, origfunc): |
|
563 | def _getsvfsward(self, origfunc): | |
564 | """build a ward for self.svfs""" |
|
564 | """build a ward for self.svfs""" | |
565 | rref = weakref.ref(self) |
|
565 | rref = weakref.ref(self) | |
566 | def checksvfs(path, mode=None): |
|
566 | def checksvfs(path, mode=None): | |
567 | ret = origfunc(path, mode=mode) |
|
567 | ret = origfunc(path, mode=mode) | |
568 | repo = rref() |
|
568 | repo = rref() | |
569 | if repo is None or not util.safehasattr(repo, '_lockref'): |
|
569 | if repo is None or not util.safehasattr(repo, '_lockref'): | |
570 | return |
|
570 | return | |
571 | if mode in (None, 'r', 'rb'): |
|
571 | if mode in (None, 'r', 'rb'): | |
572 | return |
|
572 | return | |
573 | if path.startswith(repo.sharedpath): |
|
573 | if path.startswith(repo.sharedpath): | |
574 | # truncate name relative to the repository (.hg) |
|
574 | # truncate name relative to the repository (.hg) | |
575 | path = path[len(repo.sharedpath) + 1:] |
|
575 | path = path[len(repo.sharedpath) + 1:] | |
576 | if repo._currentlock(repo._lockref) is None: |
|
576 | if repo._currentlock(repo._lockref) is None: | |
577 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
577 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
578 | stacklevel=3) |
|
578 | stacklevel=3) | |
579 | return ret |
|
579 | return ret | |
580 | return checksvfs |
|
580 | return checksvfs | |
581 |
|
581 | |||
582 | def close(self): |
|
582 | def close(self): | |
583 | self._writecaches() |
|
583 | self._writecaches() | |
584 |
|
584 | |||
585 | def _loadextensions(self): |
|
585 | def _loadextensions(self): | |
586 | extensions.loadall(self.ui) |
|
586 | extensions.loadall(self.ui) | |
587 |
|
587 | |||
588 | def _writecaches(self): |
|
588 | def _writecaches(self): | |
589 | if self._revbranchcache: |
|
589 | if self._revbranchcache: | |
590 | self._revbranchcache.write() |
|
590 | self._revbranchcache.write() | |
591 |
|
591 | |||
592 | def _restrictcapabilities(self, caps): |
|
592 | def _restrictcapabilities(self, caps): | |
593 | if self.ui.configbool('experimental', 'bundle2-advertise'): |
|
593 | if self.ui.configbool('experimental', 'bundle2-advertise'): | |
594 | caps = set(caps) |
|
594 | caps = set(caps) | |
595 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, |
|
595 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, | |
596 | role='client')) |
|
596 | role='client')) | |
597 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
597 | caps.add('bundle2=' + urlreq.quote(capsblob)) | |
598 | return caps |
|
598 | return caps | |
599 |
|
599 | |||
600 | def _applyopenerreqs(self): |
|
600 | def _applyopenerreqs(self): | |
601 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
601 | self.svfs.options = dict((r, 1) for r in self.requirements | |
602 | if r in self.openerreqs) |
|
602 | if r in self.openerreqs) | |
603 | # experimental config: format.chunkcachesize |
|
603 | # experimental config: format.chunkcachesize | |
604 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
604 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') | |
605 | if chunkcachesize is not None: |
|
605 | if chunkcachesize is not None: | |
606 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
606 | self.svfs.options['chunkcachesize'] = chunkcachesize | |
607 | # experimental config: format.maxchainlen |
|
607 | # experimental config: format.maxchainlen | |
608 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
608 | maxchainlen = self.ui.configint('format', 'maxchainlen') | |
609 | if maxchainlen is not None: |
|
609 | if maxchainlen is not None: | |
610 | self.svfs.options['maxchainlen'] = maxchainlen |
|
610 | self.svfs.options['maxchainlen'] = maxchainlen | |
611 | # experimental config: format.manifestcachesize |
|
611 | # experimental config: format.manifestcachesize | |
612 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
612 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') | |
613 | if manifestcachesize is not None: |
|
613 | if manifestcachesize is not None: | |
614 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
614 | self.svfs.options['manifestcachesize'] = manifestcachesize | |
615 | # experimental config: format.aggressivemergedeltas |
|
615 | # experimental config: format.aggressivemergedeltas | |
616 | aggressivemergedeltas = self.ui.configbool('format', |
|
616 | aggressivemergedeltas = self.ui.configbool('format', | |
617 | 'aggressivemergedeltas') |
|
617 | 'aggressivemergedeltas') | |
618 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
618 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas | |
619 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) |
|
619 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) | |
620 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') |
|
620 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') | |
621 | if 0 <= chainspan: |
|
621 | if 0 <= chainspan: | |
622 | self.svfs.options['maxdeltachainspan'] = chainspan |
|
622 | self.svfs.options['maxdeltachainspan'] = chainspan | |
623 | mmapindexthreshold = self.ui.configbytes('experimental', |
|
623 | mmapindexthreshold = self.ui.configbytes('experimental', | |
624 | 'mmapindexthreshold') |
|
624 | 'mmapindexthreshold') | |
625 | if mmapindexthreshold is not None: |
|
625 | if mmapindexthreshold is not None: | |
626 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold |
|
626 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold | |
627 | withsparseread = self.ui.configbool('experimental', 'sparse-read') |
|
627 | withsparseread = self.ui.configbool('experimental', 'sparse-read') | |
628 | srdensitythres = float(self.ui.config('experimental', |
|
628 | srdensitythres = float(self.ui.config('experimental', | |
629 | 'sparse-read.density-threshold')) |
|
629 | 'sparse-read.density-threshold')) | |
630 | srmingapsize = self.ui.configbytes('experimental', |
|
630 | srmingapsize = self.ui.configbytes('experimental', | |
631 | 'sparse-read.min-gap-size') |
|
631 | 'sparse-read.min-gap-size') | |
632 | self.svfs.options['with-sparse-read'] = withsparseread |
|
632 | self.svfs.options['with-sparse-read'] = withsparseread | |
633 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres |
|
633 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres | |
634 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize |
|
634 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize | |
635 |
|
635 | |||
636 | for r in self.requirements: |
|
636 | for r in self.requirements: | |
637 | if r.startswith('exp-compression-'): |
|
637 | if r.startswith('exp-compression-'): | |
638 | self.svfs.options['compengine'] = r[len('exp-compression-'):] |
|
638 | self.svfs.options['compengine'] = r[len('exp-compression-'):] | |
639 |
|
639 | |||
640 | # TODO move "revlogv2" to openerreqs once finalized. |
|
640 | # TODO move "revlogv2" to openerreqs once finalized. | |
641 | if REVLOGV2_REQUIREMENT in self.requirements: |
|
641 | if REVLOGV2_REQUIREMENT in self.requirements: | |
642 | self.svfs.options['revlogv2'] = True |
|
642 | self.svfs.options['revlogv2'] = True | |
643 |
|
643 | |||
644 | def _writerequirements(self): |
|
644 | def _writerequirements(self): | |
645 | scmutil.writerequires(self.vfs, self.requirements) |
|
645 | scmutil.writerequires(self.vfs, self.requirements) | |
646 |
|
646 | |||
647 | def _checknested(self, path): |
|
647 | def _checknested(self, path): | |
648 | """Determine if path is a legal nested repository.""" |
|
648 | """Determine if path is a legal nested repository.""" | |
649 | if not path.startswith(self.root): |
|
649 | if not path.startswith(self.root): | |
650 | return False |
|
650 | return False | |
651 | subpath = path[len(self.root) + 1:] |
|
651 | subpath = path[len(self.root) + 1:] | |
652 | normsubpath = util.pconvert(subpath) |
|
652 | normsubpath = util.pconvert(subpath) | |
653 |
|
653 | |||
654 | # XXX: Checking against the current working copy is wrong in |
|
654 | # XXX: Checking against the current working copy is wrong in | |
655 | # the sense that it can reject things like |
|
655 | # the sense that it can reject things like | |
656 | # |
|
656 | # | |
657 | # $ hg cat -r 10 sub/x.txt |
|
657 | # $ hg cat -r 10 sub/x.txt | |
658 | # |
|
658 | # | |
659 | # if sub/ is no longer a subrepository in the working copy |
|
659 | # if sub/ is no longer a subrepository in the working copy | |
660 | # parent revision. |
|
660 | # parent revision. | |
661 | # |
|
661 | # | |
662 | # However, it can of course also allow things that would have |
|
662 | # However, it can of course also allow things that would have | |
663 | # been rejected before, such as the above cat command if sub/ |
|
663 | # been rejected before, such as the above cat command if sub/ | |
664 | # is a subrepository now, but was a normal directory before. |
|
664 | # is a subrepository now, but was a normal directory before. | |
665 | # The old path auditor would have rejected by mistake since it |
|
665 | # The old path auditor would have rejected by mistake since it | |
666 | # panics when it sees sub/.hg/. |
|
666 | # panics when it sees sub/.hg/. | |
667 | # |
|
667 | # | |
668 | # All in all, checking against the working copy seems sensible |
|
668 | # All in all, checking against the working copy seems sensible | |
669 | # since we want to prevent access to nested repositories on |
|
669 | # since we want to prevent access to nested repositories on | |
670 | # the filesystem *now*. |
|
670 | # the filesystem *now*. | |
671 | ctx = self[None] |
|
671 | ctx = self[None] | |
672 | parts = util.splitpath(subpath) |
|
672 | parts = util.splitpath(subpath) | |
673 | while parts: |
|
673 | while parts: | |
674 | prefix = '/'.join(parts) |
|
674 | prefix = '/'.join(parts) | |
675 | if prefix in ctx.substate: |
|
675 | if prefix in ctx.substate: | |
676 | if prefix == normsubpath: |
|
676 | if prefix == normsubpath: | |
677 | return True |
|
677 | return True | |
678 | else: |
|
678 | else: | |
679 | sub = ctx.sub(prefix) |
|
679 | sub = ctx.sub(prefix) | |
680 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
680 | return sub.checknested(subpath[len(prefix) + 1:]) | |
681 | else: |
|
681 | else: | |
682 | parts.pop() |
|
682 | parts.pop() | |
683 | return False |
|
683 | return False | |
684 |
|
684 | |||
685 | def peer(self): |
|
685 | def peer(self): | |
686 | return localpeer(self) # not cached to avoid reference cycle |
|
686 | return localpeer(self) # not cached to avoid reference cycle | |
687 |
|
687 | |||
688 | def unfiltered(self): |
|
688 | def unfiltered(self): | |
689 | """Return unfiltered version of the repository |
|
689 | """Return unfiltered version of the repository | |
690 |
|
690 | |||
691 | Intended to be overwritten by filtered repo.""" |
|
691 | Intended to be overwritten by filtered repo.""" | |
692 | return self |
|
692 | return self | |
693 |
|
693 | |||
694 | def filtered(self, name, visibilityexceptions=None): |
|
694 | def filtered(self, name, visibilityexceptions=None): | |
695 | """Return a filtered version of a repository""" |
|
695 | """Return a filtered version of a repository""" | |
696 | cls = repoview.newtype(self.unfiltered().__class__) |
|
696 | cls = repoview.newtype(self.unfiltered().__class__) | |
697 | return cls(self, name, visibilityexceptions) |
|
697 | return cls(self, name, visibilityexceptions) | |
698 |
|
698 | |||
699 | @repofilecache('bookmarks', 'bookmarks.current') |
|
699 | @repofilecache('bookmarks', 'bookmarks.current') | |
700 | def _bookmarks(self): |
|
700 | def _bookmarks(self): | |
701 | return bookmarks.bmstore(self) |
|
701 | return bookmarks.bmstore(self) | |
702 |
|
702 | |||
703 | @property |
|
703 | @property | |
704 | def _activebookmark(self): |
|
704 | def _activebookmark(self): | |
705 | return self._bookmarks.active |
|
705 | return self._bookmarks.active | |
706 |
|
706 | |||
707 | # _phasesets depend on changelog. what we need is to call |
|
707 | # _phasesets depend on changelog. what we need is to call | |
708 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
708 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
709 | # can't be easily expressed in filecache mechanism. |
|
709 | # can't be easily expressed in filecache mechanism. | |
710 | @storecache('phaseroots', '00changelog.i') |
|
710 | @storecache('phaseroots', '00changelog.i') | |
711 | def _phasecache(self): |
|
711 | def _phasecache(self): | |
712 | return phases.phasecache(self, self._phasedefaults) |
|
712 | return phases.phasecache(self, self._phasedefaults) | |
713 |
|
713 | |||
714 | @storecache('obsstore') |
|
714 | @storecache('obsstore') | |
715 | def obsstore(self): |
|
715 | def obsstore(self): | |
716 | return obsolete.makestore(self.ui, self) |
|
716 | return obsolete.makestore(self.ui, self) | |
717 |
|
717 | |||
718 | @storecache('00changelog.i') |
|
718 | @storecache('00changelog.i') | |
719 | def changelog(self): |
|
719 | def changelog(self): | |
720 | return changelog.changelog(self.svfs, |
|
720 | return changelog.changelog(self.svfs, | |
721 | trypending=txnutil.mayhavepending(self.root)) |
|
721 | trypending=txnutil.mayhavepending(self.root)) | |
722 |
|
722 | |||
723 | def _constructmanifest(self): |
|
723 | def _constructmanifest(self): | |
724 | # This is a temporary function while we migrate from manifest to |
|
724 | # This is a temporary function while we migrate from manifest to | |
725 | # manifestlog. It allows bundlerepo and unionrepo to intercept the |
|
725 | # manifestlog. It allows bundlerepo and unionrepo to intercept the | |
726 | # manifest creation. |
|
726 | # manifest creation. | |
727 | return manifest.manifestrevlog(self.svfs) |
|
727 | return manifest.manifestrevlog(self.svfs) | |
728 |
|
728 | |||
729 | @storecache('00manifest.i') |
|
729 | @storecache('00manifest.i') | |
730 | def manifestlog(self): |
|
730 | def manifestlog(self): | |
731 | return manifest.manifestlog(self.svfs, self) |
|
731 | return manifest.manifestlog(self.svfs, self) | |
732 |
|
732 | |||
733 | @repofilecache('dirstate') |
|
733 | @repofilecache('dirstate') | |
734 | def dirstate(self): |
|
734 | def dirstate(self): | |
735 | sparsematchfn = lambda: sparse.matcher(self) |
|
735 | sparsematchfn = lambda: sparse.matcher(self) | |
736 |
|
736 | |||
737 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
737 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
738 | self._dirstatevalidate, sparsematchfn) |
|
738 | self._dirstatevalidate, sparsematchfn) | |
739 |
|
739 | |||
740 | def _dirstatevalidate(self, node): |
|
740 | def _dirstatevalidate(self, node): | |
741 | try: |
|
741 | try: | |
742 | self.changelog.rev(node) |
|
742 | self.changelog.rev(node) | |
743 | return node |
|
743 | return node | |
744 | except error.LookupError: |
|
744 | except error.LookupError: | |
745 | if not self._dirstatevalidatewarned: |
|
745 | if not self._dirstatevalidatewarned: | |
746 | self._dirstatevalidatewarned = True |
|
746 | self._dirstatevalidatewarned = True | |
747 | self.ui.warn(_("warning: ignoring unknown" |
|
747 | self.ui.warn(_("warning: ignoring unknown" | |
748 | " working parent %s!\n") % short(node)) |
|
748 | " working parent %s!\n") % short(node)) | |
749 | return nullid |
|
749 | return nullid | |
750 |
|
750 | |||
751 | @repofilecache(narrowspec.FILENAME) |
|
751 | @repofilecache(narrowspec.FILENAME) | |
752 | def narrowpats(self): |
|
752 | def narrowpats(self): | |
753 | """matcher patterns for this repository's narrowspec |
|
753 | """matcher patterns for this repository's narrowspec | |
754 |
|
754 | |||
755 | A tuple of (includes, excludes). |
|
755 | A tuple of (includes, excludes). | |
756 | """ |
|
756 | """ | |
757 | source = self |
|
757 | source = self | |
758 | if self.shared(): |
|
758 | if self.shared(): | |
759 | from . import hg |
|
759 | from . import hg | |
760 | source = hg.sharedreposource(self) |
|
760 | source = hg.sharedreposource(self) | |
761 | return narrowspec.load(source) |
|
761 | return narrowspec.load(source) | |
762 |
|
762 | |||
763 | @repofilecache(narrowspec.FILENAME) |
|
763 | @repofilecache(narrowspec.FILENAME) | |
764 | def _narrowmatch(self): |
|
764 | def _narrowmatch(self): | |
765 | if changegroup.NARROW_REQUIREMENT not in self.requirements: |
|
765 | if changegroup.NARROW_REQUIREMENT not in self.requirements: | |
766 | return matchmod.always(self.root, '') |
|
766 | return matchmod.always(self.root, '') | |
767 | include, exclude = self.narrowpats |
|
767 | include, exclude = self.narrowpats | |
768 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
768 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
769 |
|
769 | |||
770 | # TODO(martinvonz): make this property-like instead? |
|
770 | # TODO(martinvonz): make this property-like instead? | |
771 | def narrowmatch(self): |
|
771 | def narrowmatch(self): | |
772 | return self._narrowmatch |
|
772 | return self._narrowmatch | |
773 |
|
773 | |||
774 | def setnarrowpats(self, newincludes, newexcludes): |
|
774 | def setnarrowpats(self, newincludes, newexcludes): | |
775 | target = self |
|
775 | target = self | |
776 | if self.shared(): |
|
776 | if self.shared(): | |
777 | from . import hg |
|
777 | from . import hg | |
778 | target = hg.sharedreposource(self) |
|
778 | target = hg.sharedreposource(self) | |
779 | narrowspec.save(target, newincludes, newexcludes) |
|
779 | narrowspec.save(target, newincludes, newexcludes) | |
780 | self.invalidate(clearfilecache=True) |
|
780 | self.invalidate(clearfilecache=True) | |
781 |
|
781 | |||
782 | def __getitem__(self, changeid): |
|
782 | def __getitem__(self, changeid): | |
783 | if changeid is None: |
|
783 | if changeid is None: | |
784 | return context.workingctx(self) |
|
784 | return context.workingctx(self) | |
785 | if isinstance(changeid, slice): |
|
785 | if isinstance(changeid, slice): | |
786 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
786 | # wdirrev isn't contiguous so the slice shouldn't include it | |
787 | return [context.changectx(self, i) |
|
787 | return [context.changectx(self, i) | |
788 | for i in xrange(*changeid.indices(len(self))) |
|
788 | for i in xrange(*changeid.indices(len(self))) | |
789 | if i not in self.changelog.filteredrevs] |
|
789 | if i not in self.changelog.filteredrevs] | |
790 | try: |
|
790 | try: | |
791 | return context.changectx(self, changeid) |
|
791 | return context.changectx(self, changeid) | |
792 | except error.WdirUnsupported: |
|
792 | except error.WdirUnsupported: | |
793 | return context.workingctx(self) |
|
793 | return context.workingctx(self) | |
794 |
|
794 | |||
795 | def __contains__(self, changeid): |
|
795 | def __contains__(self, changeid): | |
796 | """True if the given changeid exists |
|
796 | """True if the given changeid exists | |
797 |
|
797 | |||
798 | error.LookupError is raised if an ambiguous node specified. |
|
798 | error.LookupError is raised if an ambiguous node specified. | |
799 | """ |
|
799 | """ | |
800 | try: |
|
800 | try: | |
801 | self[changeid] |
|
801 | self[changeid] | |
802 | return True |
|
802 | return True | |
803 | except error.RepoLookupError: |
|
803 | except error.RepoLookupError: | |
804 | return False |
|
804 | return False | |
805 |
|
805 | |||
806 | def __nonzero__(self): |
|
806 | def __nonzero__(self): | |
807 | return True |
|
807 | return True | |
808 |
|
808 | |||
809 | __bool__ = __nonzero__ |
|
809 | __bool__ = __nonzero__ | |
810 |
|
810 | |||
811 | def __len__(self): |
|
811 | def __len__(self): | |
812 | # no need to pay the cost of repoview.changelog |
|
812 | # no need to pay the cost of repoview.changelog | |
813 | unfi = self.unfiltered() |
|
813 | unfi = self.unfiltered() | |
814 | return len(unfi.changelog) |
|
814 | return len(unfi.changelog) | |
815 |
|
815 | |||
816 | def __iter__(self): |
|
816 | def __iter__(self): | |
817 | return iter(self.changelog) |
|
817 | return iter(self.changelog) | |
818 |
|
818 | |||
819 | def revs(self, expr, *args): |
|
819 | def revs(self, expr, *args): | |
820 | '''Find revisions matching a revset. |
|
820 | '''Find revisions matching a revset. | |
821 |
|
821 | |||
822 | The revset is specified as a string ``expr`` that may contain |
|
822 | The revset is specified as a string ``expr`` that may contain | |
823 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
823 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
824 |
|
824 | |||
825 | Revset aliases from the configuration are not expanded. To expand |
|
825 | Revset aliases from the configuration are not expanded. To expand | |
826 | user aliases, consider calling ``scmutil.revrange()`` or |
|
826 | user aliases, consider calling ``scmutil.revrange()`` or | |
827 | ``repo.anyrevs([expr], user=True)``. |
|
827 | ``repo.anyrevs([expr], user=True)``. | |
828 |
|
828 | |||
829 | Returns a revset.abstractsmartset, which is a list-like interface |
|
829 | Returns a revset.abstractsmartset, which is a list-like interface | |
830 | that contains integer revisions. |
|
830 | that contains integer revisions. | |
831 | ''' |
|
831 | ''' | |
832 | expr = revsetlang.formatspec(expr, *args) |
|
832 | expr = revsetlang.formatspec(expr, *args) | |
833 | m = revset.match(None, expr) |
|
833 | m = revset.match(None, expr) | |
834 | return m(self) |
|
834 | return m(self) | |
835 |
|
835 | |||
836 | def set(self, expr, *args): |
|
836 | def set(self, expr, *args): | |
837 | '''Find revisions matching a revset and emit changectx instances. |
|
837 | '''Find revisions matching a revset and emit changectx instances. | |
838 |
|
838 | |||
839 | This is a convenience wrapper around ``revs()`` that iterates the |
|
839 | This is a convenience wrapper around ``revs()`` that iterates the | |
840 | result and is a generator of changectx instances. |
|
840 | result and is a generator of changectx instances. | |
841 |
|
841 | |||
842 | Revset aliases from the configuration are not expanded. To expand |
|
842 | Revset aliases from the configuration are not expanded. To expand | |
843 | user aliases, consider calling ``scmutil.revrange()``. |
|
843 | user aliases, consider calling ``scmutil.revrange()``. | |
844 | ''' |
|
844 | ''' | |
845 | for r in self.revs(expr, *args): |
|
845 | for r in self.revs(expr, *args): | |
846 | yield self[r] |
|
846 | yield self[r] | |
847 |
|
847 | |||
848 | def anyrevs(self, specs, user=False, localalias=None): |
|
848 | def anyrevs(self, specs, user=False, localalias=None): | |
849 | '''Find revisions matching one of the given revsets. |
|
849 | '''Find revisions matching one of the given revsets. | |
850 |
|
850 | |||
851 | Revset aliases from the configuration are not expanded by default. To |
|
851 | Revset aliases from the configuration are not expanded by default. To | |
852 | expand user aliases, specify ``user=True``. To provide some local |
|
852 | expand user aliases, specify ``user=True``. To provide some local | |
853 | definitions overriding user aliases, set ``localalias`` to |
|
853 | definitions overriding user aliases, set ``localalias`` to | |
854 | ``{name: definitionstring}``. |
|
854 | ``{name: definitionstring}``. | |
855 | ''' |
|
855 | ''' | |
856 | if user: |
|
856 | if user: | |
857 | m = revset.matchany(self.ui, specs, repo=self, |
|
857 | m = revset.matchany(self.ui, specs, repo=self, | |
858 | localalias=localalias) |
|
858 | localalias=localalias) | |
859 | else: |
|
859 | else: | |
860 | m = revset.matchany(None, specs, localalias=localalias) |
|
860 | m = revset.matchany(None, specs, localalias=localalias) | |
861 | return m(self) |
|
861 | return m(self) | |
862 |
|
862 | |||
863 | def url(self): |
|
863 | def url(self): | |
864 | return 'file:' + self.root |
|
864 | return 'file:' + self.root | |
865 |
|
865 | |||
866 | def hook(self, name, throw=False, **args): |
|
866 | def hook(self, name, throw=False, **args): | |
867 | """Call a hook, passing this repo instance. |
|
867 | """Call a hook, passing this repo instance. | |
868 |
|
868 | |||
869 | This a convenience method to aid invoking hooks. Extensions likely |
|
869 | This a convenience method to aid invoking hooks. Extensions likely | |
870 | won't call this unless they have registered a custom hook or are |
|
870 | won't call this unless they have registered a custom hook or are | |
871 | replacing code that is expected to call a hook. |
|
871 | replacing code that is expected to call a hook. | |
872 | """ |
|
872 | """ | |
873 | return hook.hook(self.ui, self, name, throw, **args) |
|
873 | return hook.hook(self.ui, self, name, throw, **args) | |
874 |
|
874 | |||
875 | @filteredpropertycache |
|
875 | @filteredpropertycache | |
876 | def _tagscache(self): |
|
876 | def _tagscache(self): | |
877 | '''Returns a tagscache object that contains various tags related |
|
877 | '''Returns a tagscache object that contains various tags related | |
878 | caches.''' |
|
878 | caches.''' | |
879 |
|
879 | |||
880 | # This simplifies its cache management by having one decorated |
|
880 | # This simplifies its cache management by having one decorated | |
881 | # function (this one) and the rest simply fetch things from it. |
|
881 | # function (this one) and the rest simply fetch things from it. | |
882 | class tagscache(object): |
|
882 | class tagscache(object): | |
883 | def __init__(self): |
|
883 | def __init__(self): | |
884 | # These two define the set of tags for this repository. tags |
|
884 | # These two define the set of tags for this repository. tags | |
885 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
885 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
886 | # 'local'. (Global tags are defined by .hgtags across all |
|
886 | # 'local'. (Global tags are defined by .hgtags across all | |
887 | # heads, and local tags are defined in .hg/localtags.) |
|
887 | # heads, and local tags are defined in .hg/localtags.) | |
888 | # They constitute the in-memory cache of tags. |
|
888 | # They constitute the in-memory cache of tags. | |
889 | self.tags = self.tagtypes = None |
|
889 | self.tags = self.tagtypes = None | |
890 |
|
890 | |||
891 | self.nodetagscache = self.tagslist = None |
|
891 | self.nodetagscache = self.tagslist = None | |
892 |
|
892 | |||
893 | cache = tagscache() |
|
893 | cache = tagscache() | |
894 | cache.tags, cache.tagtypes = self._findtags() |
|
894 | cache.tags, cache.tagtypes = self._findtags() | |
895 |
|
895 | |||
896 | return cache |
|
896 | return cache | |
897 |
|
897 | |||
898 | def tags(self): |
|
898 | def tags(self): | |
899 | '''return a mapping of tag to node''' |
|
899 | '''return a mapping of tag to node''' | |
900 | t = {} |
|
900 | t = {} | |
901 | if self.changelog.filteredrevs: |
|
901 | if self.changelog.filteredrevs: | |
902 | tags, tt = self._findtags() |
|
902 | tags, tt = self._findtags() | |
903 | else: |
|
903 | else: | |
904 | tags = self._tagscache.tags |
|
904 | tags = self._tagscache.tags | |
905 | for k, v in tags.iteritems(): |
|
905 | for k, v in tags.iteritems(): | |
906 | try: |
|
906 | try: | |
907 | # ignore tags to unknown nodes |
|
907 | # ignore tags to unknown nodes | |
908 | self.changelog.rev(v) |
|
908 | self.changelog.rev(v) | |
909 | t[k] = v |
|
909 | t[k] = v | |
910 | except (error.LookupError, ValueError): |
|
910 | except (error.LookupError, ValueError): | |
911 | pass |
|
911 | pass | |
912 | return t |
|
912 | return t | |
913 |
|
913 | |||
914 | def _findtags(self): |
|
914 | def _findtags(self): | |
915 | '''Do the hard work of finding tags. Return a pair of dicts |
|
915 | '''Do the hard work of finding tags. Return a pair of dicts | |
916 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
916 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
917 | maps tag name to a string like \'global\' or \'local\'. |
|
917 | maps tag name to a string like \'global\' or \'local\'. | |
918 | Subclasses or extensions are free to add their own tags, but |
|
918 | Subclasses or extensions are free to add their own tags, but | |
919 | should be aware that the returned dicts will be retained for the |
|
919 | should be aware that the returned dicts will be retained for the | |
920 | duration of the localrepo object.''' |
|
920 | duration of the localrepo object.''' | |
921 |
|
921 | |||
922 | # XXX what tagtype should subclasses/extensions use? Currently |
|
922 | # XXX what tagtype should subclasses/extensions use? Currently | |
923 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
923 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
924 | # Should each extension invent its own tag type? Should there |
|
924 | # Should each extension invent its own tag type? Should there | |
925 | # be one tagtype for all such "virtual" tags? Or is the status |
|
925 | # be one tagtype for all such "virtual" tags? Or is the status | |
926 | # quo fine? |
|
926 | # quo fine? | |
927 |
|
927 | |||
928 |
|
928 | |||
929 | # map tag name to (node, hist) |
|
929 | # map tag name to (node, hist) | |
930 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
930 | alltags = tagsmod.findglobaltags(self.ui, self) | |
931 | # map tag name to tag type |
|
931 | # map tag name to tag type | |
932 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
932 | tagtypes = dict((tag, 'global') for tag in alltags) | |
933 |
|
933 | |||
934 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
934 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
935 |
|
935 | |||
936 | # Build the return dicts. Have to re-encode tag names because |
|
936 | # Build the return dicts. Have to re-encode tag names because | |
937 | # the tags module always uses UTF-8 (in order not to lose info |
|
937 | # the tags module always uses UTF-8 (in order not to lose info | |
938 | # writing to the cache), but the rest of Mercurial wants them in |
|
938 | # writing to the cache), but the rest of Mercurial wants them in | |
939 | # local encoding. |
|
939 | # local encoding. | |
940 | tags = {} |
|
940 | tags = {} | |
941 | for (name, (node, hist)) in alltags.iteritems(): |
|
941 | for (name, (node, hist)) in alltags.iteritems(): | |
942 | if node != nullid: |
|
942 | if node != nullid: | |
943 | tags[encoding.tolocal(name)] = node |
|
943 | tags[encoding.tolocal(name)] = node | |
944 | tags['tip'] = self.changelog.tip() |
|
944 | tags['tip'] = self.changelog.tip() | |
945 | tagtypes = dict([(encoding.tolocal(name), value) |
|
945 | tagtypes = dict([(encoding.tolocal(name), value) | |
946 | for (name, value) in tagtypes.iteritems()]) |
|
946 | for (name, value) in tagtypes.iteritems()]) | |
947 | return (tags, tagtypes) |
|
947 | return (tags, tagtypes) | |
948 |
|
948 | |||
949 | def tagtype(self, tagname): |
|
949 | def tagtype(self, tagname): | |
950 | ''' |
|
950 | ''' | |
951 | return the type of the given tag. result can be: |
|
951 | return the type of the given tag. result can be: | |
952 |
|
952 | |||
953 | 'local' : a local tag |
|
953 | 'local' : a local tag | |
954 | 'global' : a global tag |
|
954 | 'global' : a global tag | |
955 | None : tag does not exist |
|
955 | None : tag does not exist | |
956 | ''' |
|
956 | ''' | |
957 |
|
957 | |||
958 | return self._tagscache.tagtypes.get(tagname) |
|
958 | return self._tagscache.tagtypes.get(tagname) | |
959 |
|
959 | |||
960 | def tagslist(self): |
|
960 | def tagslist(self): | |
961 | '''return a list of tags ordered by revision''' |
|
961 | '''return a list of tags ordered by revision''' | |
962 | if not self._tagscache.tagslist: |
|
962 | if not self._tagscache.tagslist: | |
963 | l = [] |
|
963 | l = [] | |
964 | for t, n in self.tags().iteritems(): |
|
964 | for t, n in self.tags().iteritems(): | |
965 | l.append((self.changelog.rev(n), t, n)) |
|
965 | l.append((self.changelog.rev(n), t, n)) | |
966 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
966 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
967 |
|
967 | |||
968 | return self._tagscache.tagslist |
|
968 | return self._tagscache.tagslist | |
969 |
|
969 | |||
970 | def nodetags(self, node): |
|
970 | def nodetags(self, node): | |
971 | '''return the tags associated with a node''' |
|
971 | '''return the tags associated with a node''' | |
972 | if not self._tagscache.nodetagscache: |
|
972 | if not self._tagscache.nodetagscache: | |
973 | nodetagscache = {} |
|
973 | nodetagscache = {} | |
974 | for t, n in self._tagscache.tags.iteritems(): |
|
974 | for t, n in self._tagscache.tags.iteritems(): | |
975 | nodetagscache.setdefault(n, []).append(t) |
|
975 | nodetagscache.setdefault(n, []).append(t) | |
976 | for tags in nodetagscache.itervalues(): |
|
976 | for tags in nodetagscache.itervalues(): | |
977 | tags.sort() |
|
977 | tags.sort() | |
978 | self._tagscache.nodetagscache = nodetagscache |
|
978 | self._tagscache.nodetagscache = nodetagscache | |
979 | return self._tagscache.nodetagscache.get(node, []) |
|
979 | return self._tagscache.nodetagscache.get(node, []) | |
980 |
|
980 | |||
981 | def nodebookmarks(self, node): |
|
981 | def nodebookmarks(self, node): | |
982 | """return the list of bookmarks pointing to the specified node""" |
|
982 | """return the list of bookmarks pointing to the specified node""" | |
983 | marks = [] |
|
983 | marks = [] | |
984 | for bookmark, n in self._bookmarks.iteritems(): |
|
984 | for bookmark, n in self._bookmarks.iteritems(): | |
985 | if n == node: |
|
985 | if n == node: | |
986 | marks.append(bookmark) |
|
986 | marks.append(bookmark) | |
987 | return sorted(marks) |
|
987 | return sorted(marks) | |
988 |
|
988 | |||
989 | def branchmap(self): |
|
989 | def branchmap(self): | |
990 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
990 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
991 | ordered by increasing revision number''' |
|
991 | ordered by increasing revision number''' | |
992 | branchmap.updatecache(self) |
|
992 | branchmap.updatecache(self) | |
993 | return self._branchcaches[self.filtername] |
|
993 | return self._branchcaches[self.filtername] | |
994 |
|
994 | |||
995 | @unfilteredmethod |
|
995 | @unfilteredmethod | |
996 | def revbranchcache(self): |
|
996 | def revbranchcache(self): | |
997 | if not self._revbranchcache: |
|
997 | if not self._revbranchcache: | |
998 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
998 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
999 | return self._revbranchcache |
|
999 | return self._revbranchcache | |
1000 |
|
1000 | |||
1001 | def branchtip(self, branch, ignoremissing=False): |
|
1001 | def branchtip(self, branch, ignoremissing=False): | |
1002 | '''return the tip node for a given branch |
|
1002 | '''return the tip node for a given branch | |
1003 |
|
1003 | |||
1004 | If ignoremissing is True, then this method will not raise an error. |
|
1004 | If ignoremissing is True, then this method will not raise an error. | |
1005 | This is helpful for callers that only expect None for a missing branch |
|
1005 | This is helpful for callers that only expect None for a missing branch | |
1006 | (e.g. namespace). |
|
1006 | (e.g. namespace). | |
1007 |
|
1007 | |||
1008 | ''' |
|
1008 | ''' | |
1009 | try: |
|
1009 | try: | |
1010 | return self.branchmap().branchtip(branch) |
|
1010 | return self.branchmap().branchtip(branch) | |
1011 | except KeyError: |
|
1011 | except KeyError: | |
1012 | if not ignoremissing: |
|
1012 | if not ignoremissing: | |
1013 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
1013 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
1014 | else: |
|
1014 | else: | |
1015 | pass |
|
1015 | pass | |
1016 |
|
1016 | |||
1017 | def lookup(self, key): |
|
1017 | def lookup(self, key): | |
1018 | return self[key].node() |
|
1018 | return self[key].node() | |
1019 |
|
1019 | |||
1020 | def lookupbranch(self, key, remote=None): |
|
1020 | def lookupbranch(self, key, remote=None): | |
1021 | repo = remote or self |
|
1021 | repo = remote or self | |
1022 | if key in repo.branchmap(): |
|
1022 | if key in repo.branchmap(): | |
1023 | return key |
|
1023 | return key | |
1024 |
|
1024 | |||
1025 | repo = (remote and remote.local()) and remote or self |
|
1025 | repo = (remote and remote.local()) and remote or self | |
1026 | return repo[key].branch() |
|
1026 | return repo[key].branch() | |
1027 |
|
1027 | |||
1028 | def known(self, nodes): |
|
1028 | def known(self, nodes): | |
1029 | cl = self.changelog |
|
1029 | cl = self.changelog | |
1030 | nm = cl.nodemap |
|
1030 | nm = cl.nodemap | |
1031 | filtered = cl.filteredrevs |
|
1031 | filtered = cl.filteredrevs | |
1032 | result = [] |
|
1032 | result = [] | |
1033 | for n in nodes: |
|
1033 | for n in nodes: | |
1034 | r = nm.get(n) |
|
1034 | r = nm.get(n) | |
1035 | resp = not (r is None or r in filtered) |
|
1035 | resp = not (r is None or r in filtered) | |
1036 | result.append(resp) |
|
1036 | result.append(resp) | |
1037 | return result |
|
1037 | return result | |
1038 |
|
1038 | |||
1039 | def local(self): |
|
1039 | def local(self): | |
1040 | return self |
|
1040 | return self | |
1041 |
|
1041 | |||
1042 | def publishing(self): |
|
1042 | def publishing(self): | |
1043 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1043 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1044 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1044 | # so that we don't finalize changes shared between users via ssh or nfs | |
1045 | return self.ui.configbool('phases', 'publish', untrusted=True) |
|
1045 | return self.ui.configbool('phases', 'publish', untrusted=True) | |
1046 |
|
1046 | |||
1047 | def cancopy(self): |
|
1047 | def cancopy(self): | |
1048 | # so statichttprepo's override of local() works |
|
1048 | # so statichttprepo's override of local() works | |
1049 | if not self.local(): |
|
1049 | if not self.local(): | |
1050 | return False |
|
1050 | return False | |
1051 | if not self.publishing(): |
|
1051 | if not self.publishing(): | |
1052 | return True |
|
1052 | return True | |
1053 | # if publishing we can't copy if there is filtered content |
|
1053 | # if publishing we can't copy if there is filtered content | |
1054 | return not self.filtered('visible').changelog.filteredrevs |
|
1054 | return not self.filtered('visible').changelog.filteredrevs | |
1055 |
|
1055 | |||
1056 | def shared(self): |
|
1056 | def shared(self): | |
1057 | '''the type of shared repository (None if not shared)''' |
|
1057 | '''the type of shared repository (None if not shared)''' | |
1058 | if self.sharedpath != self.path: |
|
1058 | if self.sharedpath != self.path: | |
1059 | return 'store' |
|
1059 | return 'store' | |
1060 | return None |
|
1060 | return None | |
1061 |
|
1061 | |||
1062 | def wjoin(self, f, *insidef): |
|
1062 | def wjoin(self, f, *insidef): | |
1063 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1063 | return self.vfs.reljoin(self.root, f, *insidef) | |
1064 |
|
1064 | |||
1065 | def file(self, f): |
|
1065 | def file(self, f): | |
1066 | if f[0] == '/': |
|
1066 | if f[0] == '/': | |
1067 | f = f[1:] |
|
1067 | f = f[1:] | |
1068 | return filelog.filelog(self.svfs, f) |
|
1068 | return filelog.filelog(self.svfs, f) | |
1069 |
|
1069 | |||
1070 | def changectx(self, changeid): |
|
1070 | def changectx(self, changeid): | |
1071 | return self[changeid] |
|
1071 | return self[changeid] | |
1072 |
|
1072 | |||
1073 | def setparents(self, p1, p2=nullid): |
|
1073 | def setparents(self, p1, p2=nullid): | |
1074 | with self.dirstate.parentchange(): |
|
1074 | with self.dirstate.parentchange(): | |
1075 | copies = self.dirstate.setparents(p1, p2) |
|
1075 | copies = self.dirstate.setparents(p1, p2) | |
1076 | pctx = self[p1] |
|
1076 | pctx = self[p1] | |
1077 | if copies: |
|
1077 | if copies: | |
1078 | # Adjust copy records, the dirstate cannot do it, it |
|
1078 | # Adjust copy records, the dirstate cannot do it, it | |
1079 | # requires access to parents manifests. Preserve them |
|
1079 | # requires access to parents manifests. Preserve them | |
1080 | # only for entries added to first parent. |
|
1080 | # only for entries added to first parent. | |
1081 | for f in copies: |
|
1081 | for f in copies: | |
1082 | if f not in pctx and copies[f] in pctx: |
|
1082 | if f not in pctx and copies[f] in pctx: | |
1083 | self.dirstate.copy(copies[f], f) |
|
1083 | self.dirstate.copy(copies[f], f) | |
1084 | if p2 == nullid: |
|
1084 | if p2 == nullid: | |
1085 | for f, s in sorted(self.dirstate.copies().items()): |
|
1085 | for f, s in sorted(self.dirstate.copies().items()): | |
1086 | if f not in pctx and s not in pctx: |
|
1086 | if f not in pctx and s not in pctx: | |
1087 | self.dirstate.copy(None, f) |
|
1087 | self.dirstate.copy(None, f) | |
1088 |
|
1088 | |||
1089 | def filectx(self, path, changeid=None, fileid=None): |
|
1089 | def filectx(self, path, changeid=None, fileid=None): | |
1090 | """changeid can be a changeset revision, node, or tag. |
|
1090 | """changeid can be a changeset revision, node, or tag. | |
1091 | fileid can be a file revision or node.""" |
|
1091 | fileid can be a file revision or node.""" | |
1092 | return context.filectx(self, path, changeid, fileid) |
|
1092 | return context.filectx(self, path, changeid, fileid) | |
1093 |
|
1093 | |||
1094 | def getcwd(self): |
|
1094 | def getcwd(self): | |
1095 | return self.dirstate.getcwd() |
|
1095 | return self.dirstate.getcwd() | |
1096 |
|
1096 | |||
1097 | def pathto(self, f, cwd=None): |
|
1097 | def pathto(self, f, cwd=None): | |
1098 | return self.dirstate.pathto(f, cwd) |
|
1098 | return self.dirstate.pathto(f, cwd) | |
1099 |
|
1099 | |||
1100 | def _loadfilter(self, filter): |
|
1100 | def _loadfilter(self, filter): | |
1101 | if filter not in self.filterpats: |
|
1101 | if filter not in self._filterpats: | |
1102 | l = [] |
|
1102 | l = [] | |
1103 | for pat, cmd in self.ui.configitems(filter): |
|
1103 | for pat, cmd in self.ui.configitems(filter): | |
1104 | if cmd == '!': |
|
1104 | if cmd == '!': | |
1105 | continue |
|
1105 | continue | |
1106 | mf = matchmod.match(self.root, '', [pat]) |
|
1106 | mf = matchmod.match(self.root, '', [pat]) | |
1107 | fn = None |
|
1107 | fn = None | |
1108 | params = cmd |
|
1108 | params = cmd | |
1109 | for name, filterfn in self._datafilters.iteritems(): |
|
1109 | for name, filterfn in self._datafilters.iteritems(): | |
1110 | if cmd.startswith(name): |
|
1110 | if cmd.startswith(name): | |
1111 | fn = filterfn |
|
1111 | fn = filterfn | |
1112 | params = cmd[len(name):].lstrip() |
|
1112 | params = cmd[len(name):].lstrip() | |
1113 | break |
|
1113 | break | |
1114 | if not fn: |
|
1114 | if not fn: | |
1115 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1115 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1116 | # Wrap old filters not supporting keyword arguments |
|
1116 | # Wrap old filters not supporting keyword arguments | |
1117 | if not pycompat.getargspec(fn)[2]: |
|
1117 | if not pycompat.getargspec(fn)[2]: | |
1118 | oldfn = fn |
|
1118 | oldfn = fn | |
1119 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
1119 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
1120 | l.append((mf, fn, params)) |
|
1120 | l.append((mf, fn, params)) | |
1121 | self.filterpats[filter] = l |
|
1121 | self._filterpats[filter] = l | |
1122 | return self.filterpats[filter] |
|
1122 | return self._filterpats[filter] | |
1123 |
|
1123 | |||
1124 | def _filter(self, filterpats, filename, data): |
|
1124 | def _filter(self, filterpats, filename, data): | |
1125 | for mf, fn, cmd in filterpats: |
|
1125 | for mf, fn, cmd in filterpats: | |
1126 | if mf(filename): |
|
1126 | if mf(filename): | |
1127 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
1127 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
1128 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1128 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1129 | break |
|
1129 | break | |
1130 |
|
1130 | |||
1131 | return data |
|
1131 | return data | |
1132 |
|
1132 | |||
1133 | @unfilteredpropertycache |
|
1133 | @unfilteredpropertycache | |
1134 | def _encodefilterpats(self): |
|
1134 | def _encodefilterpats(self): | |
1135 | return self._loadfilter('encode') |
|
1135 | return self._loadfilter('encode') | |
1136 |
|
1136 | |||
1137 | @unfilteredpropertycache |
|
1137 | @unfilteredpropertycache | |
1138 | def _decodefilterpats(self): |
|
1138 | def _decodefilterpats(self): | |
1139 | return self._loadfilter('decode') |
|
1139 | return self._loadfilter('decode') | |
1140 |
|
1140 | |||
1141 | def adddatafilter(self, name, filter): |
|
1141 | def adddatafilter(self, name, filter): | |
1142 | self._datafilters[name] = filter |
|
1142 | self._datafilters[name] = filter | |
1143 |
|
1143 | |||
1144 | def wread(self, filename): |
|
1144 | def wread(self, filename): | |
1145 | if self.wvfs.islink(filename): |
|
1145 | if self.wvfs.islink(filename): | |
1146 | data = self.wvfs.readlink(filename) |
|
1146 | data = self.wvfs.readlink(filename) | |
1147 | else: |
|
1147 | else: | |
1148 | data = self.wvfs.read(filename) |
|
1148 | data = self.wvfs.read(filename) | |
1149 | return self._filter(self._encodefilterpats, filename, data) |
|
1149 | return self._filter(self._encodefilterpats, filename, data) | |
1150 |
|
1150 | |||
1151 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
1151 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
1152 | """write ``data`` into ``filename`` in the working directory |
|
1152 | """write ``data`` into ``filename`` in the working directory | |
1153 |
|
1153 | |||
1154 | This returns length of written (maybe decoded) data. |
|
1154 | This returns length of written (maybe decoded) data. | |
1155 | """ |
|
1155 | """ | |
1156 | data = self._filter(self._decodefilterpats, filename, data) |
|
1156 | data = self._filter(self._decodefilterpats, filename, data) | |
1157 | if 'l' in flags: |
|
1157 | if 'l' in flags: | |
1158 | self.wvfs.symlink(data, filename) |
|
1158 | self.wvfs.symlink(data, filename) | |
1159 | else: |
|
1159 | else: | |
1160 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, |
|
1160 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, | |
1161 | **kwargs) |
|
1161 | **kwargs) | |
1162 | if 'x' in flags: |
|
1162 | if 'x' in flags: | |
1163 | self.wvfs.setflags(filename, False, True) |
|
1163 | self.wvfs.setflags(filename, False, True) | |
1164 | else: |
|
1164 | else: | |
1165 | self.wvfs.setflags(filename, False, False) |
|
1165 | self.wvfs.setflags(filename, False, False) | |
1166 | return len(data) |
|
1166 | return len(data) | |
1167 |
|
1167 | |||
1168 | def wwritedata(self, filename, data): |
|
1168 | def wwritedata(self, filename, data): | |
1169 | return self._filter(self._decodefilterpats, filename, data) |
|
1169 | return self._filter(self._decodefilterpats, filename, data) | |
1170 |
|
1170 | |||
1171 | def currenttransaction(self): |
|
1171 | def currenttransaction(self): | |
1172 | """return the current transaction or None if non exists""" |
|
1172 | """return the current transaction or None if non exists""" | |
1173 | if self._transref: |
|
1173 | if self._transref: | |
1174 | tr = self._transref() |
|
1174 | tr = self._transref() | |
1175 | else: |
|
1175 | else: | |
1176 | tr = None |
|
1176 | tr = None | |
1177 |
|
1177 | |||
1178 | if tr and tr.running(): |
|
1178 | if tr and tr.running(): | |
1179 | return tr |
|
1179 | return tr | |
1180 | return None |
|
1180 | return None | |
1181 |
|
1181 | |||
1182 | def transaction(self, desc, report=None): |
|
1182 | def transaction(self, desc, report=None): | |
1183 | if (self.ui.configbool('devel', 'all-warnings') |
|
1183 | if (self.ui.configbool('devel', 'all-warnings') | |
1184 | or self.ui.configbool('devel', 'check-locks')): |
|
1184 | or self.ui.configbool('devel', 'check-locks')): | |
1185 | if self._currentlock(self._lockref) is None: |
|
1185 | if self._currentlock(self._lockref) is None: | |
1186 | raise error.ProgrammingError('transaction requires locking') |
|
1186 | raise error.ProgrammingError('transaction requires locking') | |
1187 | tr = self.currenttransaction() |
|
1187 | tr = self.currenttransaction() | |
1188 | if tr is not None: |
|
1188 | if tr is not None: | |
1189 | return tr.nest(name=desc) |
|
1189 | return tr.nest(name=desc) | |
1190 |
|
1190 | |||
1191 | # abort here if the journal already exists |
|
1191 | # abort here if the journal already exists | |
1192 | if self.svfs.exists("journal"): |
|
1192 | if self.svfs.exists("journal"): | |
1193 | raise error.RepoError( |
|
1193 | raise error.RepoError( | |
1194 | _("abandoned transaction found"), |
|
1194 | _("abandoned transaction found"), | |
1195 | hint=_("run 'hg recover' to clean up transaction")) |
|
1195 | hint=_("run 'hg recover' to clean up transaction")) | |
1196 |
|
1196 | |||
1197 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
1197 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
1198 | ha = hex(hashlib.sha1(idbase).digest()) |
|
1198 | ha = hex(hashlib.sha1(idbase).digest()) | |
1199 | txnid = 'TXN:' + ha |
|
1199 | txnid = 'TXN:' + ha | |
1200 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
1200 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
1201 |
|
1201 | |||
1202 | self._writejournal(desc) |
|
1202 | self._writejournal(desc) | |
1203 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
1203 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
1204 | if report: |
|
1204 | if report: | |
1205 | rp = report |
|
1205 | rp = report | |
1206 | else: |
|
1206 | else: | |
1207 | rp = self.ui.warn |
|
1207 | rp = self.ui.warn | |
1208 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
1208 | vfsmap = {'plain': self.vfs} # root of .hg/ | |
1209 | # we must avoid cyclic reference between repo and transaction. |
|
1209 | # we must avoid cyclic reference between repo and transaction. | |
1210 | reporef = weakref.ref(self) |
|
1210 | reporef = weakref.ref(self) | |
1211 | # Code to track tag movement |
|
1211 | # Code to track tag movement | |
1212 | # |
|
1212 | # | |
1213 | # Since tags are all handled as file content, it is actually quite hard |
|
1213 | # Since tags are all handled as file content, it is actually quite hard | |
1214 | # to track these movement from a code perspective. So we fallback to a |
|
1214 | # to track these movement from a code perspective. So we fallback to a | |
1215 | # tracking at the repository level. One could envision to track changes |
|
1215 | # tracking at the repository level. One could envision to track changes | |
1216 | # to the '.hgtags' file through changegroup apply but that fails to |
|
1216 | # to the '.hgtags' file through changegroup apply but that fails to | |
1217 | # cope with case where transaction expose new heads without changegroup |
|
1217 | # cope with case where transaction expose new heads without changegroup | |
1218 | # being involved (eg: phase movement). |
|
1218 | # being involved (eg: phase movement). | |
1219 | # |
|
1219 | # | |
1220 | # For now, We gate the feature behind a flag since this likely comes |
|
1220 | # For now, We gate the feature behind a flag since this likely comes | |
1221 | # with performance impacts. The current code run more often than needed |
|
1221 | # with performance impacts. The current code run more often than needed | |
1222 | # and do not use caches as much as it could. The current focus is on |
|
1222 | # and do not use caches as much as it could. The current focus is on | |
1223 | # the behavior of the feature so we disable it by default. The flag |
|
1223 | # the behavior of the feature so we disable it by default. The flag | |
1224 | # will be removed when we are happy with the performance impact. |
|
1224 | # will be removed when we are happy with the performance impact. | |
1225 | # |
|
1225 | # | |
1226 | # Once this feature is no longer experimental move the following |
|
1226 | # Once this feature is no longer experimental move the following | |
1227 | # documentation to the appropriate help section: |
|
1227 | # documentation to the appropriate help section: | |
1228 | # |
|
1228 | # | |
1229 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
1229 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
1230 | # tags (new or changed or deleted tags). In addition the details of |
|
1230 | # tags (new or changed or deleted tags). In addition the details of | |
1231 | # these changes are made available in a file at: |
|
1231 | # these changes are made available in a file at: | |
1232 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
1232 | # ``REPOROOT/.hg/changes/tags.changes``. | |
1233 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
1233 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
1234 | # might exist from a previous transaction even if no tag were touched |
|
1234 | # might exist from a previous transaction even if no tag were touched | |
1235 | # in this one. Changes are recorded in a line base format:: |
|
1235 | # in this one. Changes are recorded in a line base format:: | |
1236 | # |
|
1236 | # | |
1237 | # <action> <hex-node> <tag-name>\n |
|
1237 | # <action> <hex-node> <tag-name>\n | |
1238 | # |
|
1238 | # | |
1239 | # Actions are defined as follow: |
|
1239 | # Actions are defined as follow: | |
1240 | # "-R": tag is removed, |
|
1240 | # "-R": tag is removed, | |
1241 | # "+A": tag is added, |
|
1241 | # "+A": tag is added, | |
1242 | # "-M": tag is moved (old value), |
|
1242 | # "-M": tag is moved (old value), | |
1243 | # "+M": tag is moved (new value), |
|
1243 | # "+M": tag is moved (new value), | |
1244 | tracktags = lambda x: None |
|
1244 | tracktags = lambda x: None | |
1245 | # experimental config: experimental.hook-track-tags |
|
1245 | # experimental config: experimental.hook-track-tags | |
1246 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') |
|
1246 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') | |
1247 | if desc != 'strip' and shouldtracktags: |
|
1247 | if desc != 'strip' and shouldtracktags: | |
1248 | oldheads = self.changelog.headrevs() |
|
1248 | oldheads = self.changelog.headrevs() | |
1249 | def tracktags(tr2): |
|
1249 | def tracktags(tr2): | |
1250 | repo = reporef() |
|
1250 | repo = reporef() | |
1251 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1251 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
1252 | newheads = repo.changelog.headrevs() |
|
1252 | newheads = repo.changelog.headrevs() | |
1253 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1253 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
1254 | # notes: we compare lists here. |
|
1254 | # notes: we compare lists here. | |
1255 | # As we do it only once buiding set would not be cheaper |
|
1255 | # As we do it only once buiding set would not be cheaper | |
1256 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1256 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
1257 | if changes: |
|
1257 | if changes: | |
1258 | tr2.hookargs['tag_moved'] = '1' |
|
1258 | tr2.hookargs['tag_moved'] = '1' | |
1259 | with repo.vfs('changes/tags.changes', 'w', |
|
1259 | with repo.vfs('changes/tags.changes', 'w', | |
1260 | atomictemp=True) as changesfile: |
|
1260 | atomictemp=True) as changesfile: | |
1261 | # note: we do not register the file to the transaction |
|
1261 | # note: we do not register the file to the transaction | |
1262 | # because we needs it to still exist on the transaction |
|
1262 | # because we needs it to still exist on the transaction | |
1263 | # is close (for txnclose hooks) |
|
1263 | # is close (for txnclose hooks) | |
1264 | tagsmod.writediff(changesfile, changes) |
|
1264 | tagsmod.writediff(changesfile, changes) | |
1265 | def validate(tr2): |
|
1265 | def validate(tr2): | |
1266 | """will run pre-closing hooks""" |
|
1266 | """will run pre-closing hooks""" | |
1267 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1267 | # XXX the transaction API is a bit lacking here so we take a hacky | |
1268 | # path for now |
|
1268 | # path for now | |
1269 | # |
|
1269 | # | |
1270 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1270 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
1271 | # dict is copied before these run. In addition we needs the data |
|
1271 | # dict is copied before these run. In addition we needs the data | |
1272 | # available to in memory hooks too. |
|
1272 | # available to in memory hooks too. | |
1273 | # |
|
1273 | # | |
1274 | # Moreover, we also need to make sure this runs before txnclose |
|
1274 | # Moreover, we also need to make sure this runs before txnclose | |
1275 | # hooks and there is no "pending" mechanism that would execute |
|
1275 | # hooks and there is no "pending" mechanism that would execute | |
1276 | # logic only if hooks are about to run. |
|
1276 | # logic only if hooks are about to run. | |
1277 | # |
|
1277 | # | |
1278 | # Fixing this limitation of the transaction is also needed to track |
|
1278 | # Fixing this limitation of the transaction is also needed to track | |
1279 | # other families of changes (bookmarks, phases, obsolescence). |
|
1279 | # other families of changes (bookmarks, phases, obsolescence). | |
1280 | # |
|
1280 | # | |
1281 | # This will have to be fixed before we remove the experimental |
|
1281 | # This will have to be fixed before we remove the experimental | |
1282 | # gating. |
|
1282 | # gating. | |
1283 | tracktags(tr2) |
|
1283 | tracktags(tr2) | |
1284 | repo = reporef() |
|
1284 | repo = reporef() | |
1285 | if repo.ui.configbool('experimental', 'single-head-per-branch'): |
|
1285 | if repo.ui.configbool('experimental', 'single-head-per-branch'): | |
1286 | scmutil.enforcesinglehead(repo, tr2, desc) |
|
1286 | scmutil.enforcesinglehead(repo, tr2, desc) | |
1287 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): |
|
1287 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): | |
1288 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): |
|
1288 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): | |
1289 | args = tr.hookargs.copy() |
|
1289 | args = tr.hookargs.copy() | |
1290 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1290 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1291 | repo.hook('pretxnclose-bookmark', throw=True, |
|
1291 | repo.hook('pretxnclose-bookmark', throw=True, | |
1292 | txnname=desc, |
|
1292 | txnname=desc, | |
1293 | **pycompat.strkwargs(args)) |
|
1293 | **pycompat.strkwargs(args)) | |
1294 | if hook.hashook(repo.ui, 'pretxnclose-phase'): |
|
1294 | if hook.hashook(repo.ui, 'pretxnclose-phase'): | |
1295 | cl = repo.unfiltered().changelog |
|
1295 | cl = repo.unfiltered().changelog | |
1296 | for rev, (old, new) in tr.changes['phases'].items(): |
|
1296 | for rev, (old, new) in tr.changes['phases'].items(): | |
1297 | args = tr.hookargs.copy() |
|
1297 | args = tr.hookargs.copy() | |
1298 | node = hex(cl.node(rev)) |
|
1298 | node = hex(cl.node(rev)) | |
1299 | args.update(phases.preparehookargs(node, old, new)) |
|
1299 | args.update(phases.preparehookargs(node, old, new)) | |
1300 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, |
|
1300 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, | |
1301 | **pycompat.strkwargs(args)) |
|
1301 | **pycompat.strkwargs(args)) | |
1302 |
|
1302 | |||
1303 | repo.hook('pretxnclose', throw=True, |
|
1303 | repo.hook('pretxnclose', throw=True, | |
1304 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1304 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) | |
1305 | def releasefn(tr, success): |
|
1305 | def releasefn(tr, success): | |
1306 | repo = reporef() |
|
1306 | repo = reporef() | |
1307 | if success: |
|
1307 | if success: | |
1308 | # this should be explicitly invoked here, because |
|
1308 | # this should be explicitly invoked here, because | |
1309 | # in-memory changes aren't written out at closing |
|
1309 | # in-memory changes aren't written out at closing | |
1310 | # transaction, if tr.addfilegenerator (via |
|
1310 | # transaction, if tr.addfilegenerator (via | |
1311 | # dirstate.write or so) isn't invoked while |
|
1311 | # dirstate.write or so) isn't invoked while | |
1312 | # transaction running |
|
1312 | # transaction running | |
1313 | repo.dirstate.write(None) |
|
1313 | repo.dirstate.write(None) | |
1314 | else: |
|
1314 | else: | |
1315 | # discard all changes (including ones already written |
|
1315 | # discard all changes (including ones already written | |
1316 | # out) in this transaction |
|
1316 | # out) in this transaction | |
1317 | repo.dirstate.restorebackup(None, 'journal.dirstate') |
|
1317 | repo.dirstate.restorebackup(None, 'journal.dirstate') | |
1318 |
|
1318 | |||
1319 | repo.invalidate(clearfilecache=True) |
|
1319 | repo.invalidate(clearfilecache=True) | |
1320 |
|
1320 | |||
1321 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1321 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1322 | "journal", |
|
1322 | "journal", | |
1323 | "undo", |
|
1323 | "undo", | |
1324 | aftertrans(renames), |
|
1324 | aftertrans(renames), | |
1325 | self.store.createmode, |
|
1325 | self.store.createmode, | |
1326 | validator=validate, |
|
1326 | validator=validate, | |
1327 | releasefn=releasefn, |
|
1327 | releasefn=releasefn, | |
1328 | checkambigfiles=_cachedfiles, |
|
1328 | checkambigfiles=_cachedfiles, | |
1329 | name=desc) |
|
1329 | name=desc) | |
1330 | tr.changes['revs'] = xrange(0, 0) |
|
1330 | tr.changes['revs'] = xrange(0, 0) | |
1331 | tr.changes['obsmarkers'] = set() |
|
1331 | tr.changes['obsmarkers'] = set() | |
1332 | tr.changes['phases'] = {} |
|
1332 | tr.changes['phases'] = {} | |
1333 | tr.changes['bookmarks'] = {} |
|
1333 | tr.changes['bookmarks'] = {} | |
1334 |
|
1334 | |||
1335 | tr.hookargs['txnid'] = txnid |
|
1335 | tr.hookargs['txnid'] = txnid | |
1336 | # note: writing the fncache only during finalize mean that the file is |
|
1336 | # note: writing the fncache only during finalize mean that the file is | |
1337 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1337 | # outdated when running hooks. As fncache is used for streaming clone, | |
1338 | # this is not expected to break anything that happen during the hooks. |
|
1338 | # this is not expected to break anything that happen during the hooks. | |
1339 | tr.addfinalize('flush-fncache', self.store.write) |
|
1339 | tr.addfinalize('flush-fncache', self.store.write) | |
1340 | def txnclosehook(tr2): |
|
1340 | def txnclosehook(tr2): | |
1341 | """To be run if transaction is successful, will schedule a hook run |
|
1341 | """To be run if transaction is successful, will schedule a hook run | |
1342 | """ |
|
1342 | """ | |
1343 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1343 | # Don't reference tr2 in hook() so we don't hold a reference. | |
1344 | # This reduces memory consumption when there are multiple |
|
1344 | # This reduces memory consumption when there are multiple | |
1345 | # transactions per lock. This can likely go away if issue5045 |
|
1345 | # transactions per lock. This can likely go away if issue5045 | |
1346 | # fixes the function accumulation. |
|
1346 | # fixes the function accumulation. | |
1347 | hookargs = tr2.hookargs |
|
1347 | hookargs = tr2.hookargs | |
1348 |
|
1348 | |||
1349 | def hookfunc(): |
|
1349 | def hookfunc(): | |
1350 | repo = reporef() |
|
1350 | repo = reporef() | |
1351 | if hook.hashook(repo.ui, 'txnclose-bookmark'): |
|
1351 | if hook.hashook(repo.ui, 'txnclose-bookmark'): | |
1352 | bmchanges = sorted(tr.changes['bookmarks'].items()) |
|
1352 | bmchanges = sorted(tr.changes['bookmarks'].items()) | |
1353 | for name, (old, new) in bmchanges: |
|
1353 | for name, (old, new) in bmchanges: | |
1354 | args = tr.hookargs.copy() |
|
1354 | args = tr.hookargs.copy() | |
1355 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1355 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1356 | repo.hook('txnclose-bookmark', throw=False, |
|
1356 | repo.hook('txnclose-bookmark', throw=False, | |
1357 | txnname=desc, **pycompat.strkwargs(args)) |
|
1357 | txnname=desc, **pycompat.strkwargs(args)) | |
1358 |
|
1358 | |||
1359 | if hook.hashook(repo.ui, 'txnclose-phase'): |
|
1359 | if hook.hashook(repo.ui, 'txnclose-phase'): | |
1360 | cl = repo.unfiltered().changelog |
|
1360 | cl = repo.unfiltered().changelog | |
1361 | phasemv = sorted(tr.changes['phases'].items()) |
|
1361 | phasemv = sorted(tr.changes['phases'].items()) | |
1362 | for rev, (old, new) in phasemv: |
|
1362 | for rev, (old, new) in phasemv: | |
1363 | args = tr.hookargs.copy() |
|
1363 | args = tr.hookargs.copy() | |
1364 | node = hex(cl.node(rev)) |
|
1364 | node = hex(cl.node(rev)) | |
1365 | args.update(phases.preparehookargs(node, old, new)) |
|
1365 | args.update(phases.preparehookargs(node, old, new)) | |
1366 | repo.hook('txnclose-phase', throw=False, txnname=desc, |
|
1366 | repo.hook('txnclose-phase', throw=False, txnname=desc, | |
1367 | **pycompat.strkwargs(args)) |
|
1367 | **pycompat.strkwargs(args)) | |
1368 |
|
1368 | |||
1369 | repo.hook('txnclose', throw=False, txnname=desc, |
|
1369 | repo.hook('txnclose', throw=False, txnname=desc, | |
1370 | **pycompat.strkwargs(hookargs)) |
|
1370 | **pycompat.strkwargs(hookargs)) | |
1371 | reporef()._afterlock(hookfunc) |
|
1371 | reporef()._afterlock(hookfunc) | |
1372 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1372 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1373 | # Include a leading "-" to make it happen before the transaction summary |
|
1373 | # Include a leading "-" to make it happen before the transaction summary | |
1374 | # reports registered via scmutil.registersummarycallback() whose names |
|
1374 | # reports registered via scmutil.registersummarycallback() whose names | |
1375 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
1375 | # are 00-txnreport etc. That way, the caches will be warm when the | |
1376 | # callbacks run. |
|
1376 | # callbacks run. | |
1377 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) |
|
1377 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) | |
1378 | def txnaborthook(tr2): |
|
1378 | def txnaborthook(tr2): | |
1379 | """To be run if transaction is aborted |
|
1379 | """To be run if transaction is aborted | |
1380 | """ |
|
1380 | """ | |
1381 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1381 | reporef().hook('txnabort', throw=False, txnname=desc, | |
1382 | **pycompat.strkwargs(tr2.hookargs)) |
|
1382 | **pycompat.strkwargs(tr2.hookargs)) | |
1383 | tr.addabort('txnabort-hook', txnaborthook) |
|
1383 | tr.addabort('txnabort-hook', txnaborthook) | |
1384 | # avoid eager cache invalidation. in-memory data should be identical |
|
1384 | # avoid eager cache invalidation. in-memory data should be identical | |
1385 | # to stored data if transaction has no error. |
|
1385 | # to stored data if transaction has no error. | |
1386 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1386 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1387 | self._transref = weakref.ref(tr) |
|
1387 | self._transref = weakref.ref(tr) | |
1388 | scmutil.registersummarycallback(self, tr, desc) |
|
1388 | scmutil.registersummarycallback(self, tr, desc) | |
1389 | return tr |
|
1389 | return tr | |
1390 |
|
1390 | |||
1391 | def _journalfiles(self): |
|
1391 | def _journalfiles(self): | |
1392 | return ((self.svfs, 'journal'), |
|
1392 | return ((self.svfs, 'journal'), | |
1393 | (self.vfs, 'journal.dirstate'), |
|
1393 | (self.vfs, 'journal.dirstate'), | |
1394 | (self.vfs, 'journal.branch'), |
|
1394 | (self.vfs, 'journal.branch'), | |
1395 | (self.vfs, 'journal.desc'), |
|
1395 | (self.vfs, 'journal.desc'), | |
1396 | (self.vfs, 'journal.bookmarks'), |
|
1396 | (self.vfs, 'journal.bookmarks'), | |
1397 | (self.svfs, 'journal.phaseroots')) |
|
1397 | (self.svfs, 'journal.phaseroots')) | |
1398 |
|
1398 | |||
1399 | def undofiles(self): |
|
1399 | def undofiles(self): | |
1400 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1400 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1401 |
|
1401 | |||
1402 | @unfilteredmethod |
|
1402 | @unfilteredmethod | |
1403 | def _writejournal(self, desc): |
|
1403 | def _writejournal(self, desc): | |
1404 | self.dirstate.savebackup(None, 'journal.dirstate') |
|
1404 | self.dirstate.savebackup(None, 'journal.dirstate') | |
1405 | self.vfs.write("journal.branch", |
|
1405 | self.vfs.write("journal.branch", | |
1406 | encoding.fromlocal(self.dirstate.branch())) |
|
1406 | encoding.fromlocal(self.dirstate.branch())) | |
1407 | self.vfs.write("journal.desc", |
|
1407 | self.vfs.write("journal.desc", | |
1408 | "%d\n%s\n" % (len(self), desc)) |
|
1408 | "%d\n%s\n" % (len(self), desc)) | |
1409 | self.vfs.write("journal.bookmarks", |
|
1409 | self.vfs.write("journal.bookmarks", | |
1410 | self.vfs.tryread("bookmarks")) |
|
1410 | self.vfs.tryread("bookmarks")) | |
1411 | self.svfs.write("journal.phaseroots", |
|
1411 | self.svfs.write("journal.phaseroots", | |
1412 | self.svfs.tryread("phaseroots")) |
|
1412 | self.svfs.tryread("phaseroots")) | |
1413 |
|
1413 | |||
1414 | def recover(self): |
|
1414 | def recover(self): | |
1415 | with self.lock(): |
|
1415 | with self.lock(): | |
1416 | if self.svfs.exists("journal"): |
|
1416 | if self.svfs.exists("journal"): | |
1417 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1417 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1418 | vfsmap = {'': self.svfs, |
|
1418 | vfsmap = {'': self.svfs, | |
1419 | 'plain': self.vfs,} |
|
1419 | 'plain': self.vfs,} | |
1420 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1420 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1421 | self.ui.warn, |
|
1421 | self.ui.warn, | |
1422 | checkambigfiles=_cachedfiles) |
|
1422 | checkambigfiles=_cachedfiles) | |
1423 | self.invalidate() |
|
1423 | self.invalidate() | |
1424 | return True |
|
1424 | return True | |
1425 | else: |
|
1425 | else: | |
1426 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1426 | self.ui.warn(_("no interrupted transaction available\n")) | |
1427 | return False |
|
1427 | return False | |
1428 |
|
1428 | |||
1429 | def rollback(self, dryrun=False, force=False): |
|
1429 | def rollback(self, dryrun=False, force=False): | |
1430 | wlock = lock = dsguard = None |
|
1430 | wlock = lock = dsguard = None | |
1431 | try: |
|
1431 | try: | |
1432 | wlock = self.wlock() |
|
1432 | wlock = self.wlock() | |
1433 | lock = self.lock() |
|
1433 | lock = self.lock() | |
1434 | if self.svfs.exists("undo"): |
|
1434 | if self.svfs.exists("undo"): | |
1435 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
1435 | dsguard = dirstateguard.dirstateguard(self, 'rollback') | |
1436 |
|
1436 | |||
1437 | return self._rollback(dryrun, force, dsguard) |
|
1437 | return self._rollback(dryrun, force, dsguard) | |
1438 | else: |
|
1438 | else: | |
1439 | self.ui.warn(_("no rollback information available\n")) |
|
1439 | self.ui.warn(_("no rollback information available\n")) | |
1440 | return 1 |
|
1440 | return 1 | |
1441 | finally: |
|
1441 | finally: | |
1442 | release(dsguard, lock, wlock) |
|
1442 | release(dsguard, lock, wlock) | |
1443 |
|
1443 | |||
1444 | @unfilteredmethod # Until we get smarter cache management |
|
1444 | @unfilteredmethod # Until we get smarter cache management | |
1445 | def _rollback(self, dryrun, force, dsguard): |
|
1445 | def _rollback(self, dryrun, force, dsguard): | |
1446 | ui = self.ui |
|
1446 | ui = self.ui | |
1447 | try: |
|
1447 | try: | |
1448 | args = self.vfs.read('undo.desc').splitlines() |
|
1448 | args = self.vfs.read('undo.desc').splitlines() | |
1449 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1449 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
1450 | if len(args) >= 3: |
|
1450 | if len(args) >= 3: | |
1451 | detail = args[2] |
|
1451 | detail = args[2] | |
1452 | oldtip = oldlen - 1 |
|
1452 | oldtip = oldlen - 1 | |
1453 |
|
1453 | |||
1454 | if detail and ui.verbose: |
|
1454 | if detail and ui.verbose: | |
1455 | msg = (_('repository tip rolled back to revision %d' |
|
1455 | msg = (_('repository tip rolled back to revision %d' | |
1456 | ' (undo %s: %s)\n') |
|
1456 | ' (undo %s: %s)\n') | |
1457 | % (oldtip, desc, detail)) |
|
1457 | % (oldtip, desc, detail)) | |
1458 | else: |
|
1458 | else: | |
1459 | msg = (_('repository tip rolled back to revision %d' |
|
1459 | msg = (_('repository tip rolled back to revision %d' | |
1460 | ' (undo %s)\n') |
|
1460 | ' (undo %s)\n') | |
1461 | % (oldtip, desc)) |
|
1461 | % (oldtip, desc)) | |
1462 | except IOError: |
|
1462 | except IOError: | |
1463 | msg = _('rolling back unknown transaction\n') |
|
1463 | msg = _('rolling back unknown transaction\n') | |
1464 | desc = None |
|
1464 | desc = None | |
1465 |
|
1465 | |||
1466 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1466 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
1467 | raise error.Abort( |
|
1467 | raise error.Abort( | |
1468 | _('rollback of last commit while not checked out ' |
|
1468 | _('rollback of last commit while not checked out ' | |
1469 | 'may lose data'), hint=_('use -f to force')) |
|
1469 | 'may lose data'), hint=_('use -f to force')) | |
1470 |
|
1470 | |||
1471 | ui.status(msg) |
|
1471 | ui.status(msg) | |
1472 | if dryrun: |
|
1472 | if dryrun: | |
1473 | return 0 |
|
1473 | return 0 | |
1474 |
|
1474 | |||
1475 | parents = self.dirstate.parents() |
|
1475 | parents = self.dirstate.parents() | |
1476 | self.destroying() |
|
1476 | self.destroying() | |
1477 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1477 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
1478 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, |
|
1478 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, | |
1479 | checkambigfiles=_cachedfiles) |
|
1479 | checkambigfiles=_cachedfiles) | |
1480 | if self.vfs.exists('undo.bookmarks'): |
|
1480 | if self.vfs.exists('undo.bookmarks'): | |
1481 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
1481 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) | |
1482 | if self.svfs.exists('undo.phaseroots'): |
|
1482 | if self.svfs.exists('undo.phaseroots'): | |
1483 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
1483 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) | |
1484 | self.invalidate() |
|
1484 | self.invalidate() | |
1485 |
|
1485 | |||
1486 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1486 | parentgone = (parents[0] not in self.changelog.nodemap or | |
1487 | parents[1] not in self.changelog.nodemap) |
|
1487 | parents[1] not in self.changelog.nodemap) | |
1488 | if parentgone: |
|
1488 | if parentgone: | |
1489 | # prevent dirstateguard from overwriting already restored one |
|
1489 | # prevent dirstateguard from overwriting already restored one | |
1490 | dsguard.close() |
|
1490 | dsguard.close() | |
1491 |
|
1491 | |||
1492 | self.dirstate.restorebackup(None, 'undo.dirstate') |
|
1492 | self.dirstate.restorebackup(None, 'undo.dirstate') | |
1493 | try: |
|
1493 | try: | |
1494 | branch = self.vfs.read('undo.branch') |
|
1494 | branch = self.vfs.read('undo.branch') | |
1495 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1495 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
1496 | except IOError: |
|
1496 | except IOError: | |
1497 | ui.warn(_('named branch could not be reset: ' |
|
1497 | ui.warn(_('named branch could not be reset: ' | |
1498 | 'current branch is still \'%s\'\n') |
|
1498 | 'current branch is still \'%s\'\n') | |
1499 | % self.dirstate.branch()) |
|
1499 | % self.dirstate.branch()) | |
1500 |
|
1500 | |||
1501 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
1501 | parents = tuple([p.rev() for p in self[None].parents()]) | |
1502 | if len(parents) > 1: |
|
1502 | if len(parents) > 1: | |
1503 | ui.status(_('working directory now based on ' |
|
1503 | ui.status(_('working directory now based on ' | |
1504 | 'revisions %d and %d\n') % parents) |
|
1504 | 'revisions %d and %d\n') % parents) | |
1505 | else: |
|
1505 | else: | |
1506 | ui.status(_('working directory now based on ' |
|
1506 | ui.status(_('working directory now based on ' | |
1507 | 'revision %d\n') % parents) |
|
1507 | 'revision %d\n') % parents) | |
1508 | mergemod.mergestate.clean(self, self['.'].node()) |
|
1508 | mergemod.mergestate.clean(self, self['.'].node()) | |
1509 |
|
1509 | |||
1510 | # TODO: if we know which new heads may result from this rollback, pass |
|
1510 | # TODO: if we know which new heads may result from this rollback, pass | |
1511 | # them to destroy(), which will prevent the branchhead cache from being |
|
1511 | # them to destroy(), which will prevent the branchhead cache from being | |
1512 | # invalidated. |
|
1512 | # invalidated. | |
1513 | self.destroyed() |
|
1513 | self.destroyed() | |
1514 | return 0 |
|
1514 | return 0 | |
1515 |
|
1515 | |||
1516 | def _buildcacheupdater(self, newtransaction): |
|
1516 | def _buildcacheupdater(self, newtransaction): | |
1517 | """called during transaction to build the callback updating cache |
|
1517 | """called during transaction to build the callback updating cache | |
1518 |
|
1518 | |||
1519 | Lives on the repository to help extension who might want to augment |
|
1519 | Lives on the repository to help extension who might want to augment | |
1520 | this logic. For this purpose, the created transaction is passed to the |
|
1520 | this logic. For this purpose, the created transaction is passed to the | |
1521 | method. |
|
1521 | method. | |
1522 | """ |
|
1522 | """ | |
1523 | # we must avoid cyclic reference between repo and transaction. |
|
1523 | # we must avoid cyclic reference between repo and transaction. | |
1524 | reporef = weakref.ref(self) |
|
1524 | reporef = weakref.ref(self) | |
1525 | def updater(tr): |
|
1525 | def updater(tr): | |
1526 | repo = reporef() |
|
1526 | repo = reporef() | |
1527 | repo.updatecaches(tr) |
|
1527 | repo.updatecaches(tr) | |
1528 | return updater |
|
1528 | return updater | |
1529 |
|
1529 | |||
1530 | @unfilteredmethod |
|
1530 | @unfilteredmethod | |
1531 | def updatecaches(self, tr=None, full=False): |
|
1531 | def updatecaches(self, tr=None, full=False): | |
1532 | """warm appropriate caches |
|
1532 | """warm appropriate caches | |
1533 |
|
1533 | |||
1534 | If this function is called after a transaction closed. The transaction |
|
1534 | If this function is called after a transaction closed. The transaction | |
1535 | will be available in the 'tr' argument. This can be used to selectively |
|
1535 | will be available in the 'tr' argument. This can be used to selectively | |
1536 | update caches relevant to the changes in that transaction. |
|
1536 | update caches relevant to the changes in that transaction. | |
1537 |
|
1537 | |||
1538 | If 'full' is set, make sure all caches the function knows about have |
|
1538 | If 'full' is set, make sure all caches the function knows about have | |
1539 | up-to-date data. Even the ones usually loaded more lazily. |
|
1539 | up-to-date data. Even the ones usually loaded more lazily. | |
1540 | """ |
|
1540 | """ | |
1541 | if tr is not None and tr.hookargs.get('source') == 'strip': |
|
1541 | if tr is not None and tr.hookargs.get('source') == 'strip': | |
1542 | # During strip, many caches are invalid but |
|
1542 | # During strip, many caches are invalid but | |
1543 | # later call to `destroyed` will refresh them. |
|
1543 | # later call to `destroyed` will refresh them. | |
1544 | return |
|
1544 | return | |
1545 |
|
1545 | |||
1546 | if tr is None or tr.changes['revs']: |
|
1546 | if tr is None or tr.changes['revs']: | |
1547 | # updating the unfiltered branchmap should refresh all the others, |
|
1547 | # updating the unfiltered branchmap should refresh all the others, | |
1548 | self.ui.debug('updating the branch cache\n') |
|
1548 | self.ui.debug('updating the branch cache\n') | |
1549 | branchmap.updatecache(self.filtered('served')) |
|
1549 | branchmap.updatecache(self.filtered('served')) | |
1550 |
|
1550 | |||
1551 | if full: |
|
1551 | if full: | |
1552 | rbc = self.revbranchcache() |
|
1552 | rbc = self.revbranchcache() | |
1553 | for r in self.changelog: |
|
1553 | for r in self.changelog: | |
1554 | rbc.branchinfo(r) |
|
1554 | rbc.branchinfo(r) | |
1555 | rbc.write() |
|
1555 | rbc.write() | |
1556 |
|
1556 | |||
1557 | def invalidatecaches(self): |
|
1557 | def invalidatecaches(self): | |
1558 |
|
1558 | |||
1559 | if '_tagscache' in vars(self): |
|
1559 | if '_tagscache' in vars(self): | |
1560 | # can't use delattr on proxy |
|
1560 | # can't use delattr on proxy | |
1561 | del self.__dict__['_tagscache'] |
|
1561 | del self.__dict__['_tagscache'] | |
1562 |
|
1562 | |||
1563 | self.unfiltered()._branchcaches.clear() |
|
1563 | self.unfiltered()._branchcaches.clear() | |
1564 | self.invalidatevolatilesets() |
|
1564 | self.invalidatevolatilesets() | |
1565 | self._sparsesignaturecache.clear() |
|
1565 | self._sparsesignaturecache.clear() | |
1566 |
|
1566 | |||
1567 | def invalidatevolatilesets(self): |
|
1567 | def invalidatevolatilesets(self): | |
1568 | self.filteredrevcache.clear() |
|
1568 | self.filteredrevcache.clear() | |
1569 | obsolete.clearobscaches(self) |
|
1569 | obsolete.clearobscaches(self) | |
1570 |
|
1570 | |||
1571 | def invalidatedirstate(self): |
|
1571 | def invalidatedirstate(self): | |
1572 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1572 | '''Invalidates the dirstate, causing the next call to dirstate | |
1573 | to check if it was modified since the last time it was read, |
|
1573 | to check if it was modified since the last time it was read, | |
1574 | rereading it if it has. |
|
1574 | rereading it if it has. | |
1575 |
|
1575 | |||
1576 | This is different to dirstate.invalidate() that it doesn't always |
|
1576 | This is different to dirstate.invalidate() that it doesn't always | |
1577 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1577 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
1578 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1578 | explicitly read the dirstate again (i.e. restoring it to a previous | |
1579 | known good state).''' |
|
1579 | known good state).''' | |
1580 | if hasunfilteredcache(self, 'dirstate'): |
|
1580 | if hasunfilteredcache(self, 'dirstate'): | |
1581 | for k in self.dirstate._filecache: |
|
1581 | for k in self.dirstate._filecache: | |
1582 | try: |
|
1582 | try: | |
1583 | delattr(self.dirstate, k) |
|
1583 | delattr(self.dirstate, k) | |
1584 | except AttributeError: |
|
1584 | except AttributeError: | |
1585 | pass |
|
1585 | pass | |
1586 | delattr(self.unfiltered(), 'dirstate') |
|
1586 | delattr(self.unfiltered(), 'dirstate') | |
1587 |
|
1587 | |||
1588 | def invalidate(self, clearfilecache=False): |
|
1588 | def invalidate(self, clearfilecache=False): | |
1589 | '''Invalidates both store and non-store parts other than dirstate |
|
1589 | '''Invalidates both store and non-store parts other than dirstate | |
1590 |
|
1590 | |||
1591 | If a transaction is running, invalidation of store is omitted, |
|
1591 | If a transaction is running, invalidation of store is omitted, | |
1592 | because discarding in-memory changes might cause inconsistency |
|
1592 | because discarding in-memory changes might cause inconsistency | |
1593 | (e.g. incomplete fncache causes unintentional failure, but |
|
1593 | (e.g. incomplete fncache causes unintentional failure, but | |
1594 | redundant one doesn't). |
|
1594 | redundant one doesn't). | |
1595 | ''' |
|
1595 | ''' | |
1596 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1596 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
1597 | for k in list(self._filecache.keys()): |
|
1597 | for k in list(self._filecache.keys()): | |
1598 | # dirstate is invalidated separately in invalidatedirstate() |
|
1598 | # dirstate is invalidated separately in invalidatedirstate() | |
1599 | if k == 'dirstate': |
|
1599 | if k == 'dirstate': | |
1600 | continue |
|
1600 | continue | |
1601 | if (k == 'changelog' and |
|
1601 | if (k == 'changelog' and | |
1602 | self.currenttransaction() and |
|
1602 | self.currenttransaction() and | |
1603 | self.changelog._delayed): |
|
1603 | self.changelog._delayed): | |
1604 | # The changelog object may store unwritten revisions. We don't |
|
1604 | # The changelog object may store unwritten revisions. We don't | |
1605 | # want to lose them. |
|
1605 | # want to lose them. | |
1606 | # TODO: Solve the problem instead of working around it. |
|
1606 | # TODO: Solve the problem instead of working around it. | |
1607 | continue |
|
1607 | continue | |
1608 |
|
1608 | |||
1609 | if clearfilecache: |
|
1609 | if clearfilecache: | |
1610 | del self._filecache[k] |
|
1610 | del self._filecache[k] | |
1611 | try: |
|
1611 | try: | |
1612 | delattr(unfiltered, k) |
|
1612 | delattr(unfiltered, k) | |
1613 | except AttributeError: |
|
1613 | except AttributeError: | |
1614 | pass |
|
1614 | pass | |
1615 | self.invalidatecaches() |
|
1615 | self.invalidatecaches() | |
1616 | if not self.currenttransaction(): |
|
1616 | if not self.currenttransaction(): | |
1617 | # TODO: Changing contents of store outside transaction |
|
1617 | # TODO: Changing contents of store outside transaction | |
1618 | # causes inconsistency. We should make in-memory store |
|
1618 | # causes inconsistency. We should make in-memory store | |
1619 | # changes detectable, and abort if changed. |
|
1619 | # changes detectable, and abort if changed. | |
1620 | self.store.invalidatecaches() |
|
1620 | self.store.invalidatecaches() | |
1621 |
|
1621 | |||
1622 | def invalidateall(self): |
|
1622 | def invalidateall(self): | |
1623 | '''Fully invalidates both store and non-store parts, causing the |
|
1623 | '''Fully invalidates both store and non-store parts, causing the | |
1624 | subsequent operation to reread any outside changes.''' |
|
1624 | subsequent operation to reread any outside changes.''' | |
1625 | # extension should hook this to invalidate its caches |
|
1625 | # extension should hook this to invalidate its caches | |
1626 | self.invalidate() |
|
1626 | self.invalidate() | |
1627 | self.invalidatedirstate() |
|
1627 | self.invalidatedirstate() | |
1628 |
|
1628 | |||
1629 | @unfilteredmethod |
|
1629 | @unfilteredmethod | |
1630 | def _refreshfilecachestats(self, tr): |
|
1630 | def _refreshfilecachestats(self, tr): | |
1631 | """Reload stats of cached files so that they are flagged as valid""" |
|
1631 | """Reload stats of cached files so that they are flagged as valid""" | |
1632 | for k, ce in self._filecache.items(): |
|
1632 | for k, ce in self._filecache.items(): | |
1633 | k = pycompat.sysstr(k) |
|
1633 | k = pycompat.sysstr(k) | |
1634 | if k == r'dirstate' or k not in self.__dict__: |
|
1634 | if k == r'dirstate' or k not in self.__dict__: | |
1635 | continue |
|
1635 | continue | |
1636 | ce.refresh() |
|
1636 | ce.refresh() | |
1637 |
|
1637 | |||
1638 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1638 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
1639 | inheritchecker=None, parentenvvar=None): |
|
1639 | inheritchecker=None, parentenvvar=None): | |
1640 | parentlock = None |
|
1640 | parentlock = None | |
1641 | # the contents of parentenvvar are used by the underlying lock to |
|
1641 | # the contents of parentenvvar are used by the underlying lock to | |
1642 | # determine whether it can be inherited |
|
1642 | # determine whether it can be inherited | |
1643 | if parentenvvar is not None: |
|
1643 | if parentenvvar is not None: | |
1644 | parentlock = encoding.environ.get(parentenvvar) |
|
1644 | parentlock = encoding.environ.get(parentenvvar) | |
1645 |
|
1645 | |||
1646 | timeout = 0 |
|
1646 | timeout = 0 | |
1647 | warntimeout = 0 |
|
1647 | warntimeout = 0 | |
1648 | if wait: |
|
1648 | if wait: | |
1649 | timeout = self.ui.configint("ui", "timeout") |
|
1649 | timeout = self.ui.configint("ui", "timeout") | |
1650 | warntimeout = self.ui.configint("ui", "timeout.warn") |
|
1650 | warntimeout = self.ui.configint("ui", "timeout.warn") | |
1651 |
|
1651 | |||
1652 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, |
|
1652 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, | |
1653 | releasefn=releasefn, |
|
1653 | releasefn=releasefn, | |
1654 | acquirefn=acquirefn, desc=desc, |
|
1654 | acquirefn=acquirefn, desc=desc, | |
1655 | inheritchecker=inheritchecker, |
|
1655 | inheritchecker=inheritchecker, | |
1656 | parentlock=parentlock) |
|
1656 | parentlock=parentlock) | |
1657 | return l |
|
1657 | return l | |
1658 |
|
1658 | |||
1659 | def _afterlock(self, callback): |
|
1659 | def _afterlock(self, callback): | |
1660 | """add a callback to be run when the repository is fully unlocked |
|
1660 | """add a callback to be run when the repository is fully unlocked | |
1661 |
|
1661 | |||
1662 | The callback will be executed when the outermost lock is released |
|
1662 | The callback will be executed when the outermost lock is released | |
1663 | (with wlock being higher level than 'lock').""" |
|
1663 | (with wlock being higher level than 'lock').""" | |
1664 | for ref in (self._wlockref, self._lockref): |
|
1664 | for ref in (self._wlockref, self._lockref): | |
1665 | l = ref and ref() |
|
1665 | l = ref and ref() | |
1666 | if l and l.held: |
|
1666 | if l and l.held: | |
1667 | l.postrelease.append(callback) |
|
1667 | l.postrelease.append(callback) | |
1668 | break |
|
1668 | break | |
1669 | else: # no lock have been found. |
|
1669 | else: # no lock have been found. | |
1670 | callback() |
|
1670 | callback() | |
1671 |
|
1671 | |||
1672 | def lock(self, wait=True): |
|
1672 | def lock(self, wait=True): | |
1673 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1673 | '''Lock the repository store (.hg/store) and return a weak reference | |
1674 | to the lock. Use this before modifying the store (e.g. committing or |
|
1674 | to the lock. Use this before modifying the store (e.g. committing or | |
1675 | stripping). If you are opening a transaction, get a lock as well.) |
|
1675 | stripping). If you are opening a transaction, get a lock as well.) | |
1676 |
|
1676 | |||
1677 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1677 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1678 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1678 | 'wlock' first to avoid a dead-lock hazard.''' | |
1679 | l = self._currentlock(self._lockref) |
|
1679 | l = self._currentlock(self._lockref) | |
1680 | if l is not None: |
|
1680 | if l is not None: | |
1681 | l.lock() |
|
1681 | l.lock() | |
1682 | return l |
|
1682 | return l | |
1683 |
|
1683 | |||
1684 | l = self._lock(self.svfs, "lock", wait, None, |
|
1684 | l = self._lock(self.svfs, "lock", wait, None, | |
1685 | self.invalidate, _('repository %s') % self.origroot) |
|
1685 | self.invalidate, _('repository %s') % self.origroot) | |
1686 | self._lockref = weakref.ref(l) |
|
1686 | self._lockref = weakref.ref(l) | |
1687 | return l |
|
1687 | return l | |
1688 |
|
1688 | |||
1689 | def _wlockchecktransaction(self): |
|
1689 | def _wlockchecktransaction(self): | |
1690 | if self.currenttransaction() is not None: |
|
1690 | if self.currenttransaction() is not None: | |
1691 | raise error.LockInheritanceContractViolation( |
|
1691 | raise error.LockInheritanceContractViolation( | |
1692 | 'wlock cannot be inherited in the middle of a transaction') |
|
1692 | 'wlock cannot be inherited in the middle of a transaction') | |
1693 |
|
1693 | |||
1694 | def wlock(self, wait=True): |
|
1694 | def wlock(self, wait=True): | |
1695 | '''Lock the non-store parts of the repository (everything under |
|
1695 | '''Lock the non-store parts of the repository (everything under | |
1696 | .hg except .hg/store) and return a weak reference to the lock. |
|
1696 | .hg except .hg/store) and return a weak reference to the lock. | |
1697 |
|
1697 | |||
1698 | Use this before modifying files in .hg. |
|
1698 | Use this before modifying files in .hg. | |
1699 |
|
1699 | |||
1700 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1700 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1701 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1701 | 'wlock' first to avoid a dead-lock hazard.''' | |
1702 | l = self._wlockref and self._wlockref() |
|
1702 | l = self._wlockref and self._wlockref() | |
1703 | if l is not None and l.held: |
|
1703 | if l is not None and l.held: | |
1704 | l.lock() |
|
1704 | l.lock() | |
1705 | return l |
|
1705 | return l | |
1706 |
|
1706 | |||
1707 | # We do not need to check for non-waiting lock acquisition. Such |
|
1707 | # We do not need to check for non-waiting lock acquisition. Such | |
1708 | # acquisition would not cause dead-lock as they would just fail. |
|
1708 | # acquisition would not cause dead-lock as they would just fail. | |
1709 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1709 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
1710 | or self.ui.configbool('devel', 'check-locks')): |
|
1710 | or self.ui.configbool('devel', 'check-locks')): | |
1711 | if self._currentlock(self._lockref) is not None: |
|
1711 | if self._currentlock(self._lockref) is not None: | |
1712 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1712 | self.ui.develwarn('"wlock" acquired after "lock"') | |
1713 |
|
1713 | |||
1714 | def unlock(): |
|
1714 | def unlock(): | |
1715 | if self.dirstate.pendingparentchange(): |
|
1715 | if self.dirstate.pendingparentchange(): | |
1716 | self.dirstate.invalidate() |
|
1716 | self.dirstate.invalidate() | |
1717 | else: |
|
1717 | else: | |
1718 | self.dirstate.write(None) |
|
1718 | self.dirstate.write(None) | |
1719 |
|
1719 | |||
1720 | self._filecache['dirstate'].refresh() |
|
1720 | self._filecache['dirstate'].refresh() | |
1721 |
|
1721 | |||
1722 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1722 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
1723 | self.invalidatedirstate, _('working directory of %s') % |
|
1723 | self.invalidatedirstate, _('working directory of %s') % | |
1724 | self.origroot, |
|
1724 | self.origroot, | |
1725 | inheritchecker=self._wlockchecktransaction, |
|
1725 | inheritchecker=self._wlockchecktransaction, | |
1726 | parentenvvar='HG_WLOCK_LOCKER') |
|
1726 | parentenvvar='HG_WLOCK_LOCKER') | |
1727 | self._wlockref = weakref.ref(l) |
|
1727 | self._wlockref = weakref.ref(l) | |
1728 | return l |
|
1728 | return l | |
1729 |
|
1729 | |||
1730 | def _currentlock(self, lockref): |
|
1730 | def _currentlock(self, lockref): | |
1731 | """Returns the lock if it's held, or None if it's not.""" |
|
1731 | """Returns the lock if it's held, or None if it's not.""" | |
1732 | if lockref is None: |
|
1732 | if lockref is None: | |
1733 | return None |
|
1733 | return None | |
1734 | l = lockref() |
|
1734 | l = lockref() | |
1735 | if l is None or not l.held: |
|
1735 | if l is None or not l.held: | |
1736 | return None |
|
1736 | return None | |
1737 | return l |
|
1737 | return l | |
1738 |
|
1738 | |||
1739 | def currentwlock(self): |
|
1739 | def currentwlock(self): | |
1740 | """Returns the wlock if it's held, or None if it's not.""" |
|
1740 | """Returns the wlock if it's held, or None if it's not.""" | |
1741 | return self._currentlock(self._wlockref) |
|
1741 | return self._currentlock(self._wlockref) | |
1742 |
|
1742 | |||
1743 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1743 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
1744 | """ |
|
1744 | """ | |
1745 | commit an individual file as part of a larger transaction |
|
1745 | commit an individual file as part of a larger transaction | |
1746 | """ |
|
1746 | """ | |
1747 |
|
1747 | |||
1748 | fname = fctx.path() |
|
1748 | fname = fctx.path() | |
1749 | fparent1 = manifest1.get(fname, nullid) |
|
1749 | fparent1 = manifest1.get(fname, nullid) | |
1750 | fparent2 = manifest2.get(fname, nullid) |
|
1750 | fparent2 = manifest2.get(fname, nullid) | |
1751 | if isinstance(fctx, context.filectx): |
|
1751 | if isinstance(fctx, context.filectx): | |
1752 | node = fctx.filenode() |
|
1752 | node = fctx.filenode() | |
1753 | if node in [fparent1, fparent2]: |
|
1753 | if node in [fparent1, fparent2]: | |
1754 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1754 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
1755 | if manifest1.flags(fname) != fctx.flags(): |
|
1755 | if manifest1.flags(fname) != fctx.flags(): | |
1756 | changelist.append(fname) |
|
1756 | changelist.append(fname) | |
1757 | return node |
|
1757 | return node | |
1758 |
|
1758 | |||
1759 | flog = self.file(fname) |
|
1759 | flog = self.file(fname) | |
1760 | meta = {} |
|
1760 | meta = {} | |
1761 | copy = fctx.renamed() |
|
1761 | copy = fctx.renamed() | |
1762 | if copy and copy[0] != fname: |
|
1762 | if copy and copy[0] != fname: | |
1763 | # Mark the new revision of this file as a copy of another |
|
1763 | # Mark the new revision of this file as a copy of another | |
1764 | # file. This copy data will effectively act as a parent |
|
1764 | # file. This copy data will effectively act as a parent | |
1765 | # of this new revision. If this is a merge, the first |
|
1765 | # of this new revision. If this is a merge, the first | |
1766 | # parent will be the nullid (meaning "look up the copy data") |
|
1766 | # parent will be the nullid (meaning "look up the copy data") | |
1767 | # and the second one will be the other parent. For example: |
|
1767 | # and the second one will be the other parent. For example: | |
1768 | # |
|
1768 | # | |
1769 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1769 | # 0 --- 1 --- 3 rev1 changes file foo | |
1770 | # \ / rev2 renames foo to bar and changes it |
|
1770 | # \ / rev2 renames foo to bar and changes it | |
1771 | # \- 2 -/ rev3 should have bar with all changes and |
|
1771 | # \- 2 -/ rev3 should have bar with all changes and | |
1772 | # should record that bar descends from |
|
1772 | # should record that bar descends from | |
1773 | # bar in rev2 and foo in rev1 |
|
1773 | # bar in rev2 and foo in rev1 | |
1774 | # |
|
1774 | # | |
1775 | # this allows this merge to succeed: |
|
1775 | # this allows this merge to succeed: | |
1776 | # |
|
1776 | # | |
1777 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1777 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1778 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1778 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1779 | # \- 2 --- 4 as the merge base |
|
1779 | # \- 2 --- 4 as the merge base | |
1780 | # |
|
1780 | # | |
1781 |
|
1781 | |||
1782 | cfname = copy[0] |
|
1782 | cfname = copy[0] | |
1783 | crev = manifest1.get(cfname) |
|
1783 | crev = manifest1.get(cfname) | |
1784 | newfparent = fparent2 |
|
1784 | newfparent = fparent2 | |
1785 |
|
1785 | |||
1786 | if manifest2: # branch merge |
|
1786 | if manifest2: # branch merge | |
1787 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1787 | if fparent2 == nullid or crev is None: # copied on remote side | |
1788 | if cfname in manifest2: |
|
1788 | if cfname in manifest2: | |
1789 | crev = manifest2[cfname] |
|
1789 | crev = manifest2[cfname] | |
1790 | newfparent = fparent1 |
|
1790 | newfparent = fparent1 | |
1791 |
|
1791 | |||
1792 | # Here, we used to search backwards through history to try to find |
|
1792 | # Here, we used to search backwards through history to try to find | |
1793 | # where the file copy came from if the source of a copy was not in |
|
1793 | # where the file copy came from if the source of a copy was not in | |
1794 | # the parent directory. However, this doesn't actually make sense to |
|
1794 | # the parent directory. However, this doesn't actually make sense to | |
1795 | # do (what does a copy from something not in your working copy even |
|
1795 | # do (what does a copy from something not in your working copy even | |
1796 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1796 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
1797 | # the user that copy information was dropped, so if they didn't |
|
1797 | # the user that copy information was dropped, so if they didn't | |
1798 | # expect this outcome it can be fixed, but this is the correct |
|
1798 | # expect this outcome it can be fixed, but this is the correct | |
1799 | # behavior in this circumstance. |
|
1799 | # behavior in this circumstance. | |
1800 |
|
1800 | |||
1801 | if crev: |
|
1801 | if crev: | |
1802 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1802 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1803 | meta["copy"] = cfname |
|
1803 | meta["copy"] = cfname | |
1804 | meta["copyrev"] = hex(crev) |
|
1804 | meta["copyrev"] = hex(crev) | |
1805 | fparent1, fparent2 = nullid, newfparent |
|
1805 | fparent1, fparent2 = nullid, newfparent | |
1806 | else: |
|
1806 | else: | |
1807 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1807 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1808 | "copied from '%s'!\n") % (fname, cfname)) |
|
1808 | "copied from '%s'!\n") % (fname, cfname)) | |
1809 |
|
1809 | |||
1810 | elif fparent1 == nullid: |
|
1810 | elif fparent1 == nullid: | |
1811 | fparent1, fparent2 = fparent2, nullid |
|
1811 | fparent1, fparent2 = fparent2, nullid | |
1812 | elif fparent2 != nullid: |
|
1812 | elif fparent2 != nullid: | |
1813 | # is one parent an ancestor of the other? |
|
1813 | # is one parent an ancestor of the other? | |
1814 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1814 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
1815 | if fparent1 in fparentancestors: |
|
1815 | if fparent1 in fparentancestors: | |
1816 | fparent1, fparent2 = fparent2, nullid |
|
1816 | fparent1, fparent2 = fparent2, nullid | |
1817 | elif fparent2 in fparentancestors: |
|
1817 | elif fparent2 in fparentancestors: | |
1818 | fparent2 = nullid |
|
1818 | fparent2 = nullid | |
1819 |
|
1819 | |||
1820 | # is the file changed? |
|
1820 | # is the file changed? | |
1821 | text = fctx.data() |
|
1821 | text = fctx.data() | |
1822 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1822 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1823 | changelist.append(fname) |
|
1823 | changelist.append(fname) | |
1824 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1824 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1825 | # are just the flags changed during merge? |
|
1825 | # are just the flags changed during merge? | |
1826 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1826 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
1827 | changelist.append(fname) |
|
1827 | changelist.append(fname) | |
1828 |
|
1828 | |||
1829 | return fparent1 |
|
1829 | return fparent1 | |
1830 |
|
1830 | |||
1831 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
1831 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): | |
1832 | """check for commit arguments that aren't committable""" |
|
1832 | """check for commit arguments that aren't committable""" | |
1833 | if match.isexact() or match.prefix(): |
|
1833 | if match.isexact() or match.prefix(): | |
1834 | matched = set(status.modified + status.added + status.removed) |
|
1834 | matched = set(status.modified + status.added + status.removed) | |
1835 |
|
1835 | |||
1836 | for f in match.files(): |
|
1836 | for f in match.files(): | |
1837 | f = self.dirstate.normalize(f) |
|
1837 | f = self.dirstate.normalize(f) | |
1838 | if f == '.' or f in matched or f in wctx.substate: |
|
1838 | if f == '.' or f in matched or f in wctx.substate: | |
1839 | continue |
|
1839 | continue | |
1840 | if f in status.deleted: |
|
1840 | if f in status.deleted: | |
1841 | fail(f, _('file not found!')) |
|
1841 | fail(f, _('file not found!')) | |
1842 | if f in vdirs: # visited directory |
|
1842 | if f in vdirs: # visited directory | |
1843 | d = f + '/' |
|
1843 | d = f + '/' | |
1844 | for mf in matched: |
|
1844 | for mf in matched: | |
1845 | if mf.startswith(d): |
|
1845 | if mf.startswith(d): | |
1846 | break |
|
1846 | break | |
1847 | else: |
|
1847 | else: | |
1848 | fail(f, _("no match under directory!")) |
|
1848 | fail(f, _("no match under directory!")) | |
1849 | elif f not in self.dirstate: |
|
1849 | elif f not in self.dirstate: | |
1850 | fail(f, _("file not tracked!")) |
|
1850 | fail(f, _("file not tracked!")) | |
1851 |
|
1851 | |||
1852 | @unfilteredmethod |
|
1852 | @unfilteredmethod | |
1853 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1853 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1854 | editor=False, extra=None): |
|
1854 | editor=False, extra=None): | |
1855 | """Add a new revision to current repository. |
|
1855 | """Add a new revision to current repository. | |
1856 |
|
1856 | |||
1857 | Revision information is gathered from the working directory, |
|
1857 | Revision information is gathered from the working directory, | |
1858 | match can be used to filter the committed files. If editor is |
|
1858 | match can be used to filter the committed files. If editor is | |
1859 | supplied, it is called to get a commit message. |
|
1859 | supplied, it is called to get a commit message. | |
1860 | """ |
|
1860 | """ | |
1861 | if extra is None: |
|
1861 | if extra is None: | |
1862 | extra = {} |
|
1862 | extra = {} | |
1863 |
|
1863 | |||
1864 | def fail(f, msg): |
|
1864 | def fail(f, msg): | |
1865 | raise error.Abort('%s: %s' % (f, msg)) |
|
1865 | raise error.Abort('%s: %s' % (f, msg)) | |
1866 |
|
1866 | |||
1867 | if not match: |
|
1867 | if not match: | |
1868 | match = matchmod.always(self.root, '') |
|
1868 | match = matchmod.always(self.root, '') | |
1869 |
|
1869 | |||
1870 | if not force: |
|
1870 | if not force: | |
1871 | vdirs = [] |
|
1871 | vdirs = [] | |
1872 | match.explicitdir = vdirs.append |
|
1872 | match.explicitdir = vdirs.append | |
1873 | match.bad = fail |
|
1873 | match.bad = fail | |
1874 |
|
1874 | |||
1875 | wlock = lock = tr = None |
|
1875 | wlock = lock = tr = None | |
1876 | try: |
|
1876 | try: | |
1877 | wlock = self.wlock() |
|
1877 | wlock = self.wlock() | |
1878 | lock = self.lock() # for recent changelog (see issue4368) |
|
1878 | lock = self.lock() # for recent changelog (see issue4368) | |
1879 |
|
1879 | |||
1880 | wctx = self[None] |
|
1880 | wctx = self[None] | |
1881 | merge = len(wctx.parents()) > 1 |
|
1881 | merge = len(wctx.parents()) > 1 | |
1882 |
|
1882 | |||
1883 | if not force and merge and not match.always(): |
|
1883 | if not force and merge and not match.always(): | |
1884 | raise error.Abort(_('cannot partially commit a merge ' |
|
1884 | raise error.Abort(_('cannot partially commit a merge ' | |
1885 | '(do not specify files or patterns)')) |
|
1885 | '(do not specify files or patterns)')) | |
1886 |
|
1886 | |||
1887 | status = self.status(match=match, clean=force) |
|
1887 | status = self.status(match=match, clean=force) | |
1888 | if force: |
|
1888 | if force: | |
1889 | status.modified.extend(status.clean) # mq may commit clean files |
|
1889 | status.modified.extend(status.clean) # mq may commit clean files | |
1890 |
|
1890 | |||
1891 | # check subrepos |
|
1891 | # check subrepos | |
1892 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
1892 | subs, commitsubs, newstate = subrepoutil.precommit( | |
1893 | self.ui, wctx, status, match, force=force) |
|
1893 | self.ui, wctx, status, match, force=force) | |
1894 |
|
1894 | |||
1895 | # make sure all explicit patterns are matched |
|
1895 | # make sure all explicit patterns are matched | |
1896 | if not force: |
|
1896 | if not force: | |
1897 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
1897 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) | |
1898 |
|
1898 | |||
1899 | cctx = context.workingcommitctx(self, status, |
|
1899 | cctx = context.workingcommitctx(self, status, | |
1900 | text, user, date, extra) |
|
1900 | text, user, date, extra) | |
1901 |
|
1901 | |||
1902 | # internal config: ui.allowemptycommit |
|
1902 | # internal config: ui.allowemptycommit | |
1903 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1903 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
1904 | or extra.get('close') or merge or cctx.files() |
|
1904 | or extra.get('close') or merge or cctx.files() | |
1905 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1905 | or self.ui.configbool('ui', 'allowemptycommit')) | |
1906 | if not allowemptycommit: |
|
1906 | if not allowemptycommit: | |
1907 | return None |
|
1907 | return None | |
1908 |
|
1908 | |||
1909 | if merge and cctx.deleted(): |
|
1909 | if merge and cctx.deleted(): | |
1910 | raise error.Abort(_("cannot commit merge with missing files")) |
|
1910 | raise error.Abort(_("cannot commit merge with missing files")) | |
1911 |
|
1911 | |||
1912 | ms = mergemod.mergestate.read(self) |
|
1912 | ms = mergemod.mergestate.read(self) | |
1913 | mergeutil.checkunresolved(ms) |
|
1913 | mergeutil.checkunresolved(ms) | |
1914 |
|
1914 | |||
1915 | if editor: |
|
1915 | if editor: | |
1916 | cctx._text = editor(self, cctx, subs) |
|
1916 | cctx._text = editor(self, cctx, subs) | |
1917 | edited = (text != cctx._text) |
|
1917 | edited = (text != cctx._text) | |
1918 |
|
1918 | |||
1919 | # Save commit message in case this transaction gets rolled back |
|
1919 | # Save commit message in case this transaction gets rolled back | |
1920 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1920 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1921 | # the assumption that the user will use the same editor again. |
|
1921 | # the assumption that the user will use the same editor again. | |
1922 | msgfn = self.savecommitmessage(cctx._text) |
|
1922 | msgfn = self.savecommitmessage(cctx._text) | |
1923 |
|
1923 | |||
1924 | # commit subs and write new state |
|
1924 | # commit subs and write new state | |
1925 | if subs: |
|
1925 | if subs: | |
1926 | for s in sorted(commitsubs): |
|
1926 | for s in sorted(commitsubs): | |
1927 | sub = wctx.sub(s) |
|
1927 | sub = wctx.sub(s) | |
1928 | self.ui.status(_('committing subrepository %s\n') % |
|
1928 | self.ui.status(_('committing subrepository %s\n') % | |
1929 | subrepoutil.subrelpath(sub)) |
|
1929 | subrepoutil.subrelpath(sub)) | |
1930 | sr = sub.commit(cctx._text, user, date) |
|
1930 | sr = sub.commit(cctx._text, user, date) | |
1931 | newstate[s] = (newstate[s][0], sr) |
|
1931 | newstate[s] = (newstate[s][0], sr) | |
1932 | subrepoutil.writestate(self, newstate) |
|
1932 | subrepoutil.writestate(self, newstate) | |
1933 |
|
1933 | |||
1934 | p1, p2 = self.dirstate.parents() |
|
1934 | p1, p2 = self.dirstate.parents() | |
1935 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1935 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1936 | try: |
|
1936 | try: | |
1937 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1937 | self.hook("precommit", throw=True, parent1=hookp1, | |
1938 | parent2=hookp2) |
|
1938 | parent2=hookp2) | |
1939 | tr = self.transaction('commit') |
|
1939 | tr = self.transaction('commit') | |
1940 | ret = self.commitctx(cctx, True) |
|
1940 | ret = self.commitctx(cctx, True) | |
1941 | except: # re-raises |
|
1941 | except: # re-raises | |
1942 | if edited: |
|
1942 | if edited: | |
1943 | self.ui.write( |
|
1943 | self.ui.write( | |
1944 | _('note: commit message saved in %s\n') % msgfn) |
|
1944 | _('note: commit message saved in %s\n') % msgfn) | |
1945 | raise |
|
1945 | raise | |
1946 | # update bookmarks, dirstate and mergestate |
|
1946 | # update bookmarks, dirstate and mergestate | |
1947 | bookmarks.update(self, [p1, p2], ret) |
|
1947 | bookmarks.update(self, [p1, p2], ret) | |
1948 | cctx.markcommitted(ret) |
|
1948 | cctx.markcommitted(ret) | |
1949 | ms.reset() |
|
1949 | ms.reset() | |
1950 | tr.close() |
|
1950 | tr.close() | |
1951 |
|
1951 | |||
1952 | finally: |
|
1952 | finally: | |
1953 | lockmod.release(tr, lock, wlock) |
|
1953 | lockmod.release(tr, lock, wlock) | |
1954 |
|
1954 | |||
1955 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1955 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
1956 | # hack for command that use a temporary commit (eg: histedit) |
|
1956 | # hack for command that use a temporary commit (eg: histedit) | |
1957 | # temporary commit got stripped before hook release |
|
1957 | # temporary commit got stripped before hook release | |
1958 | if self.changelog.hasnode(ret): |
|
1958 | if self.changelog.hasnode(ret): | |
1959 | self.hook("commit", node=node, parent1=parent1, |
|
1959 | self.hook("commit", node=node, parent1=parent1, | |
1960 | parent2=parent2) |
|
1960 | parent2=parent2) | |
1961 | self._afterlock(commithook) |
|
1961 | self._afterlock(commithook) | |
1962 | return ret |
|
1962 | return ret | |
1963 |
|
1963 | |||
1964 | @unfilteredmethod |
|
1964 | @unfilteredmethod | |
1965 | def commitctx(self, ctx, error=False): |
|
1965 | def commitctx(self, ctx, error=False): | |
1966 | """Add a new revision to current repository. |
|
1966 | """Add a new revision to current repository. | |
1967 | Revision information is passed via the context argument. |
|
1967 | Revision information is passed via the context argument. | |
1968 | """ |
|
1968 | """ | |
1969 |
|
1969 | |||
1970 | tr = None |
|
1970 | tr = None | |
1971 | p1, p2 = ctx.p1(), ctx.p2() |
|
1971 | p1, p2 = ctx.p1(), ctx.p2() | |
1972 | user = ctx.user() |
|
1972 | user = ctx.user() | |
1973 |
|
1973 | |||
1974 | lock = self.lock() |
|
1974 | lock = self.lock() | |
1975 | try: |
|
1975 | try: | |
1976 | tr = self.transaction("commit") |
|
1976 | tr = self.transaction("commit") | |
1977 | trp = weakref.proxy(tr) |
|
1977 | trp = weakref.proxy(tr) | |
1978 |
|
1978 | |||
1979 | if ctx.manifestnode(): |
|
1979 | if ctx.manifestnode(): | |
1980 | # reuse an existing manifest revision |
|
1980 | # reuse an existing manifest revision | |
1981 | mn = ctx.manifestnode() |
|
1981 | mn = ctx.manifestnode() | |
1982 | files = ctx.files() |
|
1982 | files = ctx.files() | |
1983 | elif ctx.files(): |
|
1983 | elif ctx.files(): | |
1984 | m1ctx = p1.manifestctx() |
|
1984 | m1ctx = p1.manifestctx() | |
1985 | m2ctx = p2.manifestctx() |
|
1985 | m2ctx = p2.manifestctx() | |
1986 | mctx = m1ctx.copy() |
|
1986 | mctx = m1ctx.copy() | |
1987 |
|
1987 | |||
1988 | m = mctx.read() |
|
1988 | m = mctx.read() | |
1989 | m1 = m1ctx.read() |
|
1989 | m1 = m1ctx.read() | |
1990 | m2 = m2ctx.read() |
|
1990 | m2 = m2ctx.read() | |
1991 |
|
1991 | |||
1992 | # check in files |
|
1992 | # check in files | |
1993 | added = [] |
|
1993 | added = [] | |
1994 | changed = [] |
|
1994 | changed = [] | |
1995 | removed = list(ctx.removed()) |
|
1995 | removed = list(ctx.removed()) | |
1996 | linkrev = len(self) |
|
1996 | linkrev = len(self) | |
1997 | self.ui.note(_("committing files:\n")) |
|
1997 | self.ui.note(_("committing files:\n")) | |
1998 | for f in sorted(ctx.modified() + ctx.added()): |
|
1998 | for f in sorted(ctx.modified() + ctx.added()): | |
1999 | self.ui.note(f + "\n") |
|
1999 | self.ui.note(f + "\n") | |
2000 | try: |
|
2000 | try: | |
2001 | fctx = ctx[f] |
|
2001 | fctx = ctx[f] | |
2002 | if fctx is None: |
|
2002 | if fctx is None: | |
2003 | removed.append(f) |
|
2003 | removed.append(f) | |
2004 | else: |
|
2004 | else: | |
2005 | added.append(f) |
|
2005 | added.append(f) | |
2006 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
2006 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
2007 | trp, changed) |
|
2007 | trp, changed) | |
2008 | m.setflag(f, fctx.flags()) |
|
2008 | m.setflag(f, fctx.flags()) | |
2009 | except OSError as inst: |
|
2009 | except OSError as inst: | |
2010 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2010 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2011 | raise |
|
2011 | raise | |
2012 | except IOError as inst: |
|
2012 | except IOError as inst: | |
2013 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
2013 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
2014 | if error or errcode and errcode != errno.ENOENT: |
|
2014 | if error or errcode and errcode != errno.ENOENT: | |
2015 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2015 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2016 | raise |
|
2016 | raise | |
2017 |
|
2017 | |||
2018 | # update manifest |
|
2018 | # update manifest | |
2019 | self.ui.note(_("committing manifest\n")) |
|
2019 | self.ui.note(_("committing manifest\n")) | |
2020 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
2020 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
2021 | drop = [f for f in removed if f in m] |
|
2021 | drop = [f for f in removed if f in m] | |
2022 | for f in drop: |
|
2022 | for f in drop: | |
2023 | del m[f] |
|
2023 | del m[f] | |
2024 | mn = mctx.write(trp, linkrev, |
|
2024 | mn = mctx.write(trp, linkrev, | |
2025 | p1.manifestnode(), p2.manifestnode(), |
|
2025 | p1.manifestnode(), p2.manifestnode(), | |
2026 | added, drop) |
|
2026 | added, drop) | |
2027 | files = changed + removed |
|
2027 | files = changed + removed | |
2028 | else: |
|
2028 | else: | |
2029 | mn = p1.manifestnode() |
|
2029 | mn = p1.manifestnode() | |
2030 | files = [] |
|
2030 | files = [] | |
2031 |
|
2031 | |||
2032 | # update changelog |
|
2032 | # update changelog | |
2033 | self.ui.note(_("committing changelog\n")) |
|
2033 | self.ui.note(_("committing changelog\n")) | |
2034 | self.changelog.delayupdate(tr) |
|
2034 | self.changelog.delayupdate(tr) | |
2035 | n = self.changelog.add(mn, files, ctx.description(), |
|
2035 | n = self.changelog.add(mn, files, ctx.description(), | |
2036 | trp, p1.node(), p2.node(), |
|
2036 | trp, p1.node(), p2.node(), | |
2037 | user, ctx.date(), ctx.extra().copy()) |
|
2037 | user, ctx.date(), ctx.extra().copy()) | |
2038 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
2038 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
2039 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
2039 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
2040 | parent2=xp2) |
|
2040 | parent2=xp2) | |
2041 | # set the new commit is proper phase |
|
2041 | # set the new commit is proper phase | |
2042 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
2042 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
2043 | if targetphase: |
|
2043 | if targetphase: | |
2044 | # retract boundary do not alter parent changeset. |
|
2044 | # retract boundary do not alter parent changeset. | |
2045 | # if a parent have higher the resulting phase will |
|
2045 | # if a parent have higher the resulting phase will | |
2046 | # be compliant anyway |
|
2046 | # be compliant anyway | |
2047 | # |
|
2047 | # | |
2048 | # if minimal phase was 0 we don't need to retract anything |
|
2048 | # if minimal phase was 0 we don't need to retract anything | |
2049 | phases.registernew(self, tr, targetphase, [n]) |
|
2049 | phases.registernew(self, tr, targetphase, [n]) | |
2050 | tr.close() |
|
2050 | tr.close() | |
2051 | return n |
|
2051 | return n | |
2052 | finally: |
|
2052 | finally: | |
2053 | if tr: |
|
2053 | if tr: | |
2054 | tr.release() |
|
2054 | tr.release() | |
2055 | lock.release() |
|
2055 | lock.release() | |
2056 |
|
2056 | |||
2057 | @unfilteredmethod |
|
2057 | @unfilteredmethod | |
2058 | def destroying(self): |
|
2058 | def destroying(self): | |
2059 | '''Inform the repository that nodes are about to be destroyed. |
|
2059 | '''Inform the repository that nodes are about to be destroyed. | |
2060 | Intended for use by strip and rollback, so there's a common |
|
2060 | Intended for use by strip and rollback, so there's a common | |
2061 | place for anything that has to be done before destroying history. |
|
2061 | place for anything that has to be done before destroying history. | |
2062 |
|
2062 | |||
2063 | This is mostly useful for saving state that is in memory and waiting |
|
2063 | This is mostly useful for saving state that is in memory and waiting | |
2064 | to be flushed when the current lock is released. Because a call to |
|
2064 | to be flushed when the current lock is released. Because a call to | |
2065 | destroyed is imminent, the repo will be invalidated causing those |
|
2065 | destroyed is imminent, the repo will be invalidated causing those | |
2066 | changes to stay in memory (waiting for the next unlock), or vanish |
|
2066 | changes to stay in memory (waiting for the next unlock), or vanish | |
2067 | completely. |
|
2067 | completely. | |
2068 | ''' |
|
2068 | ''' | |
2069 | # When using the same lock to commit and strip, the phasecache is left |
|
2069 | # When using the same lock to commit and strip, the phasecache is left | |
2070 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
2070 | # dirty after committing. Then when we strip, the repo is invalidated, | |
2071 | # causing those changes to disappear. |
|
2071 | # causing those changes to disappear. | |
2072 | if '_phasecache' in vars(self): |
|
2072 | if '_phasecache' in vars(self): | |
2073 | self._phasecache.write() |
|
2073 | self._phasecache.write() | |
2074 |
|
2074 | |||
2075 | @unfilteredmethod |
|
2075 | @unfilteredmethod | |
2076 | def destroyed(self): |
|
2076 | def destroyed(self): | |
2077 | '''Inform the repository that nodes have been destroyed. |
|
2077 | '''Inform the repository that nodes have been destroyed. | |
2078 | Intended for use by strip and rollback, so there's a common |
|
2078 | Intended for use by strip and rollback, so there's a common | |
2079 | place for anything that has to be done after destroying history. |
|
2079 | place for anything that has to be done after destroying history. | |
2080 | ''' |
|
2080 | ''' | |
2081 | # When one tries to: |
|
2081 | # When one tries to: | |
2082 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
2082 | # 1) destroy nodes thus calling this method (e.g. strip) | |
2083 | # 2) use phasecache somewhere (e.g. commit) |
|
2083 | # 2) use phasecache somewhere (e.g. commit) | |
2084 | # |
|
2084 | # | |
2085 | # then 2) will fail because the phasecache contains nodes that were |
|
2085 | # then 2) will fail because the phasecache contains nodes that were | |
2086 | # removed. We can either remove phasecache from the filecache, |
|
2086 | # removed. We can either remove phasecache from the filecache, | |
2087 | # causing it to reload next time it is accessed, or simply filter |
|
2087 | # causing it to reload next time it is accessed, or simply filter | |
2088 | # the removed nodes now and write the updated cache. |
|
2088 | # the removed nodes now and write the updated cache. | |
2089 | self._phasecache.filterunknown(self) |
|
2089 | self._phasecache.filterunknown(self) | |
2090 | self._phasecache.write() |
|
2090 | self._phasecache.write() | |
2091 |
|
2091 | |||
2092 | # refresh all repository caches |
|
2092 | # refresh all repository caches | |
2093 | self.updatecaches() |
|
2093 | self.updatecaches() | |
2094 |
|
2094 | |||
2095 | # Ensure the persistent tag cache is updated. Doing it now |
|
2095 | # Ensure the persistent tag cache is updated. Doing it now | |
2096 | # means that the tag cache only has to worry about destroyed |
|
2096 | # means that the tag cache only has to worry about destroyed | |
2097 | # heads immediately after a strip/rollback. That in turn |
|
2097 | # heads immediately after a strip/rollback. That in turn | |
2098 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
2098 | # guarantees that "cachetip == currenttip" (comparing both rev | |
2099 | # and node) always means no nodes have been added or destroyed. |
|
2099 | # and node) always means no nodes have been added or destroyed. | |
2100 |
|
2100 | |||
2101 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
2101 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
2102 | # head, refresh the tag cache, then immediately add a new head. |
|
2102 | # head, refresh the tag cache, then immediately add a new head. | |
2103 | # But I think doing it this way is necessary for the "instant |
|
2103 | # But I think doing it this way is necessary for the "instant | |
2104 | # tag cache retrieval" case to work. |
|
2104 | # tag cache retrieval" case to work. | |
2105 | self.invalidate() |
|
2105 | self.invalidate() | |
2106 |
|
2106 | |||
2107 | def status(self, node1='.', node2=None, match=None, |
|
2107 | def status(self, node1='.', node2=None, match=None, | |
2108 | ignored=False, clean=False, unknown=False, |
|
2108 | ignored=False, clean=False, unknown=False, | |
2109 | listsubrepos=False): |
|
2109 | listsubrepos=False): | |
2110 | '''a convenience method that calls node1.status(node2)''' |
|
2110 | '''a convenience method that calls node1.status(node2)''' | |
2111 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
2111 | return self[node1].status(node2, match, ignored, clean, unknown, | |
2112 | listsubrepos) |
|
2112 | listsubrepos) | |
2113 |
|
2113 | |||
2114 | def addpostdsstatus(self, ps): |
|
2114 | def addpostdsstatus(self, ps): | |
2115 | """Add a callback to run within the wlock, at the point at which status |
|
2115 | """Add a callback to run within the wlock, at the point at which status | |
2116 | fixups happen. |
|
2116 | fixups happen. | |
2117 |
|
2117 | |||
2118 | On status completion, callback(wctx, status) will be called with the |
|
2118 | On status completion, callback(wctx, status) will be called with the | |
2119 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
2119 | wlock held, unless the dirstate has changed from underneath or the wlock | |
2120 | couldn't be grabbed. |
|
2120 | couldn't be grabbed. | |
2121 |
|
2121 | |||
2122 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
2122 | Callbacks should not capture and use a cached copy of the dirstate -- | |
2123 | it might change in the meanwhile. Instead, they should access the |
|
2123 | it might change in the meanwhile. Instead, they should access the | |
2124 | dirstate via wctx.repo().dirstate. |
|
2124 | dirstate via wctx.repo().dirstate. | |
2125 |
|
2125 | |||
2126 | This list is emptied out after each status run -- extensions should |
|
2126 | This list is emptied out after each status run -- extensions should | |
2127 | make sure it adds to this list each time dirstate.status is called. |
|
2127 | make sure it adds to this list each time dirstate.status is called. | |
2128 | Extensions should also make sure they don't call this for statuses |
|
2128 | Extensions should also make sure they don't call this for statuses | |
2129 | that don't involve the dirstate. |
|
2129 | that don't involve the dirstate. | |
2130 | """ |
|
2130 | """ | |
2131 |
|
2131 | |||
2132 | # The list is located here for uniqueness reasons -- it is actually |
|
2132 | # The list is located here for uniqueness reasons -- it is actually | |
2133 | # managed by the workingctx, but that isn't unique per-repo. |
|
2133 | # managed by the workingctx, but that isn't unique per-repo. | |
2134 | self._postdsstatus.append(ps) |
|
2134 | self._postdsstatus.append(ps) | |
2135 |
|
2135 | |||
2136 | def postdsstatus(self): |
|
2136 | def postdsstatus(self): | |
2137 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
2137 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
2138 | return self._postdsstatus |
|
2138 | return self._postdsstatus | |
2139 |
|
2139 | |||
2140 | def clearpostdsstatus(self): |
|
2140 | def clearpostdsstatus(self): | |
2141 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
2141 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
2142 | del self._postdsstatus[:] |
|
2142 | del self._postdsstatus[:] | |
2143 |
|
2143 | |||
2144 | def heads(self, start=None): |
|
2144 | def heads(self, start=None): | |
2145 | if start is None: |
|
2145 | if start is None: | |
2146 | cl = self.changelog |
|
2146 | cl = self.changelog | |
2147 | headrevs = reversed(cl.headrevs()) |
|
2147 | headrevs = reversed(cl.headrevs()) | |
2148 | return [cl.node(rev) for rev in headrevs] |
|
2148 | return [cl.node(rev) for rev in headrevs] | |
2149 |
|
2149 | |||
2150 | heads = self.changelog.heads(start) |
|
2150 | heads = self.changelog.heads(start) | |
2151 | # sort the output in rev descending order |
|
2151 | # sort the output in rev descending order | |
2152 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
2152 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
2153 |
|
2153 | |||
2154 | def branchheads(self, branch=None, start=None, closed=False): |
|
2154 | def branchheads(self, branch=None, start=None, closed=False): | |
2155 | '''return a (possibly filtered) list of heads for the given branch |
|
2155 | '''return a (possibly filtered) list of heads for the given branch | |
2156 |
|
2156 | |||
2157 | Heads are returned in topological order, from newest to oldest. |
|
2157 | Heads are returned in topological order, from newest to oldest. | |
2158 | If branch is None, use the dirstate branch. |
|
2158 | If branch is None, use the dirstate branch. | |
2159 | If start is not None, return only heads reachable from start. |
|
2159 | If start is not None, return only heads reachable from start. | |
2160 | If closed is True, return heads that are marked as closed as well. |
|
2160 | If closed is True, return heads that are marked as closed as well. | |
2161 | ''' |
|
2161 | ''' | |
2162 | if branch is None: |
|
2162 | if branch is None: | |
2163 | branch = self[None].branch() |
|
2163 | branch = self[None].branch() | |
2164 | branches = self.branchmap() |
|
2164 | branches = self.branchmap() | |
2165 | if branch not in branches: |
|
2165 | if branch not in branches: | |
2166 | return [] |
|
2166 | return [] | |
2167 | # the cache returns heads ordered lowest to highest |
|
2167 | # the cache returns heads ordered lowest to highest | |
2168 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
2168 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
2169 | if start is not None: |
|
2169 | if start is not None: | |
2170 | # filter out the heads that cannot be reached from startrev |
|
2170 | # filter out the heads that cannot be reached from startrev | |
2171 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
2171 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
2172 | bheads = [h for h in bheads if h in fbheads] |
|
2172 | bheads = [h for h in bheads if h in fbheads] | |
2173 | return bheads |
|
2173 | return bheads | |
2174 |
|
2174 | |||
2175 | def branches(self, nodes): |
|
2175 | def branches(self, nodes): | |
2176 | if not nodes: |
|
2176 | if not nodes: | |
2177 | nodes = [self.changelog.tip()] |
|
2177 | nodes = [self.changelog.tip()] | |
2178 | b = [] |
|
2178 | b = [] | |
2179 | for n in nodes: |
|
2179 | for n in nodes: | |
2180 | t = n |
|
2180 | t = n | |
2181 | while True: |
|
2181 | while True: | |
2182 | p = self.changelog.parents(n) |
|
2182 | p = self.changelog.parents(n) | |
2183 | if p[1] != nullid or p[0] == nullid: |
|
2183 | if p[1] != nullid or p[0] == nullid: | |
2184 | b.append((t, n, p[0], p[1])) |
|
2184 | b.append((t, n, p[0], p[1])) | |
2185 | break |
|
2185 | break | |
2186 | n = p[0] |
|
2186 | n = p[0] | |
2187 | return b |
|
2187 | return b | |
2188 |
|
2188 | |||
2189 | def between(self, pairs): |
|
2189 | def between(self, pairs): | |
2190 | r = [] |
|
2190 | r = [] | |
2191 |
|
2191 | |||
2192 | for top, bottom in pairs: |
|
2192 | for top, bottom in pairs: | |
2193 | n, l, i = top, [], 0 |
|
2193 | n, l, i = top, [], 0 | |
2194 | f = 1 |
|
2194 | f = 1 | |
2195 |
|
2195 | |||
2196 | while n != bottom and n != nullid: |
|
2196 | while n != bottom and n != nullid: | |
2197 | p = self.changelog.parents(n)[0] |
|
2197 | p = self.changelog.parents(n)[0] | |
2198 | if i == f: |
|
2198 | if i == f: | |
2199 | l.append(n) |
|
2199 | l.append(n) | |
2200 | f = f * 2 |
|
2200 | f = f * 2 | |
2201 | n = p |
|
2201 | n = p | |
2202 | i += 1 |
|
2202 | i += 1 | |
2203 |
|
2203 | |||
2204 | r.append(l) |
|
2204 | r.append(l) | |
2205 |
|
2205 | |||
2206 | return r |
|
2206 | return r | |
2207 |
|
2207 | |||
2208 | def checkpush(self, pushop): |
|
2208 | def checkpush(self, pushop): | |
2209 | """Extensions can override this function if additional checks have |
|
2209 | """Extensions can override this function if additional checks have | |
2210 | to be performed before pushing, or call it if they override push |
|
2210 | to be performed before pushing, or call it if they override push | |
2211 | command. |
|
2211 | command. | |
2212 | """ |
|
2212 | """ | |
2213 |
|
2213 | |||
2214 | @unfilteredpropertycache |
|
2214 | @unfilteredpropertycache | |
2215 | def prepushoutgoinghooks(self): |
|
2215 | def prepushoutgoinghooks(self): | |
2216 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
2216 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
2217 | methods, which are called before pushing changesets. |
|
2217 | methods, which are called before pushing changesets. | |
2218 | """ |
|
2218 | """ | |
2219 | return util.hooks() |
|
2219 | return util.hooks() | |
2220 |
|
2220 | |||
2221 | def pushkey(self, namespace, key, old, new): |
|
2221 | def pushkey(self, namespace, key, old, new): | |
2222 | try: |
|
2222 | try: | |
2223 | tr = self.currenttransaction() |
|
2223 | tr = self.currenttransaction() | |
2224 | hookargs = {} |
|
2224 | hookargs = {} | |
2225 | if tr is not None: |
|
2225 | if tr is not None: | |
2226 | hookargs.update(tr.hookargs) |
|
2226 | hookargs.update(tr.hookargs) | |
2227 | hookargs = pycompat.strkwargs(hookargs) |
|
2227 | hookargs = pycompat.strkwargs(hookargs) | |
2228 | hookargs[r'namespace'] = namespace |
|
2228 | hookargs[r'namespace'] = namespace | |
2229 | hookargs[r'key'] = key |
|
2229 | hookargs[r'key'] = key | |
2230 | hookargs[r'old'] = old |
|
2230 | hookargs[r'old'] = old | |
2231 | hookargs[r'new'] = new |
|
2231 | hookargs[r'new'] = new | |
2232 | self.hook('prepushkey', throw=True, **hookargs) |
|
2232 | self.hook('prepushkey', throw=True, **hookargs) | |
2233 | except error.HookAbort as exc: |
|
2233 | except error.HookAbort as exc: | |
2234 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
2234 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
2235 | if exc.hint: |
|
2235 | if exc.hint: | |
2236 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
2236 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
2237 | return False |
|
2237 | return False | |
2238 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
2238 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
2239 | ret = pushkey.push(self, namespace, key, old, new) |
|
2239 | ret = pushkey.push(self, namespace, key, old, new) | |
2240 | def runhook(): |
|
2240 | def runhook(): | |
2241 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2241 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
2242 | ret=ret) |
|
2242 | ret=ret) | |
2243 | self._afterlock(runhook) |
|
2243 | self._afterlock(runhook) | |
2244 | return ret |
|
2244 | return ret | |
2245 |
|
2245 | |||
2246 | def listkeys(self, namespace): |
|
2246 | def listkeys(self, namespace): | |
2247 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2247 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
2248 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
2248 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
2249 | values = pushkey.list(self, namespace) |
|
2249 | values = pushkey.list(self, namespace) | |
2250 | self.hook('listkeys', namespace=namespace, values=values) |
|
2250 | self.hook('listkeys', namespace=namespace, values=values) | |
2251 | return values |
|
2251 | return values | |
2252 |
|
2252 | |||
2253 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2253 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
2254 | '''used to test argument passing over the wire''' |
|
2254 | '''used to test argument passing over the wire''' | |
2255 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
2255 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
2256 | pycompat.bytestr(four), |
|
2256 | pycompat.bytestr(four), | |
2257 | pycompat.bytestr(five)) |
|
2257 | pycompat.bytestr(five)) | |
2258 |
|
2258 | |||
2259 | def savecommitmessage(self, text): |
|
2259 | def savecommitmessage(self, text): | |
2260 | fp = self.vfs('last-message.txt', 'wb') |
|
2260 | fp = self.vfs('last-message.txt', 'wb') | |
2261 | try: |
|
2261 | try: | |
2262 | fp.write(text) |
|
2262 | fp.write(text) | |
2263 | finally: |
|
2263 | finally: | |
2264 | fp.close() |
|
2264 | fp.close() | |
2265 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
2265 | return self.pathto(fp.name[len(self.root) + 1:]) | |
2266 |
|
2266 | |||
2267 | # used to avoid circular references so destructors work |
|
2267 | # used to avoid circular references so destructors work | |
2268 | def aftertrans(files): |
|
2268 | def aftertrans(files): | |
2269 | renamefiles = [tuple(t) for t in files] |
|
2269 | renamefiles = [tuple(t) for t in files] | |
2270 | def a(): |
|
2270 | def a(): | |
2271 | for vfs, src, dest in renamefiles: |
|
2271 | for vfs, src, dest in renamefiles: | |
2272 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
2272 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
2273 | # leaving both src and dest on disk. delete dest to make sure |
|
2273 | # leaving both src and dest on disk. delete dest to make sure | |
2274 | # the rename couldn't be such a no-op. |
|
2274 | # the rename couldn't be such a no-op. | |
2275 | vfs.tryunlink(dest) |
|
2275 | vfs.tryunlink(dest) | |
2276 | try: |
|
2276 | try: | |
2277 | vfs.rename(src, dest) |
|
2277 | vfs.rename(src, dest) | |
2278 | except OSError: # journal file does not yet exist |
|
2278 | except OSError: # journal file does not yet exist | |
2279 | pass |
|
2279 | pass | |
2280 | return a |
|
2280 | return a | |
2281 |
|
2281 | |||
2282 | def undoname(fn): |
|
2282 | def undoname(fn): | |
2283 | base, name = os.path.split(fn) |
|
2283 | base, name = os.path.split(fn) | |
2284 | assert name.startswith('journal') |
|
2284 | assert name.startswith('journal') | |
2285 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2285 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
2286 |
|
2286 | |||
2287 | def instance(ui, path, create): |
|
2287 | def instance(ui, path, create): | |
2288 | return localrepository(ui, util.urllocalpath(path), create) |
|
2288 | return localrepository(ui, util.urllocalpath(path), create) | |
2289 |
|
2289 | |||
2290 | def islocal(path): |
|
2290 | def islocal(path): | |
2291 | return True |
|
2291 | return True | |
2292 |
|
2292 | |||
2293 | def newreporequirements(repo): |
|
2293 | def newreporequirements(repo): | |
2294 | """Determine the set of requirements for a new local repository. |
|
2294 | """Determine the set of requirements for a new local repository. | |
2295 |
|
2295 | |||
2296 | Extensions can wrap this function to specify custom requirements for |
|
2296 | Extensions can wrap this function to specify custom requirements for | |
2297 | new repositories. |
|
2297 | new repositories. | |
2298 | """ |
|
2298 | """ | |
2299 | ui = repo.ui |
|
2299 | ui = repo.ui | |
2300 | requirements = {'revlogv1'} |
|
2300 | requirements = {'revlogv1'} | |
2301 | if ui.configbool('format', 'usestore'): |
|
2301 | if ui.configbool('format', 'usestore'): | |
2302 | requirements.add('store') |
|
2302 | requirements.add('store') | |
2303 | if ui.configbool('format', 'usefncache'): |
|
2303 | if ui.configbool('format', 'usefncache'): | |
2304 | requirements.add('fncache') |
|
2304 | requirements.add('fncache') | |
2305 | if ui.configbool('format', 'dotencode'): |
|
2305 | if ui.configbool('format', 'dotencode'): | |
2306 | requirements.add('dotencode') |
|
2306 | requirements.add('dotencode') | |
2307 |
|
2307 | |||
2308 | compengine = ui.config('experimental', 'format.compression') |
|
2308 | compengine = ui.config('experimental', 'format.compression') | |
2309 | if compengine not in util.compengines: |
|
2309 | if compengine not in util.compengines: | |
2310 | raise error.Abort(_('compression engine %s defined by ' |
|
2310 | raise error.Abort(_('compression engine %s defined by ' | |
2311 | 'experimental.format.compression not available') % |
|
2311 | 'experimental.format.compression not available') % | |
2312 | compengine, |
|
2312 | compengine, | |
2313 | hint=_('run "hg debuginstall" to list available ' |
|
2313 | hint=_('run "hg debuginstall" to list available ' | |
2314 | 'compression engines')) |
|
2314 | 'compression engines')) | |
2315 |
|
2315 | |||
2316 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2316 | # zlib is the historical default and doesn't need an explicit requirement. | |
2317 | if compengine != 'zlib': |
|
2317 | if compengine != 'zlib': | |
2318 | requirements.add('exp-compression-%s' % compengine) |
|
2318 | requirements.add('exp-compression-%s' % compengine) | |
2319 |
|
2319 | |||
2320 | if scmutil.gdinitconfig(ui): |
|
2320 | if scmutil.gdinitconfig(ui): | |
2321 | requirements.add('generaldelta') |
|
2321 | requirements.add('generaldelta') | |
2322 | if ui.configbool('experimental', 'treemanifest'): |
|
2322 | if ui.configbool('experimental', 'treemanifest'): | |
2323 | requirements.add('treemanifest') |
|
2323 | requirements.add('treemanifest') | |
2324 |
|
2324 | |||
2325 | revlogv2 = ui.config('experimental', 'revlogv2') |
|
2325 | revlogv2 = ui.config('experimental', 'revlogv2') | |
2326 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': |
|
2326 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': | |
2327 | requirements.remove('revlogv1') |
|
2327 | requirements.remove('revlogv1') | |
2328 | # generaldelta is implied by revlogv2. |
|
2328 | # generaldelta is implied by revlogv2. | |
2329 | requirements.discard('generaldelta') |
|
2329 | requirements.discard('generaldelta') | |
2330 | requirements.add(REVLOGV2_REQUIREMENT) |
|
2330 | requirements.add(REVLOGV2_REQUIREMENT) | |
2331 |
|
2331 | |||
2332 | return requirements |
|
2332 | return requirements |
General Comments 0
You need to be logged in to leave comments.
Login now