Show More
@@ -1,928 +1,925 b'' | |||||
1 | # context.py - changeset and file context objects for mercurial |
|
1 | # context.py - changeset and file context objects for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import nullid, nullrev, short, hex |
|
8 | from node import nullid, nullrev, short, hex | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import ancestor, bdiff, error, util, subrepo |
|
10 | import ancestor, bdiff, error, util, subrepo | |
11 | import os, errno |
|
11 | import os, errno | |
12 |
|
12 | |||
13 | propertycache = util.propertycache |
|
13 | propertycache = util.propertycache | |
14 |
|
14 | |||
15 | class changectx(object): |
|
15 | class changectx(object): | |
16 | """A changecontext object makes access to data related to a particular |
|
16 | """A changecontext object makes access to data related to a particular | |
17 | changeset convenient.""" |
|
17 | changeset convenient.""" | |
18 | def __init__(self, repo, changeid=''): |
|
18 | def __init__(self, repo, changeid=''): | |
19 | """changeid is a revision number, node, or tag""" |
|
19 | """changeid is a revision number, node, or tag""" | |
20 | if changeid == '': |
|
20 | if changeid == '': | |
21 | changeid = '.' |
|
21 | changeid = '.' | |
22 | self._repo = repo |
|
22 | self._repo = repo | |
23 | if isinstance(changeid, (long, int)): |
|
23 | if isinstance(changeid, (long, int)): | |
24 | self._rev = changeid |
|
24 | self._rev = changeid | |
25 | self._node = self._repo.changelog.node(changeid) |
|
25 | self._node = self._repo.changelog.node(changeid) | |
26 | else: |
|
26 | else: | |
27 | self._node = self._repo.lookup(changeid) |
|
27 | self._node = self._repo.lookup(changeid) | |
28 | self._rev = self._repo.changelog.rev(self._node) |
|
28 | self._rev = self._repo.changelog.rev(self._node) | |
29 |
|
29 | |||
30 | def __str__(self): |
|
30 | def __str__(self): | |
31 | return short(self.node()) |
|
31 | return short(self.node()) | |
32 |
|
32 | |||
33 | def __int__(self): |
|
33 | def __int__(self): | |
34 | return self.rev() |
|
34 | return self.rev() | |
35 |
|
35 | |||
36 | def __repr__(self): |
|
36 | def __repr__(self): | |
37 | return "<changectx %s>" % str(self) |
|
37 | return "<changectx %s>" % str(self) | |
38 |
|
38 | |||
39 | def __hash__(self): |
|
39 | def __hash__(self): | |
40 | try: |
|
40 | try: | |
41 | return hash(self._rev) |
|
41 | return hash(self._rev) | |
42 | except AttributeError: |
|
42 | except AttributeError: | |
43 | return id(self) |
|
43 | return id(self) | |
44 |
|
44 | |||
45 | def __eq__(self, other): |
|
45 | def __eq__(self, other): | |
46 | try: |
|
46 | try: | |
47 | return self._rev == other._rev |
|
47 | return self._rev == other._rev | |
48 | except AttributeError: |
|
48 | except AttributeError: | |
49 | return False |
|
49 | return False | |
50 |
|
50 | |||
51 | def __ne__(self, other): |
|
51 | def __ne__(self, other): | |
52 | return not (self == other) |
|
52 | return not (self == other) | |
53 |
|
53 | |||
54 | def __nonzero__(self): |
|
54 | def __nonzero__(self): | |
55 | return self._rev != nullrev |
|
55 | return self._rev != nullrev | |
56 |
|
56 | |||
57 | @propertycache |
|
57 | @propertycache | |
58 | def _changeset(self): |
|
58 | def _changeset(self): | |
59 | return self._repo.changelog.read(self.node()) |
|
59 | return self._repo.changelog.read(self.node()) | |
60 |
|
60 | |||
61 | @propertycache |
|
61 | @propertycache | |
62 | def _manifest(self): |
|
62 | def _manifest(self): | |
63 | return self._repo.manifest.read(self._changeset[0]) |
|
63 | return self._repo.manifest.read(self._changeset[0]) | |
64 |
|
64 | |||
65 | @propertycache |
|
65 | @propertycache | |
66 | def _manifestdelta(self): |
|
66 | def _manifestdelta(self): | |
67 | return self._repo.manifest.readdelta(self._changeset[0]) |
|
67 | return self._repo.manifest.readdelta(self._changeset[0]) | |
68 |
|
68 | |||
69 | @propertycache |
|
69 | @propertycache | |
70 | def _parents(self): |
|
70 | def _parents(self): | |
71 | p = self._repo.changelog.parentrevs(self._rev) |
|
71 | p = self._repo.changelog.parentrevs(self._rev) | |
72 | if p[1] == nullrev: |
|
72 | if p[1] == nullrev: | |
73 | p = p[:-1] |
|
73 | p = p[:-1] | |
74 | return [changectx(self._repo, x) for x in p] |
|
74 | return [changectx(self._repo, x) for x in p] | |
75 |
|
75 | |||
76 | @propertycache |
|
76 | @propertycache | |
77 | def substate(self): |
|
77 | def substate(self): | |
78 | return subrepo.state(self) |
|
78 | return subrepo.state(self) | |
79 |
|
79 | |||
80 | def __contains__(self, key): |
|
80 | def __contains__(self, key): | |
81 | return key in self._manifest |
|
81 | return key in self._manifest | |
82 |
|
82 | |||
83 | def __getitem__(self, key): |
|
83 | def __getitem__(self, key): | |
84 | return self.filectx(key) |
|
84 | return self.filectx(key) | |
85 |
|
85 | |||
86 | def __iter__(self): |
|
86 | def __iter__(self): | |
87 | for f in sorted(self._manifest): |
|
87 | for f in sorted(self._manifest): | |
88 | yield f |
|
88 | yield f | |
89 |
|
89 | |||
90 | def changeset(self): |
|
90 | def changeset(self): | |
91 | return self._changeset |
|
91 | return self._changeset | |
92 | def manifest(self): |
|
92 | def manifest(self): | |
93 | return self._manifest |
|
93 | return self._manifest | |
94 | def manifestnode(self): |
|
94 | def manifestnode(self): | |
95 | return self._changeset[0] |
|
95 | return self._changeset[0] | |
96 |
|
96 | |||
97 | def rev(self): |
|
97 | def rev(self): | |
98 | return self._rev |
|
98 | return self._rev | |
99 | def node(self): |
|
99 | def node(self): | |
100 | return self._node |
|
100 | return self._node | |
101 | def hex(self): |
|
101 | def hex(self): | |
102 | return hex(self._node) |
|
102 | return hex(self._node) | |
103 | def user(self): |
|
103 | def user(self): | |
104 | return self._changeset[1] |
|
104 | return self._changeset[1] | |
105 | def date(self): |
|
105 | def date(self): | |
106 | return self._changeset[2] |
|
106 | return self._changeset[2] | |
107 | def files(self): |
|
107 | def files(self): | |
108 | return self._changeset[3] |
|
108 | return self._changeset[3] | |
109 | def description(self): |
|
109 | def description(self): | |
110 | return self._changeset[4] |
|
110 | return self._changeset[4] | |
111 | def branch(self): |
|
111 | def branch(self): | |
112 | return self._changeset[5].get("branch") |
|
112 | return self._changeset[5].get("branch") | |
113 | def extra(self): |
|
113 | def extra(self): | |
114 | return self._changeset[5] |
|
114 | return self._changeset[5] | |
115 | def tags(self): |
|
115 | def tags(self): | |
116 | return self._repo.nodetags(self._node) |
|
116 | return self._repo.nodetags(self._node) | |
117 |
|
117 | |||
118 | def parents(self): |
|
118 | def parents(self): | |
119 | """return contexts for each parent changeset""" |
|
119 | """return contexts for each parent changeset""" | |
120 | return self._parents |
|
120 | return self._parents | |
121 |
|
121 | |||
122 | def p1(self): |
|
122 | def p1(self): | |
123 | return self._parents[0] |
|
123 | return self._parents[0] | |
124 |
|
124 | |||
125 | def p2(self): |
|
125 | def p2(self): | |
126 | if len(self._parents) == 2: |
|
126 | if len(self._parents) == 2: | |
127 | return self._parents[1] |
|
127 | return self._parents[1] | |
128 | return changectx(self._repo, -1) |
|
128 | return changectx(self._repo, -1) | |
129 |
|
129 | |||
130 | def children(self): |
|
130 | def children(self): | |
131 | """return contexts for each child changeset""" |
|
131 | """return contexts for each child changeset""" | |
132 | c = self._repo.changelog.children(self._node) |
|
132 | c = self._repo.changelog.children(self._node) | |
133 | return [changectx(self._repo, x) for x in c] |
|
133 | return [changectx(self._repo, x) for x in c] | |
134 |
|
134 | |||
135 | def ancestors(self): |
|
135 | def ancestors(self): | |
136 | for a in self._repo.changelog.ancestors(self._rev): |
|
136 | for a in self._repo.changelog.ancestors(self._rev): | |
137 | yield changectx(self._repo, a) |
|
137 | yield changectx(self._repo, a) | |
138 |
|
138 | |||
139 | def descendants(self): |
|
139 | def descendants(self): | |
140 | for d in self._repo.changelog.descendants(self._rev): |
|
140 | for d in self._repo.changelog.descendants(self._rev): | |
141 | yield changectx(self._repo, d) |
|
141 | yield changectx(self._repo, d) | |
142 |
|
142 | |||
143 | def _fileinfo(self, path): |
|
143 | def _fileinfo(self, path): | |
144 | if '_manifest' in self.__dict__: |
|
144 | if '_manifest' in self.__dict__: | |
145 | try: |
|
145 | try: | |
146 | return self._manifest[path], self._manifest.flags(path) |
|
146 | return self._manifest[path], self._manifest.flags(path) | |
147 | except KeyError: |
|
147 | except KeyError: | |
148 | raise error.LookupError(self._node, path, |
|
148 | raise error.LookupError(self._node, path, | |
149 | _('not found in manifest')) |
|
149 | _('not found in manifest')) | |
150 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
150 | if '_manifestdelta' in self.__dict__ or path in self.files(): | |
151 | if path in self._manifestdelta: |
|
151 | if path in self._manifestdelta: | |
152 | return self._manifestdelta[path], self._manifestdelta.flags(path) |
|
152 | return self._manifestdelta[path], self._manifestdelta.flags(path) | |
153 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
153 | node, flag = self._repo.manifest.find(self._changeset[0], path) | |
154 | if not node: |
|
154 | if not node: | |
155 | raise error.LookupError(self._node, path, |
|
155 | raise error.LookupError(self._node, path, | |
156 | _('not found in manifest')) |
|
156 | _('not found in manifest')) | |
157 |
|
157 | |||
158 | return node, flag |
|
158 | return node, flag | |
159 |
|
159 | |||
160 | def filenode(self, path): |
|
160 | def filenode(self, path): | |
161 | return self._fileinfo(path)[0] |
|
161 | return self._fileinfo(path)[0] | |
162 |
|
162 | |||
163 | def flags(self, path): |
|
163 | def flags(self, path): | |
164 | try: |
|
164 | try: | |
165 | return self._fileinfo(path)[1] |
|
165 | return self._fileinfo(path)[1] | |
166 | except error.LookupError: |
|
166 | except error.LookupError: | |
167 | return '' |
|
167 | return '' | |
168 |
|
168 | |||
169 | def filectx(self, path, fileid=None, filelog=None): |
|
169 | def filectx(self, path, fileid=None, filelog=None): | |
170 | """get a file context from this changeset""" |
|
170 | """get a file context from this changeset""" | |
171 | if fileid is None: |
|
171 | if fileid is None: | |
172 | fileid = self.filenode(path) |
|
172 | fileid = self.filenode(path) | |
173 | return filectx(self._repo, path, fileid=fileid, |
|
173 | return filectx(self._repo, path, fileid=fileid, | |
174 | changectx=self, filelog=filelog) |
|
174 | changectx=self, filelog=filelog) | |
175 |
|
175 | |||
176 | def ancestor(self, c2): |
|
176 | def ancestor(self, c2): | |
177 | """ |
|
177 | """ | |
178 | return the ancestor context of self and c2 |
|
178 | return the ancestor context of self and c2 | |
179 | """ |
|
179 | """ | |
180 | # deal with workingctxs |
|
180 | # deal with workingctxs | |
181 | n2 = c2._node |
|
181 | n2 = c2._node | |
182 | if n2 == None: |
|
182 | if n2 == None: | |
183 | n2 = c2._parents[0]._node |
|
183 | n2 = c2._parents[0]._node | |
184 | n = self._repo.changelog.ancestor(self._node, n2) |
|
184 | n = self._repo.changelog.ancestor(self._node, n2) | |
185 | return changectx(self._repo, n) |
|
185 | return changectx(self._repo, n) | |
186 |
|
186 | |||
187 | def walk(self, match): |
|
187 | def walk(self, match): | |
188 | fset = set(match.files()) |
|
188 | fset = set(match.files()) | |
189 | # for dirstate.walk, files=['.'] means "walk the whole tree". |
|
189 | # for dirstate.walk, files=['.'] means "walk the whole tree". | |
190 | # follow that here, too |
|
190 | # follow that here, too | |
191 | fset.discard('.') |
|
191 | fset.discard('.') | |
192 | for fn in self: |
|
192 | for fn in self: | |
193 | for ffn in fset: |
|
193 | for ffn in fset: | |
194 | # match if the file is the exact name or a directory |
|
194 | # match if the file is the exact name or a directory | |
195 | if ffn == fn or fn.startswith("%s/" % ffn): |
|
195 | if ffn == fn or fn.startswith("%s/" % ffn): | |
196 | fset.remove(ffn) |
|
196 | fset.remove(ffn) | |
197 | break |
|
197 | break | |
198 | if match(fn): |
|
198 | if match(fn): | |
199 | yield fn |
|
199 | yield fn | |
200 | for fn in sorted(fset): |
|
200 | for fn in sorted(fset): | |
201 | if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn): |
|
201 | if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn): | |
202 | yield fn |
|
202 | yield fn | |
203 |
|
203 | |||
204 | def sub(self, path): |
|
204 | def sub(self, path): | |
205 | return subrepo.subrepo(self, path) |
|
205 | return subrepo.subrepo(self, path) | |
206 |
|
206 | |||
207 | class filectx(object): |
|
207 | class filectx(object): | |
208 | """A filecontext object makes access to data related to a particular |
|
208 | """A filecontext object makes access to data related to a particular | |
209 | filerevision convenient.""" |
|
209 | filerevision convenient.""" | |
210 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
210 | def __init__(self, repo, path, changeid=None, fileid=None, | |
211 | filelog=None, changectx=None): |
|
211 | filelog=None, changectx=None): | |
212 | """changeid can be a changeset revision, node, or tag. |
|
212 | """changeid can be a changeset revision, node, or tag. | |
213 | fileid can be a file revision or node.""" |
|
213 | fileid can be a file revision or node.""" | |
214 | self._repo = repo |
|
214 | self._repo = repo | |
215 | self._path = path |
|
215 | self._path = path | |
216 |
|
216 | |||
217 | assert (changeid is not None |
|
217 | assert (changeid is not None | |
218 | or fileid is not None |
|
218 | or fileid is not None | |
219 | or changectx is not None), \ |
|
219 | or changectx is not None), \ | |
220 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
220 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
221 | % (changeid, fileid, changectx)) |
|
221 | % (changeid, fileid, changectx)) | |
222 |
|
222 | |||
223 | if filelog: |
|
223 | if filelog: | |
224 | self._filelog = filelog |
|
224 | self._filelog = filelog | |
225 |
|
225 | |||
226 | if changeid is not None: |
|
226 | if changeid is not None: | |
227 | self._changeid = changeid |
|
227 | self._changeid = changeid | |
228 | if changectx is not None: |
|
228 | if changectx is not None: | |
229 | self._changectx = changectx |
|
229 | self._changectx = changectx | |
230 | if fileid is not None: |
|
230 | if fileid is not None: | |
231 | self._fileid = fileid |
|
231 | self._fileid = fileid | |
232 |
|
232 | |||
233 | @propertycache |
|
233 | @propertycache | |
234 | def _changectx(self): |
|
234 | def _changectx(self): | |
235 | return changectx(self._repo, self._changeid) |
|
235 | return changectx(self._repo, self._changeid) | |
236 |
|
236 | |||
237 | @propertycache |
|
237 | @propertycache | |
238 | def _filelog(self): |
|
238 | def _filelog(self): | |
239 | return self._repo.file(self._path) |
|
239 | return self._repo.file(self._path) | |
240 |
|
240 | |||
241 | @propertycache |
|
241 | @propertycache | |
242 | def _changeid(self): |
|
242 | def _changeid(self): | |
243 | if '_changectx' in self.__dict__: |
|
243 | if '_changectx' in self.__dict__: | |
244 | return self._changectx.rev() |
|
244 | return self._changectx.rev() | |
245 | else: |
|
245 | else: | |
246 | return self._filelog.linkrev(self._filerev) |
|
246 | return self._filelog.linkrev(self._filerev) | |
247 |
|
247 | |||
248 | @propertycache |
|
248 | @propertycache | |
249 | def _filenode(self): |
|
249 | def _filenode(self): | |
250 | if '_fileid' in self.__dict__: |
|
250 | if '_fileid' in self.__dict__: | |
251 | return self._filelog.lookup(self._fileid) |
|
251 | return self._filelog.lookup(self._fileid) | |
252 | else: |
|
252 | else: | |
253 | return self._changectx.filenode(self._path) |
|
253 | return self._changectx.filenode(self._path) | |
254 |
|
254 | |||
255 | @propertycache |
|
255 | @propertycache | |
256 | def _filerev(self): |
|
256 | def _filerev(self): | |
257 | return self._filelog.rev(self._filenode) |
|
257 | return self._filelog.rev(self._filenode) | |
258 |
|
258 | |||
259 | @propertycache |
|
259 | @propertycache | |
260 | def _repopath(self): |
|
260 | def _repopath(self): | |
261 | return self._path |
|
261 | return self._path | |
262 |
|
262 | |||
263 | def __nonzero__(self): |
|
263 | def __nonzero__(self): | |
264 | try: |
|
264 | try: | |
265 | self._filenode |
|
265 | self._filenode | |
266 | return True |
|
266 | return True | |
267 | except error.LookupError: |
|
267 | except error.LookupError: | |
268 | # file is missing |
|
268 | # file is missing | |
269 | return False |
|
269 | return False | |
270 |
|
270 | |||
271 | def __str__(self): |
|
271 | def __str__(self): | |
272 | return "%s@%s" % (self.path(), short(self.node())) |
|
272 | return "%s@%s" % (self.path(), short(self.node())) | |
273 |
|
273 | |||
274 | def __repr__(self): |
|
274 | def __repr__(self): | |
275 | return "<filectx %s>" % str(self) |
|
275 | return "<filectx %s>" % str(self) | |
276 |
|
276 | |||
277 | def __hash__(self): |
|
277 | def __hash__(self): | |
278 | try: |
|
278 | try: | |
279 | return hash((self._path, self._filenode)) |
|
279 | return hash((self._path, self._filenode)) | |
280 | except AttributeError: |
|
280 | except AttributeError: | |
281 | return id(self) |
|
281 | return id(self) | |
282 |
|
282 | |||
283 | def __eq__(self, other): |
|
283 | def __eq__(self, other): | |
284 | try: |
|
284 | try: | |
285 | return (self._path == other._path |
|
285 | return (self._path == other._path | |
286 | and self._filenode == other._filenode) |
|
286 | and self._filenode == other._filenode) | |
287 | except AttributeError: |
|
287 | except AttributeError: | |
288 | return False |
|
288 | return False | |
289 |
|
289 | |||
290 | def __ne__(self, other): |
|
290 | def __ne__(self, other): | |
291 | return not (self == other) |
|
291 | return not (self == other) | |
292 |
|
292 | |||
293 | def filectx(self, fileid): |
|
293 | def filectx(self, fileid): | |
294 | '''opens an arbitrary revision of the file without |
|
294 | '''opens an arbitrary revision of the file without | |
295 | opening a new filelog''' |
|
295 | opening a new filelog''' | |
296 | return filectx(self._repo, self._path, fileid=fileid, |
|
296 | return filectx(self._repo, self._path, fileid=fileid, | |
297 | filelog=self._filelog) |
|
297 | filelog=self._filelog) | |
298 |
|
298 | |||
299 | def filerev(self): |
|
299 | def filerev(self): | |
300 | return self._filerev |
|
300 | return self._filerev | |
301 | def filenode(self): |
|
301 | def filenode(self): | |
302 | return self._filenode |
|
302 | return self._filenode | |
303 | def flags(self): |
|
303 | def flags(self): | |
304 | return self._changectx.flags(self._path) |
|
304 | return self._changectx.flags(self._path) | |
305 | def filelog(self): |
|
305 | def filelog(self): | |
306 | return self._filelog |
|
306 | return self._filelog | |
307 |
|
307 | |||
308 | def rev(self): |
|
308 | def rev(self): | |
309 | if '_changectx' in self.__dict__: |
|
309 | if '_changectx' in self.__dict__: | |
310 | return self._changectx.rev() |
|
310 | return self._changectx.rev() | |
311 | if '_changeid' in self.__dict__: |
|
311 | if '_changeid' in self.__dict__: | |
312 | return self._changectx.rev() |
|
312 | return self._changectx.rev() | |
313 | return self._filelog.linkrev(self._filerev) |
|
313 | return self._filelog.linkrev(self._filerev) | |
314 |
|
314 | |||
315 | def linkrev(self): |
|
315 | def linkrev(self): | |
316 | return self._filelog.linkrev(self._filerev) |
|
316 | return self._filelog.linkrev(self._filerev) | |
317 | def node(self): |
|
317 | def node(self): | |
318 | return self._changectx.node() |
|
318 | return self._changectx.node() | |
319 | def hex(self): |
|
319 | def hex(self): | |
320 | return hex(self.node()) |
|
320 | return hex(self.node()) | |
321 | def user(self): |
|
321 | def user(self): | |
322 | return self._changectx.user() |
|
322 | return self._changectx.user() | |
323 | def date(self): |
|
323 | def date(self): | |
324 | return self._changectx.date() |
|
324 | return self._changectx.date() | |
325 | def files(self): |
|
325 | def files(self): | |
326 | return self._changectx.files() |
|
326 | return self._changectx.files() | |
327 | def description(self): |
|
327 | def description(self): | |
328 | return self._changectx.description() |
|
328 | return self._changectx.description() | |
329 | def branch(self): |
|
329 | def branch(self): | |
330 | return self._changectx.branch() |
|
330 | return self._changectx.branch() | |
331 | def extra(self): |
|
331 | def extra(self): | |
332 | return self._changectx.extra() |
|
332 | return self._changectx.extra() | |
333 | def manifest(self): |
|
333 | def manifest(self): | |
334 | return self._changectx.manifest() |
|
334 | return self._changectx.manifest() | |
335 | def changectx(self): |
|
335 | def changectx(self): | |
336 | return self._changectx |
|
336 | return self._changectx | |
337 |
|
337 | |||
338 | def data(self): |
|
338 | def data(self): | |
339 | return self._filelog.read(self._filenode) |
|
339 | return self._filelog.read(self._filenode) | |
340 | def path(self): |
|
340 | def path(self): | |
341 | return self._path |
|
341 | return self._path | |
342 | def size(self): |
|
342 | def size(self): | |
343 | return self._filelog.size(self._filerev) |
|
343 | return self._filelog.size(self._filerev) | |
344 |
|
344 | |||
345 | def cmp(self, text): |
|
345 | def cmp(self, text): | |
346 | return self._filelog.cmp(self._filenode, text) |
|
346 | return self._filelog.cmp(self._filenode, text) | |
347 |
|
347 | |||
348 | def renamed(self): |
|
348 | def renamed(self): | |
349 | """check if file was actually renamed in this changeset revision |
|
349 | """check if file was actually renamed in this changeset revision | |
350 |
|
350 | |||
351 | If rename logged in file revision, we report copy for changeset only |
|
351 | If rename logged in file revision, we report copy for changeset only | |
352 | if file revisions linkrev points back to the changeset in question |
|
352 | if file revisions linkrev points back to the changeset in question | |
353 | or both changeset parents contain different file revisions. |
|
353 | or both changeset parents contain different file revisions. | |
354 | """ |
|
354 | """ | |
355 |
|
355 | |||
356 | renamed = self._filelog.renamed(self._filenode) |
|
356 | renamed = self._filelog.renamed(self._filenode) | |
357 | if not renamed: |
|
357 | if not renamed: | |
358 | return renamed |
|
358 | return renamed | |
359 |
|
359 | |||
360 | if self.rev() == self.linkrev(): |
|
360 | if self.rev() == self.linkrev(): | |
361 | return renamed |
|
361 | return renamed | |
362 |
|
362 | |||
363 | name = self.path() |
|
363 | name = self.path() | |
364 | fnode = self._filenode |
|
364 | fnode = self._filenode | |
365 | for p in self._changectx.parents(): |
|
365 | for p in self._changectx.parents(): | |
366 | try: |
|
366 | try: | |
367 | if fnode == p.filenode(name): |
|
367 | if fnode == p.filenode(name): | |
368 | return None |
|
368 | return None | |
369 | except error.LookupError: |
|
369 | except error.LookupError: | |
370 | pass |
|
370 | pass | |
371 | return renamed |
|
371 | return renamed | |
372 |
|
372 | |||
373 | def parents(self): |
|
373 | def parents(self): | |
374 | p = self._path |
|
374 | p = self._path | |
375 | fl = self._filelog |
|
375 | fl = self._filelog | |
376 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
376 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] | |
377 |
|
377 | |||
378 | r = self._filelog.renamed(self._filenode) |
|
378 | r = self._filelog.renamed(self._filenode) | |
379 | if r: |
|
379 | if r: | |
380 | pl[0] = (r[0], r[1], None) |
|
380 | pl[0] = (r[0], r[1], None) | |
381 |
|
381 | |||
382 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
382 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
383 | for p, n, l in pl if n != nullid] |
|
383 | for p, n, l in pl if n != nullid] | |
384 |
|
384 | |||
385 | def children(self): |
|
385 | def children(self): | |
386 | # hard for renames |
|
386 | # hard for renames | |
387 | c = self._filelog.children(self._filenode) |
|
387 | c = self._filelog.children(self._filenode) | |
388 | return [filectx(self._repo, self._path, fileid=x, |
|
388 | return [filectx(self._repo, self._path, fileid=x, | |
389 | filelog=self._filelog) for x in c] |
|
389 | filelog=self._filelog) for x in c] | |
390 |
|
390 | |||
391 | def annotate(self, follow=False, linenumber=None): |
|
391 | def annotate(self, follow=False, linenumber=None): | |
392 | '''returns a list of tuples of (ctx, line) for each line |
|
392 | '''returns a list of tuples of (ctx, line) for each line | |
393 | in the file, where ctx is the filectx of the node where |
|
393 | in the file, where ctx is the filectx of the node where | |
394 | that line was last changed. |
|
394 | that line was last changed. | |
395 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
395 | This returns tuples of ((ctx, linenumber), line) for each line, | |
396 | if "linenumber" parameter is NOT "None". |
|
396 | if "linenumber" parameter is NOT "None". | |
397 | In such tuples, linenumber means one at the first appearance |
|
397 | In such tuples, linenumber means one at the first appearance | |
398 | in the managed file. |
|
398 | in the managed file. | |
399 | To reduce annotation cost, |
|
399 | To reduce annotation cost, | |
400 | this returns fixed value(False is used) as linenumber, |
|
400 | this returns fixed value(False is used) as linenumber, | |
401 | if "linenumber" parameter is "False".''' |
|
401 | if "linenumber" parameter is "False".''' | |
402 |
|
402 | |||
403 | def decorate_compat(text, rev): |
|
403 | def decorate_compat(text, rev): | |
404 | return ([rev] * len(text.splitlines()), text) |
|
404 | return ([rev] * len(text.splitlines()), text) | |
405 |
|
405 | |||
406 | def without_linenumber(text, rev): |
|
406 | def without_linenumber(text, rev): | |
407 | return ([(rev, False)] * len(text.splitlines()), text) |
|
407 | return ([(rev, False)] * len(text.splitlines()), text) | |
408 |
|
408 | |||
409 | def with_linenumber(text, rev): |
|
409 | def with_linenumber(text, rev): | |
410 | size = len(text.splitlines()) |
|
410 | size = len(text.splitlines()) | |
411 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
411 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
412 |
|
412 | |||
413 | decorate = (((linenumber is None) and decorate_compat) or |
|
413 | decorate = (((linenumber is None) and decorate_compat) or | |
414 | (linenumber and with_linenumber) or |
|
414 | (linenumber and with_linenumber) or | |
415 | without_linenumber) |
|
415 | without_linenumber) | |
416 |
|
416 | |||
417 | def pair(parent, child): |
|
417 | def pair(parent, child): | |
418 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
|
418 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): | |
419 | child[0][b1:b2] = parent[0][a1:a2] |
|
419 | child[0][b1:b2] = parent[0][a1:a2] | |
420 | return child |
|
420 | return child | |
421 |
|
421 | |||
422 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
422 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
423 | def getctx(path, fileid): |
|
423 | def getctx(path, fileid): | |
424 | log = path == self._path and self._filelog or getlog(path) |
|
424 | log = path == self._path and self._filelog or getlog(path) | |
425 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
425 | return filectx(self._repo, path, fileid=fileid, filelog=log) | |
426 | getctx = util.lrucachefunc(getctx) |
|
426 | getctx = util.lrucachefunc(getctx) | |
427 |
|
427 | |||
428 | def parents(f): |
|
428 | def parents(f): | |
429 | # we want to reuse filectx objects as much as possible |
|
429 | # we want to reuse filectx objects as much as possible | |
430 | p = f._path |
|
430 | p = f._path | |
431 | if f._filerev is None: # working dir |
|
431 | if f._filerev is None: # working dir | |
432 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
432 | pl = [(n.path(), n.filerev()) for n in f.parents()] | |
433 | else: |
|
433 | else: | |
434 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
434 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] | |
435 |
|
435 | |||
436 | if follow: |
|
436 | if follow: | |
437 | r = f.renamed() |
|
437 | r = f.renamed() | |
438 | if r: |
|
438 | if r: | |
439 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
439 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) | |
440 |
|
440 | |||
441 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
441 | return [getctx(p, n) for p, n in pl if n != nullrev] | |
442 |
|
442 | |||
443 | # use linkrev to find the first changeset where self appeared |
|
443 | # use linkrev to find the first changeset where self appeared | |
444 | if self.rev() != self.linkrev(): |
|
444 | if self.rev() != self.linkrev(): | |
445 | base = self.filectx(self.filerev()) |
|
445 | base = self.filectx(self.filerev()) | |
446 | else: |
|
446 | else: | |
447 | base = self |
|
447 | base = self | |
448 |
|
448 | |||
449 | # find all ancestors |
|
449 | # find all ancestors | |
450 | needed = {base: 1} |
|
450 | needed = {base: 1} | |
451 | visit = [base] |
|
451 | visit = [base] | |
452 | files = [base._path] |
|
452 | files = [base._path] | |
453 | while visit: |
|
453 | while visit: | |
454 | f = visit.pop(0) |
|
454 | f = visit.pop(0) | |
455 | for p in parents(f): |
|
455 | for p in parents(f): | |
456 | if p not in needed: |
|
456 | if p not in needed: | |
457 | needed[p] = 1 |
|
457 | needed[p] = 1 | |
458 | visit.append(p) |
|
458 | visit.append(p) | |
459 | if p._path not in files: |
|
459 | if p._path not in files: | |
460 | files.append(p._path) |
|
460 | files.append(p._path) | |
461 | else: |
|
461 | else: | |
462 | # count how many times we'll use this |
|
462 | # count how many times we'll use this | |
463 | needed[p] += 1 |
|
463 | needed[p] += 1 | |
464 |
|
464 | |||
465 | # sort by revision (per file) which is a topological order |
|
465 | # sort by revision (per file) which is a topological order | |
466 | visit = [] |
|
466 | visit = [] | |
467 | for f in files: |
|
467 | for f in files: | |
468 | visit.extend(n for n in needed if n._path == f) |
|
468 | visit.extend(n for n in needed if n._path == f) | |
469 |
|
469 | |||
470 | hist = {} |
|
470 | hist = {} | |
471 | for f in sorted(visit, key=lambda x: x.rev()): |
|
471 | for f in sorted(visit, key=lambda x: x.rev()): | |
472 | curr = decorate(f.data(), f) |
|
472 | curr = decorate(f.data(), f) | |
473 | for p in parents(f): |
|
473 | for p in parents(f): | |
474 | curr = pair(hist[p], curr) |
|
474 | curr = pair(hist[p], curr) | |
475 | # trim the history of unneeded revs |
|
475 | # trim the history of unneeded revs | |
476 | needed[p] -= 1 |
|
476 | needed[p] -= 1 | |
477 | if not needed[p]: |
|
477 | if not needed[p]: | |
478 | del hist[p] |
|
478 | del hist[p] | |
479 | hist[f] = curr |
|
479 | hist[f] = curr | |
480 |
|
480 | |||
481 | return zip(hist[f][0], hist[f][1].splitlines(True)) |
|
481 | return zip(hist[f][0], hist[f][1].splitlines(True)) | |
482 |
|
482 | |||
483 | def ancestor(self, fc2): |
|
483 | def ancestor(self, fc2): | |
484 | """ |
|
484 | """ | |
485 | find the common ancestor file context, if any, of self, and fc2 |
|
485 | find the common ancestor file context, if any, of self, and fc2 | |
486 | """ |
|
486 | """ | |
487 |
|
487 | |||
488 | actx = self.changectx().ancestor(fc2.changectx()) |
|
488 | actx = self.changectx().ancestor(fc2.changectx()) | |
489 |
|
489 | |||
490 | # the trivial case: changesets are unrelated, files must be too |
|
490 | # the trivial case: changesets are unrelated, files must be too | |
491 | if not actx: |
|
491 | if not actx: | |
492 | return None |
|
492 | return None | |
493 |
|
493 | |||
494 | # the easy case: no (relevant) renames |
|
494 | # the easy case: no (relevant) renames | |
495 | if fc2.path() == self.path() and self.path() in actx: |
|
495 | if fc2.path() == self.path() and self.path() in actx: | |
496 | return actx[self.path()] |
|
496 | return actx[self.path()] | |
497 | acache = {} |
|
497 | acache = {} | |
498 |
|
498 | |||
499 | # prime the ancestor cache for the working directory |
|
499 | # prime the ancestor cache for the working directory | |
500 | for c in (self, fc2): |
|
500 | for c in (self, fc2): | |
501 | if c._filerev is None: |
|
501 | if c._filerev is None: | |
502 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
502 | pl = [(n.path(), n.filenode()) for n in c.parents()] | |
503 | acache[(c._path, None)] = pl |
|
503 | acache[(c._path, None)] = pl | |
504 |
|
504 | |||
505 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
|
505 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} | |
506 | def parents(vertex): |
|
506 | def parents(vertex): | |
507 | if vertex in acache: |
|
507 | if vertex in acache: | |
508 | return acache[vertex] |
|
508 | return acache[vertex] | |
509 | f, n = vertex |
|
509 | f, n = vertex | |
510 | if f not in flcache: |
|
510 | if f not in flcache: | |
511 | flcache[f] = self._repo.file(f) |
|
511 | flcache[f] = self._repo.file(f) | |
512 | fl = flcache[f] |
|
512 | fl = flcache[f] | |
513 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
513 | pl = [(f, p) for p in fl.parents(n) if p != nullid] | |
514 | re = fl.renamed(n) |
|
514 | re = fl.renamed(n) | |
515 | if re: |
|
515 | if re: | |
516 | pl.append(re) |
|
516 | pl.append(re) | |
517 | acache[vertex] = pl |
|
517 | acache[vertex] = pl | |
518 | return pl |
|
518 | return pl | |
519 |
|
519 | |||
520 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
520 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) | |
521 | v = ancestor.ancestor(a, b, parents) |
|
521 | v = ancestor.ancestor(a, b, parents) | |
522 | if v: |
|
522 | if v: | |
523 | f, n = v |
|
523 | f, n = v | |
524 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
524 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) | |
525 |
|
525 | |||
526 | return None |
|
526 | return None | |
527 |
|
527 | |||
528 | def ancestors(self): |
|
528 | def ancestors(self): | |
529 | seen = set(str(self)) |
|
529 | seen = set(str(self)) | |
530 | visit = [self] |
|
530 | visit = [self] | |
531 | while visit: |
|
531 | while visit: | |
532 | for parent in visit.pop(0).parents(): |
|
532 | for parent in visit.pop(0).parents(): | |
533 | s = str(parent) |
|
533 | s = str(parent) | |
534 | if s not in seen: |
|
534 | if s not in seen: | |
535 | visit.append(parent) |
|
535 | visit.append(parent) | |
536 | seen.add(s) |
|
536 | seen.add(s) | |
537 | yield parent |
|
537 | yield parent | |
538 |
|
538 | |||
539 | class workingctx(changectx): |
|
539 | class workingctx(changectx): | |
540 | """A workingctx object makes access to data related to |
|
540 | """A workingctx object makes access to data related to | |
541 | the current working directory convenient. |
|
541 | the current working directory convenient. | |
542 | parents - a pair of parent nodeids, or None to use the dirstate. |
|
|||
543 | date - any valid date string or (unixtime, offset), or None. |
|
542 | date - any valid date string or (unixtime, offset), or None. | |
544 | user - username string, or None. |
|
543 | user - username string, or None. | |
545 | extra - a dictionary of extra values, or None. |
|
544 | extra - a dictionary of extra values, or None. | |
546 | changes - a list of file lists as returned by localrepo.status() |
|
545 | changes - a list of file lists as returned by localrepo.status() | |
547 | or None to use the repository status. |
|
546 | or None to use the repository status. | |
548 | """ |
|
547 | """ | |
549 |
def __init__(self, repo |
|
548 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
550 |
|
|
549 | changes=None): | |
551 | self._repo = repo |
|
550 | self._repo = repo | |
552 | self._rev = None |
|
551 | self._rev = None | |
553 | self._node = None |
|
552 | self._node = None | |
554 | self._text = text |
|
553 | self._text = text | |
555 | if date: |
|
554 | if date: | |
556 | self._date = util.parsedate(date) |
|
555 | self._date = util.parsedate(date) | |
557 | if user: |
|
556 | if user: | |
558 | self._user = user |
|
557 | self._user = user | |
559 | if parents: |
|
|||
560 | self._parents = [changectx(self._repo, p) for p in parents] |
|
|||
561 | if changes: |
|
558 | if changes: | |
562 | self._status = list(changes) |
|
559 | self._status = list(changes) | |
563 |
|
560 | |||
564 | self._extra = {} |
|
561 | self._extra = {} | |
565 | if extra: |
|
562 | if extra: | |
566 | self._extra = extra.copy() |
|
563 | self._extra = extra.copy() | |
567 | if 'branch' not in self._extra: |
|
564 | if 'branch' not in self._extra: | |
568 | branch = self._repo.dirstate.branch() |
|
565 | branch = self._repo.dirstate.branch() | |
569 | try: |
|
566 | try: | |
570 | branch = branch.decode('UTF-8').encode('UTF-8') |
|
567 | branch = branch.decode('UTF-8').encode('UTF-8') | |
571 | except UnicodeDecodeError: |
|
568 | except UnicodeDecodeError: | |
572 | raise util.Abort(_('branch name not in UTF-8!')) |
|
569 | raise util.Abort(_('branch name not in UTF-8!')) | |
573 | self._extra['branch'] = branch |
|
570 | self._extra['branch'] = branch | |
574 | if self._extra['branch'] == '': |
|
571 | if self._extra['branch'] == '': | |
575 | self._extra['branch'] = 'default' |
|
572 | self._extra['branch'] = 'default' | |
576 |
|
573 | |||
577 | def __str__(self): |
|
574 | def __str__(self): | |
578 | return str(self._parents[0]) + "+" |
|
575 | return str(self._parents[0]) + "+" | |
579 |
|
576 | |||
580 | def __nonzero__(self): |
|
577 | def __nonzero__(self): | |
581 | return True |
|
578 | return True | |
582 |
|
579 | |||
583 | def __contains__(self, key): |
|
580 | def __contains__(self, key): | |
584 | return self._repo.dirstate[key] not in "?r" |
|
581 | return self._repo.dirstate[key] not in "?r" | |
585 |
|
582 | |||
586 | @propertycache |
|
583 | @propertycache | |
587 | def _manifest(self): |
|
584 | def _manifest(self): | |
588 | """generate a manifest corresponding to the working directory""" |
|
585 | """generate a manifest corresponding to the working directory""" | |
589 |
|
586 | |||
590 | man = self._parents[0].manifest().copy() |
|
587 | man = self._parents[0].manifest().copy() | |
591 | copied = self._repo.dirstate.copies() |
|
588 | copied = self._repo.dirstate.copies() | |
592 | if len(self._parents) > 1: |
|
589 | if len(self._parents) > 1: | |
593 | man2 = self.p2().manifest() |
|
590 | man2 = self.p2().manifest() | |
594 | def getman(f): |
|
591 | def getman(f): | |
595 | if f in man: |
|
592 | if f in man: | |
596 | return man |
|
593 | return man | |
597 | return man2 |
|
594 | return man2 | |
598 | else: |
|
595 | else: | |
599 | getman = lambda f: man |
|
596 | getman = lambda f: man | |
600 | def cf(f): |
|
597 | def cf(f): | |
601 | f = copied.get(f, f) |
|
598 | f = copied.get(f, f) | |
602 | return getman(f).flags(f) |
|
599 | return getman(f).flags(f) | |
603 | ff = self._repo.dirstate.flagfunc(cf) |
|
600 | ff = self._repo.dirstate.flagfunc(cf) | |
604 | modified, added, removed, deleted, unknown = self._status[:5] |
|
601 | modified, added, removed, deleted, unknown = self._status[:5] | |
605 | for i, l in (("a", added), ("m", modified), ("u", unknown)): |
|
602 | for i, l in (("a", added), ("m", modified), ("u", unknown)): | |
606 | for f in l: |
|
603 | for f in l: | |
607 | orig = copied.get(f, f) |
|
604 | orig = copied.get(f, f) | |
608 | man[f] = getman(orig).get(orig, nullid) + i |
|
605 | man[f] = getman(orig).get(orig, nullid) + i | |
609 | try: |
|
606 | try: | |
610 | man.set(f, ff(f)) |
|
607 | man.set(f, ff(f)) | |
611 | except OSError: |
|
608 | except OSError: | |
612 | pass |
|
609 | pass | |
613 |
|
610 | |||
614 | for f in deleted + removed: |
|
611 | for f in deleted + removed: | |
615 | if f in man: |
|
612 | if f in man: | |
616 | del man[f] |
|
613 | del man[f] | |
617 |
|
614 | |||
618 | return man |
|
615 | return man | |
619 |
|
616 | |||
620 | @propertycache |
|
617 | @propertycache | |
621 | def _status(self): |
|
618 | def _status(self): | |
622 | return self._repo.status(unknown=True) |
|
619 | return self._repo.status(unknown=True) | |
623 |
|
620 | |||
624 | @propertycache |
|
621 | @propertycache | |
625 | def _user(self): |
|
622 | def _user(self): | |
626 | return self._repo.ui.username() |
|
623 | return self._repo.ui.username() | |
627 |
|
624 | |||
628 | @propertycache |
|
625 | @propertycache | |
629 | def _date(self): |
|
626 | def _date(self): | |
630 | return util.makedate() |
|
627 | return util.makedate() | |
631 |
|
628 | |||
632 | @propertycache |
|
629 | @propertycache | |
633 | def _parents(self): |
|
630 | def _parents(self): | |
634 | p = self._repo.dirstate.parents() |
|
631 | p = self._repo.dirstate.parents() | |
635 | if p[1] == nullid: |
|
632 | if p[1] == nullid: | |
636 | p = p[:-1] |
|
633 | p = p[:-1] | |
637 | self._parents = [changectx(self._repo, x) for x in p] |
|
634 | self._parents = [changectx(self._repo, x) for x in p] | |
638 | return self._parents |
|
635 | return self._parents | |
639 |
|
636 | |||
640 | def manifest(self): |
|
637 | def manifest(self): | |
641 | return self._manifest |
|
638 | return self._manifest | |
642 | def user(self): |
|
639 | def user(self): | |
643 | return self._user or self._repo.ui.username() |
|
640 | return self._user or self._repo.ui.username() | |
644 | def date(self): |
|
641 | def date(self): | |
645 | return self._date |
|
642 | return self._date | |
646 | def description(self): |
|
643 | def description(self): | |
647 | return self._text |
|
644 | return self._text | |
648 | def files(self): |
|
645 | def files(self): | |
649 | return sorted(self._status[0] + self._status[1] + self._status[2]) |
|
646 | return sorted(self._status[0] + self._status[1] + self._status[2]) | |
650 |
|
647 | |||
651 | def modified(self): |
|
648 | def modified(self): | |
652 | return self._status[0] |
|
649 | return self._status[0] | |
653 | def added(self): |
|
650 | def added(self): | |
654 | return self._status[1] |
|
651 | return self._status[1] | |
655 | def removed(self): |
|
652 | def removed(self): | |
656 | return self._status[2] |
|
653 | return self._status[2] | |
657 | def deleted(self): |
|
654 | def deleted(self): | |
658 | return self._status[3] |
|
655 | return self._status[3] | |
659 | def unknown(self): |
|
656 | def unknown(self): | |
660 | return self._status[4] |
|
657 | return self._status[4] | |
661 | def clean(self): |
|
658 | def clean(self): | |
662 | return self._status[5] |
|
659 | return self._status[5] | |
663 | def branch(self): |
|
660 | def branch(self): | |
664 | return self._extra['branch'] |
|
661 | return self._extra['branch'] | |
665 | def extra(self): |
|
662 | def extra(self): | |
666 | return self._extra |
|
663 | return self._extra | |
667 |
|
664 | |||
668 | def tags(self): |
|
665 | def tags(self): | |
669 | t = [] |
|
666 | t = [] | |
670 | [t.extend(p.tags()) for p in self.parents()] |
|
667 | [t.extend(p.tags()) for p in self.parents()] | |
671 | return t |
|
668 | return t | |
672 |
|
669 | |||
673 | def children(self): |
|
670 | def children(self): | |
674 | return [] |
|
671 | return [] | |
675 |
|
672 | |||
676 | def flags(self, path): |
|
673 | def flags(self, path): | |
677 | if '_manifest' in self.__dict__: |
|
674 | if '_manifest' in self.__dict__: | |
678 | try: |
|
675 | try: | |
679 | return self._manifest.flags(path) |
|
676 | return self._manifest.flags(path) | |
680 | except KeyError: |
|
677 | except KeyError: | |
681 | return '' |
|
678 | return '' | |
682 |
|
679 | |||
683 | orig = self._repo.dirstate.copies().get(path, path) |
|
680 | orig = self._repo.dirstate.copies().get(path, path) | |
684 |
|
681 | |||
685 | def findflag(ctx): |
|
682 | def findflag(ctx): | |
686 | mnode = ctx.changeset()[0] |
|
683 | mnode = ctx.changeset()[0] | |
687 | node, flag = self._repo.manifest.find(mnode, orig) |
|
684 | node, flag = self._repo.manifest.find(mnode, orig) | |
688 | ff = self._repo.dirstate.flagfunc(lambda x: flag or None) |
|
685 | ff = self._repo.dirstate.flagfunc(lambda x: flag or None) | |
689 | try: |
|
686 | try: | |
690 | return ff(path) |
|
687 | return ff(path) | |
691 | except OSError: |
|
688 | except OSError: | |
692 | pass |
|
689 | pass | |
693 |
|
690 | |||
694 | flag = findflag(self._parents[0]) |
|
691 | flag = findflag(self._parents[0]) | |
695 | if flag is None and len(self.parents()) > 1: |
|
692 | if flag is None and len(self.parents()) > 1: | |
696 | flag = findflag(self._parents[1]) |
|
693 | flag = findflag(self._parents[1]) | |
697 | if flag is None or self._repo.dirstate[path] == 'r': |
|
694 | if flag is None or self._repo.dirstate[path] == 'r': | |
698 | return '' |
|
695 | return '' | |
699 | return flag |
|
696 | return flag | |
700 |
|
697 | |||
701 | def filectx(self, path, filelog=None): |
|
698 | def filectx(self, path, filelog=None): | |
702 | """get a file context from the working directory""" |
|
699 | """get a file context from the working directory""" | |
703 | return workingfilectx(self._repo, path, workingctx=self, |
|
700 | return workingfilectx(self._repo, path, workingctx=self, | |
704 | filelog=filelog) |
|
701 | filelog=filelog) | |
705 |
|
702 | |||
706 | def ancestor(self, c2): |
|
703 | def ancestor(self, c2): | |
707 | """return the ancestor context of self and c2""" |
|
704 | """return the ancestor context of self and c2""" | |
708 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
705 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
709 |
|
706 | |||
710 | def walk(self, match): |
|
707 | def walk(self, match): | |
711 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), |
|
708 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), | |
712 | True, False)) |
|
709 | True, False)) | |
713 |
|
710 | |||
714 | def dirty(self, missing=False): |
|
711 | def dirty(self, missing=False): | |
715 | "check whether a working directory is modified" |
|
712 | "check whether a working directory is modified" | |
716 |
|
713 | |||
717 | return (self.p2() or self.branch() != self.p1().branch() or |
|
714 | return (self.p2() or self.branch() != self.p1().branch() or | |
718 | self.modified() or self.added() or self.removed() or |
|
715 | self.modified() or self.added() or self.removed() or | |
719 | (missing and self.deleted())) |
|
716 | (missing and self.deleted())) | |
720 |
|
717 | |||
721 | class workingfilectx(filectx): |
|
718 | class workingfilectx(filectx): | |
722 | """A workingfilectx object makes access to data related to a particular |
|
719 | """A workingfilectx object makes access to data related to a particular | |
723 | file in the working directory convenient.""" |
|
720 | file in the working directory convenient.""" | |
724 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
721 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
725 | """changeid can be a changeset revision, node, or tag. |
|
722 | """changeid can be a changeset revision, node, or tag. | |
726 | fileid can be a file revision or node.""" |
|
723 | fileid can be a file revision or node.""" | |
727 | self._repo = repo |
|
724 | self._repo = repo | |
728 | self._path = path |
|
725 | self._path = path | |
729 | self._changeid = None |
|
726 | self._changeid = None | |
730 | self._filerev = self._filenode = None |
|
727 | self._filerev = self._filenode = None | |
731 |
|
728 | |||
732 | if filelog: |
|
729 | if filelog: | |
733 | self._filelog = filelog |
|
730 | self._filelog = filelog | |
734 | if workingctx: |
|
731 | if workingctx: | |
735 | self._changectx = workingctx |
|
732 | self._changectx = workingctx | |
736 |
|
733 | |||
737 | @propertycache |
|
734 | @propertycache | |
738 | def _changectx(self): |
|
735 | def _changectx(self): | |
739 | return workingctx(self._repo) |
|
736 | return workingctx(self._repo) | |
740 |
|
737 | |||
741 | def __nonzero__(self): |
|
738 | def __nonzero__(self): | |
742 | return True |
|
739 | return True | |
743 |
|
740 | |||
744 | def __str__(self): |
|
741 | def __str__(self): | |
745 | return "%s@%s" % (self.path(), self._changectx) |
|
742 | return "%s@%s" % (self.path(), self._changectx) | |
746 |
|
743 | |||
747 | def data(self): |
|
744 | def data(self): | |
748 | return self._repo.wread(self._path) |
|
745 | return self._repo.wread(self._path) | |
749 | def renamed(self): |
|
746 | def renamed(self): | |
750 | rp = self._repo.dirstate.copied(self._path) |
|
747 | rp = self._repo.dirstate.copied(self._path) | |
751 | if not rp: |
|
748 | if not rp: | |
752 | return None |
|
749 | return None | |
753 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
750 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
754 |
|
751 | |||
755 | def parents(self): |
|
752 | def parents(self): | |
756 | '''return parent filectxs, following copies if necessary''' |
|
753 | '''return parent filectxs, following copies if necessary''' | |
757 | def filenode(ctx, path): |
|
754 | def filenode(ctx, path): | |
758 | return ctx._manifest.get(path, nullid) |
|
755 | return ctx._manifest.get(path, nullid) | |
759 |
|
756 | |||
760 | path = self._path |
|
757 | path = self._path | |
761 | fl = self._filelog |
|
758 | fl = self._filelog | |
762 | pcl = self._changectx._parents |
|
759 | pcl = self._changectx._parents | |
763 | renamed = self.renamed() |
|
760 | renamed = self.renamed() | |
764 |
|
761 | |||
765 | if renamed: |
|
762 | if renamed: | |
766 | pl = [renamed + (None,)] |
|
763 | pl = [renamed + (None,)] | |
767 | else: |
|
764 | else: | |
768 | pl = [(path, filenode(pcl[0], path), fl)] |
|
765 | pl = [(path, filenode(pcl[0], path), fl)] | |
769 |
|
766 | |||
770 | for pc in pcl[1:]: |
|
767 | for pc in pcl[1:]: | |
771 | pl.append((path, filenode(pc, path), fl)) |
|
768 | pl.append((path, filenode(pc, path), fl)) | |
772 |
|
769 | |||
773 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
770 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
774 | for p, n, l in pl if n != nullid] |
|
771 | for p, n, l in pl if n != nullid] | |
775 |
|
772 | |||
776 | def children(self): |
|
773 | def children(self): | |
777 | return [] |
|
774 | return [] | |
778 |
|
775 | |||
779 | def size(self): |
|
776 | def size(self): | |
780 | return os.stat(self._repo.wjoin(self._path)).st_size |
|
777 | return os.stat(self._repo.wjoin(self._path)).st_size | |
781 | def date(self): |
|
778 | def date(self): | |
782 | t, tz = self._changectx.date() |
|
779 | t, tz = self._changectx.date() | |
783 | try: |
|
780 | try: | |
784 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
|
781 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) | |
785 | except OSError, err: |
|
782 | except OSError, err: | |
786 | if err.errno != errno.ENOENT: |
|
783 | if err.errno != errno.ENOENT: | |
787 | raise |
|
784 | raise | |
788 | return (t, tz) |
|
785 | return (t, tz) | |
789 |
|
786 | |||
790 | def cmp(self, text): |
|
787 | def cmp(self, text): | |
791 | return self._repo.wread(self._path) == text |
|
788 | return self._repo.wread(self._path) == text | |
792 |
|
789 | |||
793 | class memctx(object): |
|
790 | class memctx(object): | |
794 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
791 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
795 |
|
792 | |||
796 | Revision information is supplied at initialization time while |
|
793 | Revision information is supplied at initialization time while | |
797 | related files data and is made available through a callback |
|
794 | related files data and is made available through a callback | |
798 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
795 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
799 | sequence of two parent revisions identifiers (pass None for every |
|
796 | sequence of two parent revisions identifiers (pass None for every | |
800 | missing parent), 'text' is the commit message and 'files' lists |
|
797 | missing parent), 'text' is the commit message and 'files' lists | |
801 | names of files touched by the revision (normalized and relative to |
|
798 | names of files touched by the revision (normalized and relative to | |
802 | repository root). |
|
799 | repository root). | |
803 |
|
800 | |||
804 | filectxfn(repo, memctx, path) is a callable receiving the |
|
801 | filectxfn(repo, memctx, path) is a callable receiving the | |
805 | repository, the current memctx object and the normalized path of |
|
802 | repository, the current memctx object and the normalized path of | |
806 | requested file, relative to repository root. It is fired by the |
|
803 | requested file, relative to repository root. It is fired by the | |
807 | commit function for every file in 'files', but calls order is |
|
804 | commit function for every file in 'files', but calls order is | |
808 | undefined. If the file is available in the revision being |
|
805 | undefined. If the file is available in the revision being | |
809 | committed (updated or added), filectxfn returns a memfilectx |
|
806 | committed (updated or added), filectxfn returns a memfilectx | |
810 | object. If the file was removed, filectxfn raises an |
|
807 | object. If the file was removed, filectxfn raises an | |
811 | IOError. Moved files are represented by marking the source file |
|
808 | IOError. Moved files are represented by marking the source file | |
812 | removed and the new file added with copy information (see |
|
809 | removed and the new file added with copy information (see | |
813 | memfilectx). |
|
810 | memfilectx). | |
814 |
|
811 | |||
815 | user receives the committer name and defaults to current |
|
812 | user receives the committer name and defaults to current | |
816 | repository username, date is the commit date in any format |
|
813 | repository username, date is the commit date in any format | |
817 | supported by util.parsedate() and defaults to current date, extra |
|
814 | supported by util.parsedate() and defaults to current date, extra | |
818 | is a dictionary of metadata or is left empty. |
|
815 | is a dictionary of metadata or is left empty. | |
819 | """ |
|
816 | """ | |
820 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
817 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
821 | date=None, extra=None): |
|
818 | date=None, extra=None): | |
822 | self._repo = repo |
|
819 | self._repo = repo | |
823 | self._rev = None |
|
820 | self._rev = None | |
824 | self._node = None |
|
821 | self._node = None | |
825 | self._text = text |
|
822 | self._text = text | |
826 | self._date = date and util.parsedate(date) or util.makedate() |
|
823 | self._date = date and util.parsedate(date) or util.makedate() | |
827 | self._user = user |
|
824 | self._user = user | |
828 | parents = [(p or nullid) for p in parents] |
|
825 | parents = [(p or nullid) for p in parents] | |
829 | p1, p2 = parents |
|
826 | p1, p2 = parents | |
830 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
827 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
831 | files = sorted(set(files)) |
|
828 | files = sorted(set(files)) | |
832 | self._status = [files, [], [], [], []] |
|
829 | self._status = [files, [], [], [], []] | |
833 | self._filectxfn = filectxfn |
|
830 | self._filectxfn = filectxfn | |
834 |
|
831 | |||
835 | self._extra = extra and extra.copy() or {} |
|
832 | self._extra = extra and extra.copy() or {} | |
836 | if 'branch' not in self._extra: |
|
833 | if 'branch' not in self._extra: | |
837 | self._extra['branch'] = 'default' |
|
834 | self._extra['branch'] = 'default' | |
838 | elif self._extra.get('branch') == '': |
|
835 | elif self._extra.get('branch') == '': | |
839 | self._extra['branch'] = 'default' |
|
836 | self._extra['branch'] = 'default' | |
840 |
|
837 | |||
841 | def __str__(self): |
|
838 | def __str__(self): | |
842 | return str(self._parents[0]) + "+" |
|
839 | return str(self._parents[0]) + "+" | |
843 |
|
840 | |||
844 | def __int__(self): |
|
841 | def __int__(self): | |
845 | return self._rev |
|
842 | return self._rev | |
846 |
|
843 | |||
847 | def __nonzero__(self): |
|
844 | def __nonzero__(self): | |
848 | return True |
|
845 | return True | |
849 |
|
846 | |||
850 | def __getitem__(self, key): |
|
847 | def __getitem__(self, key): | |
851 | return self.filectx(key) |
|
848 | return self.filectx(key) | |
852 |
|
849 | |||
853 | def p1(self): |
|
850 | def p1(self): | |
854 | return self._parents[0] |
|
851 | return self._parents[0] | |
855 | def p2(self): |
|
852 | def p2(self): | |
856 | return self._parents[1] |
|
853 | return self._parents[1] | |
857 |
|
854 | |||
858 | def user(self): |
|
855 | def user(self): | |
859 | return self._user or self._repo.ui.username() |
|
856 | return self._user or self._repo.ui.username() | |
860 | def date(self): |
|
857 | def date(self): | |
861 | return self._date |
|
858 | return self._date | |
862 | def description(self): |
|
859 | def description(self): | |
863 | return self._text |
|
860 | return self._text | |
864 | def files(self): |
|
861 | def files(self): | |
865 | return self.modified() |
|
862 | return self.modified() | |
866 | def modified(self): |
|
863 | def modified(self): | |
867 | return self._status[0] |
|
864 | return self._status[0] | |
868 | def added(self): |
|
865 | def added(self): | |
869 | return self._status[1] |
|
866 | return self._status[1] | |
870 | def removed(self): |
|
867 | def removed(self): | |
871 | return self._status[2] |
|
868 | return self._status[2] | |
872 | def deleted(self): |
|
869 | def deleted(self): | |
873 | return self._status[3] |
|
870 | return self._status[3] | |
874 | def unknown(self): |
|
871 | def unknown(self): | |
875 | return self._status[4] |
|
872 | return self._status[4] | |
876 | def clean(self): |
|
873 | def clean(self): | |
877 | return self._status[5] |
|
874 | return self._status[5] | |
878 | def branch(self): |
|
875 | def branch(self): | |
879 | return self._extra['branch'] |
|
876 | return self._extra['branch'] | |
880 | def extra(self): |
|
877 | def extra(self): | |
881 | return self._extra |
|
878 | return self._extra | |
882 | def flags(self, f): |
|
879 | def flags(self, f): | |
883 | return self[f].flags() |
|
880 | return self[f].flags() | |
884 |
|
881 | |||
885 | def parents(self): |
|
882 | def parents(self): | |
886 | """return contexts for each parent changeset""" |
|
883 | """return contexts for each parent changeset""" | |
887 | return self._parents |
|
884 | return self._parents | |
888 |
|
885 | |||
889 | def filectx(self, path, filelog=None): |
|
886 | def filectx(self, path, filelog=None): | |
890 | """get a file context from the working directory""" |
|
887 | """get a file context from the working directory""" | |
891 | return self._filectxfn(self._repo, self, path) |
|
888 | return self._filectxfn(self._repo, self, path) | |
892 |
|
889 | |||
893 | class memfilectx(object): |
|
890 | class memfilectx(object): | |
894 | """memfilectx represents an in-memory file to commit. |
|
891 | """memfilectx represents an in-memory file to commit. | |
895 |
|
892 | |||
896 | See memctx for more details. |
|
893 | See memctx for more details. | |
897 | """ |
|
894 | """ | |
898 | def __init__(self, path, data, islink, isexec, copied): |
|
895 | def __init__(self, path, data, islink, isexec, copied): | |
899 | """ |
|
896 | """ | |
900 | path is the normalized file path relative to repository root. |
|
897 | path is the normalized file path relative to repository root. | |
901 | data is the file content as a string. |
|
898 | data is the file content as a string. | |
902 | islink is True if the file is a symbolic link. |
|
899 | islink is True if the file is a symbolic link. | |
903 | isexec is True if the file is executable. |
|
900 | isexec is True if the file is executable. | |
904 | copied is the source file path if current file was copied in the |
|
901 | copied is the source file path if current file was copied in the | |
905 | revision being committed, or None.""" |
|
902 | revision being committed, or None.""" | |
906 | self._path = path |
|
903 | self._path = path | |
907 | self._data = data |
|
904 | self._data = data | |
908 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
905 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
909 | self._copied = None |
|
906 | self._copied = None | |
910 | if copied: |
|
907 | if copied: | |
911 | self._copied = (copied, nullid) |
|
908 | self._copied = (copied, nullid) | |
912 |
|
909 | |||
913 | def __nonzero__(self): |
|
910 | def __nonzero__(self): | |
914 | return True |
|
911 | return True | |
915 | def __str__(self): |
|
912 | def __str__(self): | |
916 | return "%s@%s" % (self.path(), self._changectx) |
|
913 | return "%s@%s" % (self.path(), self._changectx) | |
917 | def path(self): |
|
914 | def path(self): | |
918 | return self._path |
|
915 | return self._path | |
919 | def data(self): |
|
916 | def data(self): | |
920 | return self._data |
|
917 | return self._data | |
921 | def flags(self): |
|
918 | def flags(self): | |
922 | return self._flags |
|
919 | return self._flags | |
923 | def isexec(self): |
|
920 | def isexec(self): | |
924 | return 'x' in self._flags |
|
921 | return 'x' in self._flags | |
925 | def islink(self): |
|
922 | def islink(self): | |
926 | return 'l' in self._flags |
|
923 | return 'l' in self._flags | |
927 | def renamed(self): |
|
924 | def renamed(self): | |
928 | return self._copied |
|
925 | return self._copied |
@@ -1,2255 +1,2254 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import bin, hex, nullid, nullrev, short |
|
8 | from node import bin, hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import repo, changegroup, subrepo |
|
10 | import repo, changegroup, subrepo | |
11 | import changelog, dirstate, filelog, manifest, context |
|
11 | import changelog, dirstate, filelog, manifest, context | |
12 | import lock, transaction, store, encoding |
|
12 | import lock, transaction, store, encoding | |
13 | import util, extensions, hook, error |
|
13 | import util, extensions, hook, error | |
14 | import match as matchmod |
|
14 | import match as matchmod | |
15 | import merge as mergemod |
|
15 | import merge as mergemod | |
16 | import tags as tagsmod |
|
16 | import tags as tagsmod | |
17 | import url as urlmod |
|
17 | import url as urlmod | |
18 | from lock import release |
|
18 | from lock import release | |
19 | import weakref, stat, errno, os, time, inspect |
|
19 | import weakref, stat, errno, os, time, inspect | |
20 | propertycache = util.propertycache |
|
20 | propertycache = util.propertycache | |
21 |
|
21 | |||
22 | class localrepository(repo.repository): |
|
22 | class localrepository(repo.repository): | |
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap')) |
|
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap')) | |
24 | supported = set('revlogv1 store fncache shared'.split()) |
|
24 | supported = set('revlogv1 store fncache shared'.split()) | |
25 |
|
25 | |||
26 | def __init__(self, baseui, path=None, create=0): |
|
26 | def __init__(self, baseui, path=None, create=0): | |
27 | repo.repository.__init__(self) |
|
27 | repo.repository.__init__(self) | |
28 | self.root = os.path.realpath(path) |
|
28 | self.root = os.path.realpath(path) | |
29 | self.path = os.path.join(self.root, ".hg") |
|
29 | self.path = os.path.join(self.root, ".hg") | |
30 | self.origroot = path |
|
30 | self.origroot = path | |
31 | self.opener = util.opener(self.path) |
|
31 | self.opener = util.opener(self.path) | |
32 | self.wopener = util.opener(self.root) |
|
32 | self.wopener = util.opener(self.root) | |
33 | self.baseui = baseui |
|
33 | self.baseui = baseui | |
34 | self.ui = baseui.copy() |
|
34 | self.ui = baseui.copy() | |
35 |
|
35 | |||
36 | try: |
|
36 | try: | |
37 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
37 | self.ui.readconfig(self.join("hgrc"), self.root) | |
38 | extensions.loadall(self.ui) |
|
38 | extensions.loadall(self.ui) | |
39 | except IOError: |
|
39 | except IOError: | |
40 | pass |
|
40 | pass | |
41 |
|
41 | |||
42 | if not os.path.isdir(self.path): |
|
42 | if not os.path.isdir(self.path): | |
43 | if create: |
|
43 | if create: | |
44 | if not os.path.exists(path): |
|
44 | if not os.path.exists(path): | |
45 | os.mkdir(path) |
|
45 | os.mkdir(path) | |
46 | os.mkdir(self.path) |
|
46 | os.mkdir(self.path) | |
47 | requirements = ["revlogv1"] |
|
47 | requirements = ["revlogv1"] | |
48 | if self.ui.configbool('format', 'usestore', True): |
|
48 | if self.ui.configbool('format', 'usestore', True): | |
49 | os.mkdir(os.path.join(self.path, "store")) |
|
49 | os.mkdir(os.path.join(self.path, "store")) | |
50 | requirements.append("store") |
|
50 | requirements.append("store") | |
51 | if self.ui.configbool('format', 'usefncache', True): |
|
51 | if self.ui.configbool('format', 'usefncache', True): | |
52 | requirements.append("fncache") |
|
52 | requirements.append("fncache") | |
53 | # create an invalid changelog |
|
53 | # create an invalid changelog | |
54 | self.opener("00changelog.i", "a").write( |
|
54 | self.opener("00changelog.i", "a").write( | |
55 | '\0\0\0\2' # represents revlogv2 |
|
55 | '\0\0\0\2' # represents revlogv2 | |
56 | ' dummy changelog to prevent using the old repo layout' |
|
56 | ' dummy changelog to prevent using the old repo layout' | |
57 | ) |
|
57 | ) | |
58 | reqfile = self.opener("requires", "w") |
|
58 | reqfile = self.opener("requires", "w") | |
59 | for r in requirements: |
|
59 | for r in requirements: | |
60 | reqfile.write("%s\n" % r) |
|
60 | reqfile.write("%s\n" % r) | |
61 | reqfile.close() |
|
61 | reqfile.close() | |
62 | else: |
|
62 | else: | |
63 | raise error.RepoError(_("repository %s not found") % path) |
|
63 | raise error.RepoError(_("repository %s not found") % path) | |
64 | elif create: |
|
64 | elif create: | |
65 | raise error.RepoError(_("repository %s already exists") % path) |
|
65 | raise error.RepoError(_("repository %s already exists") % path) | |
66 | else: |
|
66 | else: | |
67 | # find requirements |
|
67 | # find requirements | |
68 | requirements = set() |
|
68 | requirements = set() | |
69 | try: |
|
69 | try: | |
70 | requirements = set(self.opener("requires").read().splitlines()) |
|
70 | requirements = set(self.opener("requires").read().splitlines()) | |
71 | except IOError, inst: |
|
71 | except IOError, inst: | |
72 | if inst.errno != errno.ENOENT: |
|
72 | if inst.errno != errno.ENOENT: | |
73 | raise |
|
73 | raise | |
74 | for r in requirements - self.supported: |
|
74 | for r in requirements - self.supported: | |
75 | raise error.RepoError(_("requirement '%s' not supported") % r) |
|
75 | raise error.RepoError(_("requirement '%s' not supported") % r) | |
76 |
|
76 | |||
77 | self.sharedpath = self.path |
|
77 | self.sharedpath = self.path | |
78 | try: |
|
78 | try: | |
79 | s = os.path.realpath(self.opener("sharedpath").read()) |
|
79 | s = os.path.realpath(self.opener("sharedpath").read()) | |
80 | if not os.path.exists(s): |
|
80 | if not os.path.exists(s): | |
81 | raise error.RepoError( |
|
81 | raise error.RepoError( | |
82 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
82 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
83 | self.sharedpath = s |
|
83 | self.sharedpath = s | |
84 | except IOError, inst: |
|
84 | except IOError, inst: | |
85 | if inst.errno != errno.ENOENT: |
|
85 | if inst.errno != errno.ENOENT: | |
86 | raise |
|
86 | raise | |
87 |
|
87 | |||
88 | self.store = store.store(requirements, self.sharedpath, util.opener) |
|
88 | self.store = store.store(requirements, self.sharedpath, util.opener) | |
89 | self.spath = self.store.path |
|
89 | self.spath = self.store.path | |
90 | self.sopener = self.store.opener |
|
90 | self.sopener = self.store.opener | |
91 | self.sjoin = self.store.join |
|
91 | self.sjoin = self.store.join | |
92 | self.opener.createmode = self.store.createmode |
|
92 | self.opener.createmode = self.store.createmode | |
93 | self.sopener.options = {} |
|
93 | self.sopener.options = {} | |
94 |
|
94 | |||
95 | # These two define the set of tags for this repository. _tags |
|
95 | # These two define the set of tags for this repository. _tags | |
96 | # maps tag name to node; _tagtypes maps tag name to 'global' or |
|
96 | # maps tag name to node; _tagtypes maps tag name to 'global' or | |
97 | # 'local'. (Global tags are defined by .hgtags across all |
|
97 | # 'local'. (Global tags are defined by .hgtags across all | |
98 | # heads, and local tags are defined in .hg/localtags.) They |
|
98 | # heads, and local tags are defined in .hg/localtags.) They | |
99 | # constitute the in-memory cache of tags. |
|
99 | # constitute the in-memory cache of tags. | |
100 | self._tags = None |
|
100 | self._tags = None | |
101 | self._tagtypes = None |
|
101 | self._tagtypes = None | |
102 |
|
102 | |||
103 | self._branchcache = None # in UTF-8 |
|
103 | self._branchcache = None # in UTF-8 | |
104 | self._branchcachetip = None |
|
104 | self._branchcachetip = None | |
105 | self.nodetagscache = None |
|
105 | self.nodetagscache = None | |
106 | self.filterpats = {} |
|
106 | self.filterpats = {} | |
107 | self._datafilters = {} |
|
107 | self._datafilters = {} | |
108 | self._transref = self._lockref = self._wlockref = None |
|
108 | self._transref = self._lockref = self._wlockref = None | |
109 |
|
109 | |||
110 | @propertycache |
|
110 | @propertycache | |
111 | def changelog(self): |
|
111 | def changelog(self): | |
112 | c = changelog.changelog(self.sopener) |
|
112 | c = changelog.changelog(self.sopener) | |
113 | if 'HG_PENDING' in os.environ: |
|
113 | if 'HG_PENDING' in os.environ: | |
114 | p = os.environ['HG_PENDING'] |
|
114 | p = os.environ['HG_PENDING'] | |
115 | if p.startswith(self.root): |
|
115 | if p.startswith(self.root): | |
116 | c.readpending('00changelog.i.a') |
|
116 | c.readpending('00changelog.i.a') | |
117 | self.sopener.options['defversion'] = c.version |
|
117 | self.sopener.options['defversion'] = c.version | |
118 | return c |
|
118 | return c | |
119 |
|
119 | |||
120 | @propertycache |
|
120 | @propertycache | |
121 | def manifest(self): |
|
121 | def manifest(self): | |
122 | return manifest.manifest(self.sopener) |
|
122 | return manifest.manifest(self.sopener) | |
123 |
|
123 | |||
124 | @propertycache |
|
124 | @propertycache | |
125 | def dirstate(self): |
|
125 | def dirstate(self): | |
126 | return dirstate.dirstate(self.opener, self.ui, self.root) |
|
126 | return dirstate.dirstate(self.opener, self.ui, self.root) | |
127 |
|
127 | |||
128 | def __getitem__(self, changeid): |
|
128 | def __getitem__(self, changeid): | |
129 | if changeid is None: |
|
129 | if changeid is None: | |
130 | return context.workingctx(self) |
|
130 | return context.workingctx(self) | |
131 | return context.changectx(self, changeid) |
|
131 | return context.changectx(self, changeid) | |
132 |
|
132 | |||
133 | def __contains__(self, changeid): |
|
133 | def __contains__(self, changeid): | |
134 | try: |
|
134 | try: | |
135 | return bool(self.lookup(changeid)) |
|
135 | return bool(self.lookup(changeid)) | |
136 | except error.RepoLookupError: |
|
136 | except error.RepoLookupError: | |
137 | return False |
|
137 | return False | |
138 |
|
138 | |||
139 | def __nonzero__(self): |
|
139 | def __nonzero__(self): | |
140 | return True |
|
140 | return True | |
141 |
|
141 | |||
142 | def __len__(self): |
|
142 | def __len__(self): | |
143 | return len(self.changelog) |
|
143 | return len(self.changelog) | |
144 |
|
144 | |||
145 | def __iter__(self): |
|
145 | def __iter__(self): | |
146 | for i in xrange(len(self)): |
|
146 | for i in xrange(len(self)): | |
147 | yield i |
|
147 | yield i | |
148 |
|
148 | |||
149 | def url(self): |
|
149 | def url(self): | |
150 | return 'file:' + self.root |
|
150 | return 'file:' + self.root | |
151 |
|
151 | |||
152 | def hook(self, name, throw=False, **args): |
|
152 | def hook(self, name, throw=False, **args): | |
153 | return hook.hook(self.ui, self, name, throw, **args) |
|
153 | return hook.hook(self.ui, self, name, throw, **args) | |
154 |
|
154 | |||
155 | tag_disallowed = ':\r\n' |
|
155 | tag_disallowed = ':\r\n' | |
156 |
|
156 | |||
157 | def _tag(self, names, node, message, local, user, date, extra={}): |
|
157 | def _tag(self, names, node, message, local, user, date, extra={}): | |
158 | if isinstance(names, str): |
|
158 | if isinstance(names, str): | |
159 | allchars = names |
|
159 | allchars = names | |
160 | names = (names,) |
|
160 | names = (names,) | |
161 | else: |
|
161 | else: | |
162 | allchars = ''.join(names) |
|
162 | allchars = ''.join(names) | |
163 | for c in self.tag_disallowed: |
|
163 | for c in self.tag_disallowed: | |
164 | if c in allchars: |
|
164 | if c in allchars: | |
165 | raise util.Abort(_('%r cannot be used in a tag name') % c) |
|
165 | raise util.Abort(_('%r cannot be used in a tag name') % c) | |
166 |
|
166 | |||
167 | for name in names: |
|
167 | for name in names: | |
168 | self.hook('pretag', throw=True, node=hex(node), tag=name, |
|
168 | self.hook('pretag', throw=True, node=hex(node), tag=name, | |
169 | local=local) |
|
169 | local=local) | |
170 |
|
170 | |||
171 | def writetags(fp, names, munge, prevtags): |
|
171 | def writetags(fp, names, munge, prevtags): | |
172 | fp.seek(0, 2) |
|
172 | fp.seek(0, 2) | |
173 | if prevtags and prevtags[-1] != '\n': |
|
173 | if prevtags and prevtags[-1] != '\n': | |
174 | fp.write('\n') |
|
174 | fp.write('\n') | |
175 | for name in names: |
|
175 | for name in names: | |
176 | m = munge and munge(name) or name |
|
176 | m = munge and munge(name) or name | |
177 | if self._tagtypes and name in self._tagtypes: |
|
177 | if self._tagtypes and name in self._tagtypes: | |
178 | old = self._tags.get(name, nullid) |
|
178 | old = self._tags.get(name, nullid) | |
179 | fp.write('%s %s\n' % (hex(old), m)) |
|
179 | fp.write('%s %s\n' % (hex(old), m)) | |
180 | fp.write('%s %s\n' % (hex(node), m)) |
|
180 | fp.write('%s %s\n' % (hex(node), m)) | |
181 | fp.close() |
|
181 | fp.close() | |
182 |
|
182 | |||
183 | prevtags = '' |
|
183 | prevtags = '' | |
184 | if local: |
|
184 | if local: | |
185 | try: |
|
185 | try: | |
186 | fp = self.opener('localtags', 'r+') |
|
186 | fp = self.opener('localtags', 'r+') | |
187 | except IOError: |
|
187 | except IOError: | |
188 | fp = self.opener('localtags', 'a') |
|
188 | fp = self.opener('localtags', 'a') | |
189 | else: |
|
189 | else: | |
190 | prevtags = fp.read() |
|
190 | prevtags = fp.read() | |
191 |
|
191 | |||
192 | # local tags are stored in the current charset |
|
192 | # local tags are stored in the current charset | |
193 | writetags(fp, names, None, prevtags) |
|
193 | writetags(fp, names, None, prevtags) | |
194 | for name in names: |
|
194 | for name in names: | |
195 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
195 | self.hook('tag', node=hex(node), tag=name, local=local) | |
196 | return |
|
196 | return | |
197 |
|
197 | |||
198 | try: |
|
198 | try: | |
199 | fp = self.wfile('.hgtags', 'rb+') |
|
199 | fp = self.wfile('.hgtags', 'rb+') | |
200 | except IOError: |
|
200 | except IOError: | |
201 | fp = self.wfile('.hgtags', 'ab') |
|
201 | fp = self.wfile('.hgtags', 'ab') | |
202 | else: |
|
202 | else: | |
203 | prevtags = fp.read() |
|
203 | prevtags = fp.read() | |
204 |
|
204 | |||
205 | # committed tags are stored in UTF-8 |
|
205 | # committed tags are stored in UTF-8 | |
206 | writetags(fp, names, encoding.fromlocal, prevtags) |
|
206 | writetags(fp, names, encoding.fromlocal, prevtags) | |
207 |
|
207 | |||
208 | if '.hgtags' not in self.dirstate: |
|
208 | if '.hgtags' not in self.dirstate: | |
209 | self.add(['.hgtags']) |
|
209 | self.add(['.hgtags']) | |
210 |
|
210 | |||
211 | m = matchmod.exact(self.root, '', ['.hgtags']) |
|
211 | m = matchmod.exact(self.root, '', ['.hgtags']) | |
212 | tagnode = self.commit(message, user, date, extra=extra, match=m) |
|
212 | tagnode = self.commit(message, user, date, extra=extra, match=m) | |
213 |
|
213 | |||
214 | for name in names: |
|
214 | for name in names: | |
215 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
215 | self.hook('tag', node=hex(node), tag=name, local=local) | |
216 |
|
216 | |||
217 | return tagnode |
|
217 | return tagnode | |
218 |
|
218 | |||
219 | def tag(self, names, node, message, local, user, date): |
|
219 | def tag(self, names, node, message, local, user, date): | |
220 | '''tag a revision with one or more symbolic names. |
|
220 | '''tag a revision with one or more symbolic names. | |
221 |
|
221 | |||
222 | names is a list of strings or, when adding a single tag, names may be a |
|
222 | names is a list of strings or, when adding a single tag, names may be a | |
223 | string. |
|
223 | string. | |
224 |
|
224 | |||
225 | if local is True, the tags are stored in a per-repository file. |
|
225 | if local is True, the tags are stored in a per-repository file. | |
226 | otherwise, they are stored in the .hgtags file, and a new |
|
226 | otherwise, they are stored in the .hgtags file, and a new | |
227 | changeset is committed with the change. |
|
227 | changeset is committed with the change. | |
228 |
|
228 | |||
229 | keyword arguments: |
|
229 | keyword arguments: | |
230 |
|
230 | |||
231 | local: whether to store tags in non-version-controlled file |
|
231 | local: whether to store tags in non-version-controlled file | |
232 | (default False) |
|
232 | (default False) | |
233 |
|
233 | |||
234 | message: commit message to use if committing |
|
234 | message: commit message to use if committing | |
235 |
|
235 | |||
236 | user: name of user to use if committing |
|
236 | user: name of user to use if committing | |
237 |
|
237 | |||
238 | date: date tuple to use if committing''' |
|
238 | date: date tuple to use if committing''' | |
239 |
|
239 | |||
240 | for x in self.status()[:5]: |
|
240 | for x in self.status()[:5]: | |
241 | if '.hgtags' in x: |
|
241 | if '.hgtags' in x: | |
242 | raise util.Abort(_('working copy of .hgtags is changed ' |
|
242 | raise util.Abort(_('working copy of .hgtags is changed ' | |
243 | '(please commit .hgtags manually)')) |
|
243 | '(please commit .hgtags manually)')) | |
244 |
|
244 | |||
245 | self.tags() # instantiate the cache |
|
245 | self.tags() # instantiate the cache | |
246 | self._tag(names, node, message, local, user, date) |
|
246 | self._tag(names, node, message, local, user, date) | |
247 |
|
247 | |||
248 | def tags(self): |
|
248 | def tags(self): | |
249 | '''return a mapping of tag to node''' |
|
249 | '''return a mapping of tag to node''' | |
250 | if self._tags is None: |
|
250 | if self._tags is None: | |
251 | (self._tags, self._tagtypes) = self._findtags() |
|
251 | (self._tags, self._tagtypes) = self._findtags() | |
252 |
|
252 | |||
253 | return self._tags |
|
253 | return self._tags | |
254 |
|
254 | |||
255 | def _findtags(self): |
|
255 | def _findtags(self): | |
256 | '''Do the hard work of finding tags. Return a pair of dicts |
|
256 | '''Do the hard work of finding tags. Return a pair of dicts | |
257 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
257 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
258 | maps tag name to a string like \'global\' or \'local\'. |
|
258 | maps tag name to a string like \'global\' or \'local\'. | |
259 | Subclasses or extensions are free to add their own tags, but |
|
259 | Subclasses or extensions are free to add their own tags, but | |
260 | should be aware that the returned dicts will be retained for the |
|
260 | should be aware that the returned dicts will be retained for the | |
261 | duration of the localrepo object.''' |
|
261 | duration of the localrepo object.''' | |
262 |
|
262 | |||
263 | # XXX what tagtype should subclasses/extensions use? Currently |
|
263 | # XXX what tagtype should subclasses/extensions use? Currently | |
264 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
264 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
265 | # Should each extension invent its own tag type? Should there |
|
265 | # Should each extension invent its own tag type? Should there | |
266 | # be one tagtype for all such "virtual" tags? Or is the status |
|
266 | # be one tagtype for all such "virtual" tags? Or is the status | |
267 | # quo fine? |
|
267 | # quo fine? | |
268 |
|
268 | |||
269 | alltags = {} # map tag name to (node, hist) |
|
269 | alltags = {} # map tag name to (node, hist) | |
270 | tagtypes = {} |
|
270 | tagtypes = {} | |
271 |
|
271 | |||
272 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) |
|
272 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) | |
273 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
273 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
274 |
|
274 | |||
275 | # Build the return dicts. Have to re-encode tag names because |
|
275 | # Build the return dicts. Have to re-encode tag names because | |
276 | # the tags module always uses UTF-8 (in order not to lose info |
|
276 | # the tags module always uses UTF-8 (in order not to lose info | |
277 | # writing to the cache), but the rest of Mercurial wants them in |
|
277 | # writing to the cache), but the rest of Mercurial wants them in | |
278 | # local encoding. |
|
278 | # local encoding. | |
279 | tags = {} |
|
279 | tags = {} | |
280 | for (name, (node, hist)) in alltags.iteritems(): |
|
280 | for (name, (node, hist)) in alltags.iteritems(): | |
281 | if node != nullid: |
|
281 | if node != nullid: | |
282 | tags[encoding.tolocal(name)] = node |
|
282 | tags[encoding.tolocal(name)] = node | |
283 | tags['tip'] = self.changelog.tip() |
|
283 | tags['tip'] = self.changelog.tip() | |
284 | tagtypes = dict([(encoding.tolocal(name), value) |
|
284 | tagtypes = dict([(encoding.tolocal(name), value) | |
285 | for (name, value) in tagtypes.iteritems()]) |
|
285 | for (name, value) in tagtypes.iteritems()]) | |
286 | return (tags, tagtypes) |
|
286 | return (tags, tagtypes) | |
287 |
|
287 | |||
288 | def tagtype(self, tagname): |
|
288 | def tagtype(self, tagname): | |
289 | ''' |
|
289 | ''' | |
290 | return the type of the given tag. result can be: |
|
290 | return the type of the given tag. result can be: | |
291 |
|
291 | |||
292 | 'local' : a local tag |
|
292 | 'local' : a local tag | |
293 | 'global' : a global tag |
|
293 | 'global' : a global tag | |
294 | None : tag does not exist |
|
294 | None : tag does not exist | |
295 | ''' |
|
295 | ''' | |
296 |
|
296 | |||
297 | self.tags() |
|
297 | self.tags() | |
298 |
|
298 | |||
299 | return self._tagtypes.get(tagname) |
|
299 | return self._tagtypes.get(tagname) | |
300 |
|
300 | |||
301 | def tagslist(self): |
|
301 | def tagslist(self): | |
302 | '''return a list of tags ordered by revision''' |
|
302 | '''return a list of tags ordered by revision''' | |
303 | l = [] |
|
303 | l = [] | |
304 | for t, n in self.tags().iteritems(): |
|
304 | for t, n in self.tags().iteritems(): | |
305 | try: |
|
305 | try: | |
306 | r = self.changelog.rev(n) |
|
306 | r = self.changelog.rev(n) | |
307 | except: |
|
307 | except: | |
308 | r = -2 # sort to the beginning of the list if unknown |
|
308 | r = -2 # sort to the beginning of the list if unknown | |
309 | l.append((r, t, n)) |
|
309 | l.append((r, t, n)) | |
310 | return [(t, n) for r, t, n in sorted(l)] |
|
310 | return [(t, n) for r, t, n in sorted(l)] | |
311 |
|
311 | |||
312 | def nodetags(self, node): |
|
312 | def nodetags(self, node): | |
313 | '''return the tags associated with a node''' |
|
313 | '''return the tags associated with a node''' | |
314 | if not self.nodetagscache: |
|
314 | if not self.nodetagscache: | |
315 | self.nodetagscache = {} |
|
315 | self.nodetagscache = {} | |
316 | for t, n in self.tags().iteritems(): |
|
316 | for t, n in self.tags().iteritems(): | |
317 | self.nodetagscache.setdefault(n, []).append(t) |
|
317 | self.nodetagscache.setdefault(n, []).append(t) | |
318 | return self.nodetagscache.get(node, []) |
|
318 | return self.nodetagscache.get(node, []) | |
319 |
|
319 | |||
320 | def _branchtags(self, partial, lrev): |
|
320 | def _branchtags(self, partial, lrev): | |
321 | # TODO: rename this function? |
|
321 | # TODO: rename this function? | |
322 | tiprev = len(self) - 1 |
|
322 | tiprev = len(self) - 1 | |
323 | if lrev != tiprev: |
|
323 | if lrev != tiprev: | |
324 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) |
|
324 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) | |
325 | self._updatebranchcache(partial, ctxgen) |
|
325 | self._updatebranchcache(partial, ctxgen) | |
326 | self._writebranchcache(partial, self.changelog.tip(), tiprev) |
|
326 | self._writebranchcache(partial, self.changelog.tip(), tiprev) | |
327 |
|
327 | |||
328 | return partial |
|
328 | return partial | |
329 |
|
329 | |||
330 | def branchmap(self): |
|
330 | def branchmap(self): | |
331 | '''returns a dictionary {branch: [branchheads]}''' |
|
331 | '''returns a dictionary {branch: [branchheads]}''' | |
332 | tip = self.changelog.tip() |
|
332 | tip = self.changelog.tip() | |
333 | if self._branchcache is not None and self._branchcachetip == tip: |
|
333 | if self._branchcache is not None and self._branchcachetip == tip: | |
334 | return self._branchcache |
|
334 | return self._branchcache | |
335 |
|
335 | |||
336 | oldtip = self._branchcachetip |
|
336 | oldtip = self._branchcachetip | |
337 | self._branchcachetip = tip |
|
337 | self._branchcachetip = tip | |
338 | if oldtip is None or oldtip not in self.changelog.nodemap: |
|
338 | if oldtip is None or oldtip not in self.changelog.nodemap: | |
339 | partial, last, lrev = self._readbranchcache() |
|
339 | partial, last, lrev = self._readbranchcache() | |
340 | else: |
|
340 | else: | |
341 | lrev = self.changelog.rev(oldtip) |
|
341 | lrev = self.changelog.rev(oldtip) | |
342 | partial = self._branchcache |
|
342 | partial = self._branchcache | |
343 |
|
343 | |||
344 | self._branchtags(partial, lrev) |
|
344 | self._branchtags(partial, lrev) | |
345 | # this private cache holds all heads (not just tips) |
|
345 | # this private cache holds all heads (not just tips) | |
346 | self._branchcache = partial |
|
346 | self._branchcache = partial | |
347 |
|
347 | |||
348 | return self._branchcache |
|
348 | return self._branchcache | |
349 |
|
349 | |||
350 | def branchtags(self): |
|
350 | def branchtags(self): | |
351 | '''return a dict where branch names map to the tipmost head of |
|
351 | '''return a dict where branch names map to the tipmost head of | |
352 | the branch, open heads come before closed''' |
|
352 | the branch, open heads come before closed''' | |
353 | bt = {} |
|
353 | bt = {} | |
354 | for bn, heads in self.branchmap().iteritems(): |
|
354 | for bn, heads in self.branchmap().iteritems(): | |
355 | tip = heads[-1] |
|
355 | tip = heads[-1] | |
356 | for h in reversed(heads): |
|
356 | for h in reversed(heads): | |
357 | if 'close' not in self.changelog.read(h)[5]: |
|
357 | if 'close' not in self.changelog.read(h)[5]: | |
358 | tip = h |
|
358 | tip = h | |
359 | break |
|
359 | break | |
360 | bt[bn] = tip |
|
360 | bt[bn] = tip | |
361 | return bt |
|
361 | return bt | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | def _readbranchcache(self): |
|
364 | def _readbranchcache(self): | |
365 | partial = {} |
|
365 | partial = {} | |
366 | try: |
|
366 | try: | |
367 | f = self.opener("branchheads.cache") |
|
367 | f = self.opener("branchheads.cache") | |
368 | lines = f.read().split('\n') |
|
368 | lines = f.read().split('\n') | |
369 | f.close() |
|
369 | f.close() | |
370 | except (IOError, OSError): |
|
370 | except (IOError, OSError): | |
371 | return {}, nullid, nullrev |
|
371 | return {}, nullid, nullrev | |
372 |
|
372 | |||
373 | try: |
|
373 | try: | |
374 | last, lrev = lines.pop(0).split(" ", 1) |
|
374 | last, lrev = lines.pop(0).split(" ", 1) | |
375 | last, lrev = bin(last), int(lrev) |
|
375 | last, lrev = bin(last), int(lrev) | |
376 | if lrev >= len(self) or self[lrev].node() != last: |
|
376 | if lrev >= len(self) or self[lrev].node() != last: | |
377 | # invalidate the cache |
|
377 | # invalidate the cache | |
378 | raise ValueError('invalidating branch cache (tip differs)') |
|
378 | raise ValueError('invalidating branch cache (tip differs)') | |
379 | for l in lines: |
|
379 | for l in lines: | |
380 | if not l: |
|
380 | if not l: | |
381 | continue |
|
381 | continue | |
382 | node, label = l.split(" ", 1) |
|
382 | node, label = l.split(" ", 1) | |
383 | partial.setdefault(label.strip(), []).append(bin(node)) |
|
383 | partial.setdefault(label.strip(), []).append(bin(node)) | |
384 | except KeyboardInterrupt: |
|
384 | except KeyboardInterrupt: | |
385 | raise |
|
385 | raise | |
386 | except Exception, inst: |
|
386 | except Exception, inst: | |
387 | if self.ui.debugflag: |
|
387 | if self.ui.debugflag: | |
388 | self.ui.warn(str(inst), '\n') |
|
388 | self.ui.warn(str(inst), '\n') | |
389 | partial, last, lrev = {}, nullid, nullrev |
|
389 | partial, last, lrev = {}, nullid, nullrev | |
390 | return partial, last, lrev |
|
390 | return partial, last, lrev | |
391 |
|
391 | |||
392 | def _writebranchcache(self, branches, tip, tiprev): |
|
392 | def _writebranchcache(self, branches, tip, tiprev): | |
393 | try: |
|
393 | try: | |
394 | f = self.opener("branchheads.cache", "w", atomictemp=True) |
|
394 | f = self.opener("branchheads.cache", "w", atomictemp=True) | |
395 | f.write("%s %s\n" % (hex(tip), tiprev)) |
|
395 | f.write("%s %s\n" % (hex(tip), tiprev)) | |
396 | for label, nodes in branches.iteritems(): |
|
396 | for label, nodes in branches.iteritems(): | |
397 | for node in nodes: |
|
397 | for node in nodes: | |
398 | f.write("%s %s\n" % (hex(node), label)) |
|
398 | f.write("%s %s\n" % (hex(node), label)) | |
399 | f.rename() |
|
399 | f.rename() | |
400 | except (IOError, OSError): |
|
400 | except (IOError, OSError): | |
401 | pass |
|
401 | pass | |
402 |
|
402 | |||
403 | def _updatebranchcache(self, partial, ctxgen): |
|
403 | def _updatebranchcache(self, partial, ctxgen): | |
404 | # collect new branch entries |
|
404 | # collect new branch entries | |
405 | newbranches = {} |
|
405 | newbranches = {} | |
406 | for c in ctxgen: |
|
406 | for c in ctxgen: | |
407 | newbranches.setdefault(c.branch(), []).append(c.node()) |
|
407 | newbranches.setdefault(c.branch(), []).append(c.node()) | |
408 | # if older branchheads are reachable from new ones, they aren't |
|
408 | # if older branchheads are reachable from new ones, they aren't | |
409 | # really branchheads. Note checking parents is insufficient: |
|
409 | # really branchheads. Note checking parents is insufficient: | |
410 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
|
410 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) | |
411 | for branch, newnodes in newbranches.iteritems(): |
|
411 | for branch, newnodes in newbranches.iteritems(): | |
412 | bheads = partial.setdefault(branch, []) |
|
412 | bheads = partial.setdefault(branch, []) | |
413 | bheads.extend(newnodes) |
|
413 | bheads.extend(newnodes) | |
414 | if len(bheads) <= 1: |
|
414 | if len(bheads) <= 1: | |
415 | continue |
|
415 | continue | |
416 | # starting from tip means fewer passes over reachable |
|
416 | # starting from tip means fewer passes over reachable | |
417 | while newnodes: |
|
417 | while newnodes: | |
418 | latest = newnodes.pop() |
|
418 | latest = newnodes.pop() | |
419 | if latest not in bheads: |
|
419 | if latest not in bheads: | |
420 | continue |
|
420 | continue | |
421 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() |
|
421 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() | |
422 | reachable = self.changelog.reachable(latest, minbhrev) |
|
422 | reachable = self.changelog.reachable(latest, minbhrev) | |
423 | reachable.remove(latest) |
|
423 | reachable.remove(latest) | |
424 | bheads = [b for b in bheads if b not in reachable] |
|
424 | bheads = [b for b in bheads if b not in reachable] | |
425 | partial[branch] = bheads |
|
425 | partial[branch] = bheads | |
426 |
|
426 | |||
427 | def lookup(self, key): |
|
427 | def lookup(self, key): | |
428 | if isinstance(key, int): |
|
428 | if isinstance(key, int): | |
429 | return self.changelog.node(key) |
|
429 | return self.changelog.node(key) | |
430 | elif key == '.': |
|
430 | elif key == '.': | |
431 | return self.dirstate.parents()[0] |
|
431 | return self.dirstate.parents()[0] | |
432 | elif key == 'null': |
|
432 | elif key == 'null': | |
433 | return nullid |
|
433 | return nullid | |
434 | elif key == 'tip': |
|
434 | elif key == 'tip': | |
435 | return self.changelog.tip() |
|
435 | return self.changelog.tip() | |
436 | n = self.changelog._match(key) |
|
436 | n = self.changelog._match(key) | |
437 | if n: |
|
437 | if n: | |
438 | return n |
|
438 | return n | |
439 | if key in self.tags(): |
|
439 | if key in self.tags(): | |
440 | return self.tags()[key] |
|
440 | return self.tags()[key] | |
441 | if key in self.branchtags(): |
|
441 | if key in self.branchtags(): | |
442 | return self.branchtags()[key] |
|
442 | return self.branchtags()[key] | |
443 | n = self.changelog._partialmatch(key) |
|
443 | n = self.changelog._partialmatch(key) | |
444 | if n: |
|
444 | if n: | |
445 | return n |
|
445 | return n | |
446 |
|
446 | |||
447 | # can't find key, check if it might have come from damaged dirstate |
|
447 | # can't find key, check if it might have come from damaged dirstate | |
448 | if key in self.dirstate.parents(): |
|
448 | if key in self.dirstate.parents(): | |
449 | raise error.Abort(_("working directory has unknown parent '%s'!") |
|
449 | raise error.Abort(_("working directory has unknown parent '%s'!") | |
450 | % short(key)) |
|
450 | % short(key)) | |
451 | try: |
|
451 | try: | |
452 | if len(key) == 20: |
|
452 | if len(key) == 20: | |
453 | key = hex(key) |
|
453 | key = hex(key) | |
454 | except: |
|
454 | except: | |
455 | pass |
|
455 | pass | |
456 | raise error.RepoLookupError(_("unknown revision '%s'") % key) |
|
456 | raise error.RepoLookupError(_("unknown revision '%s'") % key) | |
457 |
|
457 | |||
458 | def lookupbranch(self, key, remote=None): |
|
458 | def lookupbranch(self, key, remote=None): | |
459 | repo = remote or self |
|
459 | repo = remote or self | |
460 | if key in repo.branchmap(): |
|
460 | if key in repo.branchmap(): | |
461 | return key |
|
461 | return key | |
462 |
|
462 | |||
463 | repo = (remote and remote.local()) and remote or self |
|
463 | repo = (remote and remote.local()) and remote or self | |
464 | return repo[key].branch() |
|
464 | return repo[key].branch() | |
465 |
|
465 | |||
466 | def local(self): |
|
466 | def local(self): | |
467 | return True |
|
467 | return True | |
468 |
|
468 | |||
469 | def join(self, f): |
|
469 | def join(self, f): | |
470 | return os.path.join(self.path, f) |
|
470 | return os.path.join(self.path, f) | |
471 |
|
471 | |||
472 | def wjoin(self, f): |
|
472 | def wjoin(self, f): | |
473 | return os.path.join(self.root, f) |
|
473 | return os.path.join(self.root, f) | |
474 |
|
474 | |||
475 | def rjoin(self, f): |
|
475 | def rjoin(self, f): | |
476 | return os.path.join(self.root, util.pconvert(f)) |
|
476 | return os.path.join(self.root, util.pconvert(f)) | |
477 |
|
477 | |||
478 | def file(self, f): |
|
478 | def file(self, f): | |
479 | if f[0] == '/': |
|
479 | if f[0] == '/': | |
480 | f = f[1:] |
|
480 | f = f[1:] | |
481 | return filelog.filelog(self.sopener, f) |
|
481 | return filelog.filelog(self.sopener, f) | |
482 |
|
482 | |||
483 | def changectx(self, changeid): |
|
483 | def changectx(self, changeid): | |
484 | return self[changeid] |
|
484 | return self[changeid] | |
485 |
|
485 | |||
486 | def parents(self, changeid=None): |
|
486 | def parents(self, changeid=None): | |
487 | '''get list of changectxs for parents of changeid''' |
|
487 | '''get list of changectxs for parents of changeid''' | |
488 | return self[changeid].parents() |
|
488 | return self[changeid].parents() | |
489 |
|
489 | |||
490 | def filectx(self, path, changeid=None, fileid=None): |
|
490 | def filectx(self, path, changeid=None, fileid=None): | |
491 | """changeid can be a changeset revision, node, or tag. |
|
491 | """changeid can be a changeset revision, node, or tag. | |
492 | fileid can be a file revision or node.""" |
|
492 | fileid can be a file revision or node.""" | |
493 | return context.filectx(self, path, changeid, fileid) |
|
493 | return context.filectx(self, path, changeid, fileid) | |
494 |
|
494 | |||
495 | def getcwd(self): |
|
495 | def getcwd(self): | |
496 | return self.dirstate.getcwd() |
|
496 | return self.dirstate.getcwd() | |
497 |
|
497 | |||
498 | def pathto(self, f, cwd=None): |
|
498 | def pathto(self, f, cwd=None): | |
499 | return self.dirstate.pathto(f, cwd) |
|
499 | return self.dirstate.pathto(f, cwd) | |
500 |
|
500 | |||
501 | def wfile(self, f, mode='r'): |
|
501 | def wfile(self, f, mode='r'): | |
502 | return self.wopener(f, mode) |
|
502 | return self.wopener(f, mode) | |
503 |
|
503 | |||
504 | def _link(self, f): |
|
504 | def _link(self, f): | |
505 | return os.path.islink(self.wjoin(f)) |
|
505 | return os.path.islink(self.wjoin(f)) | |
506 |
|
506 | |||
507 | def _filter(self, filter, filename, data): |
|
507 | def _filter(self, filter, filename, data): | |
508 | if filter not in self.filterpats: |
|
508 | if filter not in self.filterpats: | |
509 | l = [] |
|
509 | l = [] | |
510 | for pat, cmd in self.ui.configitems(filter): |
|
510 | for pat, cmd in self.ui.configitems(filter): | |
511 | if cmd == '!': |
|
511 | if cmd == '!': | |
512 | continue |
|
512 | continue | |
513 | mf = matchmod.match(self.root, '', [pat]) |
|
513 | mf = matchmod.match(self.root, '', [pat]) | |
514 | fn = None |
|
514 | fn = None | |
515 | params = cmd |
|
515 | params = cmd | |
516 | for name, filterfn in self._datafilters.iteritems(): |
|
516 | for name, filterfn in self._datafilters.iteritems(): | |
517 | if cmd.startswith(name): |
|
517 | if cmd.startswith(name): | |
518 | fn = filterfn |
|
518 | fn = filterfn | |
519 | params = cmd[len(name):].lstrip() |
|
519 | params = cmd[len(name):].lstrip() | |
520 | break |
|
520 | break | |
521 | if not fn: |
|
521 | if not fn: | |
522 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
522 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
523 | # Wrap old filters not supporting keyword arguments |
|
523 | # Wrap old filters not supporting keyword arguments | |
524 | if not inspect.getargspec(fn)[2]: |
|
524 | if not inspect.getargspec(fn)[2]: | |
525 | oldfn = fn |
|
525 | oldfn = fn | |
526 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
526 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
527 | l.append((mf, fn, params)) |
|
527 | l.append((mf, fn, params)) | |
528 | self.filterpats[filter] = l |
|
528 | self.filterpats[filter] = l | |
529 |
|
529 | |||
530 | for mf, fn, cmd in self.filterpats[filter]: |
|
530 | for mf, fn, cmd in self.filterpats[filter]: | |
531 | if mf(filename): |
|
531 | if mf(filename): | |
532 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
532 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
533 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
533 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
534 | break |
|
534 | break | |
535 |
|
535 | |||
536 | return data |
|
536 | return data | |
537 |
|
537 | |||
538 | def adddatafilter(self, name, filter): |
|
538 | def adddatafilter(self, name, filter): | |
539 | self._datafilters[name] = filter |
|
539 | self._datafilters[name] = filter | |
540 |
|
540 | |||
541 | def wread(self, filename): |
|
541 | def wread(self, filename): | |
542 | if self._link(filename): |
|
542 | if self._link(filename): | |
543 | data = os.readlink(self.wjoin(filename)) |
|
543 | data = os.readlink(self.wjoin(filename)) | |
544 | else: |
|
544 | else: | |
545 | data = self.wopener(filename, 'r').read() |
|
545 | data = self.wopener(filename, 'r').read() | |
546 | return self._filter("encode", filename, data) |
|
546 | return self._filter("encode", filename, data) | |
547 |
|
547 | |||
548 | def wwrite(self, filename, data, flags): |
|
548 | def wwrite(self, filename, data, flags): | |
549 | data = self._filter("decode", filename, data) |
|
549 | data = self._filter("decode", filename, data) | |
550 | try: |
|
550 | try: | |
551 | os.unlink(self.wjoin(filename)) |
|
551 | os.unlink(self.wjoin(filename)) | |
552 | except OSError: |
|
552 | except OSError: | |
553 | pass |
|
553 | pass | |
554 | if 'l' in flags: |
|
554 | if 'l' in flags: | |
555 | self.wopener.symlink(data, filename) |
|
555 | self.wopener.symlink(data, filename) | |
556 | else: |
|
556 | else: | |
557 | self.wopener(filename, 'w').write(data) |
|
557 | self.wopener(filename, 'w').write(data) | |
558 | if 'x' in flags: |
|
558 | if 'x' in flags: | |
559 | util.set_flags(self.wjoin(filename), False, True) |
|
559 | util.set_flags(self.wjoin(filename), False, True) | |
560 |
|
560 | |||
561 | def wwritedata(self, filename, data): |
|
561 | def wwritedata(self, filename, data): | |
562 | return self._filter("decode", filename, data) |
|
562 | return self._filter("decode", filename, data) | |
563 |
|
563 | |||
564 | def transaction(self, desc): |
|
564 | def transaction(self, desc): | |
565 | tr = self._transref and self._transref() or None |
|
565 | tr = self._transref and self._transref() or None | |
566 | if tr and tr.running(): |
|
566 | if tr and tr.running(): | |
567 | return tr.nest() |
|
567 | return tr.nest() | |
568 |
|
568 | |||
569 | # abort here if the journal already exists |
|
569 | # abort here if the journal already exists | |
570 | if os.path.exists(self.sjoin("journal")): |
|
570 | if os.path.exists(self.sjoin("journal")): | |
571 | raise error.RepoError( |
|
571 | raise error.RepoError( | |
572 | _("abandoned transaction found - run hg recover")) |
|
572 | _("abandoned transaction found - run hg recover")) | |
573 |
|
573 | |||
574 | # save dirstate for rollback |
|
574 | # save dirstate for rollback | |
575 | try: |
|
575 | try: | |
576 | ds = self.opener("dirstate").read() |
|
576 | ds = self.opener("dirstate").read() | |
577 | except IOError: |
|
577 | except IOError: | |
578 | ds = "" |
|
578 | ds = "" | |
579 | self.opener("journal.dirstate", "w").write(ds) |
|
579 | self.opener("journal.dirstate", "w").write(ds) | |
580 | self.opener("journal.branch", "w").write(self.dirstate.branch()) |
|
580 | self.opener("journal.branch", "w").write(self.dirstate.branch()) | |
581 | self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) |
|
581 | self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) | |
582 |
|
582 | |||
583 | renames = [(self.sjoin("journal"), self.sjoin("undo")), |
|
583 | renames = [(self.sjoin("journal"), self.sjoin("undo")), | |
584 | (self.join("journal.dirstate"), self.join("undo.dirstate")), |
|
584 | (self.join("journal.dirstate"), self.join("undo.dirstate")), | |
585 | (self.join("journal.branch"), self.join("undo.branch")), |
|
585 | (self.join("journal.branch"), self.join("undo.branch")), | |
586 | (self.join("journal.desc"), self.join("undo.desc"))] |
|
586 | (self.join("journal.desc"), self.join("undo.desc"))] | |
587 | tr = transaction.transaction(self.ui.warn, self.sopener, |
|
587 | tr = transaction.transaction(self.ui.warn, self.sopener, | |
588 | self.sjoin("journal"), |
|
588 | self.sjoin("journal"), | |
589 | aftertrans(renames), |
|
589 | aftertrans(renames), | |
590 | self.store.createmode) |
|
590 | self.store.createmode) | |
591 | self._transref = weakref.ref(tr) |
|
591 | self._transref = weakref.ref(tr) | |
592 | return tr |
|
592 | return tr | |
593 |
|
593 | |||
594 | def recover(self): |
|
594 | def recover(self): | |
595 | lock = self.lock() |
|
595 | lock = self.lock() | |
596 | try: |
|
596 | try: | |
597 | if os.path.exists(self.sjoin("journal")): |
|
597 | if os.path.exists(self.sjoin("journal")): | |
598 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
598 | self.ui.status(_("rolling back interrupted transaction\n")) | |
599 | transaction.rollback(self.sopener, self.sjoin("journal"), |
|
599 | transaction.rollback(self.sopener, self.sjoin("journal"), | |
600 | self.ui.warn) |
|
600 | self.ui.warn) | |
601 | self.invalidate() |
|
601 | self.invalidate() | |
602 | return True |
|
602 | return True | |
603 | else: |
|
603 | else: | |
604 | self.ui.warn(_("no interrupted transaction available\n")) |
|
604 | self.ui.warn(_("no interrupted transaction available\n")) | |
605 | return False |
|
605 | return False | |
606 | finally: |
|
606 | finally: | |
607 | lock.release() |
|
607 | lock.release() | |
608 |
|
608 | |||
609 | def rollback(self, dryrun=False): |
|
609 | def rollback(self, dryrun=False): | |
610 | wlock = lock = None |
|
610 | wlock = lock = None | |
611 | try: |
|
611 | try: | |
612 | wlock = self.wlock() |
|
612 | wlock = self.wlock() | |
613 | lock = self.lock() |
|
613 | lock = self.lock() | |
614 | if os.path.exists(self.sjoin("undo")): |
|
614 | if os.path.exists(self.sjoin("undo")): | |
615 | try: |
|
615 | try: | |
616 | args = self.opener("undo.desc", "r").read().splitlines() |
|
616 | args = self.opener("undo.desc", "r").read().splitlines() | |
617 | if len(args) >= 3 and self.ui.verbose: |
|
617 | if len(args) >= 3 and self.ui.verbose: | |
618 | desc = _("rolling back to revision %s" |
|
618 | desc = _("rolling back to revision %s" | |
619 | " (undo %s: %s)\n") % ( |
|
619 | " (undo %s: %s)\n") % ( | |
620 | args[0], args[1], args[2]) |
|
620 | args[0], args[1], args[2]) | |
621 | elif len(args) >= 2: |
|
621 | elif len(args) >= 2: | |
622 | desc = _("rolling back to revision %s (undo %s)\n") % ( |
|
622 | desc = _("rolling back to revision %s (undo %s)\n") % ( | |
623 | args[0], args[1]) |
|
623 | args[0], args[1]) | |
624 | except IOError: |
|
624 | except IOError: | |
625 | desc = _("rolling back unknown transaction\n") |
|
625 | desc = _("rolling back unknown transaction\n") | |
626 | self.ui.status(desc) |
|
626 | self.ui.status(desc) | |
627 | if dryrun: |
|
627 | if dryrun: | |
628 | return |
|
628 | return | |
629 | transaction.rollback(self.sopener, self.sjoin("undo"), |
|
629 | transaction.rollback(self.sopener, self.sjoin("undo"), | |
630 | self.ui.warn) |
|
630 | self.ui.warn) | |
631 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
631 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
632 | try: |
|
632 | try: | |
633 | branch = self.opener("undo.branch").read() |
|
633 | branch = self.opener("undo.branch").read() | |
634 | self.dirstate.setbranch(branch) |
|
634 | self.dirstate.setbranch(branch) | |
635 | except IOError: |
|
635 | except IOError: | |
636 | self.ui.warn(_("Named branch could not be reset, " |
|
636 | self.ui.warn(_("Named branch could not be reset, " | |
637 | "current branch still is: %s\n") |
|
637 | "current branch still is: %s\n") | |
638 | % encoding.tolocal(self.dirstate.branch())) |
|
638 | % encoding.tolocal(self.dirstate.branch())) | |
639 | self.invalidate() |
|
639 | self.invalidate() | |
640 | self.dirstate.invalidate() |
|
640 | self.dirstate.invalidate() | |
641 | self.destroyed() |
|
641 | self.destroyed() | |
642 | else: |
|
642 | else: | |
643 | self.ui.warn(_("no rollback information available\n")) |
|
643 | self.ui.warn(_("no rollback information available\n")) | |
644 | finally: |
|
644 | finally: | |
645 | release(lock, wlock) |
|
645 | release(lock, wlock) | |
646 |
|
646 | |||
647 | def invalidatecaches(self): |
|
647 | def invalidatecaches(self): | |
648 | self._tags = None |
|
648 | self._tags = None | |
649 | self._tagtypes = None |
|
649 | self._tagtypes = None | |
650 | self.nodetagscache = None |
|
650 | self.nodetagscache = None | |
651 | self._branchcache = None # in UTF-8 |
|
651 | self._branchcache = None # in UTF-8 | |
652 | self._branchcachetip = None |
|
652 | self._branchcachetip = None | |
653 |
|
653 | |||
654 | def invalidate(self): |
|
654 | def invalidate(self): | |
655 | for a in "changelog manifest".split(): |
|
655 | for a in "changelog manifest".split(): | |
656 | if a in self.__dict__: |
|
656 | if a in self.__dict__: | |
657 | delattr(self, a) |
|
657 | delattr(self, a) | |
658 | self.invalidatecaches() |
|
658 | self.invalidatecaches() | |
659 |
|
659 | |||
660 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): |
|
660 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): | |
661 | try: |
|
661 | try: | |
662 | l = lock.lock(lockname, 0, releasefn, desc=desc) |
|
662 | l = lock.lock(lockname, 0, releasefn, desc=desc) | |
663 | except error.LockHeld, inst: |
|
663 | except error.LockHeld, inst: | |
664 | if not wait: |
|
664 | if not wait: | |
665 | raise |
|
665 | raise | |
666 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
666 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
667 | (desc, inst.locker)) |
|
667 | (desc, inst.locker)) | |
668 | # default to 600 seconds timeout |
|
668 | # default to 600 seconds timeout | |
669 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), |
|
669 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), | |
670 | releasefn, desc=desc) |
|
670 | releasefn, desc=desc) | |
671 | if acquirefn: |
|
671 | if acquirefn: | |
672 | acquirefn() |
|
672 | acquirefn() | |
673 | return l |
|
673 | return l | |
674 |
|
674 | |||
675 | def lock(self, wait=True): |
|
675 | def lock(self, wait=True): | |
676 | '''Lock the repository store (.hg/store) and return a weak reference |
|
676 | '''Lock the repository store (.hg/store) and return a weak reference | |
677 | to the lock. Use this before modifying the store (e.g. committing or |
|
677 | to the lock. Use this before modifying the store (e.g. committing or | |
678 | stripping). If you are opening a transaction, get a lock as well.)''' |
|
678 | stripping). If you are opening a transaction, get a lock as well.)''' | |
679 | l = self._lockref and self._lockref() |
|
679 | l = self._lockref and self._lockref() | |
680 | if l is not None and l.held: |
|
680 | if l is not None and l.held: | |
681 | l.lock() |
|
681 | l.lock() | |
682 | return l |
|
682 | return l | |
683 |
|
683 | |||
684 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, |
|
684 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, | |
685 | _('repository %s') % self.origroot) |
|
685 | _('repository %s') % self.origroot) | |
686 | self._lockref = weakref.ref(l) |
|
686 | self._lockref = weakref.ref(l) | |
687 | return l |
|
687 | return l | |
688 |
|
688 | |||
689 | def wlock(self, wait=True): |
|
689 | def wlock(self, wait=True): | |
690 | '''Lock the non-store parts of the repository (everything under |
|
690 | '''Lock the non-store parts of the repository (everything under | |
691 | .hg except .hg/store) and return a weak reference to the lock. |
|
691 | .hg except .hg/store) and return a weak reference to the lock. | |
692 | Use this before modifying files in .hg.''' |
|
692 | Use this before modifying files in .hg.''' | |
693 | l = self._wlockref and self._wlockref() |
|
693 | l = self._wlockref and self._wlockref() | |
694 | if l is not None and l.held: |
|
694 | if l is not None and l.held: | |
695 | l.lock() |
|
695 | l.lock() | |
696 | return l |
|
696 | return l | |
697 |
|
697 | |||
698 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, |
|
698 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, | |
699 | self.dirstate.invalidate, _('working directory of %s') % |
|
699 | self.dirstate.invalidate, _('working directory of %s') % | |
700 | self.origroot) |
|
700 | self.origroot) | |
701 | self._wlockref = weakref.ref(l) |
|
701 | self._wlockref = weakref.ref(l) | |
702 | return l |
|
702 | return l | |
703 |
|
703 | |||
704 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
704 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
705 | """ |
|
705 | """ | |
706 | commit an individual file as part of a larger transaction |
|
706 | commit an individual file as part of a larger transaction | |
707 | """ |
|
707 | """ | |
708 |
|
708 | |||
709 | fname = fctx.path() |
|
709 | fname = fctx.path() | |
710 | text = fctx.data() |
|
710 | text = fctx.data() | |
711 | flog = self.file(fname) |
|
711 | flog = self.file(fname) | |
712 | fparent1 = manifest1.get(fname, nullid) |
|
712 | fparent1 = manifest1.get(fname, nullid) | |
713 | fparent2 = fparent2o = manifest2.get(fname, nullid) |
|
713 | fparent2 = fparent2o = manifest2.get(fname, nullid) | |
714 |
|
714 | |||
715 | meta = {} |
|
715 | meta = {} | |
716 | copy = fctx.renamed() |
|
716 | copy = fctx.renamed() | |
717 | if copy and copy[0] != fname: |
|
717 | if copy and copy[0] != fname: | |
718 | # Mark the new revision of this file as a copy of another |
|
718 | # Mark the new revision of this file as a copy of another | |
719 | # file. This copy data will effectively act as a parent |
|
719 | # file. This copy data will effectively act as a parent | |
720 | # of this new revision. If this is a merge, the first |
|
720 | # of this new revision. If this is a merge, the first | |
721 | # parent will be the nullid (meaning "look up the copy data") |
|
721 | # parent will be the nullid (meaning "look up the copy data") | |
722 | # and the second one will be the other parent. For example: |
|
722 | # and the second one will be the other parent. For example: | |
723 | # |
|
723 | # | |
724 | # 0 --- 1 --- 3 rev1 changes file foo |
|
724 | # 0 --- 1 --- 3 rev1 changes file foo | |
725 | # \ / rev2 renames foo to bar and changes it |
|
725 | # \ / rev2 renames foo to bar and changes it | |
726 | # \- 2 -/ rev3 should have bar with all changes and |
|
726 | # \- 2 -/ rev3 should have bar with all changes and | |
727 | # should record that bar descends from |
|
727 | # should record that bar descends from | |
728 | # bar in rev2 and foo in rev1 |
|
728 | # bar in rev2 and foo in rev1 | |
729 | # |
|
729 | # | |
730 | # this allows this merge to succeed: |
|
730 | # this allows this merge to succeed: | |
731 | # |
|
731 | # | |
732 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
732 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
733 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
733 | # \ / merging rev3 and rev4 should use bar@rev2 | |
734 | # \- 2 --- 4 as the merge base |
|
734 | # \- 2 --- 4 as the merge base | |
735 | # |
|
735 | # | |
736 |
|
736 | |||
737 | cfname = copy[0] |
|
737 | cfname = copy[0] | |
738 | crev = manifest1.get(cfname) |
|
738 | crev = manifest1.get(cfname) | |
739 | newfparent = fparent2 |
|
739 | newfparent = fparent2 | |
740 |
|
740 | |||
741 | if manifest2: # branch merge |
|
741 | if manifest2: # branch merge | |
742 | if fparent2 == nullid or crev is None: # copied on remote side |
|
742 | if fparent2 == nullid or crev is None: # copied on remote side | |
743 | if cfname in manifest2: |
|
743 | if cfname in manifest2: | |
744 | crev = manifest2[cfname] |
|
744 | crev = manifest2[cfname] | |
745 | newfparent = fparent1 |
|
745 | newfparent = fparent1 | |
746 |
|
746 | |||
747 | # find source in nearest ancestor if we've lost track |
|
747 | # find source in nearest ancestor if we've lost track | |
748 | if not crev: |
|
748 | if not crev: | |
749 | self.ui.debug(" %s: searching for copy revision for %s\n" % |
|
749 | self.ui.debug(" %s: searching for copy revision for %s\n" % | |
750 | (fname, cfname)) |
|
750 | (fname, cfname)) | |
751 | for ancestor in self['.'].ancestors(): |
|
751 | for ancestor in self['.'].ancestors(): | |
752 | if cfname in ancestor: |
|
752 | if cfname in ancestor: | |
753 | crev = ancestor[cfname].filenode() |
|
753 | crev = ancestor[cfname].filenode() | |
754 | break |
|
754 | break | |
755 |
|
755 | |||
756 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
756 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
757 | meta["copy"] = cfname |
|
757 | meta["copy"] = cfname | |
758 | meta["copyrev"] = hex(crev) |
|
758 | meta["copyrev"] = hex(crev) | |
759 | fparent1, fparent2 = nullid, newfparent |
|
759 | fparent1, fparent2 = nullid, newfparent | |
760 | elif fparent2 != nullid: |
|
760 | elif fparent2 != nullid: | |
761 | # is one parent an ancestor of the other? |
|
761 | # is one parent an ancestor of the other? | |
762 | fparentancestor = flog.ancestor(fparent1, fparent2) |
|
762 | fparentancestor = flog.ancestor(fparent1, fparent2) | |
763 | if fparentancestor == fparent1: |
|
763 | if fparentancestor == fparent1: | |
764 | fparent1, fparent2 = fparent2, nullid |
|
764 | fparent1, fparent2 = fparent2, nullid | |
765 | elif fparentancestor == fparent2: |
|
765 | elif fparentancestor == fparent2: | |
766 | fparent2 = nullid |
|
766 | fparent2 = nullid | |
767 |
|
767 | |||
768 | # is the file changed? |
|
768 | # is the file changed? | |
769 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
769 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
770 | changelist.append(fname) |
|
770 | changelist.append(fname) | |
771 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
771 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
772 |
|
772 | |||
773 | # are just the flags changed during merge? |
|
773 | # are just the flags changed during merge? | |
774 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): |
|
774 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): | |
775 | changelist.append(fname) |
|
775 | changelist.append(fname) | |
776 |
|
776 | |||
777 | return fparent1 |
|
777 | return fparent1 | |
778 |
|
778 | |||
779 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
779 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
780 | editor=False, extra={}): |
|
780 | editor=False, extra={}): | |
781 | """Add a new revision to current repository. |
|
781 | """Add a new revision to current repository. | |
782 |
|
782 | |||
783 | Revision information is gathered from the working directory, |
|
783 | Revision information is gathered from the working directory, | |
784 | match can be used to filter the committed files. If editor is |
|
784 | match can be used to filter the committed files. If editor is | |
785 | supplied, it is called to get a commit message. |
|
785 | supplied, it is called to get a commit message. | |
786 | """ |
|
786 | """ | |
787 |
|
787 | |||
788 | def fail(f, msg): |
|
788 | def fail(f, msg): | |
789 | raise util.Abort('%s: %s' % (f, msg)) |
|
789 | raise util.Abort('%s: %s' % (f, msg)) | |
790 |
|
790 | |||
791 | if not match: |
|
791 | if not match: | |
792 | match = matchmod.always(self.root, '') |
|
792 | match = matchmod.always(self.root, '') | |
793 |
|
793 | |||
794 | if not force: |
|
794 | if not force: | |
795 | vdirs = [] |
|
795 | vdirs = [] | |
796 | match.dir = vdirs.append |
|
796 | match.dir = vdirs.append | |
797 | match.bad = fail |
|
797 | match.bad = fail | |
798 |
|
798 | |||
799 | wlock = self.wlock() |
|
799 | wlock = self.wlock() | |
800 | try: |
|
800 | try: | |
801 | p1, p2 = self.dirstate.parents() |
|
801 | p1, p2 = self.dirstate.parents() | |
802 | wctx = self[None] |
|
802 | wctx = self[None] | |
803 |
|
803 | |||
804 | if (not force and p2 != nullid and match and |
|
804 | if (not force and p2 != nullid and match and | |
805 | (match.files() or match.anypats())): |
|
805 | (match.files() or match.anypats())): | |
806 | raise util.Abort(_('cannot partially commit a merge ' |
|
806 | raise util.Abort(_('cannot partially commit a merge ' | |
807 | '(do not specify files or patterns)')) |
|
807 | '(do not specify files or patterns)')) | |
808 |
|
808 | |||
809 | changes = self.status(match=match, clean=force) |
|
809 | changes = self.status(match=match, clean=force) | |
810 | if force: |
|
810 | if force: | |
811 | changes[0].extend(changes[6]) # mq may commit unchanged files |
|
811 | changes[0].extend(changes[6]) # mq may commit unchanged files | |
812 |
|
812 | |||
813 | # check subrepos |
|
813 | # check subrepos | |
814 | subs = [] |
|
814 | subs = [] | |
815 | removedsubs = set() |
|
815 | removedsubs = set() | |
816 | for p in wctx.parents(): |
|
816 | for p in wctx.parents(): | |
817 | removedsubs.update(s for s in p.substate if match(s)) |
|
817 | removedsubs.update(s for s in p.substate if match(s)) | |
818 | for s in wctx.substate: |
|
818 | for s in wctx.substate: | |
819 | removedsubs.discard(s) |
|
819 | removedsubs.discard(s) | |
820 | if match(s) and wctx.sub(s).dirty(): |
|
820 | if match(s) and wctx.sub(s).dirty(): | |
821 | subs.append(s) |
|
821 | subs.append(s) | |
822 | if (subs or removedsubs) and '.hgsubstate' not in changes[0]: |
|
822 | if (subs or removedsubs) and '.hgsubstate' not in changes[0]: | |
823 | changes[0].insert(0, '.hgsubstate') |
|
823 | changes[0].insert(0, '.hgsubstate') | |
824 |
|
824 | |||
825 | # make sure all explicit patterns are matched |
|
825 | # make sure all explicit patterns are matched | |
826 | if not force and match.files(): |
|
826 | if not force and match.files(): | |
827 | matched = set(changes[0] + changes[1] + changes[2]) |
|
827 | matched = set(changes[0] + changes[1] + changes[2]) | |
828 |
|
828 | |||
829 | for f in match.files(): |
|
829 | for f in match.files(): | |
830 | if f == '.' or f in matched or f in wctx.substate: |
|
830 | if f == '.' or f in matched or f in wctx.substate: | |
831 | continue |
|
831 | continue | |
832 | if f in changes[3]: # missing |
|
832 | if f in changes[3]: # missing | |
833 | fail(f, _('file not found!')) |
|
833 | fail(f, _('file not found!')) | |
834 | if f in vdirs: # visited directory |
|
834 | if f in vdirs: # visited directory | |
835 | d = f + '/' |
|
835 | d = f + '/' | |
836 | for mf in matched: |
|
836 | for mf in matched: | |
837 | if mf.startswith(d): |
|
837 | if mf.startswith(d): | |
838 | break |
|
838 | break | |
839 | else: |
|
839 | else: | |
840 | fail(f, _("no match under directory!")) |
|
840 | fail(f, _("no match under directory!")) | |
841 | elif f not in self.dirstate: |
|
841 | elif f not in self.dirstate: | |
842 | fail(f, _("file not tracked!")) |
|
842 | fail(f, _("file not tracked!")) | |
843 |
|
843 | |||
844 | if (not force and not extra.get("close") and p2 == nullid |
|
844 | if (not force and not extra.get("close") and p2 == nullid | |
845 | and not (changes[0] or changes[1] or changes[2]) |
|
845 | and not (changes[0] or changes[1] or changes[2]) | |
846 | and self[None].branch() == self['.'].branch()): |
|
846 | and self[None].branch() == self['.'].branch()): | |
847 | return None |
|
847 | return None | |
848 |
|
848 | |||
849 | ms = mergemod.mergestate(self) |
|
849 | ms = mergemod.mergestate(self) | |
850 | for f in changes[0]: |
|
850 | for f in changes[0]: | |
851 | if f in ms and ms[f] == 'u': |
|
851 | if f in ms and ms[f] == 'u': | |
852 | raise util.Abort(_("unresolved merge conflicts " |
|
852 | raise util.Abort(_("unresolved merge conflicts " | |
853 | "(see hg resolve)")) |
|
853 | "(see hg resolve)")) | |
854 |
|
854 | |||
855 |
cctx = context.workingctx(self, |
|
855 | cctx = context.workingctx(self, text, user, date, extra, changes) | |
856 | extra, changes) |
|
|||
857 | if editor: |
|
856 | if editor: | |
858 | cctx._text = editor(self, cctx, subs) |
|
857 | cctx._text = editor(self, cctx, subs) | |
859 | edited = (text != cctx._text) |
|
858 | edited = (text != cctx._text) | |
860 |
|
859 | |||
861 | # commit subs |
|
860 | # commit subs | |
862 | if subs or removedsubs: |
|
861 | if subs or removedsubs: | |
863 | state = wctx.substate.copy() |
|
862 | state = wctx.substate.copy() | |
864 | for s in subs: |
|
863 | for s in subs: | |
865 | self.ui.status(_('committing subrepository %s\n') % s) |
|
864 | self.ui.status(_('committing subrepository %s\n') % s) | |
866 | sr = wctx.sub(s).commit(cctx._text, user, date) |
|
865 | sr = wctx.sub(s).commit(cctx._text, user, date) | |
867 | state[s] = (state[s][0], sr) |
|
866 | state[s] = (state[s][0], sr) | |
868 | subrepo.writestate(self, state) |
|
867 | subrepo.writestate(self, state) | |
869 |
|
868 | |||
870 | # Save commit message in case this transaction gets rolled back |
|
869 | # Save commit message in case this transaction gets rolled back | |
871 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
870 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
872 | # the assumption that the user will use the same editor again. |
|
871 | # the assumption that the user will use the same editor again. | |
873 | msgfile = self.opener('last-message.txt', 'wb') |
|
872 | msgfile = self.opener('last-message.txt', 'wb') | |
874 | msgfile.write(cctx._text) |
|
873 | msgfile.write(cctx._text) | |
875 | msgfile.close() |
|
874 | msgfile.close() | |
876 |
|
875 | |||
877 | try: |
|
876 | try: | |
878 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
877 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
879 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) |
|
878 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) | |
880 | ret = self.commitctx(cctx, True) |
|
879 | ret = self.commitctx(cctx, True) | |
881 | except: |
|
880 | except: | |
882 | if edited: |
|
881 | if edited: | |
883 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) |
|
882 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) | |
884 | self.ui.write( |
|
883 | self.ui.write( | |
885 | _('note: commit message saved in %s\n') % msgfn) |
|
884 | _('note: commit message saved in %s\n') % msgfn) | |
886 | raise |
|
885 | raise | |
887 |
|
886 | |||
888 | # update dirstate and mergestate |
|
887 | # update dirstate and mergestate | |
889 | for f in changes[0] + changes[1]: |
|
888 | for f in changes[0] + changes[1]: | |
890 | self.dirstate.normal(f) |
|
889 | self.dirstate.normal(f) | |
891 | for f in changes[2]: |
|
890 | for f in changes[2]: | |
892 | self.dirstate.forget(f) |
|
891 | self.dirstate.forget(f) | |
893 | self.dirstate.setparents(ret) |
|
892 | self.dirstate.setparents(ret) | |
894 | ms.reset() |
|
893 | ms.reset() | |
895 | finally: |
|
894 | finally: | |
896 | wlock.release() |
|
895 | wlock.release() | |
897 |
|
896 | |||
898 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) |
|
897 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) | |
899 | return ret |
|
898 | return ret | |
900 |
|
899 | |||
901 | def commitctx(self, ctx, error=False): |
|
900 | def commitctx(self, ctx, error=False): | |
902 | """Add a new revision to current repository. |
|
901 | """Add a new revision to current repository. | |
903 | Revision information is passed via the context argument. |
|
902 | Revision information is passed via the context argument. | |
904 | """ |
|
903 | """ | |
905 |
|
904 | |||
906 | tr = lock = None |
|
905 | tr = lock = None | |
907 | removed = ctx.removed() |
|
906 | removed = ctx.removed() | |
908 | p1, p2 = ctx.p1(), ctx.p2() |
|
907 | p1, p2 = ctx.p1(), ctx.p2() | |
909 | m1 = p1.manifest().copy() |
|
908 | m1 = p1.manifest().copy() | |
910 | m2 = p2.manifest() |
|
909 | m2 = p2.manifest() | |
911 | user = ctx.user() |
|
910 | user = ctx.user() | |
912 |
|
911 | |||
913 | lock = self.lock() |
|
912 | lock = self.lock() | |
914 | try: |
|
913 | try: | |
915 | tr = self.transaction("commit") |
|
914 | tr = self.transaction("commit") | |
916 | trp = weakref.proxy(tr) |
|
915 | trp = weakref.proxy(tr) | |
917 |
|
916 | |||
918 | # check in files |
|
917 | # check in files | |
919 | new = {} |
|
918 | new = {} | |
920 | changed = [] |
|
919 | changed = [] | |
921 | linkrev = len(self) |
|
920 | linkrev = len(self) | |
922 | for f in sorted(ctx.modified() + ctx.added()): |
|
921 | for f in sorted(ctx.modified() + ctx.added()): | |
923 | self.ui.note(f + "\n") |
|
922 | self.ui.note(f + "\n") | |
924 | try: |
|
923 | try: | |
925 | fctx = ctx[f] |
|
924 | fctx = ctx[f] | |
926 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, |
|
925 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, | |
927 | changed) |
|
926 | changed) | |
928 | m1.set(f, fctx.flags()) |
|
927 | m1.set(f, fctx.flags()) | |
929 | except OSError, inst: |
|
928 | except OSError, inst: | |
930 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
929 | self.ui.warn(_("trouble committing %s!\n") % f) | |
931 | raise |
|
930 | raise | |
932 | except IOError, inst: |
|
931 | except IOError, inst: | |
933 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
932 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
934 | if error or errcode and errcode != errno.ENOENT: |
|
933 | if error or errcode and errcode != errno.ENOENT: | |
935 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
934 | self.ui.warn(_("trouble committing %s!\n") % f) | |
936 | raise |
|
935 | raise | |
937 | else: |
|
936 | else: | |
938 | removed.append(f) |
|
937 | removed.append(f) | |
939 |
|
938 | |||
940 | # update manifest |
|
939 | # update manifest | |
941 | m1.update(new) |
|
940 | m1.update(new) | |
942 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
941 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
943 | drop = [f for f in removed if f in m1] |
|
942 | drop = [f for f in removed if f in m1] | |
944 | for f in drop: |
|
943 | for f in drop: | |
945 | del m1[f] |
|
944 | del m1[f] | |
946 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), |
|
945 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), | |
947 | p2.manifestnode(), (new, drop)) |
|
946 | p2.manifestnode(), (new, drop)) | |
948 |
|
947 | |||
949 | # update changelog |
|
948 | # update changelog | |
950 | self.changelog.delayupdate() |
|
949 | self.changelog.delayupdate() | |
951 | n = self.changelog.add(mn, changed + removed, ctx.description(), |
|
950 | n = self.changelog.add(mn, changed + removed, ctx.description(), | |
952 | trp, p1.node(), p2.node(), |
|
951 | trp, p1.node(), p2.node(), | |
953 | user, ctx.date(), ctx.extra().copy()) |
|
952 | user, ctx.date(), ctx.extra().copy()) | |
954 | p = lambda: self.changelog.writepending() and self.root or "" |
|
953 | p = lambda: self.changelog.writepending() and self.root or "" | |
955 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
954 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
956 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
955 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
957 | parent2=xp2, pending=p) |
|
956 | parent2=xp2, pending=p) | |
958 | self.changelog.finalize(trp) |
|
957 | self.changelog.finalize(trp) | |
959 | tr.close() |
|
958 | tr.close() | |
960 |
|
959 | |||
961 | if self._branchcache: |
|
960 | if self._branchcache: | |
962 | self.branchtags() |
|
961 | self.branchtags() | |
963 | return n |
|
962 | return n | |
964 | finally: |
|
963 | finally: | |
965 | del tr |
|
964 | del tr | |
966 | lock.release() |
|
965 | lock.release() | |
967 |
|
966 | |||
968 | def destroyed(self): |
|
967 | def destroyed(self): | |
969 | '''Inform the repository that nodes have been destroyed. |
|
968 | '''Inform the repository that nodes have been destroyed. | |
970 | Intended for use by strip and rollback, so there's a common |
|
969 | Intended for use by strip and rollback, so there's a common | |
971 | place for anything that has to be done after destroying history.''' |
|
970 | place for anything that has to be done after destroying history.''' | |
972 | # XXX it might be nice if we could take the list of destroyed |
|
971 | # XXX it might be nice if we could take the list of destroyed | |
973 | # nodes, but I don't see an easy way for rollback() to do that |
|
972 | # nodes, but I don't see an easy way for rollback() to do that | |
974 |
|
973 | |||
975 | # Ensure the persistent tag cache is updated. Doing it now |
|
974 | # Ensure the persistent tag cache is updated. Doing it now | |
976 | # means that the tag cache only has to worry about destroyed |
|
975 | # means that the tag cache only has to worry about destroyed | |
977 | # heads immediately after a strip/rollback. That in turn |
|
976 | # heads immediately after a strip/rollback. That in turn | |
978 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
977 | # guarantees that "cachetip == currenttip" (comparing both rev | |
979 | # and node) always means no nodes have been added or destroyed. |
|
978 | # and node) always means no nodes have been added or destroyed. | |
980 |
|
979 | |||
981 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
980 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
982 | # head, refresh the tag cache, then immediately add a new head. |
|
981 | # head, refresh the tag cache, then immediately add a new head. | |
983 | # But I think doing it this way is necessary for the "instant |
|
982 | # But I think doing it this way is necessary for the "instant | |
984 | # tag cache retrieval" case to work. |
|
983 | # tag cache retrieval" case to work. | |
985 | self.invalidatecaches() |
|
984 | self.invalidatecaches() | |
986 |
|
985 | |||
987 | def walk(self, match, node=None): |
|
986 | def walk(self, match, node=None): | |
988 | ''' |
|
987 | ''' | |
989 | walk recursively through the directory tree or a given |
|
988 | walk recursively through the directory tree or a given | |
990 | changeset, finding all files matched by the match |
|
989 | changeset, finding all files matched by the match | |
991 | function |
|
990 | function | |
992 | ''' |
|
991 | ''' | |
993 | return self[node].walk(match) |
|
992 | return self[node].walk(match) | |
994 |
|
993 | |||
995 | def status(self, node1='.', node2=None, match=None, |
|
994 | def status(self, node1='.', node2=None, match=None, | |
996 | ignored=False, clean=False, unknown=False): |
|
995 | ignored=False, clean=False, unknown=False): | |
997 | """return status of files between two nodes or node and working directory |
|
996 | """return status of files between two nodes or node and working directory | |
998 |
|
997 | |||
999 | If node1 is None, use the first dirstate parent instead. |
|
998 | If node1 is None, use the first dirstate parent instead. | |
1000 | If node2 is None, compare node1 with working directory. |
|
999 | If node2 is None, compare node1 with working directory. | |
1001 | """ |
|
1000 | """ | |
1002 |
|
1001 | |||
1003 | def mfmatches(ctx): |
|
1002 | def mfmatches(ctx): | |
1004 | mf = ctx.manifest().copy() |
|
1003 | mf = ctx.manifest().copy() | |
1005 | for fn in mf.keys(): |
|
1004 | for fn in mf.keys(): | |
1006 | if not match(fn): |
|
1005 | if not match(fn): | |
1007 | del mf[fn] |
|
1006 | del mf[fn] | |
1008 | return mf |
|
1007 | return mf | |
1009 |
|
1008 | |||
1010 | if isinstance(node1, context.changectx): |
|
1009 | if isinstance(node1, context.changectx): | |
1011 | ctx1 = node1 |
|
1010 | ctx1 = node1 | |
1012 | else: |
|
1011 | else: | |
1013 | ctx1 = self[node1] |
|
1012 | ctx1 = self[node1] | |
1014 | if isinstance(node2, context.changectx): |
|
1013 | if isinstance(node2, context.changectx): | |
1015 | ctx2 = node2 |
|
1014 | ctx2 = node2 | |
1016 | else: |
|
1015 | else: | |
1017 | ctx2 = self[node2] |
|
1016 | ctx2 = self[node2] | |
1018 |
|
1017 | |||
1019 | working = ctx2.rev() is None |
|
1018 | working = ctx2.rev() is None | |
1020 | parentworking = working and ctx1 == self['.'] |
|
1019 | parentworking = working and ctx1 == self['.'] | |
1021 | match = match or matchmod.always(self.root, self.getcwd()) |
|
1020 | match = match or matchmod.always(self.root, self.getcwd()) | |
1022 | listignored, listclean, listunknown = ignored, clean, unknown |
|
1021 | listignored, listclean, listunknown = ignored, clean, unknown | |
1023 |
|
1022 | |||
1024 | # load earliest manifest first for caching reasons |
|
1023 | # load earliest manifest first for caching reasons | |
1025 | if not working and ctx2.rev() < ctx1.rev(): |
|
1024 | if not working and ctx2.rev() < ctx1.rev(): | |
1026 | ctx2.manifest() |
|
1025 | ctx2.manifest() | |
1027 |
|
1026 | |||
1028 | if not parentworking: |
|
1027 | if not parentworking: | |
1029 | def bad(f, msg): |
|
1028 | def bad(f, msg): | |
1030 | if f not in ctx1: |
|
1029 | if f not in ctx1: | |
1031 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) |
|
1030 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) | |
1032 | match.bad = bad |
|
1031 | match.bad = bad | |
1033 |
|
1032 | |||
1034 | if working: # we need to scan the working dir |
|
1033 | if working: # we need to scan the working dir | |
1035 | subrepos = ctx1.substate.keys() |
|
1034 | subrepos = ctx1.substate.keys() | |
1036 | s = self.dirstate.status(match, subrepos, listignored, |
|
1035 | s = self.dirstate.status(match, subrepos, listignored, | |
1037 | listclean, listunknown) |
|
1036 | listclean, listunknown) | |
1038 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s |
|
1037 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s | |
1039 |
|
1038 | |||
1040 | # check for any possibly clean files |
|
1039 | # check for any possibly clean files | |
1041 | if parentworking and cmp: |
|
1040 | if parentworking and cmp: | |
1042 | fixup = [] |
|
1041 | fixup = [] | |
1043 | # do a full compare of any files that might have changed |
|
1042 | # do a full compare of any files that might have changed | |
1044 | for f in sorted(cmp): |
|
1043 | for f in sorted(cmp): | |
1045 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) |
|
1044 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) | |
1046 | or ctx1[f].cmp(ctx2[f].data())): |
|
1045 | or ctx1[f].cmp(ctx2[f].data())): | |
1047 | modified.append(f) |
|
1046 | modified.append(f) | |
1048 | else: |
|
1047 | else: | |
1049 | fixup.append(f) |
|
1048 | fixup.append(f) | |
1050 |
|
1049 | |||
1051 | if listclean: |
|
1050 | if listclean: | |
1052 | clean += fixup |
|
1051 | clean += fixup | |
1053 |
|
1052 | |||
1054 | # update dirstate for files that are actually clean |
|
1053 | # update dirstate for files that are actually clean | |
1055 | if fixup: |
|
1054 | if fixup: | |
1056 | try: |
|
1055 | try: | |
1057 | # updating the dirstate is optional |
|
1056 | # updating the dirstate is optional | |
1058 | # so we don't wait on the lock |
|
1057 | # so we don't wait on the lock | |
1059 | wlock = self.wlock(False) |
|
1058 | wlock = self.wlock(False) | |
1060 | try: |
|
1059 | try: | |
1061 | for f in fixup: |
|
1060 | for f in fixup: | |
1062 | self.dirstate.normal(f) |
|
1061 | self.dirstate.normal(f) | |
1063 | finally: |
|
1062 | finally: | |
1064 | wlock.release() |
|
1063 | wlock.release() | |
1065 | except error.LockError: |
|
1064 | except error.LockError: | |
1066 | pass |
|
1065 | pass | |
1067 |
|
1066 | |||
1068 | if not parentworking: |
|
1067 | if not parentworking: | |
1069 | mf1 = mfmatches(ctx1) |
|
1068 | mf1 = mfmatches(ctx1) | |
1070 | if working: |
|
1069 | if working: | |
1071 | # we are comparing working dir against non-parent |
|
1070 | # we are comparing working dir against non-parent | |
1072 | # generate a pseudo-manifest for the working dir |
|
1071 | # generate a pseudo-manifest for the working dir | |
1073 | mf2 = mfmatches(self['.']) |
|
1072 | mf2 = mfmatches(self['.']) | |
1074 | for f in cmp + modified + added: |
|
1073 | for f in cmp + modified + added: | |
1075 | mf2[f] = None |
|
1074 | mf2[f] = None | |
1076 | mf2.set(f, ctx2.flags(f)) |
|
1075 | mf2.set(f, ctx2.flags(f)) | |
1077 | for f in removed: |
|
1076 | for f in removed: | |
1078 | if f in mf2: |
|
1077 | if f in mf2: | |
1079 | del mf2[f] |
|
1078 | del mf2[f] | |
1080 | else: |
|
1079 | else: | |
1081 | # we are comparing two revisions |
|
1080 | # we are comparing two revisions | |
1082 | deleted, unknown, ignored = [], [], [] |
|
1081 | deleted, unknown, ignored = [], [], [] | |
1083 | mf2 = mfmatches(ctx2) |
|
1082 | mf2 = mfmatches(ctx2) | |
1084 |
|
1083 | |||
1085 | modified, added, clean = [], [], [] |
|
1084 | modified, added, clean = [], [], [] | |
1086 | for fn in mf2: |
|
1085 | for fn in mf2: | |
1087 | if fn in mf1: |
|
1086 | if fn in mf1: | |
1088 | if (mf1.flags(fn) != mf2.flags(fn) or |
|
1087 | if (mf1.flags(fn) != mf2.flags(fn) or | |
1089 | (mf1[fn] != mf2[fn] and |
|
1088 | (mf1[fn] != mf2[fn] and | |
1090 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))): |
|
1089 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))): | |
1091 | modified.append(fn) |
|
1090 | modified.append(fn) | |
1092 | elif listclean: |
|
1091 | elif listclean: | |
1093 | clean.append(fn) |
|
1092 | clean.append(fn) | |
1094 | del mf1[fn] |
|
1093 | del mf1[fn] | |
1095 | else: |
|
1094 | else: | |
1096 | added.append(fn) |
|
1095 | added.append(fn) | |
1097 | removed = mf1.keys() |
|
1096 | removed = mf1.keys() | |
1098 |
|
1097 | |||
1099 | r = modified, added, removed, deleted, unknown, ignored, clean |
|
1098 | r = modified, added, removed, deleted, unknown, ignored, clean | |
1100 | [l.sort() for l in r] |
|
1099 | [l.sort() for l in r] | |
1101 | return r |
|
1100 | return r | |
1102 |
|
1101 | |||
1103 | def add(self, list): |
|
1102 | def add(self, list): | |
1104 | wlock = self.wlock() |
|
1103 | wlock = self.wlock() | |
1105 | try: |
|
1104 | try: | |
1106 | rejected = [] |
|
1105 | rejected = [] | |
1107 | for f in list: |
|
1106 | for f in list: | |
1108 | p = self.wjoin(f) |
|
1107 | p = self.wjoin(f) | |
1109 | try: |
|
1108 | try: | |
1110 | st = os.lstat(p) |
|
1109 | st = os.lstat(p) | |
1111 | except: |
|
1110 | except: | |
1112 | self.ui.warn(_("%s does not exist!\n") % f) |
|
1111 | self.ui.warn(_("%s does not exist!\n") % f) | |
1113 | rejected.append(f) |
|
1112 | rejected.append(f) | |
1114 | continue |
|
1113 | continue | |
1115 | if st.st_size > 10000000: |
|
1114 | if st.st_size > 10000000: | |
1116 | self.ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1115 | self.ui.warn(_("%s: up to %d MB of RAM may be required " | |
1117 | "to manage this file\n" |
|
1116 | "to manage this file\n" | |
1118 | "(use 'hg revert %s' to cancel the " |
|
1117 | "(use 'hg revert %s' to cancel the " | |
1119 | "pending addition)\n") |
|
1118 | "pending addition)\n") | |
1120 | % (f, 3 * st.st_size // 1000000, f)) |
|
1119 | % (f, 3 * st.st_size // 1000000, f)) | |
1121 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1120 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1122 | self.ui.warn(_("%s not added: only files and symlinks " |
|
1121 | self.ui.warn(_("%s not added: only files and symlinks " | |
1123 | "supported currently\n") % f) |
|
1122 | "supported currently\n") % f) | |
1124 | rejected.append(p) |
|
1123 | rejected.append(p) | |
1125 | elif self.dirstate[f] in 'amn': |
|
1124 | elif self.dirstate[f] in 'amn': | |
1126 | self.ui.warn(_("%s already tracked!\n") % f) |
|
1125 | self.ui.warn(_("%s already tracked!\n") % f) | |
1127 | elif self.dirstate[f] == 'r': |
|
1126 | elif self.dirstate[f] == 'r': | |
1128 | self.dirstate.normallookup(f) |
|
1127 | self.dirstate.normallookup(f) | |
1129 | else: |
|
1128 | else: | |
1130 | self.dirstate.add(f) |
|
1129 | self.dirstate.add(f) | |
1131 | return rejected |
|
1130 | return rejected | |
1132 | finally: |
|
1131 | finally: | |
1133 | wlock.release() |
|
1132 | wlock.release() | |
1134 |
|
1133 | |||
1135 | def forget(self, list): |
|
1134 | def forget(self, list): | |
1136 | wlock = self.wlock() |
|
1135 | wlock = self.wlock() | |
1137 | try: |
|
1136 | try: | |
1138 | for f in list: |
|
1137 | for f in list: | |
1139 | if self.dirstate[f] != 'a': |
|
1138 | if self.dirstate[f] != 'a': | |
1140 | self.ui.warn(_("%s not added!\n") % f) |
|
1139 | self.ui.warn(_("%s not added!\n") % f) | |
1141 | else: |
|
1140 | else: | |
1142 | self.dirstate.forget(f) |
|
1141 | self.dirstate.forget(f) | |
1143 | finally: |
|
1142 | finally: | |
1144 | wlock.release() |
|
1143 | wlock.release() | |
1145 |
|
1144 | |||
1146 | def remove(self, list, unlink=False): |
|
1145 | def remove(self, list, unlink=False): | |
1147 | if unlink: |
|
1146 | if unlink: | |
1148 | for f in list: |
|
1147 | for f in list: | |
1149 | try: |
|
1148 | try: | |
1150 | util.unlink(self.wjoin(f)) |
|
1149 | util.unlink(self.wjoin(f)) | |
1151 | except OSError, inst: |
|
1150 | except OSError, inst: | |
1152 | if inst.errno != errno.ENOENT: |
|
1151 | if inst.errno != errno.ENOENT: | |
1153 | raise |
|
1152 | raise | |
1154 | wlock = self.wlock() |
|
1153 | wlock = self.wlock() | |
1155 | try: |
|
1154 | try: | |
1156 | for f in list: |
|
1155 | for f in list: | |
1157 | if unlink and os.path.exists(self.wjoin(f)): |
|
1156 | if unlink and os.path.exists(self.wjoin(f)): | |
1158 | self.ui.warn(_("%s still exists!\n") % f) |
|
1157 | self.ui.warn(_("%s still exists!\n") % f) | |
1159 | elif self.dirstate[f] == 'a': |
|
1158 | elif self.dirstate[f] == 'a': | |
1160 | self.dirstate.forget(f) |
|
1159 | self.dirstate.forget(f) | |
1161 | elif f not in self.dirstate: |
|
1160 | elif f not in self.dirstate: | |
1162 | self.ui.warn(_("%s not tracked!\n") % f) |
|
1161 | self.ui.warn(_("%s not tracked!\n") % f) | |
1163 | else: |
|
1162 | else: | |
1164 | self.dirstate.remove(f) |
|
1163 | self.dirstate.remove(f) | |
1165 | finally: |
|
1164 | finally: | |
1166 | wlock.release() |
|
1165 | wlock.release() | |
1167 |
|
1166 | |||
1168 | def undelete(self, list): |
|
1167 | def undelete(self, list): | |
1169 | manifests = [self.manifest.read(self.changelog.read(p)[0]) |
|
1168 | manifests = [self.manifest.read(self.changelog.read(p)[0]) | |
1170 | for p in self.dirstate.parents() if p != nullid] |
|
1169 | for p in self.dirstate.parents() if p != nullid] | |
1171 | wlock = self.wlock() |
|
1170 | wlock = self.wlock() | |
1172 | try: |
|
1171 | try: | |
1173 | for f in list: |
|
1172 | for f in list: | |
1174 | if self.dirstate[f] != 'r': |
|
1173 | if self.dirstate[f] != 'r': | |
1175 | self.ui.warn(_("%s not removed!\n") % f) |
|
1174 | self.ui.warn(_("%s not removed!\n") % f) | |
1176 | else: |
|
1175 | else: | |
1177 | m = f in manifests[0] and manifests[0] or manifests[1] |
|
1176 | m = f in manifests[0] and manifests[0] or manifests[1] | |
1178 | t = self.file(f).read(m[f]) |
|
1177 | t = self.file(f).read(m[f]) | |
1179 | self.wwrite(f, t, m.flags(f)) |
|
1178 | self.wwrite(f, t, m.flags(f)) | |
1180 | self.dirstate.normal(f) |
|
1179 | self.dirstate.normal(f) | |
1181 | finally: |
|
1180 | finally: | |
1182 | wlock.release() |
|
1181 | wlock.release() | |
1183 |
|
1182 | |||
1184 | def copy(self, source, dest): |
|
1183 | def copy(self, source, dest): | |
1185 | p = self.wjoin(dest) |
|
1184 | p = self.wjoin(dest) | |
1186 | if not (os.path.exists(p) or os.path.islink(p)): |
|
1185 | if not (os.path.exists(p) or os.path.islink(p)): | |
1187 | self.ui.warn(_("%s does not exist!\n") % dest) |
|
1186 | self.ui.warn(_("%s does not exist!\n") % dest) | |
1188 | elif not (os.path.isfile(p) or os.path.islink(p)): |
|
1187 | elif not (os.path.isfile(p) or os.path.islink(p)): | |
1189 | self.ui.warn(_("copy failed: %s is not a file or a " |
|
1188 | self.ui.warn(_("copy failed: %s is not a file or a " | |
1190 | "symbolic link\n") % dest) |
|
1189 | "symbolic link\n") % dest) | |
1191 | else: |
|
1190 | else: | |
1192 | wlock = self.wlock() |
|
1191 | wlock = self.wlock() | |
1193 | try: |
|
1192 | try: | |
1194 | if self.dirstate[dest] in '?r': |
|
1193 | if self.dirstate[dest] in '?r': | |
1195 | self.dirstate.add(dest) |
|
1194 | self.dirstate.add(dest) | |
1196 | self.dirstate.copy(source, dest) |
|
1195 | self.dirstate.copy(source, dest) | |
1197 | finally: |
|
1196 | finally: | |
1198 | wlock.release() |
|
1197 | wlock.release() | |
1199 |
|
1198 | |||
1200 | def heads(self, start=None): |
|
1199 | def heads(self, start=None): | |
1201 | heads = self.changelog.heads(start) |
|
1200 | heads = self.changelog.heads(start) | |
1202 | # sort the output in rev descending order |
|
1201 | # sort the output in rev descending order | |
1203 | heads = [(-self.changelog.rev(h), h) for h in heads] |
|
1202 | heads = [(-self.changelog.rev(h), h) for h in heads] | |
1204 | return [n for (r, n) in sorted(heads)] |
|
1203 | return [n for (r, n) in sorted(heads)] | |
1205 |
|
1204 | |||
1206 | def branchheads(self, branch=None, start=None, closed=False): |
|
1205 | def branchheads(self, branch=None, start=None, closed=False): | |
1207 | '''return a (possibly filtered) list of heads for the given branch |
|
1206 | '''return a (possibly filtered) list of heads for the given branch | |
1208 |
|
1207 | |||
1209 | Heads are returned in topological order, from newest to oldest. |
|
1208 | Heads are returned in topological order, from newest to oldest. | |
1210 | If branch is None, use the dirstate branch. |
|
1209 | If branch is None, use the dirstate branch. | |
1211 | If start is not None, return only heads reachable from start. |
|
1210 | If start is not None, return only heads reachable from start. | |
1212 | If closed is True, return heads that are marked as closed as well. |
|
1211 | If closed is True, return heads that are marked as closed as well. | |
1213 | ''' |
|
1212 | ''' | |
1214 | if branch is None: |
|
1213 | if branch is None: | |
1215 | branch = self[None].branch() |
|
1214 | branch = self[None].branch() | |
1216 | branches = self.branchmap() |
|
1215 | branches = self.branchmap() | |
1217 | if branch not in branches: |
|
1216 | if branch not in branches: | |
1218 | return [] |
|
1217 | return [] | |
1219 | # the cache returns heads ordered lowest to highest |
|
1218 | # the cache returns heads ordered lowest to highest | |
1220 | bheads = list(reversed(branches[branch])) |
|
1219 | bheads = list(reversed(branches[branch])) | |
1221 | if start is not None: |
|
1220 | if start is not None: | |
1222 | # filter out the heads that cannot be reached from startrev |
|
1221 | # filter out the heads that cannot be reached from startrev | |
1223 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1222 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1224 | bheads = [h for h in bheads if h in fbheads] |
|
1223 | bheads = [h for h in bheads if h in fbheads] | |
1225 | if not closed: |
|
1224 | if not closed: | |
1226 | bheads = [h for h in bheads if |
|
1225 | bheads = [h for h in bheads if | |
1227 | ('close' not in self.changelog.read(h)[5])] |
|
1226 | ('close' not in self.changelog.read(h)[5])] | |
1228 | return bheads |
|
1227 | return bheads | |
1229 |
|
1228 | |||
1230 | def branches(self, nodes): |
|
1229 | def branches(self, nodes): | |
1231 | if not nodes: |
|
1230 | if not nodes: | |
1232 | nodes = [self.changelog.tip()] |
|
1231 | nodes = [self.changelog.tip()] | |
1233 | b = [] |
|
1232 | b = [] | |
1234 | for n in nodes: |
|
1233 | for n in nodes: | |
1235 | t = n |
|
1234 | t = n | |
1236 | while 1: |
|
1235 | while 1: | |
1237 | p = self.changelog.parents(n) |
|
1236 | p = self.changelog.parents(n) | |
1238 | if p[1] != nullid or p[0] == nullid: |
|
1237 | if p[1] != nullid or p[0] == nullid: | |
1239 | b.append((t, n, p[0], p[1])) |
|
1238 | b.append((t, n, p[0], p[1])) | |
1240 | break |
|
1239 | break | |
1241 | n = p[0] |
|
1240 | n = p[0] | |
1242 | return b |
|
1241 | return b | |
1243 |
|
1242 | |||
1244 | def between(self, pairs): |
|
1243 | def between(self, pairs): | |
1245 | r = [] |
|
1244 | r = [] | |
1246 |
|
1245 | |||
1247 | for top, bottom in pairs: |
|
1246 | for top, bottom in pairs: | |
1248 | n, l, i = top, [], 0 |
|
1247 | n, l, i = top, [], 0 | |
1249 | f = 1 |
|
1248 | f = 1 | |
1250 |
|
1249 | |||
1251 | while n != bottom and n != nullid: |
|
1250 | while n != bottom and n != nullid: | |
1252 | p = self.changelog.parents(n)[0] |
|
1251 | p = self.changelog.parents(n)[0] | |
1253 | if i == f: |
|
1252 | if i == f: | |
1254 | l.append(n) |
|
1253 | l.append(n) | |
1255 | f = f * 2 |
|
1254 | f = f * 2 | |
1256 | n = p |
|
1255 | n = p | |
1257 | i += 1 |
|
1256 | i += 1 | |
1258 |
|
1257 | |||
1259 | r.append(l) |
|
1258 | r.append(l) | |
1260 |
|
1259 | |||
1261 | return r |
|
1260 | return r | |
1262 |
|
1261 | |||
1263 | def findincoming(self, remote, base=None, heads=None, force=False): |
|
1262 | def findincoming(self, remote, base=None, heads=None, force=False): | |
1264 | """Return list of roots of the subsets of missing nodes from remote |
|
1263 | """Return list of roots of the subsets of missing nodes from remote | |
1265 |
|
1264 | |||
1266 | If base dict is specified, assume that these nodes and their parents |
|
1265 | If base dict is specified, assume that these nodes and their parents | |
1267 | exist on the remote side and that no child of a node of base exists |
|
1266 | exist on the remote side and that no child of a node of base exists | |
1268 | in both remote and self. |
|
1267 | in both remote and self. | |
1269 | Furthermore base will be updated to include the nodes that exists |
|
1268 | Furthermore base will be updated to include the nodes that exists | |
1270 | in self and remote but no children exists in self and remote. |
|
1269 | in self and remote but no children exists in self and remote. | |
1271 | If a list of heads is specified, return only nodes which are heads |
|
1270 | If a list of heads is specified, return only nodes which are heads | |
1272 | or ancestors of these heads. |
|
1271 | or ancestors of these heads. | |
1273 |
|
1272 | |||
1274 | All the ancestors of base are in self and in remote. |
|
1273 | All the ancestors of base are in self and in remote. | |
1275 | All the descendants of the list returned are missing in self. |
|
1274 | All the descendants of the list returned are missing in self. | |
1276 | (and so we know that the rest of the nodes are missing in remote, see |
|
1275 | (and so we know that the rest of the nodes are missing in remote, see | |
1277 | outgoing) |
|
1276 | outgoing) | |
1278 | """ |
|
1277 | """ | |
1279 | return self.findcommonincoming(remote, base, heads, force)[1] |
|
1278 | return self.findcommonincoming(remote, base, heads, force)[1] | |
1280 |
|
1279 | |||
1281 | def findcommonincoming(self, remote, base=None, heads=None, force=False): |
|
1280 | def findcommonincoming(self, remote, base=None, heads=None, force=False): | |
1282 | """Return a tuple (common, missing roots, heads) used to identify |
|
1281 | """Return a tuple (common, missing roots, heads) used to identify | |
1283 | missing nodes from remote. |
|
1282 | missing nodes from remote. | |
1284 |
|
1283 | |||
1285 | If base dict is specified, assume that these nodes and their parents |
|
1284 | If base dict is specified, assume that these nodes and their parents | |
1286 | exist on the remote side and that no child of a node of base exists |
|
1285 | exist on the remote side and that no child of a node of base exists | |
1287 | in both remote and self. |
|
1286 | in both remote and self. | |
1288 | Furthermore base will be updated to include the nodes that exists |
|
1287 | Furthermore base will be updated to include the nodes that exists | |
1289 | in self and remote but no children exists in self and remote. |
|
1288 | in self and remote but no children exists in self and remote. | |
1290 | If a list of heads is specified, return only nodes which are heads |
|
1289 | If a list of heads is specified, return only nodes which are heads | |
1291 | or ancestors of these heads. |
|
1290 | or ancestors of these heads. | |
1292 |
|
1291 | |||
1293 | All the ancestors of base are in self and in remote. |
|
1292 | All the ancestors of base are in self and in remote. | |
1294 | """ |
|
1293 | """ | |
1295 | m = self.changelog.nodemap |
|
1294 | m = self.changelog.nodemap | |
1296 | search = [] |
|
1295 | search = [] | |
1297 | fetch = set() |
|
1296 | fetch = set() | |
1298 | seen = set() |
|
1297 | seen = set() | |
1299 | seenbranch = set() |
|
1298 | seenbranch = set() | |
1300 | if base is None: |
|
1299 | if base is None: | |
1301 | base = {} |
|
1300 | base = {} | |
1302 |
|
1301 | |||
1303 | if not heads: |
|
1302 | if not heads: | |
1304 | heads = remote.heads() |
|
1303 | heads = remote.heads() | |
1305 |
|
1304 | |||
1306 | if self.changelog.tip() == nullid: |
|
1305 | if self.changelog.tip() == nullid: | |
1307 | base[nullid] = 1 |
|
1306 | base[nullid] = 1 | |
1308 | if heads != [nullid]: |
|
1307 | if heads != [nullid]: | |
1309 | return [nullid], [nullid], list(heads) |
|
1308 | return [nullid], [nullid], list(heads) | |
1310 | return [nullid], [], [] |
|
1309 | return [nullid], [], [] | |
1311 |
|
1310 | |||
1312 | # assume we're closer to the tip than the root |
|
1311 | # assume we're closer to the tip than the root | |
1313 | # and start by examining the heads |
|
1312 | # and start by examining the heads | |
1314 | self.ui.status(_("searching for changes\n")) |
|
1313 | self.ui.status(_("searching for changes\n")) | |
1315 |
|
1314 | |||
1316 | unknown = [] |
|
1315 | unknown = [] | |
1317 | for h in heads: |
|
1316 | for h in heads: | |
1318 | if h not in m: |
|
1317 | if h not in m: | |
1319 | unknown.append(h) |
|
1318 | unknown.append(h) | |
1320 | else: |
|
1319 | else: | |
1321 | base[h] = 1 |
|
1320 | base[h] = 1 | |
1322 |
|
1321 | |||
1323 | heads = unknown |
|
1322 | heads = unknown | |
1324 | if not unknown: |
|
1323 | if not unknown: | |
1325 | return base.keys(), [], [] |
|
1324 | return base.keys(), [], [] | |
1326 |
|
1325 | |||
1327 | req = set(unknown) |
|
1326 | req = set(unknown) | |
1328 | reqcnt = 0 |
|
1327 | reqcnt = 0 | |
1329 |
|
1328 | |||
1330 | # search through remote branches |
|
1329 | # search through remote branches | |
1331 | # a 'branch' here is a linear segment of history, with four parts: |
|
1330 | # a 'branch' here is a linear segment of history, with four parts: | |
1332 | # head, root, first parent, second parent |
|
1331 | # head, root, first parent, second parent | |
1333 | # (a branch always has two parents (or none) by definition) |
|
1332 | # (a branch always has two parents (or none) by definition) | |
1334 | unknown = remote.branches(unknown) |
|
1333 | unknown = remote.branches(unknown) | |
1335 | while unknown: |
|
1334 | while unknown: | |
1336 | r = [] |
|
1335 | r = [] | |
1337 | while unknown: |
|
1336 | while unknown: | |
1338 | n = unknown.pop(0) |
|
1337 | n = unknown.pop(0) | |
1339 | if n[0] in seen: |
|
1338 | if n[0] in seen: | |
1340 | continue |
|
1339 | continue | |
1341 |
|
1340 | |||
1342 | self.ui.debug("examining %s:%s\n" |
|
1341 | self.ui.debug("examining %s:%s\n" | |
1343 | % (short(n[0]), short(n[1]))) |
|
1342 | % (short(n[0]), short(n[1]))) | |
1344 | if n[0] == nullid: # found the end of the branch |
|
1343 | if n[0] == nullid: # found the end of the branch | |
1345 | pass |
|
1344 | pass | |
1346 | elif n in seenbranch: |
|
1345 | elif n in seenbranch: | |
1347 | self.ui.debug("branch already found\n") |
|
1346 | self.ui.debug("branch already found\n") | |
1348 | continue |
|
1347 | continue | |
1349 | elif n[1] and n[1] in m: # do we know the base? |
|
1348 | elif n[1] and n[1] in m: # do we know the base? | |
1350 | self.ui.debug("found incomplete branch %s:%s\n" |
|
1349 | self.ui.debug("found incomplete branch %s:%s\n" | |
1351 | % (short(n[0]), short(n[1]))) |
|
1350 | % (short(n[0]), short(n[1]))) | |
1352 | search.append(n[0:2]) # schedule branch range for scanning |
|
1351 | search.append(n[0:2]) # schedule branch range for scanning | |
1353 | seenbranch.add(n) |
|
1352 | seenbranch.add(n) | |
1354 | else: |
|
1353 | else: | |
1355 | if n[1] not in seen and n[1] not in fetch: |
|
1354 | if n[1] not in seen and n[1] not in fetch: | |
1356 | if n[2] in m and n[3] in m: |
|
1355 | if n[2] in m and n[3] in m: | |
1357 | self.ui.debug("found new changeset %s\n" % |
|
1356 | self.ui.debug("found new changeset %s\n" % | |
1358 | short(n[1])) |
|
1357 | short(n[1])) | |
1359 | fetch.add(n[1]) # earliest unknown |
|
1358 | fetch.add(n[1]) # earliest unknown | |
1360 | for p in n[2:4]: |
|
1359 | for p in n[2:4]: | |
1361 | if p in m: |
|
1360 | if p in m: | |
1362 | base[p] = 1 # latest known |
|
1361 | base[p] = 1 # latest known | |
1363 |
|
1362 | |||
1364 | for p in n[2:4]: |
|
1363 | for p in n[2:4]: | |
1365 | if p not in req and p not in m: |
|
1364 | if p not in req and p not in m: | |
1366 | r.append(p) |
|
1365 | r.append(p) | |
1367 | req.add(p) |
|
1366 | req.add(p) | |
1368 | seen.add(n[0]) |
|
1367 | seen.add(n[0]) | |
1369 |
|
1368 | |||
1370 | if r: |
|
1369 | if r: | |
1371 | reqcnt += 1 |
|
1370 | reqcnt += 1 | |
1372 | self.ui.progress(_('searching'), reqcnt, unit=_('queries')) |
|
1371 | self.ui.progress(_('searching'), reqcnt, unit=_('queries')) | |
1373 | self.ui.debug("request %d: %s\n" % |
|
1372 | self.ui.debug("request %d: %s\n" % | |
1374 | (reqcnt, " ".join(map(short, r)))) |
|
1373 | (reqcnt, " ".join(map(short, r)))) | |
1375 | for p in xrange(0, len(r), 10): |
|
1374 | for p in xrange(0, len(r), 10): | |
1376 | for b in remote.branches(r[p:p + 10]): |
|
1375 | for b in remote.branches(r[p:p + 10]): | |
1377 | self.ui.debug("received %s:%s\n" % |
|
1376 | self.ui.debug("received %s:%s\n" % | |
1378 | (short(b[0]), short(b[1]))) |
|
1377 | (short(b[0]), short(b[1]))) | |
1379 | unknown.append(b) |
|
1378 | unknown.append(b) | |
1380 |
|
1379 | |||
1381 | # do binary search on the branches we found |
|
1380 | # do binary search on the branches we found | |
1382 | while search: |
|
1381 | while search: | |
1383 | newsearch = [] |
|
1382 | newsearch = [] | |
1384 | reqcnt += 1 |
|
1383 | reqcnt += 1 | |
1385 | self.ui.progress(_('searching'), reqcnt, unit=_('queries')) |
|
1384 | self.ui.progress(_('searching'), reqcnt, unit=_('queries')) | |
1386 | for n, l in zip(search, remote.between(search)): |
|
1385 | for n, l in zip(search, remote.between(search)): | |
1387 | l.append(n[1]) |
|
1386 | l.append(n[1]) | |
1388 | p = n[0] |
|
1387 | p = n[0] | |
1389 | f = 1 |
|
1388 | f = 1 | |
1390 | for i in l: |
|
1389 | for i in l: | |
1391 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) |
|
1390 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) | |
1392 | if i in m: |
|
1391 | if i in m: | |
1393 | if f <= 2: |
|
1392 | if f <= 2: | |
1394 | self.ui.debug("found new branch changeset %s\n" % |
|
1393 | self.ui.debug("found new branch changeset %s\n" % | |
1395 | short(p)) |
|
1394 | short(p)) | |
1396 | fetch.add(p) |
|
1395 | fetch.add(p) | |
1397 | base[i] = 1 |
|
1396 | base[i] = 1 | |
1398 | else: |
|
1397 | else: | |
1399 | self.ui.debug("narrowed branch search to %s:%s\n" |
|
1398 | self.ui.debug("narrowed branch search to %s:%s\n" | |
1400 | % (short(p), short(i))) |
|
1399 | % (short(p), short(i))) | |
1401 | newsearch.append((p, i)) |
|
1400 | newsearch.append((p, i)) | |
1402 | break |
|
1401 | break | |
1403 | p, f = i, f * 2 |
|
1402 | p, f = i, f * 2 | |
1404 | search = newsearch |
|
1403 | search = newsearch | |
1405 |
|
1404 | |||
1406 | # sanity check our fetch list |
|
1405 | # sanity check our fetch list | |
1407 | for f in fetch: |
|
1406 | for f in fetch: | |
1408 | if f in m: |
|
1407 | if f in m: | |
1409 | raise error.RepoError(_("already have changeset ") |
|
1408 | raise error.RepoError(_("already have changeset ") | |
1410 | + short(f[:4])) |
|
1409 | + short(f[:4])) | |
1411 |
|
1410 | |||
1412 | if base.keys() == [nullid]: |
|
1411 | if base.keys() == [nullid]: | |
1413 | if force: |
|
1412 | if force: | |
1414 | self.ui.warn(_("warning: repository is unrelated\n")) |
|
1413 | self.ui.warn(_("warning: repository is unrelated\n")) | |
1415 | else: |
|
1414 | else: | |
1416 | raise util.Abort(_("repository is unrelated")) |
|
1415 | raise util.Abort(_("repository is unrelated")) | |
1417 |
|
1416 | |||
1418 | self.ui.debug("found new changesets starting at " + |
|
1417 | self.ui.debug("found new changesets starting at " + | |
1419 | " ".join([short(f) for f in fetch]) + "\n") |
|
1418 | " ".join([short(f) for f in fetch]) + "\n") | |
1420 |
|
1419 | |||
1421 | self.ui.progress(_('searching'), None) |
|
1420 | self.ui.progress(_('searching'), None) | |
1422 | self.ui.debug("%d total queries\n" % reqcnt) |
|
1421 | self.ui.debug("%d total queries\n" % reqcnt) | |
1423 |
|
1422 | |||
1424 | return base.keys(), list(fetch), heads |
|
1423 | return base.keys(), list(fetch), heads | |
1425 |
|
1424 | |||
1426 | def findoutgoing(self, remote, base=None, heads=None, force=False): |
|
1425 | def findoutgoing(self, remote, base=None, heads=None, force=False): | |
1427 | """Return list of nodes that are roots of subsets not in remote |
|
1426 | """Return list of nodes that are roots of subsets not in remote | |
1428 |
|
1427 | |||
1429 | If base dict is specified, assume that these nodes and their parents |
|
1428 | If base dict is specified, assume that these nodes and their parents | |
1430 | exist on the remote side. |
|
1429 | exist on the remote side. | |
1431 | If a list of heads is specified, return only nodes which are heads |
|
1430 | If a list of heads is specified, return only nodes which are heads | |
1432 | or ancestors of these heads, and return a second element which |
|
1431 | or ancestors of these heads, and return a second element which | |
1433 | contains all remote heads which get new children. |
|
1432 | contains all remote heads which get new children. | |
1434 | """ |
|
1433 | """ | |
1435 | if base is None: |
|
1434 | if base is None: | |
1436 | base = {} |
|
1435 | base = {} | |
1437 | self.findincoming(remote, base, heads, force=force) |
|
1436 | self.findincoming(remote, base, heads, force=force) | |
1438 |
|
1437 | |||
1439 | self.ui.debug("common changesets up to " |
|
1438 | self.ui.debug("common changesets up to " | |
1440 | + " ".join(map(short, base.keys())) + "\n") |
|
1439 | + " ".join(map(short, base.keys())) + "\n") | |
1441 |
|
1440 | |||
1442 | remain = set(self.changelog.nodemap) |
|
1441 | remain = set(self.changelog.nodemap) | |
1443 |
|
1442 | |||
1444 | # prune everything remote has from the tree |
|
1443 | # prune everything remote has from the tree | |
1445 | remain.remove(nullid) |
|
1444 | remain.remove(nullid) | |
1446 | remove = base.keys() |
|
1445 | remove = base.keys() | |
1447 | while remove: |
|
1446 | while remove: | |
1448 | n = remove.pop(0) |
|
1447 | n = remove.pop(0) | |
1449 | if n in remain: |
|
1448 | if n in remain: | |
1450 | remain.remove(n) |
|
1449 | remain.remove(n) | |
1451 | for p in self.changelog.parents(n): |
|
1450 | for p in self.changelog.parents(n): | |
1452 | remove.append(p) |
|
1451 | remove.append(p) | |
1453 |
|
1452 | |||
1454 | # find every node whose parents have been pruned |
|
1453 | # find every node whose parents have been pruned | |
1455 | subset = [] |
|
1454 | subset = [] | |
1456 | # find every remote head that will get new children |
|
1455 | # find every remote head that will get new children | |
1457 | updated_heads = set() |
|
1456 | updated_heads = set() | |
1458 | for n in remain: |
|
1457 | for n in remain: | |
1459 | p1, p2 = self.changelog.parents(n) |
|
1458 | p1, p2 = self.changelog.parents(n) | |
1460 | if p1 not in remain and p2 not in remain: |
|
1459 | if p1 not in remain and p2 not in remain: | |
1461 | subset.append(n) |
|
1460 | subset.append(n) | |
1462 | if heads: |
|
1461 | if heads: | |
1463 | if p1 in heads: |
|
1462 | if p1 in heads: | |
1464 | updated_heads.add(p1) |
|
1463 | updated_heads.add(p1) | |
1465 | if p2 in heads: |
|
1464 | if p2 in heads: | |
1466 | updated_heads.add(p2) |
|
1465 | updated_heads.add(p2) | |
1467 |
|
1466 | |||
1468 | # this is the set of all roots we have to push |
|
1467 | # this is the set of all roots we have to push | |
1469 | if heads: |
|
1468 | if heads: | |
1470 | return subset, list(updated_heads) |
|
1469 | return subset, list(updated_heads) | |
1471 | else: |
|
1470 | else: | |
1472 | return subset |
|
1471 | return subset | |
1473 |
|
1472 | |||
1474 | def pull(self, remote, heads=None, force=False): |
|
1473 | def pull(self, remote, heads=None, force=False): | |
1475 | lock = self.lock() |
|
1474 | lock = self.lock() | |
1476 | try: |
|
1475 | try: | |
1477 | common, fetch, rheads = self.findcommonincoming(remote, heads=heads, |
|
1476 | common, fetch, rheads = self.findcommonincoming(remote, heads=heads, | |
1478 | force=force) |
|
1477 | force=force) | |
1479 | if not fetch: |
|
1478 | if not fetch: | |
1480 | self.ui.status(_("no changes found\n")) |
|
1479 | self.ui.status(_("no changes found\n")) | |
1481 | return 0 |
|
1480 | return 0 | |
1482 |
|
1481 | |||
1483 | if fetch == [nullid]: |
|
1482 | if fetch == [nullid]: | |
1484 | self.ui.status(_("requesting all changes\n")) |
|
1483 | self.ui.status(_("requesting all changes\n")) | |
1485 | elif heads is None and remote.capable('changegroupsubset'): |
|
1484 | elif heads is None and remote.capable('changegroupsubset'): | |
1486 | # issue1320, avoid a race if remote changed after discovery |
|
1485 | # issue1320, avoid a race if remote changed after discovery | |
1487 | heads = rheads |
|
1486 | heads = rheads | |
1488 |
|
1487 | |||
1489 | if heads is None: |
|
1488 | if heads is None: | |
1490 | cg = remote.changegroup(fetch, 'pull') |
|
1489 | cg = remote.changegroup(fetch, 'pull') | |
1491 | else: |
|
1490 | else: | |
1492 | if not remote.capable('changegroupsubset'): |
|
1491 | if not remote.capable('changegroupsubset'): | |
1493 | raise util.Abort(_("Partial pull cannot be done because " |
|
1492 | raise util.Abort(_("Partial pull cannot be done because " | |
1494 | "other repository doesn't support " |
|
1493 | "other repository doesn't support " | |
1495 | "changegroupsubset.")) |
|
1494 | "changegroupsubset.")) | |
1496 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
1495 | cg = remote.changegroupsubset(fetch, heads, 'pull') | |
1497 | return self.addchangegroup(cg, 'pull', remote.url()) |
|
1496 | return self.addchangegroup(cg, 'pull', remote.url()) | |
1498 | finally: |
|
1497 | finally: | |
1499 | lock.release() |
|
1498 | lock.release() | |
1500 |
|
1499 | |||
1501 | def push(self, remote, force=False, revs=None): |
|
1500 | def push(self, remote, force=False, revs=None): | |
1502 | # there are two ways to push to remote repo: |
|
1501 | # there are two ways to push to remote repo: | |
1503 | # |
|
1502 | # | |
1504 | # addchangegroup assumes local user can lock remote |
|
1503 | # addchangegroup assumes local user can lock remote | |
1505 | # repo (local filesystem, old ssh servers). |
|
1504 | # repo (local filesystem, old ssh servers). | |
1506 | # |
|
1505 | # | |
1507 | # unbundle assumes local user cannot lock remote repo (new ssh |
|
1506 | # unbundle assumes local user cannot lock remote repo (new ssh | |
1508 | # servers, http servers). |
|
1507 | # servers, http servers). | |
1509 |
|
1508 | |||
1510 | if remote.capable('unbundle'): |
|
1509 | if remote.capable('unbundle'): | |
1511 | return self.push_unbundle(remote, force, revs) |
|
1510 | return self.push_unbundle(remote, force, revs) | |
1512 | return self.push_addchangegroup(remote, force, revs) |
|
1511 | return self.push_addchangegroup(remote, force, revs) | |
1513 |
|
1512 | |||
1514 | def prepush(self, remote, force, revs): |
|
1513 | def prepush(self, remote, force, revs): | |
1515 | '''Analyze the local and remote repositories and determine which |
|
1514 | '''Analyze the local and remote repositories and determine which | |
1516 | changesets need to be pushed to the remote. Return a tuple |
|
1515 | changesets need to be pushed to the remote. Return a tuple | |
1517 | (changegroup, remoteheads). changegroup is a readable file-like |
|
1516 | (changegroup, remoteheads). changegroup is a readable file-like | |
1518 | object whose read() returns successive changegroup chunks ready to |
|
1517 | object whose read() returns successive changegroup chunks ready to | |
1519 | be sent over the wire. remoteheads is the list of remote heads. |
|
1518 | be sent over the wire. remoteheads is the list of remote heads. | |
1520 | ''' |
|
1519 | ''' | |
1521 | common = {} |
|
1520 | common = {} | |
1522 | remote_heads = remote.heads() |
|
1521 | remote_heads = remote.heads() | |
1523 | inc = self.findincoming(remote, common, remote_heads, force=force) |
|
1522 | inc = self.findincoming(remote, common, remote_heads, force=force) | |
1524 |
|
1523 | |||
1525 | cl = self.changelog |
|
1524 | cl = self.changelog | |
1526 | update, updated_heads = self.findoutgoing(remote, common, remote_heads) |
|
1525 | update, updated_heads = self.findoutgoing(remote, common, remote_heads) | |
1527 | outg, bases, heads = cl.nodesbetween(update, revs) |
|
1526 | outg, bases, heads = cl.nodesbetween(update, revs) | |
1528 |
|
1527 | |||
1529 | if not bases: |
|
1528 | if not bases: | |
1530 | self.ui.status(_("no changes found\n")) |
|
1529 | self.ui.status(_("no changes found\n")) | |
1531 | return None, 1 |
|
1530 | return None, 1 | |
1532 |
|
1531 | |||
1533 | if not force and remote_heads != [nullid]: |
|
1532 | if not force and remote_heads != [nullid]: | |
1534 |
|
1533 | |||
1535 | def fail_multiple_heads(unsynced, branch=None): |
|
1534 | def fail_multiple_heads(unsynced, branch=None): | |
1536 | if branch: |
|
1535 | if branch: | |
1537 | msg = _("abort: push creates new remote heads" |
|
1536 | msg = _("abort: push creates new remote heads" | |
1538 | " on branch '%s'!\n") % branch |
|
1537 | " on branch '%s'!\n") % branch | |
1539 | else: |
|
1538 | else: | |
1540 | msg = _("abort: push creates new remote heads!\n") |
|
1539 | msg = _("abort: push creates new remote heads!\n") | |
1541 | self.ui.warn(msg) |
|
1540 | self.ui.warn(msg) | |
1542 | if unsynced: |
|
1541 | if unsynced: | |
1543 | self.ui.status(_("(you should pull and merge or" |
|
1542 | self.ui.status(_("(you should pull and merge or" | |
1544 | " use push -f to force)\n")) |
|
1543 | " use push -f to force)\n")) | |
1545 | else: |
|
1544 | else: | |
1546 | self.ui.status(_("(did you forget to merge?" |
|
1545 | self.ui.status(_("(did you forget to merge?" | |
1547 | " use push -f to force)\n")) |
|
1546 | " use push -f to force)\n")) | |
1548 | return None, 0 |
|
1547 | return None, 0 | |
1549 |
|
1548 | |||
1550 | if remote.capable('branchmap'): |
|
1549 | if remote.capable('branchmap'): | |
1551 | # Check for each named branch if we're creating new remote heads. |
|
1550 | # Check for each named branch if we're creating new remote heads. | |
1552 | # To be a remote head after push, node must be either: |
|
1551 | # To be a remote head after push, node must be either: | |
1553 | # - unknown locally |
|
1552 | # - unknown locally | |
1554 | # - a local outgoing head descended from update |
|
1553 | # - a local outgoing head descended from update | |
1555 | # - a remote head that's known locally and not |
|
1554 | # - a remote head that's known locally and not | |
1556 | # ancestral to an outgoing head |
|
1555 | # ancestral to an outgoing head | |
1557 | # |
|
1556 | # | |
1558 | # New named branches cannot be created without --force. |
|
1557 | # New named branches cannot be created without --force. | |
1559 |
|
1558 | |||
1560 | # 1. Create set of branches involved in the push. |
|
1559 | # 1. Create set of branches involved in the push. | |
1561 | branches = set(self[n].branch() for n in outg) |
|
1560 | branches = set(self[n].branch() for n in outg) | |
1562 |
|
1561 | |||
1563 | # 2. Check for new branches on the remote. |
|
1562 | # 2. Check for new branches on the remote. | |
1564 | remotemap = remote.branchmap() |
|
1563 | remotemap = remote.branchmap() | |
1565 | newbranches = branches - set(remotemap) |
|
1564 | newbranches = branches - set(remotemap) | |
1566 | if newbranches: # new branch requires --force |
|
1565 | if newbranches: # new branch requires --force | |
1567 | branchnames = ', '.join("%s" % b for b in newbranches) |
|
1566 | branchnames = ', '.join("%s" % b for b in newbranches) | |
1568 | self.ui.warn(_("abort: push creates " |
|
1567 | self.ui.warn(_("abort: push creates " | |
1569 | "new remote branches: %s!\n") |
|
1568 | "new remote branches: %s!\n") | |
1570 | % branchnames) |
|
1569 | % branchnames) | |
1571 | self.ui.status(_("(use 'hg push -f' to force)\n")) |
|
1570 | self.ui.status(_("(use 'hg push -f' to force)\n")) | |
1572 | return None, 0 |
|
1571 | return None, 0 | |
1573 |
|
1572 | |||
1574 | # 3. Construct the initial oldmap and newmap dicts. |
|
1573 | # 3. Construct the initial oldmap and newmap dicts. | |
1575 | # They contain information about the remote heads before and |
|
1574 | # They contain information about the remote heads before and | |
1576 | # after the push, respectively. |
|
1575 | # after the push, respectively. | |
1577 | # Heads not found locally are not included in either dict, |
|
1576 | # Heads not found locally are not included in either dict, | |
1578 | # since they won't be affected by the push. |
|
1577 | # since they won't be affected by the push. | |
1579 | # unsynced contains all branches with incoming changesets. |
|
1578 | # unsynced contains all branches with incoming changesets. | |
1580 | oldmap = {} |
|
1579 | oldmap = {} | |
1581 | newmap = {} |
|
1580 | newmap = {} | |
1582 | unsynced = set() |
|
1581 | unsynced = set() | |
1583 | for branch in branches: |
|
1582 | for branch in branches: | |
1584 | remoteheads = remotemap[branch] |
|
1583 | remoteheads = remotemap[branch] | |
1585 | prunedheads = [h for h in remoteheads if h in cl.nodemap] |
|
1584 | prunedheads = [h for h in remoteheads if h in cl.nodemap] | |
1586 | oldmap[branch] = prunedheads |
|
1585 | oldmap[branch] = prunedheads | |
1587 | newmap[branch] = list(prunedheads) |
|
1586 | newmap[branch] = list(prunedheads) | |
1588 | if len(remoteheads) > len(prunedheads): |
|
1587 | if len(remoteheads) > len(prunedheads): | |
1589 | unsynced.add(branch) |
|
1588 | unsynced.add(branch) | |
1590 |
|
1589 | |||
1591 | # 4. Update newmap with outgoing changes. |
|
1590 | # 4. Update newmap with outgoing changes. | |
1592 | # This will possibly add new heads and remove existing ones. |
|
1591 | # This will possibly add new heads and remove existing ones. | |
1593 | ctxgen = (self[n] for n in outg) |
|
1592 | ctxgen = (self[n] for n in outg) | |
1594 | self._updatebranchcache(newmap, ctxgen) |
|
1593 | self._updatebranchcache(newmap, ctxgen) | |
1595 |
|
1594 | |||
1596 | # 5. Check for new heads. |
|
1595 | # 5. Check for new heads. | |
1597 | # If there are more heads after the push than before, a suitable |
|
1596 | # If there are more heads after the push than before, a suitable | |
1598 | # warning, depending on unsynced status, is displayed. |
|
1597 | # warning, depending on unsynced status, is displayed. | |
1599 | for branch in branches: |
|
1598 | for branch in branches: | |
1600 | if len(newmap[branch]) > len(oldmap[branch]): |
|
1599 | if len(newmap[branch]) > len(oldmap[branch]): | |
1601 | return fail_multiple_heads(branch in unsynced, branch) |
|
1600 | return fail_multiple_heads(branch in unsynced, branch) | |
1602 |
|
1601 | |||
1603 | # 6. Check for unsynced changes on involved branches. |
|
1602 | # 6. Check for unsynced changes on involved branches. | |
1604 | if unsynced: |
|
1603 | if unsynced: | |
1605 | self.ui.warn(_("note: unsynced remote changes!\n")) |
|
1604 | self.ui.warn(_("note: unsynced remote changes!\n")) | |
1606 |
|
1605 | |||
1607 | else: |
|
1606 | else: | |
1608 | # Old servers: Check for new topological heads. |
|
1607 | # Old servers: Check for new topological heads. | |
1609 | # Code based on _updatebranchcache. |
|
1608 | # Code based on _updatebranchcache. | |
1610 | newheads = set(h for h in remote_heads if h in cl.nodemap) |
|
1609 | newheads = set(h for h in remote_heads if h in cl.nodemap) | |
1611 | oldheadcnt = len(newheads) |
|
1610 | oldheadcnt = len(newheads) | |
1612 | newheads.update(outg) |
|
1611 | newheads.update(outg) | |
1613 | if len(newheads) > 1: |
|
1612 | if len(newheads) > 1: | |
1614 | for latest in reversed(outg): |
|
1613 | for latest in reversed(outg): | |
1615 | if latest not in newheads: |
|
1614 | if latest not in newheads: | |
1616 | continue |
|
1615 | continue | |
1617 | minhrev = min(cl.rev(h) for h in newheads) |
|
1616 | minhrev = min(cl.rev(h) for h in newheads) | |
1618 | reachable = cl.reachable(latest, cl.node(minhrev)) |
|
1617 | reachable = cl.reachable(latest, cl.node(minhrev)) | |
1619 | reachable.remove(latest) |
|
1618 | reachable.remove(latest) | |
1620 | newheads.difference_update(reachable) |
|
1619 | newheads.difference_update(reachable) | |
1621 | if len(newheads) > oldheadcnt: |
|
1620 | if len(newheads) > oldheadcnt: | |
1622 | return fail_multiple_heads(inc) |
|
1621 | return fail_multiple_heads(inc) | |
1623 | if inc: |
|
1622 | if inc: | |
1624 | self.ui.warn(_("note: unsynced remote changes!\n")) |
|
1623 | self.ui.warn(_("note: unsynced remote changes!\n")) | |
1625 |
|
1624 | |||
1626 | if revs is None: |
|
1625 | if revs is None: | |
1627 | # use the fast path, no race possible on push |
|
1626 | # use the fast path, no race possible on push | |
1628 | nodes = self.changelog.findmissing(common.keys()) |
|
1627 | nodes = self.changelog.findmissing(common.keys()) | |
1629 | cg = self._changegroup(nodes, 'push') |
|
1628 | cg = self._changegroup(nodes, 'push') | |
1630 | else: |
|
1629 | else: | |
1631 | cg = self.changegroupsubset(update, revs, 'push') |
|
1630 | cg = self.changegroupsubset(update, revs, 'push') | |
1632 | return cg, remote_heads |
|
1631 | return cg, remote_heads | |
1633 |
|
1632 | |||
1634 | def push_addchangegroup(self, remote, force, revs): |
|
1633 | def push_addchangegroup(self, remote, force, revs): | |
1635 | lock = remote.lock() |
|
1634 | lock = remote.lock() | |
1636 | try: |
|
1635 | try: | |
1637 | ret = self.prepush(remote, force, revs) |
|
1636 | ret = self.prepush(remote, force, revs) | |
1638 | if ret[0] is not None: |
|
1637 | if ret[0] is not None: | |
1639 | cg, remote_heads = ret |
|
1638 | cg, remote_heads = ret | |
1640 | return remote.addchangegroup(cg, 'push', self.url()) |
|
1639 | return remote.addchangegroup(cg, 'push', self.url()) | |
1641 | return ret[1] |
|
1640 | return ret[1] | |
1642 | finally: |
|
1641 | finally: | |
1643 | lock.release() |
|
1642 | lock.release() | |
1644 |
|
1643 | |||
1645 | def push_unbundle(self, remote, force, revs): |
|
1644 | def push_unbundle(self, remote, force, revs): | |
1646 | # local repo finds heads on server, finds out what revs it |
|
1645 | # local repo finds heads on server, finds out what revs it | |
1647 | # must push. once revs transferred, if server finds it has |
|
1646 | # must push. once revs transferred, if server finds it has | |
1648 | # different heads (someone else won commit/push race), server |
|
1647 | # different heads (someone else won commit/push race), server | |
1649 | # aborts. |
|
1648 | # aborts. | |
1650 |
|
1649 | |||
1651 | ret = self.prepush(remote, force, revs) |
|
1650 | ret = self.prepush(remote, force, revs) | |
1652 | if ret[0] is not None: |
|
1651 | if ret[0] is not None: | |
1653 | cg, remote_heads = ret |
|
1652 | cg, remote_heads = ret | |
1654 | if force: |
|
1653 | if force: | |
1655 | remote_heads = ['force'] |
|
1654 | remote_heads = ['force'] | |
1656 | return remote.unbundle(cg, remote_heads, 'push') |
|
1655 | return remote.unbundle(cg, remote_heads, 'push') | |
1657 | return ret[1] |
|
1656 | return ret[1] | |
1658 |
|
1657 | |||
1659 | def changegroupinfo(self, nodes, source): |
|
1658 | def changegroupinfo(self, nodes, source): | |
1660 | if self.ui.verbose or source == 'bundle': |
|
1659 | if self.ui.verbose or source == 'bundle': | |
1661 | self.ui.status(_("%d changesets found\n") % len(nodes)) |
|
1660 | self.ui.status(_("%d changesets found\n") % len(nodes)) | |
1662 | if self.ui.debugflag: |
|
1661 | if self.ui.debugflag: | |
1663 | self.ui.debug("list of changesets:\n") |
|
1662 | self.ui.debug("list of changesets:\n") | |
1664 | for node in nodes: |
|
1663 | for node in nodes: | |
1665 | self.ui.debug("%s\n" % hex(node)) |
|
1664 | self.ui.debug("%s\n" % hex(node)) | |
1666 |
|
1665 | |||
1667 | def changegroupsubset(self, bases, heads, source, extranodes=None): |
|
1666 | def changegroupsubset(self, bases, heads, source, extranodes=None): | |
1668 | """Compute a changegroup consisting of all the nodes that are |
|
1667 | """Compute a changegroup consisting of all the nodes that are | |
1669 | descendents of any of the bases and ancestors of any of the heads. |
|
1668 | descendents of any of the bases and ancestors of any of the heads. | |
1670 | Return a chunkbuffer object whose read() method will return |
|
1669 | Return a chunkbuffer object whose read() method will return | |
1671 | successive changegroup chunks. |
|
1670 | successive changegroup chunks. | |
1672 |
|
1671 | |||
1673 | It is fairly complex as determining which filenodes and which |
|
1672 | It is fairly complex as determining which filenodes and which | |
1674 | manifest nodes need to be included for the changeset to be complete |
|
1673 | manifest nodes need to be included for the changeset to be complete | |
1675 | is non-trivial. |
|
1674 | is non-trivial. | |
1676 |
|
1675 | |||
1677 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1676 | Another wrinkle is doing the reverse, figuring out which changeset in | |
1678 | the changegroup a particular filenode or manifestnode belongs to. |
|
1677 | the changegroup a particular filenode or manifestnode belongs to. | |
1679 |
|
1678 | |||
1680 | The caller can specify some nodes that must be included in the |
|
1679 | The caller can specify some nodes that must be included in the | |
1681 | changegroup using the extranodes argument. It should be a dict |
|
1680 | changegroup using the extranodes argument. It should be a dict | |
1682 | where the keys are the filenames (or 1 for the manifest), and the |
|
1681 | where the keys are the filenames (or 1 for the manifest), and the | |
1683 | values are lists of (node, linknode) tuples, where node is a wanted |
|
1682 | values are lists of (node, linknode) tuples, where node is a wanted | |
1684 | node and linknode is the changelog node that should be transmitted as |
|
1683 | node and linknode is the changelog node that should be transmitted as | |
1685 | the linkrev. |
|
1684 | the linkrev. | |
1686 | """ |
|
1685 | """ | |
1687 |
|
1686 | |||
1688 | # Set up some initial variables |
|
1687 | # Set up some initial variables | |
1689 | # Make it easy to refer to self.changelog |
|
1688 | # Make it easy to refer to self.changelog | |
1690 | cl = self.changelog |
|
1689 | cl = self.changelog | |
1691 | # msng is short for missing - compute the list of changesets in this |
|
1690 | # msng is short for missing - compute the list of changesets in this | |
1692 | # changegroup. |
|
1691 | # changegroup. | |
1693 | if not bases: |
|
1692 | if not bases: | |
1694 | bases = [nullid] |
|
1693 | bases = [nullid] | |
1695 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) |
|
1694 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) | |
1696 |
|
1695 | |||
1697 | if extranodes is None: |
|
1696 | if extranodes is None: | |
1698 | # can we go through the fast path ? |
|
1697 | # can we go through the fast path ? | |
1699 | heads.sort() |
|
1698 | heads.sort() | |
1700 | allheads = self.heads() |
|
1699 | allheads = self.heads() | |
1701 | allheads.sort() |
|
1700 | allheads.sort() | |
1702 | if heads == allheads: |
|
1701 | if heads == allheads: | |
1703 | return self._changegroup(msng_cl_lst, source) |
|
1702 | return self._changegroup(msng_cl_lst, source) | |
1704 |
|
1703 | |||
1705 | # slow path |
|
1704 | # slow path | |
1706 | self.hook('preoutgoing', throw=True, source=source) |
|
1705 | self.hook('preoutgoing', throw=True, source=source) | |
1707 |
|
1706 | |||
1708 | self.changegroupinfo(msng_cl_lst, source) |
|
1707 | self.changegroupinfo(msng_cl_lst, source) | |
1709 | # Some bases may turn out to be superfluous, and some heads may be |
|
1708 | # Some bases may turn out to be superfluous, and some heads may be | |
1710 | # too. nodesbetween will return the minimal set of bases and heads |
|
1709 | # too. nodesbetween will return the minimal set of bases and heads | |
1711 | # necessary to re-create the changegroup. |
|
1710 | # necessary to re-create the changegroup. | |
1712 |
|
1711 | |||
1713 | # Known heads are the list of heads that it is assumed the recipient |
|
1712 | # Known heads are the list of heads that it is assumed the recipient | |
1714 | # of this changegroup will know about. |
|
1713 | # of this changegroup will know about. | |
1715 | knownheads = set() |
|
1714 | knownheads = set() | |
1716 | # We assume that all parents of bases are known heads. |
|
1715 | # We assume that all parents of bases are known heads. | |
1717 | for n in bases: |
|
1716 | for n in bases: | |
1718 | knownheads.update(cl.parents(n)) |
|
1717 | knownheads.update(cl.parents(n)) | |
1719 | knownheads.discard(nullid) |
|
1718 | knownheads.discard(nullid) | |
1720 | knownheads = list(knownheads) |
|
1719 | knownheads = list(knownheads) | |
1721 | if knownheads: |
|
1720 | if knownheads: | |
1722 | # Now that we know what heads are known, we can compute which |
|
1721 | # Now that we know what heads are known, we can compute which | |
1723 | # changesets are known. The recipient must know about all |
|
1722 | # changesets are known. The recipient must know about all | |
1724 | # changesets required to reach the known heads from the null |
|
1723 | # changesets required to reach the known heads from the null | |
1725 | # changeset. |
|
1724 | # changeset. | |
1726 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) |
|
1725 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) | |
1727 | junk = None |
|
1726 | junk = None | |
1728 | # Transform the list into a set. |
|
1727 | # Transform the list into a set. | |
1729 | has_cl_set = set(has_cl_set) |
|
1728 | has_cl_set = set(has_cl_set) | |
1730 | else: |
|
1729 | else: | |
1731 | # If there were no known heads, the recipient cannot be assumed to |
|
1730 | # If there were no known heads, the recipient cannot be assumed to | |
1732 | # know about any changesets. |
|
1731 | # know about any changesets. | |
1733 | has_cl_set = set() |
|
1732 | has_cl_set = set() | |
1734 |
|
1733 | |||
1735 | # Make it easy to refer to self.manifest |
|
1734 | # Make it easy to refer to self.manifest | |
1736 | mnfst = self.manifest |
|
1735 | mnfst = self.manifest | |
1737 | # We don't know which manifests are missing yet |
|
1736 | # We don't know which manifests are missing yet | |
1738 | msng_mnfst_set = {} |
|
1737 | msng_mnfst_set = {} | |
1739 | # Nor do we know which filenodes are missing. |
|
1738 | # Nor do we know which filenodes are missing. | |
1740 | msng_filenode_set = {} |
|
1739 | msng_filenode_set = {} | |
1741 |
|
1740 | |||
1742 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex |
|
1741 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex | |
1743 | junk = None |
|
1742 | junk = None | |
1744 |
|
1743 | |||
1745 | # A changeset always belongs to itself, so the changenode lookup |
|
1744 | # A changeset always belongs to itself, so the changenode lookup | |
1746 | # function for a changenode is identity. |
|
1745 | # function for a changenode is identity. | |
1747 | def identity(x): |
|
1746 | def identity(x): | |
1748 | return x |
|
1747 | return x | |
1749 |
|
1748 | |||
1750 | # If we determine that a particular file or manifest node must be a |
|
1749 | # If we determine that a particular file or manifest node must be a | |
1751 | # node that the recipient of the changegroup will already have, we can |
|
1750 | # node that the recipient of the changegroup will already have, we can | |
1752 | # also assume the recipient will have all the parents. This function |
|
1751 | # also assume the recipient will have all the parents. This function | |
1753 | # prunes them from the set of missing nodes. |
|
1752 | # prunes them from the set of missing nodes. | |
1754 | def prune_parents(revlog, hasset, msngset): |
|
1753 | def prune_parents(revlog, hasset, msngset): | |
1755 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): |
|
1754 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): | |
1756 | msngset.pop(revlog.node(r), None) |
|
1755 | msngset.pop(revlog.node(r), None) | |
1757 |
|
1756 | |||
1758 | # Use the information collected in collect_manifests_and_files to say |
|
1757 | # Use the information collected in collect_manifests_and_files to say | |
1759 | # which changenode any manifestnode belongs to. |
|
1758 | # which changenode any manifestnode belongs to. | |
1760 | def lookup_manifest_link(mnfstnode): |
|
1759 | def lookup_manifest_link(mnfstnode): | |
1761 | return msng_mnfst_set[mnfstnode] |
|
1760 | return msng_mnfst_set[mnfstnode] | |
1762 |
|
1761 | |||
1763 | # A function generating function that sets up the initial environment |
|
1762 | # A function generating function that sets up the initial environment | |
1764 | # the inner function. |
|
1763 | # the inner function. | |
1765 | def filenode_collector(changedfiles): |
|
1764 | def filenode_collector(changedfiles): | |
1766 | # This gathers information from each manifestnode included in the |
|
1765 | # This gathers information from each manifestnode included in the | |
1767 | # changegroup about which filenodes the manifest node references |
|
1766 | # changegroup about which filenodes the manifest node references | |
1768 | # so we can include those in the changegroup too. |
|
1767 | # so we can include those in the changegroup too. | |
1769 | # |
|
1768 | # | |
1770 | # It also remembers which changenode each filenode belongs to. It |
|
1769 | # It also remembers which changenode each filenode belongs to. It | |
1771 | # does this by assuming the a filenode belongs to the changenode |
|
1770 | # does this by assuming the a filenode belongs to the changenode | |
1772 | # the first manifest that references it belongs to. |
|
1771 | # the first manifest that references it belongs to. | |
1773 | def collect_msng_filenodes(mnfstnode): |
|
1772 | def collect_msng_filenodes(mnfstnode): | |
1774 | r = mnfst.rev(mnfstnode) |
|
1773 | r = mnfst.rev(mnfstnode) | |
1775 | if r - 1 in mnfst.parentrevs(r): |
|
1774 | if r - 1 in mnfst.parentrevs(r): | |
1776 | # If the previous rev is one of the parents, |
|
1775 | # If the previous rev is one of the parents, | |
1777 | # we only need to see a diff. |
|
1776 | # we only need to see a diff. | |
1778 | deltamf = mnfst.readdelta(mnfstnode) |
|
1777 | deltamf = mnfst.readdelta(mnfstnode) | |
1779 | # For each line in the delta |
|
1778 | # For each line in the delta | |
1780 | for f, fnode in deltamf.iteritems(): |
|
1779 | for f, fnode in deltamf.iteritems(): | |
1781 | f = changedfiles.get(f, None) |
|
1780 | f = changedfiles.get(f, None) | |
1782 | # And if the file is in the list of files we care |
|
1781 | # And if the file is in the list of files we care | |
1783 | # about. |
|
1782 | # about. | |
1784 | if f is not None: |
|
1783 | if f is not None: | |
1785 | # Get the changenode this manifest belongs to |
|
1784 | # Get the changenode this manifest belongs to | |
1786 | clnode = msng_mnfst_set[mnfstnode] |
|
1785 | clnode = msng_mnfst_set[mnfstnode] | |
1787 | # Create the set of filenodes for the file if |
|
1786 | # Create the set of filenodes for the file if | |
1788 | # there isn't one already. |
|
1787 | # there isn't one already. | |
1789 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1788 | ndset = msng_filenode_set.setdefault(f, {}) | |
1790 | # And set the filenode's changelog node to the |
|
1789 | # And set the filenode's changelog node to the | |
1791 | # manifest's if it hasn't been set already. |
|
1790 | # manifest's if it hasn't been set already. | |
1792 | ndset.setdefault(fnode, clnode) |
|
1791 | ndset.setdefault(fnode, clnode) | |
1793 | else: |
|
1792 | else: | |
1794 | # Otherwise we need a full manifest. |
|
1793 | # Otherwise we need a full manifest. | |
1795 | m = mnfst.read(mnfstnode) |
|
1794 | m = mnfst.read(mnfstnode) | |
1796 | # For every file in we care about. |
|
1795 | # For every file in we care about. | |
1797 | for f in changedfiles: |
|
1796 | for f in changedfiles: | |
1798 | fnode = m.get(f, None) |
|
1797 | fnode = m.get(f, None) | |
1799 | # If it's in the manifest |
|
1798 | # If it's in the manifest | |
1800 | if fnode is not None: |
|
1799 | if fnode is not None: | |
1801 | # See comments above. |
|
1800 | # See comments above. | |
1802 | clnode = msng_mnfst_set[mnfstnode] |
|
1801 | clnode = msng_mnfst_set[mnfstnode] | |
1803 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1802 | ndset = msng_filenode_set.setdefault(f, {}) | |
1804 | ndset.setdefault(fnode, clnode) |
|
1803 | ndset.setdefault(fnode, clnode) | |
1805 | return collect_msng_filenodes |
|
1804 | return collect_msng_filenodes | |
1806 |
|
1805 | |||
1807 | # We have a list of filenodes we think we need for a file, lets remove |
|
1806 | # We have a list of filenodes we think we need for a file, lets remove | |
1808 | # all those we know the recipient must have. |
|
1807 | # all those we know the recipient must have. | |
1809 | def prune_filenodes(f, filerevlog): |
|
1808 | def prune_filenodes(f, filerevlog): | |
1810 | msngset = msng_filenode_set[f] |
|
1809 | msngset = msng_filenode_set[f] | |
1811 | hasset = set() |
|
1810 | hasset = set() | |
1812 | # If a 'missing' filenode thinks it belongs to a changenode we |
|
1811 | # If a 'missing' filenode thinks it belongs to a changenode we | |
1813 | # assume the recipient must have, then the recipient must have |
|
1812 | # assume the recipient must have, then the recipient must have | |
1814 | # that filenode. |
|
1813 | # that filenode. | |
1815 | for n in msngset: |
|
1814 | for n in msngset: | |
1816 | clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) |
|
1815 | clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) | |
1817 | if clnode in has_cl_set: |
|
1816 | if clnode in has_cl_set: | |
1818 | hasset.add(n) |
|
1817 | hasset.add(n) | |
1819 | prune_parents(filerevlog, hasset, msngset) |
|
1818 | prune_parents(filerevlog, hasset, msngset) | |
1820 |
|
1819 | |||
1821 | # A function generator function that sets up the a context for the |
|
1820 | # A function generator function that sets up the a context for the | |
1822 | # inner function. |
|
1821 | # inner function. | |
1823 | def lookup_filenode_link_func(fname): |
|
1822 | def lookup_filenode_link_func(fname): | |
1824 | msngset = msng_filenode_set[fname] |
|
1823 | msngset = msng_filenode_set[fname] | |
1825 | # Lookup the changenode the filenode belongs to. |
|
1824 | # Lookup the changenode the filenode belongs to. | |
1826 | def lookup_filenode_link(fnode): |
|
1825 | def lookup_filenode_link(fnode): | |
1827 | return msngset[fnode] |
|
1826 | return msngset[fnode] | |
1828 | return lookup_filenode_link |
|
1827 | return lookup_filenode_link | |
1829 |
|
1828 | |||
1830 | # Add the nodes that were explicitly requested. |
|
1829 | # Add the nodes that were explicitly requested. | |
1831 | def add_extra_nodes(name, nodes): |
|
1830 | def add_extra_nodes(name, nodes): | |
1832 | if not extranodes or name not in extranodes: |
|
1831 | if not extranodes or name not in extranodes: | |
1833 | return |
|
1832 | return | |
1834 |
|
1833 | |||
1835 | for node, linknode in extranodes[name]: |
|
1834 | for node, linknode in extranodes[name]: | |
1836 | if node not in nodes: |
|
1835 | if node not in nodes: | |
1837 | nodes[node] = linknode |
|
1836 | nodes[node] = linknode | |
1838 |
|
1837 | |||
1839 | # Now that we have all theses utility functions to help out and |
|
1838 | # Now that we have all theses utility functions to help out and | |
1840 | # logically divide up the task, generate the group. |
|
1839 | # logically divide up the task, generate the group. | |
1841 | def gengroup(): |
|
1840 | def gengroup(): | |
1842 | # The set of changed files starts empty. |
|
1841 | # The set of changed files starts empty. | |
1843 | changedfiles = {} |
|
1842 | changedfiles = {} | |
1844 | collect = changegroup.collector(cl, msng_mnfst_set, changedfiles) |
|
1843 | collect = changegroup.collector(cl, msng_mnfst_set, changedfiles) | |
1845 |
|
1844 | |||
1846 | # Create a changenode group generator that will call our functions |
|
1845 | # Create a changenode group generator that will call our functions | |
1847 | # back to lookup the owning changenode and collect information. |
|
1846 | # back to lookup the owning changenode and collect information. | |
1848 | group = cl.group(msng_cl_lst, identity, collect) |
|
1847 | group = cl.group(msng_cl_lst, identity, collect) | |
1849 | cnt = 0 |
|
1848 | cnt = 0 | |
1850 | for chnk in group: |
|
1849 | for chnk in group: | |
1851 | yield chnk |
|
1850 | yield chnk | |
1852 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) |
|
1851 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) | |
1853 | cnt += 1 |
|
1852 | cnt += 1 | |
1854 | self.ui.progress(_('bundling changes'), None) |
|
1853 | self.ui.progress(_('bundling changes'), None) | |
1855 |
|
1854 | |||
1856 |
|
1855 | |||
1857 | # Figure out which manifest nodes (of the ones we think might be |
|
1856 | # Figure out which manifest nodes (of the ones we think might be | |
1858 | # part of the changegroup) the recipient must know about and |
|
1857 | # part of the changegroup) the recipient must know about and | |
1859 | # remove them from the changegroup. |
|
1858 | # remove them from the changegroup. | |
1860 | has_mnfst_set = set() |
|
1859 | has_mnfst_set = set() | |
1861 | for n in msng_mnfst_set: |
|
1860 | for n in msng_mnfst_set: | |
1862 | # If a 'missing' manifest thinks it belongs to a changenode |
|
1861 | # If a 'missing' manifest thinks it belongs to a changenode | |
1863 | # the recipient is assumed to have, obviously the recipient |
|
1862 | # the recipient is assumed to have, obviously the recipient | |
1864 | # must have that manifest. |
|
1863 | # must have that manifest. | |
1865 | linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) |
|
1864 | linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) | |
1866 | if linknode in has_cl_set: |
|
1865 | if linknode in has_cl_set: | |
1867 | has_mnfst_set.add(n) |
|
1866 | has_mnfst_set.add(n) | |
1868 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) |
|
1867 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) | |
1869 | add_extra_nodes(1, msng_mnfst_set) |
|
1868 | add_extra_nodes(1, msng_mnfst_set) | |
1870 | msng_mnfst_lst = msng_mnfst_set.keys() |
|
1869 | msng_mnfst_lst = msng_mnfst_set.keys() | |
1871 | # Sort the manifestnodes by revision number. |
|
1870 | # Sort the manifestnodes by revision number. | |
1872 | msng_mnfst_lst.sort(key=mnfst.rev) |
|
1871 | msng_mnfst_lst.sort(key=mnfst.rev) | |
1873 | # Create a generator for the manifestnodes that calls our lookup |
|
1872 | # Create a generator for the manifestnodes that calls our lookup | |
1874 | # and data collection functions back. |
|
1873 | # and data collection functions back. | |
1875 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, |
|
1874 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, | |
1876 | filenode_collector(changedfiles)) |
|
1875 | filenode_collector(changedfiles)) | |
1877 | cnt = 0 |
|
1876 | cnt = 0 | |
1878 | for chnk in group: |
|
1877 | for chnk in group: | |
1879 | yield chnk |
|
1878 | yield chnk | |
1880 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) |
|
1879 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) | |
1881 | cnt += 1 |
|
1880 | cnt += 1 | |
1882 | self.ui.progress(_('bundling manifests'), None) |
|
1881 | self.ui.progress(_('bundling manifests'), None) | |
1883 |
|
1882 | |||
1884 | # These are no longer needed, dereference and toss the memory for |
|
1883 | # These are no longer needed, dereference and toss the memory for | |
1885 | # them. |
|
1884 | # them. | |
1886 | msng_mnfst_lst = None |
|
1885 | msng_mnfst_lst = None | |
1887 | msng_mnfst_set.clear() |
|
1886 | msng_mnfst_set.clear() | |
1888 |
|
1887 | |||
1889 | if extranodes: |
|
1888 | if extranodes: | |
1890 | for fname in extranodes: |
|
1889 | for fname in extranodes: | |
1891 | if isinstance(fname, int): |
|
1890 | if isinstance(fname, int): | |
1892 | continue |
|
1891 | continue | |
1893 | msng_filenode_set.setdefault(fname, {}) |
|
1892 | msng_filenode_set.setdefault(fname, {}) | |
1894 | changedfiles[fname] = 1 |
|
1893 | changedfiles[fname] = 1 | |
1895 | # Go through all our files in order sorted by name. |
|
1894 | # Go through all our files in order sorted by name. | |
1896 | cnt = 0 |
|
1895 | cnt = 0 | |
1897 | for fname in sorted(changedfiles): |
|
1896 | for fname in sorted(changedfiles): | |
1898 | filerevlog = self.file(fname) |
|
1897 | filerevlog = self.file(fname) | |
1899 | if not len(filerevlog): |
|
1898 | if not len(filerevlog): | |
1900 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1899 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1901 | # Toss out the filenodes that the recipient isn't really |
|
1900 | # Toss out the filenodes that the recipient isn't really | |
1902 | # missing. |
|
1901 | # missing. | |
1903 | if fname in msng_filenode_set: |
|
1902 | if fname in msng_filenode_set: | |
1904 | prune_filenodes(fname, filerevlog) |
|
1903 | prune_filenodes(fname, filerevlog) | |
1905 | add_extra_nodes(fname, msng_filenode_set[fname]) |
|
1904 | add_extra_nodes(fname, msng_filenode_set[fname]) | |
1906 | msng_filenode_lst = msng_filenode_set[fname].keys() |
|
1905 | msng_filenode_lst = msng_filenode_set[fname].keys() | |
1907 | else: |
|
1906 | else: | |
1908 | msng_filenode_lst = [] |
|
1907 | msng_filenode_lst = [] | |
1909 | # If any filenodes are left, generate the group for them, |
|
1908 | # If any filenodes are left, generate the group for them, | |
1910 | # otherwise don't bother. |
|
1909 | # otherwise don't bother. | |
1911 | if len(msng_filenode_lst) > 0: |
|
1910 | if len(msng_filenode_lst) > 0: | |
1912 | yield changegroup.chunkheader(len(fname)) |
|
1911 | yield changegroup.chunkheader(len(fname)) | |
1913 | yield fname |
|
1912 | yield fname | |
1914 | # Sort the filenodes by their revision # |
|
1913 | # Sort the filenodes by their revision # | |
1915 | msng_filenode_lst.sort(key=filerevlog.rev) |
|
1914 | msng_filenode_lst.sort(key=filerevlog.rev) | |
1916 | # Create a group generator and only pass in a changenode |
|
1915 | # Create a group generator and only pass in a changenode | |
1917 | # lookup function as we need to collect no information |
|
1916 | # lookup function as we need to collect no information | |
1918 | # from filenodes. |
|
1917 | # from filenodes. | |
1919 | group = filerevlog.group(msng_filenode_lst, |
|
1918 | group = filerevlog.group(msng_filenode_lst, | |
1920 | lookup_filenode_link_func(fname)) |
|
1919 | lookup_filenode_link_func(fname)) | |
1921 | for chnk in group: |
|
1920 | for chnk in group: | |
1922 | self.ui.progress( |
|
1921 | self.ui.progress( | |
1923 | _('bundling files'), cnt, item=fname, unit=_('chunks')) |
|
1922 | _('bundling files'), cnt, item=fname, unit=_('chunks')) | |
1924 | cnt += 1 |
|
1923 | cnt += 1 | |
1925 | yield chnk |
|
1924 | yield chnk | |
1926 | if fname in msng_filenode_set: |
|
1925 | if fname in msng_filenode_set: | |
1927 | # Don't need this anymore, toss it to free memory. |
|
1926 | # Don't need this anymore, toss it to free memory. | |
1928 | del msng_filenode_set[fname] |
|
1927 | del msng_filenode_set[fname] | |
1929 | # Signal that no more groups are left. |
|
1928 | # Signal that no more groups are left. | |
1930 | yield changegroup.closechunk() |
|
1929 | yield changegroup.closechunk() | |
1931 | self.ui.progress(_('bundling files'), None) |
|
1930 | self.ui.progress(_('bundling files'), None) | |
1932 |
|
1931 | |||
1933 | if msng_cl_lst: |
|
1932 | if msng_cl_lst: | |
1934 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) |
|
1933 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) | |
1935 |
|
1934 | |||
1936 | return util.chunkbuffer(gengroup()) |
|
1935 | return util.chunkbuffer(gengroup()) | |
1937 |
|
1936 | |||
1938 | def changegroup(self, basenodes, source): |
|
1937 | def changegroup(self, basenodes, source): | |
1939 | # to avoid a race we use changegroupsubset() (issue1320) |
|
1938 | # to avoid a race we use changegroupsubset() (issue1320) | |
1940 | return self.changegroupsubset(basenodes, self.heads(), source) |
|
1939 | return self.changegroupsubset(basenodes, self.heads(), source) | |
1941 |
|
1940 | |||
1942 | def _changegroup(self, nodes, source): |
|
1941 | def _changegroup(self, nodes, source): | |
1943 | """Compute the changegroup of all nodes that we have that a recipient |
|
1942 | """Compute the changegroup of all nodes that we have that a recipient | |
1944 | doesn't. Return a chunkbuffer object whose read() method will return |
|
1943 | doesn't. Return a chunkbuffer object whose read() method will return | |
1945 | successive changegroup chunks. |
|
1944 | successive changegroup chunks. | |
1946 |
|
1945 | |||
1947 | This is much easier than the previous function as we can assume that |
|
1946 | This is much easier than the previous function as we can assume that | |
1948 | the recipient has any changenode we aren't sending them. |
|
1947 | the recipient has any changenode we aren't sending them. | |
1949 |
|
1948 | |||
1950 | nodes is the set of nodes to send""" |
|
1949 | nodes is the set of nodes to send""" | |
1951 |
|
1950 | |||
1952 | self.hook('preoutgoing', throw=True, source=source) |
|
1951 | self.hook('preoutgoing', throw=True, source=source) | |
1953 |
|
1952 | |||
1954 | cl = self.changelog |
|
1953 | cl = self.changelog | |
1955 | revset = set([cl.rev(n) for n in nodes]) |
|
1954 | revset = set([cl.rev(n) for n in nodes]) | |
1956 | self.changegroupinfo(nodes, source) |
|
1955 | self.changegroupinfo(nodes, source) | |
1957 |
|
1956 | |||
1958 | def identity(x): |
|
1957 | def identity(x): | |
1959 | return x |
|
1958 | return x | |
1960 |
|
1959 | |||
1961 | def gennodelst(log): |
|
1960 | def gennodelst(log): | |
1962 | for r in log: |
|
1961 | for r in log: | |
1963 | if log.linkrev(r) in revset: |
|
1962 | if log.linkrev(r) in revset: | |
1964 | yield log.node(r) |
|
1963 | yield log.node(r) | |
1965 |
|
1964 | |||
1966 | def lookuprevlink_func(revlog): |
|
1965 | def lookuprevlink_func(revlog): | |
1967 | def lookuprevlink(n): |
|
1966 | def lookuprevlink(n): | |
1968 | return cl.node(revlog.linkrev(revlog.rev(n))) |
|
1967 | return cl.node(revlog.linkrev(revlog.rev(n))) | |
1969 | return lookuprevlink |
|
1968 | return lookuprevlink | |
1970 |
|
1969 | |||
1971 | def gengroup(): |
|
1970 | def gengroup(): | |
1972 | '''yield a sequence of changegroup chunks (strings)''' |
|
1971 | '''yield a sequence of changegroup chunks (strings)''' | |
1973 | # construct a list of all changed files |
|
1972 | # construct a list of all changed files | |
1974 | changedfiles = {} |
|
1973 | changedfiles = {} | |
1975 | mmfs = {} |
|
1974 | mmfs = {} | |
1976 | collect = changegroup.collector(cl, mmfs, changedfiles) |
|
1975 | collect = changegroup.collector(cl, mmfs, changedfiles) | |
1977 |
|
1976 | |||
1978 | cnt = 0 |
|
1977 | cnt = 0 | |
1979 | for chnk in cl.group(nodes, identity, collect): |
|
1978 | for chnk in cl.group(nodes, identity, collect): | |
1980 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) |
|
1979 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) | |
1981 | cnt += 1 |
|
1980 | cnt += 1 | |
1982 | yield chnk |
|
1981 | yield chnk | |
1983 | self.ui.progress(_('bundling changes'), None) |
|
1982 | self.ui.progress(_('bundling changes'), None) | |
1984 |
|
1983 | |||
1985 | mnfst = self.manifest |
|
1984 | mnfst = self.manifest | |
1986 | nodeiter = gennodelst(mnfst) |
|
1985 | nodeiter = gennodelst(mnfst) | |
1987 | cnt = 0 |
|
1986 | cnt = 0 | |
1988 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): |
|
1987 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): | |
1989 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) |
|
1988 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) | |
1990 | cnt += 1 |
|
1989 | cnt += 1 | |
1991 | yield chnk |
|
1990 | yield chnk | |
1992 | self.ui.progress(_('bundling manifests'), None) |
|
1991 | self.ui.progress(_('bundling manifests'), None) | |
1993 |
|
1992 | |||
1994 | cnt = 0 |
|
1993 | cnt = 0 | |
1995 | for fname in sorted(changedfiles): |
|
1994 | for fname in sorted(changedfiles): | |
1996 | filerevlog = self.file(fname) |
|
1995 | filerevlog = self.file(fname) | |
1997 | if not len(filerevlog): |
|
1996 | if not len(filerevlog): | |
1998 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1997 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1999 | nodeiter = gennodelst(filerevlog) |
|
1998 | nodeiter = gennodelst(filerevlog) | |
2000 | nodeiter = list(nodeiter) |
|
1999 | nodeiter = list(nodeiter) | |
2001 | if nodeiter: |
|
2000 | if nodeiter: | |
2002 | yield changegroup.chunkheader(len(fname)) |
|
2001 | yield changegroup.chunkheader(len(fname)) | |
2003 | yield fname |
|
2002 | yield fname | |
2004 | lookup = lookuprevlink_func(filerevlog) |
|
2003 | lookup = lookuprevlink_func(filerevlog) | |
2005 | for chnk in filerevlog.group(nodeiter, lookup): |
|
2004 | for chnk in filerevlog.group(nodeiter, lookup): | |
2006 | self.ui.progress( |
|
2005 | self.ui.progress( | |
2007 | _('bundling files'), cnt, item=fname, unit=_('chunks')) |
|
2006 | _('bundling files'), cnt, item=fname, unit=_('chunks')) | |
2008 | cnt += 1 |
|
2007 | cnt += 1 | |
2009 | yield chnk |
|
2008 | yield chnk | |
2010 | self.ui.progress(_('bundling files'), None) |
|
2009 | self.ui.progress(_('bundling files'), None) | |
2011 |
|
2010 | |||
2012 | yield changegroup.closechunk() |
|
2011 | yield changegroup.closechunk() | |
2013 |
|
2012 | |||
2014 | if nodes: |
|
2013 | if nodes: | |
2015 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
2014 | self.hook('outgoing', node=hex(nodes[0]), source=source) | |
2016 |
|
2015 | |||
2017 | return util.chunkbuffer(gengroup()) |
|
2016 | return util.chunkbuffer(gengroup()) | |
2018 |
|
2017 | |||
2019 | def addchangegroup(self, source, srctype, url, emptyok=False): |
|
2018 | def addchangegroup(self, source, srctype, url, emptyok=False): | |
2020 | """add changegroup to repo. |
|
2019 | """add changegroup to repo. | |
2021 |
|
2020 | |||
2022 | return values: |
|
2021 | return values: | |
2023 | - nothing changed or no source: 0 |
|
2022 | - nothing changed or no source: 0 | |
2024 | - more heads than before: 1+added heads (2..n) |
|
2023 | - more heads than before: 1+added heads (2..n) | |
2025 | - less heads than before: -1-removed heads (-2..-n) |
|
2024 | - less heads than before: -1-removed heads (-2..-n) | |
2026 | - number of heads stays the same: 1 |
|
2025 | - number of heads stays the same: 1 | |
2027 | """ |
|
2026 | """ | |
2028 | def csmap(x): |
|
2027 | def csmap(x): | |
2029 | self.ui.debug("add changeset %s\n" % short(x)) |
|
2028 | self.ui.debug("add changeset %s\n" % short(x)) | |
2030 | return len(cl) |
|
2029 | return len(cl) | |
2031 |
|
2030 | |||
2032 | def revmap(x): |
|
2031 | def revmap(x): | |
2033 | return cl.rev(x) |
|
2032 | return cl.rev(x) | |
2034 |
|
2033 | |||
2035 | if not source: |
|
2034 | if not source: | |
2036 | return 0 |
|
2035 | return 0 | |
2037 |
|
2036 | |||
2038 | self.hook('prechangegroup', throw=True, source=srctype, url=url) |
|
2037 | self.hook('prechangegroup', throw=True, source=srctype, url=url) | |
2039 |
|
2038 | |||
2040 | changesets = files = revisions = 0 |
|
2039 | changesets = files = revisions = 0 | |
2041 | efiles = set() |
|
2040 | efiles = set() | |
2042 |
|
2041 | |||
2043 | # write changelog data to temp files so concurrent readers will not see |
|
2042 | # write changelog data to temp files so concurrent readers will not see | |
2044 | # inconsistent view |
|
2043 | # inconsistent view | |
2045 | cl = self.changelog |
|
2044 | cl = self.changelog | |
2046 | cl.delayupdate() |
|
2045 | cl.delayupdate() | |
2047 | oldheads = len(cl.heads()) |
|
2046 | oldheads = len(cl.heads()) | |
2048 |
|
2047 | |||
2049 | tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)])) |
|
2048 | tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)])) | |
2050 | try: |
|
2049 | try: | |
2051 | trp = weakref.proxy(tr) |
|
2050 | trp = weakref.proxy(tr) | |
2052 | # pull off the changeset group |
|
2051 | # pull off the changeset group | |
2053 | self.ui.status(_("adding changesets\n")) |
|
2052 | self.ui.status(_("adding changesets\n")) | |
2054 | clstart = len(cl) |
|
2053 | clstart = len(cl) | |
2055 | class prog(object): |
|
2054 | class prog(object): | |
2056 | step = _('changesets') |
|
2055 | step = _('changesets') | |
2057 | count = 1 |
|
2056 | count = 1 | |
2058 | ui = self.ui |
|
2057 | ui = self.ui | |
2059 | total = None |
|
2058 | total = None | |
2060 | def __call__(self): |
|
2059 | def __call__(self): | |
2061 | self.ui.progress(self.step, self.count, unit=_('chunks'), |
|
2060 | self.ui.progress(self.step, self.count, unit=_('chunks'), | |
2062 | total=self.total) |
|
2061 | total=self.total) | |
2063 | self.count += 1 |
|
2062 | self.count += 1 | |
2064 | pr = prog() |
|
2063 | pr = prog() | |
2065 | chunkiter = changegroup.chunkiter(source, progress=pr) |
|
2064 | chunkiter = changegroup.chunkiter(source, progress=pr) | |
2066 | if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok: |
|
2065 | if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok: | |
2067 | raise util.Abort(_("received changelog group is empty")) |
|
2066 | raise util.Abort(_("received changelog group is empty")) | |
2068 | clend = len(cl) |
|
2067 | clend = len(cl) | |
2069 | changesets = clend - clstart |
|
2068 | changesets = clend - clstart | |
2070 | for c in xrange(clstart, clend): |
|
2069 | for c in xrange(clstart, clend): | |
2071 | efiles.update(self[c].files()) |
|
2070 | efiles.update(self[c].files()) | |
2072 | efiles = len(efiles) |
|
2071 | efiles = len(efiles) | |
2073 | self.ui.progress(_('changesets'), None) |
|
2072 | self.ui.progress(_('changesets'), None) | |
2074 |
|
2073 | |||
2075 | # pull off the manifest group |
|
2074 | # pull off the manifest group | |
2076 | self.ui.status(_("adding manifests\n")) |
|
2075 | self.ui.status(_("adding manifests\n")) | |
2077 | pr.step = _('manifests') |
|
2076 | pr.step = _('manifests') | |
2078 | pr.count = 1 |
|
2077 | pr.count = 1 | |
2079 | pr.total = changesets # manifests <= changesets |
|
2078 | pr.total = changesets # manifests <= changesets | |
2080 | chunkiter = changegroup.chunkiter(source, progress=pr) |
|
2079 | chunkiter = changegroup.chunkiter(source, progress=pr) | |
2081 | # no need to check for empty manifest group here: |
|
2080 | # no need to check for empty manifest group here: | |
2082 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
2081 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
2083 | # no new manifest will be created and the manifest group will |
|
2082 | # no new manifest will be created and the manifest group will | |
2084 | # be empty during the pull |
|
2083 | # be empty during the pull | |
2085 | self.manifest.addgroup(chunkiter, revmap, trp) |
|
2084 | self.manifest.addgroup(chunkiter, revmap, trp) | |
2086 | self.ui.progress(_('manifests'), None) |
|
2085 | self.ui.progress(_('manifests'), None) | |
2087 |
|
2086 | |||
2088 | needfiles = {} |
|
2087 | needfiles = {} | |
2089 | if self.ui.configbool('server', 'validate', default=False): |
|
2088 | if self.ui.configbool('server', 'validate', default=False): | |
2090 | # validate incoming csets have their manifests |
|
2089 | # validate incoming csets have their manifests | |
2091 | for cset in xrange(clstart, clend): |
|
2090 | for cset in xrange(clstart, clend): | |
2092 | mfest = self.changelog.read(self.changelog.node(cset))[0] |
|
2091 | mfest = self.changelog.read(self.changelog.node(cset))[0] | |
2093 | mfest = self.manifest.readdelta(mfest) |
|
2092 | mfest = self.manifest.readdelta(mfest) | |
2094 | # store file nodes we must see |
|
2093 | # store file nodes we must see | |
2095 | for f, n in mfest.iteritems(): |
|
2094 | for f, n in mfest.iteritems(): | |
2096 | needfiles.setdefault(f, set()).add(n) |
|
2095 | needfiles.setdefault(f, set()).add(n) | |
2097 |
|
2096 | |||
2098 | # process the files |
|
2097 | # process the files | |
2099 | self.ui.status(_("adding file changes\n")) |
|
2098 | self.ui.status(_("adding file changes\n")) | |
2100 | pr.step = 'files' |
|
2099 | pr.step = 'files' | |
2101 | pr.count = 1 |
|
2100 | pr.count = 1 | |
2102 | pr.total = efiles |
|
2101 | pr.total = efiles | |
2103 | while 1: |
|
2102 | while 1: | |
2104 | f = changegroup.getchunk(source) |
|
2103 | f = changegroup.getchunk(source) | |
2105 | if not f: |
|
2104 | if not f: | |
2106 | break |
|
2105 | break | |
2107 | self.ui.debug("adding %s revisions\n" % f) |
|
2106 | self.ui.debug("adding %s revisions\n" % f) | |
2108 | pr() |
|
2107 | pr() | |
2109 | fl = self.file(f) |
|
2108 | fl = self.file(f) | |
2110 | o = len(fl) |
|
2109 | o = len(fl) | |
2111 | chunkiter = changegroup.chunkiter(source) |
|
2110 | chunkiter = changegroup.chunkiter(source) | |
2112 | if fl.addgroup(chunkiter, revmap, trp) is None: |
|
2111 | if fl.addgroup(chunkiter, revmap, trp) is None: | |
2113 | raise util.Abort(_("received file revlog group is empty")) |
|
2112 | raise util.Abort(_("received file revlog group is empty")) | |
2114 | revisions += len(fl) - o |
|
2113 | revisions += len(fl) - o | |
2115 | files += 1 |
|
2114 | files += 1 | |
2116 | if f in needfiles: |
|
2115 | if f in needfiles: | |
2117 | needs = needfiles[f] |
|
2116 | needs = needfiles[f] | |
2118 | for new in xrange(o, len(fl)): |
|
2117 | for new in xrange(o, len(fl)): | |
2119 | n = fl.node(new) |
|
2118 | n = fl.node(new) | |
2120 | if n in needs: |
|
2119 | if n in needs: | |
2121 | needs.remove(n) |
|
2120 | needs.remove(n) | |
2122 | if not needs: |
|
2121 | if not needs: | |
2123 | del needfiles[f] |
|
2122 | del needfiles[f] | |
2124 | self.ui.progress(_('files'), None) |
|
2123 | self.ui.progress(_('files'), None) | |
2125 |
|
2124 | |||
2126 | for f, needs in needfiles.iteritems(): |
|
2125 | for f, needs in needfiles.iteritems(): | |
2127 | fl = self.file(f) |
|
2126 | fl = self.file(f) | |
2128 | for n in needs: |
|
2127 | for n in needs: | |
2129 | try: |
|
2128 | try: | |
2130 | fl.rev(n) |
|
2129 | fl.rev(n) | |
2131 | except error.LookupError: |
|
2130 | except error.LookupError: | |
2132 | raise util.Abort( |
|
2131 | raise util.Abort( | |
2133 | _('missing file data for %s:%s - run hg verify') % |
|
2132 | _('missing file data for %s:%s - run hg verify') % | |
2134 | (f, hex(n))) |
|
2133 | (f, hex(n))) | |
2135 |
|
2134 | |||
2136 | newheads = len(cl.heads()) |
|
2135 | newheads = len(cl.heads()) | |
2137 | heads = "" |
|
2136 | heads = "" | |
2138 | if oldheads and newheads != oldheads: |
|
2137 | if oldheads and newheads != oldheads: | |
2139 | heads = _(" (%+d heads)") % (newheads - oldheads) |
|
2138 | heads = _(" (%+d heads)") % (newheads - oldheads) | |
2140 |
|
2139 | |||
2141 | self.ui.status(_("added %d changesets" |
|
2140 | self.ui.status(_("added %d changesets" | |
2142 | " with %d changes to %d files%s\n") |
|
2141 | " with %d changes to %d files%s\n") | |
2143 | % (changesets, revisions, files, heads)) |
|
2142 | % (changesets, revisions, files, heads)) | |
2144 |
|
2143 | |||
2145 | if changesets > 0: |
|
2144 | if changesets > 0: | |
2146 | p = lambda: cl.writepending() and self.root or "" |
|
2145 | p = lambda: cl.writepending() and self.root or "" | |
2147 | self.hook('pretxnchangegroup', throw=True, |
|
2146 | self.hook('pretxnchangegroup', throw=True, | |
2148 | node=hex(cl.node(clstart)), source=srctype, |
|
2147 | node=hex(cl.node(clstart)), source=srctype, | |
2149 | url=url, pending=p) |
|
2148 | url=url, pending=p) | |
2150 |
|
2149 | |||
2151 | # make changelog see real files again |
|
2150 | # make changelog see real files again | |
2152 | cl.finalize(trp) |
|
2151 | cl.finalize(trp) | |
2153 |
|
2152 | |||
2154 | tr.close() |
|
2153 | tr.close() | |
2155 | finally: |
|
2154 | finally: | |
2156 | del tr |
|
2155 | del tr | |
2157 |
|
2156 | |||
2158 | if changesets > 0: |
|
2157 | if changesets > 0: | |
2159 | # forcefully update the on-disk branch cache |
|
2158 | # forcefully update the on-disk branch cache | |
2160 | self.ui.debug("updating the branch cache\n") |
|
2159 | self.ui.debug("updating the branch cache\n") | |
2161 | self.branchtags() |
|
2160 | self.branchtags() | |
2162 | self.hook("changegroup", node=hex(cl.node(clstart)), |
|
2161 | self.hook("changegroup", node=hex(cl.node(clstart)), | |
2163 | source=srctype, url=url) |
|
2162 | source=srctype, url=url) | |
2164 |
|
2163 | |||
2165 | for i in xrange(clstart, clend): |
|
2164 | for i in xrange(clstart, clend): | |
2166 | self.hook("incoming", node=hex(cl.node(i)), |
|
2165 | self.hook("incoming", node=hex(cl.node(i)), | |
2167 | source=srctype, url=url) |
|
2166 | source=srctype, url=url) | |
2168 |
|
2167 | |||
2169 | # never return 0 here: |
|
2168 | # never return 0 here: | |
2170 | if newheads < oldheads: |
|
2169 | if newheads < oldheads: | |
2171 | return newheads - oldheads - 1 |
|
2170 | return newheads - oldheads - 1 | |
2172 | else: |
|
2171 | else: | |
2173 | return newheads - oldheads + 1 |
|
2172 | return newheads - oldheads + 1 | |
2174 |
|
2173 | |||
2175 |
|
2174 | |||
2176 | def stream_in(self, remote): |
|
2175 | def stream_in(self, remote): | |
2177 | fp = remote.stream_out() |
|
2176 | fp = remote.stream_out() | |
2178 | l = fp.readline() |
|
2177 | l = fp.readline() | |
2179 | try: |
|
2178 | try: | |
2180 | resp = int(l) |
|
2179 | resp = int(l) | |
2181 | except ValueError: |
|
2180 | except ValueError: | |
2182 | raise error.ResponseError( |
|
2181 | raise error.ResponseError( | |
2183 | _('Unexpected response from remote server:'), l) |
|
2182 | _('Unexpected response from remote server:'), l) | |
2184 | if resp == 1: |
|
2183 | if resp == 1: | |
2185 | raise util.Abort(_('operation forbidden by server')) |
|
2184 | raise util.Abort(_('operation forbidden by server')) | |
2186 | elif resp == 2: |
|
2185 | elif resp == 2: | |
2187 | raise util.Abort(_('locking the remote repository failed')) |
|
2186 | raise util.Abort(_('locking the remote repository failed')) | |
2188 | elif resp != 0: |
|
2187 | elif resp != 0: | |
2189 | raise util.Abort(_('the server sent an unknown error code')) |
|
2188 | raise util.Abort(_('the server sent an unknown error code')) | |
2190 | self.ui.status(_('streaming all changes\n')) |
|
2189 | self.ui.status(_('streaming all changes\n')) | |
2191 | l = fp.readline() |
|
2190 | l = fp.readline() | |
2192 | try: |
|
2191 | try: | |
2193 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
2192 | total_files, total_bytes = map(int, l.split(' ', 1)) | |
2194 | except (ValueError, TypeError): |
|
2193 | except (ValueError, TypeError): | |
2195 | raise error.ResponseError( |
|
2194 | raise error.ResponseError( | |
2196 | _('Unexpected response from remote server:'), l) |
|
2195 | _('Unexpected response from remote server:'), l) | |
2197 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
2196 | self.ui.status(_('%d files to transfer, %s of data\n') % | |
2198 | (total_files, util.bytecount(total_bytes))) |
|
2197 | (total_files, util.bytecount(total_bytes))) | |
2199 | start = time.time() |
|
2198 | start = time.time() | |
2200 | for i in xrange(total_files): |
|
2199 | for i in xrange(total_files): | |
2201 | # XXX doesn't support '\n' or '\r' in filenames |
|
2200 | # XXX doesn't support '\n' or '\r' in filenames | |
2202 | l = fp.readline() |
|
2201 | l = fp.readline() | |
2203 | try: |
|
2202 | try: | |
2204 | name, size = l.split('\0', 1) |
|
2203 | name, size = l.split('\0', 1) | |
2205 | size = int(size) |
|
2204 | size = int(size) | |
2206 | except (ValueError, TypeError): |
|
2205 | except (ValueError, TypeError): | |
2207 | raise error.ResponseError( |
|
2206 | raise error.ResponseError( | |
2208 | _('Unexpected response from remote server:'), l) |
|
2207 | _('Unexpected response from remote server:'), l) | |
2209 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
|
2208 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) | |
2210 | # for backwards compat, name was partially encoded |
|
2209 | # for backwards compat, name was partially encoded | |
2211 | ofp = self.sopener(store.decodedir(name), 'w') |
|
2210 | ofp = self.sopener(store.decodedir(name), 'w') | |
2212 | for chunk in util.filechunkiter(fp, limit=size): |
|
2211 | for chunk in util.filechunkiter(fp, limit=size): | |
2213 | ofp.write(chunk) |
|
2212 | ofp.write(chunk) | |
2214 | ofp.close() |
|
2213 | ofp.close() | |
2215 | elapsed = time.time() - start |
|
2214 | elapsed = time.time() - start | |
2216 | if elapsed <= 0: |
|
2215 | if elapsed <= 0: | |
2217 | elapsed = 0.001 |
|
2216 | elapsed = 0.001 | |
2218 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
2217 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |
2219 | (util.bytecount(total_bytes), elapsed, |
|
2218 | (util.bytecount(total_bytes), elapsed, | |
2220 | util.bytecount(total_bytes / elapsed))) |
|
2219 | util.bytecount(total_bytes / elapsed))) | |
2221 | self.invalidate() |
|
2220 | self.invalidate() | |
2222 | return len(self.heads()) + 1 |
|
2221 | return len(self.heads()) + 1 | |
2223 |
|
2222 | |||
2224 | def clone(self, remote, heads=[], stream=False): |
|
2223 | def clone(self, remote, heads=[], stream=False): | |
2225 | '''clone remote repository. |
|
2224 | '''clone remote repository. | |
2226 |
|
2225 | |||
2227 | keyword arguments: |
|
2226 | keyword arguments: | |
2228 | heads: list of revs to clone (forces use of pull) |
|
2227 | heads: list of revs to clone (forces use of pull) | |
2229 | stream: use streaming clone if possible''' |
|
2228 | stream: use streaming clone if possible''' | |
2230 |
|
2229 | |||
2231 | # now, all clients that can request uncompressed clones can |
|
2230 | # now, all clients that can request uncompressed clones can | |
2232 | # read repo formats supported by all servers that can serve |
|
2231 | # read repo formats supported by all servers that can serve | |
2233 | # them. |
|
2232 | # them. | |
2234 |
|
2233 | |||
2235 | # if revlog format changes, client will have to check version |
|
2234 | # if revlog format changes, client will have to check version | |
2236 | # and format flags on "stream" capability, and use |
|
2235 | # and format flags on "stream" capability, and use | |
2237 | # uncompressed only if compatible. |
|
2236 | # uncompressed only if compatible. | |
2238 |
|
2237 | |||
2239 | if stream and not heads and remote.capable('stream'): |
|
2238 | if stream and not heads and remote.capable('stream'): | |
2240 | return self.stream_in(remote) |
|
2239 | return self.stream_in(remote) | |
2241 | return self.pull(remote, heads) |
|
2240 | return self.pull(remote, heads) | |
2242 |
|
2241 | |||
2243 | # used to avoid circular references so destructors work |
|
2242 | # used to avoid circular references so destructors work | |
2244 | def aftertrans(files): |
|
2243 | def aftertrans(files): | |
2245 | renamefiles = [tuple(t) for t in files] |
|
2244 | renamefiles = [tuple(t) for t in files] | |
2246 | def a(): |
|
2245 | def a(): | |
2247 | for src, dest in renamefiles: |
|
2246 | for src, dest in renamefiles: | |
2248 | util.rename(src, dest) |
|
2247 | util.rename(src, dest) | |
2249 | return a |
|
2248 | return a | |
2250 |
|
2249 | |||
2251 | def instance(ui, path, create): |
|
2250 | def instance(ui, path, create): | |
2252 | return localrepository(ui, util.drop_scheme('file', path), create) |
|
2251 | return localrepository(ui, util.drop_scheme('file', path), create) | |
2253 |
|
2252 | |||
2254 | def islocal(path): |
|
2253 | def islocal(path): | |
2255 | return True |
|
2254 | return True |
General Comments 0
You need to be logged in to leave comments.
Login now