Show More
@@ -1,2332 +1,2333 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import hashlib |
|
11 | import hashlib | |
12 | import os |
|
12 | import os | |
13 | import random |
|
13 | import random | |
14 | import time |
|
14 | import time | |
15 | import weakref |
|
15 | import weakref | |
16 |
|
16 | |||
17 | from .i18n import _ |
|
17 | from .i18n import _ | |
18 | from .node import ( |
|
18 | from .node import ( | |
19 | hex, |
|
19 | hex, | |
20 | nullid, |
|
20 | nullid, | |
21 | short, |
|
21 | short, | |
22 | ) |
|
22 | ) | |
23 | from . import ( |
|
23 | from . import ( | |
24 | bookmarks, |
|
24 | bookmarks, | |
25 | branchmap, |
|
25 | branchmap, | |
26 | bundle2, |
|
26 | bundle2, | |
27 | changegroup, |
|
27 | changegroup, | |
28 | changelog, |
|
28 | changelog, | |
29 | color, |
|
29 | color, | |
30 | context, |
|
30 | context, | |
31 | dirstate, |
|
31 | dirstate, | |
32 | dirstateguard, |
|
32 | dirstateguard, | |
33 | discovery, |
|
33 | discovery, | |
34 | encoding, |
|
34 | encoding, | |
35 | error, |
|
35 | error, | |
36 | exchange, |
|
36 | exchange, | |
37 | extensions, |
|
37 | extensions, | |
38 | filelog, |
|
38 | filelog, | |
39 | hook, |
|
39 | hook, | |
40 | lock as lockmod, |
|
40 | lock as lockmod, | |
41 | manifest, |
|
41 | manifest, | |
42 | match as matchmod, |
|
42 | match as matchmod, | |
43 | merge as mergemod, |
|
43 | merge as mergemod, | |
44 | mergeutil, |
|
44 | mergeutil, | |
45 | namespaces, |
|
45 | namespaces, | |
46 | narrowspec, |
|
46 | narrowspec, | |
47 | obsolete, |
|
47 | obsolete, | |
48 | pathutil, |
|
48 | pathutil, | |
49 | peer, |
|
49 | peer, | |
50 | phases, |
|
50 | phases, | |
51 | pushkey, |
|
51 | pushkey, | |
52 | pycompat, |
|
52 | pycompat, | |
53 | repository, |
|
53 | repository, | |
54 | repoview, |
|
54 | repoview, | |
55 | revset, |
|
55 | revset, | |
56 | revsetlang, |
|
56 | revsetlang, | |
57 | scmutil, |
|
57 | scmutil, | |
58 | sparse, |
|
58 | sparse, | |
59 | store, |
|
59 | store, | |
60 | subrepoutil, |
|
60 | subrepoutil, | |
61 | tags as tagsmod, |
|
61 | tags as tagsmod, | |
62 | transaction, |
|
62 | transaction, | |
63 | txnutil, |
|
63 | txnutil, | |
64 | util, |
|
64 | util, | |
65 | vfs as vfsmod, |
|
65 | vfs as vfsmod, | |
66 | ) |
|
66 | ) | |
67 | from .utils import ( |
|
67 | from .utils import ( | |
68 | procutil, |
|
68 | procutil, | |
69 | stringutil, |
|
69 | stringutil, | |
70 | ) |
|
70 | ) | |
71 |
|
71 | |||
72 | release = lockmod.release |
|
72 | release = lockmod.release | |
73 | urlerr = util.urlerr |
|
73 | urlerr = util.urlerr | |
74 | urlreq = util.urlreq |
|
74 | urlreq = util.urlreq | |
75 |
|
75 | |||
76 | # set of (path, vfs-location) tuples. vfs-location is: |
|
76 | # set of (path, vfs-location) tuples. vfs-location is: | |
77 | # - 'plain for vfs relative paths |
|
77 | # - 'plain for vfs relative paths | |
78 | # - '' for svfs relative paths |
|
78 | # - '' for svfs relative paths | |
79 | _cachedfiles = set() |
|
79 | _cachedfiles = set() | |
80 |
|
80 | |||
81 | class _basefilecache(scmutil.filecache): |
|
81 | class _basefilecache(scmutil.filecache): | |
82 | """All filecache usage on repo are done for logic that should be unfiltered |
|
82 | """All filecache usage on repo are done for logic that should be unfiltered | |
83 | """ |
|
83 | """ | |
84 | def __get__(self, repo, type=None): |
|
84 | def __get__(self, repo, type=None): | |
85 | if repo is None: |
|
85 | if repo is None: | |
86 | return self |
|
86 | return self | |
87 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) |
|
87 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) | |
88 | def __set__(self, repo, value): |
|
88 | def __set__(self, repo, value): | |
89 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) |
|
89 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) | |
90 | def __delete__(self, repo): |
|
90 | def __delete__(self, repo): | |
91 | return super(_basefilecache, self).__delete__(repo.unfiltered()) |
|
91 | return super(_basefilecache, self).__delete__(repo.unfiltered()) | |
92 |
|
92 | |||
93 | class repofilecache(_basefilecache): |
|
93 | class repofilecache(_basefilecache): | |
94 | """filecache for files in .hg but outside of .hg/store""" |
|
94 | """filecache for files in .hg but outside of .hg/store""" | |
95 | def __init__(self, *paths): |
|
95 | def __init__(self, *paths): | |
96 | super(repofilecache, self).__init__(*paths) |
|
96 | super(repofilecache, self).__init__(*paths) | |
97 | for path in paths: |
|
97 | for path in paths: | |
98 | _cachedfiles.add((path, 'plain')) |
|
98 | _cachedfiles.add((path, 'plain')) | |
99 |
|
99 | |||
100 | def join(self, obj, fname): |
|
100 | def join(self, obj, fname): | |
101 | return obj.vfs.join(fname) |
|
101 | return obj.vfs.join(fname) | |
102 |
|
102 | |||
103 | class storecache(_basefilecache): |
|
103 | class storecache(_basefilecache): | |
104 | """filecache for files in the store""" |
|
104 | """filecache for files in the store""" | |
105 | def __init__(self, *paths): |
|
105 | def __init__(self, *paths): | |
106 | super(storecache, self).__init__(*paths) |
|
106 | super(storecache, self).__init__(*paths) | |
107 | for path in paths: |
|
107 | for path in paths: | |
108 | _cachedfiles.add((path, '')) |
|
108 | _cachedfiles.add((path, '')) | |
109 |
|
109 | |||
110 | def join(self, obj, fname): |
|
110 | def join(self, obj, fname): | |
111 | return obj.sjoin(fname) |
|
111 | return obj.sjoin(fname) | |
112 |
|
112 | |||
113 | def isfilecached(repo, name): |
|
113 | def isfilecached(repo, name): | |
114 | """check if a repo has already cached "name" filecache-ed property |
|
114 | """check if a repo has already cached "name" filecache-ed property | |
115 |
|
115 | |||
116 | This returns (cachedobj-or-None, iscached) tuple. |
|
116 | This returns (cachedobj-or-None, iscached) tuple. | |
117 | """ |
|
117 | """ | |
118 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
118 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
119 | if not cacheentry: |
|
119 | if not cacheentry: | |
120 | return None, False |
|
120 | return None, False | |
121 | return cacheentry.obj, True |
|
121 | return cacheentry.obj, True | |
122 |
|
122 | |||
123 | class unfilteredpropertycache(util.propertycache): |
|
123 | class unfilteredpropertycache(util.propertycache): | |
124 | """propertycache that apply to unfiltered repo only""" |
|
124 | """propertycache that apply to unfiltered repo only""" | |
125 |
|
125 | |||
126 | def __get__(self, repo, type=None): |
|
126 | def __get__(self, repo, type=None): | |
127 | unfi = repo.unfiltered() |
|
127 | unfi = repo.unfiltered() | |
128 | if unfi is repo: |
|
128 | if unfi is repo: | |
129 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
129 | return super(unfilteredpropertycache, self).__get__(unfi) | |
130 | return getattr(unfi, self.name) |
|
130 | return getattr(unfi, self.name) | |
131 |
|
131 | |||
132 | class filteredpropertycache(util.propertycache): |
|
132 | class filteredpropertycache(util.propertycache): | |
133 | """propertycache that must take filtering in account""" |
|
133 | """propertycache that must take filtering in account""" | |
134 |
|
134 | |||
135 | def cachevalue(self, obj, value): |
|
135 | def cachevalue(self, obj, value): | |
136 | object.__setattr__(obj, self.name, value) |
|
136 | object.__setattr__(obj, self.name, value) | |
137 |
|
137 | |||
138 |
|
138 | |||
139 | def hasunfilteredcache(repo, name): |
|
139 | def hasunfilteredcache(repo, name): | |
140 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
140 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
141 | return name in vars(repo.unfiltered()) |
|
141 | return name in vars(repo.unfiltered()) | |
142 |
|
142 | |||
143 | def unfilteredmethod(orig): |
|
143 | def unfilteredmethod(orig): | |
144 | """decorate method that always need to be run on unfiltered version""" |
|
144 | """decorate method that always need to be run on unfiltered version""" | |
145 | def wrapper(repo, *args, **kwargs): |
|
145 | def wrapper(repo, *args, **kwargs): | |
146 | return orig(repo.unfiltered(), *args, **kwargs) |
|
146 | return orig(repo.unfiltered(), *args, **kwargs) | |
147 | return wrapper |
|
147 | return wrapper | |
148 |
|
148 | |||
149 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
149 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
150 | 'unbundle'} |
|
150 | 'unbundle'} | |
151 | legacycaps = moderncaps.union({'changegroupsubset'}) |
|
151 | legacycaps = moderncaps.union({'changegroupsubset'}) | |
152 |
|
152 | |||
153 | class localpeer(repository.peer): |
|
153 | class localpeer(repository.peer): | |
154 | '''peer for a local repo; reflects only the most recent API''' |
|
154 | '''peer for a local repo; reflects only the most recent API''' | |
155 |
|
155 | |||
156 | def __init__(self, repo, caps=None): |
|
156 | def __init__(self, repo, caps=None): | |
157 | super(localpeer, self).__init__() |
|
157 | super(localpeer, self).__init__() | |
158 |
|
158 | |||
159 | if caps is None: |
|
159 | if caps is None: | |
160 | caps = moderncaps.copy() |
|
160 | caps = moderncaps.copy() | |
161 | self._repo = repo.filtered('served') |
|
161 | self._repo = repo.filtered('served') | |
162 | self._ui = repo.ui |
|
162 | self._ui = repo.ui | |
163 | self._caps = repo._restrictcapabilities(caps) |
|
163 | self._caps = repo._restrictcapabilities(caps) | |
164 |
|
164 | |||
165 | # Begin of _basepeer interface. |
|
165 | # Begin of _basepeer interface. | |
166 |
|
166 | |||
167 | @util.propertycache |
|
167 | @util.propertycache | |
168 | def ui(self): |
|
168 | def ui(self): | |
169 | return self._ui |
|
169 | return self._ui | |
170 |
|
170 | |||
171 | def url(self): |
|
171 | def url(self): | |
172 | return self._repo.url() |
|
172 | return self._repo.url() | |
173 |
|
173 | |||
174 | def local(self): |
|
174 | def local(self): | |
175 | return self._repo |
|
175 | return self._repo | |
176 |
|
176 | |||
177 | def peer(self): |
|
177 | def peer(self): | |
178 | return self |
|
178 | return self | |
179 |
|
179 | |||
180 | def canpush(self): |
|
180 | def canpush(self): | |
181 | return True |
|
181 | return True | |
182 |
|
182 | |||
183 | def close(self): |
|
183 | def close(self): | |
184 | self._repo.close() |
|
184 | self._repo.close() | |
185 |
|
185 | |||
186 | # End of _basepeer interface. |
|
186 | # End of _basepeer interface. | |
187 |
|
187 | |||
188 | # Begin of _basewirecommands interface. |
|
188 | # Begin of _basewirecommands interface. | |
189 |
|
189 | |||
190 | def branchmap(self): |
|
190 | def branchmap(self): | |
191 | return self._repo.branchmap() |
|
191 | return self._repo.branchmap() | |
192 |
|
192 | |||
193 | def capabilities(self): |
|
193 | def capabilities(self): | |
194 | return self._caps |
|
194 | return self._caps | |
195 |
|
195 | |||
196 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
196 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
197 | """Used to test argument passing over the wire""" |
|
197 | """Used to test argument passing over the wire""" | |
198 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
198 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
199 | pycompat.bytestr(four), |
|
199 | pycompat.bytestr(four), | |
200 | pycompat.bytestr(five)) |
|
200 | pycompat.bytestr(five)) | |
201 |
|
201 | |||
202 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
202 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
203 | **kwargs): |
|
203 | **kwargs): | |
204 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
204 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, | |
205 | common=common, bundlecaps=bundlecaps, |
|
205 | common=common, bundlecaps=bundlecaps, | |
206 | **kwargs)[1] |
|
206 | **kwargs)[1] | |
207 | cb = util.chunkbuffer(chunks) |
|
207 | cb = util.chunkbuffer(chunks) | |
208 |
|
208 | |||
209 | if exchange.bundle2requested(bundlecaps): |
|
209 | if exchange.bundle2requested(bundlecaps): | |
210 | # When requesting a bundle2, getbundle returns a stream to make the |
|
210 | # When requesting a bundle2, getbundle returns a stream to make the | |
211 | # wire level function happier. We need to build a proper object |
|
211 | # wire level function happier. We need to build a proper object | |
212 | # from it in local peer. |
|
212 | # from it in local peer. | |
213 | return bundle2.getunbundler(self.ui, cb) |
|
213 | return bundle2.getunbundler(self.ui, cb) | |
214 | else: |
|
214 | else: | |
215 | return changegroup.getunbundler('01', cb, None) |
|
215 | return changegroup.getunbundler('01', cb, None) | |
216 |
|
216 | |||
217 | def heads(self): |
|
217 | def heads(self): | |
218 | return self._repo.heads() |
|
218 | return self._repo.heads() | |
219 |
|
219 | |||
220 | def known(self, nodes): |
|
220 | def known(self, nodes): | |
221 | return self._repo.known(nodes) |
|
221 | return self._repo.known(nodes) | |
222 |
|
222 | |||
223 | def listkeys(self, namespace): |
|
223 | def listkeys(self, namespace): | |
224 | return self._repo.listkeys(namespace) |
|
224 | return self._repo.listkeys(namespace) | |
225 |
|
225 | |||
226 | def lookup(self, key): |
|
226 | def lookup(self, key): | |
227 | return self._repo.lookup(key) |
|
227 | return self._repo.lookup(key) | |
228 |
|
228 | |||
229 | def pushkey(self, namespace, key, old, new): |
|
229 | def pushkey(self, namespace, key, old, new): | |
230 | return self._repo.pushkey(namespace, key, old, new) |
|
230 | return self._repo.pushkey(namespace, key, old, new) | |
231 |
|
231 | |||
232 | def stream_out(self): |
|
232 | def stream_out(self): | |
233 | raise error.Abort(_('cannot perform stream clone against local ' |
|
233 | raise error.Abort(_('cannot perform stream clone against local ' | |
234 | 'peer')) |
|
234 | 'peer')) | |
235 |
|
235 | |||
236 | def unbundle(self, cg, heads, url): |
|
236 | def unbundle(self, cg, heads, url): | |
237 | """apply a bundle on a repo |
|
237 | """apply a bundle on a repo | |
238 |
|
238 | |||
239 | This function handles the repo locking itself.""" |
|
239 | This function handles the repo locking itself.""" | |
240 | try: |
|
240 | try: | |
241 | try: |
|
241 | try: | |
242 | cg = exchange.readbundle(self.ui, cg, None) |
|
242 | cg = exchange.readbundle(self.ui, cg, None) | |
243 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
243 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) | |
244 | if util.safehasattr(ret, 'getchunks'): |
|
244 | if util.safehasattr(ret, 'getchunks'): | |
245 | # This is a bundle20 object, turn it into an unbundler. |
|
245 | # This is a bundle20 object, turn it into an unbundler. | |
246 | # This little dance should be dropped eventually when the |
|
246 | # This little dance should be dropped eventually when the | |
247 | # API is finally improved. |
|
247 | # API is finally improved. | |
248 | stream = util.chunkbuffer(ret.getchunks()) |
|
248 | stream = util.chunkbuffer(ret.getchunks()) | |
249 | ret = bundle2.getunbundler(self.ui, stream) |
|
249 | ret = bundle2.getunbundler(self.ui, stream) | |
250 | return ret |
|
250 | return ret | |
251 | except Exception as exc: |
|
251 | except Exception as exc: | |
252 | # If the exception contains output salvaged from a bundle2 |
|
252 | # If the exception contains output salvaged from a bundle2 | |
253 | # reply, we need to make sure it is printed before continuing |
|
253 | # reply, we need to make sure it is printed before continuing | |
254 | # to fail. So we build a bundle2 with such output and consume |
|
254 | # to fail. So we build a bundle2 with such output and consume | |
255 | # it directly. |
|
255 | # it directly. | |
256 | # |
|
256 | # | |
257 | # This is not very elegant but allows a "simple" solution for |
|
257 | # This is not very elegant but allows a "simple" solution for | |
258 | # issue4594 |
|
258 | # issue4594 | |
259 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
259 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
260 | if output: |
|
260 | if output: | |
261 | bundler = bundle2.bundle20(self._repo.ui) |
|
261 | bundler = bundle2.bundle20(self._repo.ui) | |
262 | for out in output: |
|
262 | for out in output: | |
263 | bundler.addpart(out) |
|
263 | bundler.addpart(out) | |
264 | stream = util.chunkbuffer(bundler.getchunks()) |
|
264 | stream = util.chunkbuffer(bundler.getchunks()) | |
265 | b = bundle2.getunbundler(self.ui, stream) |
|
265 | b = bundle2.getunbundler(self.ui, stream) | |
266 | bundle2.processbundle(self._repo, b) |
|
266 | bundle2.processbundle(self._repo, b) | |
267 | raise |
|
267 | raise | |
268 | except error.PushRaced as exc: |
|
268 | except error.PushRaced as exc: | |
269 | raise error.ResponseError(_('push failed:'), |
|
269 | raise error.ResponseError(_('push failed:'), | |
270 | stringutil.forcebytestr(exc)) |
|
270 | stringutil.forcebytestr(exc)) | |
271 |
|
271 | |||
272 | # End of _basewirecommands interface. |
|
272 | # End of _basewirecommands interface. | |
273 |
|
273 | |||
274 | # Begin of peer interface. |
|
274 | # Begin of peer interface. | |
275 |
|
275 | |||
276 | def iterbatch(self): |
|
276 | def iterbatch(self): | |
277 | return peer.localiterbatcher(self) |
|
277 | return peer.localiterbatcher(self) | |
278 |
|
278 | |||
279 | # End of peer interface. |
|
279 | # End of peer interface. | |
280 |
|
280 | |||
281 | class locallegacypeer(repository.legacypeer, localpeer): |
|
281 | class locallegacypeer(repository.legacypeer, localpeer): | |
282 | '''peer extension which implements legacy methods too; used for tests with |
|
282 | '''peer extension which implements legacy methods too; used for tests with | |
283 | restricted capabilities''' |
|
283 | restricted capabilities''' | |
284 |
|
284 | |||
285 | def __init__(self, repo): |
|
285 | def __init__(self, repo): | |
286 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
286 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
287 |
|
287 | |||
288 | # Begin of baselegacywirecommands interface. |
|
288 | # Begin of baselegacywirecommands interface. | |
289 |
|
289 | |||
290 | def between(self, pairs): |
|
290 | def between(self, pairs): | |
291 | return self._repo.between(pairs) |
|
291 | return self._repo.between(pairs) | |
292 |
|
292 | |||
293 | def branches(self, nodes): |
|
293 | def branches(self, nodes): | |
294 | return self._repo.branches(nodes) |
|
294 | return self._repo.branches(nodes) | |
295 |
|
295 | |||
296 | def changegroup(self, basenodes, source): |
|
296 | def changegroup(self, basenodes, source): | |
297 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, |
|
297 | outgoing = discovery.outgoing(self._repo, missingroots=basenodes, | |
298 | missingheads=self._repo.heads()) |
|
298 | missingheads=self._repo.heads()) | |
299 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
299 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
300 |
|
300 | |||
301 | def changegroupsubset(self, bases, heads, source): |
|
301 | def changegroupsubset(self, bases, heads, source): | |
302 | outgoing = discovery.outgoing(self._repo, missingroots=bases, |
|
302 | outgoing = discovery.outgoing(self._repo, missingroots=bases, | |
303 | missingheads=heads) |
|
303 | missingheads=heads) | |
304 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) |
|
304 | return changegroup.makechangegroup(self._repo, outgoing, '01', source) | |
305 |
|
305 | |||
306 | # End of baselegacywirecommands interface. |
|
306 | # End of baselegacywirecommands interface. | |
307 |
|
307 | |||
308 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
308 | # Increment the sub-version when the revlog v2 format changes to lock out old | |
309 | # clients. |
|
309 | # clients. | |
310 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' |
|
310 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' | |
311 |
|
311 | |||
312 | # Functions receiving (ui, features) that extensions can register to impact |
|
312 | # Functions receiving (ui, features) that extensions can register to impact | |
313 | # the ability to load repositories with custom requirements. Only |
|
313 | # the ability to load repositories with custom requirements. Only | |
314 | # functions defined in loaded extensions are called. |
|
314 | # functions defined in loaded extensions are called. | |
315 | # |
|
315 | # | |
316 | # The function receives a set of requirement strings that the repository |
|
316 | # The function receives a set of requirement strings that the repository | |
317 | # is capable of opening. Functions will typically add elements to the |
|
317 | # is capable of opening. Functions will typically add elements to the | |
318 | # set to reflect that the extension knows how to handle that requirements. |
|
318 | # set to reflect that the extension knows how to handle that requirements. | |
319 | featuresetupfuncs = set() |
|
319 | featuresetupfuncs = set() | |
320 |
|
320 | |||
321 | class localrepository(object): |
|
321 | class localrepository(object): | |
322 |
|
322 | |||
323 | # obsolete experimental requirements: |
|
323 | # obsolete experimental requirements: | |
324 | # - manifestv2: An experimental new manifest format that allowed |
|
324 | # - manifestv2: An experimental new manifest format that allowed | |
325 | # for stem compression of long paths. Experiment ended up not |
|
325 | # for stem compression of long paths. Experiment ended up not | |
326 | # being successful (repository sizes went up due to worse delta |
|
326 | # being successful (repository sizes went up due to worse delta | |
327 | # chains), and the code was deleted in 4.6. |
|
327 | # chains), and the code was deleted in 4.6. | |
328 | supportedformats = { |
|
328 | supportedformats = { | |
329 | 'revlogv1', |
|
329 | 'revlogv1', | |
330 | 'generaldelta', |
|
330 | 'generaldelta', | |
331 | 'treemanifest', |
|
331 | 'treemanifest', | |
332 | REVLOGV2_REQUIREMENT, |
|
332 | REVLOGV2_REQUIREMENT, | |
333 | } |
|
333 | } | |
334 | _basesupported = supportedformats | { |
|
334 | _basesupported = supportedformats | { | |
335 | 'store', |
|
335 | 'store', | |
336 | 'fncache', |
|
336 | 'fncache', | |
337 | 'shared', |
|
337 | 'shared', | |
338 | 'relshared', |
|
338 | 'relshared', | |
339 | 'dotencode', |
|
339 | 'dotencode', | |
340 | 'exp-sparse', |
|
340 | 'exp-sparse', | |
341 | } |
|
341 | } | |
342 | openerreqs = { |
|
342 | openerreqs = { | |
343 | 'revlogv1', |
|
343 | 'revlogv1', | |
344 | 'generaldelta', |
|
344 | 'generaldelta', | |
345 | 'treemanifest', |
|
345 | 'treemanifest', | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | # list of prefix for file which can be written without 'wlock' |
|
348 | # list of prefix for file which can be written without 'wlock' | |
349 | # Extensions should extend this list when needed |
|
349 | # Extensions should extend this list when needed | |
350 | _wlockfreeprefix = { |
|
350 | _wlockfreeprefix = { | |
351 | # We migh consider requiring 'wlock' for the next |
|
351 | # We migh consider requiring 'wlock' for the next | |
352 | # two, but pretty much all the existing code assume |
|
352 | # two, but pretty much all the existing code assume | |
353 | # wlock is not needed so we keep them excluded for |
|
353 | # wlock is not needed so we keep them excluded for | |
354 | # now. |
|
354 | # now. | |
355 | 'hgrc', |
|
355 | 'hgrc', | |
356 | 'requires', |
|
356 | 'requires', | |
357 | # XXX cache is a complicatged business someone |
|
357 | # XXX cache is a complicatged business someone | |
358 | # should investigate this in depth at some point |
|
358 | # should investigate this in depth at some point | |
359 | 'cache/', |
|
359 | 'cache/', | |
360 | # XXX shouldn't be dirstate covered by the wlock? |
|
360 | # XXX shouldn't be dirstate covered by the wlock? | |
361 | 'dirstate', |
|
361 | 'dirstate', | |
362 | # XXX bisect was still a bit too messy at the time |
|
362 | # XXX bisect was still a bit too messy at the time | |
363 | # this changeset was introduced. Someone should fix |
|
363 | # this changeset was introduced. Someone should fix | |
364 | # the remainig bit and drop this line |
|
364 | # the remainig bit and drop this line | |
365 | 'bisect.state', |
|
365 | 'bisect.state', | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | def __init__(self, baseui, path, create=False): |
|
368 | def __init__(self, baseui, path, create=False): | |
369 | self.requirements = set() |
|
369 | self.requirements = set() | |
370 | self.filtername = None |
|
370 | self.filtername = None | |
371 | # wvfs: rooted at the repository root, used to access the working copy |
|
371 | # wvfs: rooted at the repository root, used to access the working copy | |
372 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
372 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
373 | # vfs: rooted at .hg, used to access repo files outside of .hg/store |
|
373 | # vfs: rooted at .hg, used to access repo files outside of .hg/store | |
374 | self.vfs = None |
|
374 | self.vfs = None | |
375 | # svfs: usually rooted at .hg/store, used to access repository history |
|
375 | # svfs: usually rooted at .hg/store, used to access repository history | |
376 | # If this is a shared repository, this vfs may point to another |
|
376 | # If this is a shared repository, this vfs may point to another | |
377 | # repository's .hg/store directory. |
|
377 | # repository's .hg/store directory. | |
378 | self.svfs = None |
|
378 | self.svfs = None | |
379 | self.root = self.wvfs.base |
|
379 | self.root = self.wvfs.base | |
380 | self.path = self.wvfs.join(".hg") |
|
380 | self.path = self.wvfs.join(".hg") | |
381 | self.origroot = path |
|
381 | self.origroot = path | |
382 | # This is only used by context.workingctx.match in order to |
|
382 | # This is only used by context.workingctx.match in order to | |
383 | # detect files in subrepos. |
|
383 | # detect files in subrepos. | |
384 | self.auditor = pathutil.pathauditor( |
|
384 | self.auditor = pathutil.pathauditor( | |
385 | self.root, callback=self._checknested) |
|
385 | self.root, callback=self._checknested) | |
386 | # This is only used by context.basectx.match in order to detect |
|
386 | # This is only used by context.basectx.match in order to detect | |
387 | # files in subrepos. |
|
387 | # files in subrepos. | |
388 | self.nofsauditor = pathutil.pathauditor( |
|
388 | self.nofsauditor = pathutil.pathauditor( | |
389 | self.root, callback=self._checknested, realfs=False, cached=True) |
|
389 | self.root, callback=self._checknested, realfs=False, cached=True) | |
390 | self.baseui = baseui |
|
390 | self.baseui = baseui | |
391 | self.ui = baseui.copy() |
|
391 | self.ui = baseui.copy() | |
392 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
392 | self.ui.copy = baseui.copy # prevent copying repo configuration | |
393 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) |
|
393 | self.vfs = vfsmod.vfs(self.path, cacheaudited=True) | |
394 | if (self.ui.configbool('devel', 'all-warnings') or |
|
394 | if (self.ui.configbool('devel', 'all-warnings') or | |
395 | self.ui.configbool('devel', 'check-locks')): |
|
395 | self.ui.configbool('devel', 'check-locks')): | |
396 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
396 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
397 | # A list of callback to shape the phase if no data were found. |
|
397 | # A list of callback to shape the phase if no data were found. | |
398 | # Callback are in the form: func(repo, roots) --> processed root. |
|
398 | # Callback are in the form: func(repo, roots) --> processed root. | |
399 | # This list it to be filled by extension during repo setup |
|
399 | # This list it to be filled by extension during repo setup | |
400 | self._phasedefaults = [] |
|
400 | self._phasedefaults = [] | |
401 | try: |
|
401 | try: | |
402 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) |
|
402 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) | |
403 | self._loadextensions() |
|
403 | self._loadextensions() | |
404 | except IOError: |
|
404 | except IOError: | |
405 | pass |
|
405 | pass | |
406 |
|
406 | |||
407 | if featuresetupfuncs: |
|
407 | if featuresetupfuncs: | |
408 | self.supported = set(self._basesupported) # use private copy |
|
408 | self.supported = set(self._basesupported) # use private copy | |
409 | extmods = set(m.__name__ for n, m |
|
409 | extmods = set(m.__name__ for n, m | |
410 | in extensions.extensions(self.ui)) |
|
410 | in extensions.extensions(self.ui)) | |
411 | for setupfunc in featuresetupfuncs: |
|
411 | for setupfunc in featuresetupfuncs: | |
412 | if setupfunc.__module__ in extmods: |
|
412 | if setupfunc.__module__ in extmods: | |
413 | setupfunc(self.ui, self.supported) |
|
413 | setupfunc(self.ui, self.supported) | |
414 | else: |
|
414 | else: | |
415 | self.supported = self._basesupported |
|
415 | self.supported = self._basesupported | |
416 | color.setup(self.ui) |
|
416 | color.setup(self.ui) | |
417 |
|
417 | |||
418 | # Add compression engines. |
|
418 | # Add compression engines. | |
419 | for name in util.compengines: |
|
419 | for name in util.compengines: | |
420 | engine = util.compengines[name] |
|
420 | engine = util.compengines[name] | |
421 | if engine.revlogheader(): |
|
421 | if engine.revlogheader(): | |
422 | self.supported.add('exp-compression-%s' % name) |
|
422 | self.supported.add('exp-compression-%s' % name) | |
423 |
|
423 | |||
424 | if not self.vfs.isdir(): |
|
424 | if not self.vfs.isdir(): | |
425 | if create: |
|
425 | if create: | |
426 | self.requirements = newreporequirements(self) |
|
426 | self.requirements = newreporequirements(self) | |
427 |
|
427 | |||
428 | if not self.wvfs.exists(): |
|
428 | if not self.wvfs.exists(): | |
429 | self.wvfs.makedirs() |
|
429 | self.wvfs.makedirs() | |
430 | self.vfs.makedir(notindexed=True) |
|
430 | self.vfs.makedir(notindexed=True) | |
431 |
|
431 | |||
432 | if 'store' in self.requirements: |
|
432 | if 'store' in self.requirements: | |
433 | self.vfs.mkdir("store") |
|
433 | self.vfs.mkdir("store") | |
434 |
|
434 | |||
435 | # create an invalid changelog |
|
435 | # create an invalid changelog | |
436 | self.vfs.append( |
|
436 | self.vfs.append( | |
437 | "00changelog.i", |
|
437 | "00changelog.i", | |
438 | '\0\0\0\2' # represents revlogv2 |
|
438 | '\0\0\0\2' # represents revlogv2 | |
439 | ' dummy changelog to prevent using the old repo layout' |
|
439 | ' dummy changelog to prevent using the old repo layout' | |
440 | ) |
|
440 | ) | |
441 | else: |
|
441 | else: | |
442 | raise error.RepoError(_("repository %s not found") % path) |
|
442 | raise error.RepoError(_("repository %s not found") % path) | |
443 | elif create: |
|
443 | elif create: | |
444 | raise error.RepoError(_("repository %s already exists") % path) |
|
444 | raise error.RepoError(_("repository %s already exists") % path) | |
445 | else: |
|
445 | else: | |
446 | try: |
|
446 | try: | |
447 | self.requirements = scmutil.readrequires( |
|
447 | self.requirements = scmutil.readrequires( | |
448 | self.vfs, self.supported) |
|
448 | self.vfs, self.supported) | |
449 | except IOError as inst: |
|
449 | except IOError as inst: | |
450 | if inst.errno != errno.ENOENT: |
|
450 | if inst.errno != errno.ENOENT: | |
451 | raise |
|
451 | raise | |
452 |
|
452 | |||
453 | cachepath = self.vfs.join('cache') |
|
453 | cachepath = self.vfs.join('cache') | |
454 | self.sharedpath = self.path |
|
454 | self.sharedpath = self.path | |
455 | try: |
|
455 | try: | |
456 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') |
|
456 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') | |
457 | if 'relshared' in self.requirements: |
|
457 | if 'relshared' in self.requirements: | |
458 | sharedpath = self.vfs.join(sharedpath) |
|
458 | sharedpath = self.vfs.join(sharedpath) | |
459 | vfs = vfsmod.vfs(sharedpath, realpath=True) |
|
459 | vfs = vfsmod.vfs(sharedpath, realpath=True) | |
460 | cachepath = vfs.join('cache') |
|
460 | cachepath = vfs.join('cache') | |
461 | s = vfs.base |
|
461 | s = vfs.base | |
462 | if not vfs.exists(): |
|
462 | if not vfs.exists(): | |
463 | raise error.RepoError( |
|
463 | raise error.RepoError( | |
464 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
464 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
465 | self.sharedpath = s |
|
465 | self.sharedpath = s | |
466 | except IOError as inst: |
|
466 | except IOError as inst: | |
467 | if inst.errno != errno.ENOENT: |
|
467 | if inst.errno != errno.ENOENT: | |
468 | raise |
|
468 | raise | |
469 |
|
469 | |||
470 | if 'exp-sparse' in self.requirements and not sparse.enabled: |
|
470 | if 'exp-sparse' in self.requirements and not sparse.enabled: | |
471 | raise error.RepoError(_('repository is using sparse feature but ' |
|
471 | raise error.RepoError(_('repository is using sparse feature but ' | |
472 | 'sparse is not enabled; enable the ' |
|
472 | 'sparse is not enabled; enable the ' | |
473 | '"sparse" extensions to access')) |
|
473 | '"sparse" extensions to access')) | |
474 |
|
474 | |||
475 | self.store = store.store( |
|
475 | self.store = store.store( | |
476 | self.requirements, self.sharedpath, |
|
476 | self.requirements, self.sharedpath, | |
477 | lambda base: vfsmod.vfs(base, cacheaudited=True)) |
|
477 | lambda base: vfsmod.vfs(base, cacheaudited=True)) | |
478 | self.spath = self.store.path |
|
478 | self.spath = self.store.path | |
479 | self.svfs = self.store.vfs |
|
479 | self.svfs = self.store.vfs | |
480 | self.sjoin = self.store.join |
|
480 | self.sjoin = self.store.join | |
481 | self.vfs.createmode = self.store.createmode |
|
481 | self.vfs.createmode = self.store.createmode | |
482 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
482 | self.cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
483 | self.cachevfs.createmode = self.store.createmode |
|
483 | self.cachevfs.createmode = self.store.createmode | |
484 | if (self.ui.configbool('devel', 'all-warnings') or |
|
484 | if (self.ui.configbool('devel', 'all-warnings') or | |
485 | self.ui.configbool('devel', 'check-locks')): |
|
485 | self.ui.configbool('devel', 'check-locks')): | |
486 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs |
|
486 | if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs | |
487 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
487 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
488 | else: # standard vfs |
|
488 | else: # standard vfs | |
489 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
489 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
490 | self._applyopenerreqs() |
|
490 | self._applyopenerreqs() | |
491 | if create: |
|
491 | if create: | |
492 | self._writerequirements() |
|
492 | self._writerequirements() | |
493 |
|
493 | |||
494 | self._dirstatevalidatewarned = False |
|
494 | self._dirstatevalidatewarned = False | |
495 |
|
495 | |||
496 | self._branchcaches = {} |
|
496 | self._branchcaches = {} | |
497 | self._revbranchcache = None |
|
497 | self._revbranchcache = None | |
498 | self._filterpats = {} |
|
498 | self._filterpats = {} | |
499 | self._datafilters = {} |
|
499 | self._datafilters = {} | |
500 | self._transref = self._lockref = self._wlockref = None |
|
500 | self._transref = self._lockref = self._wlockref = None | |
501 |
|
501 | |||
502 | # A cache for various files under .hg/ that tracks file changes, |
|
502 | # A cache for various files under .hg/ that tracks file changes, | |
503 | # (used by the filecache decorator) |
|
503 | # (used by the filecache decorator) | |
504 | # |
|
504 | # | |
505 | # Maps a property name to its util.filecacheentry |
|
505 | # Maps a property name to its util.filecacheentry | |
506 | self._filecache = {} |
|
506 | self._filecache = {} | |
507 |
|
507 | |||
508 | # hold sets of revision to be filtered |
|
508 | # hold sets of revision to be filtered | |
509 | # should be cleared when something might have changed the filter value: |
|
509 | # should be cleared when something might have changed the filter value: | |
510 | # - new changesets, |
|
510 | # - new changesets, | |
511 | # - phase change, |
|
511 | # - phase change, | |
512 | # - new obsolescence marker, |
|
512 | # - new obsolescence marker, | |
513 | # - working directory parent change, |
|
513 | # - working directory parent change, | |
514 | # - bookmark changes |
|
514 | # - bookmark changes | |
515 | self.filteredrevcache = {} |
|
515 | self.filteredrevcache = {} | |
516 |
|
516 | |||
517 | # post-dirstate-status hooks |
|
517 | # post-dirstate-status hooks | |
518 | self._postdsstatus = [] |
|
518 | self._postdsstatus = [] | |
519 |
|
519 | |||
520 | # generic mapping between names and nodes |
|
520 | # generic mapping between names and nodes | |
521 | self.names = namespaces.namespaces() |
|
521 | self.names = namespaces.namespaces() | |
522 |
|
522 | |||
523 | # Key to signature value. |
|
523 | # Key to signature value. | |
524 | self._sparsesignaturecache = {} |
|
524 | self._sparsesignaturecache = {} | |
525 | # Signature to cached matcher instance. |
|
525 | # Signature to cached matcher instance. | |
526 | self._sparsematchercache = {} |
|
526 | self._sparsematchercache = {} | |
527 |
|
527 | |||
528 | def _getvfsward(self, origfunc): |
|
528 | def _getvfsward(self, origfunc): | |
529 | """build a ward for self.vfs""" |
|
529 | """build a ward for self.vfs""" | |
530 | rref = weakref.ref(self) |
|
530 | rref = weakref.ref(self) | |
531 | def checkvfs(path, mode=None): |
|
531 | def checkvfs(path, mode=None): | |
532 | ret = origfunc(path, mode=mode) |
|
532 | ret = origfunc(path, mode=mode) | |
533 | repo = rref() |
|
533 | repo = rref() | |
534 | if (repo is None |
|
534 | if (repo is None | |
535 | or not util.safehasattr(repo, '_wlockref') |
|
535 | or not util.safehasattr(repo, '_wlockref') | |
536 | or not util.safehasattr(repo, '_lockref')): |
|
536 | or not util.safehasattr(repo, '_lockref')): | |
537 | return |
|
537 | return | |
538 | if mode in (None, 'r', 'rb'): |
|
538 | if mode in (None, 'r', 'rb'): | |
539 | return |
|
539 | return | |
540 | if path.startswith(repo.path): |
|
540 | if path.startswith(repo.path): | |
541 | # truncate name relative to the repository (.hg) |
|
541 | # truncate name relative to the repository (.hg) | |
542 | path = path[len(repo.path) + 1:] |
|
542 | path = path[len(repo.path) + 1:] | |
543 | if path.startswith('cache/'): |
|
543 | if path.startswith('cache/'): | |
544 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' |
|
544 | msg = 'accessing cache with vfs instead of cachevfs: "%s"' | |
545 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") |
|
545 | repo.ui.develwarn(msg % path, stacklevel=2, config="cache-vfs") | |
546 | if path.startswith('journal.'): |
|
546 | if path.startswith('journal.'): | |
547 | # journal is covered by 'lock' |
|
547 | # journal is covered by 'lock' | |
548 | if repo._currentlock(repo._lockref) is None: |
|
548 | if repo._currentlock(repo._lockref) is None: | |
549 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
549 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
550 | stacklevel=2, config='check-locks') |
|
550 | stacklevel=2, config='check-locks') | |
551 | elif repo._currentlock(repo._wlockref) is None: |
|
551 | elif repo._currentlock(repo._wlockref) is None: | |
552 | # rest of vfs files are covered by 'wlock' |
|
552 | # rest of vfs files are covered by 'wlock' | |
553 | # |
|
553 | # | |
554 | # exclude special files |
|
554 | # exclude special files | |
555 | for prefix in self._wlockfreeprefix: |
|
555 | for prefix in self._wlockfreeprefix: | |
556 | if path.startswith(prefix): |
|
556 | if path.startswith(prefix): | |
557 | return |
|
557 | return | |
558 | repo.ui.develwarn('write with no wlock: "%s"' % path, |
|
558 | repo.ui.develwarn('write with no wlock: "%s"' % path, | |
559 | stacklevel=2, config='check-locks') |
|
559 | stacklevel=2, config='check-locks') | |
560 | return ret |
|
560 | return ret | |
561 | return checkvfs |
|
561 | return checkvfs | |
562 |
|
562 | |||
563 | def _getsvfsward(self, origfunc): |
|
563 | def _getsvfsward(self, origfunc): | |
564 | """build a ward for self.svfs""" |
|
564 | """build a ward for self.svfs""" | |
565 | rref = weakref.ref(self) |
|
565 | rref = weakref.ref(self) | |
566 | def checksvfs(path, mode=None): |
|
566 | def checksvfs(path, mode=None): | |
567 | ret = origfunc(path, mode=mode) |
|
567 | ret = origfunc(path, mode=mode) | |
568 | repo = rref() |
|
568 | repo = rref() | |
569 | if repo is None or not util.safehasattr(repo, '_lockref'): |
|
569 | if repo is None or not util.safehasattr(repo, '_lockref'): | |
570 | return |
|
570 | return | |
571 | if mode in (None, 'r', 'rb'): |
|
571 | if mode in (None, 'r', 'rb'): | |
572 | return |
|
572 | return | |
573 | if path.startswith(repo.sharedpath): |
|
573 | if path.startswith(repo.sharedpath): | |
574 | # truncate name relative to the repository (.hg) |
|
574 | # truncate name relative to the repository (.hg) | |
575 | path = path[len(repo.sharedpath) + 1:] |
|
575 | path = path[len(repo.sharedpath) + 1:] | |
576 | if repo._currentlock(repo._lockref) is None: |
|
576 | if repo._currentlock(repo._lockref) is None: | |
577 | repo.ui.develwarn('write with no lock: "%s"' % path, |
|
577 | repo.ui.develwarn('write with no lock: "%s"' % path, | |
578 | stacklevel=3) |
|
578 | stacklevel=3) | |
579 | return ret |
|
579 | return ret | |
580 | return checksvfs |
|
580 | return checksvfs | |
581 |
|
581 | |||
582 | def close(self): |
|
582 | def close(self): | |
583 | self._writecaches() |
|
583 | self._writecaches() | |
584 |
|
584 | |||
585 | def _loadextensions(self): |
|
585 | def _loadextensions(self): | |
586 | extensions.loadall(self.ui) |
|
586 | extensions.loadall(self.ui) | |
587 |
|
587 | |||
588 | def _writecaches(self): |
|
588 | def _writecaches(self): | |
589 | if self._revbranchcache: |
|
589 | if self._revbranchcache: | |
590 | self._revbranchcache.write() |
|
590 | self._revbranchcache.write() | |
591 |
|
591 | |||
592 | def _restrictcapabilities(self, caps): |
|
592 | def _restrictcapabilities(self, caps): | |
593 | if self.ui.configbool('experimental', 'bundle2-advertise'): |
|
593 | if self.ui.configbool('experimental', 'bundle2-advertise'): | |
594 | caps = set(caps) |
|
594 | caps = set(caps) | |
595 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, |
|
595 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self, | |
596 | role='client')) |
|
596 | role='client')) | |
597 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
597 | caps.add('bundle2=' + urlreq.quote(capsblob)) | |
598 | return caps |
|
598 | return caps | |
599 |
|
599 | |||
600 | def _applyopenerreqs(self): |
|
600 | def _applyopenerreqs(self): | |
601 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
601 | self.svfs.options = dict((r, 1) for r in self.requirements | |
602 | if r in self.openerreqs) |
|
602 | if r in self.openerreqs) | |
603 | # experimental config: format.chunkcachesize |
|
603 | # experimental config: format.chunkcachesize | |
604 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
604 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') | |
605 | if chunkcachesize is not None: |
|
605 | if chunkcachesize is not None: | |
606 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
606 | self.svfs.options['chunkcachesize'] = chunkcachesize | |
607 | # experimental config: format.maxchainlen |
|
607 | # experimental config: format.maxchainlen | |
608 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
608 | maxchainlen = self.ui.configint('format', 'maxchainlen') | |
609 | if maxchainlen is not None: |
|
609 | if maxchainlen is not None: | |
610 | self.svfs.options['maxchainlen'] = maxchainlen |
|
610 | self.svfs.options['maxchainlen'] = maxchainlen | |
611 | # experimental config: format.manifestcachesize |
|
611 | # experimental config: format.manifestcachesize | |
612 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
612 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') | |
613 | if manifestcachesize is not None: |
|
613 | if manifestcachesize is not None: | |
614 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
614 | self.svfs.options['manifestcachesize'] = manifestcachesize | |
615 | # experimental config: format.aggressivemergedeltas |
|
615 | # experimental config: format.aggressivemergedeltas | |
616 | aggressivemergedeltas = self.ui.configbool('format', |
|
616 | aggressivemergedeltas = self.ui.configbool('format', | |
617 | 'aggressivemergedeltas') |
|
617 | 'aggressivemergedeltas') | |
618 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
618 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas | |
619 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) |
|
619 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) | |
620 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') |
|
620 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan') | |
621 | if 0 <= chainspan: |
|
621 | if 0 <= chainspan: | |
622 | self.svfs.options['maxdeltachainspan'] = chainspan |
|
622 | self.svfs.options['maxdeltachainspan'] = chainspan | |
623 | mmapindexthreshold = self.ui.configbytes('experimental', |
|
623 | mmapindexthreshold = self.ui.configbytes('experimental', | |
624 | 'mmapindexthreshold') |
|
624 | 'mmapindexthreshold') | |
625 | if mmapindexthreshold is not None: |
|
625 | if mmapindexthreshold is not None: | |
626 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold |
|
626 | self.svfs.options['mmapindexthreshold'] = mmapindexthreshold | |
627 | withsparseread = self.ui.configbool('experimental', 'sparse-read') |
|
627 | withsparseread = self.ui.configbool('experimental', 'sparse-read') | |
628 | srdensitythres = float(self.ui.config('experimental', |
|
628 | srdensitythres = float(self.ui.config('experimental', | |
629 | 'sparse-read.density-threshold')) |
|
629 | 'sparse-read.density-threshold')) | |
630 | srmingapsize = self.ui.configbytes('experimental', |
|
630 | srmingapsize = self.ui.configbytes('experimental', | |
631 | 'sparse-read.min-gap-size') |
|
631 | 'sparse-read.min-gap-size') | |
632 | self.svfs.options['with-sparse-read'] = withsparseread |
|
632 | self.svfs.options['with-sparse-read'] = withsparseread | |
633 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres |
|
633 | self.svfs.options['sparse-read-density-threshold'] = srdensitythres | |
634 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize |
|
634 | self.svfs.options['sparse-read-min-gap-size'] = srmingapsize | |
635 |
|
635 | |||
636 | for r in self.requirements: |
|
636 | for r in self.requirements: | |
637 | if r.startswith('exp-compression-'): |
|
637 | if r.startswith('exp-compression-'): | |
638 | self.svfs.options['compengine'] = r[len('exp-compression-'):] |
|
638 | self.svfs.options['compengine'] = r[len('exp-compression-'):] | |
639 |
|
639 | |||
640 | # TODO move "revlogv2" to openerreqs once finalized. |
|
640 | # TODO move "revlogv2" to openerreqs once finalized. | |
641 | if REVLOGV2_REQUIREMENT in self.requirements: |
|
641 | if REVLOGV2_REQUIREMENT in self.requirements: | |
642 | self.svfs.options['revlogv2'] = True |
|
642 | self.svfs.options['revlogv2'] = True | |
643 |
|
643 | |||
644 | def _writerequirements(self): |
|
644 | def _writerequirements(self): | |
645 | scmutil.writerequires(self.vfs, self.requirements) |
|
645 | scmutil.writerequires(self.vfs, self.requirements) | |
646 |
|
646 | |||
647 | def _checknested(self, path): |
|
647 | def _checknested(self, path): | |
648 | """Determine if path is a legal nested repository.""" |
|
648 | """Determine if path is a legal nested repository.""" | |
649 | if not path.startswith(self.root): |
|
649 | if not path.startswith(self.root): | |
650 | return False |
|
650 | return False | |
651 | subpath = path[len(self.root) + 1:] |
|
651 | subpath = path[len(self.root) + 1:] | |
652 | normsubpath = util.pconvert(subpath) |
|
652 | normsubpath = util.pconvert(subpath) | |
653 |
|
653 | |||
654 | # XXX: Checking against the current working copy is wrong in |
|
654 | # XXX: Checking against the current working copy is wrong in | |
655 | # the sense that it can reject things like |
|
655 | # the sense that it can reject things like | |
656 | # |
|
656 | # | |
657 | # $ hg cat -r 10 sub/x.txt |
|
657 | # $ hg cat -r 10 sub/x.txt | |
658 | # |
|
658 | # | |
659 | # if sub/ is no longer a subrepository in the working copy |
|
659 | # if sub/ is no longer a subrepository in the working copy | |
660 | # parent revision. |
|
660 | # parent revision. | |
661 | # |
|
661 | # | |
662 | # However, it can of course also allow things that would have |
|
662 | # However, it can of course also allow things that would have | |
663 | # been rejected before, such as the above cat command if sub/ |
|
663 | # been rejected before, such as the above cat command if sub/ | |
664 | # is a subrepository now, but was a normal directory before. |
|
664 | # is a subrepository now, but was a normal directory before. | |
665 | # The old path auditor would have rejected by mistake since it |
|
665 | # The old path auditor would have rejected by mistake since it | |
666 | # panics when it sees sub/.hg/. |
|
666 | # panics when it sees sub/.hg/. | |
667 | # |
|
667 | # | |
668 | # All in all, checking against the working copy seems sensible |
|
668 | # All in all, checking against the working copy seems sensible | |
669 | # since we want to prevent access to nested repositories on |
|
669 | # since we want to prevent access to nested repositories on | |
670 | # the filesystem *now*. |
|
670 | # the filesystem *now*. | |
671 | ctx = self[None] |
|
671 | ctx = self[None] | |
672 | parts = util.splitpath(subpath) |
|
672 | parts = util.splitpath(subpath) | |
673 | while parts: |
|
673 | while parts: | |
674 | prefix = '/'.join(parts) |
|
674 | prefix = '/'.join(parts) | |
675 | if prefix in ctx.substate: |
|
675 | if prefix in ctx.substate: | |
676 | if prefix == normsubpath: |
|
676 | if prefix == normsubpath: | |
677 | return True |
|
677 | return True | |
678 | else: |
|
678 | else: | |
679 | sub = ctx.sub(prefix) |
|
679 | sub = ctx.sub(prefix) | |
680 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
680 | return sub.checknested(subpath[len(prefix) + 1:]) | |
681 | else: |
|
681 | else: | |
682 | parts.pop() |
|
682 | parts.pop() | |
683 | return False |
|
683 | return False | |
684 |
|
684 | |||
685 | def peer(self): |
|
685 | def peer(self): | |
686 | return localpeer(self) # not cached to avoid reference cycle |
|
686 | return localpeer(self) # not cached to avoid reference cycle | |
687 |
|
687 | |||
688 | def unfiltered(self): |
|
688 | def unfiltered(self): | |
689 | """Return unfiltered version of the repository |
|
689 | """Return unfiltered version of the repository | |
690 |
|
690 | |||
691 | Intended to be overwritten by filtered repo.""" |
|
691 | Intended to be overwritten by filtered repo.""" | |
692 | return self |
|
692 | return self | |
693 |
|
693 | |||
694 | def filtered(self, name, visibilityexceptions=None): |
|
694 | def filtered(self, name, visibilityexceptions=None): | |
695 | """Return a filtered version of a repository""" |
|
695 | """Return a filtered version of a repository""" | |
696 | cls = repoview.newtype(self.unfiltered().__class__) |
|
696 | cls = repoview.newtype(self.unfiltered().__class__) | |
697 | return cls(self, name, visibilityexceptions) |
|
697 | return cls(self, name, visibilityexceptions) | |
698 |
|
698 | |||
699 | @repofilecache('bookmarks', 'bookmarks.current') |
|
699 | @repofilecache('bookmarks', 'bookmarks.current') | |
700 | def _bookmarks(self): |
|
700 | def _bookmarks(self): | |
701 | return bookmarks.bmstore(self) |
|
701 | return bookmarks.bmstore(self) | |
702 |
|
702 | |||
703 | @property |
|
703 | @property | |
704 | def _activebookmark(self): |
|
704 | def _activebookmark(self): | |
705 | return self._bookmarks.active |
|
705 | return self._bookmarks.active | |
706 |
|
706 | |||
707 | # _phasesets depend on changelog. what we need is to call |
|
707 | # _phasesets depend on changelog. what we need is to call | |
708 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
708 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
709 | # can't be easily expressed in filecache mechanism. |
|
709 | # can't be easily expressed in filecache mechanism. | |
710 | @storecache('phaseroots', '00changelog.i') |
|
710 | @storecache('phaseroots', '00changelog.i') | |
711 | def _phasecache(self): |
|
711 | def _phasecache(self): | |
712 | return phases.phasecache(self, self._phasedefaults) |
|
712 | return phases.phasecache(self, self._phasedefaults) | |
713 |
|
713 | |||
714 | @storecache('obsstore') |
|
714 | @storecache('obsstore') | |
715 | def obsstore(self): |
|
715 | def obsstore(self): | |
716 | return obsolete.makestore(self.ui, self) |
|
716 | return obsolete.makestore(self.ui, self) | |
717 |
|
717 | |||
718 | @storecache('00changelog.i') |
|
718 | @storecache('00changelog.i') | |
719 | def changelog(self): |
|
719 | def changelog(self): | |
720 | return changelog.changelog(self.svfs, |
|
720 | return changelog.changelog(self.svfs, | |
721 | trypending=txnutil.mayhavepending(self.root)) |
|
721 | trypending=txnutil.mayhavepending(self.root)) | |
722 |
|
722 | |||
723 | def _constructmanifest(self): |
|
723 | def _constructmanifest(self): | |
724 | # This is a temporary function while we migrate from manifest to |
|
724 | # This is a temporary function while we migrate from manifest to | |
725 | # manifestlog. It allows bundlerepo and unionrepo to intercept the |
|
725 | # manifestlog. It allows bundlerepo and unionrepo to intercept the | |
726 | # manifest creation. |
|
726 | # manifest creation. | |
727 | return manifest.manifestrevlog(self.svfs) |
|
727 | return manifest.manifestrevlog(self.svfs) | |
728 |
|
728 | |||
729 | @storecache('00manifest.i') |
|
729 | @storecache('00manifest.i') | |
730 | def manifestlog(self): |
|
730 | def manifestlog(self): | |
731 | return manifest.manifestlog(self.svfs, self) |
|
731 | return manifest.manifestlog(self.svfs, self) | |
732 |
|
732 | |||
733 | @repofilecache('dirstate') |
|
733 | @repofilecache('dirstate') | |
734 | def dirstate(self): |
|
734 | def dirstate(self): | |
735 | sparsematchfn = lambda: sparse.matcher(self) |
|
735 | sparsematchfn = lambda: sparse.matcher(self) | |
736 |
|
736 | |||
737 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
737 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
738 | self._dirstatevalidate, sparsematchfn) |
|
738 | self._dirstatevalidate, sparsematchfn) | |
739 |
|
739 | |||
740 | def _dirstatevalidate(self, node): |
|
740 | def _dirstatevalidate(self, node): | |
741 | try: |
|
741 | try: | |
742 | self.changelog.rev(node) |
|
742 | self.changelog.rev(node) | |
743 | return node |
|
743 | return node | |
744 | except error.LookupError: |
|
744 | except error.LookupError: | |
745 | if not self._dirstatevalidatewarned: |
|
745 | if not self._dirstatevalidatewarned: | |
746 | self._dirstatevalidatewarned = True |
|
746 | self._dirstatevalidatewarned = True | |
747 | self.ui.warn(_("warning: ignoring unknown" |
|
747 | self.ui.warn(_("warning: ignoring unknown" | |
748 | " working parent %s!\n") % short(node)) |
|
748 | " working parent %s!\n") % short(node)) | |
749 | return nullid |
|
749 | return nullid | |
750 |
|
750 | |||
751 | @repofilecache(narrowspec.FILENAME) |
|
751 | @repofilecache(narrowspec.FILENAME) | |
752 | def narrowpats(self): |
|
752 | def narrowpats(self): | |
753 | """matcher patterns for this repository's narrowspec |
|
753 | """matcher patterns for this repository's narrowspec | |
754 |
|
754 | |||
755 | A tuple of (includes, excludes). |
|
755 | A tuple of (includes, excludes). | |
756 | """ |
|
756 | """ | |
757 | source = self |
|
757 | source = self | |
758 | if self.shared(): |
|
758 | if self.shared(): | |
759 | from . import hg |
|
759 | from . import hg | |
760 | source = hg.sharedreposource(self) |
|
760 | source = hg.sharedreposource(self) | |
761 | return narrowspec.load(source) |
|
761 | return narrowspec.load(source) | |
762 |
|
762 | |||
763 | @repofilecache(narrowspec.FILENAME) |
|
763 | @repofilecache(narrowspec.FILENAME) | |
764 | def _narrowmatch(self): |
|
764 | def _narrowmatch(self): | |
765 | if changegroup.NARROW_REQUIREMENT not in self.requirements: |
|
765 | if changegroup.NARROW_REQUIREMENT not in self.requirements: | |
766 | return matchmod.always(self.root, '') |
|
766 | return matchmod.always(self.root, '') | |
767 | include, exclude = self.narrowpats |
|
767 | include, exclude = self.narrowpats | |
768 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
768 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
769 |
|
769 | |||
770 | # TODO(martinvonz): make this property-like instead? |
|
770 | # TODO(martinvonz): make this property-like instead? | |
771 | def narrowmatch(self): |
|
771 | def narrowmatch(self): | |
772 | return self._narrowmatch |
|
772 | return self._narrowmatch | |
773 |
|
773 | |||
774 | def setnarrowpats(self, newincludes, newexcludes): |
|
774 | def setnarrowpats(self, newincludes, newexcludes): | |
775 | target = self |
|
775 | target = self | |
776 | if self.shared(): |
|
776 | if self.shared(): | |
777 | from . import hg |
|
777 | from . import hg | |
778 | target = hg.sharedreposource(self) |
|
778 | target = hg.sharedreposource(self) | |
779 | narrowspec.save(target, newincludes, newexcludes) |
|
779 | narrowspec.save(target, newincludes, newexcludes) | |
780 | self.invalidate(clearfilecache=True) |
|
780 | self.invalidate(clearfilecache=True) | |
781 |
|
781 | |||
782 | def __getitem__(self, changeid): |
|
782 | def __getitem__(self, changeid): | |
783 | if changeid is None: |
|
783 | if changeid is None: | |
784 | return context.workingctx(self) |
|
784 | return context.workingctx(self) | |
785 | if isinstance(changeid, slice): |
|
785 | if isinstance(changeid, slice): | |
786 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
786 | # wdirrev isn't contiguous so the slice shouldn't include it | |
787 | return [context.changectx(self, i) |
|
787 | return [context.changectx(self, i) | |
788 | for i in xrange(*changeid.indices(len(self))) |
|
788 | for i in xrange(*changeid.indices(len(self))) | |
789 | if i not in self.changelog.filteredrevs] |
|
789 | if i not in self.changelog.filteredrevs] | |
790 | try: |
|
790 | try: | |
791 | return context.changectx(self, changeid) |
|
791 | return context.changectx(self, changeid) | |
792 | except error.WdirUnsupported: |
|
792 | except error.WdirUnsupported: | |
793 | return context.workingctx(self) |
|
793 | return context.workingctx(self) | |
794 |
|
794 | |||
795 | def __contains__(self, changeid): |
|
795 | def __contains__(self, changeid): | |
796 | """True if the given changeid exists |
|
796 | """True if the given changeid exists | |
797 |
|
797 | |||
798 | error.LookupError is raised if an ambiguous node specified. |
|
798 | error.LookupError is raised if an ambiguous node specified. | |
799 | """ |
|
799 | """ | |
800 | try: |
|
800 | try: | |
801 | self[changeid] |
|
801 | self[changeid] | |
802 | return True |
|
802 | return True | |
803 | except error.RepoLookupError: |
|
803 | except error.RepoLookupError: | |
804 | return False |
|
804 | return False | |
805 |
|
805 | |||
806 | def __nonzero__(self): |
|
806 | def __nonzero__(self): | |
807 | return True |
|
807 | return True | |
808 |
|
808 | |||
809 | __bool__ = __nonzero__ |
|
809 | __bool__ = __nonzero__ | |
810 |
|
810 | |||
811 | def __len__(self): |
|
811 | def __len__(self): | |
812 | # no need to pay the cost of repoview.changelog |
|
812 | # no need to pay the cost of repoview.changelog | |
813 | unfi = self.unfiltered() |
|
813 | unfi = self.unfiltered() | |
814 | return len(unfi.changelog) |
|
814 | return len(unfi.changelog) | |
815 |
|
815 | |||
816 | def __iter__(self): |
|
816 | def __iter__(self): | |
817 | return iter(self.changelog) |
|
817 | return iter(self.changelog) | |
818 |
|
818 | |||
819 | def revs(self, expr, *args): |
|
819 | def revs(self, expr, *args): | |
820 | '''Find revisions matching a revset. |
|
820 | '''Find revisions matching a revset. | |
821 |
|
821 | |||
822 | The revset is specified as a string ``expr`` that may contain |
|
822 | The revset is specified as a string ``expr`` that may contain | |
823 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
823 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
824 |
|
824 | |||
825 | Revset aliases from the configuration are not expanded. To expand |
|
825 | Revset aliases from the configuration are not expanded. To expand | |
826 | user aliases, consider calling ``scmutil.revrange()`` or |
|
826 | user aliases, consider calling ``scmutil.revrange()`` or | |
827 | ``repo.anyrevs([expr], user=True)``. |
|
827 | ``repo.anyrevs([expr], user=True)``. | |
828 |
|
828 | |||
829 | Returns a revset.abstractsmartset, which is a list-like interface |
|
829 | Returns a revset.abstractsmartset, which is a list-like interface | |
830 | that contains integer revisions. |
|
830 | that contains integer revisions. | |
831 | ''' |
|
831 | ''' | |
832 | expr = revsetlang.formatspec(expr, *args) |
|
832 | expr = revsetlang.formatspec(expr, *args) | |
833 | m = revset.match(None, expr) |
|
833 | m = revset.match(None, expr) | |
834 | return m(self) |
|
834 | return m(self) | |
835 |
|
835 | |||
836 | def set(self, expr, *args): |
|
836 | def set(self, expr, *args): | |
837 | '''Find revisions matching a revset and emit changectx instances. |
|
837 | '''Find revisions matching a revset and emit changectx instances. | |
838 |
|
838 | |||
839 | This is a convenience wrapper around ``revs()`` that iterates the |
|
839 | This is a convenience wrapper around ``revs()`` that iterates the | |
840 | result and is a generator of changectx instances. |
|
840 | result and is a generator of changectx instances. | |
841 |
|
841 | |||
842 | Revset aliases from the configuration are not expanded. To expand |
|
842 | Revset aliases from the configuration are not expanded. To expand | |
843 | user aliases, consider calling ``scmutil.revrange()``. |
|
843 | user aliases, consider calling ``scmutil.revrange()``. | |
844 | ''' |
|
844 | ''' | |
845 | for r in self.revs(expr, *args): |
|
845 | for r in self.revs(expr, *args): | |
846 | yield self[r] |
|
846 | yield self[r] | |
847 |
|
847 | |||
848 | def anyrevs(self, specs, user=False, localalias=None): |
|
848 | def anyrevs(self, specs, user=False, localalias=None): | |
849 | '''Find revisions matching one of the given revsets. |
|
849 | '''Find revisions matching one of the given revsets. | |
850 |
|
850 | |||
851 | Revset aliases from the configuration are not expanded by default. To |
|
851 | Revset aliases from the configuration are not expanded by default. To | |
852 | expand user aliases, specify ``user=True``. To provide some local |
|
852 | expand user aliases, specify ``user=True``. To provide some local | |
853 | definitions overriding user aliases, set ``localalias`` to |
|
853 | definitions overriding user aliases, set ``localalias`` to | |
854 | ``{name: definitionstring}``. |
|
854 | ``{name: definitionstring}``. | |
855 | ''' |
|
855 | ''' | |
856 | if user: |
|
856 | if user: | |
857 | m = revset.matchany(self.ui, specs, repo=self, |
|
857 | m = revset.matchany(self.ui, specs, repo=self, | |
858 | localalias=localalias) |
|
858 | localalias=localalias) | |
859 | else: |
|
859 | else: | |
860 | m = revset.matchany(None, specs, localalias=localalias) |
|
860 | m = revset.matchany(None, specs, localalias=localalias) | |
861 | return m(self) |
|
861 | return m(self) | |
862 |
|
862 | |||
863 | def url(self): |
|
863 | def url(self): | |
864 | return 'file:' + self.root |
|
864 | return 'file:' + self.root | |
865 |
|
865 | |||
866 | def hook(self, name, throw=False, **args): |
|
866 | def hook(self, name, throw=False, **args): | |
867 | """Call a hook, passing this repo instance. |
|
867 | """Call a hook, passing this repo instance. | |
868 |
|
868 | |||
869 | This a convenience method to aid invoking hooks. Extensions likely |
|
869 | This a convenience method to aid invoking hooks. Extensions likely | |
870 | won't call this unless they have registered a custom hook or are |
|
870 | won't call this unless they have registered a custom hook or are | |
871 | replacing code that is expected to call a hook. |
|
871 | replacing code that is expected to call a hook. | |
872 | """ |
|
872 | """ | |
873 | return hook.hook(self.ui, self, name, throw, **args) |
|
873 | return hook.hook(self.ui, self, name, throw, **args) | |
874 |
|
874 | |||
875 | @filteredpropertycache |
|
875 | @filteredpropertycache | |
876 | def _tagscache(self): |
|
876 | def _tagscache(self): | |
877 | '''Returns a tagscache object that contains various tags related |
|
877 | '''Returns a tagscache object that contains various tags related | |
878 | caches.''' |
|
878 | caches.''' | |
879 |
|
879 | |||
880 | # This simplifies its cache management by having one decorated |
|
880 | # This simplifies its cache management by having one decorated | |
881 | # function (this one) and the rest simply fetch things from it. |
|
881 | # function (this one) and the rest simply fetch things from it. | |
882 | class tagscache(object): |
|
882 | class tagscache(object): | |
883 | def __init__(self): |
|
883 | def __init__(self): | |
884 | # These two define the set of tags for this repository. tags |
|
884 | # These two define the set of tags for this repository. tags | |
885 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
885 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
886 | # 'local'. (Global tags are defined by .hgtags across all |
|
886 | # 'local'. (Global tags are defined by .hgtags across all | |
887 | # heads, and local tags are defined in .hg/localtags.) |
|
887 | # heads, and local tags are defined in .hg/localtags.) | |
888 | # They constitute the in-memory cache of tags. |
|
888 | # They constitute the in-memory cache of tags. | |
889 | self.tags = self.tagtypes = None |
|
889 | self.tags = self.tagtypes = None | |
890 |
|
890 | |||
891 | self.nodetagscache = self.tagslist = None |
|
891 | self.nodetagscache = self.tagslist = None | |
892 |
|
892 | |||
893 | cache = tagscache() |
|
893 | cache = tagscache() | |
894 | cache.tags, cache.tagtypes = self._findtags() |
|
894 | cache.tags, cache.tagtypes = self._findtags() | |
895 |
|
895 | |||
896 | return cache |
|
896 | return cache | |
897 |
|
897 | |||
898 | def tags(self): |
|
898 | def tags(self): | |
899 | '''return a mapping of tag to node''' |
|
899 | '''return a mapping of tag to node''' | |
900 | t = {} |
|
900 | t = {} | |
901 | if self.changelog.filteredrevs: |
|
901 | if self.changelog.filteredrevs: | |
902 | tags, tt = self._findtags() |
|
902 | tags, tt = self._findtags() | |
903 | else: |
|
903 | else: | |
904 | tags = self._tagscache.tags |
|
904 | tags = self._tagscache.tags | |
905 | for k, v in tags.iteritems(): |
|
905 | for k, v in tags.iteritems(): | |
906 | try: |
|
906 | try: | |
907 | # ignore tags to unknown nodes |
|
907 | # ignore tags to unknown nodes | |
908 | self.changelog.rev(v) |
|
908 | self.changelog.rev(v) | |
909 | t[k] = v |
|
909 | t[k] = v | |
910 | except (error.LookupError, ValueError): |
|
910 | except (error.LookupError, ValueError): | |
911 | pass |
|
911 | pass | |
912 | return t |
|
912 | return t | |
913 |
|
913 | |||
914 | def _findtags(self): |
|
914 | def _findtags(self): | |
915 | '''Do the hard work of finding tags. Return a pair of dicts |
|
915 | '''Do the hard work of finding tags. Return a pair of dicts | |
916 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
916 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
917 | maps tag name to a string like \'global\' or \'local\'. |
|
917 | maps tag name to a string like \'global\' or \'local\'. | |
918 | Subclasses or extensions are free to add their own tags, but |
|
918 | Subclasses or extensions are free to add their own tags, but | |
919 | should be aware that the returned dicts will be retained for the |
|
919 | should be aware that the returned dicts will be retained for the | |
920 | duration of the localrepo object.''' |
|
920 | duration of the localrepo object.''' | |
921 |
|
921 | |||
922 | # XXX what tagtype should subclasses/extensions use? Currently |
|
922 | # XXX what tagtype should subclasses/extensions use? Currently | |
923 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
923 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
924 | # Should each extension invent its own tag type? Should there |
|
924 | # Should each extension invent its own tag type? Should there | |
925 | # be one tagtype for all such "virtual" tags? Or is the status |
|
925 | # be one tagtype for all such "virtual" tags? Or is the status | |
926 | # quo fine? |
|
926 | # quo fine? | |
927 |
|
927 | |||
928 |
|
928 | |||
929 | # map tag name to (node, hist) |
|
929 | # map tag name to (node, hist) | |
930 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
930 | alltags = tagsmod.findglobaltags(self.ui, self) | |
931 | # map tag name to tag type |
|
931 | # map tag name to tag type | |
932 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
932 | tagtypes = dict((tag, 'global') for tag in alltags) | |
933 |
|
933 | |||
934 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
934 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
935 |
|
935 | |||
936 | # Build the return dicts. Have to re-encode tag names because |
|
936 | # Build the return dicts. Have to re-encode tag names because | |
937 | # the tags module always uses UTF-8 (in order not to lose info |
|
937 | # the tags module always uses UTF-8 (in order not to lose info | |
938 | # writing to the cache), but the rest of Mercurial wants them in |
|
938 | # writing to the cache), but the rest of Mercurial wants them in | |
939 | # local encoding. |
|
939 | # local encoding. | |
940 | tags = {} |
|
940 | tags = {} | |
941 | for (name, (node, hist)) in alltags.iteritems(): |
|
941 | for (name, (node, hist)) in alltags.iteritems(): | |
942 | if node != nullid: |
|
942 | if node != nullid: | |
943 | tags[encoding.tolocal(name)] = node |
|
943 | tags[encoding.tolocal(name)] = node | |
944 | tags['tip'] = self.changelog.tip() |
|
944 | tags['tip'] = self.changelog.tip() | |
945 | tagtypes = dict([(encoding.tolocal(name), value) |
|
945 | tagtypes = dict([(encoding.tolocal(name), value) | |
946 | for (name, value) in tagtypes.iteritems()]) |
|
946 | for (name, value) in tagtypes.iteritems()]) | |
947 | return (tags, tagtypes) |
|
947 | return (tags, tagtypes) | |
948 |
|
948 | |||
949 | def tagtype(self, tagname): |
|
949 | def tagtype(self, tagname): | |
950 | ''' |
|
950 | ''' | |
951 | return the type of the given tag. result can be: |
|
951 | return the type of the given tag. result can be: | |
952 |
|
952 | |||
953 | 'local' : a local tag |
|
953 | 'local' : a local tag | |
954 | 'global' : a global tag |
|
954 | 'global' : a global tag | |
955 | None : tag does not exist |
|
955 | None : tag does not exist | |
956 | ''' |
|
956 | ''' | |
957 |
|
957 | |||
958 | return self._tagscache.tagtypes.get(tagname) |
|
958 | return self._tagscache.tagtypes.get(tagname) | |
959 |
|
959 | |||
960 | def tagslist(self): |
|
960 | def tagslist(self): | |
961 | '''return a list of tags ordered by revision''' |
|
961 | '''return a list of tags ordered by revision''' | |
962 | if not self._tagscache.tagslist: |
|
962 | if not self._tagscache.tagslist: | |
963 | l = [] |
|
963 | l = [] | |
964 | for t, n in self.tags().iteritems(): |
|
964 | for t, n in self.tags().iteritems(): | |
965 | l.append((self.changelog.rev(n), t, n)) |
|
965 | l.append((self.changelog.rev(n), t, n)) | |
966 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
966 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
967 |
|
967 | |||
968 | return self._tagscache.tagslist |
|
968 | return self._tagscache.tagslist | |
969 |
|
969 | |||
970 | def nodetags(self, node): |
|
970 | def nodetags(self, node): | |
971 | '''return the tags associated with a node''' |
|
971 | '''return the tags associated with a node''' | |
972 | if not self._tagscache.nodetagscache: |
|
972 | if not self._tagscache.nodetagscache: | |
973 | nodetagscache = {} |
|
973 | nodetagscache = {} | |
974 | for t, n in self._tagscache.tags.iteritems(): |
|
974 | for t, n in self._tagscache.tags.iteritems(): | |
975 | nodetagscache.setdefault(n, []).append(t) |
|
975 | nodetagscache.setdefault(n, []).append(t) | |
976 | for tags in nodetagscache.itervalues(): |
|
976 | for tags in nodetagscache.itervalues(): | |
977 | tags.sort() |
|
977 | tags.sort() | |
978 | self._tagscache.nodetagscache = nodetagscache |
|
978 | self._tagscache.nodetagscache = nodetagscache | |
979 | return self._tagscache.nodetagscache.get(node, []) |
|
979 | return self._tagscache.nodetagscache.get(node, []) | |
980 |
|
980 | |||
981 | def nodebookmarks(self, node): |
|
981 | def nodebookmarks(self, node): | |
982 | """return the list of bookmarks pointing to the specified node""" |
|
982 | """return the list of bookmarks pointing to the specified node""" | |
983 | marks = [] |
|
983 | marks = [] | |
984 | for bookmark, n in self._bookmarks.iteritems(): |
|
984 | for bookmark, n in self._bookmarks.iteritems(): | |
985 | if n == node: |
|
985 | if n == node: | |
986 | marks.append(bookmark) |
|
986 | marks.append(bookmark) | |
987 | return sorted(marks) |
|
987 | return sorted(marks) | |
988 |
|
988 | |||
989 | def branchmap(self): |
|
989 | def branchmap(self): | |
990 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
990 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
991 | ordered by increasing revision number''' |
|
991 | ordered by increasing revision number''' | |
992 | branchmap.updatecache(self) |
|
992 | branchmap.updatecache(self) | |
993 | return self._branchcaches[self.filtername] |
|
993 | return self._branchcaches[self.filtername] | |
994 |
|
994 | |||
995 | @unfilteredmethod |
|
995 | @unfilteredmethod | |
996 | def revbranchcache(self): |
|
996 | def revbranchcache(self): | |
997 | if not self._revbranchcache: |
|
997 | if not self._revbranchcache: | |
998 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
998 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
999 | return self._revbranchcache |
|
999 | return self._revbranchcache | |
1000 |
|
1000 | |||
1001 | def branchtip(self, branch, ignoremissing=False): |
|
1001 | def branchtip(self, branch, ignoremissing=False): | |
1002 | '''return the tip node for a given branch |
|
1002 | '''return the tip node for a given branch | |
1003 |
|
1003 | |||
1004 | If ignoremissing is True, then this method will not raise an error. |
|
1004 | If ignoremissing is True, then this method will not raise an error. | |
1005 | This is helpful for callers that only expect None for a missing branch |
|
1005 | This is helpful for callers that only expect None for a missing branch | |
1006 | (e.g. namespace). |
|
1006 | (e.g. namespace). | |
1007 |
|
1007 | |||
1008 | ''' |
|
1008 | ''' | |
1009 | try: |
|
1009 | try: | |
1010 | return self.branchmap().branchtip(branch) |
|
1010 | return self.branchmap().branchtip(branch) | |
1011 | except KeyError: |
|
1011 | except KeyError: | |
1012 | if not ignoremissing: |
|
1012 | if not ignoremissing: | |
1013 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
1013 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
1014 | else: |
|
1014 | else: | |
1015 | pass |
|
1015 | pass | |
1016 |
|
1016 | |||
1017 | def lookup(self, key): |
|
1017 | def lookup(self, key): | |
1018 | return self[key].node() |
|
1018 | return self[key].node() | |
1019 |
|
1019 | |||
1020 | def lookupbranch(self, key, remote=None): |
|
1020 | def lookupbranch(self, key, remote=None): | |
1021 | repo = remote or self |
|
1021 | repo = remote or self | |
1022 | if key in repo.branchmap(): |
|
1022 | if key in repo.branchmap(): | |
1023 | return key |
|
1023 | return key | |
1024 |
|
1024 | |||
1025 | repo = (remote and remote.local()) and remote or self |
|
1025 | repo = (remote and remote.local()) and remote or self | |
1026 | return repo[key].branch() |
|
1026 | return repo[key].branch() | |
1027 |
|
1027 | |||
1028 | def known(self, nodes): |
|
1028 | def known(self, nodes): | |
1029 | cl = self.changelog |
|
1029 | cl = self.changelog | |
1030 | nm = cl.nodemap |
|
1030 | nm = cl.nodemap | |
1031 | filtered = cl.filteredrevs |
|
1031 | filtered = cl.filteredrevs | |
1032 | result = [] |
|
1032 | result = [] | |
1033 | for n in nodes: |
|
1033 | for n in nodes: | |
1034 | r = nm.get(n) |
|
1034 | r = nm.get(n) | |
1035 | resp = not (r is None or r in filtered) |
|
1035 | resp = not (r is None or r in filtered) | |
1036 | result.append(resp) |
|
1036 | result.append(resp) | |
1037 | return result |
|
1037 | return result | |
1038 |
|
1038 | |||
1039 | def local(self): |
|
1039 | def local(self): | |
1040 | return self |
|
1040 | return self | |
1041 |
|
1041 | |||
1042 | def publishing(self): |
|
1042 | def publishing(self): | |
1043 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
1043 | # it's safe (and desirable) to trust the publish flag unconditionally | |
1044 | # so that we don't finalize changes shared between users via ssh or nfs |
|
1044 | # so that we don't finalize changes shared between users via ssh or nfs | |
1045 | return self.ui.configbool('phases', 'publish', untrusted=True) |
|
1045 | return self.ui.configbool('phases', 'publish', untrusted=True) | |
1046 |
|
1046 | |||
1047 | def cancopy(self): |
|
1047 | def cancopy(self): | |
1048 | # so statichttprepo's override of local() works |
|
1048 | # so statichttprepo's override of local() works | |
1049 | if not self.local(): |
|
1049 | if not self.local(): | |
1050 | return False |
|
1050 | return False | |
1051 | if not self.publishing(): |
|
1051 | if not self.publishing(): | |
1052 | return True |
|
1052 | return True | |
1053 | # if publishing we can't copy if there is filtered content |
|
1053 | # if publishing we can't copy if there is filtered content | |
1054 | return not self.filtered('visible').changelog.filteredrevs |
|
1054 | return not self.filtered('visible').changelog.filteredrevs | |
1055 |
|
1055 | |||
1056 | def shared(self): |
|
1056 | def shared(self): | |
1057 | '''the type of shared repository (None if not shared)''' |
|
1057 | '''the type of shared repository (None if not shared)''' | |
1058 | if self.sharedpath != self.path: |
|
1058 | if self.sharedpath != self.path: | |
1059 | return 'store' |
|
1059 | return 'store' | |
1060 | return None |
|
1060 | return None | |
1061 |
|
1061 | |||
1062 | def wjoin(self, f, *insidef): |
|
1062 | def wjoin(self, f, *insidef): | |
1063 | return self.vfs.reljoin(self.root, f, *insidef) |
|
1063 | return self.vfs.reljoin(self.root, f, *insidef) | |
1064 |
|
1064 | |||
1065 | def file(self, f): |
|
1065 | def file(self, f): | |
1066 | if f[0] == '/': |
|
1066 | if f[0] == '/': | |
1067 | f = f[1:] |
|
1067 | f = f[1:] | |
1068 | return filelog.filelog(self.svfs, f) |
|
1068 | return filelog.filelog(self.svfs, f) | |
1069 |
|
1069 | |||
1070 | def changectx(self, changeid): |
|
1070 | def changectx(self, changeid): | |
1071 | return self[changeid] |
|
1071 | return self[changeid] | |
1072 |
|
1072 | |||
1073 | def setparents(self, p1, p2=nullid): |
|
1073 | def setparents(self, p1, p2=nullid): | |
1074 | with self.dirstate.parentchange(): |
|
1074 | with self.dirstate.parentchange(): | |
1075 | copies = self.dirstate.setparents(p1, p2) |
|
1075 | copies = self.dirstate.setparents(p1, p2) | |
1076 | pctx = self[p1] |
|
1076 | pctx = self[p1] | |
1077 | if copies: |
|
1077 | if copies: | |
1078 | # Adjust copy records, the dirstate cannot do it, it |
|
1078 | # Adjust copy records, the dirstate cannot do it, it | |
1079 | # requires access to parents manifests. Preserve them |
|
1079 | # requires access to parents manifests. Preserve them | |
1080 | # only for entries added to first parent. |
|
1080 | # only for entries added to first parent. | |
1081 | for f in copies: |
|
1081 | for f in copies: | |
1082 | if f not in pctx and copies[f] in pctx: |
|
1082 | if f not in pctx and copies[f] in pctx: | |
1083 | self.dirstate.copy(copies[f], f) |
|
1083 | self.dirstate.copy(copies[f], f) | |
1084 | if p2 == nullid: |
|
1084 | if p2 == nullid: | |
1085 | for f, s in sorted(self.dirstate.copies().items()): |
|
1085 | for f, s in sorted(self.dirstate.copies().items()): | |
1086 | if f not in pctx and s not in pctx: |
|
1086 | if f not in pctx and s not in pctx: | |
1087 | self.dirstate.copy(None, f) |
|
1087 | self.dirstate.copy(None, f) | |
1088 |
|
1088 | |||
1089 | def filectx(self, path, changeid=None, fileid=None): |
|
1089 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
1090 | """changeid can be a changeset revision, node, or tag. |
|
1090 | """changeid can be a changeset revision, node, or tag. | |
1091 | fileid can be a file revision or node.""" |
|
1091 | fileid can be a file revision or node.""" | |
1092 |
return context.filectx(self, path, changeid, fileid |
|
1092 | return context.filectx(self, path, changeid, fileid, | |
|
1093 | changectx=changectx) | |||
1093 |
|
1094 | |||
1094 | def getcwd(self): |
|
1095 | def getcwd(self): | |
1095 | return self.dirstate.getcwd() |
|
1096 | return self.dirstate.getcwd() | |
1096 |
|
1097 | |||
1097 | def pathto(self, f, cwd=None): |
|
1098 | def pathto(self, f, cwd=None): | |
1098 | return self.dirstate.pathto(f, cwd) |
|
1099 | return self.dirstate.pathto(f, cwd) | |
1099 |
|
1100 | |||
1100 | def _loadfilter(self, filter): |
|
1101 | def _loadfilter(self, filter): | |
1101 | if filter not in self._filterpats: |
|
1102 | if filter not in self._filterpats: | |
1102 | l = [] |
|
1103 | l = [] | |
1103 | for pat, cmd in self.ui.configitems(filter): |
|
1104 | for pat, cmd in self.ui.configitems(filter): | |
1104 | if cmd == '!': |
|
1105 | if cmd == '!': | |
1105 | continue |
|
1106 | continue | |
1106 | mf = matchmod.match(self.root, '', [pat]) |
|
1107 | mf = matchmod.match(self.root, '', [pat]) | |
1107 | fn = None |
|
1108 | fn = None | |
1108 | params = cmd |
|
1109 | params = cmd | |
1109 | for name, filterfn in self._datafilters.iteritems(): |
|
1110 | for name, filterfn in self._datafilters.iteritems(): | |
1110 | if cmd.startswith(name): |
|
1111 | if cmd.startswith(name): | |
1111 | fn = filterfn |
|
1112 | fn = filterfn | |
1112 | params = cmd[len(name):].lstrip() |
|
1113 | params = cmd[len(name):].lstrip() | |
1113 | break |
|
1114 | break | |
1114 | if not fn: |
|
1115 | if not fn: | |
1115 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
1116 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
1116 | # Wrap old filters not supporting keyword arguments |
|
1117 | # Wrap old filters not supporting keyword arguments | |
1117 | if not pycompat.getargspec(fn)[2]: |
|
1118 | if not pycompat.getargspec(fn)[2]: | |
1118 | oldfn = fn |
|
1119 | oldfn = fn | |
1119 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
1120 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
1120 | l.append((mf, fn, params)) |
|
1121 | l.append((mf, fn, params)) | |
1121 | self._filterpats[filter] = l |
|
1122 | self._filterpats[filter] = l | |
1122 | return self._filterpats[filter] |
|
1123 | return self._filterpats[filter] | |
1123 |
|
1124 | |||
1124 | def _filter(self, filterpats, filename, data): |
|
1125 | def _filter(self, filterpats, filename, data): | |
1125 | for mf, fn, cmd in filterpats: |
|
1126 | for mf, fn, cmd in filterpats: | |
1126 | if mf(filename): |
|
1127 | if mf(filename): | |
1127 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
1128 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
1128 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
1129 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
1129 | break |
|
1130 | break | |
1130 |
|
1131 | |||
1131 | return data |
|
1132 | return data | |
1132 |
|
1133 | |||
1133 | @unfilteredpropertycache |
|
1134 | @unfilteredpropertycache | |
1134 | def _encodefilterpats(self): |
|
1135 | def _encodefilterpats(self): | |
1135 | return self._loadfilter('encode') |
|
1136 | return self._loadfilter('encode') | |
1136 |
|
1137 | |||
1137 | @unfilteredpropertycache |
|
1138 | @unfilteredpropertycache | |
1138 | def _decodefilterpats(self): |
|
1139 | def _decodefilterpats(self): | |
1139 | return self._loadfilter('decode') |
|
1140 | return self._loadfilter('decode') | |
1140 |
|
1141 | |||
1141 | def adddatafilter(self, name, filter): |
|
1142 | def adddatafilter(self, name, filter): | |
1142 | self._datafilters[name] = filter |
|
1143 | self._datafilters[name] = filter | |
1143 |
|
1144 | |||
1144 | def wread(self, filename): |
|
1145 | def wread(self, filename): | |
1145 | if self.wvfs.islink(filename): |
|
1146 | if self.wvfs.islink(filename): | |
1146 | data = self.wvfs.readlink(filename) |
|
1147 | data = self.wvfs.readlink(filename) | |
1147 | else: |
|
1148 | else: | |
1148 | data = self.wvfs.read(filename) |
|
1149 | data = self.wvfs.read(filename) | |
1149 | return self._filter(self._encodefilterpats, filename, data) |
|
1150 | return self._filter(self._encodefilterpats, filename, data) | |
1150 |
|
1151 | |||
1151 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
1152 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
1152 | """write ``data`` into ``filename`` in the working directory |
|
1153 | """write ``data`` into ``filename`` in the working directory | |
1153 |
|
1154 | |||
1154 | This returns length of written (maybe decoded) data. |
|
1155 | This returns length of written (maybe decoded) data. | |
1155 | """ |
|
1156 | """ | |
1156 | data = self._filter(self._decodefilterpats, filename, data) |
|
1157 | data = self._filter(self._decodefilterpats, filename, data) | |
1157 | if 'l' in flags: |
|
1158 | if 'l' in flags: | |
1158 | self.wvfs.symlink(data, filename) |
|
1159 | self.wvfs.symlink(data, filename) | |
1159 | else: |
|
1160 | else: | |
1160 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, |
|
1161 | self.wvfs.write(filename, data, backgroundclose=backgroundclose, | |
1161 | **kwargs) |
|
1162 | **kwargs) | |
1162 | if 'x' in flags: |
|
1163 | if 'x' in flags: | |
1163 | self.wvfs.setflags(filename, False, True) |
|
1164 | self.wvfs.setflags(filename, False, True) | |
1164 | else: |
|
1165 | else: | |
1165 | self.wvfs.setflags(filename, False, False) |
|
1166 | self.wvfs.setflags(filename, False, False) | |
1166 | return len(data) |
|
1167 | return len(data) | |
1167 |
|
1168 | |||
1168 | def wwritedata(self, filename, data): |
|
1169 | def wwritedata(self, filename, data): | |
1169 | return self._filter(self._decodefilterpats, filename, data) |
|
1170 | return self._filter(self._decodefilterpats, filename, data) | |
1170 |
|
1171 | |||
1171 | def currenttransaction(self): |
|
1172 | def currenttransaction(self): | |
1172 | """return the current transaction or None if non exists""" |
|
1173 | """return the current transaction or None if non exists""" | |
1173 | if self._transref: |
|
1174 | if self._transref: | |
1174 | tr = self._transref() |
|
1175 | tr = self._transref() | |
1175 | else: |
|
1176 | else: | |
1176 | tr = None |
|
1177 | tr = None | |
1177 |
|
1178 | |||
1178 | if tr and tr.running(): |
|
1179 | if tr and tr.running(): | |
1179 | return tr |
|
1180 | return tr | |
1180 | return None |
|
1181 | return None | |
1181 |
|
1182 | |||
1182 | def transaction(self, desc, report=None): |
|
1183 | def transaction(self, desc, report=None): | |
1183 | if (self.ui.configbool('devel', 'all-warnings') |
|
1184 | if (self.ui.configbool('devel', 'all-warnings') | |
1184 | or self.ui.configbool('devel', 'check-locks')): |
|
1185 | or self.ui.configbool('devel', 'check-locks')): | |
1185 | if self._currentlock(self._lockref) is None: |
|
1186 | if self._currentlock(self._lockref) is None: | |
1186 | raise error.ProgrammingError('transaction requires locking') |
|
1187 | raise error.ProgrammingError('transaction requires locking') | |
1187 | tr = self.currenttransaction() |
|
1188 | tr = self.currenttransaction() | |
1188 | if tr is not None: |
|
1189 | if tr is not None: | |
1189 | return tr.nest(name=desc) |
|
1190 | return tr.nest(name=desc) | |
1190 |
|
1191 | |||
1191 | # abort here if the journal already exists |
|
1192 | # abort here if the journal already exists | |
1192 | if self.svfs.exists("journal"): |
|
1193 | if self.svfs.exists("journal"): | |
1193 | raise error.RepoError( |
|
1194 | raise error.RepoError( | |
1194 | _("abandoned transaction found"), |
|
1195 | _("abandoned transaction found"), | |
1195 | hint=_("run 'hg recover' to clean up transaction")) |
|
1196 | hint=_("run 'hg recover' to clean up transaction")) | |
1196 |
|
1197 | |||
1197 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
1198 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
1198 | ha = hex(hashlib.sha1(idbase).digest()) |
|
1199 | ha = hex(hashlib.sha1(idbase).digest()) | |
1199 | txnid = 'TXN:' + ha |
|
1200 | txnid = 'TXN:' + ha | |
1200 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
1201 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
1201 |
|
1202 | |||
1202 | self._writejournal(desc) |
|
1203 | self._writejournal(desc) | |
1203 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
1204 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
1204 | if report: |
|
1205 | if report: | |
1205 | rp = report |
|
1206 | rp = report | |
1206 | else: |
|
1207 | else: | |
1207 | rp = self.ui.warn |
|
1208 | rp = self.ui.warn | |
1208 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
1209 | vfsmap = {'plain': self.vfs} # root of .hg/ | |
1209 | # we must avoid cyclic reference between repo and transaction. |
|
1210 | # we must avoid cyclic reference between repo and transaction. | |
1210 | reporef = weakref.ref(self) |
|
1211 | reporef = weakref.ref(self) | |
1211 | # Code to track tag movement |
|
1212 | # Code to track tag movement | |
1212 | # |
|
1213 | # | |
1213 | # Since tags are all handled as file content, it is actually quite hard |
|
1214 | # Since tags are all handled as file content, it is actually quite hard | |
1214 | # to track these movement from a code perspective. So we fallback to a |
|
1215 | # to track these movement from a code perspective. So we fallback to a | |
1215 | # tracking at the repository level. One could envision to track changes |
|
1216 | # tracking at the repository level. One could envision to track changes | |
1216 | # to the '.hgtags' file through changegroup apply but that fails to |
|
1217 | # to the '.hgtags' file through changegroup apply but that fails to | |
1217 | # cope with case where transaction expose new heads without changegroup |
|
1218 | # cope with case where transaction expose new heads without changegroup | |
1218 | # being involved (eg: phase movement). |
|
1219 | # being involved (eg: phase movement). | |
1219 | # |
|
1220 | # | |
1220 | # For now, We gate the feature behind a flag since this likely comes |
|
1221 | # For now, We gate the feature behind a flag since this likely comes | |
1221 | # with performance impacts. The current code run more often than needed |
|
1222 | # with performance impacts. The current code run more often than needed | |
1222 | # and do not use caches as much as it could. The current focus is on |
|
1223 | # and do not use caches as much as it could. The current focus is on | |
1223 | # the behavior of the feature so we disable it by default. The flag |
|
1224 | # the behavior of the feature so we disable it by default. The flag | |
1224 | # will be removed when we are happy with the performance impact. |
|
1225 | # will be removed when we are happy with the performance impact. | |
1225 | # |
|
1226 | # | |
1226 | # Once this feature is no longer experimental move the following |
|
1227 | # Once this feature is no longer experimental move the following | |
1227 | # documentation to the appropriate help section: |
|
1228 | # documentation to the appropriate help section: | |
1228 | # |
|
1229 | # | |
1229 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
1230 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
1230 | # tags (new or changed or deleted tags). In addition the details of |
|
1231 | # tags (new or changed or deleted tags). In addition the details of | |
1231 | # these changes are made available in a file at: |
|
1232 | # these changes are made available in a file at: | |
1232 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
1233 | # ``REPOROOT/.hg/changes/tags.changes``. | |
1233 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
1234 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
1234 | # might exist from a previous transaction even if no tag were touched |
|
1235 | # might exist from a previous transaction even if no tag were touched | |
1235 | # in this one. Changes are recorded in a line base format:: |
|
1236 | # in this one. Changes are recorded in a line base format:: | |
1236 | # |
|
1237 | # | |
1237 | # <action> <hex-node> <tag-name>\n |
|
1238 | # <action> <hex-node> <tag-name>\n | |
1238 | # |
|
1239 | # | |
1239 | # Actions are defined as follow: |
|
1240 | # Actions are defined as follow: | |
1240 | # "-R": tag is removed, |
|
1241 | # "-R": tag is removed, | |
1241 | # "+A": tag is added, |
|
1242 | # "+A": tag is added, | |
1242 | # "-M": tag is moved (old value), |
|
1243 | # "-M": tag is moved (old value), | |
1243 | # "+M": tag is moved (new value), |
|
1244 | # "+M": tag is moved (new value), | |
1244 | tracktags = lambda x: None |
|
1245 | tracktags = lambda x: None | |
1245 | # experimental config: experimental.hook-track-tags |
|
1246 | # experimental config: experimental.hook-track-tags | |
1246 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') |
|
1247 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags') | |
1247 | if desc != 'strip' and shouldtracktags: |
|
1248 | if desc != 'strip' and shouldtracktags: | |
1248 | oldheads = self.changelog.headrevs() |
|
1249 | oldheads = self.changelog.headrevs() | |
1249 | def tracktags(tr2): |
|
1250 | def tracktags(tr2): | |
1250 | repo = reporef() |
|
1251 | repo = reporef() | |
1251 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1252 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
1252 | newheads = repo.changelog.headrevs() |
|
1253 | newheads = repo.changelog.headrevs() | |
1253 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1254 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
1254 | # notes: we compare lists here. |
|
1255 | # notes: we compare lists here. | |
1255 | # As we do it only once buiding set would not be cheaper |
|
1256 | # As we do it only once buiding set would not be cheaper | |
1256 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1257 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
1257 | if changes: |
|
1258 | if changes: | |
1258 | tr2.hookargs['tag_moved'] = '1' |
|
1259 | tr2.hookargs['tag_moved'] = '1' | |
1259 | with repo.vfs('changes/tags.changes', 'w', |
|
1260 | with repo.vfs('changes/tags.changes', 'w', | |
1260 | atomictemp=True) as changesfile: |
|
1261 | atomictemp=True) as changesfile: | |
1261 | # note: we do not register the file to the transaction |
|
1262 | # note: we do not register the file to the transaction | |
1262 | # because we needs it to still exist on the transaction |
|
1263 | # because we needs it to still exist on the transaction | |
1263 | # is close (for txnclose hooks) |
|
1264 | # is close (for txnclose hooks) | |
1264 | tagsmod.writediff(changesfile, changes) |
|
1265 | tagsmod.writediff(changesfile, changes) | |
1265 | def validate(tr2): |
|
1266 | def validate(tr2): | |
1266 | """will run pre-closing hooks""" |
|
1267 | """will run pre-closing hooks""" | |
1267 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1268 | # XXX the transaction API is a bit lacking here so we take a hacky | |
1268 | # path for now |
|
1269 | # path for now | |
1269 | # |
|
1270 | # | |
1270 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1271 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
1271 | # dict is copied before these run. In addition we needs the data |
|
1272 | # dict is copied before these run. In addition we needs the data | |
1272 | # available to in memory hooks too. |
|
1273 | # available to in memory hooks too. | |
1273 | # |
|
1274 | # | |
1274 | # Moreover, we also need to make sure this runs before txnclose |
|
1275 | # Moreover, we also need to make sure this runs before txnclose | |
1275 | # hooks and there is no "pending" mechanism that would execute |
|
1276 | # hooks and there is no "pending" mechanism that would execute | |
1276 | # logic only if hooks are about to run. |
|
1277 | # logic only if hooks are about to run. | |
1277 | # |
|
1278 | # | |
1278 | # Fixing this limitation of the transaction is also needed to track |
|
1279 | # Fixing this limitation of the transaction is also needed to track | |
1279 | # other families of changes (bookmarks, phases, obsolescence). |
|
1280 | # other families of changes (bookmarks, phases, obsolescence). | |
1280 | # |
|
1281 | # | |
1281 | # This will have to be fixed before we remove the experimental |
|
1282 | # This will have to be fixed before we remove the experimental | |
1282 | # gating. |
|
1283 | # gating. | |
1283 | tracktags(tr2) |
|
1284 | tracktags(tr2) | |
1284 | repo = reporef() |
|
1285 | repo = reporef() | |
1285 | if repo.ui.configbool('experimental', 'single-head-per-branch'): |
|
1286 | if repo.ui.configbool('experimental', 'single-head-per-branch'): | |
1286 | scmutil.enforcesinglehead(repo, tr2, desc) |
|
1287 | scmutil.enforcesinglehead(repo, tr2, desc) | |
1287 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): |
|
1288 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): | |
1288 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): |
|
1289 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): | |
1289 | args = tr.hookargs.copy() |
|
1290 | args = tr.hookargs.copy() | |
1290 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1291 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1291 | repo.hook('pretxnclose-bookmark', throw=True, |
|
1292 | repo.hook('pretxnclose-bookmark', throw=True, | |
1292 | txnname=desc, |
|
1293 | txnname=desc, | |
1293 | **pycompat.strkwargs(args)) |
|
1294 | **pycompat.strkwargs(args)) | |
1294 | if hook.hashook(repo.ui, 'pretxnclose-phase'): |
|
1295 | if hook.hashook(repo.ui, 'pretxnclose-phase'): | |
1295 | cl = repo.unfiltered().changelog |
|
1296 | cl = repo.unfiltered().changelog | |
1296 | for rev, (old, new) in tr.changes['phases'].items(): |
|
1297 | for rev, (old, new) in tr.changes['phases'].items(): | |
1297 | args = tr.hookargs.copy() |
|
1298 | args = tr.hookargs.copy() | |
1298 | node = hex(cl.node(rev)) |
|
1299 | node = hex(cl.node(rev)) | |
1299 | args.update(phases.preparehookargs(node, old, new)) |
|
1300 | args.update(phases.preparehookargs(node, old, new)) | |
1300 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, |
|
1301 | repo.hook('pretxnclose-phase', throw=True, txnname=desc, | |
1301 | **pycompat.strkwargs(args)) |
|
1302 | **pycompat.strkwargs(args)) | |
1302 |
|
1303 | |||
1303 | repo.hook('pretxnclose', throw=True, |
|
1304 | repo.hook('pretxnclose', throw=True, | |
1304 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1305 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) | |
1305 | def releasefn(tr, success): |
|
1306 | def releasefn(tr, success): | |
1306 | repo = reporef() |
|
1307 | repo = reporef() | |
1307 | if success: |
|
1308 | if success: | |
1308 | # this should be explicitly invoked here, because |
|
1309 | # this should be explicitly invoked here, because | |
1309 | # in-memory changes aren't written out at closing |
|
1310 | # in-memory changes aren't written out at closing | |
1310 | # transaction, if tr.addfilegenerator (via |
|
1311 | # transaction, if tr.addfilegenerator (via | |
1311 | # dirstate.write or so) isn't invoked while |
|
1312 | # dirstate.write or so) isn't invoked while | |
1312 | # transaction running |
|
1313 | # transaction running | |
1313 | repo.dirstate.write(None) |
|
1314 | repo.dirstate.write(None) | |
1314 | else: |
|
1315 | else: | |
1315 | # discard all changes (including ones already written |
|
1316 | # discard all changes (including ones already written | |
1316 | # out) in this transaction |
|
1317 | # out) in this transaction | |
1317 | repo.dirstate.restorebackup(None, 'journal.dirstate') |
|
1318 | repo.dirstate.restorebackup(None, 'journal.dirstate') | |
1318 |
|
1319 | |||
1319 | repo.invalidate(clearfilecache=True) |
|
1320 | repo.invalidate(clearfilecache=True) | |
1320 |
|
1321 | |||
1321 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1322 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1322 | "journal", |
|
1323 | "journal", | |
1323 | "undo", |
|
1324 | "undo", | |
1324 | aftertrans(renames), |
|
1325 | aftertrans(renames), | |
1325 | self.store.createmode, |
|
1326 | self.store.createmode, | |
1326 | validator=validate, |
|
1327 | validator=validate, | |
1327 | releasefn=releasefn, |
|
1328 | releasefn=releasefn, | |
1328 | checkambigfiles=_cachedfiles, |
|
1329 | checkambigfiles=_cachedfiles, | |
1329 | name=desc) |
|
1330 | name=desc) | |
1330 | tr.changes['revs'] = xrange(0, 0) |
|
1331 | tr.changes['revs'] = xrange(0, 0) | |
1331 | tr.changes['obsmarkers'] = set() |
|
1332 | tr.changes['obsmarkers'] = set() | |
1332 | tr.changes['phases'] = {} |
|
1333 | tr.changes['phases'] = {} | |
1333 | tr.changes['bookmarks'] = {} |
|
1334 | tr.changes['bookmarks'] = {} | |
1334 |
|
1335 | |||
1335 | tr.hookargs['txnid'] = txnid |
|
1336 | tr.hookargs['txnid'] = txnid | |
1336 | # note: writing the fncache only during finalize mean that the file is |
|
1337 | # note: writing the fncache only during finalize mean that the file is | |
1337 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1338 | # outdated when running hooks. As fncache is used for streaming clone, | |
1338 | # this is not expected to break anything that happen during the hooks. |
|
1339 | # this is not expected to break anything that happen during the hooks. | |
1339 | tr.addfinalize('flush-fncache', self.store.write) |
|
1340 | tr.addfinalize('flush-fncache', self.store.write) | |
1340 | def txnclosehook(tr2): |
|
1341 | def txnclosehook(tr2): | |
1341 | """To be run if transaction is successful, will schedule a hook run |
|
1342 | """To be run if transaction is successful, will schedule a hook run | |
1342 | """ |
|
1343 | """ | |
1343 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1344 | # Don't reference tr2 in hook() so we don't hold a reference. | |
1344 | # This reduces memory consumption when there are multiple |
|
1345 | # This reduces memory consumption when there are multiple | |
1345 | # transactions per lock. This can likely go away if issue5045 |
|
1346 | # transactions per lock. This can likely go away if issue5045 | |
1346 | # fixes the function accumulation. |
|
1347 | # fixes the function accumulation. | |
1347 | hookargs = tr2.hookargs |
|
1348 | hookargs = tr2.hookargs | |
1348 |
|
1349 | |||
1349 | def hookfunc(): |
|
1350 | def hookfunc(): | |
1350 | repo = reporef() |
|
1351 | repo = reporef() | |
1351 | if hook.hashook(repo.ui, 'txnclose-bookmark'): |
|
1352 | if hook.hashook(repo.ui, 'txnclose-bookmark'): | |
1352 | bmchanges = sorted(tr.changes['bookmarks'].items()) |
|
1353 | bmchanges = sorted(tr.changes['bookmarks'].items()) | |
1353 | for name, (old, new) in bmchanges: |
|
1354 | for name, (old, new) in bmchanges: | |
1354 | args = tr.hookargs.copy() |
|
1355 | args = tr.hookargs.copy() | |
1355 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
1356 | args.update(bookmarks.preparehookargs(name, old, new)) | |
1356 | repo.hook('txnclose-bookmark', throw=False, |
|
1357 | repo.hook('txnclose-bookmark', throw=False, | |
1357 | txnname=desc, **pycompat.strkwargs(args)) |
|
1358 | txnname=desc, **pycompat.strkwargs(args)) | |
1358 |
|
1359 | |||
1359 | if hook.hashook(repo.ui, 'txnclose-phase'): |
|
1360 | if hook.hashook(repo.ui, 'txnclose-phase'): | |
1360 | cl = repo.unfiltered().changelog |
|
1361 | cl = repo.unfiltered().changelog | |
1361 | phasemv = sorted(tr.changes['phases'].items()) |
|
1362 | phasemv = sorted(tr.changes['phases'].items()) | |
1362 | for rev, (old, new) in phasemv: |
|
1363 | for rev, (old, new) in phasemv: | |
1363 | args = tr.hookargs.copy() |
|
1364 | args = tr.hookargs.copy() | |
1364 | node = hex(cl.node(rev)) |
|
1365 | node = hex(cl.node(rev)) | |
1365 | args.update(phases.preparehookargs(node, old, new)) |
|
1366 | args.update(phases.preparehookargs(node, old, new)) | |
1366 | repo.hook('txnclose-phase', throw=False, txnname=desc, |
|
1367 | repo.hook('txnclose-phase', throw=False, txnname=desc, | |
1367 | **pycompat.strkwargs(args)) |
|
1368 | **pycompat.strkwargs(args)) | |
1368 |
|
1369 | |||
1369 | repo.hook('txnclose', throw=False, txnname=desc, |
|
1370 | repo.hook('txnclose', throw=False, txnname=desc, | |
1370 | **pycompat.strkwargs(hookargs)) |
|
1371 | **pycompat.strkwargs(hookargs)) | |
1371 | reporef()._afterlock(hookfunc) |
|
1372 | reporef()._afterlock(hookfunc) | |
1372 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1373 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1373 | # Include a leading "-" to make it happen before the transaction summary |
|
1374 | # Include a leading "-" to make it happen before the transaction summary | |
1374 | # reports registered via scmutil.registersummarycallback() whose names |
|
1375 | # reports registered via scmutil.registersummarycallback() whose names | |
1375 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
1376 | # are 00-txnreport etc. That way, the caches will be warm when the | |
1376 | # callbacks run. |
|
1377 | # callbacks run. | |
1377 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) |
|
1378 | tr.addpostclose('-warm-cache', self._buildcacheupdater(tr)) | |
1378 | def txnaborthook(tr2): |
|
1379 | def txnaborthook(tr2): | |
1379 | """To be run if transaction is aborted |
|
1380 | """To be run if transaction is aborted | |
1380 | """ |
|
1381 | """ | |
1381 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1382 | reporef().hook('txnabort', throw=False, txnname=desc, | |
1382 | **pycompat.strkwargs(tr2.hookargs)) |
|
1383 | **pycompat.strkwargs(tr2.hookargs)) | |
1383 | tr.addabort('txnabort-hook', txnaborthook) |
|
1384 | tr.addabort('txnabort-hook', txnaborthook) | |
1384 | # avoid eager cache invalidation. in-memory data should be identical |
|
1385 | # avoid eager cache invalidation. in-memory data should be identical | |
1385 | # to stored data if transaction has no error. |
|
1386 | # to stored data if transaction has no error. | |
1386 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1387 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1387 | self._transref = weakref.ref(tr) |
|
1388 | self._transref = weakref.ref(tr) | |
1388 | scmutil.registersummarycallback(self, tr, desc) |
|
1389 | scmutil.registersummarycallback(self, tr, desc) | |
1389 | return tr |
|
1390 | return tr | |
1390 |
|
1391 | |||
1391 | def _journalfiles(self): |
|
1392 | def _journalfiles(self): | |
1392 | return ((self.svfs, 'journal'), |
|
1393 | return ((self.svfs, 'journal'), | |
1393 | (self.vfs, 'journal.dirstate'), |
|
1394 | (self.vfs, 'journal.dirstate'), | |
1394 | (self.vfs, 'journal.branch'), |
|
1395 | (self.vfs, 'journal.branch'), | |
1395 | (self.vfs, 'journal.desc'), |
|
1396 | (self.vfs, 'journal.desc'), | |
1396 | (self.vfs, 'journal.bookmarks'), |
|
1397 | (self.vfs, 'journal.bookmarks'), | |
1397 | (self.svfs, 'journal.phaseroots')) |
|
1398 | (self.svfs, 'journal.phaseroots')) | |
1398 |
|
1399 | |||
1399 | def undofiles(self): |
|
1400 | def undofiles(self): | |
1400 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1401 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1401 |
|
1402 | |||
1402 | @unfilteredmethod |
|
1403 | @unfilteredmethod | |
1403 | def _writejournal(self, desc): |
|
1404 | def _writejournal(self, desc): | |
1404 | self.dirstate.savebackup(None, 'journal.dirstate') |
|
1405 | self.dirstate.savebackup(None, 'journal.dirstate') | |
1405 | self.vfs.write("journal.branch", |
|
1406 | self.vfs.write("journal.branch", | |
1406 | encoding.fromlocal(self.dirstate.branch())) |
|
1407 | encoding.fromlocal(self.dirstate.branch())) | |
1407 | self.vfs.write("journal.desc", |
|
1408 | self.vfs.write("journal.desc", | |
1408 | "%d\n%s\n" % (len(self), desc)) |
|
1409 | "%d\n%s\n" % (len(self), desc)) | |
1409 | self.vfs.write("journal.bookmarks", |
|
1410 | self.vfs.write("journal.bookmarks", | |
1410 | self.vfs.tryread("bookmarks")) |
|
1411 | self.vfs.tryread("bookmarks")) | |
1411 | self.svfs.write("journal.phaseroots", |
|
1412 | self.svfs.write("journal.phaseroots", | |
1412 | self.svfs.tryread("phaseroots")) |
|
1413 | self.svfs.tryread("phaseroots")) | |
1413 |
|
1414 | |||
1414 | def recover(self): |
|
1415 | def recover(self): | |
1415 | with self.lock(): |
|
1416 | with self.lock(): | |
1416 | if self.svfs.exists("journal"): |
|
1417 | if self.svfs.exists("journal"): | |
1417 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1418 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1418 | vfsmap = {'': self.svfs, |
|
1419 | vfsmap = {'': self.svfs, | |
1419 | 'plain': self.vfs,} |
|
1420 | 'plain': self.vfs,} | |
1420 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1421 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1421 | self.ui.warn, |
|
1422 | self.ui.warn, | |
1422 | checkambigfiles=_cachedfiles) |
|
1423 | checkambigfiles=_cachedfiles) | |
1423 | self.invalidate() |
|
1424 | self.invalidate() | |
1424 | return True |
|
1425 | return True | |
1425 | else: |
|
1426 | else: | |
1426 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1427 | self.ui.warn(_("no interrupted transaction available\n")) | |
1427 | return False |
|
1428 | return False | |
1428 |
|
1429 | |||
1429 | def rollback(self, dryrun=False, force=False): |
|
1430 | def rollback(self, dryrun=False, force=False): | |
1430 | wlock = lock = dsguard = None |
|
1431 | wlock = lock = dsguard = None | |
1431 | try: |
|
1432 | try: | |
1432 | wlock = self.wlock() |
|
1433 | wlock = self.wlock() | |
1433 | lock = self.lock() |
|
1434 | lock = self.lock() | |
1434 | if self.svfs.exists("undo"): |
|
1435 | if self.svfs.exists("undo"): | |
1435 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
1436 | dsguard = dirstateguard.dirstateguard(self, 'rollback') | |
1436 |
|
1437 | |||
1437 | return self._rollback(dryrun, force, dsguard) |
|
1438 | return self._rollback(dryrun, force, dsguard) | |
1438 | else: |
|
1439 | else: | |
1439 | self.ui.warn(_("no rollback information available\n")) |
|
1440 | self.ui.warn(_("no rollback information available\n")) | |
1440 | return 1 |
|
1441 | return 1 | |
1441 | finally: |
|
1442 | finally: | |
1442 | release(dsguard, lock, wlock) |
|
1443 | release(dsguard, lock, wlock) | |
1443 |
|
1444 | |||
1444 | @unfilteredmethod # Until we get smarter cache management |
|
1445 | @unfilteredmethod # Until we get smarter cache management | |
1445 | def _rollback(self, dryrun, force, dsguard): |
|
1446 | def _rollback(self, dryrun, force, dsguard): | |
1446 | ui = self.ui |
|
1447 | ui = self.ui | |
1447 | try: |
|
1448 | try: | |
1448 | args = self.vfs.read('undo.desc').splitlines() |
|
1449 | args = self.vfs.read('undo.desc').splitlines() | |
1449 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1450 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
1450 | if len(args) >= 3: |
|
1451 | if len(args) >= 3: | |
1451 | detail = args[2] |
|
1452 | detail = args[2] | |
1452 | oldtip = oldlen - 1 |
|
1453 | oldtip = oldlen - 1 | |
1453 |
|
1454 | |||
1454 | if detail and ui.verbose: |
|
1455 | if detail and ui.verbose: | |
1455 | msg = (_('repository tip rolled back to revision %d' |
|
1456 | msg = (_('repository tip rolled back to revision %d' | |
1456 | ' (undo %s: %s)\n') |
|
1457 | ' (undo %s: %s)\n') | |
1457 | % (oldtip, desc, detail)) |
|
1458 | % (oldtip, desc, detail)) | |
1458 | else: |
|
1459 | else: | |
1459 | msg = (_('repository tip rolled back to revision %d' |
|
1460 | msg = (_('repository tip rolled back to revision %d' | |
1460 | ' (undo %s)\n') |
|
1461 | ' (undo %s)\n') | |
1461 | % (oldtip, desc)) |
|
1462 | % (oldtip, desc)) | |
1462 | except IOError: |
|
1463 | except IOError: | |
1463 | msg = _('rolling back unknown transaction\n') |
|
1464 | msg = _('rolling back unknown transaction\n') | |
1464 | desc = None |
|
1465 | desc = None | |
1465 |
|
1466 | |||
1466 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1467 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
1467 | raise error.Abort( |
|
1468 | raise error.Abort( | |
1468 | _('rollback of last commit while not checked out ' |
|
1469 | _('rollback of last commit while not checked out ' | |
1469 | 'may lose data'), hint=_('use -f to force')) |
|
1470 | 'may lose data'), hint=_('use -f to force')) | |
1470 |
|
1471 | |||
1471 | ui.status(msg) |
|
1472 | ui.status(msg) | |
1472 | if dryrun: |
|
1473 | if dryrun: | |
1473 | return 0 |
|
1474 | return 0 | |
1474 |
|
1475 | |||
1475 | parents = self.dirstate.parents() |
|
1476 | parents = self.dirstate.parents() | |
1476 | self.destroying() |
|
1477 | self.destroying() | |
1477 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1478 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
1478 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, |
|
1479 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, | |
1479 | checkambigfiles=_cachedfiles) |
|
1480 | checkambigfiles=_cachedfiles) | |
1480 | if self.vfs.exists('undo.bookmarks'): |
|
1481 | if self.vfs.exists('undo.bookmarks'): | |
1481 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
1482 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) | |
1482 | if self.svfs.exists('undo.phaseroots'): |
|
1483 | if self.svfs.exists('undo.phaseroots'): | |
1483 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
1484 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) | |
1484 | self.invalidate() |
|
1485 | self.invalidate() | |
1485 |
|
1486 | |||
1486 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1487 | parentgone = (parents[0] not in self.changelog.nodemap or | |
1487 | parents[1] not in self.changelog.nodemap) |
|
1488 | parents[1] not in self.changelog.nodemap) | |
1488 | if parentgone: |
|
1489 | if parentgone: | |
1489 | # prevent dirstateguard from overwriting already restored one |
|
1490 | # prevent dirstateguard from overwriting already restored one | |
1490 | dsguard.close() |
|
1491 | dsguard.close() | |
1491 |
|
1492 | |||
1492 | self.dirstate.restorebackup(None, 'undo.dirstate') |
|
1493 | self.dirstate.restorebackup(None, 'undo.dirstate') | |
1493 | try: |
|
1494 | try: | |
1494 | branch = self.vfs.read('undo.branch') |
|
1495 | branch = self.vfs.read('undo.branch') | |
1495 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1496 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
1496 | except IOError: |
|
1497 | except IOError: | |
1497 | ui.warn(_('named branch could not be reset: ' |
|
1498 | ui.warn(_('named branch could not be reset: ' | |
1498 | 'current branch is still \'%s\'\n') |
|
1499 | 'current branch is still \'%s\'\n') | |
1499 | % self.dirstate.branch()) |
|
1500 | % self.dirstate.branch()) | |
1500 |
|
1501 | |||
1501 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
1502 | parents = tuple([p.rev() for p in self[None].parents()]) | |
1502 | if len(parents) > 1: |
|
1503 | if len(parents) > 1: | |
1503 | ui.status(_('working directory now based on ' |
|
1504 | ui.status(_('working directory now based on ' | |
1504 | 'revisions %d and %d\n') % parents) |
|
1505 | 'revisions %d and %d\n') % parents) | |
1505 | else: |
|
1506 | else: | |
1506 | ui.status(_('working directory now based on ' |
|
1507 | ui.status(_('working directory now based on ' | |
1507 | 'revision %d\n') % parents) |
|
1508 | 'revision %d\n') % parents) | |
1508 | mergemod.mergestate.clean(self, self['.'].node()) |
|
1509 | mergemod.mergestate.clean(self, self['.'].node()) | |
1509 |
|
1510 | |||
1510 | # TODO: if we know which new heads may result from this rollback, pass |
|
1511 | # TODO: if we know which new heads may result from this rollback, pass | |
1511 | # them to destroy(), which will prevent the branchhead cache from being |
|
1512 | # them to destroy(), which will prevent the branchhead cache from being | |
1512 | # invalidated. |
|
1513 | # invalidated. | |
1513 | self.destroyed() |
|
1514 | self.destroyed() | |
1514 | return 0 |
|
1515 | return 0 | |
1515 |
|
1516 | |||
1516 | def _buildcacheupdater(self, newtransaction): |
|
1517 | def _buildcacheupdater(self, newtransaction): | |
1517 | """called during transaction to build the callback updating cache |
|
1518 | """called during transaction to build the callback updating cache | |
1518 |
|
1519 | |||
1519 | Lives on the repository to help extension who might want to augment |
|
1520 | Lives on the repository to help extension who might want to augment | |
1520 | this logic. For this purpose, the created transaction is passed to the |
|
1521 | this logic. For this purpose, the created transaction is passed to the | |
1521 | method. |
|
1522 | method. | |
1522 | """ |
|
1523 | """ | |
1523 | # we must avoid cyclic reference between repo and transaction. |
|
1524 | # we must avoid cyclic reference between repo and transaction. | |
1524 | reporef = weakref.ref(self) |
|
1525 | reporef = weakref.ref(self) | |
1525 | def updater(tr): |
|
1526 | def updater(tr): | |
1526 | repo = reporef() |
|
1527 | repo = reporef() | |
1527 | repo.updatecaches(tr) |
|
1528 | repo.updatecaches(tr) | |
1528 | return updater |
|
1529 | return updater | |
1529 |
|
1530 | |||
1530 | @unfilteredmethod |
|
1531 | @unfilteredmethod | |
1531 | def updatecaches(self, tr=None, full=False): |
|
1532 | def updatecaches(self, tr=None, full=False): | |
1532 | """warm appropriate caches |
|
1533 | """warm appropriate caches | |
1533 |
|
1534 | |||
1534 | If this function is called after a transaction closed. The transaction |
|
1535 | If this function is called after a transaction closed. The transaction | |
1535 | will be available in the 'tr' argument. This can be used to selectively |
|
1536 | will be available in the 'tr' argument. This can be used to selectively | |
1536 | update caches relevant to the changes in that transaction. |
|
1537 | update caches relevant to the changes in that transaction. | |
1537 |
|
1538 | |||
1538 | If 'full' is set, make sure all caches the function knows about have |
|
1539 | If 'full' is set, make sure all caches the function knows about have | |
1539 | up-to-date data. Even the ones usually loaded more lazily. |
|
1540 | up-to-date data. Even the ones usually loaded more lazily. | |
1540 | """ |
|
1541 | """ | |
1541 | if tr is not None and tr.hookargs.get('source') == 'strip': |
|
1542 | if tr is not None and tr.hookargs.get('source') == 'strip': | |
1542 | # During strip, many caches are invalid but |
|
1543 | # During strip, many caches are invalid but | |
1543 | # later call to `destroyed` will refresh them. |
|
1544 | # later call to `destroyed` will refresh them. | |
1544 | return |
|
1545 | return | |
1545 |
|
1546 | |||
1546 | if tr is None or tr.changes['revs']: |
|
1547 | if tr is None or tr.changes['revs']: | |
1547 | # updating the unfiltered branchmap should refresh all the others, |
|
1548 | # updating the unfiltered branchmap should refresh all the others, | |
1548 | self.ui.debug('updating the branch cache\n') |
|
1549 | self.ui.debug('updating the branch cache\n') | |
1549 | branchmap.updatecache(self.filtered('served')) |
|
1550 | branchmap.updatecache(self.filtered('served')) | |
1550 |
|
1551 | |||
1551 | if full: |
|
1552 | if full: | |
1552 | rbc = self.revbranchcache() |
|
1553 | rbc = self.revbranchcache() | |
1553 | for r in self.changelog: |
|
1554 | for r in self.changelog: | |
1554 | rbc.branchinfo(r) |
|
1555 | rbc.branchinfo(r) | |
1555 | rbc.write() |
|
1556 | rbc.write() | |
1556 |
|
1557 | |||
1557 | def invalidatecaches(self): |
|
1558 | def invalidatecaches(self): | |
1558 |
|
1559 | |||
1559 | if '_tagscache' in vars(self): |
|
1560 | if '_tagscache' in vars(self): | |
1560 | # can't use delattr on proxy |
|
1561 | # can't use delattr on proxy | |
1561 | del self.__dict__['_tagscache'] |
|
1562 | del self.__dict__['_tagscache'] | |
1562 |
|
1563 | |||
1563 | self.unfiltered()._branchcaches.clear() |
|
1564 | self.unfiltered()._branchcaches.clear() | |
1564 | self.invalidatevolatilesets() |
|
1565 | self.invalidatevolatilesets() | |
1565 | self._sparsesignaturecache.clear() |
|
1566 | self._sparsesignaturecache.clear() | |
1566 |
|
1567 | |||
1567 | def invalidatevolatilesets(self): |
|
1568 | def invalidatevolatilesets(self): | |
1568 | self.filteredrevcache.clear() |
|
1569 | self.filteredrevcache.clear() | |
1569 | obsolete.clearobscaches(self) |
|
1570 | obsolete.clearobscaches(self) | |
1570 |
|
1571 | |||
1571 | def invalidatedirstate(self): |
|
1572 | def invalidatedirstate(self): | |
1572 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1573 | '''Invalidates the dirstate, causing the next call to dirstate | |
1573 | to check if it was modified since the last time it was read, |
|
1574 | to check if it was modified since the last time it was read, | |
1574 | rereading it if it has. |
|
1575 | rereading it if it has. | |
1575 |
|
1576 | |||
1576 | This is different to dirstate.invalidate() that it doesn't always |
|
1577 | This is different to dirstate.invalidate() that it doesn't always | |
1577 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1578 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
1578 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1579 | explicitly read the dirstate again (i.e. restoring it to a previous | |
1579 | known good state).''' |
|
1580 | known good state).''' | |
1580 | if hasunfilteredcache(self, 'dirstate'): |
|
1581 | if hasunfilteredcache(self, 'dirstate'): | |
1581 | for k in self.dirstate._filecache: |
|
1582 | for k in self.dirstate._filecache: | |
1582 | try: |
|
1583 | try: | |
1583 | delattr(self.dirstate, k) |
|
1584 | delattr(self.dirstate, k) | |
1584 | except AttributeError: |
|
1585 | except AttributeError: | |
1585 | pass |
|
1586 | pass | |
1586 | delattr(self.unfiltered(), 'dirstate') |
|
1587 | delattr(self.unfiltered(), 'dirstate') | |
1587 |
|
1588 | |||
1588 | def invalidate(self, clearfilecache=False): |
|
1589 | def invalidate(self, clearfilecache=False): | |
1589 | '''Invalidates both store and non-store parts other than dirstate |
|
1590 | '''Invalidates both store and non-store parts other than dirstate | |
1590 |
|
1591 | |||
1591 | If a transaction is running, invalidation of store is omitted, |
|
1592 | If a transaction is running, invalidation of store is omitted, | |
1592 | because discarding in-memory changes might cause inconsistency |
|
1593 | because discarding in-memory changes might cause inconsistency | |
1593 | (e.g. incomplete fncache causes unintentional failure, but |
|
1594 | (e.g. incomplete fncache causes unintentional failure, but | |
1594 | redundant one doesn't). |
|
1595 | redundant one doesn't). | |
1595 | ''' |
|
1596 | ''' | |
1596 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1597 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
1597 | for k in list(self._filecache.keys()): |
|
1598 | for k in list(self._filecache.keys()): | |
1598 | # dirstate is invalidated separately in invalidatedirstate() |
|
1599 | # dirstate is invalidated separately in invalidatedirstate() | |
1599 | if k == 'dirstate': |
|
1600 | if k == 'dirstate': | |
1600 | continue |
|
1601 | continue | |
1601 | if (k == 'changelog' and |
|
1602 | if (k == 'changelog' and | |
1602 | self.currenttransaction() and |
|
1603 | self.currenttransaction() and | |
1603 | self.changelog._delayed): |
|
1604 | self.changelog._delayed): | |
1604 | # The changelog object may store unwritten revisions. We don't |
|
1605 | # The changelog object may store unwritten revisions. We don't | |
1605 | # want to lose them. |
|
1606 | # want to lose them. | |
1606 | # TODO: Solve the problem instead of working around it. |
|
1607 | # TODO: Solve the problem instead of working around it. | |
1607 | continue |
|
1608 | continue | |
1608 |
|
1609 | |||
1609 | if clearfilecache: |
|
1610 | if clearfilecache: | |
1610 | del self._filecache[k] |
|
1611 | del self._filecache[k] | |
1611 | try: |
|
1612 | try: | |
1612 | delattr(unfiltered, k) |
|
1613 | delattr(unfiltered, k) | |
1613 | except AttributeError: |
|
1614 | except AttributeError: | |
1614 | pass |
|
1615 | pass | |
1615 | self.invalidatecaches() |
|
1616 | self.invalidatecaches() | |
1616 | if not self.currenttransaction(): |
|
1617 | if not self.currenttransaction(): | |
1617 | # TODO: Changing contents of store outside transaction |
|
1618 | # TODO: Changing contents of store outside transaction | |
1618 | # causes inconsistency. We should make in-memory store |
|
1619 | # causes inconsistency. We should make in-memory store | |
1619 | # changes detectable, and abort if changed. |
|
1620 | # changes detectable, and abort if changed. | |
1620 | self.store.invalidatecaches() |
|
1621 | self.store.invalidatecaches() | |
1621 |
|
1622 | |||
1622 | def invalidateall(self): |
|
1623 | def invalidateall(self): | |
1623 | '''Fully invalidates both store and non-store parts, causing the |
|
1624 | '''Fully invalidates both store and non-store parts, causing the | |
1624 | subsequent operation to reread any outside changes.''' |
|
1625 | subsequent operation to reread any outside changes.''' | |
1625 | # extension should hook this to invalidate its caches |
|
1626 | # extension should hook this to invalidate its caches | |
1626 | self.invalidate() |
|
1627 | self.invalidate() | |
1627 | self.invalidatedirstate() |
|
1628 | self.invalidatedirstate() | |
1628 |
|
1629 | |||
1629 | @unfilteredmethod |
|
1630 | @unfilteredmethod | |
1630 | def _refreshfilecachestats(self, tr): |
|
1631 | def _refreshfilecachestats(self, tr): | |
1631 | """Reload stats of cached files so that they are flagged as valid""" |
|
1632 | """Reload stats of cached files so that they are flagged as valid""" | |
1632 | for k, ce in self._filecache.items(): |
|
1633 | for k, ce in self._filecache.items(): | |
1633 | k = pycompat.sysstr(k) |
|
1634 | k = pycompat.sysstr(k) | |
1634 | if k == r'dirstate' or k not in self.__dict__: |
|
1635 | if k == r'dirstate' or k not in self.__dict__: | |
1635 | continue |
|
1636 | continue | |
1636 | ce.refresh() |
|
1637 | ce.refresh() | |
1637 |
|
1638 | |||
1638 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1639 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
1639 | inheritchecker=None, parentenvvar=None): |
|
1640 | inheritchecker=None, parentenvvar=None): | |
1640 | parentlock = None |
|
1641 | parentlock = None | |
1641 | # the contents of parentenvvar are used by the underlying lock to |
|
1642 | # the contents of parentenvvar are used by the underlying lock to | |
1642 | # determine whether it can be inherited |
|
1643 | # determine whether it can be inherited | |
1643 | if parentenvvar is not None: |
|
1644 | if parentenvvar is not None: | |
1644 | parentlock = encoding.environ.get(parentenvvar) |
|
1645 | parentlock = encoding.environ.get(parentenvvar) | |
1645 |
|
1646 | |||
1646 | timeout = 0 |
|
1647 | timeout = 0 | |
1647 | warntimeout = 0 |
|
1648 | warntimeout = 0 | |
1648 | if wait: |
|
1649 | if wait: | |
1649 | timeout = self.ui.configint("ui", "timeout") |
|
1650 | timeout = self.ui.configint("ui", "timeout") | |
1650 | warntimeout = self.ui.configint("ui", "timeout.warn") |
|
1651 | warntimeout = self.ui.configint("ui", "timeout.warn") | |
1651 |
|
1652 | |||
1652 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, |
|
1653 | l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, | |
1653 | releasefn=releasefn, |
|
1654 | releasefn=releasefn, | |
1654 | acquirefn=acquirefn, desc=desc, |
|
1655 | acquirefn=acquirefn, desc=desc, | |
1655 | inheritchecker=inheritchecker, |
|
1656 | inheritchecker=inheritchecker, | |
1656 | parentlock=parentlock) |
|
1657 | parentlock=parentlock) | |
1657 | return l |
|
1658 | return l | |
1658 |
|
1659 | |||
1659 | def _afterlock(self, callback): |
|
1660 | def _afterlock(self, callback): | |
1660 | """add a callback to be run when the repository is fully unlocked |
|
1661 | """add a callback to be run when the repository is fully unlocked | |
1661 |
|
1662 | |||
1662 | The callback will be executed when the outermost lock is released |
|
1663 | The callback will be executed when the outermost lock is released | |
1663 | (with wlock being higher level than 'lock').""" |
|
1664 | (with wlock being higher level than 'lock').""" | |
1664 | for ref in (self._wlockref, self._lockref): |
|
1665 | for ref in (self._wlockref, self._lockref): | |
1665 | l = ref and ref() |
|
1666 | l = ref and ref() | |
1666 | if l and l.held: |
|
1667 | if l and l.held: | |
1667 | l.postrelease.append(callback) |
|
1668 | l.postrelease.append(callback) | |
1668 | break |
|
1669 | break | |
1669 | else: # no lock have been found. |
|
1670 | else: # no lock have been found. | |
1670 | callback() |
|
1671 | callback() | |
1671 |
|
1672 | |||
1672 | def lock(self, wait=True): |
|
1673 | def lock(self, wait=True): | |
1673 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1674 | '''Lock the repository store (.hg/store) and return a weak reference | |
1674 | to the lock. Use this before modifying the store (e.g. committing or |
|
1675 | to the lock. Use this before modifying the store (e.g. committing or | |
1675 | stripping). If you are opening a transaction, get a lock as well.) |
|
1676 | stripping). If you are opening a transaction, get a lock as well.) | |
1676 |
|
1677 | |||
1677 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1678 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1678 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1679 | 'wlock' first to avoid a dead-lock hazard.''' | |
1679 | l = self._currentlock(self._lockref) |
|
1680 | l = self._currentlock(self._lockref) | |
1680 | if l is not None: |
|
1681 | if l is not None: | |
1681 | l.lock() |
|
1682 | l.lock() | |
1682 | return l |
|
1683 | return l | |
1683 |
|
1684 | |||
1684 | l = self._lock(self.svfs, "lock", wait, None, |
|
1685 | l = self._lock(self.svfs, "lock", wait, None, | |
1685 | self.invalidate, _('repository %s') % self.origroot) |
|
1686 | self.invalidate, _('repository %s') % self.origroot) | |
1686 | self._lockref = weakref.ref(l) |
|
1687 | self._lockref = weakref.ref(l) | |
1687 | return l |
|
1688 | return l | |
1688 |
|
1689 | |||
1689 | def _wlockchecktransaction(self): |
|
1690 | def _wlockchecktransaction(self): | |
1690 | if self.currenttransaction() is not None: |
|
1691 | if self.currenttransaction() is not None: | |
1691 | raise error.LockInheritanceContractViolation( |
|
1692 | raise error.LockInheritanceContractViolation( | |
1692 | 'wlock cannot be inherited in the middle of a transaction') |
|
1693 | 'wlock cannot be inherited in the middle of a transaction') | |
1693 |
|
1694 | |||
1694 | def wlock(self, wait=True): |
|
1695 | def wlock(self, wait=True): | |
1695 | '''Lock the non-store parts of the repository (everything under |
|
1696 | '''Lock the non-store parts of the repository (everything under | |
1696 | .hg except .hg/store) and return a weak reference to the lock. |
|
1697 | .hg except .hg/store) and return a weak reference to the lock. | |
1697 |
|
1698 | |||
1698 | Use this before modifying files in .hg. |
|
1699 | Use this before modifying files in .hg. | |
1699 |
|
1700 | |||
1700 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1701 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1701 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1702 | 'wlock' first to avoid a dead-lock hazard.''' | |
1702 | l = self._wlockref and self._wlockref() |
|
1703 | l = self._wlockref and self._wlockref() | |
1703 | if l is not None and l.held: |
|
1704 | if l is not None and l.held: | |
1704 | l.lock() |
|
1705 | l.lock() | |
1705 | return l |
|
1706 | return l | |
1706 |
|
1707 | |||
1707 | # We do not need to check for non-waiting lock acquisition. Such |
|
1708 | # We do not need to check for non-waiting lock acquisition. Such | |
1708 | # acquisition would not cause dead-lock as they would just fail. |
|
1709 | # acquisition would not cause dead-lock as they would just fail. | |
1709 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1710 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
1710 | or self.ui.configbool('devel', 'check-locks')): |
|
1711 | or self.ui.configbool('devel', 'check-locks')): | |
1711 | if self._currentlock(self._lockref) is not None: |
|
1712 | if self._currentlock(self._lockref) is not None: | |
1712 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1713 | self.ui.develwarn('"wlock" acquired after "lock"') | |
1713 |
|
1714 | |||
1714 | def unlock(): |
|
1715 | def unlock(): | |
1715 | if self.dirstate.pendingparentchange(): |
|
1716 | if self.dirstate.pendingparentchange(): | |
1716 | self.dirstate.invalidate() |
|
1717 | self.dirstate.invalidate() | |
1717 | else: |
|
1718 | else: | |
1718 | self.dirstate.write(None) |
|
1719 | self.dirstate.write(None) | |
1719 |
|
1720 | |||
1720 | self._filecache['dirstate'].refresh() |
|
1721 | self._filecache['dirstate'].refresh() | |
1721 |
|
1722 | |||
1722 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1723 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
1723 | self.invalidatedirstate, _('working directory of %s') % |
|
1724 | self.invalidatedirstate, _('working directory of %s') % | |
1724 | self.origroot, |
|
1725 | self.origroot, | |
1725 | inheritchecker=self._wlockchecktransaction, |
|
1726 | inheritchecker=self._wlockchecktransaction, | |
1726 | parentenvvar='HG_WLOCK_LOCKER') |
|
1727 | parentenvvar='HG_WLOCK_LOCKER') | |
1727 | self._wlockref = weakref.ref(l) |
|
1728 | self._wlockref = weakref.ref(l) | |
1728 | return l |
|
1729 | return l | |
1729 |
|
1730 | |||
1730 | def _currentlock(self, lockref): |
|
1731 | def _currentlock(self, lockref): | |
1731 | """Returns the lock if it's held, or None if it's not.""" |
|
1732 | """Returns the lock if it's held, or None if it's not.""" | |
1732 | if lockref is None: |
|
1733 | if lockref is None: | |
1733 | return None |
|
1734 | return None | |
1734 | l = lockref() |
|
1735 | l = lockref() | |
1735 | if l is None or not l.held: |
|
1736 | if l is None or not l.held: | |
1736 | return None |
|
1737 | return None | |
1737 | return l |
|
1738 | return l | |
1738 |
|
1739 | |||
1739 | def currentwlock(self): |
|
1740 | def currentwlock(self): | |
1740 | """Returns the wlock if it's held, or None if it's not.""" |
|
1741 | """Returns the wlock if it's held, or None if it's not.""" | |
1741 | return self._currentlock(self._wlockref) |
|
1742 | return self._currentlock(self._wlockref) | |
1742 |
|
1743 | |||
1743 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1744 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
1744 | """ |
|
1745 | """ | |
1745 | commit an individual file as part of a larger transaction |
|
1746 | commit an individual file as part of a larger transaction | |
1746 | """ |
|
1747 | """ | |
1747 |
|
1748 | |||
1748 | fname = fctx.path() |
|
1749 | fname = fctx.path() | |
1749 | fparent1 = manifest1.get(fname, nullid) |
|
1750 | fparent1 = manifest1.get(fname, nullid) | |
1750 | fparent2 = manifest2.get(fname, nullid) |
|
1751 | fparent2 = manifest2.get(fname, nullid) | |
1751 | if isinstance(fctx, context.filectx): |
|
1752 | if isinstance(fctx, context.filectx): | |
1752 | node = fctx.filenode() |
|
1753 | node = fctx.filenode() | |
1753 | if node in [fparent1, fparent2]: |
|
1754 | if node in [fparent1, fparent2]: | |
1754 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1755 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
1755 | if manifest1.flags(fname) != fctx.flags(): |
|
1756 | if manifest1.flags(fname) != fctx.flags(): | |
1756 | changelist.append(fname) |
|
1757 | changelist.append(fname) | |
1757 | return node |
|
1758 | return node | |
1758 |
|
1759 | |||
1759 | flog = self.file(fname) |
|
1760 | flog = self.file(fname) | |
1760 | meta = {} |
|
1761 | meta = {} | |
1761 | copy = fctx.renamed() |
|
1762 | copy = fctx.renamed() | |
1762 | if copy and copy[0] != fname: |
|
1763 | if copy and copy[0] != fname: | |
1763 | # Mark the new revision of this file as a copy of another |
|
1764 | # Mark the new revision of this file as a copy of another | |
1764 | # file. This copy data will effectively act as a parent |
|
1765 | # file. This copy data will effectively act as a parent | |
1765 | # of this new revision. If this is a merge, the first |
|
1766 | # of this new revision. If this is a merge, the first | |
1766 | # parent will be the nullid (meaning "look up the copy data") |
|
1767 | # parent will be the nullid (meaning "look up the copy data") | |
1767 | # and the second one will be the other parent. For example: |
|
1768 | # and the second one will be the other parent. For example: | |
1768 | # |
|
1769 | # | |
1769 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1770 | # 0 --- 1 --- 3 rev1 changes file foo | |
1770 | # \ / rev2 renames foo to bar and changes it |
|
1771 | # \ / rev2 renames foo to bar and changes it | |
1771 | # \- 2 -/ rev3 should have bar with all changes and |
|
1772 | # \- 2 -/ rev3 should have bar with all changes and | |
1772 | # should record that bar descends from |
|
1773 | # should record that bar descends from | |
1773 | # bar in rev2 and foo in rev1 |
|
1774 | # bar in rev2 and foo in rev1 | |
1774 | # |
|
1775 | # | |
1775 | # this allows this merge to succeed: |
|
1776 | # this allows this merge to succeed: | |
1776 | # |
|
1777 | # | |
1777 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1778 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1778 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1779 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1779 | # \- 2 --- 4 as the merge base |
|
1780 | # \- 2 --- 4 as the merge base | |
1780 | # |
|
1781 | # | |
1781 |
|
1782 | |||
1782 | cfname = copy[0] |
|
1783 | cfname = copy[0] | |
1783 | crev = manifest1.get(cfname) |
|
1784 | crev = manifest1.get(cfname) | |
1784 | newfparent = fparent2 |
|
1785 | newfparent = fparent2 | |
1785 |
|
1786 | |||
1786 | if manifest2: # branch merge |
|
1787 | if manifest2: # branch merge | |
1787 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1788 | if fparent2 == nullid or crev is None: # copied on remote side | |
1788 | if cfname in manifest2: |
|
1789 | if cfname in manifest2: | |
1789 | crev = manifest2[cfname] |
|
1790 | crev = manifest2[cfname] | |
1790 | newfparent = fparent1 |
|
1791 | newfparent = fparent1 | |
1791 |
|
1792 | |||
1792 | # Here, we used to search backwards through history to try to find |
|
1793 | # Here, we used to search backwards through history to try to find | |
1793 | # where the file copy came from if the source of a copy was not in |
|
1794 | # where the file copy came from if the source of a copy was not in | |
1794 | # the parent directory. However, this doesn't actually make sense to |
|
1795 | # the parent directory. However, this doesn't actually make sense to | |
1795 | # do (what does a copy from something not in your working copy even |
|
1796 | # do (what does a copy from something not in your working copy even | |
1796 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1797 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
1797 | # the user that copy information was dropped, so if they didn't |
|
1798 | # the user that copy information was dropped, so if they didn't | |
1798 | # expect this outcome it can be fixed, but this is the correct |
|
1799 | # expect this outcome it can be fixed, but this is the correct | |
1799 | # behavior in this circumstance. |
|
1800 | # behavior in this circumstance. | |
1800 |
|
1801 | |||
1801 | if crev: |
|
1802 | if crev: | |
1802 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1803 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1803 | meta["copy"] = cfname |
|
1804 | meta["copy"] = cfname | |
1804 | meta["copyrev"] = hex(crev) |
|
1805 | meta["copyrev"] = hex(crev) | |
1805 | fparent1, fparent2 = nullid, newfparent |
|
1806 | fparent1, fparent2 = nullid, newfparent | |
1806 | else: |
|
1807 | else: | |
1807 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1808 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1808 | "copied from '%s'!\n") % (fname, cfname)) |
|
1809 | "copied from '%s'!\n") % (fname, cfname)) | |
1809 |
|
1810 | |||
1810 | elif fparent1 == nullid: |
|
1811 | elif fparent1 == nullid: | |
1811 | fparent1, fparent2 = fparent2, nullid |
|
1812 | fparent1, fparent2 = fparent2, nullid | |
1812 | elif fparent2 != nullid: |
|
1813 | elif fparent2 != nullid: | |
1813 | # is one parent an ancestor of the other? |
|
1814 | # is one parent an ancestor of the other? | |
1814 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1815 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
1815 | if fparent1 in fparentancestors: |
|
1816 | if fparent1 in fparentancestors: | |
1816 | fparent1, fparent2 = fparent2, nullid |
|
1817 | fparent1, fparent2 = fparent2, nullid | |
1817 | elif fparent2 in fparentancestors: |
|
1818 | elif fparent2 in fparentancestors: | |
1818 | fparent2 = nullid |
|
1819 | fparent2 = nullid | |
1819 |
|
1820 | |||
1820 | # is the file changed? |
|
1821 | # is the file changed? | |
1821 | text = fctx.data() |
|
1822 | text = fctx.data() | |
1822 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1823 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1823 | changelist.append(fname) |
|
1824 | changelist.append(fname) | |
1824 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1825 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1825 | # are just the flags changed during merge? |
|
1826 | # are just the flags changed during merge? | |
1826 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1827 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
1827 | changelist.append(fname) |
|
1828 | changelist.append(fname) | |
1828 |
|
1829 | |||
1829 | return fparent1 |
|
1830 | return fparent1 | |
1830 |
|
1831 | |||
1831 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
1832 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): | |
1832 | """check for commit arguments that aren't committable""" |
|
1833 | """check for commit arguments that aren't committable""" | |
1833 | if match.isexact() or match.prefix(): |
|
1834 | if match.isexact() or match.prefix(): | |
1834 | matched = set(status.modified + status.added + status.removed) |
|
1835 | matched = set(status.modified + status.added + status.removed) | |
1835 |
|
1836 | |||
1836 | for f in match.files(): |
|
1837 | for f in match.files(): | |
1837 | f = self.dirstate.normalize(f) |
|
1838 | f = self.dirstate.normalize(f) | |
1838 | if f == '.' or f in matched or f in wctx.substate: |
|
1839 | if f == '.' or f in matched or f in wctx.substate: | |
1839 | continue |
|
1840 | continue | |
1840 | if f in status.deleted: |
|
1841 | if f in status.deleted: | |
1841 | fail(f, _('file not found!')) |
|
1842 | fail(f, _('file not found!')) | |
1842 | if f in vdirs: # visited directory |
|
1843 | if f in vdirs: # visited directory | |
1843 | d = f + '/' |
|
1844 | d = f + '/' | |
1844 | for mf in matched: |
|
1845 | for mf in matched: | |
1845 | if mf.startswith(d): |
|
1846 | if mf.startswith(d): | |
1846 | break |
|
1847 | break | |
1847 | else: |
|
1848 | else: | |
1848 | fail(f, _("no match under directory!")) |
|
1849 | fail(f, _("no match under directory!")) | |
1849 | elif f not in self.dirstate: |
|
1850 | elif f not in self.dirstate: | |
1850 | fail(f, _("file not tracked!")) |
|
1851 | fail(f, _("file not tracked!")) | |
1851 |
|
1852 | |||
1852 | @unfilteredmethod |
|
1853 | @unfilteredmethod | |
1853 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1854 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1854 | editor=False, extra=None): |
|
1855 | editor=False, extra=None): | |
1855 | """Add a new revision to current repository. |
|
1856 | """Add a new revision to current repository. | |
1856 |
|
1857 | |||
1857 | Revision information is gathered from the working directory, |
|
1858 | Revision information is gathered from the working directory, | |
1858 | match can be used to filter the committed files. If editor is |
|
1859 | match can be used to filter the committed files. If editor is | |
1859 | supplied, it is called to get a commit message. |
|
1860 | supplied, it is called to get a commit message. | |
1860 | """ |
|
1861 | """ | |
1861 | if extra is None: |
|
1862 | if extra is None: | |
1862 | extra = {} |
|
1863 | extra = {} | |
1863 |
|
1864 | |||
1864 | def fail(f, msg): |
|
1865 | def fail(f, msg): | |
1865 | raise error.Abort('%s: %s' % (f, msg)) |
|
1866 | raise error.Abort('%s: %s' % (f, msg)) | |
1866 |
|
1867 | |||
1867 | if not match: |
|
1868 | if not match: | |
1868 | match = matchmod.always(self.root, '') |
|
1869 | match = matchmod.always(self.root, '') | |
1869 |
|
1870 | |||
1870 | if not force: |
|
1871 | if not force: | |
1871 | vdirs = [] |
|
1872 | vdirs = [] | |
1872 | match.explicitdir = vdirs.append |
|
1873 | match.explicitdir = vdirs.append | |
1873 | match.bad = fail |
|
1874 | match.bad = fail | |
1874 |
|
1875 | |||
1875 | wlock = lock = tr = None |
|
1876 | wlock = lock = tr = None | |
1876 | try: |
|
1877 | try: | |
1877 | wlock = self.wlock() |
|
1878 | wlock = self.wlock() | |
1878 | lock = self.lock() # for recent changelog (see issue4368) |
|
1879 | lock = self.lock() # for recent changelog (see issue4368) | |
1879 |
|
1880 | |||
1880 | wctx = self[None] |
|
1881 | wctx = self[None] | |
1881 | merge = len(wctx.parents()) > 1 |
|
1882 | merge = len(wctx.parents()) > 1 | |
1882 |
|
1883 | |||
1883 | if not force and merge and not match.always(): |
|
1884 | if not force and merge and not match.always(): | |
1884 | raise error.Abort(_('cannot partially commit a merge ' |
|
1885 | raise error.Abort(_('cannot partially commit a merge ' | |
1885 | '(do not specify files or patterns)')) |
|
1886 | '(do not specify files or patterns)')) | |
1886 |
|
1887 | |||
1887 | status = self.status(match=match, clean=force) |
|
1888 | status = self.status(match=match, clean=force) | |
1888 | if force: |
|
1889 | if force: | |
1889 | status.modified.extend(status.clean) # mq may commit clean files |
|
1890 | status.modified.extend(status.clean) # mq may commit clean files | |
1890 |
|
1891 | |||
1891 | # check subrepos |
|
1892 | # check subrepos | |
1892 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
1893 | subs, commitsubs, newstate = subrepoutil.precommit( | |
1893 | self.ui, wctx, status, match, force=force) |
|
1894 | self.ui, wctx, status, match, force=force) | |
1894 |
|
1895 | |||
1895 | # make sure all explicit patterns are matched |
|
1896 | # make sure all explicit patterns are matched | |
1896 | if not force: |
|
1897 | if not force: | |
1897 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
1898 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) | |
1898 |
|
1899 | |||
1899 | cctx = context.workingcommitctx(self, status, |
|
1900 | cctx = context.workingcommitctx(self, status, | |
1900 | text, user, date, extra) |
|
1901 | text, user, date, extra) | |
1901 |
|
1902 | |||
1902 | # internal config: ui.allowemptycommit |
|
1903 | # internal config: ui.allowemptycommit | |
1903 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1904 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
1904 | or extra.get('close') or merge or cctx.files() |
|
1905 | or extra.get('close') or merge or cctx.files() | |
1905 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1906 | or self.ui.configbool('ui', 'allowemptycommit')) | |
1906 | if not allowemptycommit: |
|
1907 | if not allowemptycommit: | |
1907 | return None |
|
1908 | return None | |
1908 |
|
1909 | |||
1909 | if merge and cctx.deleted(): |
|
1910 | if merge and cctx.deleted(): | |
1910 | raise error.Abort(_("cannot commit merge with missing files")) |
|
1911 | raise error.Abort(_("cannot commit merge with missing files")) | |
1911 |
|
1912 | |||
1912 | ms = mergemod.mergestate.read(self) |
|
1913 | ms = mergemod.mergestate.read(self) | |
1913 | mergeutil.checkunresolved(ms) |
|
1914 | mergeutil.checkunresolved(ms) | |
1914 |
|
1915 | |||
1915 | if editor: |
|
1916 | if editor: | |
1916 | cctx._text = editor(self, cctx, subs) |
|
1917 | cctx._text = editor(self, cctx, subs) | |
1917 | edited = (text != cctx._text) |
|
1918 | edited = (text != cctx._text) | |
1918 |
|
1919 | |||
1919 | # Save commit message in case this transaction gets rolled back |
|
1920 | # Save commit message in case this transaction gets rolled back | |
1920 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1921 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1921 | # the assumption that the user will use the same editor again. |
|
1922 | # the assumption that the user will use the same editor again. | |
1922 | msgfn = self.savecommitmessage(cctx._text) |
|
1923 | msgfn = self.savecommitmessage(cctx._text) | |
1923 |
|
1924 | |||
1924 | # commit subs and write new state |
|
1925 | # commit subs and write new state | |
1925 | if subs: |
|
1926 | if subs: | |
1926 | for s in sorted(commitsubs): |
|
1927 | for s in sorted(commitsubs): | |
1927 | sub = wctx.sub(s) |
|
1928 | sub = wctx.sub(s) | |
1928 | self.ui.status(_('committing subrepository %s\n') % |
|
1929 | self.ui.status(_('committing subrepository %s\n') % | |
1929 | subrepoutil.subrelpath(sub)) |
|
1930 | subrepoutil.subrelpath(sub)) | |
1930 | sr = sub.commit(cctx._text, user, date) |
|
1931 | sr = sub.commit(cctx._text, user, date) | |
1931 | newstate[s] = (newstate[s][0], sr) |
|
1932 | newstate[s] = (newstate[s][0], sr) | |
1932 | subrepoutil.writestate(self, newstate) |
|
1933 | subrepoutil.writestate(self, newstate) | |
1933 |
|
1934 | |||
1934 | p1, p2 = self.dirstate.parents() |
|
1935 | p1, p2 = self.dirstate.parents() | |
1935 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1936 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1936 | try: |
|
1937 | try: | |
1937 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1938 | self.hook("precommit", throw=True, parent1=hookp1, | |
1938 | parent2=hookp2) |
|
1939 | parent2=hookp2) | |
1939 | tr = self.transaction('commit') |
|
1940 | tr = self.transaction('commit') | |
1940 | ret = self.commitctx(cctx, True) |
|
1941 | ret = self.commitctx(cctx, True) | |
1941 | except: # re-raises |
|
1942 | except: # re-raises | |
1942 | if edited: |
|
1943 | if edited: | |
1943 | self.ui.write( |
|
1944 | self.ui.write( | |
1944 | _('note: commit message saved in %s\n') % msgfn) |
|
1945 | _('note: commit message saved in %s\n') % msgfn) | |
1945 | raise |
|
1946 | raise | |
1946 | # update bookmarks, dirstate and mergestate |
|
1947 | # update bookmarks, dirstate and mergestate | |
1947 | bookmarks.update(self, [p1, p2], ret) |
|
1948 | bookmarks.update(self, [p1, p2], ret) | |
1948 | cctx.markcommitted(ret) |
|
1949 | cctx.markcommitted(ret) | |
1949 | ms.reset() |
|
1950 | ms.reset() | |
1950 | tr.close() |
|
1951 | tr.close() | |
1951 |
|
1952 | |||
1952 | finally: |
|
1953 | finally: | |
1953 | lockmod.release(tr, lock, wlock) |
|
1954 | lockmod.release(tr, lock, wlock) | |
1954 |
|
1955 | |||
1955 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1956 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
1956 | # hack for command that use a temporary commit (eg: histedit) |
|
1957 | # hack for command that use a temporary commit (eg: histedit) | |
1957 | # temporary commit got stripped before hook release |
|
1958 | # temporary commit got stripped before hook release | |
1958 | if self.changelog.hasnode(ret): |
|
1959 | if self.changelog.hasnode(ret): | |
1959 | self.hook("commit", node=node, parent1=parent1, |
|
1960 | self.hook("commit", node=node, parent1=parent1, | |
1960 | parent2=parent2) |
|
1961 | parent2=parent2) | |
1961 | self._afterlock(commithook) |
|
1962 | self._afterlock(commithook) | |
1962 | return ret |
|
1963 | return ret | |
1963 |
|
1964 | |||
1964 | @unfilteredmethod |
|
1965 | @unfilteredmethod | |
1965 | def commitctx(self, ctx, error=False): |
|
1966 | def commitctx(self, ctx, error=False): | |
1966 | """Add a new revision to current repository. |
|
1967 | """Add a new revision to current repository. | |
1967 | Revision information is passed via the context argument. |
|
1968 | Revision information is passed via the context argument. | |
1968 | """ |
|
1969 | """ | |
1969 |
|
1970 | |||
1970 | tr = None |
|
1971 | tr = None | |
1971 | p1, p2 = ctx.p1(), ctx.p2() |
|
1972 | p1, p2 = ctx.p1(), ctx.p2() | |
1972 | user = ctx.user() |
|
1973 | user = ctx.user() | |
1973 |
|
1974 | |||
1974 | lock = self.lock() |
|
1975 | lock = self.lock() | |
1975 | try: |
|
1976 | try: | |
1976 | tr = self.transaction("commit") |
|
1977 | tr = self.transaction("commit") | |
1977 | trp = weakref.proxy(tr) |
|
1978 | trp = weakref.proxy(tr) | |
1978 |
|
1979 | |||
1979 | if ctx.manifestnode(): |
|
1980 | if ctx.manifestnode(): | |
1980 | # reuse an existing manifest revision |
|
1981 | # reuse an existing manifest revision | |
1981 | mn = ctx.manifestnode() |
|
1982 | mn = ctx.manifestnode() | |
1982 | files = ctx.files() |
|
1983 | files = ctx.files() | |
1983 | elif ctx.files(): |
|
1984 | elif ctx.files(): | |
1984 | m1ctx = p1.manifestctx() |
|
1985 | m1ctx = p1.manifestctx() | |
1985 | m2ctx = p2.manifestctx() |
|
1986 | m2ctx = p2.manifestctx() | |
1986 | mctx = m1ctx.copy() |
|
1987 | mctx = m1ctx.copy() | |
1987 |
|
1988 | |||
1988 | m = mctx.read() |
|
1989 | m = mctx.read() | |
1989 | m1 = m1ctx.read() |
|
1990 | m1 = m1ctx.read() | |
1990 | m2 = m2ctx.read() |
|
1991 | m2 = m2ctx.read() | |
1991 |
|
1992 | |||
1992 | # check in files |
|
1993 | # check in files | |
1993 | added = [] |
|
1994 | added = [] | |
1994 | changed = [] |
|
1995 | changed = [] | |
1995 | removed = list(ctx.removed()) |
|
1996 | removed = list(ctx.removed()) | |
1996 | linkrev = len(self) |
|
1997 | linkrev = len(self) | |
1997 | self.ui.note(_("committing files:\n")) |
|
1998 | self.ui.note(_("committing files:\n")) | |
1998 | for f in sorted(ctx.modified() + ctx.added()): |
|
1999 | for f in sorted(ctx.modified() + ctx.added()): | |
1999 | self.ui.note(f + "\n") |
|
2000 | self.ui.note(f + "\n") | |
2000 | try: |
|
2001 | try: | |
2001 | fctx = ctx[f] |
|
2002 | fctx = ctx[f] | |
2002 | if fctx is None: |
|
2003 | if fctx is None: | |
2003 | removed.append(f) |
|
2004 | removed.append(f) | |
2004 | else: |
|
2005 | else: | |
2005 | added.append(f) |
|
2006 | added.append(f) | |
2006 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
2007 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
2007 | trp, changed) |
|
2008 | trp, changed) | |
2008 | m.setflag(f, fctx.flags()) |
|
2009 | m.setflag(f, fctx.flags()) | |
2009 | except OSError as inst: |
|
2010 | except OSError as inst: | |
2010 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2011 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2011 | raise |
|
2012 | raise | |
2012 | except IOError as inst: |
|
2013 | except IOError as inst: | |
2013 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
2014 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
2014 | if error or errcode and errcode != errno.ENOENT: |
|
2015 | if error or errcode and errcode != errno.ENOENT: | |
2015 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
2016 | self.ui.warn(_("trouble committing %s!\n") % f) | |
2016 | raise |
|
2017 | raise | |
2017 |
|
2018 | |||
2018 | # update manifest |
|
2019 | # update manifest | |
2019 | self.ui.note(_("committing manifest\n")) |
|
2020 | self.ui.note(_("committing manifest\n")) | |
2020 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
2021 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
2021 | drop = [f for f in removed if f in m] |
|
2022 | drop = [f for f in removed if f in m] | |
2022 | for f in drop: |
|
2023 | for f in drop: | |
2023 | del m[f] |
|
2024 | del m[f] | |
2024 | mn = mctx.write(trp, linkrev, |
|
2025 | mn = mctx.write(trp, linkrev, | |
2025 | p1.manifestnode(), p2.manifestnode(), |
|
2026 | p1.manifestnode(), p2.manifestnode(), | |
2026 | added, drop) |
|
2027 | added, drop) | |
2027 | files = changed + removed |
|
2028 | files = changed + removed | |
2028 | else: |
|
2029 | else: | |
2029 | mn = p1.manifestnode() |
|
2030 | mn = p1.manifestnode() | |
2030 | files = [] |
|
2031 | files = [] | |
2031 |
|
2032 | |||
2032 | # update changelog |
|
2033 | # update changelog | |
2033 | self.ui.note(_("committing changelog\n")) |
|
2034 | self.ui.note(_("committing changelog\n")) | |
2034 | self.changelog.delayupdate(tr) |
|
2035 | self.changelog.delayupdate(tr) | |
2035 | n = self.changelog.add(mn, files, ctx.description(), |
|
2036 | n = self.changelog.add(mn, files, ctx.description(), | |
2036 | trp, p1.node(), p2.node(), |
|
2037 | trp, p1.node(), p2.node(), | |
2037 | user, ctx.date(), ctx.extra().copy()) |
|
2038 | user, ctx.date(), ctx.extra().copy()) | |
2038 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
2039 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
2039 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
2040 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
2040 | parent2=xp2) |
|
2041 | parent2=xp2) | |
2041 | # set the new commit is proper phase |
|
2042 | # set the new commit is proper phase | |
2042 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) |
|
2043 | targetphase = subrepoutil.newcommitphase(self.ui, ctx) | |
2043 | if targetphase: |
|
2044 | if targetphase: | |
2044 | # retract boundary do not alter parent changeset. |
|
2045 | # retract boundary do not alter parent changeset. | |
2045 | # if a parent have higher the resulting phase will |
|
2046 | # if a parent have higher the resulting phase will | |
2046 | # be compliant anyway |
|
2047 | # be compliant anyway | |
2047 | # |
|
2048 | # | |
2048 | # if minimal phase was 0 we don't need to retract anything |
|
2049 | # if minimal phase was 0 we don't need to retract anything | |
2049 | phases.registernew(self, tr, targetphase, [n]) |
|
2050 | phases.registernew(self, tr, targetphase, [n]) | |
2050 | tr.close() |
|
2051 | tr.close() | |
2051 | return n |
|
2052 | return n | |
2052 | finally: |
|
2053 | finally: | |
2053 | if tr: |
|
2054 | if tr: | |
2054 | tr.release() |
|
2055 | tr.release() | |
2055 | lock.release() |
|
2056 | lock.release() | |
2056 |
|
2057 | |||
2057 | @unfilteredmethod |
|
2058 | @unfilteredmethod | |
2058 | def destroying(self): |
|
2059 | def destroying(self): | |
2059 | '''Inform the repository that nodes are about to be destroyed. |
|
2060 | '''Inform the repository that nodes are about to be destroyed. | |
2060 | Intended for use by strip and rollback, so there's a common |
|
2061 | Intended for use by strip and rollback, so there's a common | |
2061 | place for anything that has to be done before destroying history. |
|
2062 | place for anything that has to be done before destroying history. | |
2062 |
|
2063 | |||
2063 | This is mostly useful for saving state that is in memory and waiting |
|
2064 | This is mostly useful for saving state that is in memory and waiting | |
2064 | to be flushed when the current lock is released. Because a call to |
|
2065 | to be flushed when the current lock is released. Because a call to | |
2065 | destroyed is imminent, the repo will be invalidated causing those |
|
2066 | destroyed is imminent, the repo will be invalidated causing those | |
2066 | changes to stay in memory (waiting for the next unlock), or vanish |
|
2067 | changes to stay in memory (waiting for the next unlock), or vanish | |
2067 | completely. |
|
2068 | completely. | |
2068 | ''' |
|
2069 | ''' | |
2069 | # When using the same lock to commit and strip, the phasecache is left |
|
2070 | # When using the same lock to commit and strip, the phasecache is left | |
2070 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
2071 | # dirty after committing. Then when we strip, the repo is invalidated, | |
2071 | # causing those changes to disappear. |
|
2072 | # causing those changes to disappear. | |
2072 | if '_phasecache' in vars(self): |
|
2073 | if '_phasecache' in vars(self): | |
2073 | self._phasecache.write() |
|
2074 | self._phasecache.write() | |
2074 |
|
2075 | |||
2075 | @unfilteredmethod |
|
2076 | @unfilteredmethod | |
2076 | def destroyed(self): |
|
2077 | def destroyed(self): | |
2077 | '''Inform the repository that nodes have been destroyed. |
|
2078 | '''Inform the repository that nodes have been destroyed. | |
2078 | Intended for use by strip and rollback, so there's a common |
|
2079 | Intended for use by strip and rollback, so there's a common | |
2079 | place for anything that has to be done after destroying history. |
|
2080 | place for anything that has to be done after destroying history. | |
2080 | ''' |
|
2081 | ''' | |
2081 | # When one tries to: |
|
2082 | # When one tries to: | |
2082 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
2083 | # 1) destroy nodes thus calling this method (e.g. strip) | |
2083 | # 2) use phasecache somewhere (e.g. commit) |
|
2084 | # 2) use phasecache somewhere (e.g. commit) | |
2084 | # |
|
2085 | # | |
2085 | # then 2) will fail because the phasecache contains nodes that were |
|
2086 | # then 2) will fail because the phasecache contains nodes that were | |
2086 | # removed. We can either remove phasecache from the filecache, |
|
2087 | # removed. We can either remove phasecache from the filecache, | |
2087 | # causing it to reload next time it is accessed, or simply filter |
|
2088 | # causing it to reload next time it is accessed, or simply filter | |
2088 | # the removed nodes now and write the updated cache. |
|
2089 | # the removed nodes now and write the updated cache. | |
2089 | self._phasecache.filterunknown(self) |
|
2090 | self._phasecache.filterunknown(self) | |
2090 | self._phasecache.write() |
|
2091 | self._phasecache.write() | |
2091 |
|
2092 | |||
2092 | # refresh all repository caches |
|
2093 | # refresh all repository caches | |
2093 | self.updatecaches() |
|
2094 | self.updatecaches() | |
2094 |
|
2095 | |||
2095 | # Ensure the persistent tag cache is updated. Doing it now |
|
2096 | # Ensure the persistent tag cache is updated. Doing it now | |
2096 | # means that the tag cache only has to worry about destroyed |
|
2097 | # means that the tag cache only has to worry about destroyed | |
2097 | # heads immediately after a strip/rollback. That in turn |
|
2098 | # heads immediately after a strip/rollback. That in turn | |
2098 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
2099 | # guarantees that "cachetip == currenttip" (comparing both rev | |
2099 | # and node) always means no nodes have been added or destroyed. |
|
2100 | # and node) always means no nodes have been added or destroyed. | |
2100 |
|
2101 | |||
2101 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
2102 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
2102 | # head, refresh the tag cache, then immediately add a new head. |
|
2103 | # head, refresh the tag cache, then immediately add a new head. | |
2103 | # But I think doing it this way is necessary for the "instant |
|
2104 | # But I think doing it this way is necessary for the "instant | |
2104 | # tag cache retrieval" case to work. |
|
2105 | # tag cache retrieval" case to work. | |
2105 | self.invalidate() |
|
2106 | self.invalidate() | |
2106 |
|
2107 | |||
2107 | def status(self, node1='.', node2=None, match=None, |
|
2108 | def status(self, node1='.', node2=None, match=None, | |
2108 | ignored=False, clean=False, unknown=False, |
|
2109 | ignored=False, clean=False, unknown=False, | |
2109 | listsubrepos=False): |
|
2110 | listsubrepos=False): | |
2110 | '''a convenience method that calls node1.status(node2)''' |
|
2111 | '''a convenience method that calls node1.status(node2)''' | |
2111 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
2112 | return self[node1].status(node2, match, ignored, clean, unknown, | |
2112 | listsubrepos) |
|
2113 | listsubrepos) | |
2113 |
|
2114 | |||
2114 | def addpostdsstatus(self, ps): |
|
2115 | def addpostdsstatus(self, ps): | |
2115 | """Add a callback to run within the wlock, at the point at which status |
|
2116 | """Add a callback to run within the wlock, at the point at which status | |
2116 | fixups happen. |
|
2117 | fixups happen. | |
2117 |
|
2118 | |||
2118 | On status completion, callback(wctx, status) will be called with the |
|
2119 | On status completion, callback(wctx, status) will be called with the | |
2119 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
2120 | wlock held, unless the dirstate has changed from underneath or the wlock | |
2120 | couldn't be grabbed. |
|
2121 | couldn't be grabbed. | |
2121 |
|
2122 | |||
2122 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
2123 | Callbacks should not capture and use a cached copy of the dirstate -- | |
2123 | it might change in the meanwhile. Instead, they should access the |
|
2124 | it might change in the meanwhile. Instead, they should access the | |
2124 | dirstate via wctx.repo().dirstate. |
|
2125 | dirstate via wctx.repo().dirstate. | |
2125 |
|
2126 | |||
2126 | This list is emptied out after each status run -- extensions should |
|
2127 | This list is emptied out after each status run -- extensions should | |
2127 | make sure it adds to this list each time dirstate.status is called. |
|
2128 | make sure it adds to this list each time dirstate.status is called. | |
2128 | Extensions should also make sure they don't call this for statuses |
|
2129 | Extensions should also make sure they don't call this for statuses | |
2129 | that don't involve the dirstate. |
|
2130 | that don't involve the dirstate. | |
2130 | """ |
|
2131 | """ | |
2131 |
|
2132 | |||
2132 | # The list is located here for uniqueness reasons -- it is actually |
|
2133 | # The list is located here for uniqueness reasons -- it is actually | |
2133 | # managed by the workingctx, but that isn't unique per-repo. |
|
2134 | # managed by the workingctx, but that isn't unique per-repo. | |
2134 | self._postdsstatus.append(ps) |
|
2135 | self._postdsstatus.append(ps) | |
2135 |
|
2136 | |||
2136 | def postdsstatus(self): |
|
2137 | def postdsstatus(self): | |
2137 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
2138 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
2138 | return self._postdsstatus |
|
2139 | return self._postdsstatus | |
2139 |
|
2140 | |||
2140 | def clearpostdsstatus(self): |
|
2141 | def clearpostdsstatus(self): | |
2141 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
2142 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
2142 | del self._postdsstatus[:] |
|
2143 | del self._postdsstatus[:] | |
2143 |
|
2144 | |||
2144 | def heads(self, start=None): |
|
2145 | def heads(self, start=None): | |
2145 | if start is None: |
|
2146 | if start is None: | |
2146 | cl = self.changelog |
|
2147 | cl = self.changelog | |
2147 | headrevs = reversed(cl.headrevs()) |
|
2148 | headrevs = reversed(cl.headrevs()) | |
2148 | return [cl.node(rev) for rev in headrevs] |
|
2149 | return [cl.node(rev) for rev in headrevs] | |
2149 |
|
2150 | |||
2150 | heads = self.changelog.heads(start) |
|
2151 | heads = self.changelog.heads(start) | |
2151 | # sort the output in rev descending order |
|
2152 | # sort the output in rev descending order | |
2152 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
2153 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
2153 |
|
2154 | |||
2154 | def branchheads(self, branch=None, start=None, closed=False): |
|
2155 | def branchheads(self, branch=None, start=None, closed=False): | |
2155 | '''return a (possibly filtered) list of heads for the given branch |
|
2156 | '''return a (possibly filtered) list of heads for the given branch | |
2156 |
|
2157 | |||
2157 | Heads are returned in topological order, from newest to oldest. |
|
2158 | Heads are returned in topological order, from newest to oldest. | |
2158 | If branch is None, use the dirstate branch. |
|
2159 | If branch is None, use the dirstate branch. | |
2159 | If start is not None, return only heads reachable from start. |
|
2160 | If start is not None, return only heads reachable from start. | |
2160 | If closed is True, return heads that are marked as closed as well. |
|
2161 | If closed is True, return heads that are marked as closed as well. | |
2161 | ''' |
|
2162 | ''' | |
2162 | if branch is None: |
|
2163 | if branch is None: | |
2163 | branch = self[None].branch() |
|
2164 | branch = self[None].branch() | |
2164 | branches = self.branchmap() |
|
2165 | branches = self.branchmap() | |
2165 | if branch not in branches: |
|
2166 | if branch not in branches: | |
2166 | return [] |
|
2167 | return [] | |
2167 | # the cache returns heads ordered lowest to highest |
|
2168 | # the cache returns heads ordered lowest to highest | |
2168 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
2169 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
2169 | if start is not None: |
|
2170 | if start is not None: | |
2170 | # filter out the heads that cannot be reached from startrev |
|
2171 | # filter out the heads that cannot be reached from startrev | |
2171 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
2172 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
2172 | bheads = [h for h in bheads if h in fbheads] |
|
2173 | bheads = [h for h in bheads if h in fbheads] | |
2173 | return bheads |
|
2174 | return bheads | |
2174 |
|
2175 | |||
2175 | def branches(self, nodes): |
|
2176 | def branches(self, nodes): | |
2176 | if not nodes: |
|
2177 | if not nodes: | |
2177 | nodes = [self.changelog.tip()] |
|
2178 | nodes = [self.changelog.tip()] | |
2178 | b = [] |
|
2179 | b = [] | |
2179 | for n in nodes: |
|
2180 | for n in nodes: | |
2180 | t = n |
|
2181 | t = n | |
2181 | while True: |
|
2182 | while True: | |
2182 | p = self.changelog.parents(n) |
|
2183 | p = self.changelog.parents(n) | |
2183 | if p[1] != nullid or p[0] == nullid: |
|
2184 | if p[1] != nullid or p[0] == nullid: | |
2184 | b.append((t, n, p[0], p[1])) |
|
2185 | b.append((t, n, p[0], p[1])) | |
2185 | break |
|
2186 | break | |
2186 | n = p[0] |
|
2187 | n = p[0] | |
2187 | return b |
|
2188 | return b | |
2188 |
|
2189 | |||
2189 | def between(self, pairs): |
|
2190 | def between(self, pairs): | |
2190 | r = [] |
|
2191 | r = [] | |
2191 |
|
2192 | |||
2192 | for top, bottom in pairs: |
|
2193 | for top, bottom in pairs: | |
2193 | n, l, i = top, [], 0 |
|
2194 | n, l, i = top, [], 0 | |
2194 | f = 1 |
|
2195 | f = 1 | |
2195 |
|
2196 | |||
2196 | while n != bottom and n != nullid: |
|
2197 | while n != bottom and n != nullid: | |
2197 | p = self.changelog.parents(n)[0] |
|
2198 | p = self.changelog.parents(n)[0] | |
2198 | if i == f: |
|
2199 | if i == f: | |
2199 | l.append(n) |
|
2200 | l.append(n) | |
2200 | f = f * 2 |
|
2201 | f = f * 2 | |
2201 | n = p |
|
2202 | n = p | |
2202 | i += 1 |
|
2203 | i += 1 | |
2203 |
|
2204 | |||
2204 | r.append(l) |
|
2205 | r.append(l) | |
2205 |
|
2206 | |||
2206 | return r |
|
2207 | return r | |
2207 |
|
2208 | |||
2208 | def checkpush(self, pushop): |
|
2209 | def checkpush(self, pushop): | |
2209 | """Extensions can override this function if additional checks have |
|
2210 | """Extensions can override this function if additional checks have | |
2210 | to be performed before pushing, or call it if they override push |
|
2211 | to be performed before pushing, or call it if they override push | |
2211 | command. |
|
2212 | command. | |
2212 | """ |
|
2213 | """ | |
2213 |
|
2214 | |||
2214 | @unfilteredpropertycache |
|
2215 | @unfilteredpropertycache | |
2215 | def prepushoutgoinghooks(self): |
|
2216 | def prepushoutgoinghooks(self): | |
2216 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
2217 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
2217 | methods, which are called before pushing changesets. |
|
2218 | methods, which are called before pushing changesets. | |
2218 | """ |
|
2219 | """ | |
2219 | return util.hooks() |
|
2220 | return util.hooks() | |
2220 |
|
2221 | |||
2221 | def pushkey(self, namespace, key, old, new): |
|
2222 | def pushkey(self, namespace, key, old, new): | |
2222 | try: |
|
2223 | try: | |
2223 | tr = self.currenttransaction() |
|
2224 | tr = self.currenttransaction() | |
2224 | hookargs = {} |
|
2225 | hookargs = {} | |
2225 | if tr is not None: |
|
2226 | if tr is not None: | |
2226 | hookargs.update(tr.hookargs) |
|
2227 | hookargs.update(tr.hookargs) | |
2227 | hookargs = pycompat.strkwargs(hookargs) |
|
2228 | hookargs = pycompat.strkwargs(hookargs) | |
2228 | hookargs[r'namespace'] = namespace |
|
2229 | hookargs[r'namespace'] = namespace | |
2229 | hookargs[r'key'] = key |
|
2230 | hookargs[r'key'] = key | |
2230 | hookargs[r'old'] = old |
|
2231 | hookargs[r'old'] = old | |
2231 | hookargs[r'new'] = new |
|
2232 | hookargs[r'new'] = new | |
2232 | self.hook('prepushkey', throw=True, **hookargs) |
|
2233 | self.hook('prepushkey', throw=True, **hookargs) | |
2233 | except error.HookAbort as exc: |
|
2234 | except error.HookAbort as exc: | |
2234 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
2235 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
2235 | if exc.hint: |
|
2236 | if exc.hint: | |
2236 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
2237 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
2237 | return False |
|
2238 | return False | |
2238 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
2239 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
2239 | ret = pushkey.push(self, namespace, key, old, new) |
|
2240 | ret = pushkey.push(self, namespace, key, old, new) | |
2240 | def runhook(): |
|
2241 | def runhook(): | |
2241 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2242 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
2242 | ret=ret) |
|
2243 | ret=ret) | |
2243 | self._afterlock(runhook) |
|
2244 | self._afterlock(runhook) | |
2244 | return ret |
|
2245 | return ret | |
2245 |
|
2246 | |||
2246 | def listkeys(self, namespace): |
|
2247 | def listkeys(self, namespace): | |
2247 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2248 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
2248 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
2249 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
2249 | values = pushkey.list(self, namespace) |
|
2250 | values = pushkey.list(self, namespace) | |
2250 | self.hook('listkeys', namespace=namespace, values=values) |
|
2251 | self.hook('listkeys', namespace=namespace, values=values) | |
2251 | return values |
|
2252 | return values | |
2252 |
|
2253 | |||
2253 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2254 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
2254 | '''used to test argument passing over the wire''' |
|
2255 | '''used to test argument passing over the wire''' | |
2255 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), |
|
2256 | return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three), | |
2256 | pycompat.bytestr(four), |
|
2257 | pycompat.bytestr(four), | |
2257 | pycompat.bytestr(five)) |
|
2258 | pycompat.bytestr(five)) | |
2258 |
|
2259 | |||
2259 | def savecommitmessage(self, text): |
|
2260 | def savecommitmessage(self, text): | |
2260 | fp = self.vfs('last-message.txt', 'wb') |
|
2261 | fp = self.vfs('last-message.txt', 'wb') | |
2261 | try: |
|
2262 | try: | |
2262 | fp.write(text) |
|
2263 | fp.write(text) | |
2263 | finally: |
|
2264 | finally: | |
2264 | fp.close() |
|
2265 | fp.close() | |
2265 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
2266 | return self.pathto(fp.name[len(self.root) + 1:]) | |
2266 |
|
2267 | |||
2267 | # used to avoid circular references so destructors work |
|
2268 | # used to avoid circular references so destructors work | |
2268 | def aftertrans(files): |
|
2269 | def aftertrans(files): | |
2269 | renamefiles = [tuple(t) for t in files] |
|
2270 | renamefiles = [tuple(t) for t in files] | |
2270 | def a(): |
|
2271 | def a(): | |
2271 | for vfs, src, dest in renamefiles: |
|
2272 | for vfs, src, dest in renamefiles: | |
2272 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
2273 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
2273 | # leaving both src and dest on disk. delete dest to make sure |
|
2274 | # leaving both src and dest on disk. delete dest to make sure | |
2274 | # the rename couldn't be such a no-op. |
|
2275 | # the rename couldn't be such a no-op. | |
2275 | vfs.tryunlink(dest) |
|
2276 | vfs.tryunlink(dest) | |
2276 | try: |
|
2277 | try: | |
2277 | vfs.rename(src, dest) |
|
2278 | vfs.rename(src, dest) | |
2278 | except OSError: # journal file does not yet exist |
|
2279 | except OSError: # journal file does not yet exist | |
2279 | pass |
|
2280 | pass | |
2280 | return a |
|
2281 | return a | |
2281 |
|
2282 | |||
2282 | def undoname(fn): |
|
2283 | def undoname(fn): | |
2283 | base, name = os.path.split(fn) |
|
2284 | base, name = os.path.split(fn) | |
2284 | assert name.startswith('journal') |
|
2285 | assert name.startswith('journal') | |
2285 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2286 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
2286 |
|
2287 | |||
2287 | def instance(ui, path, create): |
|
2288 | def instance(ui, path, create): | |
2288 | return localrepository(ui, util.urllocalpath(path), create) |
|
2289 | return localrepository(ui, util.urllocalpath(path), create) | |
2289 |
|
2290 | |||
2290 | def islocal(path): |
|
2291 | def islocal(path): | |
2291 | return True |
|
2292 | return True | |
2292 |
|
2293 | |||
2293 | def newreporequirements(repo): |
|
2294 | def newreporequirements(repo): | |
2294 | """Determine the set of requirements for a new local repository. |
|
2295 | """Determine the set of requirements for a new local repository. | |
2295 |
|
2296 | |||
2296 | Extensions can wrap this function to specify custom requirements for |
|
2297 | Extensions can wrap this function to specify custom requirements for | |
2297 | new repositories. |
|
2298 | new repositories. | |
2298 | """ |
|
2299 | """ | |
2299 | ui = repo.ui |
|
2300 | ui = repo.ui | |
2300 | requirements = {'revlogv1'} |
|
2301 | requirements = {'revlogv1'} | |
2301 | if ui.configbool('format', 'usestore'): |
|
2302 | if ui.configbool('format', 'usestore'): | |
2302 | requirements.add('store') |
|
2303 | requirements.add('store') | |
2303 | if ui.configbool('format', 'usefncache'): |
|
2304 | if ui.configbool('format', 'usefncache'): | |
2304 | requirements.add('fncache') |
|
2305 | requirements.add('fncache') | |
2305 | if ui.configbool('format', 'dotencode'): |
|
2306 | if ui.configbool('format', 'dotencode'): | |
2306 | requirements.add('dotencode') |
|
2307 | requirements.add('dotencode') | |
2307 |
|
2308 | |||
2308 | compengine = ui.config('experimental', 'format.compression') |
|
2309 | compengine = ui.config('experimental', 'format.compression') | |
2309 | if compengine not in util.compengines: |
|
2310 | if compengine not in util.compengines: | |
2310 | raise error.Abort(_('compression engine %s defined by ' |
|
2311 | raise error.Abort(_('compression engine %s defined by ' | |
2311 | 'experimental.format.compression not available') % |
|
2312 | 'experimental.format.compression not available') % | |
2312 | compengine, |
|
2313 | compengine, | |
2313 | hint=_('run "hg debuginstall" to list available ' |
|
2314 | hint=_('run "hg debuginstall" to list available ' | |
2314 | 'compression engines')) |
|
2315 | 'compression engines')) | |
2315 |
|
2316 | |||
2316 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2317 | # zlib is the historical default and doesn't need an explicit requirement. | |
2317 | if compengine != 'zlib': |
|
2318 | if compengine != 'zlib': | |
2318 | requirements.add('exp-compression-%s' % compengine) |
|
2319 | requirements.add('exp-compression-%s' % compengine) | |
2319 |
|
2320 | |||
2320 | if scmutil.gdinitconfig(ui): |
|
2321 | if scmutil.gdinitconfig(ui): | |
2321 | requirements.add('generaldelta') |
|
2322 | requirements.add('generaldelta') | |
2322 | if ui.configbool('experimental', 'treemanifest'): |
|
2323 | if ui.configbool('experimental', 'treemanifest'): | |
2323 | requirements.add('treemanifest') |
|
2324 | requirements.add('treemanifest') | |
2324 |
|
2325 | |||
2325 | revlogv2 = ui.config('experimental', 'revlogv2') |
|
2326 | revlogv2 = ui.config('experimental', 'revlogv2') | |
2326 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': |
|
2327 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': | |
2327 | requirements.remove('revlogv1') |
|
2328 | requirements.remove('revlogv1') | |
2328 | # generaldelta is implied by revlogv2. |
|
2329 | # generaldelta is implied by revlogv2. | |
2329 | requirements.discard('generaldelta') |
|
2330 | requirements.discard('generaldelta') | |
2330 | requirements.add(REVLOGV2_REQUIREMENT) |
|
2331 | requirements.add(REVLOGV2_REQUIREMENT) | |
2331 |
|
2332 | |||
2332 | return requirements |
|
2333 | return requirements |
@@ -1,2216 +1,2216 b'' | |||||
1 | # merge.py - directory-level update/merge handling for Mercurial |
|
1 | # merge.py - directory-level update/merge handling for Mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006, 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 shutil |
|
12 | import shutil | |
13 | import struct |
|
13 | import struct | |
14 |
|
14 | |||
15 | from .i18n import _ |
|
15 | from .i18n import _ | |
16 | from .node import ( |
|
16 | from .node import ( | |
17 | addednodeid, |
|
17 | addednodeid, | |
18 | bin, |
|
18 | bin, | |
19 | hex, |
|
19 | hex, | |
20 | modifiednodeid, |
|
20 | modifiednodeid, | |
21 | nullhex, |
|
21 | nullhex, | |
22 | nullid, |
|
22 | nullid, | |
23 | nullrev, |
|
23 | nullrev, | |
24 | ) |
|
24 | ) | |
25 | from .thirdparty import ( |
|
25 | from .thirdparty import ( | |
26 | attr, |
|
26 | attr, | |
27 | ) |
|
27 | ) | |
28 | from . import ( |
|
28 | from . import ( | |
29 | copies, |
|
29 | copies, | |
30 | error, |
|
30 | error, | |
31 | filemerge, |
|
31 | filemerge, | |
32 | match as matchmod, |
|
32 | match as matchmod, | |
33 | obsutil, |
|
33 | obsutil, | |
34 | pycompat, |
|
34 | pycompat, | |
35 | scmutil, |
|
35 | scmutil, | |
36 | subrepoutil, |
|
36 | subrepoutil, | |
37 | util, |
|
37 | util, | |
38 | worker, |
|
38 | worker, | |
39 | ) |
|
39 | ) | |
40 |
|
40 | |||
41 | _pack = struct.pack |
|
41 | _pack = struct.pack | |
42 | _unpack = struct.unpack |
|
42 | _unpack = struct.unpack | |
43 |
|
43 | |||
44 | def _droponode(data): |
|
44 | def _droponode(data): | |
45 | # used for compatibility for v1 |
|
45 | # used for compatibility for v1 | |
46 | bits = data.split('\0') |
|
46 | bits = data.split('\0') | |
47 | bits = bits[:-2] + bits[-1:] |
|
47 | bits = bits[:-2] + bits[-1:] | |
48 | return '\0'.join(bits) |
|
48 | return '\0'.join(bits) | |
49 |
|
49 | |||
50 | # Merge state record types. See ``mergestate`` docs for more. |
|
50 | # Merge state record types. See ``mergestate`` docs for more. | |
51 | RECORD_LOCAL = b'L' |
|
51 | RECORD_LOCAL = b'L' | |
52 | RECORD_OTHER = b'O' |
|
52 | RECORD_OTHER = b'O' | |
53 | RECORD_MERGED = b'F' |
|
53 | RECORD_MERGED = b'F' | |
54 | RECORD_CHANGEDELETE_CONFLICT = b'C' |
|
54 | RECORD_CHANGEDELETE_CONFLICT = b'C' | |
55 | RECORD_MERGE_DRIVER_MERGE = b'D' |
|
55 | RECORD_MERGE_DRIVER_MERGE = b'D' | |
56 | RECORD_PATH_CONFLICT = b'P' |
|
56 | RECORD_PATH_CONFLICT = b'P' | |
57 | RECORD_MERGE_DRIVER_STATE = b'm' |
|
57 | RECORD_MERGE_DRIVER_STATE = b'm' | |
58 | RECORD_FILE_VALUES = b'f' |
|
58 | RECORD_FILE_VALUES = b'f' | |
59 | RECORD_LABELS = b'l' |
|
59 | RECORD_LABELS = b'l' | |
60 | RECORD_OVERRIDE = b't' |
|
60 | RECORD_OVERRIDE = b't' | |
61 | RECORD_UNSUPPORTED_MANDATORY = b'X' |
|
61 | RECORD_UNSUPPORTED_MANDATORY = b'X' | |
62 | RECORD_UNSUPPORTED_ADVISORY = b'x' |
|
62 | RECORD_UNSUPPORTED_ADVISORY = b'x' | |
63 |
|
63 | |||
64 | MERGE_DRIVER_STATE_UNMARKED = b'u' |
|
64 | MERGE_DRIVER_STATE_UNMARKED = b'u' | |
65 | MERGE_DRIVER_STATE_MARKED = b'm' |
|
65 | MERGE_DRIVER_STATE_MARKED = b'm' | |
66 | MERGE_DRIVER_STATE_SUCCESS = b's' |
|
66 | MERGE_DRIVER_STATE_SUCCESS = b's' | |
67 |
|
67 | |||
68 | MERGE_RECORD_UNRESOLVED = b'u' |
|
68 | MERGE_RECORD_UNRESOLVED = b'u' | |
69 | MERGE_RECORD_RESOLVED = b'r' |
|
69 | MERGE_RECORD_RESOLVED = b'r' | |
70 | MERGE_RECORD_UNRESOLVED_PATH = b'pu' |
|
70 | MERGE_RECORD_UNRESOLVED_PATH = b'pu' | |
71 | MERGE_RECORD_RESOLVED_PATH = b'pr' |
|
71 | MERGE_RECORD_RESOLVED_PATH = b'pr' | |
72 | MERGE_RECORD_DRIVER_RESOLVED = b'd' |
|
72 | MERGE_RECORD_DRIVER_RESOLVED = b'd' | |
73 |
|
73 | |||
74 | ACTION_FORGET = b'f' |
|
74 | ACTION_FORGET = b'f' | |
75 | ACTION_REMOVE = b'r' |
|
75 | ACTION_REMOVE = b'r' | |
76 | ACTION_ADD = b'a' |
|
76 | ACTION_ADD = b'a' | |
77 | ACTION_GET = b'g' |
|
77 | ACTION_GET = b'g' | |
78 | ACTION_PATH_CONFLICT = b'p' |
|
78 | ACTION_PATH_CONFLICT = b'p' | |
79 | ACTION_PATH_CONFLICT_RESOLVE = b'pr' |
|
79 | ACTION_PATH_CONFLICT_RESOLVE = b'pr' | |
80 | ACTION_ADD_MODIFIED = b'am' |
|
80 | ACTION_ADD_MODIFIED = b'am' | |
81 | ACTION_CREATED = b'c' |
|
81 | ACTION_CREATED = b'c' | |
82 | ACTION_DELETED_CHANGED = b'dc' |
|
82 | ACTION_DELETED_CHANGED = b'dc' | |
83 | ACTION_CHANGED_DELETED = b'cd' |
|
83 | ACTION_CHANGED_DELETED = b'cd' | |
84 | ACTION_MERGE = b'm' |
|
84 | ACTION_MERGE = b'm' | |
85 | ACTION_LOCAL_DIR_RENAME_GET = b'dg' |
|
85 | ACTION_LOCAL_DIR_RENAME_GET = b'dg' | |
86 | ACTION_DIR_RENAME_MOVE_LOCAL = b'dm' |
|
86 | ACTION_DIR_RENAME_MOVE_LOCAL = b'dm' | |
87 | ACTION_KEEP = b'k' |
|
87 | ACTION_KEEP = b'k' | |
88 | ACTION_EXEC = b'e' |
|
88 | ACTION_EXEC = b'e' | |
89 | ACTION_CREATED_MERGE = b'cm' |
|
89 | ACTION_CREATED_MERGE = b'cm' | |
90 |
|
90 | |||
91 | class mergestate(object): |
|
91 | class mergestate(object): | |
92 | '''track 3-way merge state of individual files |
|
92 | '''track 3-way merge state of individual files | |
93 |
|
93 | |||
94 | The merge state is stored on disk when needed. Two files are used: one with |
|
94 | The merge state is stored on disk when needed. Two files are used: one with | |
95 | an old format (version 1), and one with a new format (version 2). Version 2 |
|
95 | an old format (version 1), and one with a new format (version 2). Version 2 | |
96 | stores a superset of the data in version 1, including new kinds of records |
|
96 | stores a superset of the data in version 1, including new kinds of records | |
97 | in the future. For more about the new format, see the documentation for |
|
97 | in the future. For more about the new format, see the documentation for | |
98 | `_readrecordsv2`. |
|
98 | `_readrecordsv2`. | |
99 |
|
99 | |||
100 | Each record can contain arbitrary content, and has an associated type. This |
|
100 | Each record can contain arbitrary content, and has an associated type. This | |
101 | `type` should be a letter. If `type` is uppercase, the record is mandatory: |
|
101 | `type` should be a letter. If `type` is uppercase, the record is mandatory: | |
102 | versions of Mercurial that don't support it should abort. If `type` is |
|
102 | versions of Mercurial that don't support it should abort. If `type` is | |
103 | lowercase, the record can be safely ignored. |
|
103 | lowercase, the record can be safely ignored. | |
104 |
|
104 | |||
105 | Currently known records: |
|
105 | Currently known records: | |
106 |
|
106 | |||
107 | L: the node of the "local" part of the merge (hexified version) |
|
107 | L: the node of the "local" part of the merge (hexified version) | |
108 | O: the node of the "other" part of the merge (hexified version) |
|
108 | O: the node of the "other" part of the merge (hexified version) | |
109 | F: a file to be merged entry |
|
109 | F: a file to be merged entry | |
110 | C: a change/delete or delete/change conflict |
|
110 | C: a change/delete or delete/change conflict | |
111 | D: a file that the external merge driver will merge internally |
|
111 | D: a file that the external merge driver will merge internally | |
112 | (experimental) |
|
112 | (experimental) | |
113 | P: a path conflict (file vs directory) |
|
113 | P: a path conflict (file vs directory) | |
114 | m: the external merge driver defined for this merge plus its run state |
|
114 | m: the external merge driver defined for this merge plus its run state | |
115 | (experimental) |
|
115 | (experimental) | |
116 | f: a (filename, dictionary) tuple of optional values for a given file |
|
116 | f: a (filename, dictionary) tuple of optional values for a given file | |
117 | X: unsupported mandatory record type (used in tests) |
|
117 | X: unsupported mandatory record type (used in tests) | |
118 | x: unsupported advisory record type (used in tests) |
|
118 | x: unsupported advisory record type (used in tests) | |
119 | l: the labels for the parts of the merge. |
|
119 | l: the labels for the parts of the merge. | |
120 |
|
120 | |||
121 | Merge driver run states (experimental): |
|
121 | Merge driver run states (experimental): | |
122 | u: driver-resolved files unmarked -- needs to be run next time we're about |
|
122 | u: driver-resolved files unmarked -- needs to be run next time we're about | |
123 | to resolve or commit |
|
123 | to resolve or commit | |
124 | m: driver-resolved files marked -- only needs to be run before commit |
|
124 | m: driver-resolved files marked -- only needs to be run before commit | |
125 | s: success/skipped -- does not need to be run any more |
|
125 | s: success/skipped -- does not need to be run any more | |
126 |
|
126 | |||
127 | Merge record states (stored in self._state, indexed by filename): |
|
127 | Merge record states (stored in self._state, indexed by filename): | |
128 | u: unresolved conflict |
|
128 | u: unresolved conflict | |
129 | r: resolved conflict |
|
129 | r: resolved conflict | |
130 | pu: unresolved path conflict (file conflicts with directory) |
|
130 | pu: unresolved path conflict (file conflicts with directory) | |
131 | pr: resolved path conflict |
|
131 | pr: resolved path conflict | |
132 | d: driver-resolved conflict |
|
132 | d: driver-resolved conflict | |
133 |
|
133 | |||
134 | The resolve command transitions between 'u' and 'r' for conflicts and |
|
134 | The resolve command transitions between 'u' and 'r' for conflicts and | |
135 | 'pu' and 'pr' for path conflicts. |
|
135 | 'pu' and 'pr' for path conflicts. | |
136 | ''' |
|
136 | ''' | |
137 | statepathv1 = 'merge/state' |
|
137 | statepathv1 = 'merge/state' | |
138 | statepathv2 = 'merge/state2' |
|
138 | statepathv2 = 'merge/state2' | |
139 |
|
139 | |||
140 | @staticmethod |
|
140 | @staticmethod | |
141 | def clean(repo, node=None, other=None, labels=None): |
|
141 | def clean(repo, node=None, other=None, labels=None): | |
142 | """Initialize a brand new merge state, removing any existing state on |
|
142 | """Initialize a brand new merge state, removing any existing state on | |
143 | disk.""" |
|
143 | disk.""" | |
144 | ms = mergestate(repo) |
|
144 | ms = mergestate(repo) | |
145 | ms.reset(node, other, labels) |
|
145 | ms.reset(node, other, labels) | |
146 | return ms |
|
146 | return ms | |
147 |
|
147 | |||
148 | @staticmethod |
|
148 | @staticmethod | |
149 | def read(repo): |
|
149 | def read(repo): | |
150 | """Initialize the merge state, reading it from disk.""" |
|
150 | """Initialize the merge state, reading it from disk.""" | |
151 | ms = mergestate(repo) |
|
151 | ms = mergestate(repo) | |
152 | ms._read() |
|
152 | ms._read() | |
153 | return ms |
|
153 | return ms | |
154 |
|
154 | |||
155 | def __init__(self, repo): |
|
155 | def __init__(self, repo): | |
156 | """Initialize the merge state. |
|
156 | """Initialize the merge state. | |
157 |
|
157 | |||
158 | Do not use this directly! Instead call read() or clean().""" |
|
158 | Do not use this directly! Instead call read() or clean().""" | |
159 | self._repo = repo |
|
159 | self._repo = repo | |
160 | self._dirty = False |
|
160 | self._dirty = False | |
161 | self._labels = None |
|
161 | self._labels = None | |
162 |
|
162 | |||
163 | def reset(self, node=None, other=None, labels=None): |
|
163 | def reset(self, node=None, other=None, labels=None): | |
164 | self._state = {} |
|
164 | self._state = {} | |
165 | self._stateextras = {} |
|
165 | self._stateextras = {} | |
166 | self._local = None |
|
166 | self._local = None | |
167 | self._other = None |
|
167 | self._other = None | |
168 | self._labels = labels |
|
168 | self._labels = labels | |
169 | for var in ('localctx', 'otherctx'): |
|
169 | for var in ('localctx', 'otherctx'): | |
170 | if var in vars(self): |
|
170 | if var in vars(self): | |
171 | delattr(self, var) |
|
171 | delattr(self, var) | |
172 | if node: |
|
172 | if node: | |
173 | self._local = node |
|
173 | self._local = node | |
174 | self._other = other |
|
174 | self._other = other | |
175 | self._readmergedriver = None |
|
175 | self._readmergedriver = None | |
176 | if self.mergedriver: |
|
176 | if self.mergedriver: | |
177 | self._mdstate = MERGE_DRIVER_STATE_SUCCESS |
|
177 | self._mdstate = MERGE_DRIVER_STATE_SUCCESS | |
178 | else: |
|
178 | else: | |
179 | self._mdstate = MERGE_DRIVER_STATE_UNMARKED |
|
179 | self._mdstate = MERGE_DRIVER_STATE_UNMARKED | |
180 | shutil.rmtree(self._repo.vfs.join('merge'), True) |
|
180 | shutil.rmtree(self._repo.vfs.join('merge'), True) | |
181 | self._results = {} |
|
181 | self._results = {} | |
182 | self._dirty = False |
|
182 | self._dirty = False | |
183 |
|
183 | |||
184 | def _read(self): |
|
184 | def _read(self): | |
185 | """Analyse each record content to restore a serialized state from disk |
|
185 | """Analyse each record content to restore a serialized state from disk | |
186 |
|
186 | |||
187 | This function process "record" entry produced by the de-serialization |
|
187 | This function process "record" entry produced by the de-serialization | |
188 | of on disk file. |
|
188 | of on disk file. | |
189 | """ |
|
189 | """ | |
190 | self._state = {} |
|
190 | self._state = {} | |
191 | self._stateextras = {} |
|
191 | self._stateextras = {} | |
192 | self._local = None |
|
192 | self._local = None | |
193 | self._other = None |
|
193 | self._other = None | |
194 | for var in ('localctx', 'otherctx'): |
|
194 | for var in ('localctx', 'otherctx'): | |
195 | if var in vars(self): |
|
195 | if var in vars(self): | |
196 | delattr(self, var) |
|
196 | delattr(self, var) | |
197 | self._readmergedriver = None |
|
197 | self._readmergedriver = None | |
198 | self._mdstate = MERGE_DRIVER_STATE_SUCCESS |
|
198 | self._mdstate = MERGE_DRIVER_STATE_SUCCESS | |
199 | unsupported = set() |
|
199 | unsupported = set() | |
200 | records = self._readrecords() |
|
200 | records = self._readrecords() | |
201 | for rtype, record in records: |
|
201 | for rtype, record in records: | |
202 | if rtype == RECORD_LOCAL: |
|
202 | if rtype == RECORD_LOCAL: | |
203 | self._local = bin(record) |
|
203 | self._local = bin(record) | |
204 | elif rtype == RECORD_OTHER: |
|
204 | elif rtype == RECORD_OTHER: | |
205 | self._other = bin(record) |
|
205 | self._other = bin(record) | |
206 | elif rtype == RECORD_MERGE_DRIVER_STATE: |
|
206 | elif rtype == RECORD_MERGE_DRIVER_STATE: | |
207 | bits = record.split('\0', 1) |
|
207 | bits = record.split('\0', 1) | |
208 | mdstate = bits[1] |
|
208 | mdstate = bits[1] | |
209 | if len(mdstate) != 1 or mdstate not in ( |
|
209 | if len(mdstate) != 1 or mdstate not in ( | |
210 | MERGE_DRIVER_STATE_UNMARKED, MERGE_DRIVER_STATE_MARKED, |
|
210 | MERGE_DRIVER_STATE_UNMARKED, MERGE_DRIVER_STATE_MARKED, | |
211 | MERGE_DRIVER_STATE_SUCCESS): |
|
211 | MERGE_DRIVER_STATE_SUCCESS): | |
212 | # the merge driver should be idempotent, so just rerun it |
|
212 | # the merge driver should be idempotent, so just rerun it | |
213 | mdstate = MERGE_DRIVER_STATE_UNMARKED |
|
213 | mdstate = MERGE_DRIVER_STATE_UNMARKED | |
214 |
|
214 | |||
215 | self._readmergedriver = bits[0] |
|
215 | self._readmergedriver = bits[0] | |
216 | self._mdstate = mdstate |
|
216 | self._mdstate = mdstate | |
217 | elif rtype in (RECORD_MERGED, RECORD_CHANGEDELETE_CONFLICT, |
|
217 | elif rtype in (RECORD_MERGED, RECORD_CHANGEDELETE_CONFLICT, | |
218 | RECORD_PATH_CONFLICT, RECORD_MERGE_DRIVER_MERGE): |
|
218 | RECORD_PATH_CONFLICT, RECORD_MERGE_DRIVER_MERGE): | |
219 | bits = record.split('\0') |
|
219 | bits = record.split('\0') | |
220 | self._state[bits[0]] = bits[1:] |
|
220 | self._state[bits[0]] = bits[1:] | |
221 | elif rtype == RECORD_FILE_VALUES: |
|
221 | elif rtype == RECORD_FILE_VALUES: | |
222 | filename, rawextras = record.split('\0', 1) |
|
222 | filename, rawextras = record.split('\0', 1) | |
223 | extraparts = rawextras.split('\0') |
|
223 | extraparts = rawextras.split('\0') | |
224 | extras = {} |
|
224 | extras = {} | |
225 | i = 0 |
|
225 | i = 0 | |
226 | while i < len(extraparts): |
|
226 | while i < len(extraparts): | |
227 | extras[extraparts[i]] = extraparts[i + 1] |
|
227 | extras[extraparts[i]] = extraparts[i + 1] | |
228 | i += 2 |
|
228 | i += 2 | |
229 |
|
229 | |||
230 | self._stateextras[filename] = extras |
|
230 | self._stateextras[filename] = extras | |
231 | elif rtype == RECORD_LABELS: |
|
231 | elif rtype == RECORD_LABELS: | |
232 | labels = record.split('\0', 2) |
|
232 | labels = record.split('\0', 2) | |
233 | self._labels = [l for l in labels if len(l) > 0] |
|
233 | self._labels = [l for l in labels if len(l) > 0] | |
234 | elif not rtype.islower(): |
|
234 | elif not rtype.islower(): | |
235 | unsupported.add(rtype) |
|
235 | unsupported.add(rtype) | |
236 | self._results = {} |
|
236 | self._results = {} | |
237 | self._dirty = False |
|
237 | self._dirty = False | |
238 |
|
238 | |||
239 | if unsupported: |
|
239 | if unsupported: | |
240 | raise error.UnsupportedMergeRecords(unsupported) |
|
240 | raise error.UnsupportedMergeRecords(unsupported) | |
241 |
|
241 | |||
242 | def _readrecords(self): |
|
242 | def _readrecords(self): | |
243 | """Read merge state from disk and return a list of record (TYPE, data) |
|
243 | """Read merge state from disk and return a list of record (TYPE, data) | |
244 |
|
244 | |||
245 | We read data from both v1 and v2 files and decide which one to use. |
|
245 | We read data from both v1 and v2 files and decide which one to use. | |
246 |
|
246 | |||
247 | V1 has been used by version prior to 2.9.1 and contains less data than |
|
247 | V1 has been used by version prior to 2.9.1 and contains less data than | |
248 | v2. We read both versions and check if no data in v2 contradicts |
|
248 | v2. We read both versions and check if no data in v2 contradicts | |
249 | v1. If there is not contradiction we can safely assume that both v1 |
|
249 | v1. If there is not contradiction we can safely assume that both v1 | |
250 | and v2 were written at the same time and use the extract data in v2. If |
|
250 | and v2 were written at the same time and use the extract data in v2. If | |
251 | there is contradiction we ignore v2 content as we assume an old version |
|
251 | there is contradiction we ignore v2 content as we assume an old version | |
252 | of Mercurial has overwritten the mergestate file and left an old v2 |
|
252 | of Mercurial has overwritten the mergestate file and left an old v2 | |
253 | file around. |
|
253 | file around. | |
254 |
|
254 | |||
255 | returns list of record [(TYPE, data), ...]""" |
|
255 | returns list of record [(TYPE, data), ...]""" | |
256 | v1records = self._readrecordsv1() |
|
256 | v1records = self._readrecordsv1() | |
257 | v2records = self._readrecordsv2() |
|
257 | v2records = self._readrecordsv2() | |
258 | if self._v1v2match(v1records, v2records): |
|
258 | if self._v1v2match(v1records, v2records): | |
259 | return v2records |
|
259 | return v2records | |
260 | else: |
|
260 | else: | |
261 | # v1 file is newer than v2 file, use it |
|
261 | # v1 file is newer than v2 file, use it | |
262 | # we have to infer the "other" changeset of the merge |
|
262 | # we have to infer the "other" changeset of the merge | |
263 | # we cannot do better than that with v1 of the format |
|
263 | # we cannot do better than that with v1 of the format | |
264 | mctx = self._repo[None].parents()[-1] |
|
264 | mctx = self._repo[None].parents()[-1] | |
265 | v1records.append((RECORD_OTHER, mctx.hex())) |
|
265 | v1records.append((RECORD_OTHER, mctx.hex())) | |
266 | # add place holder "other" file node information |
|
266 | # add place holder "other" file node information | |
267 | # nobody is using it yet so we do no need to fetch the data |
|
267 | # nobody is using it yet so we do no need to fetch the data | |
268 | # if mctx was wrong `mctx[bits[-2]]` may fails. |
|
268 | # if mctx was wrong `mctx[bits[-2]]` may fails. | |
269 | for idx, r in enumerate(v1records): |
|
269 | for idx, r in enumerate(v1records): | |
270 | if r[0] == RECORD_MERGED: |
|
270 | if r[0] == RECORD_MERGED: | |
271 | bits = r[1].split('\0') |
|
271 | bits = r[1].split('\0') | |
272 | bits.insert(-2, '') |
|
272 | bits.insert(-2, '') | |
273 | v1records[idx] = (r[0], '\0'.join(bits)) |
|
273 | v1records[idx] = (r[0], '\0'.join(bits)) | |
274 | return v1records |
|
274 | return v1records | |
275 |
|
275 | |||
276 | def _v1v2match(self, v1records, v2records): |
|
276 | def _v1v2match(self, v1records, v2records): | |
277 | oldv2 = set() # old format version of v2 record |
|
277 | oldv2 = set() # old format version of v2 record | |
278 | for rec in v2records: |
|
278 | for rec in v2records: | |
279 | if rec[0] == RECORD_LOCAL: |
|
279 | if rec[0] == RECORD_LOCAL: | |
280 | oldv2.add(rec) |
|
280 | oldv2.add(rec) | |
281 | elif rec[0] == RECORD_MERGED: |
|
281 | elif rec[0] == RECORD_MERGED: | |
282 | # drop the onode data (not contained in v1) |
|
282 | # drop the onode data (not contained in v1) | |
283 | oldv2.add((RECORD_MERGED, _droponode(rec[1]))) |
|
283 | oldv2.add((RECORD_MERGED, _droponode(rec[1]))) | |
284 | for rec in v1records: |
|
284 | for rec in v1records: | |
285 | if rec not in oldv2: |
|
285 | if rec not in oldv2: | |
286 | return False |
|
286 | return False | |
287 | else: |
|
287 | else: | |
288 | return True |
|
288 | return True | |
289 |
|
289 | |||
290 | def _readrecordsv1(self): |
|
290 | def _readrecordsv1(self): | |
291 | """read on disk merge state for version 1 file |
|
291 | """read on disk merge state for version 1 file | |
292 |
|
292 | |||
293 | returns list of record [(TYPE, data), ...] |
|
293 | returns list of record [(TYPE, data), ...] | |
294 |
|
294 | |||
295 | Note: the "F" data from this file are one entry short |
|
295 | Note: the "F" data from this file are one entry short | |
296 | (no "other file node" entry) |
|
296 | (no "other file node" entry) | |
297 | """ |
|
297 | """ | |
298 | records = [] |
|
298 | records = [] | |
299 | try: |
|
299 | try: | |
300 | f = self._repo.vfs(self.statepathv1) |
|
300 | f = self._repo.vfs(self.statepathv1) | |
301 | for i, l in enumerate(f): |
|
301 | for i, l in enumerate(f): | |
302 | if i == 0: |
|
302 | if i == 0: | |
303 | records.append((RECORD_LOCAL, l[:-1])) |
|
303 | records.append((RECORD_LOCAL, l[:-1])) | |
304 | else: |
|
304 | else: | |
305 | records.append((RECORD_MERGED, l[:-1])) |
|
305 | records.append((RECORD_MERGED, l[:-1])) | |
306 | f.close() |
|
306 | f.close() | |
307 | except IOError as err: |
|
307 | except IOError as err: | |
308 | if err.errno != errno.ENOENT: |
|
308 | if err.errno != errno.ENOENT: | |
309 | raise |
|
309 | raise | |
310 | return records |
|
310 | return records | |
311 |
|
311 | |||
312 | def _readrecordsv2(self): |
|
312 | def _readrecordsv2(self): | |
313 | """read on disk merge state for version 2 file |
|
313 | """read on disk merge state for version 2 file | |
314 |
|
314 | |||
315 | This format is a list of arbitrary records of the form: |
|
315 | This format is a list of arbitrary records of the form: | |
316 |
|
316 | |||
317 | [type][length][content] |
|
317 | [type][length][content] | |
318 |
|
318 | |||
319 | `type` is a single character, `length` is a 4 byte integer, and |
|
319 | `type` is a single character, `length` is a 4 byte integer, and | |
320 | `content` is an arbitrary byte sequence of length `length`. |
|
320 | `content` is an arbitrary byte sequence of length `length`. | |
321 |
|
321 | |||
322 | Mercurial versions prior to 3.7 have a bug where if there are |
|
322 | Mercurial versions prior to 3.7 have a bug where if there are | |
323 | unsupported mandatory merge records, attempting to clear out the merge |
|
323 | unsupported mandatory merge records, attempting to clear out the merge | |
324 | state with hg update --clean or similar aborts. The 't' record type |
|
324 | state with hg update --clean or similar aborts. The 't' record type | |
325 | works around that by writing out what those versions treat as an |
|
325 | works around that by writing out what those versions treat as an | |
326 | advisory record, but later versions interpret as special: the first |
|
326 | advisory record, but later versions interpret as special: the first | |
327 | character is the 'real' record type and everything onwards is the data. |
|
327 | character is the 'real' record type and everything onwards is the data. | |
328 |
|
328 | |||
329 | Returns list of records [(TYPE, data), ...].""" |
|
329 | Returns list of records [(TYPE, data), ...].""" | |
330 | records = [] |
|
330 | records = [] | |
331 | try: |
|
331 | try: | |
332 | f = self._repo.vfs(self.statepathv2) |
|
332 | f = self._repo.vfs(self.statepathv2) | |
333 | data = f.read() |
|
333 | data = f.read() | |
334 | off = 0 |
|
334 | off = 0 | |
335 | end = len(data) |
|
335 | end = len(data) | |
336 | while off < end: |
|
336 | while off < end: | |
337 | rtype = data[off:off + 1] |
|
337 | rtype = data[off:off + 1] | |
338 | off += 1 |
|
338 | off += 1 | |
339 | length = _unpack('>I', data[off:(off + 4)])[0] |
|
339 | length = _unpack('>I', data[off:(off + 4)])[0] | |
340 | off += 4 |
|
340 | off += 4 | |
341 | record = data[off:(off + length)] |
|
341 | record = data[off:(off + length)] | |
342 | off += length |
|
342 | off += length | |
343 | if rtype == RECORD_OVERRIDE: |
|
343 | if rtype == RECORD_OVERRIDE: | |
344 | rtype, record = record[0:1], record[1:] |
|
344 | rtype, record = record[0:1], record[1:] | |
345 | records.append((rtype, record)) |
|
345 | records.append((rtype, record)) | |
346 | f.close() |
|
346 | f.close() | |
347 | except IOError as err: |
|
347 | except IOError as err: | |
348 | if err.errno != errno.ENOENT: |
|
348 | if err.errno != errno.ENOENT: | |
349 | raise |
|
349 | raise | |
350 | return records |
|
350 | return records | |
351 |
|
351 | |||
352 | @util.propertycache |
|
352 | @util.propertycache | |
353 | def mergedriver(self): |
|
353 | def mergedriver(self): | |
354 | # protect against the following: |
|
354 | # protect against the following: | |
355 | # - A configures a malicious merge driver in their hgrc, then |
|
355 | # - A configures a malicious merge driver in their hgrc, then | |
356 | # pauses the merge |
|
356 | # pauses the merge | |
357 | # - A edits their hgrc to remove references to the merge driver |
|
357 | # - A edits their hgrc to remove references to the merge driver | |
358 | # - A gives a copy of their entire repo, including .hg, to B |
|
358 | # - A gives a copy of their entire repo, including .hg, to B | |
359 | # - B inspects .hgrc and finds it to be clean |
|
359 | # - B inspects .hgrc and finds it to be clean | |
360 | # - B then continues the merge and the malicious merge driver |
|
360 | # - B then continues the merge and the malicious merge driver | |
361 | # gets invoked |
|
361 | # gets invoked | |
362 | configmergedriver = self._repo.ui.config('experimental', 'mergedriver') |
|
362 | configmergedriver = self._repo.ui.config('experimental', 'mergedriver') | |
363 | if (self._readmergedriver is not None |
|
363 | if (self._readmergedriver is not None | |
364 | and self._readmergedriver != configmergedriver): |
|
364 | and self._readmergedriver != configmergedriver): | |
365 | raise error.ConfigError( |
|
365 | raise error.ConfigError( | |
366 | _("merge driver changed since merge started"), |
|
366 | _("merge driver changed since merge started"), | |
367 | hint=_("revert merge driver change or abort merge")) |
|
367 | hint=_("revert merge driver change or abort merge")) | |
368 |
|
368 | |||
369 | return configmergedriver |
|
369 | return configmergedriver | |
370 |
|
370 | |||
371 | @util.propertycache |
|
371 | @util.propertycache | |
372 | def localctx(self): |
|
372 | def localctx(self): | |
373 | if self._local is None: |
|
373 | if self._local is None: | |
374 | msg = "localctx accessed but self._local isn't set" |
|
374 | msg = "localctx accessed but self._local isn't set" | |
375 | raise error.ProgrammingError(msg) |
|
375 | raise error.ProgrammingError(msg) | |
376 | return self._repo[self._local] |
|
376 | return self._repo[self._local] | |
377 |
|
377 | |||
378 | @util.propertycache |
|
378 | @util.propertycache | |
379 | def otherctx(self): |
|
379 | def otherctx(self): | |
380 | if self._other is None: |
|
380 | if self._other is None: | |
381 | msg = "otherctx accessed but self._other isn't set" |
|
381 | msg = "otherctx accessed but self._other isn't set" | |
382 | raise error.ProgrammingError(msg) |
|
382 | raise error.ProgrammingError(msg) | |
383 | return self._repo[self._other] |
|
383 | return self._repo[self._other] | |
384 |
|
384 | |||
385 | def active(self): |
|
385 | def active(self): | |
386 | """Whether mergestate is active. |
|
386 | """Whether mergestate is active. | |
387 |
|
387 | |||
388 | Returns True if there appears to be mergestate. This is a rough proxy |
|
388 | Returns True if there appears to be mergestate. This is a rough proxy | |
389 | for "is a merge in progress." |
|
389 | for "is a merge in progress." | |
390 | """ |
|
390 | """ | |
391 | # Check local variables before looking at filesystem for performance |
|
391 | # Check local variables before looking at filesystem for performance | |
392 | # reasons. |
|
392 | # reasons. | |
393 | return bool(self._local) or bool(self._state) or \ |
|
393 | return bool(self._local) or bool(self._state) or \ | |
394 | self._repo.vfs.exists(self.statepathv1) or \ |
|
394 | self._repo.vfs.exists(self.statepathv1) or \ | |
395 | self._repo.vfs.exists(self.statepathv2) |
|
395 | self._repo.vfs.exists(self.statepathv2) | |
396 |
|
396 | |||
397 | def commit(self): |
|
397 | def commit(self): | |
398 | """Write current state on disk (if necessary)""" |
|
398 | """Write current state on disk (if necessary)""" | |
399 | if self._dirty: |
|
399 | if self._dirty: | |
400 | records = self._makerecords() |
|
400 | records = self._makerecords() | |
401 | self._writerecords(records) |
|
401 | self._writerecords(records) | |
402 | self._dirty = False |
|
402 | self._dirty = False | |
403 |
|
403 | |||
404 | def _makerecords(self): |
|
404 | def _makerecords(self): | |
405 | records = [] |
|
405 | records = [] | |
406 | records.append((RECORD_LOCAL, hex(self._local))) |
|
406 | records.append((RECORD_LOCAL, hex(self._local))) | |
407 | records.append((RECORD_OTHER, hex(self._other))) |
|
407 | records.append((RECORD_OTHER, hex(self._other))) | |
408 | if self.mergedriver: |
|
408 | if self.mergedriver: | |
409 | records.append((RECORD_MERGE_DRIVER_STATE, '\0'.join([ |
|
409 | records.append((RECORD_MERGE_DRIVER_STATE, '\0'.join([ | |
410 | self.mergedriver, self._mdstate]))) |
|
410 | self.mergedriver, self._mdstate]))) | |
411 | # Write out state items. In all cases, the value of the state map entry |
|
411 | # Write out state items. In all cases, the value of the state map entry | |
412 | # is written as the contents of the record. The record type depends on |
|
412 | # is written as the contents of the record. The record type depends on | |
413 | # the type of state that is stored, and capital-letter records are used |
|
413 | # the type of state that is stored, and capital-letter records are used | |
414 | # to prevent older versions of Mercurial that do not support the feature |
|
414 | # to prevent older versions of Mercurial that do not support the feature | |
415 | # from loading them. |
|
415 | # from loading them. | |
416 | for filename, v in self._state.iteritems(): |
|
416 | for filename, v in self._state.iteritems(): | |
417 | if v[0] == MERGE_RECORD_DRIVER_RESOLVED: |
|
417 | if v[0] == MERGE_RECORD_DRIVER_RESOLVED: | |
418 | # Driver-resolved merge. These are stored in 'D' records. |
|
418 | # Driver-resolved merge. These are stored in 'D' records. | |
419 | records.append((RECORD_MERGE_DRIVER_MERGE, |
|
419 | records.append((RECORD_MERGE_DRIVER_MERGE, | |
420 | '\0'.join([filename] + v))) |
|
420 | '\0'.join([filename] + v))) | |
421 | elif v[0] in (MERGE_RECORD_UNRESOLVED_PATH, |
|
421 | elif v[0] in (MERGE_RECORD_UNRESOLVED_PATH, | |
422 | MERGE_RECORD_RESOLVED_PATH): |
|
422 | MERGE_RECORD_RESOLVED_PATH): | |
423 | # Path conflicts. These are stored in 'P' records. The current |
|
423 | # Path conflicts. These are stored in 'P' records. The current | |
424 | # resolution state ('pu' or 'pr') is stored within the record. |
|
424 | # resolution state ('pu' or 'pr') is stored within the record. | |
425 | records.append((RECORD_PATH_CONFLICT, |
|
425 | records.append((RECORD_PATH_CONFLICT, | |
426 | '\0'.join([filename] + v))) |
|
426 | '\0'.join([filename] + v))) | |
427 | elif v[1] == nullhex or v[6] == nullhex: |
|
427 | elif v[1] == nullhex or v[6] == nullhex: | |
428 | # Change/Delete or Delete/Change conflicts. These are stored in |
|
428 | # Change/Delete or Delete/Change conflicts. These are stored in | |
429 | # 'C' records. v[1] is the local file, and is nullhex when the |
|
429 | # 'C' records. v[1] is the local file, and is nullhex when the | |
430 | # file is deleted locally ('dc'). v[6] is the remote file, and |
|
430 | # file is deleted locally ('dc'). v[6] is the remote file, and | |
431 | # is nullhex when the file is deleted remotely ('cd'). |
|
431 | # is nullhex when the file is deleted remotely ('cd'). | |
432 | records.append((RECORD_CHANGEDELETE_CONFLICT, |
|
432 | records.append((RECORD_CHANGEDELETE_CONFLICT, | |
433 | '\0'.join([filename] + v))) |
|
433 | '\0'.join([filename] + v))) | |
434 | else: |
|
434 | else: | |
435 | # Normal files. These are stored in 'F' records. |
|
435 | # Normal files. These are stored in 'F' records. | |
436 | records.append((RECORD_MERGED, |
|
436 | records.append((RECORD_MERGED, | |
437 | '\0'.join([filename] + v))) |
|
437 | '\0'.join([filename] + v))) | |
438 | for filename, extras in sorted(self._stateextras.iteritems()): |
|
438 | for filename, extras in sorted(self._stateextras.iteritems()): | |
439 | rawextras = '\0'.join('%s\0%s' % (k, v) for k, v in |
|
439 | rawextras = '\0'.join('%s\0%s' % (k, v) for k, v in | |
440 | extras.iteritems()) |
|
440 | extras.iteritems()) | |
441 | records.append((RECORD_FILE_VALUES, |
|
441 | records.append((RECORD_FILE_VALUES, | |
442 | '%s\0%s' % (filename, rawextras))) |
|
442 | '%s\0%s' % (filename, rawextras))) | |
443 | if self._labels is not None: |
|
443 | if self._labels is not None: | |
444 | labels = '\0'.join(self._labels) |
|
444 | labels = '\0'.join(self._labels) | |
445 | records.append((RECORD_LABELS, labels)) |
|
445 | records.append((RECORD_LABELS, labels)) | |
446 | return records |
|
446 | return records | |
447 |
|
447 | |||
448 | def _writerecords(self, records): |
|
448 | def _writerecords(self, records): | |
449 | """Write current state on disk (both v1 and v2)""" |
|
449 | """Write current state on disk (both v1 and v2)""" | |
450 | self._writerecordsv1(records) |
|
450 | self._writerecordsv1(records) | |
451 | self._writerecordsv2(records) |
|
451 | self._writerecordsv2(records) | |
452 |
|
452 | |||
453 | def _writerecordsv1(self, records): |
|
453 | def _writerecordsv1(self, records): | |
454 | """Write current state on disk in a version 1 file""" |
|
454 | """Write current state on disk in a version 1 file""" | |
455 | f = self._repo.vfs(self.statepathv1, 'wb') |
|
455 | f = self._repo.vfs(self.statepathv1, 'wb') | |
456 | irecords = iter(records) |
|
456 | irecords = iter(records) | |
457 | lrecords = next(irecords) |
|
457 | lrecords = next(irecords) | |
458 | assert lrecords[0] == RECORD_LOCAL |
|
458 | assert lrecords[0] == RECORD_LOCAL | |
459 | f.write(hex(self._local) + '\n') |
|
459 | f.write(hex(self._local) + '\n') | |
460 | for rtype, data in irecords: |
|
460 | for rtype, data in irecords: | |
461 | if rtype == RECORD_MERGED: |
|
461 | if rtype == RECORD_MERGED: | |
462 | f.write('%s\n' % _droponode(data)) |
|
462 | f.write('%s\n' % _droponode(data)) | |
463 | f.close() |
|
463 | f.close() | |
464 |
|
464 | |||
465 | def _writerecordsv2(self, records): |
|
465 | def _writerecordsv2(self, records): | |
466 | """Write current state on disk in a version 2 file |
|
466 | """Write current state on disk in a version 2 file | |
467 |
|
467 | |||
468 | See the docstring for _readrecordsv2 for why we use 't'.""" |
|
468 | See the docstring for _readrecordsv2 for why we use 't'.""" | |
469 | # these are the records that all version 2 clients can read |
|
469 | # these are the records that all version 2 clients can read | |
470 | allowlist = (RECORD_LOCAL, RECORD_OTHER, RECORD_MERGED) |
|
470 | allowlist = (RECORD_LOCAL, RECORD_OTHER, RECORD_MERGED) | |
471 | f = self._repo.vfs(self.statepathv2, 'wb') |
|
471 | f = self._repo.vfs(self.statepathv2, 'wb') | |
472 | for key, data in records: |
|
472 | for key, data in records: | |
473 | assert len(key) == 1 |
|
473 | assert len(key) == 1 | |
474 | if key not in allowlist: |
|
474 | if key not in allowlist: | |
475 | key, data = RECORD_OVERRIDE, '%s%s' % (key, data) |
|
475 | key, data = RECORD_OVERRIDE, '%s%s' % (key, data) | |
476 | format = '>sI%is' % len(data) |
|
476 | format = '>sI%is' % len(data) | |
477 | f.write(_pack(format, key, len(data), data)) |
|
477 | f.write(_pack(format, key, len(data), data)) | |
478 | f.close() |
|
478 | f.close() | |
479 |
|
479 | |||
480 | def add(self, fcl, fco, fca, fd): |
|
480 | def add(self, fcl, fco, fca, fd): | |
481 | """add a new (potentially?) conflicting file the merge state |
|
481 | """add a new (potentially?) conflicting file the merge state | |
482 | fcl: file context for local, |
|
482 | fcl: file context for local, | |
483 | fco: file context for remote, |
|
483 | fco: file context for remote, | |
484 | fca: file context for ancestors, |
|
484 | fca: file context for ancestors, | |
485 | fd: file path of the resulting merge. |
|
485 | fd: file path of the resulting merge. | |
486 |
|
486 | |||
487 | note: also write the local version to the `.hg/merge` directory. |
|
487 | note: also write the local version to the `.hg/merge` directory. | |
488 | """ |
|
488 | """ | |
489 | if fcl.isabsent(): |
|
489 | if fcl.isabsent(): | |
490 | hash = nullhex |
|
490 | hash = nullhex | |
491 | else: |
|
491 | else: | |
492 | hash = hex(hashlib.sha1(fcl.path()).digest()) |
|
492 | hash = hex(hashlib.sha1(fcl.path()).digest()) | |
493 | self._repo.vfs.write('merge/' + hash, fcl.data()) |
|
493 | self._repo.vfs.write('merge/' + hash, fcl.data()) | |
494 | self._state[fd] = [MERGE_RECORD_UNRESOLVED, hash, fcl.path(), |
|
494 | self._state[fd] = [MERGE_RECORD_UNRESOLVED, hash, fcl.path(), | |
495 | fca.path(), hex(fca.filenode()), |
|
495 | fca.path(), hex(fca.filenode()), | |
496 | fco.path(), hex(fco.filenode()), |
|
496 | fco.path(), hex(fco.filenode()), | |
497 | fcl.flags()] |
|
497 | fcl.flags()] | |
498 | self._stateextras[fd] = {'ancestorlinknode': hex(fca.node())} |
|
498 | self._stateextras[fd] = {'ancestorlinknode': hex(fca.node())} | |
499 | self._dirty = True |
|
499 | self._dirty = True | |
500 |
|
500 | |||
501 | def addpath(self, path, frename, forigin): |
|
501 | def addpath(self, path, frename, forigin): | |
502 | """add a new conflicting path to the merge state |
|
502 | """add a new conflicting path to the merge state | |
503 | path: the path that conflicts |
|
503 | path: the path that conflicts | |
504 | frename: the filename the conflicting file was renamed to |
|
504 | frename: the filename the conflicting file was renamed to | |
505 | forigin: origin of the file ('l' or 'r' for local/remote) |
|
505 | forigin: origin of the file ('l' or 'r' for local/remote) | |
506 | """ |
|
506 | """ | |
507 | self._state[path] = [MERGE_RECORD_UNRESOLVED_PATH, frename, forigin] |
|
507 | self._state[path] = [MERGE_RECORD_UNRESOLVED_PATH, frename, forigin] | |
508 | self._dirty = True |
|
508 | self._dirty = True | |
509 |
|
509 | |||
510 | def __contains__(self, dfile): |
|
510 | def __contains__(self, dfile): | |
511 | return dfile in self._state |
|
511 | return dfile in self._state | |
512 |
|
512 | |||
513 | def __getitem__(self, dfile): |
|
513 | def __getitem__(self, dfile): | |
514 | return self._state[dfile][0] |
|
514 | return self._state[dfile][0] | |
515 |
|
515 | |||
516 | def __iter__(self): |
|
516 | def __iter__(self): | |
517 | return iter(sorted(self._state)) |
|
517 | return iter(sorted(self._state)) | |
518 |
|
518 | |||
519 | def files(self): |
|
519 | def files(self): | |
520 | return self._state.keys() |
|
520 | return self._state.keys() | |
521 |
|
521 | |||
522 | def mark(self, dfile, state): |
|
522 | def mark(self, dfile, state): | |
523 | self._state[dfile][0] = state |
|
523 | self._state[dfile][0] = state | |
524 | self._dirty = True |
|
524 | self._dirty = True | |
525 |
|
525 | |||
526 | def mdstate(self): |
|
526 | def mdstate(self): | |
527 | return self._mdstate |
|
527 | return self._mdstate | |
528 |
|
528 | |||
529 | def unresolved(self): |
|
529 | def unresolved(self): | |
530 | """Obtain the paths of unresolved files.""" |
|
530 | """Obtain the paths of unresolved files.""" | |
531 |
|
531 | |||
532 | for f, entry in self._state.iteritems(): |
|
532 | for f, entry in self._state.iteritems(): | |
533 | if entry[0] in (MERGE_RECORD_UNRESOLVED, |
|
533 | if entry[0] in (MERGE_RECORD_UNRESOLVED, | |
534 | MERGE_RECORD_UNRESOLVED_PATH): |
|
534 | MERGE_RECORD_UNRESOLVED_PATH): | |
535 | yield f |
|
535 | yield f | |
536 |
|
536 | |||
537 | def driverresolved(self): |
|
537 | def driverresolved(self): | |
538 | """Obtain the paths of driver-resolved files.""" |
|
538 | """Obtain the paths of driver-resolved files.""" | |
539 |
|
539 | |||
540 | for f, entry in self._state.items(): |
|
540 | for f, entry in self._state.items(): | |
541 | if entry[0] == MERGE_RECORD_DRIVER_RESOLVED: |
|
541 | if entry[0] == MERGE_RECORD_DRIVER_RESOLVED: | |
542 | yield f |
|
542 | yield f | |
543 |
|
543 | |||
544 | def extras(self, filename): |
|
544 | def extras(self, filename): | |
545 | return self._stateextras.setdefault(filename, {}) |
|
545 | return self._stateextras.setdefault(filename, {}) | |
546 |
|
546 | |||
547 | def _resolve(self, preresolve, dfile, wctx): |
|
547 | def _resolve(self, preresolve, dfile, wctx): | |
548 | """rerun merge process for file path `dfile`""" |
|
548 | """rerun merge process for file path `dfile`""" | |
549 | if self[dfile] in (MERGE_RECORD_RESOLVED, |
|
549 | if self[dfile] in (MERGE_RECORD_RESOLVED, | |
550 | MERGE_RECORD_DRIVER_RESOLVED): |
|
550 | MERGE_RECORD_DRIVER_RESOLVED): | |
551 | return True, 0 |
|
551 | return True, 0 | |
552 | stateentry = self._state[dfile] |
|
552 | stateentry = self._state[dfile] | |
553 | state, hash, lfile, afile, anode, ofile, onode, flags = stateentry |
|
553 | state, hash, lfile, afile, anode, ofile, onode, flags = stateentry | |
554 | octx = self._repo[self._other] |
|
554 | octx = self._repo[self._other] | |
555 | extras = self.extras(dfile) |
|
555 | extras = self.extras(dfile) | |
556 | anccommitnode = extras.get('ancestorlinknode') |
|
556 | anccommitnode = extras.get('ancestorlinknode') | |
557 | if anccommitnode: |
|
557 | if anccommitnode: | |
558 | actx = self._repo[anccommitnode] |
|
558 | actx = self._repo[anccommitnode] | |
559 | else: |
|
559 | else: | |
560 | actx = None |
|
560 | actx = None | |
561 | fcd = self._filectxorabsent(hash, wctx, dfile) |
|
561 | fcd = self._filectxorabsent(hash, wctx, dfile) | |
562 | fco = self._filectxorabsent(onode, octx, ofile) |
|
562 | fco = self._filectxorabsent(onode, octx, ofile) | |
563 | # TODO: move this to filectxorabsent |
|
563 | # TODO: move this to filectxorabsent | |
564 |
fca = self._repo.filectx(afile, fileid=anode, change |
|
564 | fca = self._repo.filectx(afile, fileid=anode, changectx=actx) | |
565 | # "premerge" x flags |
|
565 | # "premerge" x flags | |
566 | flo = fco.flags() |
|
566 | flo = fco.flags() | |
567 | fla = fca.flags() |
|
567 | fla = fca.flags() | |
568 | if 'x' in flags + flo + fla and 'l' not in flags + flo + fla: |
|
568 | if 'x' in flags + flo + fla and 'l' not in flags + flo + fla: | |
569 | if fca.node() == nullid and flags != flo: |
|
569 | if fca.node() == nullid and flags != flo: | |
570 | if preresolve: |
|
570 | if preresolve: | |
571 | self._repo.ui.warn( |
|
571 | self._repo.ui.warn( | |
572 | _('warning: cannot merge flags for %s ' |
|
572 | _('warning: cannot merge flags for %s ' | |
573 | 'without common ancestor - keeping local flags\n') |
|
573 | 'without common ancestor - keeping local flags\n') | |
574 | % afile) |
|
574 | % afile) | |
575 | elif flags == fla: |
|
575 | elif flags == fla: | |
576 | flags = flo |
|
576 | flags = flo | |
577 | if preresolve: |
|
577 | if preresolve: | |
578 | # restore local |
|
578 | # restore local | |
579 | if hash != nullhex: |
|
579 | if hash != nullhex: | |
580 | f = self._repo.vfs('merge/' + hash) |
|
580 | f = self._repo.vfs('merge/' + hash) | |
581 | wctx[dfile].write(f.read(), flags) |
|
581 | wctx[dfile].write(f.read(), flags) | |
582 | f.close() |
|
582 | f.close() | |
583 | else: |
|
583 | else: | |
584 | wctx[dfile].remove(ignoremissing=True) |
|
584 | wctx[dfile].remove(ignoremissing=True) | |
585 | complete, r, deleted = filemerge.premerge(self._repo, wctx, |
|
585 | complete, r, deleted = filemerge.premerge(self._repo, wctx, | |
586 | self._local, lfile, fcd, |
|
586 | self._local, lfile, fcd, | |
587 | fco, fca, |
|
587 | fco, fca, | |
588 | labels=self._labels) |
|
588 | labels=self._labels) | |
589 | else: |
|
589 | else: | |
590 | complete, r, deleted = filemerge.filemerge(self._repo, wctx, |
|
590 | complete, r, deleted = filemerge.filemerge(self._repo, wctx, | |
591 | self._local, lfile, fcd, |
|
591 | self._local, lfile, fcd, | |
592 | fco, fca, |
|
592 | fco, fca, | |
593 | labels=self._labels) |
|
593 | labels=self._labels) | |
594 | if r is None: |
|
594 | if r is None: | |
595 | # no real conflict |
|
595 | # no real conflict | |
596 | del self._state[dfile] |
|
596 | del self._state[dfile] | |
597 | self._stateextras.pop(dfile, None) |
|
597 | self._stateextras.pop(dfile, None) | |
598 | self._dirty = True |
|
598 | self._dirty = True | |
599 | elif not r: |
|
599 | elif not r: | |
600 | self.mark(dfile, MERGE_RECORD_RESOLVED) |
|
600 | self.mark(dfile, MERGE_RECORD_RESOLVED) | |
601 |
|
601 | |||
602 | if complete: |
|
602 | if complete: | |
603 | action = None |
|
603 | action = None | |
604 | if deleted: |
|
604 | if deleted: | |
605 | if fcd.isabsent(): |
|
605 | if fcd.isabsent(): | |
606 | # dc: local picked. Need to drop if present, which may |
|
606 | # dc: local picked. Need to drop if present, which may | |
607 | # happen on re-resolves. |
|
607 | # happen on re-resolves. | |
608 | action = ACTION_FORGET |
|
608 | action = ACTION_FORGET | |
609 | else: |
|
609 | else: | |
610 | # cd: remote picked (or otherwise deleted) |
|
610 | # cd: remote picked (or otherwise deleted) | |
611 | action = ACTION_REMOVE |
|
611 | action = ACTION_REMOVE | |
612 | else: |
|
612 | else: | |
613 | if fcd.isabsent(): # dc: remote picked |
|
613 | if fcd.isabsent(): # dc: remote picked | |
614 | action = ACTION_GET |
|
614 | action = ACTION_GET | |
615 | elif fco.isabsent(): # cd: local picked |
|
615 | elif fco.isabsent(): # cd: local picked | |
616 | if dfile in self.localctx: |
|
616 | if dfile in self.localctx: | |
617 | action = ACTION_ADD_MODIFIED |
|
617 | action = ACTION_ADD_MODIFIED | |
618 | else: |
|
618 | else: | |
619 | action = ACTION_ADD |
|
619 | action = ACTION_ADD | |
620 | # else: regular merges (no action necessary) |
|
620 | # else: regular merges (no action necessary) | |
621 | self._results[dfile] = r, action |
|
621 | self._results[dfile] = r, action | |
622 |
|
622 | |||
623 | return complete, r |
|
623 | return complete, r | |
624 |
|
624 | |||
625 | def _filectxorabsent(self, hexnode, ctx, f): |
|
625 | def _filectxorabsent(self, hexnode, ctx, f): | |
626 | if hexnode == nullhex: |
|
626 | if hexnode == nullhex: | |
627 | return filemerge.absentfilectx(ctx, f) |
|
627 | return filemerge.absentfilectx(ctx, f) | |
628 | else: |
|
628 | else: | |
629 | return ctx[f] |
|
629 | return ctx[f] | |
630 |
|
630 | |||
631 | def preresolve(self, dfile, wctx): |
|
631 | def preresolve(self, dfile, wctx): | |
632 | """run premerge process for dfile |
|
632 | """run premerge process for dfile | |
633 |
|
633 | |||
634 | Returns whether the merge is complete, and the exit code.""" |
|
634 | Returns whether the merge is complete, and the exit code.""" | |
635 | return self._resolve(True, dfile, wctx) |
|
635 | return self._resolve(True, dfile, wctx) | |
636 |
|
636 | |||
637 | def resolve(self, dfile, wctx): |
|
637 | def resolve(self, dfile, wctx): | |
638 | """run merge process (assuming premerge was run) for dfile |
|
638 | """run merge process (assuming premerge was run) for dfile | |
639 |
|
639 | |||
640 | Returns the exit code of the merge.""" |
|
640 | Returns the exit code of the merge.""" | |
641 | return self._resolve(False, dfile, wctx)[1] |
|
641 | return self._resolve(False, dfile, wctx)[1] | |
642 |
|
642 | |||
643 | def counts(self): |
|
643 | def counts(self): | |
644 | """return counts for updated, merged and removed files in this |
|
644 | """return counts for updated, merged and removed files in this | |
645 | session""" |
|
645 | session""" | |
646 | updated, merged, removed = 0, 0, 0 |
|
646 | updated, merged, removed = 0, 0, 0 | |
647 | for r, action in self._results.itervalues(): |
|
647 | for r, action in self._results.itervalues(): | |
648 | if r is None: |
|
648 | if r is None: | |
649 | updated += 1 |
|
649 | updated += 1 | |
650 | elif r == 0: |
|
650 | elif r == 0: | |
651 | if action == ACTION_REMOVE: |
|
651 | if action == ACTION_REMOVE: | |
652 | removed += 1 |
|
652 | removed += 1 | |
653 | else: |
|
653 | else: | |
654 | merged += 1 |
|
654 | merged += 1 | |
655 | return updated, merged, removed |
|
655 | return updated, merged, removed | |
656 |
|
656 | |||
657 | def unresolvedcount(self): |
|
657 | def unresolvedcount(self): | |
658 | """get unresolved count for this merge (persistent)""" |
|
658 | """get unresolved count for this merge (persistent)""" | |
659 | return len(list(self.unresolved())) |
|
659 | return len(list(self.unresolved())) | |
660 |
|
660 | |||
661 | def actions(self): |
|
661 | def actions(self): | |
662 | """return lists of actions to perform on the dirstate""" |
|
662 | """return lists of actions to perform on the dirstate""" | |
663 | actions = { |
|
663 | actions = { | |
664 | ACTION_REMOVE: [], |
|
664 | ACTION_REMOVE: [], | |
665 | ACTION_FORGET: [], |
|
665 | ACTION_FORGET: [], | |
666 | ACTION_ADD: [], |
|
666 | ACTION_ADD: [], | |
667 | ACTION_ADD_MODIFIED: [], |
|
667 | ACTION_ADD_MODIFIED: [], | |
668 | ACTION_GET: [], |
|
668 | ACTION_GET: [], | |
669 | } |
|
669 | } | |
670 | for f, (r, action) in self._results.iteritems(): |
|
670 | for f, (r, action) in self._results.iteritems(): | |
671 | if action is not None: |
|
671 | if action is not None: | |
672 | actions[action].append((f, None, "merge result")) |
|
672 | actions[action].append((f, None, "merge result")) | |
673 | return actions |
|
673 | return actions | |
674 |
|
674 | |||
675 | def recordactions(self): |
|
675 | def recordactions(self): | |
676 | """record remove/add/get actions in the dirstate""" |
|
676 | """record remove/add/get actions in the dirstate""" | |
677 | branchmerge = self._repo.dirstate.p2() != nullid |
|
677 | branchmerge = self._repo.dirstate.p2() != nullid | |
678 | recordupdates(self._repo, self.actions(), branchmerge) |
|
678 | recordupdates(self._repo, self.actions(), branchmerge) | |
679 |
|
679 | |||
680 | def queueremove(self, f): |
|
680 | def queueremove(self, f): | |
681 | """queues a file to be removed from the dirstate |
|
681 | """queues a file to be removed from the dirstate | |
682 |
|
682 | |||
683 | Meant for use by custom merge drivers.""" |
|
683 | Meant for use by custom merge drivers.""" | |
684 | self._results[f] = 0, ACTION_REMOVE |
|
684 | self._results[f] = 0, ACTION_REMOVE | |
685 |
|
685 | |||
686 | def queueadd(self, f): |
|
686 | def queueadd(self, f): | |
687 | """queues a file to be added to the dirstate |
|
687 | """queues a file to be added to the dirstate | |
688 |
|
688 | |||
689 | Meant for use by custom merge drivers.""" |
|
689 | Meant for use by custom merge drivers.""" | |
690 | self._results[f] = 0, ACTION_ADD |
|
690 | self._results[f] = 0, ACTION_ADD | |
691 |
|
691 | |||
692 | def queueget(self, f): |
|
692 | def queueget(self, f): | |
693 | """queues a file to be marked modified in the dirstate |
|
693 | """queues a file to be marked modified in the dirstate | |
694 |
|
694 | |||
695 | Meant for use by custom merge drivers.""" |
|
695 | Meant for use by custom merge drivers.""" | |
696 | self._results[f] = 0, ACTION_GET |
|
696 | self._results[f] = 0, ACTION_GET | |
697 |
|
697 | |||
698 | def _getcheckunknownconfig(repo, section, name): |
|
698 | def _getcheckunknownconfig(repo, section, name): | |
699 | config = repo.ui.config(section, name) |
|
699 | config = repo.ui.config(section, name) | |
700 | valid = ['abort', 'ignore', 'warn'] |
|
700 | valid = ['abort', 'ignore', 'warn'] | |
701 | if config not in valid: |
|
701 | if config not in valid: | |
702 | validstr = ', '.join(["'" + v + "'" for v in valid]) |
|
702 | validstr = ', '.join(["'" + v + "'" for v in valid]) | |
703 | raise error.ConfigError(_("%s.%s not valid " |
|
703 | raise error.ConfigError(_("%s.%s not valid " | |
704 | "('%s' is none of %s)") |
|
704 | "('%s' is none of %s)") | |
705 | % (section, name, config, validstr)) |
|
705 | % (section, name, config, validstr)) | |
706 | return config |
|
706 | return config | |
707 |
|
707 | |||
708 | def _checkunknownfile(repo, wctx, mctx, f, f2=None): |
|
708 | def _checkunknownfile(repo, wctx, mctx, f, f2=None): | |
709 | if wctx.isinmemory(): |
|
709 | if wctx.isinmemory(): | |
710 | # Nothing to do in IMM because nothing in the "working copy" can be an |
|
710 | # Nothing to do in IMM because nothing in the "working copy" can be an | |
711 | # unknown file. |
|
711 | # unknown file. | |
712 | # |
|
712 | # | |
713 | # Note that we should bail out here, not in ``_checkunknownfiles()``, |
|
713 | # Note that we should bail out here, not in ``_checkunknownfiles()``, | |
714 | # because that function does other useful work. |
|
714 | # because that function does other useful work. | |
715 | return False |
|
715 | return False | |
716 |
|
716 | |||
717 | if f2 is None: |
|
717 | if f2 is None: | |
718 | f2 = f |
|
718 | f2 = f | |
719 | return (repo.wvfs.audit.check(f) |
|
719 | return (repo.wvfs.audit.check(f) | |
720 | and repo.wvfs.isfileorlink(f) |
|
720 | and repo.wvfs.isfileorlink(f) | |
721 | and repo.dirstate.normalize(f) not in repo.dirstate |
|
721 | and repo.dirstate.normalize(f) not in repo.dirstate | |
722 | and mctx[f2].cmp(wctx[f])) |
|
722 | and mctx[f2].cmp(wctx[f])) | |
723 |
|
723 | |||
724 | class _unknowndirschecker(object): |
|
724 | class _unknowndirschecker(object): | |
725 | """ |
|
725 | """ | |
726 | Look for any unknown files or directories that may have a path conflict |
|
726 | Look for any unknown files or directories that may have a path conflict | |
727 | with a file. If any path prefix of the file exists as a file or link, |
|
727 | with a file. If any path prefix of the file exists as a file or link, | |
728 | then it conflicts. If the file itself is a directory that contains any |
|
728 | then it conflicts. If the file itself is a directory that contains any | |
729 | file that is not tracked, then it conflicts. |
|
729 | file that is not tracked, then it conflicts. | |
730 |
|
730 | |||
731 | Returns the shortest path at which a conflict occurs, or None if there is |
|
731 | Returns the shortest path at which a conflict occurs, or None if there is | |
732 | no conflict. |
|
732 | no conflict. | |
733 | """ |
|
733 | """ | |
734 | def __init__(self): |
|
734 | def __init__(self): | |
735 | # A set of paths known to be good. This prevents repeated checking of |
|
735 | # A set of paths known to be good. This prevents repeated checking of | |
736 | # dirs. It will be updated with any new dirs that are checked and found |
|
736 | # dirs. It will be updated with any new dirs that are checked and found | |
737 | # to be safe. |
|
737 | # to be safe. | |
738 | self._unknowndircache = set() |
|
738 | self._unknowndircache = set() | |
739 |
|
739 | |||
740 | # A set of paths that are known to be absent. This prevents repeated |
|
740 | # A set of paths that are known to be absent. This prevents repeated | |
741 | # checking of subdirectories that are known not to exist. It will be |
|
741 | # checking of subdirectories that are known not to exist. It will be | |
742 | # updated with any new dirs that are checked and found to be absent. |
|
742 | # updated with any new dirs that are checked and found to be absent. | |
743 | self._missingdircache = set() |
|
743 | self._missingdircache = set() | |
744 |
|
744 | |||
745 | def __call__(self, repo, wctx, f): |
|
745 | def __call__(self, repo, wctx, f): | |
746 | if wctx.isinmemory(): |
|
746 | if wctx.isinmemory(): | |
747 | # Nothing to do in IMM for the same reason as ``_checkunknownfile``. |
|
747 | # Nothing to do in IMM for the same reason as ``_checkunknownfile``. | |
748 | return False |
|
748 | return False | |
749 |
|
749 | |||
750 | # Check for path prefixes that exist as unknown files. |
|
750 | # Check for path prefixes that exist as unknown files. | |
751 | for p in reversed(list(util.finddirs(f))): |
|
751 | for p in reversed(list(util.finddirs(f))): | |
752 | if p in self._missingdircache: |
|
752 | if p in self._missingdircache: | |
753 | return |
|
753 | return | |
754 | if p in self._unknowndircache: |
|
754 | if p in self._unknowndircache: | |
755 | continue |
|
755 | continue | |
756 | if repo.wvfs.audit.check(p): |
|
756 | if repo.wvfs.audit.check(p): | |
757 | if (repo.wvfs.isfileorlink(p) |
|
757 | if (repo.wvfs.isfileorlink(p) | |
758 | and repo.dirstate.normalize(p) not in repo.dirstate): |
|
758 | and repo.dirstate.normalize(p) not in repo.dirstate): | |
759 | return p |
|
759 | return p | |
760 | if not repo.wvfs.lexists(p): |
|
760 | if not repo.wvfs.lexists(p): | |
761 | self._missingdircache.add(p) |
|
761 | self._missingdircache.add(p) | |
762 | return |
|
762 | return | |
763 | self._unknowndircache.add(p) |
|
763 | self._unknowndircache.add(p) | |
764 |
|
764 | |||
765 | # Check if the file conflicts with a directory containing unknown files. |
|
765 | # Check if the file conflicts with a directory containing unknown files. | |
766 | if repo.wvfs.audit.check(f) and repo.wvfs.isdir(f): |
|
766 | if repo.wvfs.audit.check(f) and repo.wvfs.isdir(f): | |
767 | # Does the directory contain any files that are not in the dirstate? |
|
767 | # Does the directory contain any files that are not in the dirstate? | |
768 | for p, dirs, files in repo.wvfs.walk(f): |
|
768 | for p, dirs, files in repo.wvfs.walk(f): | |
769 | for fn in files: |
|
769 | for fn in files: | |
770 | relf = util.pconvert(repo.wvfs.reljoin(p, fn)) |
|
770 | relf = util.pconvert(repo.wvfs.reljoin(p, fn)) | |
771 | relf = repo.dirstate.normalize(relf, isknown=True) |
|
771 | relf = repo.dirstate.normalize(relf, isknown=True) | |
772 | if relf not in repo.dirstate: |
|
772 | if relf not in repo.dirstate: | |
773 | return f |
|
773 | return f | |
774 | return None |
|
774 | return None | |
775 |
|
775 | |||
776 | def _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce): |
|
776 | def _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce): | |
777 | """ |
|
777 | """ | |
778 | Considers any actions that care about the presence of conflicting unknown |
|
778 | Considers any actions that care about the presence of conflicting unknown | |
779 | files. For some actions, the result is to abort; for others, it is to |
|
779 | files. For some actions, the result is to abort; for others, it is to | |
780 | choose a different action. |
|
780 | choose a different action. | |
781 | """ |
|
781 | """ | |
782 | fileconflicts = set() |
|
782 | fileconflicts = set() | |
783 | pathconflicts = set() |
|
783 | pathconflicts = set() | |
784 | warnconflicts = set() |
|
784 | warnconflicts = set() | |
785 | abortconflicts = set() |
|
785 | abortconflicts = set() | |
786 | unknownconfig = _getcheckunknownconfig(repo, 'merge', 'checkunknown') |
|
786 | unknownconfig = _getcheckunknownconfig(repo, 'merge', 'checkunknown') | |
787 | ignoredconfig = _getcheckunknownconfig(repo, 'merge', 'checkignored') |
|
787 | ignoredconfig = _getcheckunknownconfig(repo, 'merge', 'checkignored') | |
788 | pathconfig = repo.ui.configbool('experimental', 'merge.checkpathconflicts') |
|
788 | pathconfig = repo.ui.configbool('experimental', 'merge.checkpathconflicts') | |
789 | if not force: |
|
789 | if not force: | |
790 | def collectconflicts(conflicts, config): |
|
790 | def collectconflicts(conflicts, config): | |
791 | if config == 'abort': |
|
791 | if config == 'abort': | |
792 | abortconflicts.update(conflicts) |
|
792 | abortconflicts.update(conflicts) | |
793 | elif config == 'warn': |
|
793 | elif config == 'warn': | |
794 | warnconflicts.update(conflicts) |
|
794 | warnconflicts.update(conflicts) | |
795 |
|
795 | |||
796 | checkunknowndirs = _unknowndirschecker() |
|
796 | checkunknowndirs = _unknowndirschecker() | |
797 | for f, (m, args, msg) in actions.iteritems(): |
|
797 | for f, (m, args, msg) in actions.iteritems(): | |
798 | if m in (ACTION_CREATED, ACTION_DELETED_CHANGED): |
|
798 | if m in (ACTION_CREATED, ACTION_DELETED_CHANGED): | |
799 | if _checkunknownfile(repo, wctx, mctx, f): |
|
799 | if _checkunknownfile(repo, wctx, mctx, f): | |
800 | fileconflicts.add(f) |
|
800 | fileconflicts.add(f) | |
801 | elif pathconfig and f not in wctx: |
|
801 | elif pathconfig and f not in wctx: | |
802 | path = checkunknowndirs(repo, wctx, f) |
|
802 | path = checkunknowndirs(repo, wctx, f) | |
803 | if path is not None: |
|
803 | if path is not None: | |
804 | pathconflicts.add(path) |
|
804 | pathconflicts.add(path) | |
805 | elif m == ACTION_LOCAL_DIR_RENAME_GET: |
|
805 | elif m == ACTION_LOCAL_DIR_RENAME_GET: | |
806 | if _checkunknownfile(repo, wctx, mctx, f, args[0]): |
|
806 | if _checkunknownfile(repo, wctx, mctx, f, args[0]): | |
807 | fileconflicts.add(f) |
|
807 | fileconflicts.add(f) | |
808 |
|
808 | |||
809 | allconflicts = fileconflicts | pathconflicts |
|
809 | allconflicts = fileconflicts | pathconflicts | |
810 | ignoredconflicts = set([c for c in allconflicts |
|
810 | ignoredconflicts = set([c for c in allconflicts | |
811 | if repo.dirstate._ignore(c)]) |
|
811 | if repo.dirstate._ignore(c)]) | |
812 | unknownconflicts = allconflicts - ignoredconflicts |
|
812 | unknownconflicts = allconflicts - ignoredconflicts | |
813 | collectconflicts(ignoredconflicts, ignoredconfig) |
|
813 | collectconflicts(ignoredconflicts, ignoredconfig) | |
814 | collectconflicts(unknownconflicts, unknownconfig) |
|
814 | collectconflicts(unknownconflicts, unknownconfig) | |
815 | else: |
|
815 | else: | |
816 | for f, (m, args, msg) in actions.iteritems(): |
|
816 | for f, (m, args, msg) in actions.iteritems(): | |
817 | if m == ACTION_CREATED_MERGE: |
|
817 | if m == ACTION_CREATED_MERGE: | |
818 | fl2, anc = args |
|
818 | fl2, anc = args | |
819 | different = _checkunknownfile(repo, wctx, mctx, f) |
|
819 | different = _checkunknownfile(repo, wctx, mctx, f) | |
820 | if repo.dirstate._ignore(f): |
|
820 | if repo.dirstate._ignore(f): | |
821 | config = ignoredconfig |
|
821 | config = ignoredconfig | |
822 | else: |
|
822 | else: | |
823 | config = unknownconfig |
|
823 | config = unknownconfig | |
824 |
|
824 | |||
825 | # The behavior when force is True is described by this table: |
|
825 | # The behavior when force is True is described by this table: | |
826 | # config different mergeforce | action backup |
|
826 | # config different mergeforce | action backup | |
827 | # * n * | get n |
|
827 | # * n * | get n | |
828 | # * y y | merge - |
|
828 | # * y y | merge - | |
829 | # abort y n | merge - (1) |
|
829 | # abort y n | merge - (1) | |
830 | # warn y n | warn + get y |
|
830 | # warn y n | warn + get y | |
831 | # ignore y n | get y |
|
831 | # ignore y n | get y | |
832 | # |
|
832 | # | |
833 | # (1) this is probably the wrong behavior here -- we should |
|
833 | # (1) this is probably the wrong behavior here -- we should | |
834 | # probably abort, but some actions like rebases currently |
|
834 | # probably abort, but some actions like rebases currently | |
835 | # don't like an abort happening in the middle of |
|
835 | # don't like an abort happening in the middle of | |
836 | # merge.update. |
|
836 | # merge.update. | |
837 | if not different: |
|
837 | if not different: | |
838 | actions[f] = (ACTION_GET, (fl2, False), 'remote created') |
|
838 | actions[f] = (ACTION_GET, (fl2, False), 'remote created') | |
839 | elif mergeforce or config == 'abort': |
|
839 | elif mergeforce or config == 'abort': | |
840 | actions[f] = (ACTION_MERGE, (f, f, None, False, anc), |
|
840 | actions[f] = (ACTION_MERGE, (f, f, None, False, anc), | |
841 | 'remote differs from untracked local') |
|
841 | 'remote differs from untracked local') | |
842 | elif config == 'abort': |
|
842 | elif config == 'abort': | |
843 | abortconflicts.add(f) |
|
843 | abortconflicts.add(f) | |
844 | else: |
|
844 | else: | |
845 | if config == 'warn': |
|
845 | if config == 'warn': | |
846 | warnconflicts.add(f) |
|
846 | warnconflicts.add(f) | |
847 | actions[f] = (ACTION_GET, (fl2, True), 'remote created') |
|
847 | actions[f] = (ACTION_GET, (fl2, True), 'remote created') | |
848 |
|
848 | |||
849 | for f in sorted(abortconflicts): |
|
849 | for f in sorted(abortconflicts): | |
850 | warn = repo.ui.warn |
|
850 | warn = repo.ui.warn | |
851 | if f in pathconflicts: |
|
851 | if f in pathconflicts: | |
852 | if repo.wvfs.isfileorlink(f): |
|
852 | if repo.wvfs.isfileorlink(f): | |
853 | warn(_("%s: untracked file conflicts with directory\n") % f) |
|
853 | warn(_("%s: untracked file conflicts with directory\n") % f) | |
854 | else: |
|
854 | else: | |
855 | warn(_("%s: untracked directory conflicts with file\n") % f) |
|
855 | warn(_("%s: untracked directory conflicts with file\n") % f) | |
856 | else: |
|
856 | else: | |
857 | warn(_("%s: untracked file differs\n") % f) |
|
857 | warn(_("%s: untracked file differs\n") % f) | |
858 | if abortconflicts: |
|
858 | if abortconflicts: | |
859 | raise error.Abort(_("untracked files in working directory " |
|
859 | raise error.Abort(_("untracked files in working directory " | |
860 | "differ from files in requested revision")) |
|
860 | "differ from files in requested revision")) | |
861 |
|
861 | |||
862 | for f in sorted(warnconflicts): |
|
862 | for f in sorted(warnconflicts): | |
863 | if repo.wvfs.isfileorlink(f): |
|
863 | if repo.wvfs.isfileorlink(f): | |
864 | repo.ui.warn(_("%s: replacing untracked file\n") % f) |
|
864 | repo.ui.warn(_("%s: replacing untracked file\n") % f) | |
865 | else: |
|
865 | else: | |
866 | repo.ui.warn(_("%s: replacing untracked files in directory\n") % f) |
|
866 | repo.ui.warn(_("%s: replacing untracked files in directory\n") % f) | |
867 |
|
867 | |||
868 | for f, (m, args, msg) in actions.iteritems(): |
|
868 | for f, (m, args, msg) in actions.iteritems(): | |
869 | if m == ACTION_CREATED: |
|
869 | if m == ACTION_CREATED: | |
870 | backup = (f in fileconflicts or f in pathconflicts or |
|
870 | backup = (f in fileconflicts or f in pathconflicts or | |
871 | any(p in pathconflicts for p in util.finddirs(f))) |
|
871 | any(p in pathconflicts for p in util.finddirs(f))) | |
872 | flags, = args |
|
872 | flags, = args | |
873 | actions[f] = (ACTION_GET, (flags, backup), msg) |
|
873 | actions[f] = (ACTION_GET, (flags, backup), msg) | |
874 |
|
874 | |||
875 | def _forgetremoved(wctx, mctx, branchmerge): |
|
875 | def _forgetremoved(wctx, mctx, branchmerge): | |
876 | """ |
|
876 | """ | |
877 | Forget removed files |
|
877 | Forget removed files | |
878 |
|
878 | |||
879 | If we're jumping between revisions (as opposed to merging), and if |
|
879 | If we're jumping between revisions (as opposed to merging), and if | |
880 | neither the working directory nor the target rev has the file, |
|
880 | neither the working directory nor the target rev has the file, | |
881 | then we need to remove it from the dirstate, to prevent the |
|
881 | then we need to remove it from the dirstate, to prevent the | |
882 | dirstate from listing the file when it is no longer in the |
|
882 | dirstate from listing the file when it is no longer in the | |
883 | manifest. |
|
883 | manifest. | |
884 |
|
884 | |||
885 | If we're merging, and the other revision has removed a file |
|
885 | If we're merging, and the other revision has removed a file | |
886 | that is not present in the working directory, we need to mark it |
|
886 | that is not present in the working directory, we need to mark it | |
887 | as removed. |
|
887 | as removed. | |
888 | """ |
|
888 | """ | |
889 |
|
889 | |||
890 | actions = {} |
|
890 | actions = {} | |
891 | m = ACTION_FORGET |
|
891 | m = ACTION_FORGET | |
892 | if branchmerge: |
|
892 | if branchmerge: | |
893 | m = ACTION_REMOVE |
|
893 | m = ACTION_REMOVE | |
894 | for f in wctx.deleted(): |
|
894 | for f in wctx.deleted(): | |
895 | if f not in mctx: |
|
895 | if f not in mctx: | |
896 | actions[f] = m, None, "forget deleted" |
|
896 | actions[f] = m, None, "forget deleted" | |
897 |
|
897 | |||
898 | if not branchmerge: |
|
898 | if not branchmerge: | |
899 | for f in wctx.removed(): |
|
899 | for f in wctx.removed(): | |
900 | if f not in mctx: |
|
900 | if f not in mctx: | |
901 | actions[f] = ACTION_FORGET, None, "forget removed" |
|
901 | actions[f] = ACTION_FORGET, None, "forget removed" | |
902 |
|
902 | |||
903 | return actions |
|
903 | return actions | |
904 |
|
904 | |||
905 | def _checkcollision(repo, wmf, actions): |
|
905 | def _checkcollision(repo, wmf, actions): | |
906 | # build provisional merged manifest up |
|
906 | # build provisional merged manifest up | |
907 | pmmf = set(wmf) |
|
907 | pmmf = set(wmf) | |
908 |
|
908 | |||
909 | if actions: |
|
909 | if actions: | |
910 | # KEEP and EXEC are no-op |
|
910 | # KEEP and EXEC are no-op | |
911 | for m in (ACTION_ADD, ACTION_ADD_MODIFIED, ACTION_FORGET, ACTION_GET, |
|
911 | for m in (ACTION_ADD, ACTION_ADD_MODIFIED, ACTION_FORGET, ACTION_GET, | |
912 | ACTION_CHANGED_DELETED, ACTION_DELETED_CHANGED): |
|
912 | ACTION_CHANGED_DELETED, ACTION_DELETED_CHANGED): | |
913 | for f, args, msg in actions[m]: |
|
913 | for f, args, msg in actions[m]: | |
914 | pmmf.add(f) |
|
914 | pmmf.add(f) | |
915 | for f, args, msg in actions[ACTION_REMOVE]: |
|
915 | for f, args, msg in actions[ACTION_REMOVE]: | |
916 | pmmf.discard(f) |
|
916 | pmmf.discard(f) | |
917 | for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]: |
|
917 | for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]: | |
918 | f2, flags = args |
|
918 | f2, flags = args | |
919 | pmmf.discard(f2) |
|
919 | pmmf.discard(f2) | |
920 | pmmf.add(f) |
|
920 | pmmf.add(f) | |
921 | for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]: |
|
921 | for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]: | |
922 | pmmf.add(f) |
|
922 | pmmf.add(f) | |
923 | for f, args, msg in actions[ACTION_MERGE]: |
|
923 | for f, args, msg in actions[ACTION_MERGE]: | |
924 | f1, f2, fa, move, anc = args |
|
924 | f1, f2, fa, move, anc = args | |
925 | if move: |
|
925 | if move: | |
926 | pmmf.discard(f1) |
|
926 | pmmf.discard(f1) | |
927 | pmmf.add(f) |
|
927 | pmmf.add(f) | |
928 |
|
928 | |||
929 | # check case-folding collision in provisional merged manifest |
|
929 | # check case-folding collision in provisional merged manifest | |
930 | foldmap = {} |
|
930 | foldmap = {} | |
931 | for f in pmmf: |
|
931 | for f in pmmf: | |
932 | fold = util.normcase(f) |
|
932 | fold = util.normcase(f) | |
933 | if fold in foldmap: |
|
933 | if fold in foldmap: | |
934 | raise error.Abort(_("case-folding collision between %s and %s") |
|
934 | raise error.Abort(_("case-folding collision between %s and %s") | |
935 | % (f, foldmap[fold])) |
|
935 | % (f, foldmap[fold])) | |
936 | foldmap[fold] = f |
|
936 | foldmap[fold] = f | |
937 |
|
937 | |||
938 | # check case-folding of directories |
|
938 | # check case-folding of directories | |
939 | foldprefix = unfoldprefix = lastfull = '' |
|
939 | foldprefix = unfoldprefix = lastfull = '' | |
940 | for fold, f in sorted(foldmap.items()): |
|
940 | for fold, f in sorted(foldmap.items()): | |
941 | if fold.startswith(foldprefix) and not f.startswith(unfoldprefix): |
|
941 | if fold.startswith(foldprefix) and not f.startswith(unfoldprefix): | |
942 | # the folded prefix matches but actual casing is different |
|
942 | # the folded prefix matches but actual casing is different | |
943 | raise error.Abort(_("case-folding collision between " |
|
943 | raise error.Abort(_("case-folding collision between " | |
944 | "%s and directory of %s") % (lastfull, f)) |
|
944 | "%s and directory of %s") % (lastfull, f)) | |
945 | foldprefix = fold + '/' |
|
945 | foldprefix = fold + '/' | |
946 | unfoldprefix = f + '/' |
|
946 | unfoldprefix = f + '/' | |
947 | lastfull = f |
|
947 | lastfull = f | |
948 |
|
948 | |||
949 | def driverpreprocess(repo, ms, wctx, labels=None): |
|
949 | def driverpreprocess(repo, ms, wctx, labels=None): | |
950 | """run the preprocess step of the merge driver, if any |
|
950 | """run the preprocess step of the merge driver, if any | |
951 |
|
951 | |||
952 | This is currently not implemented -- it's an extension point.""" |
|
952 | This is currently not implemented -- it's an extension point.""" | |
953 | return True |
|
953 | return True | |
954 |
|
954 | |||
955 | def driverconclude(repo, ms, wctx, labels=None): |
|
955 | def driverconclude(repo, ms, wctx, labels=None): | |
956 | """run the conclude step of the merge driver, if any |
|
956 | """run the conclude step of the merge driver, if any | |
957 |
|
957 | |||
958 | This is currently not implemented -- it's an extension point.""" |
|
958 | This is currently not implemented -- it's an extension point.""" | |
959 | return True |
|
959 | return True | |
960 |
|
960 | |||
961 | def _filesindirs(repo, manifest, dirs): |
|
961 | def _filesindirs(repo, manifest, dirs): | |
962 | """ |
|
962 | """ | |
963 | Generator that yields pairs of all the files in the manifest that are found |
|
963 | Generator that yields pairs of all the files in the manifest that are found | |
964 | inside the directories listed in dirs, and which directory they are found |
|
964 | inside the directories listed in dirs, and which directory they are found | |
965 | in. |
|
965 | in. | |
966 | """ |
|
966 | """ | |
967 | for f in manifest: |
|
967 | for f in manifest: | |
968 | for p in util.finddirs(f): |
|
968 | for p in util.finddirs(f): | |
969 | if p in dirs: |
|
969 | if p in dirs: | |
970 | yield f, p |
|
970 | yield f, p | |
971 | break |
|
971 | break | |
972 |
|
972 | |||
973 | def checkpathconflicts(repo, wctx, mctx, actions): |
|
973 | def checkpathconflicts(repo, wctx, mctx, actions): | |
974 | """ |
|
974 | """ | |
975 | Check if any actions introduce path conflicts in the repository, updating |
|
975 | Check if any actions introduce path conflicts in the repository, updating | |
976 | actions to record or handle the path conflict accordingly. |
|
976 | actions to record or handle the path conflict accordingly. | |
977 | """ |
|
977 | """ | |
978 | mf = wctx.manifest() |
|
978 | mf = wctx.manifest() | |
979 |
|
979 | |||
980 | # The set of local files that conflict with a remote directory. |
|
980 | # The set of local files that conflict with a remote directory. | |
981 | localconflicts = set() |
|
981 | localconflicts = set() | |
982 |
|
982 | |||
983 | # The set of directories that conflict with a remote file, and so may cause |
|
983 | # The set of directories that conflict with a remote file, and so may cause | |
984 | # conflicts if they still contain any files after the merge. |
|
984 | # conflicts if they still contain any files after the merge. | |
985 | remoteconflicts = set() |
|
985 | remoteconflicts = set() | |
986 |
|
986 | |||
987 | # The set of directories that appear as both a file and a directory in the |
|
987 | # The set of directories that appear as both a file and a directory in the | |
988 | # remote manifest. These indicate an invalid remote manifest, which |
|
988 | # remote manifest. These indicate an invalid remote manifest, which | |
989 | # can't be updated to cleanly. |
|
989 | # can't be updated to cleanly. | |
990 | invalidconflicts = set() |
|
990 | invalidconflicts = set() | |
991 |
|
991 | |||
992 | # The set of directories that contain files that are being created. |
|
992 | # The set of directories that contain files that are being created. | |
993 | createdfiledirs = set() |
|
993 | createdfiledirs = set() | |
994 |
|
994 | |||
995 | # The set of files deleted by all the actions. |
|
995 | # The set of files deleted by all the actions. | |
996 | deletedfiles = set() |
|
996 | deletedfiles = set() | |
997 |
|
997 | |||
998 | for f, (m, args, msg) in actions.items(): |
|
998 | for f, (m, args, msg) in actions.items(): | |
999 | if m in (ACTION_CREATED, ACTION_DELETED_CHANGED, ACTION_MERGE, |
|
999 | if m in (ACTION_CREATED, ACTION_DELETED_CHANGED, ACTION_MERGE, | |
1000 | ACTION_CREATED_MERGE): |
|
1000 | ACTION_CREATED_MERGE): | |
1001 | # This action may create a new local file. |
|
1001 | # This action may create a new local file. | |
1002 | createdfiledirs.update(util.finddirs(f)) |
|
1002 | createdfiledirs.update(util.finddirs(f)) | |
1003 | if mf.hasdir(f): |
|
1003 | if mf.hasdir(f): | |
1004 | # The file aliases a local directory. This might be ok if all |
|
1004 | # The file aliases a local directory. This might be ok if all | |
1005 | # the files in the local directory are being deleted. This |
|
1005 | # the files in the local directory are being deleted. This | |
1006 | # will be checked once we know what all the deleted files are. |
|
1006 | # will be checked once we know what all the deleted files are. | |
1007 | remoteconflicts.add(f) |
|
1007 | remoteconflicts.add(f) | |
1008 | # Track the names of all deleted files. |
|
1008 | # Track the names of all deleted files. | |
1009 | if m == ACTION_REMOVE: |
|
1009 | if m == ACTION_REMOVE: | |
1010 | deletedfiles.add(f) |
|
1010 | deletedfiles.add(f) | |
1011 | if m == ACTION_MERGE: |
|
1011 | if m == ACTION_MERGE: | |
1012 | f1, f2, fa, move, anc = args |
|
1012 | f1, f2, fa, move, anc = args | |
1013 | if move: |
|
1013 | if move: | |
1014 | deletedfiles.add(f1) |
|
1014 | deletedfiles.add(f1) | |
1015 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: |
|
1015 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: | |
1016 | f2, flags = args |
|
1016 | f2, flags = args | |
1017 | deletedfiles.add(f2) |
|
1017 | deletedfiles.add(f2) | |
1018 |
|
1018 | |||
1019 | # Check all directories that contain created files for path conflicts. |
|
1019 | # Check all directories that contain created files for path conflicts. | |
1020 | for p in createdfiledirs: |
|
1020 | for p in createdfiledirs: | |
1021 | if p in mf: |
|
1021 | if p in mf: | |
1022 | if p in mctx: |
|
1022 | if p in mctx: | |
1023 | # A file is in a directory which aliases both a local |
|
1023 | # A file is in a directory which aliases both a local | |
1024 | # and a remote file. This is an internal inconsistency |
|
1024 | # and a remote file. This is an internal inconsistency | |
1025 | # within the remote manifest. |
|
1025 | # within the remote manifest. | |
1026 | invalidconflicts.add(p) |
|
1026 | invalidconflicts.add(p) | |
1027 | else: |
|
1027 | else: | |
1028 | # A file is in a directory which aliases a local file. |
|
1028 | # A file is in a directory which aliases a local file. | |
1029 | # We will need to rename the local file. |
|
1029 | # We will need to rename the local file. | |
1030 | localconflicts.add(p) |
|
1030 | localconflicts.add(p) | |
1031 | if p in actions and actions[p][0] in (ACTION_CREATED, |
|
1031 | if p in actions and actions[p][0] in (ACTION_CREATED, | |
1032 | ACTION_DELETED_CHANGED, |
|
1032 | ACTION_DELETED_CHANGED, | |
1033 | ACTION_MERGE, |
|
1033 | ACTION_MERGE, | |
1034 | ACTION_CREATED_MERGE): |
|
1034 | ACTION_CREATED_MERGE): | |
1035 | # The file is in a directory which aliases a remote file. |
|
1035 | # The file is in a directory which aliases a remote file. | |
1036 | # This is an internal inconsistency within the remote |
|
1036 | # This is an internal inconsistency within the remote | |
1037 | # manifest. |
|
1037 | # manifest. | |
1038 | invalidconflicts.add(p) |
|
1038 | invalidconflicts.add(p) | |
1039 |
|
1039 | |||
1040 | # Rename all local conflicting files that have not been deleted. |
|
1040 | # Rename all local conflicting files that have not been deleted. | |
1041 | for p in localconflicts: |
|
1041 | for p in localconflicts: | |
1042 | if p not in deletedfiles: |
|
1042 | if p not in deletedfiles: | |
1043 | ctxname = bytes(wctx).rstrip('+') |
|
1043 | ctxname = bytes(wctx).rstrip('+') | |
1044 | pnew = util.safename(p, ctxname, wctx, set(actions.keys())) |
|
1044 | pnew = util.safename(p, ctxname, wctx, set(actions.keys())) | |
1045 | actions[pnew] = (ACTION_PATH_CONFLICT_RESOLVE, (p,), |
|
1045 | actions[pnew] = (ACTION_PATH_CONFLICT_RESOLVE, (p,), | |
1046 | 'local path conflict') |
|
1046 | 'local path conflict') | |
1047 | actions[p] = (ACTION_PATH_CONFLICT, (pnew, 'l'), |
|
1047 | actions[p] = (ACTION_PATH_CONFLICT, (pnew, 'l'), | |
1048 | 'path conflict') |
|
1048 | 'path conflict') | |
1049 |
|
1049 | |||
1050 | if remoteconflicts: |
|
1050 | if remoteconflicts: | |
1051 | # Check if all files in the conflicting directories have been removed. |
|
1051 | # Check if all files in the conflicting directories have been removed. | |
1052 | ctxname = bytes(mctx).rstrip('+') |
|
1052 | ctxname = bytes(mctx).rstrip('+') | |
1053 | for f, p in _filesindirs(repo, mf, remoteconflicts): |
|
1053 | for f, p in _filesindirs(repo, mf, remoteconflicts): | |
1054 | if f not in deletedfiles: |
|
1054 | if f not in deletedfiles: | |
1055 | m, args, msg = actions[p] |
|
1055 | m, args, msg = actions[p] | |
1056 | pnew = util.safename(p, ctxname, wctx, set(actions.keys())) |
|
1056 | pnew = util.safename(p, ctxname, wctx, set(actions.keys())) | |
1057 | if m in (ACTION_DELETED_CHANGED, ACTION_MERGE): |
|
1057 | if m in (ACTION_DELETED_CHANGED, ACTION_MERGE): | |
1058 | # Action was merge, just update target. |
|
1058 | # Action was merge, just update target. | |
1059 | actions[pnew] = (m, args, msg) |
|
1059 | actions[pnew] = (m, args, msg) | |
1060 | else: |
|
1060 | else: | |
1061 | # Action was create, change to renamed get action. |
|
1061 | # Action was create, change to renamed get action. | |
1062 | fl = args[0] |
|
1062 | fl = args[0] | |
1063 | actions[pnew] = (ACTION_LOCAL_DIR_RENAME_GET, (p, fl), |
|
1063 | actions[pnew] = (ACTION_LOCAL_DIR_RENAME_GET, (p, fl), | |
1064 | 'remote path conflict') |
|
1064 | 'remote path conflict') | |
1065 | actions[p] = (ACTION_PATH_CONFLICT, (pnew, ACTION_REMOVE), |
|
1065 | actions[p] = (ACTION_PATH_CONFLICT, (pnew, ACTION_REMOVE), | |
1066 | 'path conflict') |
|
1066 | 'path conflict') | |
1067 | remoteconflicts.remove(p) |
|
1067 | remoteconflicts.remove(p) | |
1068 | break |
|
1068 | break | |
1069 |
|
1069 | |||
1070 | if invalidconflicts: |
|
1070 | if invalidconflicts: | |
1071 | for p in invalidconflicts: |
|
1071 | for p in invalidconflicts: | |
1072 | repo.ui.warn(_("%s: is both a file and a directory\n") % p) |
|
1072 | repo.ui.warn(_("%s: is both a file and a directory\n") % p) | |
1073 | raise error.Abort(_("destination manifest contains path conflicts")) |
|
1073 | raise error.Abort(_("destination manifest contains path conflicts")) | |
1074 |
|
1074 | |||
1075 | def manifestmerge(repo, wctx, p2, pa, branchmerge, force, matcher, |
|
1075 | def manifestmerge(repo, wctx, p2, pa, branchmerge, force, matcher, | |
1076 | acceptremote, followcopies, forcefulldiff=False): |
|
1076 | acceptremote, followcopies, forcefulldiff=False): | |
1077 | """ |
|
1077 | """ | |
1078 | Merge wctx and p2 with ancestor pa and generate merge action list |
|
1078 | Merge wctx and p2 with ancestor pa and generate merge action list | |
1079 |
|
1079 | |||
1080 | branchmerge and force are as passed in to update |
|
1080 | branchmerge and force are as passed in to update | |
1081 | matcher = matcher to filter file lists |
|
1081 | matcher = matcher to filter file lists | |
1082 | acceptremote = accept the incoming changes without prompting |
|
1082 | acceptremote = accept the incoming changes without prompting | |
1083 | """ |
|
1083 | """ | |
1084 | if matcher is not None and matcher.always(): |
|
1084 | if matcher is not None and matcher.always(): | |
1085 | matcher = None |
|
1085 | matcher = None | |
1086 |
|
1086 | |||
1087 | copy, movewithdir, diverge, renamedelete, dirmove = {}, {}, {}, {}, {} |
|
1087 | copy, movewithdir, diverge, renamedelete, dirmove = {}, {}, {}, {}, {} | |
1088 |
|
1088 | |||
1089 | # manifests fetched in order are going to be faster, so prime the caches |
|
1089 | # manifests fetched in order are going to be faster, so prime the caches | |
1090 | [x.manifest() for x in |
|
1090 | [x.manifest() for x in | |
1091 | sorted(wctx.parents() + [p2, pa], key=scmutil.intrev)] |
|
1091 | sorted(wctx.parents() + [p2, pa], key=scmutil.intrev)] | |
1092 |
|
1092 | |||
1093 | if followcopies: |
|
1093 | if followcopies: | |
1094 | ret = copies.mergecopies(repo, wctx, p2, pa) |
|
1094 | ret = copies.mergecopies(repo, wctx, p2, pa) | |
1095 | copy, movewithdir, diverge, renamedelete, dirmove = ret |
|
1095 | copy, movewithdir, diverge, renamedelete, dirmove = ret | |
1096 |
|
1096 | |||
1097 | boolbm = pycompat.bytestr(bool(branchmerge)) |
|
1097 | boolbm = pycompat.bytestr(bool(branchmerge)) | |
1098 | boolf = pycompat.bytestr(bool(force)) |
|
1098 | boolf = pycompat.bytestr(bool(force)) | |
1099 | boolm = pycompat.bytestr(bool(matcher)) |
|
1099 | boolm = pycompat.bytestr(bool(matcher)) | |
1100 | repo.ui.note(_("resolving manifests\n")) |
|
1100 | repo.ui.note(_("resolving manifests\n")) | |
1101 | repo.ui.debug(" branchmerge: %s, force: %s, partial: %s\n" |
|
1101 | repo.ui.debug(" branchmerge: %s, force: %s, partial: %s\n" | |
1102 | % (boolbm, boolf, boolm)) |
|
1102 | % (boolbm, boolf, boolm)) | |
1103 | repo.ui.debug(" ancestor: %s, local: %s, remote: %s\n" % (pa, wctx, p2)) |
|
1103 | repo.ui.debug(" ancestor: %s, local: %s, remote: %s\n" % (pa, wctx, p2)) | |
1104 |
|
1104 | |||
1105 | m1, m2, ma = wctx.manifest(), p2.manifest(), pa.manifest() |
|
1105 | m1, m2, ma = wctx.manifest(), p2.manifest(), pa.manifest() | |
1106 | copied = set(copy.values()) |
|
1106 | copied = set(copy.values()) | |
1107 | copied.update(movewithdir.values()) |
|
1107 | copied.update(movewithdir.values()) | |
1108 |
|
1108 | |||
1109 | if '.hgsubstate' in m1: |
|
1109 | if '.hgsubstate' in m1: | |
1110 | # check whether sub state is modified |
|
1110 | # check whether sub state is modified | |
1111 | if any(wctx.sub(s).dirty() for s in wctx.substate): |
|
1111 | if any(wctx.sub(s).dirty() for s in wctx.substate): | |
1112 | m1['.hgsubstate'] = modifiednodeid |
|
1112 | m1['.hgsubstate'] = modifiednodeid | |
1113 |
|
1113 | |||
1114 | # Don't use m2-vs-ma optimization if: |
|
1114 | # Don't use m2-vs-ma optimization if: | |
1115 | # - ma is the same as m1 or m2, which we're just going to diff again later |
|
1115 | # - ma is the same as m1 or m2, which we're just going to diff again later | |
1116 | # - The caller specifically asks for a full diff, which is useful during bid |
|
1116 | # - The caller specifically asks for a full diff, which is useful during bid | |
1117 | # merge. |
|
1117 | # merge. | |
1118 | if (pa not in ([wctx, p2] + wctx.parents()) and not forcefulldiff): |
|
1118 | if (pa not in ([wctx, p2] + wctx.parents()) and not forcefulldiff): | |
1119 | # Identify which files are relevant to the merge, so we can limit the |
|
1119 | # Identify which files are relevant to the merge, so we can limit the | |
1120 | # total m1-vs-m2 diff to just those files. This has significant |
|
1120 | # total m1-vs-m2 diff to just those files. This has significant | |
1121 | # performance benefits in large repositories. |
|
1121 | # performance benefits in large repositories. | |
1122 | relevantfiles = set(ma.diff(m2).keys()) |
|
1122 | relevantfiles = set(ma.diff(m2).keys()) | |
1123 |
|
1123 | |||
1124 | # For copied and moved files, we need to add the source file too. |
|
1124 | # For copied and moved files, we need to add the source file too. | |
1125 | for copykey, copyvalue in copy.iteritems(): |
|
1125 | for copykey, copyvalue in copy.iteritems(): | |
1126 | if copyvalue in relevantfiles: |
|
1126 | if copyvalue in relevantfiles: | |
1127 | relevantfiles.add(copykey) |
|
1127 | relevantfiles.add(copykey) | |
1128 | for movedirkey in movewithdir: |
|
1128 | for movedirkey in movewithdir: | |
1129 | relevantfiles.add(movedirkey) |
|
1129 | relevantfiles.add(movedirkey) | |
1130 | filesmatcher = scmutil.matchfiles(repo, relevantfiles) |
|
1130 | filesmatcher = scmutil.matchfiles(repo, relevantfiles) | |
1131 | matcher = matchmod.intersectmatchers(matcher, filesmatcher) |
|
1131 | matcher = matchmod.intersectmatchers(matcher, filesmatcher) | |
1132 |
|
1132 | |||
1133 | diff = m1.diff(m2, match=matcher) |
|
1133 | diff = m1.diff(m2, match=matcher) | |
1134 |
|
1134 | |||
1135 | if matcher is None: |
|
1135 | if matcher is None: | |
1136 | matcher = matchmod.always('', '') |
|
1136 | matcher = matchmod.always('', '') | |
1137 |
|
1137 | |||
1138 | actions = {} |
|
1138 | actions = {} | |
1139 | for f, ((n1, fl1), (n2, fl2)) in diff.iteritems(): |
|
1139 | for f, ((n1, fl1), (n2, fl2)) in diff.iteritems(): | |
1140 | if n1 and n2: # file exists on both local and remote side |
|
1140 | if n1 and n2: # file exists on both local and remote side | |
1141 | if f not in ma: |
|
1141 | if f not in ma: | |
1142 | fa = copy.get(f, None) |
|
1142 | fa = copy.get(f, None) | |
1143 | if fa is not None: |
|
1143 | if fa is not None: | |
1144 | actions[f] = (ACTION_MERGE, (f, f, fa, False, pa.node()), |
|
1144 | actions[f] = (ACTION_MERGE, (f, f, fa, False, pa.node()), | |
1145 | 'both renamed from %s' % fa) |
|
1145 | 'both renamed from %s' % fa) | |
1146 | else: |
|
1146 | else: | |
1147 | actions[f] = (ACTION_MERGE, (f, f, None, False, pa.node()), |
|
1147 | actions[f] = (ACTION_MERGE, (f, f, None, False, pa.node()), | |
1148 | 'both created') |
|
1148 | 'both created') | |
1149 | else: |
|
1149 | else: | |
1150 | a = ma[f] |
|
1150 | a = ma[f] | |
1151 | fla = ma.flags(f) |
|
1151 | fla = ma.flags(f) | |
1152 | nol = 'l' not in fl1 + fl2 + fla |
|
1152 | nol = 'l' not in fl1 + fl2 + fla | |
1153 | if n2 == a and fl2 == fla: |
|
1153 | if n2 == a and fl2 == fla: | |
1154 | actions[f] = (ACTION_KEEP, (), 'remote unchanged') |
|
1154 | actions[f] = (ACTION_KEEP, (), 'remote unchanged') | |
1155 | elif n1 == a and fl1 == fla: # local unchanged - use remote |
|
1155 | elif n1 == a and fl1 == fla: # local unchanged - use remote | |
1156 | if n1 == n2: # optimization: keep local content |
|
1156 | if n1 == n2: # optimization: keep local content | |
1157 | actions[f] = (ACTION_EXEC, (fl2,), 'update permissions') |
|
1157 | actions[f] = (ACTION_EXEC, (fl2,), 'update permissions') | |
1158 | else: |
|
1158 | else: | |
1159 | actions[f] = (ACTION_GET, (fl2, False), |
|
1159 | actions[f] = (ACTION_GET, (fl2, False), | |
1160 | 'remote is newer') |
|
1160 | 'remote is newer') | |
1161 | elif nol and n2 == a: # remote only changed 'x' |
|
1161 | elif nol and n2 == a: # remote only changed 'x' | |
1162 | actions[f] = (ACTION_EXEC, (fl2,), 'update permissions') |
|
1162 | actions[f] = (ACTION_EXEC, (fl2,), 'update permissions') | |
1163 | elif nol and n1 == a: # local only changed 'x' |
|
1163 | elif nol and n1 == a: # local only changed 'x' | |
1164 | actions[f] = (ACTION_GET, (fl1, False), 'remote is newer') |
|
1164 | actions[f] = (ACTION_GET, (fl1, False), 'remote is newer') | |
1165 | else: # both changed something |
|
1165 | else: # both changed something | |
1166 | actions[f] = (ACTION_MERGE, (f, f, f, False, pa.node()), |
|
1166 | actions[f] = (ACTION_MERGE, (f, f, f, False, pa.node()), | |
1167 | 'versions differ') |
|
1167 | 'versions differ') | |
1168 | elif n1: # file exists only on local side |
|
1168 | elif n1: # file exists only on local side | |
1169 | if f in copied: |
|
1169 | if f in copied: | |
1170 | pass # we'll deal with it on m2 side |
|
1170 | pass # we'll deal with it on m2 side | |
1171 | elif f in movewithdir: # directory rename, move local |
|
1171 | elif f in movewithdir: # directory rename, move local | |
1172 | f2 = movewithdir[f] |
|
1172 | f2 = movewithdir[f] | |
1173 | if f2 in m2: |
|
1173 | if f2 in m2: | |
1174 | actions[f2] = (ACTION_MERGE, (f, f2, None, True, pa.node()), |
|
1174 | actions[f2] = (ACTION_MERGE, (f, f2, None, True, pa.node()), | |
1175 | 'remote directory rename, both created') |
|
1175 | 'remote directory rename, both created') | |
1176 | else: |
|
1176 | else: | |
1177 | actions[f2] = (ACTION_DIR_RENAME_MOVE_LOCAL, (f, fl1), |
|
1177 | actions[f2] = (ACTION_DIR_RENAME_MOVE_LOCAL, (f, fl1), | |
1178 | 'remote directory rename - move from %s' % f) |
|
1178 | 'remote directory rename - move from %s' % f) | |
1179 | elif f in copy: |
|
1179 | elif f in copy: | |
1180 | f2 = copy[f] |
|
1180 | f2 = copy[f] | |
1181 | actions[f] = (ACTION_MERGE, (f, f2, f2, False, pa.node()), |
|
1181 | actions[f] = (ACTION_MERGE, (f, f2, f2, False, pa.node()), | |
1182 | 'local copied/moved from %s' % f2) |
|
1182 | 'local copied/moved from %s' % f2) | |
1183 | elif f in ma: # clean, a different, no remote |
|
1183 | elif f in ma: # clean, a different, no remote | |
1184 | if n1 != ma[f]: |
|
1184 | if n1 != ma[f]: | |
1185 | if acceptremote: |
|
1185 | if acceptremote: | |
1186 | actions[f] = (ACTION_REMOVE, None, 'remote delete') |
|
1186 | actions[f] = (ACTION_REMOVE, None, 'remote delete') | |
1187 | else: |
|
1187 | else: | |
1188 | actions[f] = (ACTION_CHANGED_DELETED, |
|
1188 | actions[f] = (ACTION_CHANGED_DELETED, | |
1189 | (f, None, f, False, pa.node()), |
|
1189 | (f, None, f, False, pa.node()), | |
1190 | 'prompt changed/deleted') |
|
1190 | 'prompt changed/deleted') | |
1191 | elif n1 == addednodeid: |
|
1191 | elif n1 == addednodeid: | |
1192 | # This extra 'a' is added by working copy manifest to mark |
|
1192 | # This extra 'a' is added by working copy manifest to mark | |
1193 | # the file as locally added. We should forget it instead of |
|
1193 | # the file as locally added. We should forget it instead of | |
1194 | # deleting it. |
|
1194 | # deleting it. | |
1195 | actions[f] = (ACTION_FORGET, None, 'remote deleted') |
|
1195 | actions[f] = (ACTION_FORGET, None, 'remote deleted') | |
1196 | else: |
|
1196 | else: | |
1197 | actions[f] = (ACTION_REMOVE, None, 'other deleted') |
|
1197 | actions[f] = (ACTION_REMOVE, None, 'other deleted') | |
1198 | elif n2: # file exists only on remote side |
|
1198 | elif n2: # file exists only on remote side | |
1199 | if f in copied: |
|
1199 | if f in copied: | |
1200 | pass # we'll deal with it on m1 side |
|
1200 | pass # we'll deal with it on m1 side | |
1201 | elif f in movewithdir: |
|
1201 | elif f in movewithdir: | |
1202 | f2 = movewithdir[f] |
|
1202 | f2 = movewithdir[f] | |
1203 | if f2 in m1: |
|
1203 | if f2 in m1: | |
1204 | actions[f2] = (ACTION_MERGE, |
|
1204 | actions[f2] = (ACTION_MERGE, | |
1205 | (f2, f, None, False, pa.node()), |
|
1205 | (f2, f, None, False, pa.node()), | |
1206 | 'local directory rename, both created') |
|
1206 | 'local directory rename, both created') | |
1207 | else: |
|
1207 | else: | |
1208 | actions[f2] = (ACTION_LOCAL_DIR_RENAME_GET, (f, fl2), |
|
1208 | actions[f2] = (ACTION_LOCAL_DIR_RENAME_GET, (f, fl2), | |
1209 | 'local directory rename - get from %s' % f) |
|
1209 | 'local directory rename - get from %s' % f) | |
1210 | elif f in copy: |
|
1210 | elif f in copy: | |
1211 | f2 = copy[f] |
|
1211 | f2 = copy[f] | |
1212 | if f2 in m2: |
|
1212 | if f2 in m2: | |
1213 | actions[f] = (ACTION_MERGE, (f2, f, f2, False, pa.node()), |
|
1213 | actions[f] = (ACTION_MERGE, (f2, f, f2, False, pa.node()), | |
1214 | 'remote copied from %s' % f2) |
|
1214 | 'remote copied from %s' % f2) | |
1215 | else: |
|
1215 | else: | |
1216 | actions[f] = (ACTION_MERGE, (f2, f, f2, True, pa.node()), |
|
1216 | actions[f] = (ACTION_MERGE, (f2, f, f2, True, pa.node()), | |
1217 | 'remote moved from %s' % f2) |
|
1217 | 'remote moved from %s' % f2) | |
1218 | elif f not in ma: |
|
1218 | elif f not in ma: | |
1219 | # local unknown, remote created: the logic is described by the |
|
1219 | # local unknown, remote created: the logic is described by the | |
1220 | # following table: |
|
1220 | # following table: | |
1221 | # |
|
1221 | # | |
1222 | # force branchmerge different | action |
|
1222 | # force branchmerge different | action | |
1223 | # n * * | create |
|
1223 | # n * * | create | |
1224 | # y n * | create |
|
1224 | # y n * | create | |
1225 | # y y n | create |
|
1225 | # y y n | create | |
1226 | # y y y | merge |
|
1226 | # y y y | merge | |
1227 | # |
|
1227 | # | |
1228 | # Checking whether the files are different is expensive, so we |
|
1228 | # Checking whether the files are different is expensive, so we | |
1229 | # don't do that when we can avoid it. |
|
1229 | # don't do that when we can avoid it. | |
1230 | if not force: |
|
1230 | if not force: | |
1231 | actions[f] = (ACTION_CREATED, (fl2,), 'remote created') |
|
1231 | actions[f] = (ACTION_CREATED, (fl2,), 'remote created') | |
1232 | elif not branchmerge: |
|
1232 | elif not branchmerge: | |
1233 | actions[f] = (ACTION_CREATED, (fl2,), 'remote created') |
|
1233 | actions[f] = (ACTION_CREATED, (fl2,), 'remote created') | |
1234 | else: |
|
1234 | else: | |
1235 | actions[f] = (ACTION_CREATED_MERGE, (fl2, pa.node()), |
|
1235 | actions[f] = (ACTION_CREATED_MERGE, (fl2, pa.node()), | |
1236 | 'remote created, get or merge') |
|
1236 | 'remote created, get or merge') | |
1237 | elif n2 != ma[f]: |
|
1237 | elif n2 != ma[f]: | |
1238 | df = None |
|
1238 | df = None | |
1239 | for d in dirmove: |
|
1239 | for d in dirmove: | |
1240 | if f.startswith(d): |
|
1240 | if f.startswith(d): | |
1241 | # new file added in a directory that was moved |
|
1241 | # new file added in a directory that was moved | |
1242 | df = dirmove[d] + f[len(d):] |
|
1242 | df = dirmove[d] + f[len(d):] | |
1243 | break |
|
1243 | break | |
1244 | if df is not None and df in m1: |
|
1244 | if df is not None and df in m1: | |
1245 | actions[df] = (ACTION_MERGE, (df, f, f, False, pa.node()), |
|
1245 | actions[df] = (ACTION_MERGE, (df, f, f, False, pa.node()), | |
1246 | 'local directory rename - respect move ' |
|
1246 | 'local directory rename - respect move ' | |
1247 | 'from %s' % f) |
|
1247 | 'from %s' % f) | |
1248 | elif acceptremote: |
|
1248 | elif acceptremote: | |
1249 | actions[f] = (ACTION_CREATED, (fl2,), 'remote recreating') |
|
1249 | actions[f] = (ACTION_CREATED, (fl2,), 'remote recreating') | |
1250 | else: |
|
1250 | else: | |
1251 | actions[f] = (ACTION_DELETED_CHANGED, |
|
1251 | actions[f] = (ACTION_DELETED_CHANGED, | |
1252 | (None, f, f, False, pa.node()), |
|
1252 | (None, f, f, False, pa.node()), | |
1253 | 'prompt deleted/changed') |
|
1253 | 'prompt deleted/changed') | |
1254 |
|
1254 | |||
1255 | if repo.ui.configbool('experimental', 'merge.checkpathconflicts'): |
|
1255 | if repo.ui.configbool('experimental', 'merge.checkpathconflicts'): | |
1256 | # If we are merging, look for path conflicts. |
|
1256 | # If we are merging, look for path conflicts. | |
1257 | checkpathconflicts(repo, wctx, p2, actions) |
|
1257 | checkpathconflicts(repo, wctx, p2, actions) | |
1258 |
|
1258 | |||
1259 | return actions, diverge, renamedelete |
|
1259 | return actions, diverge, renamedelete | |
1260 |
|
1260 | |||
1261 | def _resolvetrivial(repo, wctx, mctx, ancestor, actions): |
|
1261 | def _resolvetrivial(repo, wctx, mctx, ancestor, actions): | |
1262 | """Resolves false conflicts where the nodeid changed but the content |
|
1262 | """Resolves false conflicts where the nodeid changed but the content | |
1263 | remained the same.""" |
|
1263 | remained the same.""" | |
1264 | # We force a copy of actions.items() because we're going to mutate |
|
1264 | # We force a copy of actions.items() because we're going to mutate | |
1265 | # actions as we resolve trivial conflicts. |
|
1265 | # actions as we resolve trivial conflicts. | |
1266 | for f, (m, args, msg) in list(actions.items()): |
|
1266 | for f, (m, args, msg) in list(actions.items()): | |
1267 | if (m == ACTION_CHANGED_DELETED and f in ancestor |
|
1267 | if (m == ACTION_CHANGED_DELETED and f in ancestor | |
1268 | and not wctx[f].cmp(ancestor[f])): |
|
1268 | and not wctx[f].cmp(ancestor[f])): | |
1269 | # local did change but ended up with same content |
|
1269 | # local did change but ended up with same content | |
1270 | actions[f] = ACTION_REMOVE, None, 'prompt same' |
|
1270 | actions[f] = ACTION_REMOVE, None, 'prompt same' | |
1271 | elif (m == ACTION_DELETED_CHANGED and f in ancestor |
|
1271 | elif (m == ACTION_DELETED_CHANGED and f in ancestor | |
1272 | and not mctx[f].cmp(ancestor[f])): |
|
1272 | and not mctx[f].cmp(ancestor[f])): | |
1273 | # remote did change but ended up with same content |
|
1273 | # remote did change but ended up with same content | |
1274 | del actions[f] # don't get = keep local deleted |
|
1274 | del actions[f] # don't get = keep local deleted | |
1275 |
|
1275 | |||
1276 | def calculateupdates(repo, wctx, mctx, ancestors, branchmerge, force, |
|
1276 | def calculateupdates(repo, wctx, mctx, ancestors, branchmerge, force, | |
1277 | acceptremote, followcopies, matcher=None, |
|
1277 | acceptremote, followcopies, matcher=None, | |
1278 | mergeforce=False): |
|
1278 | mergeforce=False): | |
1279 | """Calculate the actions needed to merge mctx into wctx using ancestors""" |
|
1279 | """Calculate the actions needed to merge mctx into wctx using ancestors""" | |
1280 | # Avoid cycle. |
|
1280 | # Avoid cycle. | |
1281 | from . import sparse |
|
1281 | from . import sparse | |
1282 |
|
1282 | |||
1283 | if len(ancestors) == 1: # default |
|
1283 | if len(ancestors) == 1: # default | |
1284 | actions, diverge, renamedelete = manifestmerge( |
|
1284 | actions, diverge, renamedelete = manifestmerge( | |
1285 | repo, wctx, mctx, ancestors[0], branchmerge, force, matcher, |
|
1285 | repo, wctx, mctx, ancestors[0], branchmerge, force, matcher, | |
1286 | acceptremote, followcopies) |
|
1286 | acceptremote, followcopies) | |
1287 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) |
|
1287 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) | |
1288 |
|
1288 | |||
1289 | else: # only when merge.preferancestor=* - the default |
|
1289 | else: # only when merge.preferancestor=* - the default | |
1290 | repo.ui.note( |
|
1290 | repo.ui.note( | |
1291 | _("note: merging %s and %s using bids from ancestors %s\n") % |
|
1291 | _("note: merging %s and %s using bids from ancestors %s\n") % | |
1292 | (wctx, mctx, _(' and ').join(pycompat.bytestr(anc) |
|
1292 | (wctx, mctx, _(' and ').join(pycompat.bytestr(anc) | |
1293 | for anc in ancestors))) |
|
1293 | for anc in ancestors))) | |
1294 |
|
1294 | |||
1295 | # Call for bids |
|
1295 | # Call for bids | |
1296 | fbids = {} # mapping filename to bids (action method to list af actions) |
|
1296 | fbids = {} # mapping filename to bids (action method to list af actions) | |
1297 | diverge, renamedelete = None, None |
|
1297 | diverge, renamedelete = None, None | |
1298 | for ancestor in ancestors: |
|
1298 | for ancestor in ancestors: | |
1299 | repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor) |
|
1299 | repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor) | |
1300 | actions, diverge1, renamedelete1 = manifestmerge( |
|
1300 | actions, diverge1, renamedelete1 = manifestmerge( | |
1301 | repo, wctx, mctx, ancestor, branchmerge, force, matcher, |
|
1301 | repo, wctx, mctx, ancestor, branchmerge, force, matcher, | |
1302 | acceptremote, followcopies, forcefulldiff=True) |
|
1302 | acceptremote, followcopies, forcefulldiff=True) | |
1303 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) |
|
1303 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) | |
1304 |
|
1304 | |||
1305 | # Track the shortest set of warning on the theory that bid |
|
1305 | # Track the shortest set of warning on the theory that bid | |
1306 | # merge will correctly incorporate more information |
|
1306 | # merge will correctly incorporate more information | |
1307 | if diverge is None or len(diverge1) < len(diverge): |
|
1307 | if diverge is None or len(diverge1) < len(diverge): | |
1308 | diverge = diverge1 |
|
1308 | diverge = diverge1 | |
1309 | if renamedelete is None or len(renamedelete) < len(renamedelete1): |
|
1309 | if renamedelete is None or len(renamedelete) < len(renamedelete1): | |
1310 | renamedelete = renamedelete1 |
|
1310 | renamedelete = renamedelete1 | |
1311 |
|
1311 | |||
1312 | for f, a in sorted(actions.iteritems()): |
|
1312 | for f, a in sorted(actions.iteritems()): | |
1313 | m, args, msg = a |
|
1313 | m, args, msg = a | |
1314 | repo.ui.debug(' %s: %s -> %s\n' % (f, msg, m)) |
|
1314 | repo.ui.debug(' %s: %s -> %s\n' % (f, msg, m)) | |
1315 | if f in fbids: |
|
1315 | if f in fbids: | |
1316 | d = fbids[f] |
|
1316 | d = fbids[f] | |
1317 | if m in d: |
|
1317 | if m in d: | |
1318 | d[m].append(a) |
|
1318 | d[m].append(a) | |
1319 | else: |
|
1319 | else: | |
1320 | d[m] = [a] |
|
1320 | d[m] = [a] | |
1321 | else: |
|
1321 | else: | |
1322 | fbids[f] = {m: [a]} |
|
1322 | fbids[f] = {m: [a]} | |
1323 |
|
1323 | |||
1324 | # Pick the best bid for each file |
|
1324 | # Pick the best bid for each file | |
1325 | repo.ui.note(_('\nauction for merging merge bids\n')) |
|
1325 | repo.ui.note(_('\nauction for merging merge bids\n')) | |
1326 | actions = {} |
|
1326 | actions = {} | |
1327 | dms = [] # filenames that have dm actions |
|
1327 | dms = [] # filenames that have dm actions | |
1328 | for f, bids in sorted(fbids.items()): |
|
1328 | for f, bids in sorted(fbids.items()): | |
1329 | # bids is a mapping from action method to list af actions |
|
1329 | # bids is a mapping from action method to list af actions | |
1330 | # Consensus? |
|
1330 | # Consensus? | |
1331 | if len(bids) == 1: # all bids are the same kind of method |
|
1331 | if len(bids) == 1: # all bids are the same kind of method | |
1332 | m, l = list(bids.items())[0] |
|
1332 | m, l = list(bids.items())[0] | |
1333 | if all(a == l[0] for a in l[1:]): # len(bids) is > 1 |
|
1333 | if all(a == l[0] for a in l[1:]): # len(bids) is > 1 | |
1334 | repo.ui.note(_(" %s: consensus for %s\n") % (f, m)) |
|
1334 | repo.ui.note(_(" %s: consensus for %s\n") % (f, m)) | |
1335 | actions[f] = l[0] |
|
1335 | actions[f] = l[0] | |
1336 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: |
|
1336 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: | |
1337 | dms.append(f) |
|
1337 | dms.append(f) | |
1338 | continue |
|
1338 | continue | |
1339 | # If keep is an option, just do it. |
|
1339 | # If keep is an option, just do it. | |
1340 | if ACTION_KEEP in bids: |
|
1340 | if ACTION_KEEP in bids: | |
1341 | repo.ui.note(_(" %s: picking 'keep' action\n") % f) |
|
1341 | repo.ui.note(_(" %s: picking 'keep' action\n") % f) | |
1342 | actions[f] = bids[ACTION_KEEP][0] |
|
1342 | actions[f] = bids[ACTION_KEEP][0] | |
1343 | continue |
|
1343 | continue | |
1344 | # If there are gets and they all agree [how could they not?], do it. |
|
1344 | # If there are gets and they all agree [how could they not?], do it. | |
1345 | if ACTION_GET in bids: |
|
1345 | if ACTION_GET in bids: | |
1346 | ga0 = bids[ACTION_GET][0] |
|
1346 | ga0 = bids[ACTION_GET][0] | |
1347 | if all(a == ga0 for a in bids[ACTION_GET][1:]): |
|
1347 | if all(a == ga0 for a in bids[ACTION_GET][1:]): | |
1348 | repo.ui.note(_(" %s: picking 'get' action\n") % f) |
|
1348 | repo.ui.note(_(" %s: picking 'get' action\n") % f) | |
1349 | actions[f] = ga0 |
|
1349 | actions[f] = ga0 | |
1350 | continue |
|
1350 | continue | |
1351 | # TODO: Consider other simple actions such as mode changes |
|
1351 | # TODO: Consider other simple actions such as mode changes | |
1352 | # Handle inefficient democrazy. |
|
1352 | # Handle inefficient democrazy. | |
1353 | repo.ui.note(_(' %s: multiple bids for merge action:\n') % f) |
|
1353 | repo.ui.note(_(' %s: multiple bids for merge action:\n') % f) | |
1354 | for m, l in sorted(bids.items()): |
|
1354 | for m, l in sorted(bids.items()): | |
1355 | for _f, args, msg in l: |
|
1355 | for _f, args, msg in l: | |
1356 | repo.ui.note(' %s -> %s\n' % (msg, m)) |
|
1356 | repo.ui.note(' %s -> %s\n' % (msg, m)) | |
1357 | # Pick random action. TODO: Instead, prompt user when resolving |
|
1357 | # Pick random action. TODO: Instead, prompt user when resolving | |
1358 | m, l = list(bids.items())[0] |
|
1358 | m, l = list(bids.items())[0] | |
1359 | repo.ui.warn(_(' %s: ambiguous merge - picked %s action\n') % |
|
1359 | repo.ui.warn(_(' %s: ambiguous merge - picked %s action\n') % | |
1360 | (f, m)) |
|
1360 | (f, m)) | |
1361 | actions[f] = l[0] |
|
1361 | actions[f] = l[0] | |
1362 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: |
|
1362 | if m == ACTION_DIR_RENAME_MOVE_LOCAL: | |
1363 | dms.append(f) |
|
1363 | dms.append(f) | |
1364 | continue |
|
1364 | continue | |
1365 | # Work around 'dm' that can cause multiple actions for the same file |
|
1365 | # Work around 'dm' that can cause multiple actions for the same file | |
1366 | for f in dms: |
|
1366 | for f in dms: | |
1367 | dm, (f0, flags), msg = actions[f] |
|
1367 | dm, (f0, flags), msg = actions[f] | |
1368 | assert dm == ACTION_DIR_RENAME_MOVE_LOCAL, dm |
|
1368 | assert dm == ACTION_DIR_RENAME_MOVE_LOCAL, dm | |
1369 | if f0 in actions and actions[f0][0] == ACTION_REMOVE: |
|
1369 | if f0 in actions and actions[f0][0] == ACTION_REMOVE: | |
1370 | # We have one bid for removing a file and another for moving it. |
|
1370 | # We have one bid for removing a file and another for moving it. | |
1371 | # These two could be merged as first move and then delete ... |
|
1371 | # These two could be merged as first move and then delete ... | |
1372 | # but instead drop moving and just delete. |
|
1372 | # but instead drop moving and just delete. | |
1373 | del actions[f] |
|
1373 | del actions[f] | |
1374 | repo.ui.note(_('end of auction\n\n')) |
|
1374 | repo.ui.note(_('end of auction\n\n')) | |
1375 |
|
1375 | |||
1376 | _resolvetrivial(repo, wctx, mctx, ancestors[0], actions) |
|
1376 | _resolvetrivial(repo, wctx, mctx, ancestors[0], actions) | |
1377 |
|
1377 | |||
1378 | if wctx.rev() is None: |
|
1378 | if wctx.rev() is None: | |
1379 | fractions = _forgetremoved(wctx, mctx, branchmerge) |
|
1379 | fractions = _forgetremoved(wctx, mctx, branchmerge) | |
1380 | actions.update(fractions) |
|
1380 | actions.update(fractions) | |
1381 |
|
1381 | |||
1382 | prunedactions = sparse.filterupdatesactions(repo, wctx, mctx, branchmerge, |
|
1382 | prunedactions = sparse.filterupdatesactions(repo, wctx, mctx, branchmerge, | |
1383 | actions) |
|
1383 | actions) | |
1384 |
|
1384 | |||
1385 | return prunedactions, diverge, renamedelete |
|
1385 | return prunedactions, diverge, renamedelete | |
1386 |
|
1386 | |||
1387 | def _getcwd(): |
|
1387 | def _getcwd(): | |
1388 | try: |
|
1388 | try: | |
1389 | return pycompat.getcwd() |
|
1389 | return pycompat.getcwd() | |
1390 | except OSError as err: |
|
1390 | except OSError as err: | |
1391 | if err.errno == errno.ENOENT: |
|
1391 | if err.errno == errno.ENOENT: | |
1392 | return None |
|
1392 | return None | |
1393 | raise |
|
1393 | raise | |
1394 |
|
1394 | |||
1395 | def batchremove(repo, wctx, actions): |
|
1395 | def batchremove(repo, wctx, actions): | |
1396 | """apply removes to the working directory |
|
1396 | """apply removes to the working directory | |
1397 |
|
1397 | |||
1398 | yields tuples for progress updates |
|
1398 | yields tuples for progress updates | |
1399 | """ |
|
1399 | """ | |
1400 | verbose = repo.ui.verbose |
|
1400 | verbose = repo.ui.verbose | |
1401 | cwd = _getcwd() |
|
1401 | cwd = _getcwd() | |
1402 | i = 0 |
|
1402 | i = 0 | |
1403 | for f, args, msg in actions: |
|
1403 | for f, args, msg in actions: | |
1404 | repo.ui.debug(" %s: %s -> r\n" % (f, msg)) |
|
1404 | repo.ui.debug(" %s: %s -> r\n" % (f, msg)) | |
1405 | if verbose: |
|
1405 | if verbose: | |
1406 | repo.ui.note(_("removing %s\n") % f) |
|
1406 | repo.ui.note(_("removing %s\n") % f) | |
1407 | wctx[f].audit() |
|
1407 | wctx[f].audit() | |
1408 | try: |
|
1408 | try: | |
1409 | wctx[f].remove(ignoremissing=True) |
|
1409 | wctx[f].remove(ignoremissing=True) | |
1410 | except OSError as inst: |
|
1410 | except OSError as inst: | |
1411 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
1411 | repo.ui.warn(_("update failed to remove %s: %s!\n") % | |
1412 | (f, inst.strerror)) |
|
1412 | (f, inst.strerror)) | |
1413 | if i == 100: |
|
1413 | if i == 100: | |
1414 | yield i, f |
|
1414 | yield i, f | |
1415 | i = 0 |
|
1415 | i = 0 | |
1416 | i += 1 |
|
1416 | i += 1 | |
1417 | if i > 0: |
|
1417 | if i > 0: | |
1418 | yield i, f |
|
1418 | yield i, f | |
1419 |
|
1419 | |||
1420 | if cwd and not _getcwd(): |
|
1420 | if cwd and not _getcwd(): | |
1421 | # cwd was removed in the course of removing files; print a helpful |
|
1421 | # cwd was removed in the course of removing files; print a helpful | |
1422 | # warning. |
|
1422 | # warning. | |
1423 | repo.ui.warn(_("current directory was removed\n" |
|
1423 | repo.ui.warn(_("current directory was removed\n" | |
1424 | "(consider changing to repo root: %s)\n") % repo.root) |
|
1424 | "(consider changing to repo root: %s)\n") % repo.root) | |
1425 |
|
1425 | |||
1426 | def batchget(repo, mctx, wctx, actions): |
|
1426 | def batchget(repo, mctx, wctx, actions): | |
1427 | """apply gets to the working directory |
|
1427 | """apply gets to the working directory | |
1428 |
|
1428 | |||
1429 | mctx is the context to get from |
|
1429 | mctx is the context to get from | |
1430 |
|
1430 | |||
1431 | yields tuples for progress updates |
|
1431 | yields tuples for progress updates | |
1432 | """ |
|
1432 | """ | |
1433 | verbose = repo.ui.verbose |
|
1433 | verbose = repo.ui.verbose | |
1434 | fctx = mctx.filectx |
|
1434 | fctx = mctx.filectx | |
1435 | ui = repo.ui |
|
1435 | ui = repo.ui | |
1436 | i = 0 |
|
1436 | i = 0 | |
1437 | with repo.wvfs.backgroundclosing(ui, expectedcount=len(actions)): |
|
1437 | with repo.wvfs.backgroundclosing(ui, expectedcount=len(actions)): | |
1438 | for f, (flags, backup), msg in actions: |
|
1438 | for f, (flags, backup), msg in actions: | |
1439 | repo.ui.debug(" %s: %s -> g\n" % (f, msg)) |
|
1439 | repo.ui.debug(" %s: %s -> g\n" % (f, msg)) | |
1440 | if verbose: |
|
1440 | if verbose: | |
1441 | repo.ui.note(_("getting %s\n") % f) |
|
1441 | repo.ui.note(_("getting %s\n") % f) | |
1442 |
|
1442 | |||
1443 | if backup: |
|
1443 | if backup: | |
1444 | # If a file or directory exists with the same name, back that |
|
1444 | # If a file or directory exists with the same name, back that | |
1445 | # up. Otherwise, look to see if there is a file that conflicts |
|
1445 | # up. Otherwise, look to see if there is a file that conflicts | |
1446 | # with a directory this file is in, and if so, back that up. |
|
1446 | # with a directory this file is in, and if so, back that up. | |
1447 | absf = repo.wjoin(f) |
|
1447 | absf = repo.wjoin(f) | |
1448 | if not repo.wvfs.lexists(f): |
|
1448 | if not repo.wvfs.lexists(f): | |
1449 | for p in util.finddirs(f): |
|
1449 | for p in util.finddirs(f): | |
1450 | if repo.wvfs.isfileorlink(p): |
|
1450 | if repo.wvfs.isfileorlink(p): | |
1451 | absf = repo.wjoin(p) |
|
1451 | absf = repo.wjoin(p) | |
1452 | break |
|
1452 | break | |
1453 | orig = scmutil.origpath(ui, repo, absf) |
|
1453 | orig = scmutil.origpath(ui, repo, absf) | |
1454 | if repo.wvfs.lexists(absf): |
|
1454 | if repo.wvfs.lexists(absf): | |
1455 | util.rename(absf, orig) |
|
1455 | util.rename(absf, orig) | |
1456 | wctx[f].clearunknown() |
|
1456 | wctx[f].clearunknown() | |
1457 | atomictemp = ui.configbool("experimental", "update.atomic-file") |
|
1457 | atomictemp = ui.configbool("experimental", "update.atomic-file") | |
1458 | wctx[f].write(fctx(f).data(), flags, backgroundclose=True, |
|
1458 | wctx[f].write(fctx(f).data(), flags, backgroundclose=True, | |
1459 | atomictemp=atomictemp) |
|
1459 | atomictemp=atomictemp) | |
1460 | if i == 100: |
|
1460 | if i == 100: | |
1461 | yield i, f |
|
1461 | yield i, f | |
1462 | i = 0 |
|
1462 | i = 0 | |
1463 | i += 1 |
|
1463 | i += 1 | |
1464 | if i > 0: |
|
1464 | if i > 0: | |
1465 | yield i, f |
|
1465 | yield i, f | |
1466 |
|
1466 | |||
1467 | def _prefetchfiles(repo, ctx, actions): |
|
1467 | def _prefetchfiles(repo, ctx, actions): | |
1468 | """Invoke ``scmutil.fileprefetchhooks()`` for the files relevant to the dict |
|
1468 | """Invoke ``scmutil.fileprefetchhooks()`` for the files relevant to the dict | |
1469 | of merge actions. ``ctx`` is the context being merged in.""" |
|
1469 | of merge actions. ``ctx`` is the context being merged in.""" | |
1470 |
|
1470 | |||
1471 | # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they |
|
1471 | # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they | |
1472 | # don't touch the context to be merged in. 'cd' is skipped, because |
|
1472 | # don't touch the context to be merged in. 'cd' is skipped, because | |
1473 | # changed/deleted never resolves to something from the remote side. |
|
1473 | # changed/deleted never resolves to something from the remote side. | |
1474 | oplist = [actions[a] for a in (ACTION_GET, ACTION_DELETED_CHANGED, |
|
1474 | oplist = [actions[a] for a in (ACTION_GET, ACTION_DELETED_CHANGED, | |
1475 | ACTION_LOCAL_DIR_RENAME_GET, ACTION_MERGE)] |
|
1475 | ACTION_LOCAL_DIR_RENAME_GET, ACTION_MERGE)] | |
1476 | prefetch = scmutil.fileprefetchhooks |
|
1476 | prefetch = scmutil.fileprefetchhooks | |
1477 | prefetch(repo, ctx, [f for sublist in oplist for f, args, msg in sublist]) |
|
1477 | prefetch(repo, ctx, [f for sublist in oplist for f, args, msg in sublist]) | |
1478 |
|
1478 | |||
1479 | @attr.s(frozen=True) |
|
1479 | @attr.s(frozen=True) | |
1480 | class updateresult(object): |
|
1480 | class updateresult(object): | |
1481 | updatedcount = attr.ib() |
|
1481 | updatedcount = attr.ib() | |
1482 | mergedcount = attr.ib() |
|
1482 | mergedcount = attr.ib() | |
1483 | removedcount = attr.ib() |
|
1483 | removedcount = attr.ib() | |
1484 | unresolvedcount = attr.ib() |
|
1484 | unresolvedcount = attr.ib() | |
1485 |
|
1485 | |||
1486 | def isempty(self): |
|
1486 | def isempty(self): | |
1487 | return (not self.updatedcount and not self.mergedcount |
|
1487 | return (not self.updatedcount and not self.mergedcount | |
1488 | and not self.removedcount and not self.unresolvedcount) |
|
1488 | and not self.removedcount and not self.unresolvedcount) | |
1489 |
|
1489 | |||
1490 | # TODO remove container emulation once consumers switch to new API. |
|
1490 | # TODO remove container emulation once consumers switch to new API. | |
1491 |
|
1491 | |||
1492 | def __getitem__(self, x): |
|
1492 | def __getitem__(self, x): | |
1493 | util.nouideprecwarn('access merge.update() results by name instead of ' |
|
1493 | util.nouideprecwarn('access merge.update() results by name instead of ' | |
1494 | 'index', '4.6', 2) |
|
1494 | 'index', '4.6', 2) | |
1495 | if x == 0: |
|
1495 | if x == 0: | |
1496 | return self.updatedcount |
|
1496 | return self.updatedcount | |
1497 | elif x == 1: |
|
1497 | elif x == 1: | |
1498 | return self.mergedcount |
|
1498 | return self.mergedcount | |
1499 | elif x == 2: |
|
1499 | elif x == 2: | |
1500 | return self.removedcount |
|
1500 | return self.removedcount | |
1501 | elif x == 3: |
|
1501 | elif x == 3: | |
1502 | return self.unresolvedcount |
|
1502 | return self.unresolvedcount | |
1503 | else: |
|
1503 | else: | |
1504 | raise IndexError('can only access items 0-3') |
|
1504 | raise IndexError('can only access items 0-3') | |
1505 |
|
1505 | |||
1506 | def __len__(self): |
|
1506 | def __len__(self): | |
1507 | util.nouideprecwarn('access merge.update() results by name instead of ' |
|
1507 | util.nouideprecwarn('access merge.update() results by name instead of ' | |
1508 | 'index', '4.6', 2) |
|
1508 | 'index', '4.6', 2) | |
1509 | return 4 |
|
1509 | return 4 | |
1510 |
|
1510 | |||
1511 | def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None): |
|
1511 | def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None): | |
1512 | """apply the merge action list to the working directory |
|
1512 | """apply the merge action list to the working directory | |
1513 |
|
1513 | |||
1514 | wctx is the working copy context |
|
1514 | wctx is the working copy context | |
1515 | mctx is the context to be merged into the working copy |
|
1515 | mctx is the context to be merged into the working copy | |
1516 |
|
1516 | |||
1517 | Return a tuple of counts (updated, merged, removed, unresolved) that |
|
1517 | Return a tuple of counts (updated, merged, removed, unresolved) that | |
1518 | describes how many files were affected by the update. |
|
1518 | describes how many files were affected by the update. | |
1519 | """ |
|
1519 | """ | |
1520 |
|
1520 | |||
1521 | _prefetchfiles(repo, mctx, actions) |
|
1521 | _prefetchfiles(repo, mctx, actions) | |
1522 |
|
1522 | |||
1523 | updated, merged, removed = 0, 0, 0 |
|
1523 | updated, merged, removed = 0, 0, 0 | |
1524 | ms = mergestate.clean(repo, wctx.p1().node(), mctx.node(), labels) |
|
1524 | ms = mergestate.clean(repo, wctx.p1().node(), mctx.node(), labels) | |
1525 | moves = [] |
|
1525 | moves = [] | |
1526 | for m, l in actions.items(): |
|
1526 | for m, l in actions.items(): | |
1527 | l.sort() |
|
1527 | l.sort() | |
1528 |
|
1528 | |||
1529 | # 'cd' and 'dc' actions are treated like other merge conflicts |
|
1529 | # 'cd' and 'dc' actions are treated like other merge conflicts | |
1530 | mergeactions = sorted(actions[ACTION_CHANGED_DELETED]) |
|
1530 | mergeactions = sorted(actions[ACTION_CHANGED_DELETED]) | |
1531 | mergeactions.extend(sorted(actions[ACTION_DELETED_CHANGED])) |
|
1531 | mergeactions.extend(sorted(actions[ACTION_DELETED_CHANGED])) | |
1532 | mergeactions.extend(actions[ACTION_MERGE]) |
|
1532 | mergeactions.extend(actions[ACTION_MERGE]) | |
1533 | for f, args, msg in mergeactions: |
|
1533 | for f, args, msg in mergeactions: | |
1534 | f1, f2, fa, move, anc = args |
|
1534 | f1, f2, fa, move, anc = args | |
1535 | if f == '.hgsubstate': # merged internally |
|
1535 | if f == '.hgsubstate': # merged internally | |
1536 | continue |
|
1536 | continue | |
1537 | if f1 is None: |
|
1537 | if f1 is None: | |
1538 | fcl = filemerge.absentfilectx(wctx, fa) |
|
1538 | fcl = filemerge.absentfilectx(wctx, fa) | |
1539 | else: |
|
1539 | else: | |
1540 | repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f)) |
|
1540 | repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f)) | |
1541 | fcl = wctx[f1] |
|
1541 | fcl = wctx[f1] | |
1542 | if f2 is None: |
|
1542 | if f2 is None: | |
1543 | fco = filemerge.absentfilectx(mctx, fa) |
|
1543 | fco = filemerge.absentfilectx(mctx, fa) | |
1544 | else: |
|
1544 | else: | |
1545 | fco = mctx[f2] |
|
1545 | fco = mctx[f2] | |
1546 | actx = repo[anc] |
|
1546 | actx = repo[anc] | |
1547 | if fa in actx: |
|
1547 | if fa in actx: | |
1548 | fca = actx[fa] |
|
1548 | fca = actx[fa] | |
1549 | else: |
|
1549 | else: | |
1550 | # TODO: move to absentfilectx |
|
1550 | # TODO: move to absentfilectx | |
1551 | fca = repo.filectx(f1, fileid=nullrev) |
|
1551 | fca = repo.filectx(f1, fileid=nullrev) | |
1552 | ms.add(fcl, fco, fca, f) |
|
1552 | ms.add(fcl, fco, fca, f) | |
1553 | if f1 != f and move: |
|
1553 | if f1 != f and move: | |
1554 | moves.append(f1) |
|
1554 | moves.append(f1) | |
1555 |
|
1555 | |||
1556 | _updating = _('updating') |
|
1556 | _updating = _('updating') | |
1557 | _files = _('files') |
|
1557 | _files = _('files') | |
1558 | progress = repo.ui.progress |
|
1558 | progress = repo.ui.progress | |
1559 |
|
1559 | |||
1560 | # remove renamed files after safely stored |
|
1560 | # remove renamed files after safely stored | |
1561 | for f in moves: |
|
1561 | for f in moves: | |
1562 | if wctx[f].lexists(): |
|
1562 | if wctx[f].lexists(): | |
1563 | repo.ui.debug("removing %s\n" % f) |
|
1563 | repo.ui.debug("removing %s\n" % f) | |
1564 | wctx[f].audit() |
|
1564 | wctx[f].audit() | |
1565 | wctx[f].remove() |
|
1565 | wctx[f].remove() | |
1566 |
|
1566 | |||
1567 | numupdates = sum(len(l) for m, l in actions.items() |
|
1567 | numupdates = sum(len(l) for m, l in actions.items() | |
1568 | if m != ACTION_KEEP) |
|
1568 | if m != ACTION_KEEP) | |
1569 | z = 0 |
|
1569 | z = 0 | |
1570 |
|
1570 | |||
1571 | if [a for a in actions[ACTION_REMOVE] if a[0] == '.hgsubstate']: |
|
1571 | if [a for a in actions[ACTION_REMOVE] if a[0] == '.hgsubstate']: | |
1572 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) |
|
1572 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) | |
1573 |
|
1573 | |||
1574 | # record path conflicts |
|
1574 | # record path conflicts | |
1575 | for f, args, msg in actions[ACTION_PATH_CONFLICT]: |
|
1575 | for f, args, msg in actions[ACTION_PATH_CONFLICT]: | |
1576 | f1, fo = args |
|
1576 | f1, fo = args | |
1577 | s = repo.ui.status |
|
1577 | s = repo.ui.status | |
1578 | s(_("%s: path conflict - a file or link has the same name as a " |
|
1578 | s(_("%s: path conflict - a file or link has the same name as a " | |
1579 | "directory\n") % f) |
|
1579 | "directory\n") % f) | |
1580 | if fo == 'l': |
|
1580 | if fo == 'l': | |
1581 | s(_("the local file has been renamed to %s\n") % f1) |
|
1581 | s(_("the local file has been renamed to %s\n") % f1) | |
1582 | else: |
|
1582 | else: | |
1583 | s(_("the remote file has been renamed to %s\n") % f1) |
|
1583 | s(_("the remote file has been renamed to %s\n") % f1) | |
1584 | s(_("resolve manually then use 'hg resolve --mark %s'\n") % f) |
|
1584 | s(_("resolve manually then use 'hg resolve --mark %s'\n") % f) | |
1585 | ms.addpath(f, f1, fo) |
|
1585 | ms.addpath(f, f1, fo) | |
1586 | z += 1 |
|
1586 | z += 1 | |
1587 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1587 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1588 |
|
1588 | |||
1589 | # When merging in-memory, we can't support worker processes, so set the |
|
1589 | # When merging in-memory, we can't support worker processes, so set the | |
1590 | # per-item cost at 0 in that case. |
|
1590 | # per-item cost at 0 in that case. | |
1591 | cost = 0 if wctx.isinmemory() else 0.001 |
|
1591 | cost = 0 if wctx.isinmemory() else 0.001 | |
1592 |
|
1592 | |||
1593 | # remove in parallel (must come before resolving path conflicts and getting) |
|
1593 | # remove in parallel (must come before resolving path conflicts and getting) | |
1594 | prog = worker.worker(repo.ui, cost, batchremove, (repo, wctx), |
|
1594 | prog = worker.worker(repo.ui, cost, batchremove, (repo, wctx), | |
1595 | actions[ACTION_REMOVE]) |
|
1595 | actions[ACTION_REMOVE]) | |
1596 | for i, item in prog: |
|
1596 | for i, item in prog: | |
1597 | z += i |
|
1597 | z += i | |
1598 | progress(_updating, z, item=item, total=numupdates, unit=_files) |
|
1598 | progress(_updating, z, item=item, total=numupdates, unit=_files) | |
1599 | removed = len(actions[ACTION_REMOVE]) |
|
1599 | removed = len(actions[ACTION_REMOVE]) | |
1600 |
|
1600 | |||
1601 | # resolve path conflicts (must come before getting) |
|
1601 | # resolve path conflicts (must come before getting) | |
1602 | for f, args, msg in actions[ACTION_PATH_CONFLICT_RESOLVE]: |
|
1602 | for f, args, msg in actions[ACTION_PATH_CONFLICT_RESOLVE]: | |
1603 | repo.ui.debug(" %s: %s -> pr\n" % (f, msg)) |
|
1603 | repo.ui.debug(" %s: %s -> pr\n" % (f, msg)) | |
1604 | f0, = args |
|
1604 | f0, = args | |
1605 | if wctx[f0].lexists(): |
|
1605 | if wctx[f0].lexists(): | |
1606 | repo.ui.note(_("moving %s to %s\n") % (f0, f)) |
|
1606 | repo.ui.note(_("moving %s to %s\n") % (f0, f)) | |
1607 | wctx[f].audit() |
|
1607 | wctx[f].audit() | |
1608 | wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags()) |
|
1608 | wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags()) | |
1609 | wctx[f0].remove() |
|
1609 | wctx[f0].remove() | |
1610 | z += 1 |
|
1610 | z += 1 | |
1611 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1611 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1612 |
|
1612 | |||
1613 | # get in parallel |
|
1613 | # get in parallel | |
1614 | prog = worker.worker(repo.ui, cost, batchget, (repo, mctx, wctx), |
|
1614 | prog = worker.worker(repo.ui, cost, batchget, (repo, mctx, wctx), | |
1615 | actions[ACTION_GET]) |
|
1615 | actions[ACTION_GET]) | |
1616 | for i, item in prog: |
|
1616 | for i, item in prog: | |
1617 | z += i |
|
1617 | z += i | |
1618 | progress(_updating, z, item=item, total=numupdates, unit=_files) |
|
1618 | progress(_updating, z, item=item, total=numupdates, unit=_files) | |
1619 | updated = len(actions[ACTION_GET]) |
|
1619 | updated = len(actions[ACTION_GET]) | |
1620 |
|
1620 | |||
1621 | if [a for a in actions[ACTION_GET] if a[0] == '.hgsubstate']: |
|
1621 | if [a for a in actions[ACTION_GET] if a[0] == '.hgsubstate']: | |
1622 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) |
|
1622 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) | |
1623 |
|
1623 | |||
1624 | # forget (manifest only, just log it) (must come first) |
|
1624 | # forget (manifest only, just log it) (must come first) | |
1625 | for f, args, msg in actions[ACTION_FORGET]: |
|
1625 | for f, args, msg in actions[ACTION_FORGET]: | |
1626 | repo.ui.debug(" %s: %s -> f\n" % (f, msg)) |
|
1626 | repo.ui.debug(" %s: %s -> f\n" % (f, msg)) | |
1627 | z += 1 |
|
1627 | z += 1 | |
1628 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1628 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1629 |
|
1629 | |||
1630 | # re-add (manifest only, just log it) |
|
1630 | # re-add (manifest only, just log it) | |
1631 | for f, args, msg in actions[ACTION_ADD]: |
|
1631 | for f, args, msg in actions[ACTION_ADD]: | |
1632 | repo.ui.debug(" %s: %s -> a\n" % (f, msg)) |
|
1632 | repo.ui.debug(" %s: %s -> a\n" % (f, msg)) | |
1633 | z += 1 |
|
1633 | z += 1 | |
1634 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1634 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1635 |
|
1635 | |||
1636 | # re-add/mark as modified (manifest only, just log it) |
|
1636 | # re-add/mark as modified (manifest only, just log it) | |
1637 | for f, args, msg in actions[ACTION_ADD_MODIFIED]: |
|
1637 | for f, args, msg in actions[ACTION_ADD_MODIFIED]: | |
1638 | repo.ui.debug(" %s: %s -> am\n" % (f, msg)) |
|
1638 | repo.ui.debug(" %s: %s -> am\n" % (f, msg)) | |
1639 | z += 1 |
|
1639 | z += 1 | |
1640 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1640 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1641 |
|
1641 | |||
1642 | # keep (noop, just log it) |
|
1642 | # keep (noop, just log it) | |
1643 | for f, args, msg in actions[ACTION_KEEP]: |
|
1643 | for f, args, msg in actions[ACTION_KEEP]: | |
1644 | repo.ui.debug(" %s: %s -> k\n" % (f, msg)) |
|
1644 | repo.ui.debug(" %s: %s -> k\n" % (f, msg)) | |
1645 | # no progress |
|
1645 | # no progress | |
1646 |
|
1646 | |||
1647 | # directory rename, move local |
|
1647 | # directory rename, move local | |
1648 | for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]: |
|
1648 | for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]: | |
1649 | repo.ui.debug(" %s: %s -> dm\n" % (f, msg)) |
|
1649 | repo.ui.debug(" %s: %s -> dm\n" % (f, msg)) | |
1650 | z += 1 |
|
1650 | z += 1 | |
1651 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1651 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1652 | f0, flags = args |
|
1652 | f0, flags = args | |
1653 | repo.ui.note(_("moving %s to %s\n") % (f0, f)) |
|
1653 | repo.ui.note(_("moving %s to %s\n") % (f0, f)) | |
1654 | wctx[f].audit() |
|
1654 | wctx[f].audit() | |
1655 | wctx[f].write(wctx.filectx(f0).data(), flags) |
|
1655 | wctx[f].write(wctx.filectx(f0).data(), flags) | |
1656 | wctx[f0].remove() |
|
1656 | wctx[f0].remove() | |
1657 | updated += 1 |
|
1657 | updated += 1 | |
1658 |
|
1658 | |||
1659 | # local directory rename, get |
|
1659 | # local directory rename, get | |
1660 | for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]: |
|
1660 | for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]: | |
1661 | repo.ui.debug(" %s: %s -> dg\n" % (f, msg)) |
|
1661 | repo.ui.debug(" %s: %s -> dg\n" % (f, msg)) | |
1662 | z += 1 |
|
1662 | z += 1 | |
1663 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1663 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1664 | f0, flags = args |
|
1664 | f0, flags = args | |
1665 | repo.ui.note(_("getting %s to %s\n") % (f0, f)) |
|
1665 | repo.ui.note(_("getting %s to %s\n") % (f0, f)) | |
1666 | wctx[f].write(mctx.filectx(f0).data(), flags) |
|
1666 | wctx[f].write(mctx.filectx(f0).data(), flags) | |
1667 | updated += 1 |
|
1667 | updated += 1 | |
1668 |
|
1668 | |||
1669 | # exec |
|
1669 | # exec | |
1670 | for f, args, msg in actions[ACTION_EXEC]: |
|
1670 | for f, args, msg in actions[ACTION_EXEC]: | |
1671 | repo.ui.debug(" %s: %s -> e\n" % (f, msg)) |
|
1671 | repo.ui.debug(" %s: %s -> e\n" % (f, msg)) | |
1672 | z += 1 |
|
1672 | z += 1 | |
1673 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1673 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1674 | flags, = args |
|
1674 | flags, = args | |
1675 | wctx[f].audit() |
|
1675 | wctx[f].audit() | |
1676 | wctx[f].setflags('l' in flags, 'x' in flags) |
|
1676 | wctx[f].setflags('l' in flags, 'x' in flags) | |
1677 | updated += 1 |
|
1677 | updated += 1 | |
1678 |
|
1678 | |||
1679 | # the ordering is important here -- ms.mergedriver will raise if the merge |
|
1679 | # the ordering is important here -- ms.mergedriver will raise if the merge | |
1680 | # driver has changed, and we want to be able to bypass it when overwrite is |
|
1680 | # driver has changed, and we want to be able to bypass it when overwrite is | |
1681 | # True |
|
1681 | # True | |
1682 | usemergedriver = not overwrite and mergeactions and ms.mergedriver |
|
1682 | usemergedriver = not overwrite and mergeactions and ms.mergedriver | |
1683 |
|
1683 | |||
1684 | if usemergedriver: |
|
1684 | if usemergedriver: | |
1685 | if wctx.isinmemory(): |
|
1685 | if wctx.isinmemory(): | |
1686 | raise error.InMemoryMergeConflictsError("in-memory merge does not " |
|
1686 | raise error.InMemoryMergeConflictsError("in-memory merge does not " | |
1687 | "support mergedriver") |
|
1687 | "support mergedriver") | |
1688 | ms.commit() |
|
1688 | ms.commit() | |
1689 | proceed = driverpreprocess(repo, ms, wctx, labels=labels) |
|
1689 | proceed = driverpreprocess(repo, ms, wctx, labels=labels) | |
1690 | # the driver might leave some files unresolved |
|
1690 | # the driver might leave some files unresolved | |
1691 | unresolvedf = set(ms.unresolved()) |
|
1691 | unresolvedf = set(ms.unresolved()) | |
1692 | if not proceed: |
|
1692 | if not proceed: | |
1693 | # XXX setting unresolved to at least 1 is a hack to make sure we |
|
1693 | # XXX setting unresolved to at least 1 is a hack to make sure we | |
1694 | # error out |
|
1694 | # error out | |
1695 | return updateresult(updated, merged, removed, |
|
1695 | return updateresult(updated, merged, removed, | |
1696 | max(len(unresolvedf), 1)) |
|
1696 | max(len(unresolvedf), 1)) | |
1697 | newactions = [] |
|
1697 | newactions = [] | |
1698 | for f, args, msg in mergeactions: |
|
1698 | for f, args, msg in mergeactions: | |
1699 | if f in unresolvedf: |
|
1699 | if f in unresolvedf: | |
1700 | newactions.append((f, args, msg)) |
|
1700 | newactions.append((f, args, msg)) | |
1701 | mergeactions = newactions |
|
1701 | mergeactions = newactions | |
1702 |
|
1702 | |||
1703 | try: |
|
1703 | try: | |
1704 | # premerge |
|
1704 | # premerge | |
1705 | tocomplete = [] |
|
1705 | tocomplete = [] | |
1706 | for f, args, msg in mergeactions: |
|
1706 | for f, args, msg in mergeactions: | |
1707 | repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg)) |
|
1707 | repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg)) | |
1708 | z += 1 |
|
1708 | z += 1 | |
1709 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1709 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1710 | if f == '.hgsubstate': # subrepo states need updating |
|
1710 | if f == '.hgsubstate': # subrepo states need updating | |
1711 | subrepoutil.submerge(repo, wctx, mctx, wctx.ancestor(mctx), |
|
1711 | subrepoutil.submerge(repo, wctx, mctx, wctx.ancestor(mctx), | |
1712 | overwrite, labels) |
|
1712 | overwrite, labels) | |
1713 | continue |
|
1713 | continue | |
1714 | wctx[f].audit() |
|
1714 | wctx[f].audit() | |
1715 | complete, r = ms.preresolve(f, wctx) |
|
1715 | complete, r = ms.preresolve(f, wctx) | |
1716 | if not complete: |
|
1716 | if not complete: | |
1717 | numupdates += 1 |
|
1717 | numupdates += 1 | |
1718 | tocomplete.append((f, args, msg)) |
|
1718 | tocomplete.append((f, args, msg)) | |
1719 |
|
1719 | |||
1720 | # merge |
|
1720 | # merge | |
1721 | for f, args, msg in tocomplete: |
|
1721 | for f, args, msg in tocomplete: | |
1722 | repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg)) |
|
1722 | repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg)) | |
1723 | z += 1 |
|
1723 | z += 1 | |
1724 | progress(_updating, z, item=f, total=numupdates, unit=_files) |
|
1724 | progress(_updating, z, item=f, total=numupdates, unit=_files) | |
1725 | ms.resolve(f, wctx) |
|
1725 | ms.resolve(f, wctx) | |
1726 |
|
1726 | |||
1727 | finally: |
|
1727 | finally: | |
1728 | ms.commit() |
|
1728 | ms.commit() | |
1729 |
|
1729 | |||
1730 | unresolved = ms.unresolvedcount() |
|
1730 | unresolved = ms.unresolvedcount() | |
1731 |
|
1731 | |||
1732 | if (usemergedriver and not unresolved |
|
1732 | if (usemergedriver and not unresolved | |
1733 | and ms.mdstate() != MERGE_DRIVER_STATE_SUCCESS): |
|
1733 | and ms.mdstate() != MERGE_DRIVER_STATE_SUCCESS): | |
1734 | if not driverconclude(repo, ms, wctx, labels=labels): |
|
1734 | if not driverconclude(repo, ms, wctx, labels=labels): | |
1735 | # XXX setting unresolved to at least 1 is a hack to make sure we |
|
1735 | # XXX setting unresolved to at least 1 is a hack to make sure we | |
1736 | # error out |
|
1736 | # error out | |
1737 | unresolved = max(unresolved, 1) |
|
1737 | unresolved = max(unresolved, 1) | |
1738 |
|
1738 | |||
1739 | ms.commit() |
|
1739 | ms.commit() | |
1740 |
|
1740 | |||
1741 | msupdated, msmerged, msremoved = ms.counts() |
|
1741 | msupdated, msmerged, msremoved = ms.counts() | |
1742 | updated += msupdated |
|
1742 | updated += msupdated | |
1743 | merged += msmerged |
|
1743 | merged += msmerged | |
1744 | removed += msremoved |
|
1744 | removed += msremoved | |
1745 |
|
1745 | |||
1746 | extraactions = ms.actions() |
|
1746 | extraactions = ms.actions() | |
1747 | if extraactions: |
|
1747 | if extraactions: | |
1748 | mfiles = set(a[0] for a in actions[ACTION_MERGE]) |
|
1748 | mfiles = set(a[0] for a in actions[ACTION_MERGE]) | |
1749 | for k, acts in extraactions.iteritems(): |
|
1749 | for k, acts in extraactions.iteritems(): | |
1750 | actions[k].extend(acts) |
|
1750 | actions[k].extend(acts) | |
1751 | # Remove these files from actions[ACTION_MERGE] as well. This is |
|
1751 | # Remove these files from actions[ACTION_MERGE] as well. This is | |
1752 | # important because in recordupdates, files in actions[ACTION_MERGE] |
|
1752 | # important because in recordupdates, files in actions[ACTION_MERGE] | |
1753 | # are processed after files in other actions, and the merge driver |
|
1753 | # are processed after files in other actions, and the merge driver | |
1754 | # might add files to those actions via extraactions above. This can |
|
1754 | # might add files to those actions via extraactions above. This can | |
1755 | # lead to a file being recorded twice, with poor results. This is |
|
1755 | # lead to a file being recorded twice, with poor results. This is | |
1756 | # especially problematic for actions[ACTION_REMOVE] (currently only |
|
1756 | # especially problematic for actions[ACTION_REMOVE] (currently only | |
1757 | # possible with the merge driver in the initial merge process; |
|
1757 | # possible with the merge driver in the initial merge process; | |
1758 | # interrupted merges don't go through this flow). |
|
1758 | # interrupted merges don't go through this flow). | |
1759 | # |
|
1759 | # | |
1760 | # The real fix here is to have indexes by both file and action so |
|
1760 | # The real fix here is to have indexes by both file and action so | |
1761 | # that when the action for a file is changed it is automatically |
|
1761 | # that when the action for a file is changed it is automatically | |
1762 | # reflected in the other action lists. But that involves a more |
|
1762 | # reflected in the other action lists. But that involves a more | |
1763 | # complex data structure, so this will do for now. |
|
1763 | # complex data structure, so this will do for now. | |
1764 | # |
|
1764 | # | |
1765 | # We don't need to do the same operation for 'dc' and 'cd' because |
|
1765 | # We don't need to do the same operation for 'dc' and 'cd' because | |
1766 | # those lists aren't consulted again. |
|
1766 | # those lists aren't consulted again. | |
1767 | mfiles.difference_update(a[0] for a in acts) |
|
1767 | mfiles.difference_update(a[0] for a in acts) | |
1768 |
|
1768 | |||
1769 | actions[ACTION_MERGE] = [a for a in actions[ACTION_MERGE] |
|
1769 | actions[ACTION_MERGE] = [a for a in actions[ACTION_MERGE] | |
1770 | if a[0] in mfiles] |
|
1770 | if a[0] in mfiles] | |
1771 |
|
1771 | |||
1772 | progress(_updating, None, total=numupdates, unit=_files) |
|
1772 | progress(_updating, None, total=numupdates, unit=_files) | |
1773 | return updateresult(updated, merged, removed, unresolved) |
|
1773 | return updateresult(updated, merged, removed, unresolved) | |
1774 |
|
1774 | |||
1775 | def recordupdates(repo, actions, branchmerge): |
|
1775 | def recordupdates(repo, actions, branchmerge): | |
1776 | "record merge actions to the dirstate" |
|
1776 | "record merge actions to the dirstate" | |
1777 | # remove (must come first) |
|
1777 | # remove (must come first) | |
1778 | for f, args, msg in actions.get(ACTION_REMOVE, []): |
|
1778 | for f, args, msg in actions.get(ACTION_REMOVE, []): | |
1779 | if branchmerge: |
|
1779 | if branchmerge: | |
1780 | repo.dirstate.remove(f) |
|
1780 | repo.dirstate.remove(f) | |
1781 | else: |
|
1781 | else: | |
1782 | repo.dirstate.drop(f) |
|
1782 | repo.dirstate.drop(f) | |
1783 |
|
1783 | |||
1784 | # forget (must come first) |
|
1784 | # forget (must come first) | |
1785 | for f, args, msg in actions.get(ACTION_FORGET, []): |
|
1785 | for f, args, msg in actions.get(ACTION_FORGET, []): | |
1786 | repo.dirstate.drop(f) |
|
1786 | repo.dirstate.drop(f) | |
1787 |
|
1787 | |||
1788 | # resolve path conflicts |
|
1788 | # resolve path conflicts | |
1789 | for f, args, msg in actions.get(ACTION_PATH_CONFLICT_RESOLVE, []): |
|
1789 | for f, args, msg in actions.get(ACTION_PATH_CONFLICT_RESOLVE, []): | |
1790 | f0, = args |
|
1790 | f0, = args | |
1791 | origf0 = repo.dirstate.copied(f0) or f0 |
|
1791 | origf0 = repo.dirstate.copied(f0) or f0 | |
1792 | repo.dirstate.add(f) |
|
1792 | repo.dirstate.add(f) | |
1793 | repo.dirstate.copy(origf0, f) |
|
1793 | repo.dirstate.copy(origf0, f) | |
1794 | if f0 == origf0: |
|
1794 | if f0 == origf0: | |
1795 | repo.dirstate.remove(f0) |
|
1795 | repo.dirstate.remove(f0) | |
1796 | else: |
|
1796 | else: | |
1797 | repo.dirstate.drop(f0) |
|
1797 | repo.dirstate.drop(f0) | |
1798 |
|
1798 | |||
1799 | # re-add |
|
1799 | # re-add | |
1800 | for f, args, msg in actions.get(ACTION_ADD, []): |
|
1800 | for f, args, msg in actions.get(ACTION_ADD, []): | |
1801 | repo.dirstate.add(f) |
|
1801 | repo.dirstate.add(f) | |
1802 |
|
1802 | |||
1803 | # re-add/mark as modified |
|
1803 | # re-add/mark as modified | |
1804 | for f, args, msg in actions.get(ACTION_ADD_MODIFIED, []): |
|
1804 | for f, args, msg in actions.get(ACTION_ADD_MODIFIED, []): | |
1805 | if branchmerge: |
|
1805 | if branchmerge: | |
1806 | repo.dirstate.normallookup(f) |
|
1806 | repo.dirstate.normallookup(f) | |
1807 | else: |
|
1807 | else: | |
1808 | repo.dirstate.add(f) |
|
1808 | repo.dirstate.add(f) | |
1809 |
|
1809 | |||
1810 | # exec change |
|
1810 | # exec change | |
1811 | for f, args, msg in actions.get(ACTION_EXEC, []): |
|
1811 | for f, args, msg in actions.get(ACTION_EXEC, []): | |
1812 | repo.dirstate.normallookup(f) |
|
1812 | repo.dirstate.normallookup(f) | |
1813 |
|
1813 | |||
1814 | # keep |
|
1814 | # keep | |
1815 | for f, args, msg in actions.get(ACTION_KEEP, []): |
|
1815 | for f, args, msg in actions.get(ACTION_KEEP, []): | |
1816 | pass |
|
1816 | pass | |
1817 |
|
1817 | |||
1818 | # get |
|
1818 | # get | |
1819 | for f, args, msg in actions.get(ACTION_GET, []): |
|
1819 | for f, args, msg in actions.get(ACTION_GET, []): | |
1820 | if branchmerge: |
|
1820 | if branchmerge: | |
1821 | repo.dirstate.otherparent(f) |
|
1821 | repo.dirstate.otherparent(f) | |
1822 | else: |
|
1822 | else: | |
1823 | repo.dirstate.normal(f) |
|
1823 | repo.dirstate.normal(f) | |
1824 |
|
1824 | |||
1825 | # merge |
|
1825 | # merge | |
1826 | for f, args, msg in actions.get(ACTION_MERGE, []): |
|
1826 | for f, args, msg in actions.get(ACTION_MERGE, []): | |
1827 | f1, f2, fa, move, anc = args |
|
1827 | f1, f2, fa, move, anc = args | |
1828 | if branchmerge: |
|
1828 | if branchmerge: | |
1829 | # We've done a branch merge, mark this file as merged |
|
1829 | # We've done a branch merge, mark this file as merged | |
1830 | # so that we properly record the merger later |
|
1830 | # so that we properly record the merger later | |
1831 | repo.dirstate.merge(f) |
|
1831 | repo.dirstate.merge(f) | |
1832 | if f1 != f2: # copy/rename |
|
1832 | if f1 != f2: # copy/rename | |
1833 | if move: |
|
1833 | if move: | |
1834 | repo.dirstate.remove(f1) |
|
1834 | repo.dirstate.remove(f1) | |
1835 | if f1 != f: |
|
1835 | if f1 != f: | |
1836 | repo.dirstate.copy(f1, f) |
|
1836 | repo.dirstate.copy(f1, f) | |
1837 | else: |
|
1837 | else: | |
1838 | repo.dirstate.copy(f2, f) |
|
1838 | repo.dirstate.copy(f2, f) | |
1839 | else: |
|
1839 | else: | |
1840 | # We've update-merged a locally modified file, so |
|
1840 | # We've update-merged a locally modified file, so | |
1841 | # we set the dirstate to emulate a normal checkout |
|
1841 | # we set the dirstate to emulate a normal checkout | |
1842 | # of that file some time in the past. Thus our |
|
1842 | # of that file some time in the past. Thus our | |
1843 | # merge will appear as a normal local file |
|
1843 | # merge will appear as a normal local file | |
1844 | # modification. |
|
1844 | # modification. | |
1845 | if f2 == f: # file not locally copied/moved |
|
1845 | if f2 == f: # file not locally copied/moved | |
1846 | repo.dirstate.normallookup(f) |
|
1846 | repo.dirstate.normallookup(f) | |
1847 | if move: |
|
1847 | if move: | |
1848 | repo.dirstate.drop(f1) |
|
1848 | repo.dirstate.drop(f1) | |
1849 |
|
1849 | |||
1850 | # directory rename, move local |
|
1850 | # directory rename, move local | |
1851 | for f, args, msg in actions.get(ACTION_DIR_RENAME_MOVE_LOCAL, []): |
|
1851 | for f, args, msg in actions.get(ACTION_DIR_RENAME_MOVE_LOCAL, []): | |
1852 | f0, flag = args |
|
1852 | f0, flag = args | |
1853 | if branchmerge: |
|
1853 | if branchmerge: | |
1854 | repo.dirstate.add(f) |
|
1854 | repo.dirstate.add(f) | |
1855 | repo.dirstate.remove(f0) |
|
1855 | repo.dirstate.remove(f0) | |
1856 | repo.dirstate.copy(f0, f) |
|
1856 | repo.dirstate.copy(f0, f) | |
1857 | else: |
|
1857 | else: | |
1858 | repo.dirstate.normal(f) |
|
1858 | repo.dirstate.normal(f) | |
1859 | repo.dirstate.drop(f0) |
|
1859 | repo.dirstate.drop(f0) | |
1860 |
|
1860 | |||
1861 | # directory rename, get |
|
1861 | # directory rename, get | |
1862 | for f, args, msg in actions.get(ACTION_LOCAL_DIR_RENAME_GET, []): |
|
1862 | for f, args, msg in actions.get(ACTION_LOCAL_DIR_RENAME_GET, []): | |
1863 | f0, flag = args |
|
1863 | f0, flag = args | |
1864 | if branchmerge: |
|
1864 | if branchmerge: | |
1865 | repo.dirstate.add(f) |
|
1865 | repo.dirstate.add(f) | |
1866 | repo.dirstate.copy(f0, f) |
|
1866 | repo.dirstate.copy(f0, f) | |
1867 | else: |
|
1867 | else: | |
1868 | repo.dirstate.normal(f) |
|
1868 | repo.dirstate.normal(f) | |
1869 |
|
1869 | |||
1870 | def update(repo, node, branchmerge, force, ancestor=None, |
|
1870 | def update(repo, node, branchmerge, force, ancestor=None, | |
1871 | mergeancestor=False, labels=None, matcher=None, mergeforce=False, |
|
1871 | mergeancestor=False, labels=None, matcher=None, mergeforce=False, | |
1872 | updatecheck=None, wc=None): |
|
1872 | updatecheck=None, wc=None): | |
1873 | """ |
|
1873 | """ | |
1874 | Perform a merge between the working directory and the given node |
|
1874 | Perform a merge between the working directory and the given node | |
1875 |
|
1875 | |||
1876 | node = the node to update to |
|
1876 | node = the node to update to | |
1877 | branchmerge = whether to merge between branches |
|
1877 | branchmerge = whether to merge between branches | |
1878 | force = whether to force branch merging or file overwriting |
|
1878 | force = whether to force branch merging or file overwriting | |
1879 | matcher = a matcher to filter file lists (dirstate not updated) |
|
1879 | matcher = a matcher to filter file lists (dirstate not updated) | |
1880 | mergeancestor = whether it is merging with an ancestor. If true, |
|
1880 | mergeancestor = whether it is merging with an ancestor. If true, | |
1881 | we should accept the incoming changes for any prompts that occur. |
|
1881 | we should accept the incoming changes for any prompts that occur. | |
1882 | If false, merging with an ancestor (fast-forward) is only allowed |
|
1882 | If false, merging with an ancestor (fast-forward) is only allowed | |
1883 | between different named branches. This flag is used by rebase extension |
|
1883 | between different named branches. This flag is used by rebase extension | |
1884 | as a temporary fix and should be avoided in general. |
|
1884 | as a temporary fix and should be avoided in general. | |
1885 | labels = labels to use for base, local and other |
|
1885 | labels = labels to use for base, local and other | |
1886 | mergeforce = whether the merge was run with 'merge --force' (deprecated): if |
|
1886 | mergeforce = whether the merge was run with 'merge --force' (deprecated): if | |
1887 | this is True, then 'force' should be True as well. |
|
1887 | this is True, then 'force' should be True as well. | |
1888 |
|
1888 | |||
1889 | The table below shows all the behaviors of the update command given the |
|
1889 | The table below shows all the behaviors of the update command given the | |
1890 | -c/--check and -C/--clean or no options, whether the working directory is |
|
1890 | -c/--check and -C/--clean or no options, whether the working directory is | |
1891 | dirty, whether a revision is specified, and the relationship of the parent |
|
1891 | dirty, whether a revision is specified, and the relationship of the parent | |
1892 | rev to the target rev (linear or not). Match from top first. The -n |
|
1892 | rev to the target rev (linear or not). Match from top first. The -n | |
1893 | option doesn't exist on the command line, but represents the |
|
1893 | option doesn't exist on the command line, but represents the | |
1894 | experimental.updatecheck=noconflict option. |
|
1894 | experimental.updatecheck=noconflict option. | |
1895 |
|
1895 | |||
1896 | This logic is tested by test-update-branches.t. |
|
1896 | This logic is tested by test-update-branches.t. | |
1897 |
|
1897 | |||
1898 | -c -C -n -m dirty rev linear | result |
|
1898 | -c -C -n -m dirty rev linear | result | |
1899 | y y * * * * * | (1) |
|
1899 | y y * * * * * | (1) | |
1900 | y * y * * * * | (1) |
|
1900 | y * y * * * * | (1) | |
1901 | y * * y * * * | (1) |
|
1901 | y * * y * * * | (1) | |
1902 | * y y * * * * | (1) |
|
1902 | * y y * * * * | (1) | |
1903 | * y * y * * * | (1) |
|
1903 | * y * y * * * | (1) | |
1904 | * * y y * * * | (1) |
|
1904 | * * y y * * * | (1) | |
1905 | * * * * * n n | x |
|
1905 | * * * * * n n | x | |
1906 | * * * * n * * | ok |
|
1906 | * * * * n * * | ok | |
1907 | n n n n y * y | merge |
|
1907 | n n n n y * y | merge | |
1908 | n n n n y y n | (2) |
|
1908 | n n n n y y n | (2) | |
1909 | n n n y y * * | merge |
|
1909 | n n n y y * * | merge | |
1910 | n n y n y * * | merge if no conflict |
|
1910 | n n y n y * * | merge if no conflict | |
1911 | n y n n y * * | discard |
|
1911 | n y n n y * * | discard | |
1912 | y n n n y * * | (3) |
|
1912 | y n n n y * * | (3) | |
1913 |
|
1913 | |||
1914 | x = can't happen |
|
1914 | x = can't happen | |
1915 | * = don't-care |
|
1915 | * = don't-care | |
1916 | 1 = incompatible options (checked in commands.py) |
|
1916 | 1 = incompatible options (checked in commands.py) | |
1917 | 2 = abort: uncommitted changes (commit or update --clean to discard changes) |
|
1917 | 2 = abort: uncommitted changes (commit or update --clean to discard changes) | |
1918 | 3 = abort: uncommitted changes (checked in commands.py) |
|
1918 | 3 = abort: uncommitted changes (checked in commands.py) | |
1919 |
|
1919 | |||
1920 | The merge is performed inside ``wc``, a workingctx-like objects. It defaults |
|
1920 | The merge is performed inside ``wc``, a workingctx-like objects. It defaults | |
1921 | to repo[None] if None is passed. |
|
1921 | to repo[None] if None is passed. | |
1922 |
|
1922 | |||
1923 | Return the same tuple as applyupdates(). |
|
1923 | Return the same tuple as applyupdates(). | |
1924 | """ |
|
1924 | """ | |
1925 | # Avoid cycle. |
|
1925 | # Avoid cycle. | |
1926 | from . import sparse |
|
1926 | from . import sparse | |
1927 |
|
1927 | |||
1928 | # This function used to find the default destination if node was None, but |
|
1928 | # This function used to find the default destination if node was None, but | |
1929 | # that's now in destutil.py. |
|
1929 | # that's now in destutil.py. | |
1930 | assert node is not None |
|
1930 | assert node is not None | |
1931 | if not branchmerge and not force: |
|
1931 | if not branchmerge and not force: | |
1932 | # TODO: remove the default once all callers that pass branchmerge=False |
|
1932 | # TODO: remove the default once all callers that pass branchmerge=False | |
1933 | # and force=False pass a value for updatecheck. We may want to allow |
|
1933 | # and force=False pass a value for updatecheck. We may want to allow | |
1934 | # updatecheck='abort' to better suppport some of these callers. |
|
1934 | # updatecheck='abort' to better suppport some of these callers. | |
1935 | if updatecheck is None: |
|
1935 | if updatecheck is None: | |
1936 | updatecheck = 'linear' |
|
1936 | updatecheck = 'linear' | |
1937 | assert updatecheck in ('none', 'linear', 'noconflict') |
|
1937 | assert updatecheck in ('none', 'linear', 'noconflict') | |
1938 | # If we're doing a partial update, we need to skip updating |
|
1938 | # If we're doing a partial update, we need to skip updating | |
1939 | # the dirstate, so make a note of any partial-ness to the |
|
1939 | # the dirstate, so make a note of any partial-ness to the | |
1940 | # update here. |
|
1940 | # update here. | |
1941 | if matcher is None or matcher.always(): |
|
1941 | if matcher is None or matcher.always(): | |
1942 | partial = False |
|
1942 | partial = False | |
1943 | else: |
|
1943 | else: | |
1944 | partial = True |
|
1944 | partial = True | |
1945 | with repo.wlock(): |
|
1945 | with repo.wlock(): | |
1946 | if wc is None: |
|
1946 | if wc is None: | |
1947 | wc = repo[None] |
|
1947 | wc = repo[None] | |
1948 | pl = wc.parents() |
|
1948 | pl = wc.parents() | |
1949 | p1 = pl[0] |
|
1949 | p1 = pl[0] | |
1950 | pas = [None] |
|
1950 | pas = [None] | |
1951 | if ancestor is not None: |
|
1951 | if ancestor is not None: | |
1952 | pas = [repo[ancestor]] |
|
1952 | pas = [repo[ancestor]] | |
1953 |
|
1953 | |||
1954 | overwrite = force and not branchmerge |
|
1954 | overwrite = force and not branchmerge | |
1955 |
|
1955 | |||
1956 | p2 = repo[node] |
|
1956 | p2 = repo[node] | |
1957 | if pas[0] is None: |
|
1957 | if pas[0] is None: | |
1958 | if repo.ui.configlist('merge', 'preferancestor') == ['*']: |
|
1958 | if repo.ui.configlist('merge', 'preferancestor') == ['*']: | |
1959 | cahs = repo.changelog.commonancestorsheads(p1.node(), p2.node()) |
|
1959 | cahs = repo.changelog.commonancestorsheads(p1.node(), p2.node()) | |
1960 | pas = [repo[anc] for anc in (sorted(cahs) or [nullid])] |
|
1960 | pas = [repo[anc] for anc in (sorted(cahs) or [nullid])] | |
1961 | else: |
|
1961 | else: | |
1962 | pas = [p1.ancestor(p2, warn=branchmerge)] |
|
1962 | pas = [p1.ancestor(p2, warn=branchmerge)] | |
1963 |
|
1963 | |||
1964 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), bytes(p1), bytes(p2) |
|
1964 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), bytes(p1), bytes(p2) | |
1965 |
|
1965 | |||
1966 | ### check phase |
|
1966 | ### check phase | |
1967 | if not overwrite: |
|
1967 | if not overwrite: | |
1968 | if len(pl) > 1: |
|
1968 | if len(pl) > 1: | |
1969 | raise error.Abort(_("outstanding uncommitted merge")) |
|
1969 | raise error.Abort(_("outstanding uncommitted merge")) | |
1970 | ms = mergestate.read(repo) |
|
1970 | ms = mergestate.read(repo) | |
1971 | if list(ms.unresolved()): |
|
1971 | if list(ms.unresolved()): | |
1972 | raise error.Abort(_("outstanding merge conflicts")) |
|
1972 | raise error.Abort(_("outstanding merge conflicts")) | |
1973 | if branchmerge: |
|
1973 | if branchmerge: | |
1974 | if pas == [p2]: |
|
1974 | if pas == [p2]: | |
1975 | raise error.Abort(_("merging with a working directory ancestor" |
|
1975 | raise error.Abort(_("merging with a working directory ancestor" | |
1976 | " has no effect")) |
|
1976 | " has no effect")) | |
1977 | elif pas == [p1]: |
|
1977 | elif pas == [p1]: | |
1978 | if not mergeancestor and wc.branch() == p2.branch(): |
|
1978 | if not mergeancestor and wc.branch() == p2.branch(): | |
1979 | raise error.Abort(_("nothing to merge"), |
|
1979 | raise error.Abort(_("nothing to merge"), | |
1980 | hint=_("use 'hg update' " |
|
1980 | hint=_("use 'hg update' " | |
1981 | "or check 'hg heads'")) |
|
1981 | "or check 'hg heads'")) | |
1982 | if not force and (wc.files() or wc.deleted()): |
|
1982 | if not force and (wc.files() or wc.deleted()): | |
1983 | raise error.Abort(_("uncommitted changes"), |
|
1983 | raise error.Abort(_("uncommitted changes"), | |
1984 | hint=_("use 'hg status' to list changes")) |
|
1984 | hint=_("use 'hg status' to list changes")) | |
1985 | if not wc.isinmemory(): |
|
1985 | if not wc.isinmemory(): | |
1986 | for s in sorted(wc.substate): |
|
1986 | for s in sorted(wc.substate): | |
1987 | wc.sub(s).bailifchanged() |
|
1987 | wc.sub(s).bailifchanged() | |
1988 |
|
1988 | |||
1989 | elif not overwrite: |
|
1989 | elif not overwrite: | |
1990 | if p1 == p2: # no-op update |
|
1990 | if p1 == p2: # no-op update | |
1991 | # call the hooks and exit early |
|
1991 | # call the hooks and exit early | |
1992 | repo.hook('preupdate', throw=True, parent1=xp2, parent2='') |
|
1992 | repo.hook('preupdate', throw=True, parent1=xp2, parent2='') | |
1993 | repo.hook('update', parent1=xp2, parent2='', error=0) |
|
1993 | repo.hook('update', parent1=xp2, parent2='', error=0) | |
1994 | return updateresult(0, 0, 0, 0) |
|
1994 | return updateresult(0, 0, 0, 0) | |
1995 |
|
1995 | |||
1996 | if (updatecheck == 'linear' and |
|
1996 | if (updatecheck == 'linear' and | |
1997 | pas not in ([p1], [p2])): # nonlinear |
|
1997 | pas not in ([p1], [p2])): # nonlinear | |
1998 | dirty = wc.dirty(missing=True) |
|
1998 | dirty = wc.dirty(missing=True) | |
1999 | if dirty: |
|
1999 | if dirty: | |
2000 | # Branching is a bit strange to ensure we do the minimal |
|
2000 | # Branching is a bit strange to ensure we do the minimal | |
2001 | # amount of call to obsutil.foreground. |
|
2001 | # amount of call to obsutil.foreground. | |
2002 | foreground = obsutil.foreground(repo, [p1.node()]) |
|
2002 | foreground = obsutil.foreground(repo, [p1.node()]) | |
2003 | # note: the <node> variable contains a random identifier |
|
2003 | # note: the <node> variable contains a random identifier | |
2004 | if repo[node].node() in foreground: |
|
2004 | if repo[node].node() in foreground: | |
2005 | pass # allow updating to successors |
|
2005 | pass # allow updating to successors | |
2006 | else: |
|
2006 | else: | |
2007 | msg = _("uncommitted changes") |
|
2007 | msg = _("uncommitted changes") | |
2008 | hint = _("commit or update --clean to discard changes") |
|
2008 | hint = _("commit or update --clean to discard changes") | |
2009 | raise error.UpdateAbort(msg, hint=hint) |
|
2009 | raise error.UpdateAbort(msg, hint=hint) | |
2010 | else: |
|
2010 | else: | |
2011 | # Allow jumping branches if clean and specific rev given |
|
2011 | # Allow jumping branches if clean and specific rev given | |
2012 | pass |
|
2012 | pass | |
2013 |
|
2013 | |||
2014 | if overwrite: |
|
2014 | if overwrite: | |
2015 | pas = [wc] |
|
2015 | pas = [wc] | |
2016 | elif not branchmerge: |
|
2016 | elif not branchmerge: | |
2017 | pas = [p1] |
|
2017 | pas = [p1] | |
2018 |
|
2018 | |||
2019 | # deprecated config: merge.followcopies |
|
2019 | # deprecated config: merge.followcopies | |
2020 | followcopies = repo.ui.configbool('merge', 'followcopies') |
|
2020 | followcopies = repo.ui.configbool('merge', 'followcopies') | |
2021 | if overwrite: |
|
2021 | if overwrite: | |
2022 | followcopies = False |
|
2022 | followcopies = False | |
2023 | elif not pas[0]: |
|
2023 | elif not pas[0]: | |
2024 | followcopies = False |
|
2024 | followcopies = False | |
2025 | if not branchmerge and not wc.dirty(missing=True): |
|
2025 | if not branchmerge and not wc.dirty(missing=True): | |
2026 | followcopies = False |
|
2026 | followcopies = False | |
2027 |
|
2027 | |||
2028 | ### calculate phase |
|
2028 | ### calculate phase | |
2029 | actionbyfile, diverge, renamedelete = calculateupdates( |
|
2029 | actionbyfile, diverge, renamedelete = calculateupdates( | |
2030 | repo, wc, p2, pas, branchmerge, force, mergeancestor, |
|
2030 | repo, wc, p2, pas, branchmerge, force, mergeancestor, | |
2031 | followcopies, matcher=matcher, mergeforce=mergeforce) |
|
2031 | followcopies, matcher=matcher, mergeforce=mergeforce) | |
2032 |
|
2032 | |||
2033 | if updatecheck == 'noconflict': |
|
2033 | if updatecheck == 'noconflict': | |
2034 | for f, (m, args, msg) in actionbyfile.iteritems(): |
|
2034 | for f, (m, args, msg) in actionbyfile.iteritems(): | |
2035 | if m not in (ACTION_GET, ACTION_KEEP, ACTION_EXEC, |
|
2035 | if m not in (ACTION_GET, ACTION_KEEP, ACTION_EXEC, | |
2036 | ACTION_REMOVE, ACTION_PATH_CONFLICT_RESOLVE): |
|
2036 | ACTION_REMOVE, ACTION_PATH_CONFLICT_RESOLVE): | |
2037 | msg = _("conflicting changes") |
|
2037 | msg = _("conflicting changes") | |
2038 | hint = _("commit or update --clean to discard changes") |
|
2038 | hint = _("commit or update --clean to discard changes") | |
2039 | raise error.Abort(msg, hint=hint) |
|
2039 | raise error.Abort(msg, hint=hint) | |
2040 |
|
2040 | |||
2041 | # Prompt and create actions. Most of this is in the resolve phase |
|
2041 | # Prompt and create actions. Most of this is in the resolve phase | |
2042 | # already, but we can't handle .hgsubstate in filemerge or |
|
2042 | # already, but we can't handle .hgsubstate in filemerge or | |
2043 | # subrepoutil.submerge yet so we have to keep prompting for it. |
|
2043 | # subrepoutil.submerge yet so we have to keep prompting for it. | |
2044 | if '.hgsubstate' in actionbyfile: |
|
2044 | if '.hgsubstate' in actionbyfile: | |
2045 | f = '.hgsubstate' |
|
2045 | f = '.hgsubstate' | |
2046 | m, args, msg = actionbyfile[f] |
|
2046 | m, args, msg = actionbyfile[f] | |
2047 | prompts = filemerge.partextras(labels) |
|
2047 | prompts = filemerge.partextras(labels) | |
2048 | prompts['f'] = f |
|
2048 | prompts['f'] = f | |
2049 | if m == ACTION_CHANGED_DELETED: |
|
2049 | if m == ACTION_CHANGED_DELETED: | |
2050 | if repo.ui.promptchoice( |
|
2050 | if repo.ui.promptchoice( | |
2051 | _("local%(l)s changed %(f)s which other%(o)s deleted\n" |
|
2051 | _("local%(l)s changed %(f)s which other%(o)s deleted\n" | |
2052 | "use (c)hanged version or (d)elete?" |
|
2052 | "use (c)hanged version or (d)elete?" | |
2053 | "$$ &Changed $$ &Delete") % prompts, 0): |
|
2053 | "$$ &Changed $$ &Delete") % prompts, 0): | |
2054 | actionbyfile[f] = (ACTION_REMOVE, None, 'prompt delete') |
|
2054 | actionbyfile[f] = (ACTION_REMOVE, None, 'prompt delete') | |
2055 | elif f in p1: |
|
2055 | elif f in p1: | |
2056 | actionbyfile[f] = (ACTION_ADD_MODIFIED, None, 'prompt keep') |
|
2056 | actionbyfile[f] = (ACTION_ADD_MODIFIED, None, 'prompt keep') | |
2057 | else: |
|
2057 | else: | |
2058 | actionbyfile[f] = (ACTION_ADD, None, 'prompt keep') |
|
2058 | actionbyfile[f] = (ACTION_ADD, None, 'prompt keep') | |
2059 | elif m == ACTION_DELETED_CHANGED: |
|
2059 | elif m == ACTION_DELETED_CHANGED: | |
2060 | f1, f2, fa, move, anc = args |
|
2060 | f1, f2, fa, move, anc = args | |
2061 | flags = p2[f2].flags() |
|
2061 | flags = p2[f2].flags() | |
2062 | if repo.ui.promptchoice( |
|
2062 | if repo.ui.promptchoice( | |
2063 | _("other%(o)s changed %(f)s which local%(l)s deleted\n" |
|
2063 | _("other%(o)s changed %(f)s which local%(l)s deleted\n" | |
2064 | "use (c)hanged version or leave (d)eleted?" |
|
2064 | "use (c)hanged version or leave (d)eleted?" | |
2065 | "$$ &Changed $$ &Deleted") % prompts, 0) == 0: |
|
2065 | "$$ &Changed $$ &Deleted") % prompts, 0) == 0: | |
2066 | actionbyfile[f] = (ACTION_GET, (flags, False), |
|
2066 | actionbyfile[f] = (ACTION_GET, (flags, False), | |
2067 | 'prompt recreating') |
|
2067 | 'prompt recreating') | |
2068 | else: |
|
2068 | else: | |
2069 | del actionbyfile[f] |
|
2069 | del actionbyfile[f] | |
2070 |
|
2070 | |||
2071 | # Convert to dictionary-of-lists format |
|
2071 | # Convert to dictionary-of-lists format | |
2072 | actions = dict((m, []) |
|
2072 | actions = dict((m, []) | |
2073 | for m in ( |
|
2073 | for m in ( | |
2074 | ACTION_ADD, |
|
2074 | ACTION_ADD, | |
2075 | ACTION_ADD_MODIFIED, |
|
2075 | ACTION_ADD_MODIFIED, | |
2076 | ACTION_FORGET, |
|
2076 | ACTION_FORGET, | |
2077 | ACTION_GET, |
|
2077 | ACTION_GET, | |
2078 | ACTION_CHANGED_DELETED, |
|
2078 | ACTION_CHANGED_DELETED, | |
2079 | ACTION_DELETED_CHANGED, |
|
2079 | ACTION_DELETED_CHANGED, | |
2080 | ACTION_REMOVE, |
|
2080 | ACTION_REMOVE, | |
2081 | ACTION_DIR_RENAME_MOVE_LOCAL, |
|
2081 | ACTION_DIR_RENAME_MOVE_LOCAL, | |
2082 | ACTION_LOCAL_DIR_RENAME_GET, |
|
2082 | ACTION_LOCAL_DIR_RENAME_GET, | |
2083 | ACTION_MERGE, |
|
2083 | ACTION_MERGE, | |
2084 | ACTION_EXEC, |
|
2084 | ACTION_EXEC, | |
2085 | ACTION_KEEP, |
|
2085 | ACTION_KEEP, | |
2086 | ACTION_PATH_CONFLICT, |
|
2086 | ACTION_PATH_CONFLICT, | |
2087 | ACTION_PATH_CONFLICT_RESOLVE)) |
|
2087 | ACTION_PATH_CONFLICT_RESOLVE)) | |
2088 | for f, (m, args, msg) in actionbyfile.iteritems(): |
|
2088 | for f, (m, args, msg) in actionbyfile.iteritems(): | |
2089 | if m not in actions: |
|
2089 | if m not in actions: | |
2090 | actions[m] = [] |
|
2090 | actions[m] = [] | |
2091 | actions[m].append((f, args, msg)) |
|
2091 | actions[m].append((f, args, msg)) | |
2092 |
|
2092 | |||
2093 | if not util.fscasesensitive(repo.path): |
|
2093 | if not util.fscasesensitive(repo.path): | |
2094 | # check collision between files only in p2 for clean update |
|
2094 | # check collision between files only in p2 for clean update | |
2095 | if (not branchmerge and |
|
2095 | if (not branchmerge and | |
2096 | (force or not wc.dirty(missing=True, branch=False))): |
|
2096 | (force or not wc.dirty(missing=True, branch=False))): | |
2097 | _checkcollision(repo, p2.manifest(), None) |
|
2097 | _checkcollision(repo, p2.manifest(), None) | |
2098 | else: |
|
2098 | else: | |
2099 | _checkcollision(repo, wc.manifest(), actions) |
|
2099 | _checkcollision(repo, wc.manifest(), actions) | |
2100 |
|
2100 | |||
2101 | # divergent renames |
|
2101 | # divergent renames | |
2102 | for f, fl in sorted(diverge.iteritems()): |
|
2102 | for f, fl in sorted(diverge.iteritems()): | |
2103 | repo.ui.warn(_("note: possible conflict - %s was renamed " |
|
2103 | repo.ui.warn(_("note: possible conflict - %s was renamed " | |
2104 | "multiple times to:\n") % f) |
|
2104 | "multiple times to:\n") % f) | |
2105 | for nf in fl: |
|
2105 | for nf in fl: | |
2106 | repo.ui.warn(" %s\n" % nf) |
|
2106 | repo.ui.warn(" %s\n" % nf) | |
2107 |
|
2107 | |||
2108 | # rename and delete |
|
2108 | # rename and delete | |
2109 | for f, fl in sorted(renamedelete.iteritems()): |
|
2109 | for f, fl in sorted(renamedelete.iteritems()): | |
2110 | repo.ui.warn(_("note: possible conflict - %s was deleted " |
|
2110 | repo.ui.warn(_("note: possible conflict - %s was deleted " | |
2111 | "and renamed to:\n") % f) |
|
2111 | "and renamed to:\n") % f) | |
2112 | for nf in fl: |
|
2112 | for nf in fl: | |
2113 | repo.ui.warn(" %s\n" % nf) |
|
2113 | repo.ui.warn(" %s\n" % nf) | |
2114 |
|
2114 | |||
2115 | ### apply phase |
|
2115 | ### apply phase | |
2116 | if not branchmerge: # just jump to the new rev |
|
2116 | if not branchmerge: # just jump to the new rev | |
2117 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' |
|
2117 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' | |
2118 | if not partial and not wc.isinmemory(): |
|
2118 | if not partial and not wc.isinmemory(): | |
2119 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) |
|
2119 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) | |
2120 | # note that we're in the middle of an update |
|
2120 | # note that we're in the middle of an update | |
2121 | repo.vfs.write('updatestate', p2.hex()) |
|
2121 | repo.vfs.write('updatestate', p2.hex()) | |
2122 |
|
2122 | |||
2123 | # Advertise fsmonitor when its presence could be useful. |
|
2123 | # Advertise fsmonitor when its presence could be useful. | |
2124 | # |
|
2124 | # | |
2125 | # We only advertise when performing an update from an empty working |
|
2125 | # We only advertise when performing an update from an empty working | |
2126 | # directory. This typically only occurs during initial clone. |
|
2126 | # directory. This typically only occurs during initial clone. | |
2127 | # |
|
2127 | # | |
2128 | # We give users a mechanism to disable the warning in case it is |
|
2128 | # We give users a mechanism to disable the warning in case it is | |
2129 | # annoying. |
|
2129 | # annoying. | |
2130 | # |
|
2130 | # | |
2131 | # We only allow on Linux and MacOS because that's where fsmonitor is |
|
2131 | # We only allow on Linux and MacOS because that's where fsmonitor is | |
2132 | # considered stable. |
|
2132 | # considered stable. | |
2133 | fsmonitorwarning = repo.ui.configbool('fsmonitor', 'warn_when_unused') |
|
2133 | fsmonitorwarning = repo.ui.configbool('fsmonitor', 'warn_when_unused') | |
2134 | fsmonitorthreshold = repo.ui.configint('fsmonitor', |
|
2134 | fsmonitorthreshold = repo.ui.configint('fsmonitor', | |
2135 | 'warn_update_file_count') |
|
2135 | 'warn_update_file_count') | |
2136 | try: |
|
2136 | try: | |
2137 | # avoid cycle: extensions -> cmdutil -> merge |
|
2137 | # avoid cycle: extensions -> cmdutil -> merge | |
2138 | from . import extensions |
|
2138 | from . import extensions | |
2139 | extensions.find('fsmonitor') |
|
2139 | extensions.find('fsmonitor') | |
2140 | fsmonitorenabled = repo.ui.config('fsmonitor', 'mode') != 'off' |
|
2140 | fsmonitorenabled = repo.ui.config('fsmonitor', 'mode') != 'off' | |
2141 | # We intentionally don't look at whether fsmonitor has disabled |
|
2141 | # We intentionally don't look at whether fsmonitor has disabled | |
2142 | # itself because a) fsmonitor may have already printed a warning |
|
2142 | # itself because a) fsmonitor may have already printed a warning | |
2143 | # b) we only care about the config state here. |
|
2143 | # b) we only care about the config state here. | |
2144 | except KeyError: |
|
2144 | except KeyError: | |
2145 | fsmonitorenabled = False |
|
2145 | fsmonitorenabled = False | |
2146 |
|
2146 | |||
2147 | if (fsmonitorwarning |
|
2147 | if (fsmonitorwarning | |
2148 | and not fsmonitorenabled |
|
2148 | and not fsmonitorenabled | |
2149 | and p1.node() == nullid |
|
2149 | and p1.node() == nullid | |
2150 | and len(actions[ACTION_GET]) >= fsmonitorthreshold |
|
2150 | and len(actions[ACTION_GET]) >= fsmonitorthreshold | |
2151 | and pycompat.sysplatform.startswith(('linux', 'darwin'))): |
|
2151 | and pycompat.sysplatform.startswith(('linux', 'darwin'))): | |
2152 | repo.ui.warn( |
|
2152 | repo.ui.warn( | |
2153 | _('(warning: large working directory being used without ' |
|
2153 | _('(warning: large working directory being used without ' | |
2154 | 'fsmonitor enabled; enable fsmonitor to improve performance; ' |
|
2154 | 'fsmonitor enabled; enable fsmonitor to improve performance; ' | |
2155 | 'see "hg help -e fsmonitor")\n')) |
|
2155 | 'see "hg help -e fsmonitor")\n')) | |
2156 |
|
2156 | |||
2157 | stats = applyupdates(repo, actions, wc, p2, overwrite, labels=labels) |
|
2157 | stats = applyupdates(repo, actions, wc, p2, overwrite, labels=labels) | |
2158 |
|
2158 | |||
2159 | if not partial and not wc.isinmemory(): |
|
2159 | if not partial and not wc.isinmemory(): | |
2160 | with repo.dirstate.parentchange(): |
|
2160 | with repo.dirstate.parentchange(): | |
2161 | repo.setparents(fp1, fp2) |
|
2161 | repo.setparents(fp1, fp2) | |
2162 | recordupdates(repo, actions, branchmerge) |
|
2162 | recordupdates(repo, actions, branchmerge) | |
2163 | # update completed, clear state |
|
2163 | # update completed, clear state | |
2164 | util.unlink(repo.vfs.join('updatestate')) |
|
2164 | util.unlink(repo.vfs.join('updatestate')) | |
2165 |
|
2165 | |||
2166 | if not branchmerge: |
|
2166 | if not branchmerge: | |
2167 | repo.dirstate.setbranch(p2.branch()) |
|
2167 | repo.dirstate.setbranch(p2.branch()) | |
2168 |
|
2168 | |||
2169 | # If we're updating to a location, clean up any stale temporary includes |
|
2169 | # If we're updating to a location, clean up any stale temporary includes | |
2170 | # (ex: this happens during hg rebase --abort). |
|
2170 | # (ex: this happens during hg rebase --abort). | |
2171 | if not branchmerge: |
|
2171 | if not branchmerge: | |
2172 | sparse.prunetemporaryincludes(repo) |
|
2172 | sparse.prunetemporaryincludes(repo) | |
2173 |
|
2173 | |||
2174 | if not partial: |
|
2174 | if not partial: | |
2175 | repo.hook('update', parent1=xp1, parent2=xp2, |
|
2175 | repo.hook('update', parent1=xp1, parent2=xp2, | |
2176 | error=stats.unresolvedcount) |
|
2176 | error=stats.unresolvedcount) | |
2177 | return stats |
|
2177 | return stats | |
2178 |
|
2178 | |||
2179 | def graft(repo, ctx, pctx, labels, keepparent=False): |
|
2179 | def graft(repo, ctx, pctx, labels, keepparent=False): | |
2180 | """Do a graft-like merge. |
|
2180 | """Do a graft-like merge. | |
2181 |
|
2181 | |||
2182 | This is a merge where the merge ancestor is chosen such that one |
|
2182 | This is a merge where the merge ancestor is chosen such that one | |
2183 | or more changesets are grafted onto the current changeset. In |
|
2183 | or more changesets are grafted onto the current changeset. In | |
2184 | addition to the merge, this fixes up the dirstate to include only |
|
2184 | addition to the merge, this fixes up the dirstate to include only | |
2185 | a single parent (if keepparent is False) and tries to duplicate any |
|
2185 | a single parent (if keepparent is False) and tries to duplicate any | |
2186 | renames/copies appropriately. |
|
2186 | renames/copies appropriately. | |
2187 |
|
2187 | |||
2188 | ctx - changeset to rebase |
|
2188 | ctx - changeset to rebase | |
2189 | pctx - merge base, usually ctx.p1() |
|
2189 | pctx - merge base, usually ctx.p1() | |
2190 | labels - merge labels eg ['local', 'graft'] |
|
2190 | labels - merge labels eg ['local', 'graft'] | |
2191 | keepparent - keep second parent if any |
|
2191 | keepparent - keep second parent if any | |
2192 |
|
2192 | |||
2193 | """ |
|
2193 | """ | |
2194 | # If we're grafting a descendant onto an ancestor, be sure to pass |
|
2194 | # If we're grafting a descendant onto an ancestor, be sure to pass | |
2195 | # mergeancestor=True to update. This does two things: 1) allows the merge if |
|
2195 | # mergeancestor=True to update. This does two things: 1) allows the merge if | |
2196 | # the destination is the same as the parent of the ctx (so we can use graft |
|
2196 | # the destination is the same as the parent of the ctx (so we can use graft | |
2197 | # to copy commits), and 2) informs update that the incoming changes are |
|
2197 | # to copy commits), and 2) informs update that the incoming changes are | |
2198 | # newer than the destination so it doesn't prompt about "remote changed foo |
|
2198 | # newer than the destination so it doesn't prompt about "remote changed foo | |
2199 | # which local deleted". |
|
2199 | # which local deleted". | |
2200 | mergeancestor = repo.changelog.isancestor(repo['.'].node(), ctx.node()) |
|
2200 | mergeancestor = repo.changelog.isancestor(repo['.'].node(), ctx.node()) | |
2201 |
|
2201 | |||
2202 | stats = update(repo, ctx.node(), True, True, pctx.node(), |
|
2202 | stats = update(repo, ctx.node(), True, True, pctx.node(), | |
2203 | mergeancestor=mergeancestor, labels=labels) |
|
2203 | mergeancestor=mergeancestor, labels=labels) | |
2204 |
|
2204 | |||
2205 | pother = nullid |
|
2205 | pother = nullid | |
2206 | parents = ctx.parents() |
|
2206 | parents = ctx.parents() | |
2207 | if keepparent and len(parents) == 2 and pctx in parents: |
|
2207 | if keepparent and len(parents) == 2 and pctx in parents: | |
2208 | parents.remove(pctx) |
|
2208 | parents.remove(pctx) | |
2209 | pother = parents[0].node() |
|
2209 | pother = parents[0].node() | |
2210 |
|
2210 | |||
2211 | with repo.dirstate.parentchange(): |
|
2211 | with repo.dirstate.parentchange(): | |
2212 | repo.setparents(repo['.'].node(), pother) |
|
2212 | repo.setparents(repo['.'].node(), pother) | |
2213 | repo.dirstate.write(repo.currenttransaction()) |
|
2213 | repo.dirstate.write(repo.currenttransaction()) | |
2214 | # fix up dirstate for copies and renames |
|
2214 | # fix up dirstate for copies and renames | |
2215 | copies.duplicatecopies(repo, repo[None], ctx.rev(), pctx.rev()) |
|
2215 | copies.duplicatecopies(repo, repo[None], ctx.rev(), pctx.rev()) | |
2216 | return stats |
|
2216 | return stats |
General Comments 0
You need to be logged in to leave comments.
Login now