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