Show More
@@ -1,1897 +1,1873 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 | from node import hex, nullid, wdirrev, short |
|
7 | from node import hex, nullid, wdirrev, short | |
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import urllib |
|
9 | import urllib | |
10 | import peer, changegroup, subrepo, pushkey, obsolete, repoview |
|
10 | import peer, changegroup, subrepo, pushkey, obsolete, repoview | |
11 | import changelog, dirstate, filelog, manifest, context, bookmarks, phases |
|
11 | import changelog, dirstate, filelog, manifest, context, bookmarks, phases | |
12 | import lock as lockmod |
|
12 | import lock as lockmod | |
13 | import transaction, store, encoding, exchange, bundle2 |
|
13 | import transaction, store, encoding, exchange, bundle2 | |
14 | import scmutil, util, extensions, hook, error, revset |
|
14 | import scmutil, util, extensions, hook, error, revset | |
15 | import match as matchmod |
|
15 | import match as matchmod | |
16 | import merge as mergemod |
|
16 | import merge as mergemod | |
17 | import tags as tagsmod |
|
17 | import tags as tagsmod | |
18 | from lock import release |
|
18 | from lock import release | |
19 | import weakref, errno, os, time, inspect, random |
|
19 | import weakref, errno, os, time, inspect, random | |
20 | import branchmap, pathutil |
|
20 | import branchmap, pathutil | |
21 | import namespaces |
|
21 | import namespaces | |
22 | import streamclone |
|
22 | import streamclone | |
23 | propertycache = util.propertycache |
|
23 | propertycache = util.propertycache | |
24 | filecache = scmutil.filecache |
|
24 | filecache = scmutil.filecache | |
25 |
|
25 | |||
26 | class repofilecache(filecache): |
|
26 | class repofilecache(filecache): | |
27 | """All filecache usage on repo are done for logic that should be unfiltered |
|
27 | """All filecache usage on repo are done for logic that should be unfiltered | |
28 | """ |
|
28 | """ | |
29 |
|
29 | |||
30 | def __get__(self, repo, type=None): |
|
30 | def __get__(self, repo, type=None): | |
31 | return super(repofilecache, self).__get__(repo.unfiltered(), type) |
|
31 | return super(repofilecache, self).__get__(repo.unfiltered(), type) | |
32 | def __set__(self, repo, value): |
|
32 | def __set__(self, repo, value): | |
33 | return super(repofilecache, self).__set__(repo.unfiltered(), value) |
|
33 | return super(repofilecache, self).__set__(repo.unfiltered(), value) | |
34 | def __delete__(self, repo): |
|
34 | def __delete__(self, repo): | |
35 | return super(repofilecache, self).__delete__(repo.unfiltered()) |
|
35 | return super(repofilecache, self).__delete__(repo.unfiltered()) | |
36 |
|
36 | |||
37 | class storecache(repofilecache): |
|
37 | class storecache(repofilecache): | |
38 | """filecache for files in the store""" |
|
38 | """filecache for files in the store""" | |
39 | def join(self, obj, fname): |
|
39 | def join(self, obj, fname): | |
40 | return obj.sjoin(fname) |
|
40 | return obj.sjoin(fname) | |
41 |
|
41 | |||
42 | class unfilteredpropertycache(propertycache): |
|
42 | class unfilteredpropertycache(propertycache): | |
43 | """propertycache that apply to unfiltered repo only""" |
|
43 | """propertycache that apply to unfiltered repo only""" | |
44 |
|
44 | |||
45 | def __get__(self, repo, type=None): |
|
45 | def __get__(self, repo, type=None): | |
46 | unfi = repo.unfiltered() |
|
46 | unfi = repo.unfiltered() | |
47 | if unfi is repo: |
|
47 | if unfi is repo: | |
48 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
48 | return super(unfilteredpropertycache, self).__get__(unfi) | |
49 | return getattr(unfi, self.name) |
|
49 | return getattr(unfi, self.name) | |
50 |
|
50 | |||
51 | class filteredpropertycache(propertycache): |
|
51 | class filteredpropertycache(propertycache): | |
52 | """propertycache that must take filtering in account""" |
|
52 | """propertycache that must take filtering in account""" | |
53 |
|
53 | |||
54 | def cachevalue(self, obj, value): |
|
54 | def cachevalue(self, obj, value): | |
55 | object.__setattr__(obj, self.name, value) |
|
55 | object.__setattr__(obj, self.name, value) | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def hasunfilteredcache(repo, name): |
|
58 | def hasunfilteredcache(repo, name): | |
59 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
59 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
60 | return name in vars(repo.unfiltered()) |
|
60 | return name in vars(repo.unfiltered()) | |
61 |
|
61 | |||
62 | def unfilteredmethod(orig): |
|
62 | def unfilteredmethod(orig): | |
63 | """decorate method that always need to be run on unfiltered version""" |
|
63 | """decorate method that always need to be run on unfiltered version""" | |
64 | def wrapper(repo, *args, **kwargs): |
|
64 | def wrapper(repo, *args, **kwargs): | |
65 | return orig(repo.unfiltered(), *args, **kwargs) |
|
65 | return orig(repo.unfiltered(), *args, **kwargs) | |
66 | return wrapper |
|
66 | return wrapper | |
67 |
|
67 | |||
68 | moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
68 | moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
69 | 'unbundle')) |
|
69 | 'unbundle')) | |
70 | legacycaps = moderncaps.union(set(['changegroupsubset'])) |
|
70 | legacycaps = moderncaps.union(set(['changegroupsubset'])) | |
71 |
|
71 | |||
72 | class localpeer(peer.peerrepository): |
|
72 | class localpeer(peer.peerrepository): | |
73 | '''peer for a local repo; reflects only the most recent API''' |
|
73 | '''peer for a local repo; reflects only the most recent API''' | |
74 |
|
74 | |||
75 | def __init__(self, repo, caps=moderncaps): |
|
75 | def __init__(self, repo, caps=moderncaps): | |
76 | peer.peerrepository.__init__(self) |
|
76 | peer.peerrepository.__init__(self) | |
77 | self._repo = repo.filtered('served') |
|
77 | self._repo = repo.filtered('served') | |
78 | self.ui = repo.ui |
|
78 | self.ui = repo.ui | |
79 | self._caps = repo._restrictcapabilities(caps) |
|
79 | self._caps = repo._restrictcapabilities(caps) | |
80 | self.requirements = repo.requirements |
|
80 | self.requirements = repo.requirements | |
81 | self.supportedformats = repo.supportedformats |
|
81 | self.supportedformats = repo.supportedformats | |
82 |
|
82 | |||
83 | def close(self): |
|
83 | def close(self): | |
84 | self._repo.close() |
|
84 | self._repo.close() | |
85 |
|
85 | |||
86 | def _capabilities(self): |
|
86 | def _capabilities(self): | |
87 | return self._caps |
|
87 | return self._caps | |
88 |
|
88 | |||
89 | def local(self): |
|
89 | def local(self): | |
90 | return self._repo |
|
90 | return self._repo | |
91 |
|
91 | |||
92 | def canpush(self): |
|
92 | def canpush(self): | |
93 | return True |
|
93 | return True | |
94 |
|
94 | |||
95 | def url(self): |
|
95 | def url(self): | |
96 | return self._repo.url() |
|
96 | return self._repo.url() | |
97 |
|
97 | |||
98 | def lookup(self, key): |
|
98 | def lookup(self, key): | |
99 | return self._repo.lookup(key) |
|
99 | return self._repo.lookup(key) | |
100 |
|
100 | |||
101 | def branchmap(self): |
|
101 | def branchmap(self): | |
102 | return self._repo.branchmap() |
|
102 | return self._repo.branchmap() | |
103 |
|
103 | |||
104 | def heads(self): |
|
104 | def heads(self): | |
105 | return self._repo.heads() |
|
105 | return self._repo.heads() | |
106 |
|
106 | |||
107 | def known(self, nodes): |
|
107 | def known(self, nodes): | |
108 | return self._repo.known(nodes) |
|
108 | return self._repo.known(nodes) | |
109 |
|
109 | |||
110 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
110 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
111 | **kwargs): |
|
111 | **kwargs): | |
112 | cg = exchange.getbundle(self._repo, source, heads=heads, |
|
112 | cg = exchange.getbundle(self._repo, source, heads=heads, | |
113 | common=common, bundlecaps=bundlecaps, **kwargs) |
|
113 | common=common, bundlecaps=bundlecaps, **kwargs) | |
114 | if bundlecaps is not None and 'HG20' in bundlecaps: |
|
114 | if bundlecaps is not None and 'HG20' in bundlecaps: | |
115 | # When requesting a bundle2, getbundle returns a stream to make the |
|
115 | # When requesting a bundle2, getbundle returns a stream to make the | |
116 | # wire level function happier. We need to build a proper object |
|
116 | # wire level function happier. We need to build a proper object | |
117 | # from it in local peer. |
|
117 | # from it in local peer. | |
118 | cg = bundle2.getunbundler(self.ui, cg) |
|
118 | cg = bundle2.getunbundler(self.ui, cg) | |
119 | return cg |
|
119 | return cg | |
120 |
|
120 | |||
121 | # TODO We might want to move the next two calls into legacypeer and add |
|
121 | # TODO We might want to move the next two calls into legacypeer and add | |
122 | # unbundle instead. |
|
122 | # unbundle instead. | |
123 |
|
123 | |||
124 | def unbundle(self, cg, heads, url): |
|
124 | def unbundle(self, cg, heads, url): | |
125 | """apply a bundle on a repo |
|
125 | """apply a bundle on a repo | |
126 |
|
126 | |||
127 | This function handles the repo locking itself.""" |
|
127 | This function handles the repo locking itself.""" | |
128 | try: |
|
128 | try: | |
129 | try: |
|
129 | try: | |
130 | cg = exchange.readbundle(self.ui, cg, None) |
|
130 | cg = exchange.readbundle(self.ui, cg, None) | |
131 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
131 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) | |
132 | if util.safehasattr(ret, 'getchunks'): |
|
132 | if util.safehasattr(ret, 'getchunks'): | |
133 | # This is a bundle20 object, turn it into an unbundler. |
|
133 | # This is a bundle20 object, turn it into an unbundler. | |
134 | # This little dance should be dropped eventually when the |
|
134 | # This little dance should be dropped eventually when the | |
135 | # API is finally improved. |
|
135 | # API is finally improved. | |
136 | stream = util.chunkbuffer(ret.getchunks()) |
|
136 | stream = util.chunkbuffer(ret.getchunks()) | |
137 | ret = bundle2.getunbundler(self.ui, stream) |
|
137 | ret = bundle2.getunbundler(self.ui, stream) | |
138 | return ret |
|
138 | return ret | |
139 | except Exception as exc: |
|
139 | except Exception as exc: | |
140 | # If the exception contains output salvaged from a bundle2 |
|
140 | # If the exception contains output salvaged from a bundle2 | |
141 | # reply, we need to make sure it is printed before continuing |
|
141 | # reply, we need to make sure it is printed before continuing | |
142 | # to fail. So we build a bundle2 with such output and consume |
|
142 | # to fail. So we build a bundle2 with such output and consume | |
143 | # it directly. |
|
143 | # it directly. | |
144 | # |
|
144 | # | |
145 | # This is not very elegant but allows a "simple" solution for |
|
145 | # This is not very elegant but allows a "simple" solution for | |
146 | # issue4594 |
|
146 | # issue4594 | |
147 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
147 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
148 | if output: |
|
148 | if output: | |
149 | bundler = bundle2.bundle20(self._repo.ui) |
|
149 | bundler = bundle2.bundle20(self._repo.ui) | |
150 | for out in output: |
|
150 | for out in output: | |
151 | bundler.addpart(out) |
|
151 | bundler.addpart(out) | |
152 | stream = util.chunkbuffer(bundler.getchunks()) |
|
152 | stream = util.chunkbuffer(bundler.getchunks()) | |
153 | b = bundle2.getunbundler(self.ui, stream) |
|
153 | b = bundle2.getunbundler(self.ui, stream) | |
154 | bundle2.processbundle(self._repo, b) |
|
154 | bundle2.processbundle(self._repo, b) | |
155 | raise |
|
155 | raise | |
156 | except error.PushRaced as exc: |
|
156 | except error.PushRaced as exc: | |
157 | raise error.ResponseError(_('push failed:'), str(exc)) |
|
157 | raise error.ResponseError(_('push failed:'), str(exc)) | |
158 |
|
158 | |||
159 | def lock(self): |
|
159 | def lock(self): | |
160 | return self._repo.lock() |
|
160 | return self._repo.lock() | |
161 |
|
161 | |||
162 | def addchangegroup(self, cg, source, url): |
|
162 | def addchangegroup(self, cg, source, url): | |
163 | return changegroup.addchangegroup(self._repo, cg, source, url) |
|
163 | return changegroup.addchangegroup(self._repo, cg, source, url) | |
164 |
|
164 | |||
165 | def pushkey(self, namespace, key, old, new): |
|
165 | def pushkey(self, namespace, key, old, new): | |
166 | return self._repo.pushkey(namespace, key, old, new) |
|
166 | return self._repo.pushkey(namespace, key, old, new) | |
167 |
|
167 | |||
168 | def listkeys(self, namespace): |
|
168 | def listkeys(self, namespace): | |
169 | return self._repo.listkeys(namespace) |
|
169 | return self._repo.listkeys(namespace) | |
170 |
|
170 | |||
171 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
171 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
172 | '''used to test argument passing over the wire''' |
|
172 | '''used to test argument passing over the wire''' | |
173 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
173 | return "%s %s %s %s %s" % (one, two, three, four, five) | |
174 |
|
174 | |||
175 | class locallegacypeer(localpeer): |
|
175 | class locallegacypeer(localpeer): | |
176 | '''peer extension which implements legacy methods too; used for tests with |
|
176 | '''peer extension which implements legacy methods too; used for tests with | |
177 | restricted capabilities''' |
|
177 | restricted capabilities''' | |
178 |
|
178 | |||
179 | def __init__(self, repo): |
|
179 | def __init__(self, repo): | |
180 | localpeer.__init__(self, repo, caps=legacycaps) |
|
180 | localpeer.__init__(self, repo, caps=legacycaps) | |
181 |
|
181 | |||
182 | def branches(self, nodes): |
|
182 | def branches(self, nodes): | |
183 | return self._repo.branches(nodes) |
|
183 | return self._repo.branches(nodes) | |
184 |
|
184 | |||
185 | def between(self, pairs): |
|
185 | def between(self, pairs): | |
186 | return self._repo.between(pairs) |
|
186 | return self._repo.between(pairs) | |
187 |
|
187 | |||
188 | def changegroup(self, basenodes, source): |
|
188 | def changegroup(self, basenodes, source): | |
189 | return changegroup.changegroup(self._repo, basenodes, source) |
|
189 | return changegroup.changegroup(self._repo, basenodes, source) | |
190 |
|
190 | |||
191 | def changegroupsubset(self, bases, heads, source): |
|
191 | def changegroupsubset(self, bases, heads, source): | |
192 | return changegroup.changegroupsubset(self._repo, bases, heads, source) |
|
192 | return changegroup.changegroupsubset(self._repo, bases, heads, source) | |
193 |
|
193 | |||
194 | class localrepository(object): |
|
194 | class localrepository(object): | |
195 |
|
195 | |||
196 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', |
|
196 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', | |
197 | 'manifestv2')) |
|
197 | 'manifestv2')) | |
198 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', |
|
198 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', | |
199 | 'dotencode')) |
|
199 | 'dotencode')) | |
200 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) |
|
200 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) | |
201 | filtername = None |
|
201 | filtername = None | |
202 |
|
202 | |||
203 | # a list of (ui, featureset) functions. |
|
203 | # a list of (ui, featureset) functions. | |
204 | # only functions defined in module of enabled extensions are invoked |
|
204 | # only functions defined in module of enabled extensions are invoked | |
205 | featuresetupfuncs = set() |
|
205 | featuresetupfuncs = set() | |
206 |
|
206 | |||
207 | def _baserequirements(self, create): |
|
207 | def _baserequirements(self, create): | |
208 | return ['revlogv1'] |
|
208 | return ['revlogv1'] | |
209 |
|
209 | |||
210 | def __init__(self, baseui, path=None, create=False): |
|
210 | def __init__(self, baseui, path=None, create=False): | |
211 | self.requirements = set() |
|
211 | self.requirements = set() | |
212 | self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True) |
|
212 | self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True) | |
213 | self.wopener = self.wvfs |
|
213 | self.wopener = self.wvfs | |
214 | self.root = self.wvfs.base |
|
214 | self.root = self.wvfs.base | |
215 | self.path = self.wvfs.join(".hg") |
|
215 | self.path = self.wvfs.join(".hg") | |
216 | self.origroot = path |
|
216 | self.origroot = path | |
217 | self.auditor = pathutil.pathauditor(self.root, self._checknested) |
|
217 | self.auditor = pathutil.pathauditor(self.root, self._checknested) | |
218 | self.vfs = scmutil.vfs(self.path) |
|
218 | self.vfs = scmutil.vfs(self.path) | |
219 | self.opener = self.vfs |
|
219 | self.opener = self.vfs | |
220 | self.baseui = baseui |
|
220 | self.baseui = baseui | |
221 | self.ui = baseui.copy() |
|
221 | self.ui = baseui.copy() | |
222 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
222 | self.ui.copy = baseui.copy # prevent copying repo configuration | |
223 | # A list of callback to shape the phase if no data were found. |
|
223 | # A list of callback to shape the phase if no data were found. | |
224 | # Callback are in the form: func(repo, roots) --> processed root. |
|
224 | # Callback are in the form: func(repo, roots) --> processed root. | |
225 | # This list it to be filled by extension during repo setup |
|
225 | # This list it to be filled by extension during repo setup | |
226 | self._phasedefaults = [] |
|
226 | self._phasedefaults = [] | |
227 | try: |
|
227 | try: | |
228 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
228 | self.ui.readconfig(self.join("hgrc"), self.root) | |
229 | extensions.loadall(self.ui) |
|
229 | extensions.loadall(self.ui) | |
230 | except IOError: |
|
230 | except IOError: | |
231 | pass |
|
231 | pass | |
232 |
|
232 | |||
233 | if self.featuresetupfuncs: |
|
233 | if self.featuresetupfuncs: | |
234 | self.supported = set(self._basesupported) # use private copy |
|
234 | self.supported = set(self._basesupported) # use private copy | |
235 | extmods = set(m.__name__ for n, m |
|
235 | extmods = set(m.__name__ for n, m | |
236 | in extensions.extensions(self.ui)) |
|
236 | in extensions.extensions(self.ui)) | |
237 | for setupfunc in self.featuresetupfuncs: |
|
237 | for setupfunc in self.featuresetupfuncs: | |
238 | if setupfunc.__module__ in extmods: |
|
238 | if setupfunc.__module__ in extmods: | |
239 | setupfunc(self.ui, self.supported) |
|
239 | setupfunc(self.ui, self.supported) | |
240 | else: |
|
240 | else: | |
241 | self.supported = self._basesupported |
|
241 | self.supported = self._basesupported | |
242 |
|
242 | |||
243 | if not self.vfs.isdir(): |
|
243 | if not self.vfs.isdir(): | |
244 | if create: |
|
244 | if create: | |
245 | if not self.wvfs.exists(): |
|
245 | if not self.wvfs.exists(): | |
246 | self.wvfs.makedirs() |
|
246 | self.wvfs.makedirs() | |
247 | self.vfs.makedir(notindexed=True) |
|
247 | self.vfs.makedir(notindexed=True) | |
248 | self.requirements.update(self._baserequirements(create)) |
|
248 | self.requirements.update(self._baserequirements(create)) | |
249 | if self.ui.configbool('format', 'usestore', True): |
|
249 | if self.ui.configbool('format', 'usestore', True): | |
250 | self.vfs.mkdir("store") |
|
250 | self.vfs.mkdir("store") | |
251 | self.requirements.add("store") |
|
251 | self.requirements.add("store") | |
252 | if self.ui.configbool('format', 'usefncache', True): |
|
252 | if self.ui.configbool('format', 'usefncache', True): | |
253 | self.requirements.add("fncache") |
|
253 | self.requirements.add("fncache") | |
254 | if self.ui.configbool('format', 'dotencode', True): |
|
254 | if self.ui.configbool('format', 'dotencode', True): | |
255 | self.requirements.add('dotencode') |
|
255 | self.requirements.add('dotencode') | |
256 | # create an invalid changelog |
|
256 | # create an invalid changelog | |
257 | self.vfs.append( |
|
257 | self.vfs.append( | |
258 | "00changelog.i", |
|
258 | "00changelog.i", | |
259 | '\0\0\0\2' # represents revlogv2 |
|
259 | '\0\0\0\2' # represents revlogv2 | |
260 | ' dummy changelog to prevent using the old repo layout' |
|
260 | ' dummy changelog to prevent using the old repo layout' | |
261 | ) |
|
261 | ) | |
262 | # experimental config: format.generaldelta |
|
262 | # experimental config: format.generaldelta | |
263 | if self.ui.configbool('format', 'generaldelta', False): |
|
263 | if self.ui.configbool('format', 'generaldelta', False): | |
264 | self.requirements.add("generaldelta") |
|
264 | self.requirements.add("generaldelta") | |
265 | if self.ui.configbool('experimental', 'treemanifest', False): |
|
265 | if self.ui.configbool('experimental', 'treemanifest', False): | |
266 | self.requirements.add("treemanifest") |
|
266 | self.requirements.add("treemanifest") | |
267 | if self.ui.configbool('experimental', 'manifestv2', False): |
|
267 | if self.ui.configbool('experimental', 'manifestv2', False): | |
268 | self.requirements.add("manifestv2") |
|
268 | self.requirements.add("manifestv2") | |
269 | else: |
|
269 | else: | |
270 | raise error.RepoError(_("repository %s not found") % path) |
|
270 | raise error.RepoError(_("repository %s not found") % path) | |
271 | elif create: |
|
271 | elif create: | |
272 | raise error.RepoError(_("repository %s already exists") % path) |
|
272 | raise error.RepoError(_("repository %s already exists") % path) | |
273 | else: |
|
273 | else: | |
274 | try: |
|
274 | try: | |
275 | self.requirements = scmutil.readrequires( |
|
275 | self.requirements = scmutil.readrequires( | |
276 | self.vfs, self.supported) |
|
276 | self.vfs, self.supported) | |
277 | except IOError as inst: |
|
277 | except IOError as inst: | |
278 | if inst.errno != errno.ENOENT: |
|
278 | if inst.errno != errno.ENOENT: | |
279 | raise |
|
279 | raise | |
280 |
|
280 | |||
281 | self.sharedpath = self.path |
|
281 | self.sharedpath = self.path | |
282 | try: |
|
282 | try: | |
283 | vfs = scmutil.vfs(self.vfs.read("sharedpath").rstrip('\n'), |
|
283 | vfs = scmutil.vfs(self.vfs.read("sharedpath").rstrip('\n'), | |
284 | realpath=True) |
|
284 | realpath=True) | |
285 | s = vfs.base |
|
285 | s = vfs.base | |
286 | if not vfs.exists(): |
|
286 | if not vfs.exists(): | |
287 | raise error.RepoError( |
|
287 | raise error.RepoError( | |
288 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
288 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
289 | self.sharedpath = s |
|
289 | self.sharedpath = s | |
290 | except IOError as inst: |
|
290 | except IOError as inst: | |
291 | if inst.errno != errno.ENOENT: |
|
291 | if inst.errno != errno.ENOENT: | |
292 | raise |
|
292 | raise | |
293 |
|
293 | |||
294 | self.store = store.store( |
|
294 | self.store = store.store( | |
295 | self.requirements, self.sharedpath, scmutil.vfs) |
|
295 | self.requirements, self.sharedpath, scmutil.vfs) | |
296 | self.spath = self.store.path |
|
296 | self.spath = self.store.path | |
297 | self.svfs = self.store.vfs |
|
297 | self.svfs = self.store.vfs | |
298 | self.sjoin = self.store.join |
|
298 | self.sjoin = self.store.join | |
299 | self.vfs.createmode = self.store.createmode |
|
299 | self.vfs.createmode = self.store.createmode | |
300 | self._applyopenerreqs() |
|
300 | self._applyopenerreqs() | |
301 | if create: |
|
301 | if create: | |
302 | self._writerequirements() |
|
302 | self._writerequirements() | |
303 |
|
303 | |||
304 | self._dirstatevalidatewarned = False |
|
304 | self._dirstatevalidatewarned = False | |
305 |
|
305 | |||
306 | self._branchcaches = {} |
|
306 | self._branchcaches = {} | |
307 | self._revbranchcache = None |
|
307 | self._revbranchcache = None | |
308 | self.filterpats = {} |
|
308 | self.filterpats = {} | |
309 | self._datafilters = {} |
|
309 | self._datafilters = {} | |
310 | self._transref = self._lockref = self._wlockref = None |
|
310 | self._transref = self._lockref = self._wlockref = None | |
311 |
|
311 | |||
312 | # A cache for various files under .hg/ that tracks file changes, |
|
312 | # A cache for various files under .hg/ that tracks file changes, | |
313 | # (used by the filecache decorator) |
|
313 | # (used by the filecache decorator) | |
314 | # |
|
314 | # | |
315 | # Maps a property name to its util.filecacheentry |
|
315 | # Maps a property name to its util.filecacheentry | |
316 | self._filecache = {} |
|
316 | self._filecache = {} | |
317 |
|
317 | |||
318 | # hold sets of revision to be filtered |
|
318 | # hold sets of revision to be filtered | |
319 | # should be cleared when something might have changed the filter value: |
|
319 | # should be cleared when something might have changed the filter value: | |
320 | # - new changesets, |
|
320 | # - new changesets, | |
321 | # - phase change, |
|
321 | # - phase change, | |
322 | # - new obsolescence marker, |
|
322 | # - new obsolescence marker, | |
323 | # - working directory parent change, |
|
323 | # - working directory parent change, | |
324 | # - bookmark changes |
|
324 | # - bookmark changes | |
325 | self.filteredrevcache = {} |
|
325 | self.filteredrevcache = {} | |
326 |
|
326 | |||
327 | # generic mapping between names and nodes |
|
327 | # generic mapping between names and nodes | |
328 | self.names = namespaces.namespaces() |
|
328 | self.names = namespaces.namespaces() | |
329 |
|
329 | |||
330 | def close(self): |
|
330 | def close(self): | |
331 | self._writecaches() |
|
331 | self._writecaches() | |
332 |
|
332 | |||
333 | def _writecaches(self): |
|
333 | def _writecaches(self): | |
334 | if self._revbranchcache: |
|
334 | if self._revbranchcache: | |
335 | self._revbranchcache.write() |
|
335 | self._revbranchcache.write() | |
336 |
|
336 | |||
337 | def _restrictcapabilities(self, caps): |
|
337 | def _restrictcapabilities(self, caps): | |
338 | if self.ui.configbool('experimental', 'bundle2-advertise', True): |
|
338 | if self.ui.configbool('experimental', 'bundle2-advertise', True): | |
339 | caps = set(caps) |
|
339 | caps = set(caps) | |
340 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self)) |
|
340 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self)) | |
341 | caps.add('bundle2=' + urllib.quote(capsblob)) |
|
341 | caps.add('bundle2=' + urllib.quote(capsblob)) | |
342 | return caps |
|
342 | return caps | |
343 |
|
343 | |||
344 | def _applyopenerreqs(self): |
|
344 | def _applyopenerreqs(self): | |
345 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
345 | self.svfs.options = dict((r, 1) for r in self.requirements | |
346 | if r in self.openerreqs) |
|
346 | if r in self.openerreqs) | |
347 | # experimental config: format.chunkcachesize |
|
347 | # experimental config: format.chunkcachesize | |
348 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
348 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') | |
349 | if chunkcachesize is not None: |
|
349 | if chunkcachesize is not None: | |
350 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
350 | self.svfs.options['chunkcachesize'] = chunkcachesize | |
351 | # experimental config: format.maxchainlen |
|
351 | # experimental config: format.maxchainlen | |
352 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
352 | maxchainlen = self.ui.configint('format', 'maxchainlen') | |
353 | if maxchainlen is not None: |
|
353 | if maxchainlen is not None: | |
354 | self.svfs.options['maxchainlen'] = maxchainlen |
|
354 | self.svfs.options['maxchainlen'] = maxchainlen | |
355 | # experimental config: format.manifestcachesize |
|
355 | # experimental config: format.manifestcachesize | |
356 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
356 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') | |
357 | if manifestcachesize is not None: |
|
357 | if manifestcachesize is not None: | |
358 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
358 | self.svfs.options['manifestcachesize'] = manifestcachesize | |
359 | # experimental config: format.aggressivemergedeltas |
|
359 | # experimental config: format.aggressivemergedeltas | |
360 | aggressivemergedeltas = self.ui.configbool('format', |
|
360 | aggressivemergedeltas = self.ui.configbool('format', | |
361 | 'aggressivemergedeltas', False) |
|
361 | 'aggressivemergedeltas', False) | |
362 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
362 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas | |
363 |
|
363 | |||
364 | def _writerequirements(self): |
|
364 | def _writerequirements(self): | |
365 | scmutil.writerequires(self.vfs, self.requirements) |
|
365 | scmutil.writerequires(self.vfs, self.requirements) | |
366 |
|
366 | |||
367 | def _checknested(self, path): |
|
367 | def _checknested(self, path): | |
368 | """Determine if path is a legal nested repository.""" |
|
368 | """Determine if path is a legal nested repository.""" | |
369 | if not path.startswith(self.root): |
|
369 | if not path.startswith(self.root): | |
370 | return False |
|
370 | return False | |
371 | subpath = path[len(self.root) + 1:] |
|
371 | subpath = path[len(self.root) + 1:] | |
372 | normsubpath = util.pconvert(subpath) |
|
372 | normsubpath = util.pconvert(subpath) | |
373 |
|
373 | |||
374 | # XXX: Checking against the current working copy is wrong in |
|
374 | # XXX: Checking against the current working copy is wrong in | |
375 | # the sense that it can reject things like |
|
375 | # the sense that it can reject things like | |
376 | # |
|
376 | # | |
377 | # $ hg cat -r 10 sub/x.txt |
|
377 | # $ hg cat -r 10 sub/x.txt | |
378 | # |
|
378 | # | |
379 | # if sub/ is no longer a subrepository in the working copy |
|
379 | # if sub/ is no longer a subrepository in the working copy | |
380 | # parent revision. |
|
380 | # parent revision. | |
381 | # |
|
381 | # | |
382 | # However, it can of course also allow things that would have |
|
382 | # However, it can of course also allow things that would have | |
383 | # been rejected before, such as the above cat command if sub/ |
|
383 | # been rejected before, such as the above cat command if sub/ | |
384 | # is a subrepository now, but was a normal directory before. |
|
384 | # is a subrepository now, but was a normal directory before. | |
385 | # The old path auditor would have rejected by mistake since it |
|
385 | # The old path auditor would have rejected by mistake since it | |
386 | # panics when it sees sub/.hg/. |
|
386 | # panics when it sees sub/.hg/. | |
387 | # |
|
387 | # | |
388 | # All in all, checking against the working copy seems sensible |
|
388 | # All in all, checking against the working copy seems sensible | |
389 | # since we want to prevent access to nested repositories on |
|
389 | # since we want to prevent access to nested repositories on | |
390 | # the filesystem *now*. |
|
390 | # the filesystem *now*. | |
391 | ctx = self[None] |
|
391 | ctx = self[None] | |
392 | parts = util.splitpath(subpath) |
|
392 | parts = util.splitpath(subpath) | |
393 | while parts: |
|
393 | while parts: | |
394 | prefix = '/'.join(parts) |
|
394 | prefix = '/'.join(parts) | |
395 | if prefix in ctx.substate: |
|
395 | if prefix in ctx.substate: | |
396 | if prefix == normsubpath: |
|
396 | if prefix == normsubpath: | |
397 | return True |
|
397 | return True | |
398 | else: |
|
398 | else: | |
399 | sub = ctx.sub(prefix) |
|
399 | sub = ctx.sub(prefix) | |
400 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
400 | return sub.checknested(subpath[len(prefix) + 1:]) | |
401 | else: |
|
401 | else: | |
402 | parts.pop() |
|
402 | parts.pop() | |
403 | return False |
|
403 | return False | |
404 |
|
404 | |||
405 | def peer(self): |
|
405 | def peer(self): | |
406 | return localpeer(self) # not cached to avoid reference cycle |
|
406 | return localpeer(self) # not cached to avoid reference cycle | |
407 |
|
407 | |||
408 | def unfiltered(self): |
|
408 | def unfiltered(self): | |
409 | """Return unfiltered version of the repository |
|
409 | """Return unfiltered version of the repository | |
410 |
|
410 | |||
411 | Intended to be overwritten by filtered repo.""" |
|
411 | Intended to be overwritten by filtered repo.""" | |
412 | return self |
|
412 | return self | |
413 |
|
413 | |||
414 | def filtered(self, name): |
|
414 | def filtered(self, name): | |
415 | """Return a filtered version of a repository""" |
|
415 | """Return a filtered version of a repository""" | |
416 | # build a new class with the mixin and the current class |
|
416 | # build a new class with the mixin and the current class | |
417 | # (possibly subclass of the repo) |
|
417 | # (possibly subclass of the repo) | |
418 | class proxycls(repoview.repoview, self.unfiltered().__class__): |
|
418 | class proxycls(repoview.repoview, self.unfiltered().__class__): | |
419 | pass |
|
419 | pass | |
420 | return proxycls(self, name) |
|
420 | return proxycls(self, name) | |
421 |
|
421 | |||
422 | @repofilecache('bookmarks') |
|
422 | @repofilecache('bookmarks') | |
423 | def _bookmarks(self): |
|
423 | def _bookmarks(self): | |
424 | return bookmarks.bmstore(self) |
|
424 | return bookmarks.bmstore(self) | |
425 |
|
425 | |||
426 | @repofilecache('bookmarks.current') |
|
426 | @repofilecache('bookmarks.current') | |
427 | def _activebookmark(self): |
|
427 | def _activebookmark(self): | |
428 | return bookmarks.readactive(self) |
|
428 | return bookmarks.readactive(self) | |
429 |
|
429 | |||
430 | def bookmarkheads(self, bookmark): |
|
430 | def bookmarkheads(self, bookmark): | |
431 | name = bookmark.split('@', 1)[0] |
|
431 | name = bookmark.split('@', 1)[0] | |
432 | heads = [] |
|
432 | heads = [] | |
433 | for mark, n in self._bookmarks.iteritems(): |
|
433 | for mark, n in self._bookmarks.iteritems(): | |
434 | if mark.split('@', 1)[0] == name: |
|
434 | if mark.split('@', 1)[0] == name: | |
435 | heads.append(n) |
|
435 | heads.append(n) | |
436 | return heads |
|
436 | return heads | |
437 |
|
437 | |||
438 | # _phaserevs and _phasesets depend on changelog. what we need is to |
|
438 | # _phaserevs and _phasesets depend on changelog. what we need is to | |
439 | # call _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
439 | # call _phasecache.invalidate() if '00changelog.i' was changed, but it | |
440 | # can't be easily expressed in filecache mechanism. |
|
440 | # can't be easily expressed in filecache mechanism. | |
441 | @storecache('phaseroots', '00changelog.i') |
|
441 | @storecache('phaseroots', '00changelog.i') | |
442 | def _phasecache(self): |
|
442 | def _phasecache(self): | |
443 | return phases.phasecache(self, self._phasedefaults) |
|
443 | return phases.phasecache(self, self._phasedefaults) | |
444 |
|
444 | |||
445 | @storecache('obsstore') |
|
445 | @storecache('obsstore') | |
446 | def obsstore(self): |
|
446 | def obsstore(self): | |
447 | # read default format for new obsstore. |
|
447 | # read default format for new obsstore. | |
448 | # developer config: format.obsstore-version |
|
448 | # developer config: format.obsstore-version | |
449 | defaultformat = self.ui.configint('format', 'obsstore-version', None) |
|
449 | defaultformat = self.ui.configint('format', 'obsstore-version', None) | |
450 | # rely on obsstore class default when possible. |
|
450 | # rely on obsstore class default when possible. | |
451 | kwargs = {} |
|
451 | kwargs = {} | |
452 | if defaultformat is not None: |
|
452 | if defaultformat is not None: | |
453 | kwargs['defaultformat'] = defaultformat |
|
453 | kwargs['defaultformat'] = defaultformat | |
454 | readonly = not obsolete.isenabled(self, obsolete.createmarkersopt) |
|
454 | readonly = not obsolete.isenabled(self, obsolete.createmarkersopt) | |
455 | store = obsolete.obsstore(self.svfs, readonly=readonly, |
|
455 | store = obsolete.obsstore(self.svfs, readonly=readonly, | |
456 | **kwargs) |
|
456 | **kwargs) | |
457 | if store and readonly: |
|
457 | if store and readonly: | |
458 | self.ui.warn( |
|
458 | self.ui.warn( | |
459 | _('obsolete feature not enabled but %i markers found!\n') |
|
459 | _('obsolete feature not enabled but %i markers found!\n') | |
460 | % len(list(store))) |
|
460 | % len(list(store))) | |
461 | return store |
|
461 | return store | |
462 |
|
462 | |||
463 | @storecache('00changelog.i') |
|
463 | @storecache('00changelog.i') | |
464 | def changelog(self): |
|
464 | def changelog(self): | |
465 | c = changelog.changelog(self.svfs) |
|
465 | c = changelog.changelog(self.svfs) | |
466 | if 'HG_PENDING' in os.environ: |
|
466 | if 'HG_PENDING' in os.environ: | |
467 | p = os.environ['HG_PENDING'] |
|
467 | p = os.environ['HG_PENDING'] | |
468 | if p.startswith(self.root): |
|
468 | if p.startswith(self.root): | |
469 | c.readpending('00changelog.i.a') |
|
469 | c.readpending('00changelog.i.a') | |
470 | return c |
|
470 | return c | |
471 |
|
471 | |||
472 | @storecache('00manifest.i') |
|
472 | @storecache('00manifest.i') | |
473 | def manifest(self): |
|
473 | def manifest(self): | |
474 | return manifest.manifest(self.svfs) |
|
474 | return manifest.manifest(self.svfs) | |
475 |
|
475 | |||
476 | def dirlog(self, dir): |
|
476 | def dirlog(self, dir): | |
477 | return self.manifest.dirlog(dir) |
|
477 | return self.manifest.dirlog(dir) | |
478 |
|
478 | |||
479 | @repofilecache('dirstate') |
|
479 | @repofilecache('dirstate') | |
480 | def dirstate(self): |
|
480 | def dirstate(self): | |
481 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
481 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
482 | self._dirstatevalidate) |
|
482 | self._dirstatevalidate) | |
483 |
|
483 | |||
484 | def _dirstatevalidate(self, node): |
|
484 | def _dirstatevalidate(self, node): | |
485 | try: |
|
485 | try: | |
486 | self.changelog.rev(node) |
|
486 | self.changelog.rev(node) | |
487 | return node |
|
487 | return node | |
488 | except error.LookupError: |
|
488 | except error.LookupError: | |
489 | if not self._dirstatevalidatewarned: |
|
489 | if not self._dirstatevalidatewarned: | |
490 | self._dirstatevalidatewarned = True |
|
490 | self._dirstatevalidatewarned = True | |
491 | self.ui.warn(_("warning: ignoring unknown" |
|
491 | self.ui.warn(_("warning: ignoring unknown" | |
492 | " working parent %s!\n") % short(node)) |
|
492 | " working parent %s!\n") % short(node)) | |
493 | return nullid |
|
493 | return nullid | |
494 |
|
494 | |||
495 | def __getitem__(self, changeid): |
|
495 | def __getitem__(self, changeid): | |
496 | if changeid is None or changeid == wdirrev: |
|
496 | if changeid is None or changeid == wdirrev: | |
497 | return context.workingctx(self) |
|
497 | return context.workingctx(self) | |
498 | if isinstance(changeid, slice): |
|
498 | if isinstance(changeid, slice): | |
499 | return [context.changectx(self, i) |
|
499 | return [context.changectx(self, i) | |
500 | for i in xrange(*changeid.indices(len(self))) |
|
500 | for i in xrange(*changeid.indices(len(self))) | |
501 | if i not in self.changelog.filteredrevs] |
|
501 | if i not in self.changelog.filteredrevs] | |
502 | return context.changectx(self, changeid) |
|
502 | return context.changectx(self, changeid) | |
503 |
|
503 | |||
504 | def __contains__(self, changeid): |
|
504 | def __contains__(self, changeid): | |
505 | try: |
|
505 | try: | |
506 | self[changeid] |
|
506 | self[changeid] | |
507 | return True |
|
507 | return True | |
508 | except error.RepoLookupError: |
|
508 | except error.RepoLookupError: | |
509 | return False |
|
509 | return False | |
510 |
|
510 | |||
511 | def __nonzero__(self): |
|
511 | def __nonzero__(self): | |
512 | return True |
|
512 | return True | |
513 |
|
513 | |||
514 | def __len__(self): |
|
514 | def __len__(self): | |
515 | return len(self.changelog) |
|
515 | return len(self.changelog) | |
516 |
|
516 | |||
517 | def __iter__(self): |
|
517 | def __iter__(self): | |
518 | return iter(self.changelog) |
|
518 | return iter(self.changelog) | |
519 |
|
519 | |||
520 | def revs(self, expr, *args): |
|
520 | def revs(self, expr, *args): | |
521 | '''Return a list of revisions matching the given revset''' |
|
521 | '''Return a list of revisions matching the given revset''' | |
522 | expr = revset.formatspec(expr, *args) |
|
522 | expr = revset.formatspec(expr, *args) | |
523 | m = revset.match(None, expr) |
|
523 | m = revset.match(None, expr) | |
524 | return m(self) |
|
524 | return m(self) | |
525 |
|
525 | |||
526 | def set(self, expr, *args): |
|
526 | def set(self, expr, *args): | |
527 | ''' |
|
527 | ''' | |
528 | Yield a context for each matching revision, after doing arg |
|
528 | Yield a context for each matching revision, after doing arg | |
529 | replacement via revset.formatspec |
|
529 | replacement via revset.formatspec | |
530 | ''' |
|
530 | ''' | |
531 | for r in self.revs(expr, *args): |
|
531 | for r in self.revs(expr, *args): | |
532 | yield self[r] |
|
532 | yield self[r] | |
533 |
|
533 | |||
534 | def url(self): |
|
534 | def url(self): | |
535 | return 'file:' + self.root |
|
535 | return 'file:' + self.root | |
536 |
|
536 | |||
537 | def hook(self, name, throw=False, **args): |
|
537 | def hook(self, name, throw=False, **args): | |
538 | """Call a hook, passing this repo instance. |
|
538 | """Call a hook, passing this repo instance. | |
539 |
|
539 | |||
540 | This a convenience method to aid invoking hooks. Extensions likely |
|
540 | This a convenience method to aid invoking hooks. Extensions likely | |
541 | won't call this unless they have registered a custom hook or are |
|
541 | won't call this unless they have registered a custom hook or are | |
542 | replacing code that is expected to call a hook. |
|
542 | replacing code that is expected to call a hook. | |
543 | """ |
|
543 | """ | |
544 | return hook.hook(self.ui, self, name, throw, **args) |
|
544 | return hook.hook(self.ui, self, name, throw, **args) | |
545 |
|
545 | |||
546 | @unfilteredmethod |
|
546 | @unfilteredmethod | |
547 | def _tag(self, names, node, message, local, user, date, extra=None, |
|
547 | def _tag(self, names, node, message, local, user, date, extra=None, | |
548 | editor=False): |
|
548 | editor=False): | |
549 | if isinstance(names, str): |
|
549 | if isinstance(names, str): | |
550 | names = (names,) |
|
550 | names = (names,) | |
551 |
|
551 | |||
552 | branches = self.branchmap() |
|
552 | branches = self.branchmap() | |
553 | for name in names: |
|
553 | for name in names: | |
554 | self.hook('pretag', throw=True, node=hex(node), tag=name, |
|
554 | self.hook('pretag', throw=True, node=hex(node), tag=name, | |
555 | local=local) |
|
555 | local=local) | |
556 | if name in branches: |
|
556 | if name in branches: | |
557 | self.ui.warn(_("warning: tag %s conflicts with existing" |
|
557 | self.ui.warn(_("warning: tag %s conflicts with existing" | |
558 | " branch name\n") % name) |
|
558 | " branch name\n") % name) | |
559 |
|
559 | |||
560 | def writetags(fp, names, munge, prevtags): |
|
560 | def writetags(fp, names, munge, prevtags): | |
561 | fp.seek(0, 2) |
|
561 | fp.seek(0, 2) | |
562 | if prevtags and prevtags[-1] != '\n': |
|
562 | if prevtags and prevtags[-1] != '\n': | |
563 | fp.write('\n') |
|
563 | fp.write('\n') | |
564 | for name in names: |
|
564 | for name in names: | |
565 | if munge: |
|
565 | if munge: | |
566 | m = munge(name) |
|
566 | m = munge(name) | |
567 | else: |
|
567 | else: | |
568 | m = name |
|
568 | m = name | |
569 |
|
569 | |||
570 | if (self._tagscache.tagtypes and |
|
570 | if (self._tagscache.tagtypes and | |
571 | name in self._tagscache.tagtypes): |
|
571 | name in self._tagscache.tagtypes): | |
572 | old = self.tags().get(name, nullid) |
|
572 | old = self.tags().get(name, nullid) | |
573 | fp.write('%s %s\n' % (hex(old), m)) |
|
573 | fp.write('%s %s\n' % (hex(old), m)) | |
574 | fp.write('%s %s\n' % (hex(node), m)) |
|
574 | fp.write('%s %s\n' % (hex(node), m)) | |
575 | fp.close() |
|
575 | fp.close() | |
576 |
|
576 | |||
577 | prevtags = '' |
|
577 | prevtags = '' | |
578 | if local: |
|
578 | if local: | |
579 | try: |
|
579 | try: | |
580 | fp = self.vfs('localtags', 'r+') |
|
580 | fp = self.vfs('localtags', 'r+') | |
581 | except IOError: |
|
581 | except IOError: | |
582 | fp = self.vfs('localtags', 'a') |
|
582 | fp = self.vfs('localtags', 'a') | |
583 | else: |
|
583 | else: | |
584 | prevtags = fp.read() |
|
584 | prevtags = fp.read() | |
585 |
|
585 | |||
586 | # local tags are stored in the current charset |
|
586 | # local tags are stored in the current charset | |
587 | writetags(fp, names, None, prevtags) |
|
587 | writetags(fp, names, None, prevtags) | |
588 | for name in names: |
|
588 | for name in names: | |
589 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
589 | self.hook('tag', node=hex(node), tag=name, local=local) | |
590 | return |
|
590 | return | |
591 |
|
591 | |||
592 | try: |
|
592 | try: | |
593 | fp = self.wfile('.hgtags', 'rb+') |
|
593 | fp = self.wfile('.hgtags', 'rb+') | |
594 | except IOError as e: |
|
594 | except IOError as e: | |
595 | if e.errno != errno.ENOENT: |
|
595 | if e.errno != errno.ENOENT: | |
596 | raise |
|
596 | raise | |
597 | fp = self.wfile('.hgtags', 'ab') |
|
597 | fp = self.wfile('.hgtags', 'ab') | |
598 | else: |
|
598 | else: | |
599 | prevtags = fp.read() |
|
599 | prevtags = fp.read() | |
600 |
|
600 | |||
601 | # committed tags are stored in UTF-8 |
|
601 | # committed tags are stored in UTF-8 | |
602 | writetags(fp, names, encoding.fromlocal, prevtags) |
|
602 | writetags(fp, names, encoding.fromlocal, prevtags) | |
603 |
|
603 | |||
604 | fp.close() |
|
604 | fp.close() | |
605 |
|
605 | |||
606 | self.invalidatecaches() |
|
606 | self.invalidatecaches() | |
607 |
|
607 | |||
608 | if '.hgtags' not in self.dirstate: |
|
608 | if '.hgtags' not in self.dirstate: | |
609 | self[None].add(['.hgtags']) |
|
609 | self[None].add(['.hgtags']) | |
610 |
|
610 | |||
611 | m = matchmod.exact(self.root, '', ['.hgtags']) |
|
611 | m = matchmod.exact(self.root, '', ['.hgtags']) | |
612 | tagnode = self.commit(message, user, date, extra=extra, match=m, |
|
612 | tagnode = self.commit(message, user, date, extra=extra, match=m, | |
613 | editor=editor) |
|
613 | editor=editor) | |
614 |
|
614 | |||
615 | for name in names: |
|
615 | for name in names: | |
616 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
616 | self.hook('tag', node=hex(node), tag=name, local=local) | |
617 |
|
617 | |||
618 | return tagnode |
|
618 | return tagnode | |
619 |
|
619 | |||
620 | def tag(self, names, node, message, local, user, date, editor=False): |
|
620 | def tag(self, names, node, message, local, user, date, editor=False): | |
621 | '''tag a revision with one or more symbolic names. |
|
621 | '''tag a revision with one or more symbolic names. | |
622 |
|
622 | |||
623 | names is a list of strings or, when adding a single tag, names may be a |
|
623 | names is a list of strings or, when adding a single tag, names may be a | |
624 | string. |
|
624 | string. | |
625 |
|
625 | |||
626 | if local is True, the tags are stored in a per-repository file. |
|
626 | if local is True, the tags are stored in a per-repository file. | |
627 | otherwise, they are stored in the .hgtags file, and a new |
|
627 | otherwise, they are stored in the .hgtags file, and a new | |
628 | changeset is committed with the change. |
|
628 | changeset is committed with the change. | |
629 |
|
629 | |||
630 | keyword arguments: |
|
630 | keyword arguments: | |
631 |
|
631 | |||
632 | local: whether to store tags in non-version-controlled file |
|
632 | local: whether to store tags in non-version-controlled file | |
633 | (default False) |
|
633 | (default False) | |
634 |
|
634 | |||
635 | message: commit message to use if committing |
|
635 | message: commit message to use if committing | |
636 |
|
636 | |||
637 | user: name of user to use if committing |
|
637 | user: name of user to use if committing | |
638 |
|
638 | |||
639 | date: date tuple to use if committing''' |
|
639 | date: date tuple to use if committing''' | |
640 |
|
640 | |||
641 | if not local: |
|
641 | if not local: | |
642 | m = matchmod.exact(self.root, '', ['.hgtags']) |
|
642 | m = matchmod.exact(self.root, '', ['.hgtags']) | |
643 | if any(self.status(match=m, unknown=True, ignored=True)): |
|
643 | if any(self.status(match=m, unknown=True, ignored=True)): | |
644 | raise util.Abort(_('working copy of .hgtags is changed'), |
|
644 | raise util.Abort(_('working copy of .hgtags is changed'), | |
645 | hint=_('please commit .hgtags manually')) |
|
645 | hint=_('please commit .hgtags manually')) | |
646 |
|
646 | |||
647 | self.tags() # instantiate the cache |
|
647 | self.tags() # instantiate the cache | |
648 | self._tag(names, node, message, local, user, date, editor=editor) |
|
648 | self._tag(names, node, message, local, user, date, editor=editor) | |
649 |
|
649 | |||
650 | @filteredpropertycache |
|
650 | @filteredpropertycache | |
651 | def _tagscache(self): |
|
651 | def _tagscache(self): | |
652 | '''Returns a tagscache object that contains various tags related |
|
652 | '''Returns a tagscache object that contains various tags related | |
653 | caches.''' |
|
653 | caches.''' | |
654 |
|
654 | |||
655 | # This simplifies its cache management by having one decorated |
|
655 | # This simplifies its cache management by having one decorated | |
656 | # function (this one) and the rest simply fetch things from it. |
|
656 | # function (this one) and the rest simply fetch things from it. | |
657 | class tagscache(object): |
|
657 | class tagscache(object): | |
658 | def __init__(self): |
|
658 | def __init__(self): | |
659 | # These two define the set of tags for this repository. tags |
|
659 | # These two define the set of tags for this repository. tags | |
660 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
660 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
661 | # 'local'. (Global tags are defined by .hgtags across all |
|
661 | # 'local'. (Global tags are defined by .hgtags across all | |
662 | # heads, and local tags are defined in .hg/localtags.) |
|
662 | # heads, and local tags are defined in .hg/localtags.) | |
663 | # They constitute the in-memory cache of tags. |
|
663 | # They constitute the in-memory cache of tags. | |
664 | self.tags = self.tagtypes = None |
|
664 | self.tags = self.tagtypes = None | |
665 |
|
665 | |||
666 | self.nodetagscache = self.tagslist = None |
|
666 | self.nodetagscache = self.tagslist = None | |
667 |
|
667 | |||
668 | cache = tagscache() |
|
668 | cache = tagscache() | |
669 | cache.tags, cache.tagtypes = self._findtags() |
|
669 | cache.tags, cache.tagtypes = self._findtags() | |
670 |
|
670 | |||
671 | return cache |
|
671 | return cache | |
672 |
|
672 | |||
673 | def tags(self): |
|
673 | def tags(self): | |
674 | '''return a mapping of tag to node''' |
|
674 | '''return a mapping of tag to node''' | |
675 | t = {} |
|
675 | t = {} | |
676 | if self.changelog.filteredrevs: |
|
676 | if self.changelog.filteredrevs: | |
677 | tags, tt = self._findtags() |
|
677 | tags, tt = self._findtags() | |
678 | else: |
|
678 | else: | |
679 | tags = self._tagscache.tags |
|
679 | tags = self._tagscache.tags | |
680 | for k, v in tags.iteritems(): |
|
680 | for k, v in tags.iteritems(): | |
681 | try: |
|
681 | try: | |
682 | # ignore tags to unknown nodes |
|
682 | # ignore tags to unknown nodes | |
683 | self.changelog.rev(v) |
|
683 | self.changelog.rev(v) | |
684 | t[k] = v |
|
684 | t[k] = v | |
685 | except (error.LookupError, ValueError): |
|
685 | except (error.LookupError, ValueError): | |
686 | pass |
|
686 | pass | |
687 | return t |
|
687 | return t | |
688 |
|
688 | |||
689 | def _findtags(self): |
|
689 | def _findtags(self): | |
690 | '''Do the hard work of finding tags. Return a pair of dicts |
|
690 | '''Do the hard work of finding tags. Return a pair of dicts | |
691 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
691 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
692 | maps tag name to a string like \'global\' or \'local\'. |
|
692 | maps tag name to a string like \'global\' or \'local\'. | |
693 | Subclasses or extensions are free to add their own tags, but |
|
693 | Subclasses or extensions are free to add their own tags, but | |
694 | should be aware that the returned dicts will be retained for the |
|
694 | should be aware that the returned dicts will be retained for the | |
695 | duration of the localrepo object.''' |
|
695 | duration of the localrepo object.''' | |
696 |
|
696 | |||
697 | # XXX what tagtype should subclasses/extensions use? Currently |
|
697 | # XXX what tagtype should subclasses/extensions use? Currently | |
698 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
698 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
699 | # Should each extension invent its own tag type? Should there |
|
699 | # Should each extension invent its own tag type? Should there | |
700 | # be one tagtype for all such "virtual" tags? Or is the status |
|
700 | # be one tagtype for all such "virtual" tags? Or is the status | |
701 | # quo fine? |
|
701 | # quo fine? | |
702 |
|
702 | |||
703 | alltags = {} # map tag name to (node, hist) |
|
703 | alltags = {} # map tag name to (node, hist) | |
704 | tagtypes = {} |
|
704 | tagtypes = {} | |
705 |
|
705 | |||
706 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) |
|
706 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) | |
707 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
707 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
708 |
|
708 | |||
709 | # Build the return dicts. Have to re-encode tag names because |
|
709 | # Build the return dicts. Have to re-encode tag names because | |
710 | # the tags module always uses UTF-8 (in order not to lose info |
|
710 | # the tags module always uses UTF-8 (in order not to lose info | |
711 | # writing to the cache), but the rest of Mercurial wants them in |
|
711 | # writing to the cache), but the rest of Mercurial wants them in | |
712 | # local encoding. |
|
712 | # local encoding. | |
713 | tags = {} |
|
713 | tags = {} | |
714 | for (name, (node, hist)) in alltags.iteritems(): |
|
714 | for (name, (node, hist)) in alltags.iteritems(): | |
715 | if node != nullid: |
|
715 | if node != nullid: | |
716 | tags[encoding.tolocal(name)] = node |
|
716 | tags[encoding.tolocal(name)] = node | |
717 | tags['tip'] = self.changelog.tip() |
|
717 | tags['tip'] = self.changelog.tip() | |
718 | tagtypes = dict([(encoding.tolocal(name), value) |
|
718 | tagtypes = dict([(encoding.tolocal(name), value) | |
719 | for (name, value) in tagtypes.iteritems()]) |
|
719 | for (name, value) in tagtypes.iteritems()]) | |
720 | return (tags, tagtypes) |
|
720 | return (tags, tagtypes) | |
721 |
|
721 | |||
722 | def tagtype(self, tagname): |
|
722 | def tagtype(self, tagname): | |
723 | ''' |
|
723 | ''' | |
724 | return the type of the given tag. result can be: |
|
724 | return the type of the given tag. result can be: | |
725 |
|
725 | |||
726 | 'local' : a local tag |
|
726 | 'local' : a local tag | |
727 | 'global' : a global tag |
|
727 | 'global' : a global tag | |
728 | None : tag does not exist |
|
728 | None : tag does not exist | |
729 | ''' |
|
729 | ''' | |
730 |
|
730 | |||
731 | return self._tagscache.tagtypes.get(tagname) |
|
731 | return self._tagscache.tagtypes.get(tagname) | |
732 |
|
732 | |||
733 | def tagslist(self): |
|
733 | def tagslist(self): | |
734 | '''return a list of tags ordered by revision''' |
|
734 | '''return a list of tags ordered by revision''' | |
735 | if not self._tagscache.tagslist: |
|
735 | if not self._tagscache.tagslist: | |
736 | l = [] |
|
736 | l = [] | |
737 | for t, n in self.tags().iteritems(): |
|
737 | for t, n in self.tags().iteritems(): | |
738 | l.append((self.changelog.rev(n), t, n)) |
|
738 | l.append((self.changelog.rev(n), t, n)) | |
739 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
739 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
740 |
|
740 | |||
741 | return self._tagscache.tagslist |
|
741 | return self._tagscache.tagslist | |
742 |
|
742 | |||
743 | def nodetags(self, node): |
|
743 | def nodetags(self, node): | |
744 | '''return the tags associated with a node''' |
|
744 | '''return the tags associated with a node''' | |
745 | if not self._tagscache.nodetagscache: |
|
745 | if not self._tagscache.nodetagscache: | |
746 | nodetagscache = {} |
|
746 | nodetagscache = {} | |
747 | for t, n in self._tagscache.tags.iteritems(): |
|
747 | for t, n in self._tagscache.tags.iteritems(): | |
748 | nodetagscache.setdefault(n, []).append(t) |
|
748 | nodetagscache.setdefault(n, []).append(t) | |
749 | for tags in nodetagscache.itervalues(): |
|
749 | for tags in nodetagscache.itervalues(): | |
750 | tags.sort() |
|
750 | tags.sort() | |
751 | self._tagscache.nodetagscache = nodetagscache |
|
751 | self._tagscache.nodetagscache = nodetagscache | |
752 | return self._tagscache.nodetagscache.get(node, []) |
|
752 | return self._tagscache.nodetagscache.get(node, []) | |
753 |
|
753 | |||
754 | def nodebookmarks(self, node): |
|
754 | def nodebookmarks(self, node): | |
755 | marks = [] |
|
755 | marks = [] | |
756 | for bookmark, n in self._bookmarks.iteritems(): |
|
756 | for bookmark, n in self._bookmarks.iteritems(): | |
757 | if n == node: |
|
757 | if n == node: | |
758 | marks.append(bookmark) |
|
758 | marks.append(bookmark) | |
759 | return sorted(marks) |
|
759 | return sorted(marks) | |
760 |
|
760 | |||
761 | def branchmap(self): |
|
761 | def branchmap(self): | |
762 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
762 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
763 | ordered by increasing revision number''' |
|
763 | ordered by increasing revision number''' | |
764 | branchmap.updatecache(self) |
|
764 | branchmap.updatecache(self) | |
765 | return self._branchcaches[self.filtername] |
|
765 | return self._branchcaches[self.filtername] | |
766 |
|
766 | |||
767 | @unfilteredmethod |
|
767 | @unfilteredmethod | |
768 | def revbranchcache(self): |
|
768 | def revbranchcache(self): | |
769 | if not self._revbranchcache: |
|
769 | if not self._revbranchcache: | |
770 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
770 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
771 | return self._revbranchcache |
|
771 | return self._revbranchcache | |
772 |
|
772 | |||
773 | def branchtip(self, branch, ignoremissing=False): |
|
773 | def branchtip(self, branch, ignoremissing=False): | |
774 | '''return the tip node for a given branch |
|
774 | '''return the tip node for a given branch | |
775 |
|
775 | |||
776 | If ignoremissing is True, then this method will not raise an error. |
|
776 | If ignoremissing is True, then this method will not raise an error. | |
777 | This is helpful for callers that only expect None for a missing branch |
|
777 | This is helpful for callers that only expect None for a missing branch | |
778 | (e.g. namespace). |
|
778 | (e.g. namespace). | |
779 |
|
779 | |||
780 | ''' |
|
780 | ''' | |
781 | try: |
|
781 | try: | |
782 | return self.branchmap().branchtip(branch) |
|
782 | return self.branchmap().branchtip(branch) | |
783 | except KeyError: |
|
783 | except KeyError: | |
784 | if not ignoremissing: |
|
784 | if not ignoremissing: | |
785 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
785 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
786 | else: |
|
786 | else: | |
787 | pass |
|
787 | pass | |
788 |
|
788 | |||
789 | def lookup(self, key): |
|
789 | def lookup(self, key): | |
790 | return self[key].node() |
|
790 | return self[key].node() | |
791 |
|
791 | |||
792 | def lookupbranch(self, key, remote=None): |
|
792 | def lookupbranch(self, key, remote=None): | |
793 | repo = remote or self |
|
793 | repo = remote or self | |
794 | if key in repo.branchmap(): |
|
794 | if key in repo.branchmap(): | |
795 | return key |
|
795 | return key | |
796 |
|
796 | |||
797 | repo = (remote and remote.local()) and remote or self |
|
797 | repo = (remote and remote.local()) and remote or self | |
798 | return repo[key].branch() |
|
798 | return repo[key].branch() | |
799 |
|
799 | |||
800 | def known(self, nodes): |
|
800 | def known(self, nodes): | |
801 | nm = self.changelog.nodemap |
|
801 | nm = self.changelog.nodemap | |
802 | pc = self._phasecache |
|
802 | pc = self._phasecache | |
803 | result = [] |
|
803 | result = [] | |
804 | for n in nodes: |
|
804 | for n in nodes: | |
805 | r = nm.get(n) |
|
805 | r = nm.get(n) | |
806 | resp = not (r is None or pc.phase(self, r) >= phases.secret) |
|
806 | resp = not (r is None or pc.phase(self, r) >= phases.secret) | |
807 | result.append(resp) |
|
807 | result.append(resp) | |
808 | return result |
|
808 | return result | |
809 |
|
809 | |||
810 | def local(self): |
|
810 | def local(self): | |
811 | return self |
|
811 | return self | |
812 |
|
812 | |||
813 | def publishing(self): |
|
813 | def publishing(self): | |
814 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
814 | # it's safe (and desirable) to trust the publish flag unconditionally | |
815 | # so that we don't finalize changes shared between users via ssh or nfs |
|
815 | # so that we don't finalize changes shared between users via ssh or nfs | |
816 | return self.ui.configbool('phases', 'publish', True, untrusted=True) |
|
816 | return self.ui.configbool('phases', 'publish', True, untrusted=True) | |
817 |
|
817 | |||
818 | def cancopy(self): |
|
818 | def cancopy(self): | |
819 | # so statichttprepo's override of local() works |
|
819 | # so statichttprepo's override of local() works | |
820 | if not self.local(): |
|
820 | if not self.local(): | |
821 | return False |
|
821 | return False | |
822 | if not self.publishing(): |
|
822 | if not self.publishing(): | |
823 | return True |
|
823 | return True | |
824 | # if publishing we can't copy if there is filtered content |
|
824 | # if publishing we can't copy if there is filtered content | |
825 | return not self.filtered('visible').changelog.filteredrevs |
|
825 | return not self.filtered('visible').changelog.filteredrevs | |
826 |
|
826 | |||
827 | def shared(self): |
|
827 | def shared(self): | |
828 | '''the type of shared repository (None if not shared)''' |
|
828 | '''the type of shared repository (None if not shared)''' | |
829 | if self.sharedpath != self.path: |
|
829 | if self.sharedpath != self.path: | |
830 | return 'store' |
|
830 | return 'store' | |
831 | return None |
|
831 | return None | |
832 |
|
832 | |||
833 | def join(self, f, *insidef): |
|
833 | def join(self, f, *insidef): | |
834 | return self.vfs.join(os.path.join(f, *insidef)) |
|
834 | return self.vfs.join(os.path.join(f, *insidef)) | |
835 |
|
835 | |||
836 | def wjoin(self, f, *insidef): |
|
836 | def wjoin(self, f, *insidef): | |
837 | return self.vfs.reljoin(self.root, f, *insidef) |
|
837 | return self.vfs.reljoin(self.root, f, *insidef) | |
838 |
|
838 | |||
839 | def file(self, f): |
|
839 | def file(self, f): | |
840 | if f[0] == '/': |
|
840 | if f[0] == '/': | |
841 | f = f[1:] |
|
841 | f = f[1:] | |
842 | return filelog.filelog(self.svfs, f) |
|
842 | return filelog.filelog(self.svfs, f) | |
843 |
|
843 | |||
844 | def changectx(self, changeid): |
|
844 | def changectx(self, changeid): | |
845 | return self[changeid] |
|
845 | return self[changeid] | |
846 |
|
846 | |||
847 | def parents(self, changeid=None): |
|
847 | def parents(self, changeid=None): | |
848 | '''get list of changectxs for parents of changeid''' |
|
848 | '''get list of changectxs for parents of changeid''' | |
849 | return self[changeid].parents() |
|
849 | return self[changeid].parents() | |
850 |
|
850 | |||
851 | def setparents(self, p1, p2=nullid): |
|
851 | def setparents(self, p1, p2=nullid): | |
852 | self.dirstate.beginparentchange() |
|
852 | self.dirstate.beginparentchange() | |
853 | copies = self.dirstate.setparents(p1, p2) |
|
853 | copies = self.dirstate.setparents(p1, p2) | |
854 | pctx = self[p1] |
|
854 | pctx = self[p1] | |
855 | if copies: |
|
855 | if copies: | |
856 | # Adjust copy records, the dirstate cannot do it, it |
|
856 | # Adjust copy records, the dirstate cannot do it, it | |
857 | # requires access to parents manifests. Preserve them |
|
857 | # requires access to parents manifests. Preserve them | |
858 | # only for entries added to first parent. |
|
858 | # only for entries added to first parent. | |
859 | for f in copies: |
|
859 | for f in copies: | |
860 | if f not in pctx and copies[f] in pctx: |
|
860 | if f not in pctx and copies[f] in pctx: | |
861 | self.dirstate.copy(copies[f], f) |
|
861 | self.dirstate.copy(copies[f], f) | |
862 | if p2 == nullid: |
|
862 | if p2 == nullid: | |
863 | for f, s in sorted(self.dirstate.copies().items()): |
|
863 | for f, s in sorted(self.dirstate.copies().items()): | |
864 | if f not in pctx and s not in pctx: |
|
864 | if f not in pctx and s not in pctx: | |
865 | self.dirstate.copy(None, f) |
|
865 | self.dirstate.copy(None, f) | |
866 | self.dirstate.endparentchange() |
|
866 | self.dirstate.endparentchange() | |
867 |
|
867 | |||
868 | def filectx(self, path, changeid=None, fileid=None): |
|
868 | def filectx(self, path, changeid=None, fileid=None): | |
869 | """changeid can be a changeset revision, node, or tag. |
|
869 | """changeid can be a changeset revision, node, or tag. | |
870 | fileid can be a file revision or node.""" |
|
870 | fileid can be a file revision or node.""" | |
871 | return context.filectx(self, path, changeid, fileid) |
|
871 | return context.filectx(self, path, changeid, fileid) | |
872 |
|
872 | |||
873 | def getcwd(self): |
|
873 | def getcwd(self): | |
874 | return self.dirstate.getcwd() |
|
874 | return self.dirstate.getcwd() | |
875 |
|
875 | |||
876 | def pathto(self, f, cwd=None): |
|
876 | def pathto(self, f, cwd=None): | |
877 | return self.dirstate.pathto(f, cwd) |
|
877 | return self.dirstate.pathto(f, cwd) | |
878 |
|
878 | |||
879 | def wfile(self, f, mode='r'): |
|
879 | def wfile(self, f, mode='r'): | |
880 | return self.wvfs(f, mode) |
|
880 | return self.wvfs(f, mode) | |
881 |
|
881 | |||
882 | def _link(self, f): |
|
882 | def _link(self, f): | |
883 | return self.wvfs.islink(f) |
|
883 | return self.wvfs.islink(f) | |
884 |
|
884 | |||
885 | def _loadfilter(self, filter): |
|
885 | def _loadfilter(self, filter): | |
886 | if filter not in self.filterpats: |
|
886 | if filter not in self.filterpats: | |
887 | l = [] |
|
887 | l = [] | |
888 | for pat, cmd in self.ui.configitems(filter): |
|
888 | for pat, cmd in self.ui.configitems(filter): | |
889 | if cmd == '!': |
|
889 | if cmd == '!': | |
890 | continue |
|
890 | continue | |
891 | mf = matchmod.match(self.root, '', [pat]) |
|
891 | mf = matchmod.match(self.root, '', [pat]) | |
892 | fn = None |
|
892 | fn = None | |
893 | params = cmd |
|
893 | params = cmd | |
894 | for name, filterfn in self._datafilters.iteritems(): |
|
894 | for name, filterfn in self._datafilters.iteritems(): | |
895 | if cmd.startswith(name): |
|
895 | if cmd.startswith(name): | |
896 | fn = filterfn |
|
896 | fn = filterfn | |
897 | params = cmd[len(name):].lstrip() |
|
897 | params = cmd[len(name):].lstrip() | |
898 | break |
|
898 | break | |
899 | if not fn: |
|
899 | if not fn: | |
900 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
900 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
901 | # Wrap old filters not supporting keyword arguments |
|
901 | # Wrap old filters not supporting keyword arguments | |
902 | if not inspect.getargspec(fn)[2]: |
|
902 | if not inspect.getargspec(fn)[2]: | |
903 | oldfn = fn |
|
903 | oldfn = fn | |
904 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
904 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
905 | l.append((mf, fn, params)) |
|
905 | l.append((mf, fn, params)) | |
906 | self.filterpats[filter] = l |
|
906 | self.filterpats[filter] = l | |
907 | return self.filterpats[filter] |
|
907 | return self.filterpats[filter] | |
908 |
|
908 | |||
909 | def _filter(self, filterpats, filename, data): |
|
909 | def _filter(self, filterpats, filename, data): | |
910 | for mf, fn, cmd in filterpats: |
|
910 | for mf, fn, cmd in filterpats: | |
911 | if mf(filename): |
|
911 | if mf(filename): | |
912 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
912 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
913 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
913 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
914 | break |
|
914 | break | |
915 |
|
915 | |||
916 | return data |
|
916 | return data | |
917 |
|
917 | |||
918 | @unfilteredpropertycache |
|
918 | @unfilteredpropertycache | |
919 | def _encodefilterpats(self): |
|
919 | def _encodefilterpats(self): | |
920 | return self._loadfilter('encode') |
|
920 | return self._loadfilter('encode') | |
921 |
|
921 | |||
922 | @unfilteredpropertycache |
|
922 | @unfilteredpropertycache | |
923 | def _decodefilterpats(self): |
|
923 | def _decodefilterpats(self): | |
924 | return self._loadfilter('decode') |
|
924 | return self._loadfilter('decode') | |
925 |
|
925 | |||
926 | def adddatafilter(self, name, filter): |
|
926 | def adddatafilter(self, name, filter): | |
927 | self._datafilters[name] = filter |
|
927 | self._datafilters[name] = filter | |
928 |
|
928 | |||
929 | def wread(self, filename): |
|
929 | def wread(self, filename): | |
930 | if self._link(filename): |
|
930 | if self._link(filename): | |
931 | data = self.wvfs.readlink(filename) |
|
931 | data = self.wvfs.readlink(filename) | |
932 | else: |
|
932 | else: | |
933 | data = self.wvfs.read(filename) |
|
933 | data = self.wvfs.read(filename) | |
934 | return self._filter(self._encodefilterpats, filename, data) |
|
934 | return self._filter(self._encodefilterpats, filename, data) | |
935 |
|
935 | |||
936 | def wwrite(self, filename, data, flags): |
|
936 | def wwrite(self, filename, data, flags): | |
937 | """write ``data`` into ``filename`` in the working directory |
|
937 | """write ``data`` into ``filename`` in the working directory | |
938 |
|
938 | |||
939 | This returns length of written (maybe decoded) data. |
|
939 | This returns length of written (maybe decoded) data. | |
940 | """ |
|
940 | """ | |
941 | data = self._filter(self._decodefilterpats, filename, data) |
|
941 | data = self._filter(self._decodefilterpats, filename, data) | |
942 | if 'l' in flags: |
|
942 | if 'l' in flags: | |
943 | self.wvfs.symlink(data, filename) |
|
943 | self.wvfs.symlink(data, filename) | |
944 | else: |
|
944 | else: | |
945 | self.wvfs.write(filename, data) |
|
945 | self.wvfs.write(filename, data) | |
946 | if 'x' in flags: |
|
946 | if 'x' in flags: | |
947 | self.wvfs.setflags(filename, False, True) |
|
947 | self.wvfs.setflags(filename, False, True) | |
948 | return len(data) |
|
948 | return len(data) | |
949 |
|
949 | |||
950 | def wwritedata(self, filename, data): |
|
950 | def wwritedata(self, filename, data): | |
951 | return self._filter(self._decodefilterpats, filename, data) |
|
951 | return self._filter(self._decodefilterpats, filename, data) | |
952 |
|
952 | |||
953 | def currenttransaction(self): |
|
953 | def currenttransaction(self): | |
954 | """return the current transaction or None if non exists""" |
|
954 | """return the current transaction or None if non exists""" | |
955 | if self._transref: |
|
955 | if self._transref: | |
956 | tr = self._transref() |
|
956 | tr = self._transref() | |
957 | else: |
|
957 | else: | |
958 | tr = None |
|
958 | tr = None | |
959 |
|
959 | |||
960 | if tr and tr.running(): |
|
960 | if tr and tr.running(): | |
961 | return tr |
|
961 | return tr | |
962 | return None |
|
962 | return None | |
963 |
|
963 | |||
964 | def transaction(self, desc, report=None): |
|
964 | def transaction(self, desc, report=None): | |
965 | if (self.ui.configbool('devel', 'all-warnings') |
|
965 | if (self.ui.configbool('devel', 'all-warnings') | |
966 | or self.ui.configbool('devel', 'check-locks')): |
|
966 | or self.ui.configbool('devel', 'check-locks')): | |
967 | l = self._lockref and self._lockref() |
|
967 | l = self._lockref and self._lockref() | |
968 | if l is None or not l.held: |
|
968 | if l is None or not l.held: | |
969 | self.ui.develwarn('transaction with no lock') |
|
969 | self.ui.develwarn('transaction with no lock') | |
970 | tr = self.currenttransaction() |
|
970 | tr = self.currenttransaction() | |
971 | if tr is not None: |
|
971 | if tr is not None: | |
972 | return tr.nest() |
|
972 | return tr.nest() | |
973 |
|
973 | |||
974 | # abort here if the journal already exists |
|
974 | # abort here if the journal already exists | |
975 | if self.svfs.exists("journal"): |
|
975 | if self.svfs.exists("journal"): | |
976 | raise error.RepoError( |
|
976 | raise error.RepoError( | |
977 | _("abandoned transaction found"), |
|
977 | _("abandoned transaction found"), | |
978 | hint=_("run 'hg recover' to clean up transaction")) |
|
978 | hint=_("run 'hg recover' to clean up transaction")) | |
979 |
|
979 | |||
980 | # make journal.dirstate contain in-memory changes at this point |
|
980 | # make journal.dirstate contain in-memory changes at this point | |
981 | self.dirstate.write() |
|
981 | self.dirstate.write() | |
982 |
|
982 | |||
983 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
983 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
984 | txnid = 'TXN:' + util.sha1(idbase).hexdigest() |
|
984 | txnid = 'TXN:' + util.sha1(idbase).hexdigest() | |
985 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
985 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
986 |
|
986 | |||
987 | self._writejournal(desc) |
|
987 | self._writejournal(desc) | |
988 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
988 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
989 | if report: |
|
989 | if report: | |
990 | rp = report |
|
990 | rp = report | |
991 | else: |
|
991 | else: | |
992 | rp = self.ui.warn |
|
992 | rp = self.ui.warn | |
993 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
993 | vfsmap = {'plain': self.vfs} # root of .hg/ | |
994 | # we must avoid cyclic reference between repo and transaction. |
|
994 | # we must avoid cyclic reference between repo and transaction. | |
995 | reporef = weakref.ref(self) |
|
995 | reporef = weakref.ref(self) | |
996 | def validate(tr): |
|
996 | def validate(tr): | |
997 | """will run pre-closing hooks""" |
|
997 | """will run pre-closing hooks""" | |
998 | pending = lambda: tr.writepending() and self.root or "" |
|
998 | pending = lambda: tr.writepending() and self.root or "" | |
999 | reporef().hook('pretxnclose', throw=True, pending=pending, |
|
999 | reporef().hook('pretxnclose', throw=True, pending=pending, | |
1000 | txnname=desc, **tr.hookargs) |
|
1000 | txnname=desc, **tr.hookargs) | |
1001 |
|
1001 | |||
1002 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1002 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1003 | "journal", |
|
1003 | "journal", | |
1004 | "undo", |
|
1004 | "undo", | |
1005 | aftertrans(renames), |
|
1005 | aftertrans(renames), | |
1006 | self.store.createmode, |
|
1006 | self.store.createmode, | |
1007 | validator=validate) |
|
1007 | validator=validate) | |
1008 |
|
1008 | |||
1009 | tr.hookargs['txnid'] = txnid |
|
1009 | tr.hookargs['txnid'] = txnid | |
1010 | # note: writing the fncache only during finalize mean that the file is |
|
1010 | # note: writing the fncache only during finalize mean that the file is | |
1011 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1011 | # outdated when running hooks. As fncache is used for streaming clone, | |
1012 | # this is not expected to break anything that happen during the hooks. |
|
1012 | # this is not expected to break anything that happen during the hooks. | |
1013 | tr.addfinalize('flush-fncache', self.store.write) |
|
1013 | tr.addfinalize('flush-fncache', self.store.write) | |
1014 | def txnclosehook(tr2): |
|
1014 | def txnclosehook(tr2): | |
1015 | """To be run if transaction is successful, will schedule a hook run |
|
1015 | """To be run if transaction is successful, will schedule a hook run | |
1016 | """ |
|
1016 | """ | |
1017 | def hook(): |
|
1017 | def hook(): | |
1018 | reporef().hook('txnclose', throw=False, txnname=desc, |
|
1018 | reporef().hook('txnclose', throw=False, txnname=desc, | |
1019 | **tr2.hookargs) |
|
1019 | **tr2.hookargs) | |
1020 | reporef()._afterlock(hook) |
|
1020 | reporef()._afterlock(hook) | |
1021 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1021 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1022 | def txnaborthook(tr2): |
|
1022 | def txnaborthook(tr2): | |
1023 | """To be run if transaction is aborted |
|
1023 | """To be run if transaction is aborted | |
1024 | """ |
|
1024 | """ | |
1025 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1025 | reporef().hook('txnabort', throw=False, txnname=desc, | |
1026 | **tr2.hookargs) |
|
1026 | **tr2.hookargs) | |
1027 | tr.addabort('txnabort-hook', txnaborthook) |
|
1027 | tr.addabort('txnabort-hook', txnaborthook) | |
1028 | # avoid eager cache invalidation. in-memory data should be identical |
|
1028 | # avoid eager cache invalidation. in-memory data should be identical | |
1029 | # to stored data if transaction has no error. |
|
1029 | # to stored data if transaction has no error. | |
1030 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1030 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1031 | self._transref = weakref.ref(tr) |
|
1031 | self._transref = weakref.ref(tr) | |
1032 | return tr |
|
1032 | return tr | |
1033 |
|
1033 | |||
1034 | def _journalfiles(self): |
|
1034 | def _journalfiles(self): | |
1035 | return ((self.svfs, 'journal'), |
|
1035 | return ((self.svfs, 'journal'), | |
1036 | (self.vfs, 'journal.dirstate'), |
|
1036 | (self.vfs, 'journal.dirstate'), | |
1037 | (self.vfs, 'journal.branch'), |
|
1037 | (self.vfs, 'journal.branch'), | |
1038 | (self.vfs, 'journal.desc'), |
|
1038 | (self.vfs, 'journal.desc'), | |
1039 | (self.vfs, 'journal.bookmarks'), |
|
1039 | (self.vfs, 'journal.bookmarks'), | |
1040 | (self.svfs, 'journal.phaseroots')) |
|
1040 | (self.svfs, 'journal.phaseroots')) | |
1041 |
|
1041 | |||
1042 | def undofiles(self): |
|
1042 | def undofiles(self): | |
1043 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1043 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1044 |
|
1044 | |||
1045 | def _writejournal(self, desc): |
|
1045 | def _writejournal(self, desc): | |
1046 | self.vfs.write("journal.dirstate", |
|
1046 | self.vfs.write("journal.dirstate", | |
1047 | self.vfs.tryread("dirstate")) |
|
1047 | self.vfs.tryread("dirstate")) | |
1048 | self.vfs.write("journal.branch", |
|
1048 | self.vfs.write("journal.branch", | |
1049 | encoding.fromlocal(self.dirstate.branch())) |
|
1049 | encoding.fromlocal(self.dirstate.branch())) | |
1050 | self.vfs.write("journal.desc", |
|
1050 | self.vfs.write("journal.desc", | |
1051 | "%d\n%s\n" % (len(self), desc)) |
|
1051 | "%d\n%s\n" % (len(self), desc)) | |
1052 | self.vfs.write("journal.bookmarks", |
|
1052 | self.vfs.write("journal.bookmarks", | |
1053 | self.vfs.tryread("bookmarks")) |
|
1053 | self.vfs.tryread("bookmarks")) | |
1054 | self.svfs.write("journal.phaseroots", |
|
1054 | self.svfs.write("journal.phaseroots", | |
1055 | self.svfs.tryread("phaseroots")) |
|
1055 | self.svfs.tryread("phaseroots")) | |
1056 |
|
1056 | |||
1057 | def recover(self): |
|
1057 | def recover(self): | |
1058 | lock = self.lock() |
|
1058 | lock = self.lock() | |
1059 | try: |
|
1059 | try: | |
1060 | if self.svfs.exists("journal"): |
|
1060 | if self.svfs.exists("journal"): | |
1061 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1061 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1062 | vfsmap = {'': self.svfs, |
|
1062 | vfsmap = {'': self.svfs, | |
1063 | 'plain': self.vfs,} |
|
1063 | 'plain': self.vfs,} | |
1064 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1064 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1065 | self.ui.warn) |
|
1065 | self.ui.warn) | |
1066 | self.invalidate() |
|
1066 | self.invalidate() | |
1067 | return True |
|
1067 | return True | |
1068 | else: |
|
1068 | else: | |
1069 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1069 | self.ui.warn(_("no interrupted transaction available\n")) | |
1070 | return False |
|
1070 | return False | |
1071 | finally: |
|
1071 | finally: | |
1072 | lock.release() |
|
1072 | lock.release() | |
1073 |
|
1073 | |||
1074 | def rollback(self, dryrun=False, force=False): |
|
1074 | def rollback(self, dryrun=False, force=False): | |
1075 | wlock = lock = None |
|
1075 | wlock = lock = None | |
1076 | try: |
|
1076 | try: | |
1077 | wlock = self.wlock() |
|
1077 | wlock = self.wlock() | |
1078 | lock = self.lock() |
|
1078 | lock = self.lock() | |
1079 | if self.svfs.exists("undo"): |
|
1079 | if self.svfs.exists("undo"): | |
1080 | return self._rollback(dryrun, force) |
|
1080 | return self._rollback(dryrun, force) | |
1081 | else: |
|
1081 | else: | |
1082 | self.ui.warn(_("no rollback information available\n")) |
|
1082 | self.ui.warn(_("no rollback information available\n")) | |
1083 | return 1 |
|
1083 | return 1 | |
1084 | finally: |
|
1084 | finally: | |
1085 | release(lock, wlock) |
|
1085 | release(lock, wlock) | |
1086 |
|
1086 | |||
1087 | @unfilteredmethod # Until we get smarter cache management |
|
1087 | @unfilteredmethod # Until we get smarter cache management | |
1088 | def _rollback(self, dryrun, force): |
|
1088 | def _rollback(self, dryrun, force): | |
1089 | ui = self.ui |
|
1089 | ui = self.ui | |
1090 | try: |
|
1090 | try: | |
1091 | args = self.vfs.read('undo.desc').splitlines() |
|
1091 | args = self.vfs.read('undo.desc').splitlines() | |
1092 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1092 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
1093 | if len(args) >= 3: |
|
1093 | if len(args) >= 3: | |
1094 | detail = args[2] |
|
1094 | detail = args[2] | |
1095 | oldtip = oldlen - 1 |
|
1095 | oldtip = oldlen - 1 | |
1096 |
|
1096 | |||
1097 | if detail and ui.verbose: |
|
1097 | if detail and ui.verbose: | |
1098 | msg = (_('repository tip rolled back to revision %s' |
|
1098 | msg = (_('repository tip rolled back to revision %s' | |
1099 | ' (undo %s: %s)\n') |
|
1099 | ' (undo %s: %s)\n') | |
1100 | % (oldtip, desc, detail)) |
|
1100 | % (oldtip, desc, detail)) | |
1101 | else: |
|
1101 | else: | |
1102 | msg = (_('repository tip rolled back to revision %s' |
|
1102 | msg = (_('repository tip rolled back to revision %s' | |
1103 | ' (undo %s)\n') |
|
1103 | ' (undo %s)\n') | |
1104 | % (oldtip, desc)) |
|
1104 | % (oldtip, desc)) | |
1105 | except IOError: |
|
1105 | except IOError: | |
1106 | msg = _('rolling back unknown transaction\n') |
|
1106 | msg = _('rolling back unknown transaction\n') | |
1107 | desc = None |
|
1107 | desc = None | |
1108 |
|
1108 | |||
1109 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1109 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
1110 | raise util.Abort( |
|
1110 | raise util.Abort( | |
1111 | _('rollback of last commit while not checked out ' |
|
1111 | _('rollback of last commit while not checked out ' | |
1112 | 'may lose data'), hint=_('use -f to force')) |
|
1112 | 'may lose data'), hint=_('use -f to force')) | |
1113 |
|
1113 | |||
1114 | ui.status(msg) |
|
1114 | ui.status(msg) | |
1115 | if dryrun: |
|
1115 | if dryrun: | |
1116 | return 0 |
|
1116 | return 0 | |
1117 |
|
1117 | |||
1118 | parents = self.dirstate.parents() |
|
1118 | parents = self.dirstate.parents() | |
1119 | self.destroying() |
|
1119 | self.destroying() | |
1120 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1120 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
1121 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn) |
|
1121 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn) | |
1122 | if self.vfs.exists('undo.bookmarks'): |
|
1122 | if self.vfs.exists('undo.bookmarks'): | |
1123 | self.vfs.rename('undo.bookmarks', 'bookmarks') |
|
1123 | self.vfs.rename('undo.bookmarks', 'bookmarks') | |
1124 | if self.svfs.exists('undo.phaseroots'): |
|
1124 | if self.svfs.exists('undo.phaseroots'): | |
1125 | self.svfs.rename('undo.phaseroots', 'phaseroots') |
|
1125 | self.svfs.rename('undo.phaseroots', 'phaseroots') | |
1126 | self.invalidate() |
|
1126 | self.invalidate() | |
1127 |
|
1127 | |||
1128 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1128 | parentgone = (parents[0] not in self.changelog.nodemap or | |
1129 | parents[1] not in self.changelog.nodemap) |
|
1129 | parents[1] not in self.changelog.nodemap) | |
1130 | if parentgone: |
|
1130 | if parentgone: | |
1131 | self.vfs.rename('undo.dirstate', 'dirstate') |
|
1131 | self.vfs.rename('undo.dirstate', 'dirstate') | |
1132 | try: |
|
1132 | try: | |
1133 | branch = self.vfs.read('undo.branch') |
|
1133 | branch = self.vfs.read('undo.branch') | |
1134 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1134 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
1135 | except IOError: |
|
1135 | except IOError: | |
1136 | ui.warn(_('named branch could not be reset: ' |
|
1136 | ui.warn(_('named branch could not be reset: ' | |
1137 | 'current branch is still \'%s\'\n') |
|
1137 | 'current branch is still \'%s\'\n') | |
1138 | % self.dirstate.branch()) |
|
1138 | % self.dirstate.branch()) | |
1139 |
|
1139 | |||
1140 | self.dirstate.invalidate() |
|
1140 | self.dirstate.invalidate() | |
1141 | parents = tuple([p.rev() for p in self.parents()]) |
|
1141 | parents = tuple([p.rev() for p in self.parents()]) | |
1142 | if len(parents) > 1: |
|
1142 | if len(parents) > 1: | |
1143 | ui.status(_('working directory now based on ' |
|
1143 | ui.status(_('working directory now based on ' | |
1144 | 'revisions %d and %d\n') % parents) |
|
1144 | 'revisions %d and %d\n') % parents) | |
1145 | else: |
|
1145 | else: | |
1146 | ui.status(_('working directory now based on ' |
|
1146 | ui.status(_('working directory now based on ' | |
1147 | 'revision %d\n') % parents) |
|
1147 | 'revision %d\n') % parents) | |
1148 | ms = mergemod.mergestate(self) |
|
1148 | ms = mergemod.mergestate(self) | |
1149 | ms.reset(self['.'].node()) |
|
1149 | ms.reset(self['.'].node()) | |
1150 |
|
1150 | |||
1151 | # TODO: if we know which new heads may result from this rollback, pass |
|
1151 | # TODO: if we know which new heads may result from this rollback, pass | |
1152 | # them to destroy(), which will prevent the branchhead cache from being |
|
1152 | # them to destroy(), which will prevent the branchhead cache from being | |
1153 | # invalidated. |
|
1153 | # invalidated. | |
1154 | self.destroyed() |
|
1154 | self.destroyed() | |
1155 | return 0 |
|
1155 | return 0 | |
1156 |
|
1156 | |||
1157 | def invalidatecaches(self): |
|
1157 | def invalidatecaches(self): | |
1158 |
|
1158 | |||
1159 | if '_tagscache' in vars(self): |
|
1159 | if '_tagscache' in vars(self): | |
1160 | # can't use delattr on proxy |
|
1160 | # can't use delattr on proxy | |
1161 | del self.__dict__['_tagscache'] |
|
1161 | del self.__dict__['_tagscache'] | |
1162 |
|
1162 | |||
1163 | self.unfiltered()._branchcaches.clear() |
|
1163 | self.unfiltered()._branchcaches.clear() | |
1164 | self.invalidatevolatilesets() |
|
1164 | self.invalidatevolatilesets() | |
1165 |
|
1165 | |||
1166 | def invalidatevolatilesets(self): |
|
1166 | def invalidatevolatilesets(self): | |
1167 | self.filteredrevcache.clear() |
|
1167 | self.filteredrevcache.clear() | |
1168 | obsolete.clearobscaches(self) |
|
1168 | obsolete.clearobscaches(self) | |
1169 |
|
1169 | |||
1170 | def invalidatedirstate(self): |
|
1170 | def invalidatedirstate(self): | |
1171 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1171 | '''Invalidates the dirstate, causing the next call to dirstate | |
1172 | to check if it was modified since the last time it was read, |
|
1172 | to check if it was modified since the last time it was read, | |
1173 | rereading it if it has. |
|
1173 | rereading it if it has. | |
1174 |
|
1174 | |||
1175 | This is different to dirstate.invalidate() that it doesn't always |
|
1175 | This is different to dirstate.invalidate() that it doesn't always | |
1176 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1176 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
1177 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1177 | explicitly read the dirstate again (i.e. restoring it to a previous | |
1178 | known good state).''' |
|
1178 | known good state).''' | |
1179 | if hasunfilteredcache(self, 'dirstate'): |
|
1179 | if hasunfilteredcache(self, 'dirstate'): | |
1180 | for k in self.dirstate._filecache: |
|
1180 | for k in self.dirstate._filecache: | |
1181 | try: |
|
1181 | try: | |
1182 | delattr(self.dirstate, k) |
|
1182 | delattr(self.dirstate, k) | |
1183 | except AttributeError: |
|
1183 | except AttributeError: | |
1184 | pass |
|
1184 | pass | |
1185 | delattr(self.unfiltered(), 'dirstate') |
|
1185 | delattr(self.unfiltered(), 'dirstate') | |
1186 |
|
1186 | |||
1187 | def invalidate(self): |
|
1187 | def invalidate(self): | |
1188 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1188 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
1189 | for k in self._filecache: |
|
1189 | for k in self._filecache: | |
1190 | # dirstate is invalidated separately in invalidatedirstate() |
|
1190 | # dirstate is invalidated separately in invalidatedirstate() | |
1191 | if k == 'dirstate': |
|
1191 | if k == 'dirstate': | |
1192 | continue |
|
1192 | continue | |
1193 |
|
1193 | |||
1194 | try: |
|
1194 | try: | |
1195 | delattr(unfiltered, k) |
|
1195 | delattr(unfiltered, k) | |
1196 | except AttributeError: |
|
1196 | except AttributeError: | |
1197 | pass |
|
1197 | pass | |
1198 | self.invalidatecaches() |
|
1198 | self.invalidatecaches() | |
1199 | self.store.invalidatecaches() |
|
1199 | self.store.invalidatecaches() | |
1200 |
|
1200 | |||
1201 | def invalidateall(self): |
|
1201 | def invalidateall(self): | |
1202 | '''Fully invalidates both store and non-store parts, causing the |
|
1202 | '''Fully invalidates both store and non-store parts, causing the | |
1203 | subsequent operation to reread any outside changes.''' |
|
1203 | subsequent operation to reread any outside changes.''' | |
1204 | # extension should hook this to invalidate its caches |
|
1204 | # extension should hook this to invalidate its caches | |
1205 | self.invalidate() |
|
1205 | self.invalidate() | |
1206 | self.invalidatedirstate() |
|
1206 | self.invalidatedirstate() | |
1207 |
|
1207 | |||
1208 | def _refreshfilecachestats(self, tr): |
|
1208 | def _refreshfilecachestats(self, tr): | |
1209 | """Reload stats of cached files so that they are flagged as valid""" |
|
1209 | """Reload stats of cached files so that they are flagged as valid""" | |
1210 | for k, ce in self._filecache.items(): |
|
1210 | for k, ce in self._filecache.items(): | |
1211 | if k == 'dirstate' or k not in self.__dict__: |
|
1211 | if k == 'dirstate' or k not in self.__dict__: | |
1212 | continue |
|
1212 | continue | |
1213 | ce.refresh() |
|
1213 | ce.refresh() | |
1214 |
|
1214 | |||
1215 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1215 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
1216 | parentenvvar=None): |
|
1216 | parentenvvar=None): | |
1217 | parentlock = None |
|
1217 | parentlock = None | |
1218 | if parentenvvar is not None: |
|
1218 | if parentenvvar is not None: | |
1219 | parentlock = os.environ.get(parentenvvar) |
|
1219 | parentlock = os.environ.get(parentenvvar) | |
1220 | try: |
|
1220 | try: | |
1221 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, |
|
1221 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, | |
1222 | acquirefn=acquirefn, desc=desc, |
|
1222 | acquirefn=acquirefn, desc=desc, | |
1223 | parentlock=parentlock) |
|
1223 | parentlock=parentlock) | |
1224 | except error.LockHeld as inst: |
|
1224 | except error.LockHeld as inst: | |
1225 | if not wait: |
|
1225 | if not wait: | |
1226 | raise |
|
1226 | raise | |
1227 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
1227 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
1228 | (desc, inst.locker)) |
|
1228 | (desc, inst.locker)) | |
1229 | # default to 600 seconds timeout |
|
1229 | # default to 600 seconds timeout | |
1230 | l = lockmod.lock(vfs, lockname, |
|
1230 | l = lockmod.lock(vfs, lockname, | |
1231 | int(self.ui.config("ui", "timeout", "600")), |
|
1231 | int(self.ui.config("ui", "timeout", "600")), | |
1232 | releasefn=releasefn, acquirefn=acquirefn, |
|
1232 | releasefn=releasefn, acquirefn=acquirefn, | |
1233 | desc=desc) |
|
1233 | desc=desc) | |
1234 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
1234 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) | |
1235 | return l |
|
1235 | return l | |
1236 |
|
1236 | |||
1237 | def _afterlock(self, callback): |
|
1237 | def _afterlock(self, callback): | |
1238 | """add a callback to be run when the repository is fully unlocked |
|
1238 | """add a callback to be run when the repository is fully unlocked | |
1239 |
|
1239 | |||
1240 | The callback will be executed when the outermost lock is released |
|
1240 | The callback will be executed when the outermost lock is released | |
1241 | (with wlock being higher level than 'lock').""" |
|
1241 | (with wlock being higher level than 'lock').""" | |
1242 | for ref in (self._wlockref, self._lockref): |
|
1242 | for ref in (self._wlockref, self._lockref): | |
1243 | l = ref and ref() |
|
1243 | l = ref and ref() | |
1244 | if l and l.held: |
|
1244 | if l and l.held: | |
1245 | l.postrelease.append(callback) |
|
1245 | l.postrelease.append(callback) | |
1246 | break |
|
1246 | break | |
1247 | else: # no lock have been found. |
|
1247 | else: # no lock have been found. | |
1248 | callback() |
|
1248 | callback() | |
1249 |
|
1249 | |||
1250 | def lock(self, wait=True): |
|
1250 | def lock(self, wait=True): | |
1251 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1251 | '''Lock the repository store (.hg/store) and return a weak reference | |
1252 | to the lock. Use this before modifying the store (e.g. committing or |
|
1252 | to the lock. Use this before modifying the store (e.g. committing or | |
1253 | stripping). If you are opening a transaction, get a lock as well.) |
|
1253 | stripping). If you are opening a transaction, get a lock as well.) | |
1254 |
|
1254 | |||
1255 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1255 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1256 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1256 | 'wlock' first to avoid a dead-lock hazard.''' | |
1257 | l = self._lockref and self._lockref() |
|
1257 | l = self._lockref and self._lockref() | |
1258 | if l is not None and l.held: |
|
1258 | if l is not None and l.held: | |
1259 | l.lock() |
|
1259 | l.lock() | |
1260 | return l |
|
1260 | return l | |
1261 |
|
1261 | |||
1262 | l = self._lock(self.svfs, "lock", wait, None, |
|
1262 | l = self._lock(self.svfs, "lock", wait, None, | |
1263 | self.invalidate, _('repository %s') % self.origroot) |
|
1263 | self.invalidate, _('repository %s') % self.origroot) | |
1264 | self._lockref = weakref.ref(l) |
|
1264 | self._lockref = weakref.ref(l) | |
1265 | return l |
|
1265 | return l | |
1266 |
|
1266 | |||
1267 | def wlock(self, wait=True): |
|
1267 | def wlock(self, wait=True): | |
1268 | '''Lock the non-store parts of the repository (everything under |
|
1268 | '''Lock the non-store parts of the repository (everything under | |
1269 | .hg except .hg/store) and return a weak reference to the lock. |
|
1269 | .hg except .hg/store) and return a weak reference to the lock. | |
1270 |
|
1270 | |||
1271 | Use this before modifying files in .hg. |
|
1271 | Use this before modifying files in .hg. | |
1272 |
|
1272 | |||
1273 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1273 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1274 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1274 | 'wlock' first to avoid a dead-lock hazard.''' | |
1275 | l = self._wlockref and self._wlockref() |
|
1275 | l = self._wlockref and self._wlockref() | |
1276 | if l is not None and l.held: |
|
1276 | if l is not None and l.held: | |
1277 | l.lock() |
|
1277 | l.lock() | |
1278 | return l |
|
1278 | return l | |
1279 |
|
1279 | |||
1280 | # We do not need to check for non-waiting lock aquisition. Such |
|
1280 | # We do not need to check for non-waiting lock aquisition. Such | |
1281 | # acquisition would not cause dead-lock as they would just fail. |
|
1281 | # acquisition would not cause dead-lock as they would just fail. | |
1282 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1282 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
1283 | or self.ui.configbool('devel', 'check-locks')): |
|
1283 | or self.ui.configbool('devel', 'check-locks')): | |
1284 | l = self._lockref and self._lockref() |
|
1284 | l = self._lockref and self._lockref() | |
1285 | if l is not None and l.held: |
|
1285 | if l is not None and l.held: | |
1286 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1286 | self.ui.develwarn('"wlock" acquired after "lock"') | |
1287 |
|
1287 | |||
1288 | def unlock(): |
|
1288 | def unlock(): | |
1289 | if self.dirstate.pendingparentchange(): |
|
1289 | if self.dirstate.pendingparentchange(): | |
1290 | self.dirstate.invalidate() |
|
1290 | self.dirstate.invalidate() | |
1291 | else: |
|
1291 | else: | |
1292 | self.dirstate.write() |
|
1292 | self.dirstate.write() | |
1293 |
|
1293 | |||
1294 | self._filecache['dirstate'].refresh() |
|
1294 | self._filecache['dirstate'].refresh() | |
1295 |
|
1295 | |||
1296 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1296 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
1297 | self.invalidatedirstate, _('working directory of %s') % |
|
1297 | self.invalidatedirstate, _('working directory of %s') % | |
1298 | self.origroot) |
|
1298 | self.origroot) | |
1299 | self._wlockref = weakref.ref(l) |
|
1299 | self._wlockref = weakref.ref(l) | |
1300 | return l |
|
1300 | return l | |
1301 |
|
1301 | |||
1302 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1302 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
1303 | """ |
|
1303 | """ | |
1304 | commit an individual file as part of a larger transaction |
|
1304 | commit an individual file as part of a larger transaction | |
1305 | """ |
|
1305 | """ | |
1306 |
|
1306 | |||
1307 | fname = fctx.path() |
|
1307 | fname = fctx.path() | |
1308 | fparent1 = manifest1.get(fname, nullid) |
|
1308 | fparent1 = manifest1.get(fname, nullid) | |
1309 | fparent2 = manifest2.get(fname, nullid) |
|
1309 | fparent2 = manifest2.get(fname, nullid) | |
1310 | if isinstance(fctx, context.filectx): |
|
1310 | if isinstance(fctx, context.filectx): | |
1311 | node = fctx.filenode() |
|
1311 | node = fctx.filenode() | |
1312 | if node in [fparent1, fparent2]: |
|
1312 | if node in [fparent1, fparent2]: | |
1313 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1313 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
1314 | return node |
|
1314 | return node | |
1315 |
|
1315 | |||
1316 | flog = self.file(fname) |
|
1316 | flog = self.file(fname) | |
1317 | meta = {} |
|
1317 | meta = {} | |
1318 | copy = fctx.renamed() |
|
1318 | copy = fctx.renamed() | |
1319 | if copy and copy[0] != fname: |
|
1319 | if copy and copy[0] != fname: | |
1320 | # Mark the new revision of this file as a copy of another |
|
1320 | # Mark the new revision of this file as a copy of another | |
1321 | # file. This copy data will effectively act as a parent |
|
1321 | # file. This copy data will effectively act as a parent | |
1322 | # of this new revision. If this is a merge, the first |
|
1322 | # of this new revision. If this is a merge, the first | |
1323 | # parent will be the nullid (meaning "look up the copy data") |
|
1323 | # parent will be the nullid (meaning "look up the copy data") | |
1324 | # and the second one will be the other parent. For example: |
|
1324 | # and the second one will be the other parent. For example: | |
1325 | # |
|
1325 | # | |
1326 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1326 | # 0 --- 1 --- 3 rev1 changes file foo | |
1327 | # \ / rev2 renames foo to bar and changes it |
|
1327 | # \ / rev2 renames foo to bar and changes it | |
1328 | # \- 2 -/ rev3 should have bar with all changes and |
|
1328 | # \- 2 -/ rev3 should have bar with all changes and | |
1329 | # should record that bar descends from |
|
1329 | # should record that bar descends from | |
1330 | # bar in rev2 and foo in rev1 |
|
1330 | # bar in rev2 and foo in rev1 | |
1331 | # |
|
1331 | # | |
1332 | # this allows this merge to succeed: |
|
1332 | # this allows this merge to succeed: | |
1333 | # |
|
1333 | # | |
1334 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1334 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1335 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1335 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1336 | # \- 2 --- 4 as the merge base |
|
1336 | # \- 2 --- 4 as the merge base | |
1337 | # |
|
1337 | # | |
1338 |
|
1338 | |||
1339 | cfname = copy[0] |
|
1339 | cfname = copy[0] | |
1340 | crev = manifest1.get(cfname) |
|
1340 | crev = manifest1.get(cfname) | |
1341 | newfparent = fparent2 |
|
1341 | newfparent = fparent2 | |
1342 |
|
1342 | |||
1343 | if manifest2: # branch merge |
|
1343 | if manifest2: # branch merge | |
1344 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1344 | if fparent2 == nullid or crev is None: # copied on remote side | |
1345 | if cfname in manifest2: |
|
1345 | if cfname in manifest2: | |
1346 | crev = manifest2[cfname] |
|
1346 | crev = manifest2[cfname] | |
1347 | newfparent = fparent1 |
|
1347 | newfparent = fparent1 | |
1348 |
|
1348 | |||
1349 | # Here, we used to search backwards through history to try to find |
|
1349 | # Here, we used to search backwards through history to try to find | |
1350 | # where the file copy came from if the source of a copy was not in |
|
1350 | # where the file copy came from if the source of a copy was not in | |
1351 | # the parent directory. However, this doesn't actually make sense to |
|
1351 | # the parent directory. However, this doesn't actually make sense to | |
1352 | # do (what does a copy from something not in your working copy even |
|
1352 | # do (what does a copy from something not in your working copy even | |
1353 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1353 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
1354 | # the user that copy information was dropped, so if they didn't |
|
1354 | # the user that copy information was dropped, so if they didn't | |
1355 | # expect this outcome it can be fixed, but this is the correct |
|
1355 | # expect this outcome it can be fixed, but this is the correct | |
1356 | # behavior in this circumstance. |
|
1356 | # behavior in this circumstance. | |
1357 |
|
1357 | |||
1358 | if crev: |
|
1358 | if crev: | |
1359 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1359 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1360 | meta["copy"] = cfname |
|
1360 | meta["copy"] = cfname | |
1361 | meta["copyrev"] = hex(crev) |
|
1361 | meta["copyrev"] = hex(crev) | |
1362 | fparent1, fparent2 = nullid, newfparent |
|
1362 | fparent1, fparent2 = nullid, newfparent | |
1363 | else: |
|
1363 | else: | |
1364 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1364 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1365 | "copied from '%s'!\n") % (fname, cfname)) |
|
1365 | "copied from '%s'!\n") % (fname, cfname)) | |
1366 |
|
1366 | |||
1367 | elif fparent1 == nullid: |
|
1367 | elif fparent1 == nullid: | |
1368 | fparent1, fparent2 = fparent2, nullid |
|
1368 | fparent1, fparent2 = fparent2, nullid | |
1369 | elif fparent2 != nullid: |
|
1369 | elif fparent2 != nullid: | |
1370 | # is one parent an ancestor of the other? |
|
1370 | # is one parent an ancestor of the other? | |
1371 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1371 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
1372 | if fparent1 in fparentancestors: |
|
1372 | if fparent1 in fparentancestors: | |
1373 | fparent1, fparent2 = fparent2, nullid |
|
1373 | fparent1, fparent2 = fparent2, nullid | |
1374 | elif fparent2 in fparentancestors: |
|
1374 | elif fparent2 in fparentancestors: | |
1375 | fparent2 = nullid |
|
1375 | fparent2 = nullid | |
1376 |
|
1376 | |||
1377 | # is the file changed? |
|
1377 | # is the file changed? | |
1378 | text = fctx.data() |
|
1378 | text = fctx.data() | |
1379 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1379 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1380 | changelist.append(fname) |
|
1380 | changelist.append(fname) | |
1381 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1381 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1382 | # are just the flags changed during merge? |
|
1382 | # are just the flags changed during merge? | |
1383 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1383 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
1384 | changelist.append(fname) |
|
1384 | changelist.append(fname) | |
1385 |
|
1385 | |||
1386 | return fparent1 |
|
1386 | return fparent1 | |
1387 |
|
1387 | |||
1388 | @unfilteredmethod |
|
1388 | @unfilteredmethod | |
1389 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1389 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1390 | editor=False, extra=None): |
|
1390 | editor=False, extra=None): | |
1391 | """Add a new revision to current repository. |
|
1391 | """Add a new revision to current repository. | |
1392 |
|
1392 | |||
1393 | Revision information is gathered from the working directory, |
|
1393 | Revision information is gathered from the working directory, | |
1394 | match can be used to filter the committed files. If editor is |
|
1394 | match can be used to filter the committed files. If editor is | |
1395 | supplied, it is called to get a commit message. |
|
1395 | supplied, it is called to get a commit message. | |
1396 | """ |
|
1396 | """ | |
1397 | if extra is None: |
|
1397 | if extra is None: | |
1398 | extra = {} |
|
1398 | extra = {} | |
1399 |
|
1399 | |||
1400 | def fail(f, msg): |
|
1400 | def fail(f, msg): | |
1401 | raise util.Abort('%s: %s' % (f, msg)) |
|
1401 | raise util.Abort('%s: %s' % (f, msg)) | |
1402 |
|
1402 | |||
1403 | if not match: |
|
1403 | if not match: | |
1404 | match = matchmod.always(self.root, '') |
|
1404 | match = matchmod.always(self.root, '') | |
1405 |
|
1405 | |||
1406 | if not force: |
|
1406 | if not force: | |
1407 | vdirs = [] |
|
1407 | vdirs = [] | |
1408 | match.explicitdir = vdirs.append |
|
1408 | match.explicitdir = vdirs.append | |
1409 | match.bad = fail |
|
1409 | match.bad = fail | |
1410 |
|
1410 | |||
1411 | wlock = self.wlock() |
|
1411 | wlock = self.wlock() | |
1412 | try: |
|
1412 | try: | |
1413 | wctx = self[None] |
|
1413 | wctx = self[None] | |
1414 | merge = len(wctx.parents()) > 1 |
|
1414 | merge = len(wctx.parents()) > 1 | |
1415 |
|
1415 | |||
1416 | if not force and merge and match.ispartial(): |
|
1416 | if not force and merge and match.ispartial(): | |
1417 | raise util.Abort(_('cannot partially commit a merge ' |
|
1417 | raise util.Abort(_('cannot partially commit a merge ' | |
1418 | '(do not specify files or patterns)')) |
|
1418 | '(do not specify files or patterns)')) | |
1419 |
|
1419 | |||
1420 | status = self.status(match=match, clean=force) |
|
1420 | status = self.status(match=match, clean=force) | |
1421 | if force: |
|
1421 | if force: | |
1422 | status.modified.extend(status.clean) # mq may commit clean files |
|
1422 | status.modified.extend(status.clean) # mq may commit clean files | |
1423 |
|
1423 | |||
1424 | # check subrepos |
|
1424 | # check subrepos | |
1425 | subs = [] |
|
1425 | subs = [] | |
1426 | commitsubs = set() |
|
1426 | commitsubs = set() | |
1427 | newstate = wctx.substate.copy() |
|
1427 | newstate = wctx.substate.copy() | |
1428 | # only manage subrepos and .hgsubstate if .hgsub is present |
|
1428 | # only manage subrepos and .hgsubstate if .hgsub is present | |
1429 | if '.hgsub' in wctx: |
|
1429 | if '.hgsub' in wctx: | |
1430 | # we'll decide whether to track this ourselves, thanks |
|
1430 | # we'll decide whether to track this ourselves, thanks | |
1431 | for c in status.modified, status.added, status.removed: |
|
1431 | for c in status.modified, status.added, status.removed: | |
1432 | if '.hgsubstate' in c: |
|
1432 | if '.hgsubstate' in c: | |
1433 | c.remove('.hgsubstate') |
|
1433 | c.remove('.hgsubstate') | |
1434 |
|
1434 | |||
1435 | # compare current state to last committed state |
|
1435 | # compare current state to last committed state | |
1436 | # build new substate based on last committed state |
|
1436 | # build new substate based on last committed state | |
1437 | oldstate = wctx.p1().substate |
|
1437 | oldstate = wctx.p1().substate | |
1438 | for s in sorted(newstate.keys()): |
|
1438 | for s in sorted(newstate.keys()): | |
1439 | if not match(s): |
|
1439 | if not match(s): | |
1440 | # ignore working copy, use old state if present |
|
1440 | # ignore working copy, use old state if present | |
1441 | if s in oldstate: |
|
1441 | if s in oldstate: | |
1442 | newstate[s] = oldstate[s] |
|
1442 | newstate[s] = oldstate[s] | |
1443 | continue |
|
1443 | continue | |
1444 | if not force: |
|
1444 | if not force: | |
1445 | raise util.Abort( |
|
1445 | raise util.Abort( | |
1446 | _("commit with new subrepo %s excluded") % s) |
|
1446 | _("commit with new subrepo %s excluded") % s) | |
1447 | dirtyreason = wctx.sub(s).dirtyreason(True) |
|
1447 | dirtyreason = wctx.sub(s).dirtyreason(True) | |
1448 | if dirtyreason: |
|
1448 | if dirtyreason: | |
1449 | if not self.ui.configbool('ui', 'commitsubrepos'): |
|
1449 | if not self.ui.configbool('ui', 'commitsubrepos'): | |
1450 | raise util.Abort(dirtyreason, |
|
1450 | raise util.Abort(dirtyreason, | |
1451 | hint=_("use --subrepos for recursive commit")) |
|
1451 | hint=_("use --subrepos for recursive commit")) | |
1452 | subs.append(s) |
|
1452 | subs.append(s) | |
1453 | commitsubs.add(s) |
|
1453 | commitsubs.add(s) | |
1454 | else: |
|
1454 | else: | |
1455 | bs = wctx.sub(s).basestate() |
|
1455 | bs = wctx.sub(s).basestate() | |
1456 | newstate[s] = (newstate[s][0], bs, newstate[s][2]) |
|
1456 | newstate[s] = (newstate[s][0], bs, newstate[s][2]) | |
1457 | if oldstate.get(s, (None, None, None))[1] != bs: |
|
1457 | if oldstate.get(s, (None, None, None))[1] != bs: | |
1458 | subs.append(s) |
|
1458 | subs.append(s) | |
1459 |
|
1459 | |||
1460 | # check for removed subrepos |
|
1460 | # check for removed subrepos | |
1461 | for p in wctx.parents(): |
|
1461 | for p in wctx.parents(): | |
1462 | r = [s for s in p.substate if s not in newstate] |
|
1462 | r = [s for s in p.substate if s not in newstate] | |
1463 | subs += [s for s in r if match(s)] |
|
1463 | subs += [s for s in r if match(s)] | |
1464 | if subs: |
|
1464 | if subs: | |
1465 | if (not match('.hgsub') and |
|
1465 | if (not match('.hgsub') and | |
1466 | '.hgsub' in (wctx.modified() + wctx.added())): |
|
1466 | '.hgsub' in (wctx.modified() + wctx.added())): | |
1467 | raise util.Abort( |
|
1467 | raise util.Abort( | |
1468 | _("can't commit subrepos without .hgsub")) |
|
1468 | _("can't commit subrepos without .hgsub")) | |
1469 | status.modified.insert(0, '.hgsubstate') |
|
1469 | status.modified.insert(0, '.hgsubstate') | |
1470 |
|
1470 | |||
1471 | elif '.hgsub' in status.removed: |
|
1471 | elif '.hgsub' in status.removed: | |
1472 | # clean up .hgsubstate when .hgsub is removed |
|
1472 | # clean up .hgsubstate when .hgsub is removed | |
1473 | if ('.hgsubstate' in wctx and |
|
1473 | if ('.hgsubstate' in wctx and | |
1474 | '.hgsubstate' not in (status.modified + status.added + |
|
1474 | '.hgsubstate' not in (status.modified + status.added + | |
1475 | status.removed)): |
|
1475 | status.removed)): | |
1476 | status.removed.insert(0, '.hgsubstate') |
|
1476 | status.removed.insert(0, '.hgsubstate') | |
1477 |
|
1477 | |||
1478 | # make sure all explicit patterns are matched |
|
1478 | # make sure all explicit patterns are matched | |
1479 | if not force and (match.isexact() or match.prefix()): |
|
1479 | if not force and (match.isexact() or match.prefix()): | |
1480 | matched = set(status.modified + status.added + status.removed) |
|
1480 | matched = set(status.modified + status.added + status.removed) | |
1481 |
|
1481 | |||
1482 | for f in match.files(): |
|
1482 | for f in match.files(): | |
1483 | f = self.dirstate.normalize(f) |
|
1483 | f = self.dirstate.normalize(f) | |
1484 | if f == '.' or f in matched or f in wctx.substate: |
|
1484 | if f == '.' or f in matched or f in wctx.substate: | |
1485 | continue |
|
1485 | continue | |
1486 | if f in status.deleted: |
|
1486 | if f in status.deleted: | |
1487 | fail(f, _('file not found!')) |
|
1487 | fail(f, _('file not found!')) | |
1488 | if f in vdirs: # visited directory |
|
1488 | if f in vdirs: # visited directory | |
1489 | d = f + '/' |
|
1489 | d = f + '/' | |
1490 | for mf in matched: |
|
1490 | for mf in matched: | |
1491 | if mf.startswith(d): |
|
1491 | if mf.startswith(d): | |
1492 | break |
|
1492 | break | |
1493 | else: |
|
1493 | else: | |
1494 | fail(f, _("no match under directory!")) |
|
1494 | fail(f, _("no match under directory!")) | |
1495 | elif f not in self.dirstate: |
|
1495 | elif f not in self.dirstate: | |
1496 | fail(f, _("file not tracked!")) |
|
1496 | fail(f, _("file not tracked!")) | |
1497 |
|
1497 | |||
1498 | cctx = context.workingcommitctx(self, status, |
|
1498 | cctx = context.workingcommitctx(self, status, | |
1499 | text, user, date, extra) |
|
1499 | text, user, date, extra) | |
1500 |
|
1500 | |||
1501 | # internal config: ui.allowemptycommit |
|
1501 | # internal config: ui.allowemptycommit | |
1502 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1502 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
1503 | or extra.get('close') or merge or cctx.files() |
|
1503 | or extra.get('close') or merge or cctx.files() | |
1504 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1504 | or self.ui.configbool('ui', 'allowemptycommit')) | |
1505 | if not allowemptycommit: |
|
1505 | if not allowemptycommit: | |
1506 | return None |
|
1506 | return None | |
1507 |
|
1507 | |||
1508 | if merge and cctx.deleted(): |
|
1508 | if merge and cctx.deleted(): | |
1509 | raise util.Abort(_("cannot commit merge with missing files")) |
|
1509 | raise util.Abort(_("cannot commit merge with missing files")) | |
1510 |
|
1510 | |||
1511 | ms = mergemod.mergestate(self) |
|
1511 | ms = mergemod.mergestate(self) | |
1512 | for f in status.modified: |
|
1512 | for f in status.modified: | |
1513 | if f in ms and ms[f] == 'u': |
|
1513 | if f in ms and ms[f] == 'u': | |
1514 | raise util.Abort(_('unresolved merge conflicts ' |
|
1514 | raise util.Abort(_('unresolved merge conflicts ' | |
1515 | '(see "hg help resolve")')) |
|
1515 | '(see "hg help resolve")')) | |
1516 |
|
1516 | |||
1517 | if editor: |
|
1517 | if editor: | |
1518 | cctx._text = editor(self, cctx, subs) |
|
1518 | cctx._text = editor(self, cctx, subs) | |
1519 | edited = (text != cctx._text) |
|
1519 | edited = (text != cctx._text) | |
1520 |
|
1520 | |||
1521 | # Save commit message in case this transaction gets rolled back |
|
1521 | # Save commit message in case this transaction gets rolled back | |
1522 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1522 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1523 | # the assumption that the user will use the same editor again. |
|
1523 | # the assumption that the user will use the same editor again. | |
1524 | msgfn = self.savecommitmessage(cctx._text) |
|
1524 | msgfn = self.savecommitmessage(cctx._text) | |
1525 |
|
1525 | |||
1526 | # commit subs and write new state |
|
1526 | # commit subs and write new state | |
1527 | if subs: |
|
1527 | if subs: | |
1528 | for s in sorted(commitsubs): |
|
1528 | for s in sorted(commitsubs): | |
1529 | sub = wctx.sub(s) |
|
1529 | sub = wctx.sub(s) | |
1530 | self.ui.status(_('committing subrepository %s\n') % |
|
1530 | self.ui.status(_('committing subrepository %s\n') % | |
1531 | subrepo.subrelpath(sub)) |
|
1531 | subrepo.subrelpath(sub)) | |
1532 | sr = sub.commit(cctx._text, user, date) |
|
1532 | sr = sub.commit(cctx._text, user, date) | |
1533 | newstate[s] = (newstate[s][0], sr) |
|
1533 | newstate[s] = (newstate[s][0], sr) | |
1534 | subrepo.writestate(self, newstate) |
|
1534 | subrepo.writestate(self, newstate) | |
1535 |
|
1535 | |||
1536 | p1, p2 = self.dirstate.parents() |
|
1536 | p1, p2 = self.dirstate.parents() | |
1537 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1537 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1538 | try: |
|
1538 | try: | |
1539 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1539 | self.hook("precommit", throw=True, parent1=hookp1, | |
1540 | parent2=hookp2) |
|
1540 | parent2=hookp2) | |
1541 | ret = self.commitctx(cctx, True) |
|
1541 | ret = self.commitctx(cctx, True) | |
1542 | except: # re-raises |
|
1542 | except: # re-raises | |
1543 | if edited: |
|
1543 | if edited: | |
1544 | self.ui.write( |
|
1544 | self.ui.write( | |
1545 | _('note: commit message saved in %s\n') % msgfn) |
|
1545 | _('note: commit message saved in %s\n') % msgfn) | |
1546 | raise |
|
1546 | raise | |
1547 |
|
1547 | |||
1548 | # update bookmarks, dirstate and mergestate |
|
1548 | # update bookmarks, dirstate and mergestate | |
1549 | bookmarks.update(self, [p1, p2], ret) |
|
1549 | bookmarks.update(self, [p1, p2], ret) | |
1550 | cctx.markcommitted(ret) |
|
1550 | cctx.markcommitted(ret) | |
1551 | ms.reset() |
|
1551 | ms.reset() | |
1552 | finally: |
|
1552 | finally: | |
1553 | wlock.release() |
|
1553 | wlock.release() | |
1554 |
|
1554 | |||
1555 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1555 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
1556 | # hack for command that use a temporary commit (eg: histedit) |
|
1556 | # hack for command that use a temporary commit (eg: histedit) | |
1557 | # temporary commit got stripped before hook release |
|
1557 | # temporary commit got stripped before hook release | |
1558 | if self.changelog.hasnode(ret): |
|
1558 | if self.changelog.hasnode(ret): | |
1559 | self.hook("commit", node=node, parent1=parent1, |
|
1559 | self.hook("commit", node=node, parent1=parent1, | |
1560 | parent2=parent2) |
|
1560 | parent2=parent2) | |
1561 | self._afterlock(commithook) |
|
1561 | self._afterlock(commithook) | |
1562 | return ret |
|
1562 | return ret | |
1563 |
|
1563 | |||
1564 | @unfilteredmethod |
|
1564 | @unfilteredmethod | |
1565 | def commitctx(self, ctx, error=False): |
|
1565 | def commitctx(self, ctx, error=False): | |
1566 | """Add a new revision to current repository. |
|
1566 | """Add a new revision to current repository. | |
1567 | Revision information is passed via the context argument. |
|
1567 | Revision information is passed via the context argument. | |
1568 | """ |
|
1568 | """ | |
1569 |
|
1569 | |||
1570 | tr = None |
|
1570 | tr = None | |
1571 | p1, p2 = ctx.p1(), ctx.p2() |
|
1571 | p1, p2 = ctx.p1(), ctx.p2() | |
1572 | user = ctx.user() |
|
1572 | user = ctx.user() | |
1573 |
|
1573 | |||
1574 | lock = self.lock() |
|
1574 | lock = self.lock() | |
1575 | try: |
|
1575 | try: | |
1576 | tr = self.transaction("commit") |
|
1576 | tr = self.transaction("commit") | |
1577 | trp = weakref.proxy(tr) |
|
1577 | trp = weakref.proxy(tr) | |
1578 |
|
1578 | |||
1579 | if ctx.files(): |
|
1579 | if ctx.files(): | |
1580 | m1 = p1.manifest() |
|
1580 | m1 = p1.manifest() | |
1581 | m2 = p2.manifest() |
|
1581 | m2 = p2.manifest() | |
1582 | m = m1.copy() |
|
1582 | m = m1.copy() | |
1583 |
|
1583 | |||
1584 | # check in files |
|
1584 | # check in files | |
1585 | added = [] |
|
1585 | added = [] | |
1586 | changed = [] |
|
1586 | changed = [] | |
1587 | removed = list(ctx.removed()) |
|
1587 | removed = list(ctx.removed()) | |
1588 | linkrev = len(self) |
|
1588 | linkrev = len(self) | |
1589 | self.ui.note(_("committing files:\n")) |
|
1589 | self.ui.note(_("committing files:\n")) | |
1590 | for f in sorted(ctx.modified() + ctx.added()): |
|
1590 | for f in sorted(ctx.modified() + ctx.added()): | |
1591 | self.ui.note(f + "\n") |
|
1591 | self.ui.note(f + "\n") | |
1592 | try: |
|
1592 | try: | |
1593 | fctx = ctx[f] |
|
1593 | fctx = ctx[f] | |
1594 | if fctx is None: |
|
1594 | if fctx is None: | |
1595 | removed.append(f) |
|
1595 | removed.append(f) | |
1596 | else: |
|
1596 | else: | |
1597 | added.append(f) |
|
1597 | added.append(f) | |
1598 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
1598 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
1599 | trp, changed) |
|
1599 | trp, changed) | |
1600 | m.setflag(f, fctx.flags()) |
|
1600 | m.setflag(f, fctx.flags()) | |
1601 | except OSError as inst: |
|
1601 | except OSError as inst: | |
1602 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1602 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1603 | raise |
|
1603 | raise | |
1604 | except IOError as inst: |
|
1604 | except IOError as inst: | |
1605 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1605 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
1606 | if error or errcode and errcode != errno.ENOENT: |
|
1606 | if error or errcode and errcode != errno.ENOENT: | |
1607 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1607 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1608 | raise |
|
1608 | raise | |
1609 |
|
1609 | |||
1610 | # update manifest |
|
1610 | # update manifest | |
1611 | self.ui.note(_("committing manifest\n")) |
|
1611 | self.ui.note(_("committing manifest\n")) | |
1612 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
1612 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
1613 | drop = [f for f in removed if f in m] |
|
1613 | drop = [f for f in removed if f in m] | |
1614 | for f in drop: |
|
1614 | for f in drop: | |
1615 | del m[f] |
|
1615 | del m[f] | |
1616 | mn = self.manifest.add(m, trp, linkrev, |
|
1616 | mn = self.manifest.add(m, trp, linkrev, | |
1617 | p1.manifestnode(), p2.manifestnode(), |
|
1617 | p1.manifestnode(), p2.manifestnode(), | |
1618 | added, drop) |
|
1618 | added, drop) | |
1619 | files = changed + removed |
|
1619 | files = changed + removed | |
1620 | else: |
|
1620 | else: | |
1621 | mn = p1.manifestnode() |
|
1621 | mn = p1.manifestnode() | |
1622 | files = [] |
|
1622 | files = [] | |
1623 |
|
1623 | |||
1624 | # update changelog |
|
1624 | # update changelog | |
1625 | self.ui.note(_("committing changelog\n")) |
|
1625 | self.ui.note(_("committing changelog\n")) | |
1626 | self.changelog.delayupdate(tr) |
|
1626 | self.changelog.delayupdate(tr) | |
1627 | n = self.changelog.add(mn, files, ctx.description(), |
|
1627 | n = self.changelog.add(mn, files, ctx.description(), | |
1628 | trp, p1.node(), p2.node(), |
|
1628 | trp, p1.node(), p2.node(), | |
1629 | user, ctx.date(), ctx.extra().copy()) |
|
1629 | user, ctx.date(), ctx.extra().copy()) | |
1630 | p = lambda: tr.writepending() and self.root or "" |
|
1630 | p = lambda: tr.writepending() and self.root or "" | |
1631 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
1631 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
1632 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
1632 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
1633 | parent2=xp2, pending=p) |
|
1633 | parent2=xp2, pending=p) | |
1634 | # set the new commit is proper phase |
|
1634 | # set the new commit is proper phase | |
1635 | targetphase = subrepo.newcommitphase(self.ui, ctx) |
|
1635 | targetphase = subrepo.newcommitphase(self.ui, ctx) | |
1636 | if targetphase: |
|
1636 | if targetphase: | |
1637 | # retract boundary do not alter parent changeset. |
|
1637 | # retract boundary do not alter parent changeset. | |
1638 | # if a parent have higher the resulting phase will |
|
1638 | # if a parent have higher the resulting phase will | |
1639 | # be compliant anyway |
|
1639 | # be compliant anyway | |
1640 | # |
|
1640 | # | |
1641 | # if minimal phase was 0 we don't need to retract anything |
|
1641 | # if minimal phase was 0 we don't need to retract anything | |
1642 | phases.retractboundary(self, tr, targetphase, [n]) |
|
1642 | phases.retractboundary(self, tr, targetphase, [n]) | |
1643 | tr.close() |
|
1643 | tr.close() | |
1644 | branchmap.updatecache(self.filtered('served')) |
|
1644 | branchmap.updatecache(self.filtered('served')) | |
1645 | return n |
|
1645 | return n | |
1646 | finally: |
|
1646 | finally: | |
1647 | if tr: |
|
1647 | if tr: | |
1648 | tr.release() |
|
1648 | tr.release() | |
1649 | lock.release() |
|
1649 | lock.release() | |
1650 |
|
1650 | |||
1651 | @unfilteredmethod |
|
1651 | @unfilteredmethod | |
1652 | def destroying(self): |
|
1652 | def destroying(self): | |
1653 | '''Inform the repository that nodes are about to be destroyed. |
|
1653 | '''Inform the repository that nodes are about to be destroyed. | |
1654 | Intended for use by strip and rollback, so there's a common |
|
1654 | Intended for use by strip and rollback, so there's a common | |
1655 | place for anything that has to be done before destroying history. |
|
1655 | place for anything that has to be done before destroying history. | |
1656 |
|
1656 | |||
1657 | This is mostly useful for saving state that is in memory and waiting |
|
1657 | This is mostly useful for saving state that is in memory and waiting | |
1658 | to be flushed when the current lock is released. Because a call to |
|
1658 | to be flushed when the current lock is released. Because a call to | |
1659 | destroyed is imminent, the repo will be invalidated causing those |
|
1659 | destroyed is imminent, the repo will be invalidated causing those | |
1660 | changes to stay in memory (waiting for the next unlock), or vanish |
|
1660 | changes to stay in memory (waiting for the next unlock), or vanish | |
1661 | completely. |
|
1661 | completely. | |
1662 | ''' |
|
1662 | ''' | |
1663 | # When using the same lock to commit and strip, the phasecache is left |
|
1663 | # When using the same lock to commit and strip, the phasecache is left | |
1664 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
1664 | # dirty after committing. Then when we strip, the repo is invalidated, | |
1665 | # causing those changes to disappear. |
|
1665 | # causing those changes to disappear. | |
1666 | if '_phasecache' in vars(self): |
|
1666 | if '_phasecache' in vars(self): | |
1667 | self._phasecache.write() |
|
1667 | self._phasecache.write() | |
1668 |
|
1668 | |||
1669 | @unfilteredmethod |
|
1669 | @unfilteredmethod | |
1670 | def destroyed(self): |
|
1670 | def destroyed(self): | |
1671 | '''Inform the repository that nodes have been destroyed. |
|
1671 | '''Inform the repository that nodes have been destroyed. | |
1672 | Intended for use by strip and rollback, so there's a common |
|
1672 | Intended for use by strip and rollback, so there's a common | |
1673 | place for anything that has to be done after destroying history. |
|
1673 | place for anything that has to be done after destroying history. | |
1674 | ''' |
|
1674 | ''' | |
1675 | # When one tries to: |
|
1675 | # When one tries to: | |
1676 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
1676 | # 1) destroy nodes thus calling this method (e.g. strip) | |
1677 | # 2) use phasecache somewhere (e.g. commit) |
|
1677 | # 2) use phasecache somewhere (e.g. commit) | |
1678 | # |
|
1678 | # | |
1679 | # then 2) will fail because the phasecache contains nodes that were |
|
1679 | # then 2) will fail because the phasecache contains nodes that were | |
1680 | # removed. We can either remove phasecache from the filecache, |
|
1680 | # removed. We can either remove phasecache from the filecache, | |
1681 | # causing it to reload next time it is accessed, or simply filter |
|
1681 | # causing it to reload next time it is accessed, or simply filter | |
1682 | # the removed nodes now and write the updated cache. |
|
1682 | # the removed nodes now and write the updated cache. | |
1683 | self._phasecache.filterunknown(self) |
|
1683 | self._phasecache.filterunknown(self) | |
1684 | self._phasecache.write() |
|
1684 | self._phasecache.write() | |
1685 |
|
1685 | |||
1686 | # update the 'served' branch cache to help read only server process |
|
1686 | # update the 'served' branch cache to help read only server process | |
1687 | # Thanks to branchcache collaboration this is done from the nearest |
|
1687 | # Thanks to branchcache collaboration this is done from the nearest | |
1688 | # filtered subset and it is expected to be fast. |
|
1688 | # filtered subset and it is expected to be fast. | |
1689 | branchmap.updatecache(self.filtered('served')) |
|
1689 | branchmap.updatecache(self.filtered('served')) | |
1690 |
|
1690 | |||
1691 | # Ensure the persistent tag cache is updated. Doing it now |
|
1691 | # Ensure the persistent tag cache is updated. Doing it now | |
1692 | # means that the tag cache only has to worry about destroyed |
|
1692 | # means that the tag cache only has to worry about destroyed | |
1693 | # heads immediately after a strip/rollback. That in turn |
|
1693 | # heads immediately after a strip/rollback. That in turn | |
1694 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
1694 | # guarantees that "cachetip == currenttip" (comparing both rev | |
1695 | # and node) always means no nodes have been added or destroyed. |
|
1695 | # and node) always means no nodes have been added or destroyed. | |
1696 |
|
1696 | |||
1697 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
1697 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
1698 | # head, refresh the tag cache, then immediately add a new head. |
|
1698 | # head, refresh the tag cache, then immediately add a new head. | |
1699 | # But I think doing it this way is necessary for the "instant |
|
1699 | # But I think doing it this way is necessary for the "instant | |
1700 | # tag cache retrieval" case to work. |
|
1700 | # tag cache retrieval" case to work. | |
1701 | self.invalidate() |
|
1701 | self.invalidate() | |
1702 |
|
1702 | |||
1703 | def walk(self, match, node=None): |
|
1703 | def walk(self, match, node=None): | |
1704 | ''' |
|
1704 | ''' | |
1705 | walk recursively through the directory tree or a given |
|
1705 | walk recursively through the directory tree or a given | |
1706 | changeset, finding all files matched by the match |
|
1706 | changeset, finding all files matched by the match | |
1707 | function |
|
1707 | function | |
1708 | ''' |
|
1708 | ''' | |
1709 | return self[node].walk(match) |
|
1709 | return self[node].walk(match) | |
1710 |
|
1710 | |||
1711 | def status(self, node1='.', node2=None, match=None, |
|
1711 | def status(self, node1='.', node2=None, match=None, | |
1712 | ignored=False, clean=False, unknown=False, |
|
1712 | ignored=False, clean=False, unknown=False, | |
1713 | listsubrepos=False): |
|
1713 | listsubrepos=False): | |
1714 | '''a convenience method that calls node1.status(node2)''' |
|
1714 | '''a convenience method that calls node1.status(node2)''' | |
1715 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
1715 | return self[node1].status(node2, match, ignored, clean, unknown, | |
1716 | listsubrepos) |
|
1716 | listsubrepos) | |
1717 |
|
1717 | |||
1718 | def heads(self, start=None): |
|
1718 | def heads(self, start=None): | |
1719 | heads = self.changelog.heads(start) |
|
1719 | heads = self.changelog.heads(start) | |
1720 | # sort the output in rev descending order |
|
1720 | # sort the output in rev descending order | |
1721 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
1721 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
1722 |
|
1722 | |||
1723 | def branchheads(self, branch=None, start=None, closed=False): |
|
1723 | def branchheads(self, branch=None, start=None, closed=False): | |
1724 | '''return a (possibly filtered) list of heads for the given branch |
|
1724 | '''return a (possibly filtered) list of heads for the given branch | |
1725 |
|
1725 | |||
1726 | Heads are returned in topological order, from newest to oldest. |
|
1726 | Heads are returned in topological order, from newest to oldest. | |
1727 | If branch is None, use the dirstate branch. |
|
1727 | If branch is None, use the dirstate branch. | |
1728 | If start is not None, return only heads reachable from start. |
|
1728 | If start is not None, return only heads reachable from start. | |
1729 | If closed is True, return heads that are marked as closed as well. |
|
1729 | If closed is True, return heads that are marked as closed as well. | |
1730 | ''' |
|
1730 | ''' | |
1731 | if branch is None: |
|
1731 | if branch is None: | |
1732 | branch = self[None].branch() |
|
1732 | branch = self[None].branch() | |
1733 | branches = self.branchmap() |
|
1733 | branches = self.branchmap() | |
1734 | if branch not in branches: |
|
1734 | if branch not in branches: | |
1735 | return [] |
|
1735 | return [] | |
1736 | # the cache returns heads ordered lowest to highest |
|
1736 | # the cache returns heads ordered lowest to highest | |
1737 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
1737 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
1738 | if start is not None: |
|
1738 | if start is not None: | |
1739 | # filter out the heads that cannot be reached from startrev |
|
1739 | # filter out the heads that cannot be reached from startrev | |
1740 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1740 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1741 | bheads = [h for h in bheads if h in fbheads] |
|
1741 | bheads = [h for h in bheads if h in fbheads] | |
1742 | return bheads |
|
1742 | return bheads | |
1743 |
|
1743 | |||
1744 | def branches(self, nodes): |
|
1744 | def branches(self, nodes): | |
1745 | if not nodes: |
|
1745 | if not nodes: | |
1746 | nodes = [self.changelog.tip()] |
|
1746 | nodes = [self.changelog.tip()] | |
1747 | b = [] |
|
1747 | b = [] | |
1748 | for n in nodes: |
|
1748 | for n in nodes: | |
1749 | t = n |
|
1749 | t = n | |
1750 | while True: |
|
1750 | while True: | |
1751 | p = self.changelog.parents(n) |
|
1751 | p = self.changelog.parents(n) | |
1752 | if p[1] != nullid or p[0] == nullid: |
|
1752 | if p[1] != nullid or p[0] == nullid: | |
1753 | b.append((t, n, p[0], p[1])) |
|
1753 | b.append((t, n, p[0], p[1])) | |
1754 | break |
|
1754 | break | |
1755 | n = p[0] |
|
1755 | n = p[0] | |
1756 | return b |
|
1756 | return b | |
1757 |
|
1757 | |||
1758 | def between(self, pairs): |
|
1758 | def between(self, pairs): | |
1759 | r = [] |
|
1759 | r = [] | |
1760 |
|
1760 | |||
1761 | for top, bottom in pairs: |
|
1761 | for top, bottom in pairs: | |
1762 | n, l, i = top, [], 0 |
|
1762 | n, l, i = top, [], 0 | |
1763 | f = 1 |
|
1763 | f = 1 | |
1764 |
|
1764 | |||
1765 | while n != bottom and n != nullid: |
|
1765 | while n != bottom and n != nullid: | |
1766 | p = self.changelog.parents(n)[0] |
|
1766 | p = self.changelog.parents(n)[0] | |
1767 | if i == f: |
|
1767 | if i == f: | |
1768 | l.append(n) |
|
1768 | l.append(n) | |
1769 | f = f * 2 |
|
1769 | f = f * 2 | |
1770 | n = p |
|
1770 | n = p | |
1771 | i += 1 |
|
1771 | i += 1 | |
1772 |
|
1772 | |||
1773 | r.append(l) |
|
1773 | r.append(l) | |
1774 |
|
1774 | |||
1775 | return r |
|
1775 | return r | |
1776 |
|
1776 | |||
1777 | def checkpush(self, pushop): |
|
1777 | def checkpush(self, pushop): | |
1778 | """Extensions can override this function if additional checks have |
|
1778 | """Extensions can override this function if additional checks have | |
1779 | to be performed before pushing, or call it if they override push |
|
1779 | to be performed before pushing, or call it if they override push | |
1780 | command. |
|
1780 | command. | |
1781 | """ |
|
1781 | """ | |
1782 | pass |
|
1782 | pass | |
1783 |
|
1783 | |||
1784 | @unfilteredpropertycache |
|
1784 | @unfilteredpropertycache | |
1785 | def prepushoutgoinghooks(self): |
|
1785 | def prepushoutgoinghooks(self): | |
1786 | """Return util.hooks consists of "(repo, remote, outgoing)" |
|
1786 | """Return util.hooks consists of "(repo, remote, outgoing)" | |
1787 | functions, which are called before pushing changesets. |
|
1787 | functions, which are called before pushing changesets. | |
1788 | """ |
|
1788 | """ | |
1789 | return util.hooks() |
|
1789 | return util.hooks() | |
1790 |
|
1790 | |||
1791 | def clone(self, remote, heads=[], stream=None): |
|
1791 | def clone(self, remote, heads=[], stream=None): | |
1792 | '''clone remote repository. |
|
1792 | '''clone remote repository. | |
1793 |
|
1793 | |||
1794 | keyword arguments: |
|
1794 | keyword arguments: | |
1795 | heads: list of revs to clone (forces use of pull) |
|
1795 | heads: list of revs to clone (forces use of pull) | |
1796 | stream: use streaming clone if possible''' |
|
1796 | stream: use streaming clone if possible''' | |
1797 |
|
1797 | streamclone.maybeperformstreamclone(self, remote, heads, stream) | ||
1798 | # now, all clients that can request uncompressed clones can |
|
|||
1799 | # read repo formats supported by all servers that can serve |
|
|||
1800 | # them. |
|
|||
1801 |
|
||||
1802 | # if revlog format changes, client will have to check version |
|
|||
1803 | # and format flags on "stream" capability, and use |
|
|||
1804 | # uncompressed only if compatible. |
|
|||
1805 |
|
||||
1806 | if stream is None: |
|
|||
1807 | # if the server explicitly prefers to stream (for fast LANs) |
|
|||
1808 | stream = remote.capable('stream-preferred') |
|
|||
1809 |
|
||||
1810 | if stream and not heads: |
|
|||
1811 | # 'stream' means remote revlog format is revlogv1 only |
|
|||
1812 | if remote.capable('stream'): |
|
|||
1813 | streamclone.streamin(self, remote, set(('revlogv1',))) |
|
|||
1814 | else: |
|
|||
1815 | # otherwise, 'streamreqs' contains the remote revlog format |
|
|||
1816 | streamreqs = remote.capable('streamreqs') |
|
|||
1817 | if streamreqs: |
|
|||
1818 | streamreqs = set(streamreqs.split(',')) |
|
|||
1819 | # if we support it, stream in and adjust our requirements |
|
|||
1820 | if not streamreqs - self.supportedformats: |
|
|||
1821 | streamclone.streamin(self, remote, streamreqs) |
|
|||
1822 |
|
1798 | |||
1823 | # internal config: ui.quietbookmarkmove |
|
1799 | # internal config: ui.quietbookmarkmove | |
1824 | quiet = self.ui.backupconfig('ui', 'quietbookmarkmove') |
|
1800 | quiet = self.ui.backupconfig('ui', 'quietbookmarkmove') | |
1825 | try: |
|
1801 | try: | |
1826 | self.ui.setconfig('ui', 'quietbookmarkmove', True, 'clone') |
|
1802 | self.ui.setconfig('ui', 'quietbookmarkmove', True, 'clone') | |
1827 | ret = exchange.pull(self, remote, heads).cgresult |
|
1803 | ret = exchange.pull(self, remote, heads).cgresult | |
1828 | finally: |
|
1804 | finally: | |
1829 | self.ui.restoreconfig(quiet) |
|
1805 | self.ui.restoreconfig(quiet) | |
1830 | return ret |
|
1806 | return ret | |
1831 |
|
1807 | |||
1832 | def pushkey(self, namespace, key, old, new): |
|
1808 | def pushkey(self, namespace, key, old, new): | |
1833 | try: |
|
1809 | try: | |
1834 | tr = self.currenttransaction() |
|
1810 | tr = self.currenttransaction() | |
1835 | hookargs = {} |
|
1811 | hookargs = {} | |
1836 | if tr is not None: |
|
1812 | if tr is not None: | |
1837 | hookargs.update(tr.hookargs) |
|
1813 | hookargs.update(tr.hookargs) | |
1838 | pending = lambda: tr.writepending() and self.root or "" |
|
1814 | pending = lambda: tr.writepending() and self.root or "" | |
1839 | hookargs['pending'] = pending |
|
1815 | hookargs['pending'] = pending | |
1840 | hookargs['namespace'] = namespace |
|
1816 | hookargs['namespace'] = namespace | |
1841 | hookargs['key'] = key |
|
1817 | hookargs['key'] = key | |
1842 | hookargs['old'] = old |
|
1818 | hookargs['old'] = old | |
1843 | hookargs['new'] = new |
|
1819 | hookargs['new'] = new | |
1844 | self.hook('prepushkey', throw=True, **hookargs) |
|
1820 | self.hook('prepushkey', throw=True, **hookargs) | |
1845 | except error.HookAbort as exc: |
|
1821 | except error.HookAbort as exc: | |
1846 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
1822 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
1847 | if exc.hint: |
|
1823 | if exc.hint: | |
1848 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
1824 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
1849 | return False |
|
1825 | return False | |
1850 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
1826 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
1851 | ret = pushkey.push(self, namespace, key, old, new) |
|
1827 | ret = pushkey.push(self, namespace, key, old, new) | |
1852 | def runhook(): |
|
1828 | def runhook(): | |
1853 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
1829 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
1854 | ret=ret) |
|
1830 | ret=ret) | |
1855 | self._afterlock(runhook) |
|
1831 | self._afterlock(runhook) | |
1856 | return ret |
|
1832 | return ret | |
1857 |
|
1833 | |||
1858 | def listkeys(self, namespace): |
|
1834 | def listkeys(self, namespace): | |
1859 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
1835 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
1860 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
1836 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
1861 | values = pushkey.list(self, namespace) |
|
1837 | values = pushkey.list(self, namespace) | |
1862 | self.hook('listkeys', namespace=namespace, values=values) |
|
1838 | self.hook('listkeys', namespace=namespace, values=values) | |
1863 | return values |
|
1839 | return values | |
1864 |
|
1840 | |||
1865 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
1841 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
1866 | '''used to test argument passing over the wire''' |
|
1842 | '''used to test argument passing over the wire''' | |
1867 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
1843 | return "%s %s %s %s %s" % (one, two, three, four, five) | |
1868 |
|
1844 | |||
1869 | def savecommitmessage(self, text): |
|
1845 | def savecommitmessage(self, text): | |
1870 | fp = self.vfs('last-message.txt', 'wb') |
|
1846 | fp = self.vfs('last-message.txt', 'wb') | |
1871 | try: |
|
1847 | try: | |
1872 | fp.write(text) |
|
1848 | fp.write(text) | |
1873 | finally: |
|
1849 | finally: | |
1874 | fp.close() |
|
1850 | fp.close() | |
1875 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
1851 | return self.pathto(fp.name[len(self.root) + 1:]) | |
1876 |
|
1852 | |||
1877 | # used to avoid circular references so destructors work |
|
1853 | # used to avoid circular references so destructors work | |
1878 | def aftertrans(files): |
|
1854 | def aftertrans(files): | |
1879 | renamefiles = [tuple(t) for t in files] |
|
1855 | renamefiles = [tuple(t) for t in files] | |
1880 | def a(): |
|
1856 | def a(): | |
1881 | for vfs, src, dest in renamefiles: |
|
1857 | for vfs, src, dest in renamefiles: | |
1882 | try: |
|
1858 | try: | |
1883 | vfs.rename(src, dest) |
|
1859 | vfs.rename(src, dest) | |
1884 | except OSError: # journal file does not yet exist |
|
1860 | except OSError: # journal file does not yet exist | |
1885 | pass |
|
1861 | pass | |
1886 | return a |
|
1862 | return a | |
1887 |
|
1863 | |||
1888 | def undoname(fn): |
|
1864 | def undoname(fn): | |
1889 | base, name = os.path.split(fn) |
|
1865 | base, name = os.path.split(fn) | |
1890 | assert name.startswith('journal') |
|
1866 | assert name.startswith('journal') | |
1891 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
1867 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
1892 |
|
1868 | |||
1893 | def instance(ui, path, create): |
|
1869 | def instance(ui, path, create): | |
1894 | return localrepository(ui, util.urllocalpath(path), create) |
|
1870 | return localrepository(ui, util.urllocalpath(path), create) | |
1895 |
|
1871 | |||
1896 | def islocal(path): |
|
1872 | def islocal(path): | |
1897 | return True |
|
1873 | return True |
@@ -1,225 +1,251 b'' | |||||
1 | # streamclone.py - producing and consuming streaming repository data |
|
1 | # streamclone.py - producing and consuming streaming repository data | |
2 | # |
|
2 | # | |
3 | # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com> |
|
3 | # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.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 time |
|
10 | import time | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import ( |
|
13 | from . import ( | |
14 | branchmap, |
|
14 | branchmap, | |
15 | error, |
|
15 | error, | |
16 | store, |
|
16 | store, | |
17 | util, |
|
17 | util, | |
18 | ) |
|
18 | ) | |
19 |
|
19 | |||
|
20 | def maybeperformstreamclone(repo, remote, heads, stream): | |||
|
21 | # now, all clients that can request uncompressed clones can | |||
|
22 | # read repo formats supported by all servers that can serve | |||
|
23 | # them. | |||
|
24 | ||||
|
25 | # if revlog format changes, client will have to check version | |||
|
26 | # and format flags on "stream" capability, and use | |||
|
27 | # uncompressed only if compatible. | |||
|
28 | ||||
|
29 | if stream is None: | |||
|
30 | # if the server explicitly prefers to stream (for fast LANs) | |||
|
31 | stream = remote.capable('stream-preferred') | |||
|
32 | ||||
|
33 | if stream and not heads: | |||
|
34 | # 'stream' means remote revlog format is revlogv1 only | |||
|
35 | if remote.capable('stream'): | |||
|
36 | streamin(repo, remote, set(('revlogv1',))) | |||
|
37 | else: | |||
|
38 | # otherwise, 'streamreqs' contains the remote revlog format | |||
|
39 | streamreqs = remote.capable('streamreqs') | |||
|
40 | if streamreqs: | |||
|
41 | streamreqs = set(streamreqs.split(',')) | |||
|
42 | # if we support it, stream in and adjust our requirements | |||
|
43 | if not streamreqs - repo.supportedformats: | |||
|
44 | streamin(repo, remote, streamreqs) | |||
|
45 | ||||
20 | def allowservergeneration(ui): |
|
46 | def allowservergeneration(ui): | |
21 | """Whether streaming clones are allowed from the server.""" |
|
47 | """Whether streaming clones are allowed from the server.""" | |
22 | return ui.configbool('server', 'uncompressed', True, untrusted=True) |
|
48 | return ui.configbool('server', 'uncompressed', True, untrusted=True) | |
23 |
|
49 | |||
24 | # This is it's own function so extensions can override it. |
|
50 | # This is it's own function so extensions can override it. | |
25 | def _walkstreamfiles(repo): |
|
51 | def _walkstreamfiles(repo): | |
26 | return repo.store.walk() |
|
52 | return repo.store.walk() | |
27 |
|
53 | |||
28 | def generatev1(repo): |
|
54 | def generatev1(repo): | |
29 | """Emit content for version 1 of a streaming clone. |
|
55 | """Emit content for version 1 of a streaming clone. | |
30 |
|
56 | |||
31 | This is a generator of raw chunks that constitute a streaming clone. |
|
57 | This is a generator of raw chunks that constitute a streaming clone. | |
32 |
|
58 | |||
33 | The stream begins with a line of 2 space-delimited integers containing the |
|
59 | The stream begins with a line of 2 space-delimited integers containing the | |
34 | number of entries and total bytes size. |
|
60 | number of entries and total bytes size. | |
35 |
|
61 | |||
36 | Next, are N entries for each file being transferred. Each file entry starts |
|
62 | Next, are N entries for each file being transferred. Each file entry starts | |
37 | as a line with the file name and integer size delimited by a null byte. |
|
63 | as a line with the file name and integer size delimited by a null byte. | |
38 | The raw file data follows. Following the raw file data is the next file |
|
64 | The raw file data follows. Following the raw file data is the next file | |
39 | entry, or EOF. |
|
65 | entry, or EOF. | |
40 |
|
66 | |||
41 | When used on the wire protocol, an additional line indicating protocol |
|
67 | When used on the wire protocol, an additional line indicating protocol | |
42 | success will be prepended to the stream. This function is not responsible |
|
68 | success will be prepended to the stream. This function is not responsible | |
43 | for adding it. |
|
69 | for adding it. | |
44 |
|
70 | |||
45 | This function will obtain a repository lock to ensure a consistent view of |
|
71 | This function will obtain a repository lock to ensure a consistent view of | |
46 | the store is captured. It therefore may raise LockError. |
|
72 | the store is captured. It therefore may raise LockError. | |
47 | """ |
|
73 | """ | |
48 | entries = [] |
|
74 | entries = [] | |
49 | total_bytes = 0 |
|
75 | total_bytes = 0 | |
50 | # Get consistent snapshot of repo, lock during scan. |
|
76 | # Get consistent snapshot of repo, lock during scan. | |
51 | lock = repo.lock() |
|
77 | lock = repo.lock() | |
52 | try: |
|
78 | try: | |
53 | repo.ui.debug('scanning\n') |
|
79 | repo.ui.debug('scanning\n') | |
54 | for name, ename, size in _walkstreamfiles(repo): |
|
80 | for name, ename, size in _walkstreamfiles(repo): | |
55 | if size: |
|
81 | if size: | |
56 | entries.append((name, size)) |
|
82 | entries.append((name, size)) | |
57 | total_bytes += size |
|
83 | total_bytes += size | |
58 | finally: |
|
84 | finally: | |
59 | lock.release() |
|
85 | lock.release() | |
60 |
|
86 | |||
61 | repo.ui.debug('%d files, %d bytes to transfer\n' % |
|
87 | repo.ui.debug('%d files, %d bytes to transfer\n' % | |
62 | (len(entries), total_bytes)) |
|
88 | (len(entries), total_bytes)) | |
63 | yield '%d %d\n' % (len(entries), total_bytes) |
|
89 | yield '%d %d\n' % (len(entries), total_bytes) | |
64 |
|
90 | |||
65 | svfs = repo.svfs |
|
91 | svfs = repo.svfs | |
66 | oldaudit = svfs.mustaudit |
|
92 | oldaudit = svfs.mustaudit | |
67 | debugflag = repo.ui.debugflag |
|
93 | debugflag = repo.ui.debugflag | |
68 | svfs.mustaudit = False |
|
94 | svfs.mustaudit = False | |
69 |
|
95 | |||
70 | try: |
|
96 | try: | |
71 | for name, size in entries: |
|
97 | for name, size in entries: | |
72 | if debugflag: |
|
98 | if debugflag: | |
73 | repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) |
|
99 | repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) | |
74 | # partially encode name over the wire for backwards compat |
|
100 | # partially encode name over the wire for backwards compat | |
75 | yield '%s\0%d\n' % (store.encodedir(name), size) |
|
101 | yield '%s\0%d\n' % (store.encodedir(name), size) | |
76 | if size <= 65536: |
|
102 | if size <= 65536: | |
77 | fp = svfs(name) |
|
103 | fp = svfs(name) | |
78 | try: |
|
104 | try: | |
79 | data = fp.read(size) |
|
105 | data = fp.read(size) | |
80 | finally: |
|
106 | finally: | |
81 | fp.close() |
|
107 | fp.close() | |
82 | yield data |
|
108 | yield data | |
83 | else: |
|
109 | else: | |
84 | for chunk in util.filechunkiter(svfs(name), limit=size): |
|
110 | for chunk in util.filechunkiter(svfs(name), limit=size): | |
85 | yield chunk |
|
111 | yield chunk | |
86 | finally: |
|
112 | finally: | |
87 | svfs.mustaudit = oldaudit |
|
113 | svfs.mustaudit = oldaudit | |
88 |
|
114 | |||
89 | def consumev1(repo, fp): |
|
115 | def consumev1(repo, fp): | |
90 | """Apply the contents from version 1 of a streaming clone file handle. |
|
116 | """Apply the contents from version 1 of a streaming clone file handle. | |
91 |
|
117 | |||
92 | This takes the output from "streamout" and applies it to the specified |
|
118 | This takes the output from "streamout" and applies it to the specified | |
93 | repository. |
|
119 | repository. | |
94 |
|
120 | |||
95 | Like "streamout," the status line added by the wire protocol is not handled |
|
121 | Like "streamout," the status line added by the wire protocol is not handled | |
96 | by this function. |
|
122 | by this function. | |
97 | """ |
|
123 | """ | |
98 | lock = repo.lock() |
|
124 | lock = repo.lock() | |
99 | try: |
|
125 | try: | |
100 | repo.ui.status(_('streaming all changes\n')) |
|
126 | repo.ui.status(_('streaming all changes\n')) | |
101 | l = fp.readline() |
|
127 | l = fp.readline() | |
102 | try: |
|
128 | try: | |
103 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
129 | total_files, total_bytes = map(int, l.split(' ', 1)) | |
104 | except (ValueError, TypeError): |
|
130 | except (ValueError, TypeError): | |
105 | raise error.ResponseError( |
|
131 | raise error.ResponseError( | |
106 | _('unexpected response from remote server:'), l) |
|
132 | _('unexpected response from remote server:'), l) | |
107 | repo.ui.status(_('%d files to transfer, %s of data\n') % |
|
133 | repo.ui.status(_('%d files to transfer, %s of data\n') % | |
108 | (total_files, util.bytecount(total_bytes))) |
|
134 | (total_files, util.bytecount(total_bytes))) | |
109 | handled_bytes = 0 |
|
135 | handled_bytes = 0 | |
110 | repo.ui.progress(_('clone'), 0, total=total_bytes) |
|
136 | repo.ui.progress(_('clone'), 0, total=total_bytes) | |
111 | start = time.time() |
|
137 | start = time.time() | |
112 |
|
138 | |||
113 | tr = repo.transaction(_('clone')) |
|
139 | tr = repo.transaction(_('clone')) | |
114 | try: |
|
140 | try: | |
115 | for i in xrange(total_files): |
|
141 | for i in xrange(total_files): | |
116 | # XXX doesn't support '\n' or '\r' in filenames |
|
142 | # XXX doesn't support '\n' or '\r' in filenames | |
117 | l = fp.readline() |
|
143 | l = fp.readline() | |
118 | try: |
|
144 | try: | |
119 | name, size = l.split('\0', 1) |
|
145 | name, size = l.split('\0', 1) | |
120 | size = int(size) |
|
146 | size = int(size) | |
121 | except (ValueError, TypeError): |
|
147 | except (ValueError, TypeError): | |
122 | raise error.ResponseError( |
|
148 | raise error.ResponseError( | |
123 | _('unexpected response from remote server:'), l) |
|
149 | _('unexpected response from remote server:'), l) | |
124 | if repo.ui.debugflag: |
|
150 | if repo.ui.debugflag: | |
125 | repo.ui.debug('adding %s (%s)\n' % |
|
151 | repo.ui.debug('adding %s (%s)\n' % | |
126 | (name, util.bytecount(size))) |
|
152 | (name, util.bytecount(size))) | |
127 | # for backwards compat, name was partially encoded |
|
153 | # for backwards compat, name was partially encoded | |
128 | ofp = repo.svfs(store.decodedir(name), 'w') |
|
154 | ofp = repo.svfs(store.decodedir(name), 'w') | |
129 | for chunk in util.filechunkiter(fp, limit=size): |
|
155 | for chunk in util.filechunkiter(fp, limit=size): | |
130 | handled_bytes += len(chunk) |
|
156 | handled_bytes += len(chunk) | |
131 | repo.ui.progress(_('clone'), handled_bytes, |
|
157 | repo.ui.progress(_('clone'), handled_bytes, | |
132 | total=total_bytes) |
|
158 | total=total_bytes) | |
133 | ofp.write(chunk) |
|
159 | ofp.write(chunk) | |
134 | ofp.close() |
|
160 | ofp.close() | |
135 | tr.close() |
|
161 | tr.close() | |
136 | finally: |
|
162 | finally: | |
137 | tr.release() |
|
163 | tr.release() | |
138 |
|
164 | |||
139 | # Writing straight to files circumvented the inmemory caches |
|
165 | # Writing straight to files circumvented the inmemory caches | |
140 | repo.invalidate() |
|
166 | repo.invalidate() | |
141 |
|
167 | |||
142 | elapsed = time.time() - start |
|
168 | elapsed = time.time() - start | |
143 | if elapsed <= 0: |
|
169 | if elapsed <= 0: | |
144 | elapsed = 0.001 |
|
170 | elapsed = 0.001 | |
145 | repo.ui.progress(_('clone'), None) |
|
171 | repo.ui.progress(_('clone'), None) | |
146 | repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
172 | repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |
147 | (util.bytecount(total_bytes), elapsed, |
|
173 | (util.bytecount(total_bytes), elapsed, | |
148 | util.bytecount(total_bytes / elapsed))) |
|
174 | util.bytecount(total_bytes / elapsed))) | |
149 | finally: |
|
175 | finally: | |
150 | lock.release() |
|
176 | lock.release() | |
151 |
|
177 | |||
152 | def streamin(repo, remote, remotereqs): |
|
178 | def streamin(repo, remote, remotereqs): | |
153 | # Save remote branchmap. We will use it later |
|
179 | # Save remote branchmap. We will use it later | |
154 | # to speed up branchcache creation |
|
180 | # to speed up branchcache creation | |
155 | rbranchmap = None |
|
181 | rbranchmap = None | |
156 | if remote.capable("branchmap"): |
|
182 | if remote.capable("branchmap"): | |
157 | rbranchmap = remote.branchmap() |
|
183 | rbranchmap = remote.branchmap() | |
158 |
|
184 | |||
159 | fp = remote.stream_out() |
|
185 | fp = remote.stream_out() | |
160 | l = fp.readline() |
|
186 | l = fp.readline() | |
161 | try: |
|
187 | try: | |
162 | resp = int(l) |
|
188 | resp = int(l) | |
163 | except ValueError: |
|
189 | except ValueError: | |
164 | raise error.ResponseError( |
|
190 | raise error.ResponseError( | |
165 | _('unexpected response from remote server:'), l) |
|
191 | _('unexpected response from remote server:'), l) | |
166 | if resp == 1: |
|
192 | if resp == 1: | |
167 | raise util.Abort(_('operation forbidden by server')) |
|
193 | raise util.Abort(_('operation forbidden by server')) | |
168 | elif resp == 2: |
|
194 | elif resp == 2: | |
169 | raise util.Abort(_('locking the remote repository failed')) |
|
195 | raise util.Abort(_('locking the remote repository failed')) | |
170 | elif resp != 0: |
|
196 | elif resp != 0: | |
171 | raise util.Abort(_('the server sent an unknown error code')) |
|
197 | raise util.Abort(_('the server sent an unknown error code')) | |
172 |
|
198 | |||
173 | applyremotedata(repo, remotereqs, rbranchmap, fp) |
|
199 | applyremotedata(repo, remotereqs, rbranchmap, fp) | |
174 | return len(repo.heads()) + 1 |
|
200 | return len(repo.heads()) + 1 | |
175 |
|
201 | |||
176 | def applyremotedata(repo, remotereqs, remotebranchmap, fp): |
|
202 | def applyremotedata(repo, remotereqs, remotebranchmap, fp): | |
177 | """Apply stream clone data to a repository. |
|
203 | """Apply stream clone data to a repository. | |
178 |
|
204 | |||
179 | "remotereqs" is a set of requirements to handle the incoming data. |
|
205 | "remotereqs" is a set of requirements to handle the incoming data. | |
180 | "remotebranchmap" is the result of a branchmap lookup on the remote. It |
|
206 | "remotebranchmap" is the result of a branchmap lookup on the remote. It | |
181 | can be None. |
|
207 | can be None. | |
182 | "fp" is a file object containing the raw stream data, suitable for |
|
208 | "fp" is a file object containing the raw stream data, suitable for | |
183 | feeding into consumev1(). |
|
209 | feeding into consumev1(). | |
184 | """ |
|
210 | """ | |
185 | lock = repo.lock() |
|
211 | lock = repo.lock() | |
186 | try: |
|
212 | try: | |
187 | consumev1(repo, fp) |
|
213 | consumev1(repo, fp) | |
188 |
|
214 | |||
189 | # new requirements = old non-format requirements + |
|
215 | # new requirements = old non-format requirements + | |
190 | # new format-related remote requirements |
|
216 | # new format-related remote requirements | |
191 | # requirements from the streamed-in repository |
|
217 | # requirements from the streamed-in repository | |
192 | repo.requirements = remotereqs | ( |
|
218 | repo.requirements = remotereqs | ( | |
193 | repo.requirements - repo.supportedformats) |
|
219 | repo.requirements - repo.supportedformats) | |
194 | repo._applyopenerreqs() |
|
220 | repo._applyopenerreqs() | |
195 | repo._writerequirements() |
|
221 | repo._writerequirements() | |
196 |
|
222 | |||
197 | if remotebranchmap: |
|
223 | if remotebranchmap: | |
198 | rbheads = [] |
|
224 | rbheads = [] | |
199 | closed = [] |
|
225 | closed = [] | |
200 | for bheads in remotebranchmap.itervalues(): |
|
226 | for bheads in remotebranchmap.itervalues(): | |
201 | rbheads.extend(bheads) |
|
227 | rbheads.extend(bheads) | |
202 | for h in bheads: |
|
228 | for h in bheads: | |
203 | r = repo.changelog.rev(h) |
|
229 | r = repo.changelog.rev(h) | |
204 | b, c = repo.changelog.branchinfo(r) |
|
230 | b, c = repo.changelog.branchinfo(r) | |
205 | if c: |
|
231 | if c: | |
206 | closed.append(h) |
|
232 | closed.append(h) | |
207 |
|
233 | |||
208 | if rbheads: |
|
234 | if rbheads: | |
209 | rtiprev = max((int(repo.changelog.rev(node)) |
|
235 | rtiprev = max((int(repo.changelog.rev(node)) | |
210 | for node in rbheads)) |
|
236 | for node in rbheads)) | |
211 | cache = branchmap.branchcache(remotebranchmap, |
|
237 | cache = branchmap.branchcache(remotebranchmap, | |
212 | repo[rtiprev].node(), |
|
238 | repo[rtiprev].node(), | |
213 | rtiprev, |
|
239 | rtiprev, | |
214 | closednodes=closed) |
|
240 | closednodes=closed) | |
215 | # Try to stick it as low as possible |
|
241 | # Try to stick it as low as possible | |
216 | # filter above served are unlikely to be fetch from a clone |
|
242 | # filter above served are unlikely to be fetch from a clone | |
217 | for candidate in ('base', 'immutable', 'served'): |
|
243 | for candidate in ('base', 'immutable', 'served'): | |
218 | rview = repo.filtered(candidate) |
|
244 | rview = repo.filtered(candidate) | |
219 | if cache.validfor(rview): |
|
245 | if cache.validfor(rview): | |
220 | repo._branchcaches[candidate] = cache |
|
246 | repo._branchcaches[candidate] = cache | |
221 | cache.write(rview) |
|
247 | cache.write(rview) | |
222 | break |
|
248 | break | |
223 | repo.invalidate() |
|
249 | repo.invalidate() | |
224 | finally: |
|
250 | finally: | |
225 | lock.release() |
|
251 | lock.release() |
General Comments 0
You need to be logged in to leave comments.
Login now