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