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