Show More
@@ -0,0 +1,27 b'' | |||||
|
1 | #!/bin/sh | |||
|
2 | ||||
|
3 | hg init outer | |||
|
4 | cd outer | |||
|
5 | ||||
|
6 | echo 'sub = http://example.net/libfoo' > .hgsub | |||
|
7 | hg add .hgsub | |||
|
8 | ||||
|
9 | echo '% hg debugsub with no remapping' | |||
|
10 | hg debugsub | |||
|
11 | ||||
|
12 | cat > .hg/hgrc <<EOF | |||
|
13 | [subpaths] | |||
|
14 | http://example.net = ssh://localhost | |||
|
15 | EOF | |||
|
16 | ||||
|
17 | echo '% hg debugsub with remapping' | |||
|
18 | hg debugsub | |||
|
19 | ||||
|
20 | echo '% test bad subpaths pattern' | |||
|
21 | cat > .hg/hgrc <<EOF | |||
|
22 | [subpaths] | |||
|
23 | .* = \1 | |||
|
24 | EOF | |||
|
25 | hg debugsub 2>&1 | "$TESTDIR/filtertmp.py" | |||
|
26 | ||||
|
27 | exit 0 |
@@ -0,0 +1,10 b'' | |||||
|
1 | % hg debugsub with no remapping | |||
|
2 | path sub | |||
|
3 | source http://example.net/libfoo | |||
|
4 | revision | |||
|
5 | % hg debugsub with remapping | |||
|
6 | path sub | |||
|
7 | source ssh://localhost/libfoo | |||
|
8 | revision | |||
|
9 | % test bad subpaths pattern | |||
|
10 | abort: bad subrepository pattern in $HGTMP/test-subrepo-paths/outer/.hg/hgrc:2: invalid group reference |
@@ -1,1088 +1,1088 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, patch |
|
10 | import ancestor, bdiff, error, util, subrepo, patch | |
11 | import os, errno, stat |
|
11 | import os, errno, stat | |
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, self._repo.ui) | |
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 | def diff(self, ctx2=None, match=None, **opts): |
|
207 | def diff(self, ctx2=None, match=None, **opts): | |
208 | """Returns a diff generator for the given contexts and matcher""" |
|
208 | """Returns a diff generator for the given contexts and matcher""" | |
209 | if ctx2 is None: |
|
209 | if ctx2 is None: | |
210 | ctx2 = self.p1() |
|
210 | ctx2 = self.p1() | |
211 | if ctx2 is not None and not isinstance(ctx2, changectx): |
|
211 | if ctx2 is not None and not isinstance(ctx2, changectx): | |
212 | ctx2 = self._repo[ctx2] |
|
212 | ctx2 = self._repo[ctx2] | |
213 | diffopts = patch.diffopts(self._repo.ui, opts) |
|
213 | diffopts = patch.diffopts(self._repo.ui, opts) | |
214 | return patch.diff(self._repo, ctx2.node(), self.node(), |
|
214 | return patch.diff(self._repo, ctx2.node(), self.node(), | |
215 | match=match, opts=diffopts) |
|
215 | match=match, opts=diffopts) | |
216 |
|
216 | |||
217 | class filectx(object): |
|
217 | class filectx(object): | |
218 | """A filecontext object makes access to data related to a particular |
|
218 | """A filecontext object makes access to data related to a particular | |
219 | filerevision convenient.""" |
|
219 | filerevision convenient.""" | |
220 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
220 | def __init__(self, repo, path, changeid=None, fileid=None, | |
221 | filelog=None, changectx=None): |
|
221 | filelog=None, changectx=None): | |
222 | """changeid can be a changeset revision, node, or tag. |
|
222 | """changeid can be a changeset revision, node, or tag. | |
223 | fileid can be a file revision or node.""" |
|
223 | fileid can be a file revision or node.""" | |
224 | self._repo = repo |
|
224 | self._repo = repo | |
225 | self._path = path |
|
225 | self._path = path | |
226 |
|
226 | |||
227 | assert (changeid is not None |
|
227 | assert (changeid is not None | |
228 | or fileid is not None |
|
228 | or fileid is not None | |
229 | or changectx is not None), \ |
|
229 | or changectx is not None), \ | |
230 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
230 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
231 | % (changeid, fileid, changectx)) |
|
231 | % (changeid, fileid, changectx)) | |
232 |
|
232 | |||
233 | if filelog: |
|
233 | if filelog: | |
234 | self._filelog = filelog |
|
234 | self._filelog = filelog | |
235 |
|
235 | |||
236 | if changeid is not None: |
|
236 | if changeid is not None: | |
237 | self._changeid = changeid |
|
237 | self._changeid = changeid | |
238 | if changectx is not None: |
|
238 | if changectx is not None: | |
239 | self._changectx = changectx |
|
239 | self._changectx = changectx | |
240 | if fileid is not None: |
|
240 | if fileid is not None: | |
241 | self._fileid = fileid |
|
241 | self._fileid = fileid | |
242 |
|
242 | |||
243 | @propertycache |
|
243 | @propertycache | |
244 | def _changectx(self): |
|
244 | def _changectx(self): | |
245 | return changectx(self._repo, self._changeid) |
|
245 | return changectx(self._repo, self._changeid) | |
246 |
|
246 | |||
247 | @propertycache |
|
247 | @propertycache | |
248 | def _filelog(self): |
|
248 | def _filelog(self): | |
249 | return self._repo.file(self._path) |
|
249 | return self._repo.file(self._path) | |
250 |
|
250 | |||
251 | @propertycache |
|
251 | @propertycache | |
252 | def _changeid(self): |
|
252 | def _changeid(self): | |
253 | if '_changectx' in self.__dict__: |
|
253 | if '_changectx' in self.__dict__: | |
254 | return self._changectx.rev() |
|
254 | return self._changectx.rev() | |
255 | else: |
|
255 | else: | |
256 | return self._filelog.linkrev(self._filerev) |
|
256 | return self._filelog.linkrev(self._filerev) | |
257 |
|
257 | |||
258 | @propertycache |
|
258 | @propertycache | |
259 | def _filenode(self): |
|
259 | def _filenode(self): | |
260 | if '_fileid' in self.__dict__: |
|
260 | if '_fileid' in self.__dict__: | |
261 | return self._filelog.lookup(self._fileid) |
|
261 | return self._filelog.lookup(self._fileid) | |
262 | else: |
|
262 | else: | |
263 | return self._changectx.filenode(self._path) |
|
263 | return self._changectx.filenode(self._path) | |
264 |
|
264 | |||
265 | @propertycache |
|
265 | @propertycache | |
266 | def _filerev(self): |
|
266 | def _filerev(self): | |
267 | return self._filelog.rev(self._filenode) |
|
267 | return self._filelog.rev(self._filenode) | |
268 |
|
268 | |||
269 | @propertycache |
|
269 | @propertycache | |
270 | def _repopath(self): |
|
270 | def _repopath(self): | |
271 | return self._path |
|
271 | return self._path | |
272 |
|
272 | |||
273 | def __nonzero__(self): |
|
273 | def __nonzero__(self): | |
274 | try: |
|
274 | try: | |
275 | self._filenode |
|
275 | self._filenode | |
276 | return True |
|
276 | return True | |
277 | except error.LookupError: |
|
277 | except error.LookupError: | |
278 | # file is missing |
|
278 | # file is missing | |
279 | return False |
|
279 | return False | |
280 |
|
280 | |||
281 | def __str__(self): |
|
281 | def __str__(self): | |
282 | return "%s@%s" % (self.path(), short(self.node())) |
|
282 | return "%s@%s" % (self.path(), short(self.node())) | |
283 |
|
283 | |||
284 | def __repr__(self): |
|
284 | def __repr__(self): | |
285 | return "<filectx %s>" % str(self) |
|
285 | return "<filectx %s>" % str(self) | |
286 |
|
286 | |||
287 | def __hash__(self): |
|
287 | def __hash__(self): | |
288 | try: |
|
288 | try: | |
289 | return hash((self._path, self._filenode)) |
|
289 | return hash((self._path, self._filenode)) | |
290 | except AttributeError: |
|
290 | except AttributeError: | |
291 | return id(self) |
|
291 | return id(self) | |
292 |
|
292 | |||
293 | def __eq__(self, other): |
|
293 | def __eq__(self, other): | |
294 | try: |
|
294 | try: | |
295 | return (self._path == other._path |
|
295 | return (self._path == other._path | |
296 | and self._filenode == other._filenode) |
|
296 | and self._filenode == other._filenode) | |
297 | except AttributeError: |
|
297 | except AttributeError: | |
298 | return False |
|
298 | return False | |
299 |
|
299 | |||
300 | def __ne__(self, other): |
|
300 | def __ne__(self, other): | |
301 | return not (self == other) |
|
301 | return not (self == other) | |
302 |
|
302 | |||
303 | def filectx(self, fileid): |
|
303 | def filectx(self, fileid): | |
304 | '''opens an arbitrary revision of the file without |
|
304 | '''opens an arbitrary revision of the file without | |
305 | opening a new filelog''' |
|
305 | opening a new filelog''' | |
306 | return filectx(self._repo, self._path, fileid=fileid, |
|
306 | return filectx(self._repo, self._path, fileid=fileid, | |
307 | filelog=self._filelog) |
|
307 | filelog=self._filelog) | |
308 |
|
308 | |||
309 | def filerev(self): |
|
309 | def filerev(self): | |
310 | return self._filerev |
|
310 | return self._filerev | |
311 | def filenode(self): |
|
311 | def filenode(self): | |
312 | return self._filenode |
|
312 | return self._filenode | |
313 | def flags(self): |
|
313 | def flags(self): | |
314 | return self._changectx.flags(self._path) |
|
314 | return self._changectx.flags(self._path) | |
315 | def filelog(self): |
|
315 | def filelog(self): | |
316 | return self._filelog |
|
316 | return self._filelog | |
317 |
|
317 | |||
318 | def rev(self): |
|
318 | def rev(self): | |
319 | if '_changectx' in self.__dict__: |
|
319 | if '_changectx' in self.__dict__: | |
320 | return self._changectx.rev() |
|
320 | return self._changectx.rev() | |
321 | if '_changeid' in self.__dict__: |
|
321 | if '_changeid' in self.__dict__: | |
322 | return self._changectx.rev() |
|
322 | return self._changectx.rev() | |
323 | return self._filelog.linkrev(self._filerev) |
|
323 | return self._filelog.linkrev(self._filerev) | |
324 |
|
324 | |||
325 | def linkrev(self): |
|
325 | def linkrev(self): | |
326 | return self._filelog.linkrev(self._filerev) |
|
326 | return self._filelog.linkrev(self._filerev) | |
327 | def node(self): |
|
327 | def node(self): | |
328 | return self._changectx.node() |
|
328 | return self._changectx.node() | |
329 | def hex(self): |
|
329 | def hex(self): | |
330 | return hex(self.node()) |
|
330 | return hex(self.node()) | |
331 | def user(self): |
|
331 | def user(self): | |
332 | return self._changectx.user() |
|
332 | return self._changectx.user() | |
333 | def date(self): |
|
333 | def date(self): | |
334 | return self._changectx.date() |
|
334 | return self._changectx.date() | |
335 | def files(self): |
|
335 | def files(self): | |
336 | return self._changectx.files() |
|
336 | return self._changectx.files() | |
337 | def description(self): |
|
337 | def description(self): | |
338 | return self._changectx.description() |
|
338 | return self._changectx.description() | |
339 | def branch(self): |
|
339 | def branch(self): | |
340 | return self._changectx.branch() |
|
340 | return self._changectx.branch() | |
341 | def extra(self): |
|
341 | def extra(self): | |
342 | return self._changectx.extra() |
|
342 | return self._changectx.extra() | |
343 | def manifest(self): |
|
343 | def manifest(self): | |
344 | return self._changectx.manifest() |
|
344 | return self._changectx.manifest() | |
345 | def changectx(self): |
|
345 | def changectx(self): | |
346 | return self._changectx |
|
346 | return self._changectx | |
347 |
|
347 | |||
348 | def data(self): |
|
348 | def data(self): | |
349 | return self._filelog.read(self._filenode) |
|
349 | return self._filelog.read(self._filenode) | |
350 | def path(self): |
|
350 | def path(self): | |
351 | return self._path |
|
351 | return self._path | |
352 | def size(self): |
|
352 | def size(self): | |
353 | return self._filelog.size(self._filerev) |
|
353 | return self._filelog.size(self._filerev) | |
354 |
|
354 | |||
355 | def cmp(self, fctx): |
|
355 | def cmp(self, fctx): | |
356 | """compare with other file context |
|
356 | """compare with other file context | |
357 |
|
357 | |||
358 | returns True if different than fctx. |
|
358 | returns True if different than fctx. | |
359 | """ |
|
359 | """ | |
360 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
360 | return self._filelog.cmp(self._filenode, fctx.data()) | |
361 |
|
361 | |||
362 | def renamed(self): |
|
362 | def renamed(self): | |
363 | """check if file was actually renamed in this changeset revision |
|
363 | """check if file was actually renamed in this changeset revision | |
364 |
|
364 | |||
365 | If rename logged in file revision, we report copy for changeset only |
|
365 | If rename logged in file revision, we report copy for changeset only | |
366 | if file revisions linkrev points back to the changeset in question |
|
366 | if file revisions linkrev points back to the changeset in question | |
367 | or both changeset parents contain different file revisions. |
|
367 | or both changeset parents contain different file revisions. | |
368 | """ |
|
368 | """ | |
369 |
|
369 | |||
370 | renamed = self._filelog.renamed(self._filenode) |
|
370 | renamed = self._filelog.renamed(self._filenode) | |
371 | if not renamed: |
|
371 | if not renamed: | |
372 | return renamed |
|
372 | return renamed | |
373 |
|
373 | |||
374 | if self.rev() == self.linkrev(): |
|
374 | if self.rev() == self.linkrev(): | |
375 | return renamed |
|
375 | return renamed | |
376 |
|
376 | |||
377 | name = self.path() |
|
377 | name = self.path() | |
378 | fnode = self._filenode |
|
378 | fnode = self._filenode | |
379 | for p in self._changectx.parents(): |
|
379 | for p in self._changectx.parents(): | |
380 | try: |
|
380 | try: | |
381 | if fnode == p.filenode(name): |
|
381 | if fnode == p.filenode(name): | |
382 | return None |
|
382 | return None | |
383 | except error.LookupError: |
|
383 | except error.LookupError: | |
384 | pass |
|
384 | pass | |
385 | return renamed |
|
385 | return renamed | |
386 |
|
386 | |||
387 | def parents(self): |
|
387 | def parents(self): | |
388 | p = self._path |
|
388 | p = self._path | |
389 | fl = self._filelog |
|
389 | fl = self._filelog | |
390 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
390 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] | |
391 |
|
391 | |||
392 | r = self._filelog.renamed(self._filenode) |
|
392 | r = self._filelog.renamed(self._filenode) | |
393 | if r: |
|
393 | if r: | |
394 | pl[0] = (r[0], r[1], None) |
|
394 | pl[0] = (r[0], r[1], None) | |
395 |
|
395 | |||
396 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
396 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
397 | for p, n, l in pl if n != nullid] |
|
397 | for p, n, l in pl if n != nullid] | |
398 |
|
398 | |||
399 | def children(self): |
|
399 | def children(self): | |
400 | # hard for renames |
|
400 | # hard for renames | |
401 | c = self._filelog.children(self._filenode) |
|
401 | c = self._filelog.children(self._filenode) | |
402 | return [filectx(self._repo, self._path, fileid=x, |
|
402 | return [filectx(self._repo, self._path, fileid=x, | |
403 | filelog=self._filelog) for x in c] |
|
403 | filelog=self._filelog) for x in c] | |
404 |
|
404 | |||
405 | def annotate(self, follow=False, linenumber=None): |
|
405 | def annotate(self, follow=False, linenumber=None): | |
406 | '''returns a list of tuples of (ctx, line) for each line |
|
406 | '''returns a list of tuples of (ctx, line) for each line | |
407 | in the file, where ctx is the filectx of the node where |
|
407 | in the file, where ctx is the filectx of the node where | |
408 | that line was last changed. |
|
408 | that line was last changed. | |
409 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
409 | This returns tuples of ((ctx, linenumber), line) for each line, | |
410 | if "linenumber" parameter is NOT "None". |
|
410 | if "linenumber" parameter is NOT "None". | |
411 | In such tuples, linenumber means one at the first appearance |
|
411 | In such tuples, linenumber means one at the first appearance | |
412 | in the managed file. |
|
412 | in the managed file. | |
413 | To reduce annotation cost, |
|
413 | To reduce annotation cost, | |
414 | this returns fixed value(False is used) as linenumber, |
|
414 | this returns fixed value(False is used) as linenumber, | |
415 | if "linenumber" parameter is "False".''' |
|
415 | if "linenumber" parameter is "False".''' | |
416 |
|
416 | |||
417 | def decorate_compat(text, rev): |
|
417 | def decorate_compat(text, rev): | |
418 | return ([rev] * len(text.splitlines()), text) |
|
418 | return ([rev] * len(text.splitlines()), text) | |
419 |
|
419 | |||
420 | def without_linenumber(text, rev): |
|
420 | def without_linenumber(text, rev): | |
421 | return ([(rev, False)] * len(text.splitlines()), text) |
|
421 | return ([(rev, False)] * len(text.splitlines()), text) | |
422 |
|
422 | |||
423 | def with_linenumber(text, rev): |
|
423 | def with_linenumber(text, rev): | |
424 | size = len(text.splitlines()) |
|
424 | size = len(text.splitlines()) | |
425 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
425 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
426 |
|
426 | |||
427 | decorate = (((linenumber is None) and decorate_compat) or |
|
427 | decorate = (((linenumber is None) and decorate_compat) or | |
428 | (linenumber and with_linenumber) or |
|
428 | (linenumber and with_linenumber) or | |
429 | without_linenumber) |
|
429 | without_linenumber) | |
430 |
|
430 | |||
431 | def pair(parent, child): |
|
431 | def pair(parent, child): | |
432 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
|
432 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): | |
433 | child[0][b1:b2] = parent[0][a1:a2] |
|
433 | child[0][b1:b2] = parent[0][a1:a2] | |
434 | return child |
|
434 | return child | |
435 |
|
435 | |||
436 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
436 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
437 | def getctx(path, fileid): |
|
437 | def getctx(path, fileid): | |
438 | log = path == self._path and self._filelog or getlog(path) |
|
438 | log = path == self._path and self._filelog or getlog(path) | |
439 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
439 | return filectx(self._repo, path, fileid=fileid, filelog=log) | |
440 | getctx = util.lrucachefunc(getctx) |
|
440 | getctx = util.lrucachefunc(getctx) | |
441 |
|
441 | |||
442 | def parents(f): |
|
442 | def parents(f): | |
443 | # we want to reuse filectx objects as much as possible |
|
443 | # we want to reuse filectx objects as much as possible | |
444 | p = f._path |
|
444 | p = f._path | |
445 | if f._filerev is None: # working dir |
|
445 | if f._filerev is None: # working dir | |
446 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
446 | pl = [(n.path(), n.filerev()) for n in f.parents()] | |
447 | else: |
|
447 | else: | |
448 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
448 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] | |
449 |
|
449 | |||
450 | if follow: |
|
450 | if follow: | |
451 | r = f.renamed() |
|
451 | r = f.renamed() | |
452 | if r: |
|
452 | if r: | |
453 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
453 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) | |
454 |
|
454 | |||
455 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
455 | return [getctx(p, n) for p, n in pl if n != nullrev] | |
456 |
|
456 | |||
457 | # use linkrev to find the first changeset where self appeared |
|
457 | # use linkrev to find the first changeset where self appeared | |
458 | if self.rev() != self.linkrev(): |
|
458 | if self.rev() != self.linkrev(): | |
459 | base = self.filectx(self.filerev()) |
|
459 | base = self.filectx(self.filerev()) | |
460 | else: |
|
460 | else: | |
461 | base = self |
|
461 | base = self | |
462 |
|
462 | |||
463 | # find all ancestors |
|
463 | # find all ancestors | |
464 | needed = {base: 1} |
|
464 | needed = {base: 1} | |
465 | visit = [base] |
|
465 | visit = [base] | |
466 | files = [base._path] |
|
466 | files = [base._path] | |
467 | while visit: |
|
467 | while visit: | |
468 | f = visit.pop(0) |
|
468 | f = visit.pop(0) | |
469 | for p in parents(f): |
|
469 | for p in parents(f): | |
470 | if p not in needed: |
|
470 | if p not in needed: | |
471 | needed[p] = 1 |
|
471 | needed[p] = 1 | |
472 | visit.append(p) |
|
472 | visit.append(p) | |
473 | if p._path not in files: |
|
473 | if p._path not in files: | |
474 | files.append(p._path) |
|
474 | files.append(p._path) | |
475 | else: |
|
475 | else: | |
476 | # count how many times we'll use this |
|
476 | # count how many times we'll use this | |
477 | needed[p] += 1 |
|
477 | needed[p] += 1 | |
478 |
|
478 | |||
479 | # sort by revision (per file) which is a topological order |
|
479 | # sort by revision (per file) which is a topological order | |
480 | visit = [] |
|
480 | visit = [] | |
481 | for f in files: |
|
481 | for f in files: | |
482 | visit.extend(n for n in needed if n._path == f) |
|
482 | visit.extend(n for n in needed if n._path == f) | |
483 |
|
483 | |||
484 | hist = {} |
|
484 | hist = {} | |
485 | for f in sorted(visit, key=lambda x: x.rev()): |
|
485 | for f in sorted(visit, key=lambda x: x.rev()): | |
486 | curr = decorate(f.data(), f) |
|
486 | curr = decorate(f.data(), f) | |
487 | for p in parents(f): |
|
487 | for p in parents(f): | |
488 | curr = pair(hist[p], curr) |
|
488 | curr = pair(hist[p], curr) | |
489 | # trim the history of unneeded revs |
|
489 | # trim the history of unneeded revs | |
490 | needed[p] -= 1 |
|
490 | needed[p] -= 1 | |
491 | if not needed[p]: |
|
491 | if not needed[p]: | |
492 | del hist[p] |
|
492 | del hist[p] | |
493 | hist[f] = curr |
|
493 | hist[f] = curr | |
494 |
|
494 | |||
495 | return zip(hist[f][0], hist[f][1].splitlines(True)) |
|
495 | return zip(hist[f][0], hist[f][1].splitlines(True)) | |
496 |
|
496 | |||
497 | def ancestor(self, fc2, actx=None): |
|
497 | def ancestor(self, fc2, actx=None): | |
498 | """ |
|
498 | """ | |
499 | find the common ancestor file context, if any, of self, and fc2 |
|
499 | find the common ancestor file context, if any, of self, and fc2 | |
500 |
|
500 | |||
501 | If actx is given, it must be the changectx of the common ancestor |
|
501 | If actx is given, it must be the changectx of the common ancestor | |
502 | of self's and fc2's respective changesets. |
|
502 | of self's and fc2's respective changesets. | |
503 | """ |
|
503 | """ | |
504 |
|
504 | |||
505 | if actx is None: |
|
505 | if actx is None: | |
506 | actx = self.changectx().ancestor(fc2.changectx()) |
|
506 | actx = self.changectx().ancestor(fc2.changectx()) | |
507 |
|
507 | |||
508 | # the trivial case: changesets are unrelated, files must be too |
|
508 | # the trivial case: changesets are unrelated, files must be too | |
509 | if not actx: |
|
509 | if not actx: | |
510 | return None |
|
510 | return None | |
511 |
|
511 | |||
512 | # the easy case: no (relevant) renames |
|
512 | # the easy case: no (relevant) renames | |
513 | if fc2.path() == self.path() and self.path() in actx: |
|
513 | if fc2.path() == self.path() and self.path() in actx: | |
514 | return actx[self.path()] |
|
514 | return actx[self.path()] | |
515 | acache = {} |
|
515 | acache = {} | |
516 |
|
516 | |||
517 | # prime the ancestor cache for the working directory |
|
517 | # prime the ancestor cache for the working directory | |
518 | for c in (self, fc2): |
|
518 | for c in (self, fc2): | |
519 | if c._filerev is None: |
|
519 | if c._filerev is None: | |
520 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
520 | pl = [(n.path(), n.filenode()) for n in c.parents()] | |
521 | acache[(c._path, None)] = pl |
|
521 | acache[(c._path, None)] = pl | |
522 |
|
522 | |||
523 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
|
523 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} | |
524 | def parents(vertex): |
|
524 | def parents(vertex): | |
525 | if vertex in acache: |
|
525 | if vertex in acache: | |
526 | return acache[vertex] |
|
526 | return acache[vertex] | |
527 | f, n = vertex |
|
527 | f, n = vertex | |
528 | if f not in flcache: |
|
528 | if f not in flcache: | |
529 | flcache[f] = self._repo.file(f) |
|
529 | flcache[f] = self._repo.file(f) | |
530 | fl = flcache[f] |
|
530 | fl = flcache[f] | |
531 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
531 | pl = [(f, p) for p in fl.parents(n) if p != nullid] | |
532 | re = fl.renamed(n) |
|
532 | re = fl.renamed(n) | |
533 | if re: |
|
533 | if re: | |
534 | pl.append(re) |
|
534 | pl.append(re) | |
535 | acache[vertex] = pl |
|
535 | acache[vertex] = pl | |
536 | return pl |
|
536 | return pl | |
537 |
|
537 | |||
538 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
538 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) | |
539 | v = ancestor.ancestor(a, b, parents) |
|
539 | v = ancestor.ancestor(a, b, parents) | |
540 | if v: |
|
540 | if v: | |
541 | f, n = v |
|
541 | f, n = v | |
542 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
542 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) | |
543 |
|
543 | |||
544 | return None |
|
544 | return None | |
545 |
|
545 | |||
546 | def ancestors(self): |
|
546 | def ancestors(self): | |
547 | seen = set(str(self)) |
|
547 | seen = set(str(self)) | |
548 | visit = [self] |
|
548 | visit = [self] | |
549 | while visit: |
|
549 | while visit: | |
550 | for parent in visit.pop(0).parents(): |
|
550 | for parent in visit.pop(0).parents(): | |
551 | s = str(parent) |
|
551 | s = str(parent) | |
552 | if s not in seen: |
|
552 | if s not in seen: | |
553 | visit.append(parent) |
|
553 | visit.append(parent) | |
554 | seen.add(s) |
|
554 | seen.add(s) | |
555 | yield parent |
|
555 | yield parent | |
556 |
|
556 | |||
557 | class workingctx(changectx): |
|
557 | class workingctx(changectx): | |
558 | """A workingctx object makes access to data related to |
|
558 | """A workingctx object makes access to data related to | |
559 | the current working directory convenient. |
|
559 | the current working directory convenient. | |
560 | date - any valid date string or (unixtime, offset), or None. |
|
560 | date - any valid date string or (unixtime, offset), or None. | |
561 | user - username string, or None. |
|
561 | user - username string, or None. | |
562 | extra - a dictionary of extra values, or None. |
|
562 | extra - a dictionary of extra values, or None. | |
563 | changes - a list of file lists as returned by localrepo.status() |
|
563 | changes - a list of file lists as returned by localrepo.status() | |
564 | or None to use the repository status. |
|
564 | or None to use the repository status. | |
565 | """ |
|
565 | """ | |
566 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
566 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
567 | changes=None): |
|
567 | changes=None): | |
568 | self._repo = repo |
|
568 | self._repo = repo | |
569 | self._rev = None |
|
569 | self._rev = None | |
570 | self._node = None |
|
570 | self._node = None | |
571 | self._text = text |
|
571 | self._text = text | |
572 | if date: |
|
572 | if date: | |
573 | self._date = util.parsedate(date) |
|
573 | self._date = util.parsedate(date) | |
574 | if user: |
|
574 | if user: | |
575 | self._user = user |
|
575 | self._user = user | |
576 | if changes: |
|
576 | if changes: | |
577 | self._status = list(changes[:4]) |
|
577 | self._status = list(changes[:4]) | |
578 | self._unknown = changes[4] |
|
578 | self._unknown = changes[4] | |
579 | self._ignored = changes[5] |
|
579 | self._ignored = changes[5] | |
580 | self._clean = changes[6] |
|
580 | self._clean = changes[6] | |
581 | else: |
|
581 | else: | |
582 | self._unknown = None |
|
582 | self._unknown = None | |
583 | self._ignored = None |
|
583 | self._ignored = None | |
584 | self._clean = None |
|
584 | self._clean = None | |
585 |
|
585 | |||
586 | self._extra = {} |
|
586 | self._extra = {} | |
587 | if extra: |
|
587 | if extra: | |
588 | self._extra = extra.copy() |
|
588 | self._extra = extra.copy() | |
589 | if 'branch' not in self._extra: |
|
589 | if 'branch' not in self._extra: | |
590 | branch = self._repo.dirstate.branch() |
|
590 | branch = self._repo.dirstate.branch() | |
591 | try: |
|
591 | try: | |
592 | branch = branch.decode('UTF-8').encode('UTF-8') |
|
592 | branch = branch.decode('UTF-8').encode('UTF-8') | |
593 | except UnicodeDecodeError: |
|
593 | except UnicodeDecodeError: | |
594 | raise util.Abort(_('branch name not in UTF-8!')) |
|
594 | raise util.Abort(_('branch name not in UTF-8!')) | |
595 | self._extra['branch'] = branch |
|
595 | self._extra['branch'] = branch | |
596 | if self._extra['branch'] == '': |
|
596 | if self._extra['branch'] == '': | |
597 | self._extra['branch'] = 'default' |
|
597 | self._extra['branch'] = 'default' | |
598 |
|
598 | |||
599 | def __str__(self): |
|
599 | def __str__(self): | |
600 | return str(self._parents[0]) + "+" |
|
600 | return str(self._parents[0]) + "+" | |
601 |
|
601 | |||
602 | def __nonzero__(self): |
|
602 | def __nonzero__(self): | |
603 | return True |
|
603 | return True | |
604 |
|
604 | |||
605 | def __contains__(self, key): |
|
605 | def __contains__(self, key): | |
606 | return self._repo.dirstate[key] not in "?r" |
|
606 | return self._repo.dirstate[key] not in "?r" | |
607 |
|
607 | |||
608 | @propertycache |
|
608 | @propertycache | |
609 | def _manifest(self): |
|
609 | def _manifest(self): | |
610 | """generate a manifest corresponding to the working directory""" |
|
610 | """generate a manifest corresponding to the working directory""" | |
611 |
|
611 | |||
612 | if self._unknown is None: |
|
612 | if self._unknown is None: | |
613 | self.status(unknown=True) |
|
613 | self.status(unknown=True) | |
614 |
|
614 | |||
615 | man = self._parents[0].manifest().copy() |
|
615 | man = self._parents[0].manifest().copy() | |
616 | copied = self._repo.dirstate.copies() |
|
616 | copied = self._repo.dirstate.copies() | |
617 | if len(self._parents) > 1: |
|
617 | if len(self._parents) > 1: | |
618 | man2 = self.p2().manifest() |
|
618 | man2 = self.p2().manifest() | |
619 | def getman(f): |
|
619 | def getman(f): | |
620 | if f in man: |
|
620 | if f in man: | |
621 | return man |
|
621 | return man | |
622 | return man2 |
|
622 | return man2 | |
623 | else: |
|
623 | else: | |
624 | getman = lambda f: man |
|
624 | getman = lambda f: man | |
625 | def cf(f): |
|
625 | def cf(f): | |
626 | f = copied.get(f, f) |
|
626 | f = copied.get(f, f) | |
627 | return getman(f).flags(f) |
|
627 | return getman(f).flags(f) | |
628 | ff = self._repo.dirstate.flagfunc(cf) |
|
628 | ff = self._repo.dirstate.flagfunc(cf) | |
629 | modified, added, removed, deleted = self._status |
|
629 | modified, added, removed, deleted = self._status | |
630 | unknown = self._unknown |
|
630 | unknown = self._unknown | |
631 | for i, l in (("a", added), ("m", modified), ("u", unknown)): |
|
631 | for i, l in (("a", added), ("m", modified), ("u", unknown)): | |
632 | for f in l: |
|
632 | for f in l: | |
633 | orig = copied.get(f, f) |
|
633 | orig = copied.get(f, f) | |
634 | man[f] = getman(orig).get(orig, nullid) + i |
|
634 | man[f] = getman(orig).get(orig, nullid) + i | |
635 | try: |
|
635 | try: | |
636 | man.set(f, ff(f)) |
|
636 | man.set(f, ff(f)) | |
637 | except OSError: |
|
637 | except OSError: | |
638 | pass |
|
638 | pass | |
639 |
|
639 | |||
640 | for f in deleted + removed: |
|
640 | for f in deleted + removed: | |
641 | if f in man: |
|
641 | if f in man: | |
642 | del man[f] |
|
642 | del man[f] | |
643 |
|
643 | |||
644 | return man |
|
644 | return man | |
645 |
|
645 | |||
646 | @propertycache |
|
646 | @propertycache | |
647 | def _status(self): |
|
647 | def _status(self): | |
648 | return self._repo.status()[:4] |
|
648 | return self._repo.status()[:4] | |
649 |
|
649 | |||
650 | @propertycache |
|
650 | @propertycache | |
651 | def _user(self): |
|
651 | def _user(self): | |
652 | return self._repo.ui.username() |
|
652 | return self._repo.ui.username() | |
653 |
|
653 | |||
654 | @propertycache |
|
654 | @propertycache | |
655 | def _date(self): |
|
655 | def _date(self): | |
656 | return util.makedate() |
|
656 | return util.makedate() | |
657 |
|
657 | |||
658 | @propertycache |
|
658 | @propertycache | |
659 | def _parents(self): |
|
659 | def _parents(self): | |
660 | p = self._repo.dirstate.parents() |
|
660 | p = self._repo.dirstate.parents() | |
661 | if p[1] == nullid: |
|
661 | if p[1] == nullid: | |
662 | p = p[:-1] |
|
662 | p = p[:-1] | |
663 | self._parents = [changectx(self._repo, x) for x in p] |
|
663 | self._parents = [changectx(self._repo, x) for x in p] | |
664 | return self._parents |
|
664 | return self._parents | |
665 |
|
665 | |||
666 | def status(self, ignored=False, clean=False, unknown=False): |
|
666 | def status(self, ignored=False, clean=False, unknown=False): | |
667 | """Explicit status query |
|
667 | """Explicit status query | |
668 | Unless this method is used to query the working copy status, the |
|
668 | Unless this method is used to query the working copy status, the | |
669 | _status property will implicitly read the status using its default |
|
669 | _status property will implicitly read the status using its default | |
670 | arguments.""" |
|
670 | arguments.""" | |
671 | stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown) |
|
671 | stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown) | |
672 | self._unknown = self._ignored = self._clean = None |
|
672 | self._unknown = self._ignored = self._clean = None | |
673 | if unknown: |
|
673 | if unknown: | |
674 | self._unknown = stat[4] |
|
674 | self._unknown = stat[4] | |
675 | if ignored: |
|
675 | if ignored: | |
676 | self._ignored = stat[5] |
|
676 | self._ignored = stat[5] | |
677 | if clean: |
|
677 | if clean: | |
678 | self._clean = stat[6] |
|
678 | self._clean = stat[6] | |
679 | self._status = stat[:4] |
|
679 | self._status = stat[:4] | |
680 | return stat |
|
680 | return stat | |
681 |
|
681 | |||
682 | def manifest(self): |
|
682 | def manifest(self): | |
683 | return self._manifest |
|
683 | return self._manifest | |
684 | def user(self): |
|
684 | def user(self): | |
685 | return self._user or self._repo.ui.username() |
|
685 | return self._user or self._repo.ui.username() | |
686 | def date(self): |
|
686 | def date(self): | |
687 | return self._date |
|
687 | return self._date | |
688 | def description(self): |
|
688 | def description(self): | |
689 | return self._text |
|
689 | return self._text | |
690 | def files(self): |
|
690 | def files(self): | |
691 | return sorted(self._status[0] + self._status[1] + self._status[2]) |
|
691 | return sorted(self._status[0] + self._status[1] + self._status[2]) | |
692 |
|
692 | |||
693 | def modified(self): |
|
693 | def modified(self): | |
694 | return self._status[0] |
|
694 | return self._status[0] | |
695 | def added(self): |
|
695 | def added(self): | |
696 | return self._status[1] |
|
696 | return self._status[1] | |
697 | def removed(self): |
|
697 | def removed(self): | |
698 | return self._status[2] |
|
698 | return self._status[2] | |
699 | def deleted(self): |
|
699 | def deleted(self): | |
700 | return self._status[3] |
|
700 | return self._status[3] | |
701 | def unknown(self): |
|
701 | def unknown(self): | |
702 | assert self._unknown is not None # must call status first |
|
702 | assert self._unknown is not None # must call status first | |
703 | return self._unknown |
|
703 | return self._unknown | |
704 | def ignored(self): |
|
704 | def ignored(self): | |
705 | assert self._ignored is not None # must call status first |
|
705 | assert self._ignored is not None # must call status first | |
706 | return self._ignored |
|
706 | return self._ignored | |
707 | def clean(self): |
|
707 | def clean(self): | |
708 | assert self._clean is not None # must call status first |
|
708 | assert self._clean is not None # must call status first | |
709 | return self._clean |
|
709 | return self._clean | |
710 | def branch(self): |
|
710 | def branch(self): | |
711 | return self._extra['branch'] |
|
711 | return self._extra['branch'] | |
712 | def extra(self): |
|
712 | def extra(self): | |
713 | return self._extra |
|
713 | return self._extra | |
714 |
|
714 | |||
715 | def tags(self): |
|
715 | def tags(self): | |
716 | t = [] |
|
716 | t = [] | |
717 | [t.extend(p.tags()) for p in self.parents()] |
|
717 | [t.extend(p.tags()) for p in self.parents()] | |
718 | return t |
|
718 | return t | |
719 |
|
719 | |||
720 | def children(self): |
|
720 | def children(self): | |
721 | return [] |
|
721 | return [] | |
722 |
|
722 | |||
723 | def flags(self, path): |
|
723 | def flags(self, path): | |
724 | if '_manifest' in self.__dict__: |
|
724 | if '_manifest' in self.__dict__: | |
725 | try: |
|
725 | try: | |
726 | return self._manifest.flags(path) |
|
726 | return self._manifest.flags(path) | |
727 | except KeyError: |
|
727 | except KeyError: | |
728 | return '' |
|
728 | return '' | |
729 |
|
729 | |||
730 | orig = self._repo.dirstate.copies().get(path, path) |
|
730 | orig = self._repo.dirstate.copies().get(path, path) | |
731 |
|
731 | |||
732 | def findflag(ctx): |
|
732 | def findflag(ctx): | |
733 | mnode = ctx.changeset()[0] |
|
733 | mnode = ctx.changeset()[0] | |
734 | node, flag = self._repo.manifest.find(mnode, orig) |
|
734 | node, flag = self._repo.manifest.find(mnode, orig) | |
735 | ff = self._repo.dirstate.flagfunc(lambda x: flag or '') |
|
735 | ff = self._repo.dirstate.flagfunc(lambda x: flag or '') | |
736 | try: |
|
736 | try: | |
737 | return ff(path) |
|
737 | return ff(path) | |
738 | except OSError: |
|
738 | except OSError: | |
739 | pass |
|
739 | pass | |
740 |
|
740 | |||
741 | flag = findflag(self._parents[0]) |
|
741 | flag = findflag(self._parents[0]) | |
742 | if flag is None and len(self.parents()) > 1: |
|
742 | if flag is None and len(self.parents()) > 1: | |
743 | flag = findflag(self._parents[1]) |
|
743 | flag = findflag(self._parents[1]) | |
744 | if flag is None or self._repo.dirstate[path] == 'r': |
|
744 | if flag is None or self._repo.dirstate[path] == 'r': | |
745 | return '' |
|
745 | return '' | |
746 | return flag |
|
746 | return flag | |
747 |
|
747 | |||
748 | def filectx(self, path, filelog=None): |
|
748 | def filectx(self, path, filelog=None): | |
749 | """get a file context from the working directory""" |
|
749 | """get a file context from the working directory""" | |
750 | return workingfilectx(self._repo, path, workingctx=self, |
|
750 | return workingfilectx(self._repo, path, workingctx=self, | |
751 | filelog=filelog) |
|
751 | filelog=filelog) | |
752 |
|
752 | |||
753 | def ancestor(self, c2): |
|
753 | def ancestor(self, c2): | |
754 | """return the ancestor context of self and c2""" |
|
754 | """return the ancestor context of self and c2""" | |
755 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
755 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
756 |
|
756 | |||
757 | def walk(self, match): |
|
757 | def walk(self, match): | |
758 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), |
|
758 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), | |
759 | True, False)) |
|
759 | True, False)) | |
760 |
|
760 | |||
761 | def dirty(self, missing=False): |
|
761 | def dirty(self, missing=False): | |
762 | "check whether a working directory is modified" |
|
762 | "check whether a working directory is modified" | |
763 | # check subrepos first |
|
763 | # check subrepos first | |
764 | for s in self.substate: |
|
764 | for s in self.substate: | |
765 | if self.sub(s).dirty(): |
|
765 | if self.sub(s).dirty(): | |
766 | return True |
|
766 | return True | |
767 | # check current working dir |
|
767 | # check current working dir | |
768 | return (self.p2() or self.branch() != self.p1().branch() or |
|
768 | return (self.p2() or self.branch() != self.p1().branch() or | |
769 | self.modified() or self.added() or self.removed() or |
|
769 | self.modified() or self.added() or self.removed() or | |
770 | (missing and self.deleted())) |
|
770 | (missing and self.deleted())) | |
771 |
|
771 | |||
772 | def add(self, list): |
|
772 | def add(self, list): | |
773 | wlock = self._repo.wlock() |
|
773 | wlock = self._repo.wlock() | |
774 | ui, ds = self._repo.ui, self._repo.dirstate |
|
774 | ui, ds = self._repo.ui, self._repo.dirstate | |
775 | try: |
|
775 | try: | |
776 | rejected = [] |
|
776 | rejected = [] | |
777 | for f in list: |
|
777 | for f in list: | |
778 | p = self._repo.wjoin(f) |
|
778 | p = self._repo.wjoin(f) | |
779 | try: |
|
779 | try: | |
780 | st = os.lstat(p) |
|
780 | st = os.lstat(p) | |
781 | except: |
|
781 | except: | |
782 | ui.warn(_("%s does not exist!\n") % f) |
|
782 | ui.warn(_("%s does not exist!\n") % f) | |
783 | rejected.append(f) |
|
783 | rejected.append(f) | |
784 | continue |
|
784 | continue | |
785 | if st.st_size > 10000000: |
|
785 | if st.st_size > 10000000: | |
786 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
786 | ui.warn(_("%s: up to %d MB of RAM may be required " | |
787 | "to manage this file\n" |
|
787 | "to manage this file\n" | |
788 | "(use 'hg revert %s' to cancel the " |
|
788 | "(use 'hg revert %s' to cancel the " | |
789 | "pending addition)\n") |
|
789 | "pending addition)\n") | |
790 | % (f, 3 * st.st_size // 1000000, f)) |
|
790 | % (f, 3 * st.st_size // 1000000, f)) | |
791 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
791 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
792 | ui.warn(_("%s not added: only files and symlinks " |
|
792 | ui.warn(_("%s not added: only files and symlinks " | |
793 | "supported currently\n") % f) |
|
793 | "supported currently\n") % f) | |
794 | rejected.append(p) |
|
794 | rejected.append(p) | |
795 | elif ds[f] in 'amn': |
|
795 | elif ds[f] in 'amn': | |
796 | ui.warn(_("%s already tracked!\n") % f) |
|
796 | ui.warn(_("%s already tracked!\n") % f) | |
797 | elif ds[f] == 'r': |
|
797 | elif ds[f] == 'r': | |
798 | ds.normallookup(f) |
|
798 | ds.normallookup(f) | |
799 | else: |
|
799 | else: | |
800 | ds.add(f) |
|
800 | ds.add(f) | |
801 | return rejected |
|
801 | return rejected | |
802 | finally: |
|
802 | finally: | |
803 | wlock.release() |
|
803 | wlock.release() | |
804 |
|
804 | |||
805 | def forget(self, list): |
|
805 | def forget(self, list): | |
806 | wlock = self._repo.wlock() |
|
806 | wlock = self._repo.wlock() | |
807 | try: |
|
807 | try: | |
808 | for f in list: |
|
808 | for f in list: | |
809 | if self._repo.dirstate[f] != 'a': |
|
809 | if self._repo.dirstate[f] != 'a': | |
810 | self._repo.ui.warn(_("%s not added!\n") % f) |
|
810 | self._repo.ui.warn(_("%s not added!\n") % f) | |
811 | else: |
|
811 | else: | |
812 | self._repo.dirstate.forget(f) |
|
812 | self._repo.dirstate.forget(f) | |
813 | finally: |
|
813 | finally: | |
814 | wlock.release() |
|
814 | wlock.release() | |
815 |
|
815 | |||
816 | def remove(self, list, unlink=False): |
|
816 | def remove(self, list, unlink=False): | |
817 | if unlink: |
|
817 | if unlink: | |
818 | for f in list: |
|
818 | for f in list: | |
819 | try: |
|
819 | try: | |
820 | util.unlink(self._repo.wjoin(f)) |
|
820 | util.unlink(self._repo.wjoin(f)) | |
821 | except OSError, inst: |
|
821 | except OSError, inst: | |
822 | if inst.errno != errno.ENOENT: |
|
822 | if inst.errno != errno.ENOENT: | |
823 | raise |
|
823 | raise | |
824 | wlock = self._repo.wlock() |
|
824 | wlock = self._repo.wlock() | |
825 | try: |
|
825 | try: | |
826 | for f in list: |
|
826 | for f in list: | |
827 | if unlink and os.path.exists(self._repo.wjoin(f)): |
|
827 | if unlink and os.path.exists(self._repo.wjoin(f)): | |
828 | self._repo.ui.warn(_("%s still exists!\n") % f) |
|
828 | self._repo.ui.warn(_("%s still exists!\n") % f) | |
829 | elif self._repo.dirstate[f] == 'a': |
|
829 | elif self._repo.dirstate[f] == 'a': | |
830 | self._repo.dirstate.forget(f) |
|
830 | self._repo.dirstate.forget(f) | |
831 | elif f not in self._repo.dirstate: |
|
831 | elif f not in self._repo.dirstate: | |
832 | self._repo.ui.warn(_("%s not tracked!\n") % f) |
|
832 | self._repo.ui.warn(_("%s not tracked!\n") % f) | |
833 | else: |
|
833 | else: | |
834 | self._repo.dirstate.remove(f) |
|
834 | self._repo.dirstate.remove(f) | |
835 | finally: |
|
835 | finally: | |
836 | wlock.release() |
|
836 | wlock.release() | |
837 |
|
837 | |||
838 | def undelete(self, list): |
|
838 | def undelete(self, list): | |
839 | pctxs = self.parents() |
|
839 | pctxs = self.parents() | |
840 | wlock = self._repo.wlock() |
|
840 | wlock = self._repo.wlock() | |
841 | try: |
|
841 | try: | |
842 | for f in list: |
|
842 | for f in list: | |
843 | if self._repo.dirstate[f] != 'r': |
|
843 | if self._repo.dirstate[f] != 'r': | |
844 | self._repo.ui.warn(_("%s not removed!\n") % f) |
|
844 | self._repo.ui.warn(_("%s not removed!\n") % f) | |
845 | else: |
|
845 | else: | |
846 | fctx = f in pctxs[0] and pctxs[0] or pctxs[1] |
|
846 | fctx = f in pctxs[0] and pctxs[0] or pctxs[1] | |
847 | t = fctx.data() |
|
847 | t = fctx.data() | |
848 | self._repo.wwrite(f, t, fctx.flags()) |
|
848 | self._repo.wwrite(f, t, fctx.flags()) | |
849 | self._repo.dirstate.normal(f) |
|
849 | self._repo.dirstate.normal(f) | |
850 | finally: |
|
850 | finally: | |
851 | wlock.release() |
|
851 | wlock.release() | |
852 |
|
852 | |||
853 | def copy(self, source, dest): |
|
853 | def copy(self, source, dest): | |
854 | p = self._repo.wjoin(dest) |
|
854 | p = self._repo.wjoin(dest) | |
855 | if not (os.path.exists(p) or os.path.islink(p)): |
|
855 | if not (os.path.exists(p) or os.path.islink(p)): | |
856 | self._repo.ui.warn(_("%s does not exist!\n") % dest) |
|
856 | self._repo.ui.warn(_("%s does not exist!\n") % dest) | |
857 | elif not (os.path.isfile(p) or os.path.islink(p)): |
|
857 | elif not (os.path.isfile(p) or os.path.islink(p)): | |
858 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
858 | self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
859 | "symbolic link\n") % dest) |
|
859 | "symbolic link\n") % dest) | |
860 | else: |
|
860 | else: | |
861 | wlock = self._repo.wlock() |
|
861 | wlock = self._repo.wlock() | |
862 | try: |
|
862 | try: | |
863 | if self._repo.dirstate[dest] in '?r': |
|
863 | if self._repo.dirstate[dest] in '?r': | |
864 | self._repo.dirstate.add(dest) |
|
864 | self._repo.dirstate.add(dest) | |
865 | self._repo.dirstate.copy(source, dest) |
|
865 | self._repo.dirstate.copy(source, dest) | |
866 | finally: |
|
866 | finally: | |
867 | wlock.release() |
|
867 | wlock.release() | |
868 |
|
868 | |||
869 | class workingfilectx(filectx): |
|
869 | class workingfilectx(filectx): | |
870 | """A workingfilectx object makes access to data related to a particular |
|
870 | """A workingfilectx object makes access to data related to a particular | |
871 | file in the working directory convenient.""" |
|
871 | file in the working directory convenient.""" | |
872 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
872 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
873 | """changeid can be a changeset revision, node, or tag. |
|
873 | """changeid can be a changeset revision, node, or tag. | |
874 | fileid can be a file revision or node.""" |
|
874 | fileid can be a file revision or node.""" | |
875 | self._repo = repo |
|
875 | self._repo = repo | |
876 | self._path = path |
|
876 | self._path = path | |
877 | self._changeid = None |
|
877 | self._changeid = None | |
878 | self._filerev = self._filenode = None |
|
878 | self._filerev = self._filenode = None | |
879 |
|
879 | |||
880 | if filelog: |
|
880 | if filelog: | |
881 | self._filelog = filelog |
|
881 | self._filelog = filelog | |
882 | if workingctx: |
|
882 | if workingctx: | |
883 | self._changectx = workingctx |
|
883 | self._changectx = workingctx | |
884 |
|
884 | |||
885 | @propertycache |
|
885 | @propertycache | |
886 | def _changectx(self): |
|
886 | def _changectx(self): | |
887 | return workingctx(self._repo) |
|
887 | return workingctx(self._repo) | |
888 |
|
888 | |||
889 | def __nonzero__(self): |
|
889 | def __nonzero__(self): | |
890 | return True |
|
890 | return True | |
891 |
|
891 | |||
892 | def __str__(self): |
|
892 | def __str__(self): | |
893 | return "%s@%s" % (self.path(), self._changectx) |
|
893 | return "%s@%s" % (self.path(), self._changectx) | |
894 |
|
894 | |||
895 | def data(self): |
|
895 | def data(self): | |
896 | return self._repo.wread(self._path) |
|
896 | return self._repo.wread(self._path) | |
897 | def renamed(self): |
|
897 | def renamed(self): | |
898 | rp = self._repo.dirstate.copied(self._path) |
|
898 | rp = self._repo.dirstate.copied(self._path) | |
899 | if not rp: |
|
899 | if not rp: | |
900 | return None |
|
900 | return None | |
901 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
901 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
902 |
|
902 | |||
903 | def parents(self): |
|
903 | def parents(self): | |
904 | '''return parent filectxs, following copies if necessary''' |
|
904 | '''return parent filectxs, following copies if necessary''' | |
905 | def filenode(ctx, path): |
|
905 | def filenode(ctx, path): | |
906 | return ctx._manifest.get(path, nullid) |
|
906 | return ctx._manifest.get(path, nullid) | |
907 |
|
907 | |||
908 | path = self._path |
|
908 | path = self._path | |
909 | fl = self._filelog |
|
909 | fl = self._filelog | |
910 | pcl = self._changectx._parents |
|
910 | pcl = self._changectx._parents | |
911 | renamed = self.renamed() |
|
911 | renamed = self.renamed() | |
912 |
|
912 | |||
913 | if renamed: |
|
913 | if renamed: | |
914 | pl = [renamed + (None,)] |
|
914 | pl = [renamed + (None,)] | |
915 | else: |
|
915 | else: | |
916 | pl = [(path, filenode(pcl[0], path), fl)] |
|
916 | pl = [(path, filenode(pcl[0], path), fl)] | |
917 |
|
917 | |||
918 | for pc in pcl[1:]: |
|
918 | for pc in pcl[1:]: | |
919 | pl.append((path, filenode(pc, path), fl)) |
|
919 | pl.append((path, filenode(pc, path), fl)) | |
920 |
|
920 | |||
921 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
921 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
922 | for p, n, l in pl if n != nullid] |
|
922 | for p, n, l in pl if n != nullid] | |
923 |
|
923 | |||
924 | def children(self): |
|
924 | def children(self): | |
925 | return [] |
|
925 | return [] | |
926 |
|
926 | |||
927 | def size(self): |
|
927 | def size(self): | |
928 | return os.lstat(self._repo.wjoin(self._path)).st_size |
|
928 | return os.lstat(self._repo.wjoin(self._path)).st_size | |
929 | def date(self): |
|
929 | def date(self): | |
930 | t, tz = self._changectx.date() |
|
930 | t, tz = self._changectx.date() | |
931 | try: |
|
931 | try: | |
932 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
|
932 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) | |
933 | except OSError, err: |
|
933 | except OSError, err: | |
934 | if err.errno != errno.ENOENT: |
|
934 | if err.errno != errno.ENOENT: | |
935 | raise |
|
935 | raise | |
936 | return (t, tz) |
|
936 | return (t, tz) | |
937 |
|
937 | |||
938 | def cmp(self, fctx): |
|
938 | def cmp(self, fctx): | |
939 | """compare with other file context |
|
939 | """compare with other file context | |
940 |
|
940 | |||
941 | returns True if different than fctx. |
|
941 | returns True if different than fctx. | |
942 | """ |
|
942 | """ | |
943 | # fctx should be a filectx (not a wfctx) |
|
943 | # fctx should be a filectx (not a wfctx) | |
944 | # invert comparison to reuse the same code path |
|
944 | # invert comparison to reuse the same code path | |
945 | return fctx.cmp(self) |
|
945 | return fctx.cmp(self) | |
946 |
|
946 | |||
947 | class memctx(object): |
|
947 | class memctx(object): | |
948 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
948 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
949 |
|
949 | |||
950 | Revision information is supplied at initialization time while |
|
950 | Revision information is supplied at initialization time while | |
951 | related files data and is made available through a callback |
|
951 | related files data and is made available through a callback | |
952 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
952 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
953 | sequence of two parent revisions identifiers (pass None for every |
|
953 | sequence of two parent revisions identifiers (pass None for every | |
954 | missing parent), 'text' is the commit message and 'files' lists |
|
954 | missing parent), 'text' is the commit message and 'files' lists | |
955 | names of files touched by the revision (normalized and relative to |
|
955 | names of files touched by the revision (normalized and relative to | |
956 | repository root). |
|
956 | repository root). | |
957 |
|
957 | |||
958 | filectxfn(repo, memctx, path) is a callable receiving the |
|
958 | filectxfn(repo, memctx, path) is a callable receiving the | |
959 | repository, the current memctx object and the normalized path of |
|
959 | repository, the current memctx object and the normalized path of | |
960 | requested file, relative to repository root. It is fired by the |
|
960 | requested file, relative to repository root. It is fired by the | |
961 | commit function for every file in 'files', but calls order is |
|
961 | commit function for every file in 'files', but calls order is | |
962 | undefined. If the file is available in the revision being |
|
962 | undefined. If the file is available in the revision being | |
963 | committed (updated or added), filectxfn returns a memfilectx |
|
963 | committed (updated or added), filectxfn returns a memfilectx | |
964 | object. If the file was removed, filectxfn raises an |
|
964 | object. If the file was removed, filectxfn raises an | |
965 | IOError. Moved files are represented by marking the source file |
|
965 | IOError. Moved files are represented by marking the source file | |
966 | removed and the new file added with copy information (see |
|
966 | removed and the new file added with copy information (see | |
967 | memfilectx). |
|
967 | memfilectx). | |
968 |
|
968 | |||
969 | user receives the committer name and defaults to current |
|
969 | user receives the committer name and defaults to current | |
970 | repository username, date is the commit date in any format |
|
970 | repository username, date is the commit date in any format | |
971 | supported by util.parsedate() and defaults to current date, extra |
|
971 | supported by util.parsedate() and defaults to current date, extra | |
972 | is a dictionary of metadata or is left empty. |
|
972 | is a dictionary of metadata or is left empty. | |
973 | """ |
|
973 | """ | |
974 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
974 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
975 | date=None, extra=None): |
|
975 | date=None, extra=None): | |
976 | self._repo = repo |
|
976 | self._repo = repo | |
977 | self._rev = None |
|
977 | self._rev = None | |
978 | self._node = None |
|
978 | self._node = None | |
979 | self._text = text |
|
979 | self._text = text | |
980 | self._date = date and util.parsedate(date) or util.makedate() |
|
980 | self._date = date and util.parsedate(date) or util.makedate() | |
981 | self._user = user |
|
981 | self._user = user | |
982 | parents = [(p or nullid) for p in parents] |
|
982 | parents = [(p or nullid) for p in parents] | |
983 | p1, p2 = parents |
|
983 | p1, p2 = parents | |
984 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
984 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
985 | files = sorted(set(files)) |
|
985 | files = sorted(set(files)) | |
986 | self._status = [files, [], [], [], []] |
|
986 | self._status = [files, [], [], [], []] | |
987 | self._filectxfn = filectxfn |
|
987 | self._filectxfn = filectxfn | |
988 |
|
988 | |||
989 | self._extra = extra and extra.copy() or {} |
|
989 | self._extra = extra and extra.copy() or {} | |
990 | if 'branch' not in self._extra: |
|
990 | if 'branch' not in self._extra: | |
991 | self._extra['branch'] = 'default' |
|
991 | self._extra['branch'] = 'default' | |
992 | elif self._extra.get('branch') == '': |
|
992 | elif self._extra.get('branch') == '': | |
993 | self._extra['branch'] = 'default' |
|
993 | self._extra['branch'] = 'default' | |
994 |
|
994 | |||
995 | def __str__(self): |
|
995 | def __str__(self): | |
996 | return str(self._parents[0]) + "+" |
|
996 | return str(self._parents[0]) + "+" | |
997 |
|
997 | |||
998 | def __int__(self): |
|
998 | def __int__(self): | |
999 | return self._rev |
|
999 | return self._rev | |
1000 |
|
1000 | |||
1001 | def __nonzero__(self): |
|
1001 | def __nonzero__(self): | |
1002 | return True |
|
1002 | return True | |
1003 |
|
1003 | |||
1004 | def __getitem__(self, key): |
|
1004 | def __getitem__(self, key): | |
1005 | return self.filectx(key) |
|
1005 | return self.filectx(key) | |
1006 |
|
1006 | |||
1007 | def p1(self): |
|
1007 | def p1(self): | |
1008 | return self._parents[0] |
|
1008 | return self._parents[0] | |
1009 | def p2(self): |
|
1009 | def p2(self): | |
1010 | return self._parents[1] |
|
1010 | return self._parents[1] | |
1011 |
|
1011 | |||
1012 | def user(self): |
|
1012 | def user(self): | |
1013 | return self._user or self._repo.ui.username() |
|
1013 | return self._user or self._repo.ui.username() | |
1014 | def date(self): |
|
1014 | def date(self): | |
1015 | return self._date |
|
1015 | return self._date | |
1016 | def description(self): |
|
1016 | def description(self): | |
1017 | return self._text |
|
1017 | return self._text | |
1018 | def files(self): |
|
1018 | def files(self): | |
1019 | return self.modified() |
|
1019 | return self.modified() | |
1020 | def modified(self): |
|
1020 | def modified(self): | |
1021 | return self._status[0] |
|
1021 | return self._status[0] | |
1022 | def added(self): |
|
1022 | def added(self): | |
1023 | return self._status[1] |
|
1023 | return self._status[1] | |
1024 | def removed(self): |
|
1024 | def removed(self): | |
1025 | return self._status[2] |
|
1025 | return self._status[2] | |
1026 | def deleted(self): |
|
1026 | def deleted(self): | |
1027 | return self._status[3] |
|
1027 | return self._status[3] | |
1028 | def unknown(self): |
|
1028 | def unknown(self): | |
1029 | return self._status[4] |
|
1029 | return self._status[4] | |
1030 | def ignored(self): |
|
1030 | def ignored(self): | |
1031 | return self._status[5] |
|
1031 | return self._status[5] | |
1032 | def clean(self): |
|
1032 | def clean(self): | |
1033 | return self._status[6] |
|
1033 | return self._status[6] | |
1034 | def branch(self): |
|
1034 | def branch(self): | |
1035 | return self._extra['branch'] |
|
1035 | return self._extra['branch'] | |
1036 | def extra(self): |
|
1036 | def extra(self): | |
1037 | return self._extra |
|
1037 | return self._extra | |
1038 | def flags(self, f): |
|
1038 | def flags(self, f): | |
1039 | return self[f].flags() |
|
1039 | return self[f].flags() | |
1040 |
|
1040 | |||
1041 | def parents(self): |
|
1041 | def parents(self): | |
1042 | """return contexts for each parent changeset""" |
|
1042 | """return contexts for each parent changeset""" | |
1043 | return self._parents |
|
1043 | return self._parents | |
1044 |
|
1044 | |||
1045 | def filectx(self, path, filelog=None): |
|
1045 | def filectx(self, path, filelog=None): | |
1046 | """get a file context from the working directory""" |
|
1046 | """get a file context from the working directory""" | |
1047 | return self._filectxfn(self._repo, self, path) |
|
1047 | return self._filectxfn(self._repo, self, path) | |
1048 |
|
1048 | |||
1049 | def commit(self): |
|
1049 | def commit(self): | |
1050 | """commit context to the repo""" |
|
1050 | """commit context to the repo""" | |
1051 | return self._repo.commitctx(self) |
|
1051 | return self._repo.commitctx(self) | |
1052 |
|
1052 | |||
1053 | class memfilectx(object): |
|
1053 | class memfilectx(object): | |
1054 | """memfilectx represents an in-memory file to commit. |
|
1054 | """memfilectx represents an in-memory file to commit. | |
1055 |
|
1055 | |||
1056 | See memctx for more details. |
|
1056 | See memctx for more details. | |
1057 | """ |
|
1057 | """ | |
1058 | def __init__(self, path, data, islink=False, isexec=False, copied=None): |
|
1058 | def __init__(self, path, data, islink=False, isexec=False, copied=None): | |
1059 | """ |
|
1059 | """ | |
1060 | path is the normalized file path relative to repository root. |
|
1060 | path is the normalized file path relative to repository root. | |
1061 | data is the file content as a string. |
|
1061 | data is the file content as a string. | |
1062 | islink is True if the file is a symbolic link. |
|
1062 | islink is True if the file is a symbolic link. | |
1063 | isexec is True if the file is executable. |
|
1063 | isexec is True if the file is executable. | |
1064 | copied is the source file path if current file was copied in the |
|
1064 | copied is the source file path if current file was copied in the | |
1065 | revision being committed, or None.""" |
|
1065 | revision being committed, or None.""" | |
1066 | self._path = path |
|
1066 | self._path = path | |
1067 | self._data = data |
|
1067 | self._data = data | |
1068 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
1068 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
1069 | self._copied = None |
|
1069 | self._copied = None | |
1070 | if copied: |
|
1070 | if copied: | |
1071 | self._copied = (copied, nullid) |
|
1071 | self._copied = (copied, nullid) | |
1072 |
|
1072 | |||
1073 | def __nonzero__(self): |
|
1073 | def __nonzero__(self): | |
1074 | return True |
|
1074 | return True | |
1075 | def __str__(self): |
|
1075 | def __str__(self): | |
1076 | return "%s@%s" % (self.path(), self._changectx) |
|
1076 | return "%s@%s" % (self.path(), self._changectx) | |
1077 | def path(self): |
|
1077 | def path(self): | |
1078 | return self._path |
|
1078 | return self._path | |
1079 | def data(self): |
|
1079 | def data(self): | |
1080 | return self._data |
|
1080 | return self._data | |
1081 | def flags(self): |
|
1081 | def flags(self): | |
1082 | return self._flags |
|
1082 | return self._flags | |
1083 | def isexec(self): |
|
1083 | def isexec(self): | |
1084 | return 'x' in self._flags |
|
1084 | return 'x' in self._flags | |
1085 | def islink(self): |
|
1085 | def islink(self): | |
1086 | return 'l' in self._flags |
|
1086 | return 'l' in self._flags | |
1087 | def renamed(self): |
|
1087 | def renamed(self): | |
1088 | return self._copied |
|
1088 | return self._copied |
@@ -1,429 +1,440 b'' | |||||
1 | # subrepo.py - sub-repository handling for Mercurial |
|
1 | # subrepo.py - sub-repository handling for Mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2009-2010 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2009-2010 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 | import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath |
|
8 | import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import config, util, node, error |
|
10 | import config, util, node, error | |
11 | hg = None |
|
11 | hg = None | |
12 |
|
12 | |||
13 | nullstate = ('', '', 'empty') |
|
13 | nullstate = ('', '', 'empty') | |
14 |
|
14 | |||
15 | def state(ctx): |
|
15 | def state(ctx, ui): | |
16 | """return a state dict, mapping subrepo paths configured in .hgsub |
|
16 | """return a state dict, mapping subrepo paths configured in .hgsub | |
17 | to tuple: (source from .hgsub, revision from .hgsubstate, kind |
|
17 | to tuple: (source from .hgsub, revision from .hgsubstate, kind | |
18 | (key in types dict)) |
|
18 | (key in types dict)) | |
19 | """ |
|
19 | """ | |
20 | p = config.config() |
|
20 | p = config.config() | |
21 | def read(f, sections=None, remap=None): |
|
21 | def read(f, sections=None, remap=None): | |
22 | if f in ctx: |
|
22 | if f in ctx: | |
23 | p.parse(f, ctx[f].data(), sections, remap, read) |
|
23 | p.parse(f, ctx[f].data(), sections, remap, read) | |
24 | else: |
|
24 | else: | |
25 | raise util.Abort(_("subrepo spec file %s not found") % f) |
|
25 | raise util.Abort(_("subrepo spec file %s not found") % f) | |
26 |
|
26 | |||
27 | if '.hgsub' in ctx: |
|
27 | if '.hgsub' in ctx: | |
28 | read('.hgsub') |
|
28 | read('.hgsub') | |
29 |
|
29 | |||
|
30 | for path, src in ui.configitems('subpaths'): | |||
|
31 | p.set('subpaths', path, src, ui.configsource('subpaths', path)) | |||
|
32 | ||||
30 | rev = {} |
|
33 | rev = {} | |
31 | if '.hgsubstate' in ctx: |
|
34 | if '.hgsubstate' in ctx: | |
32 | try: |
|
35 | try: | |
33 | for l in ctx['.hgsubstate'].data().splitlines(): |
|
36 | for l in ctx['.hgsubstate'].data().splitlines(): | |
34 | revision, path = l.split(" ", 1) |
|
37 | revision, path = l.split(" ", 1) | |
35 | rev[path] = revision |
|
38 | rev[path] = revision | |
36 | except IOError, err: |
|
39 | except IOError, err: | |
37 | if err.errno != errno.ENOENT: |
|
40 | if err.errno != errno.ENOENT: | |
38 | raise |
|
41 | raise | |
39 |
|
42 | |||
40 | state = {} |
|
43 | state = {} | |
41 | for path, src in p[''].items(): |
|
44 | for path, src in p[''].items(): | |
42 | kind = 'hg' |
|
45 | kind = 'hg' | |
43 | if src.startswith('['): |
|
46 | if src.startswith('['): | |
44 | if ']' not in src: |
|
47 | if ']' not in src: | |
45 | raise util.Abort(_('missing ] in subrepo source')) |
|
48 | raise util.Abort(_('missing ] in subrepo source')) | |
46 | kind, src = src.split(']', 1) |
|
49 | kind, src = src.split(']', 1) | |
47 | kind = kind[1:] |
|
50 | kind = kind[1:] | |
|
51 | ||||
|
52 | for pattern, repl in p.items('subpaths'): | |||
|
53 | try: | |||
|
54 | src = re.sub(pattern, repl, src, 1) | |||
|
55 | except re.error, e: | |||
|
56 | raise util.Abort(_("bad subrepository pattern in %s: %s") | |||
|
57 | % (p.source('subpaths', pattern), e)) | |||
|
58 | ||||
48 | state[path] = (src.strip(), rev.get(path, ''), kind) |
|
59 | state[path] = (src.strip(), rev.get(path, ''), kind) | |
49 |
|
60 | |||
50 | return state |
|
61 | return state | |
51 |
|
62 | |||
52 | def writestate(repo, state): |
|
63 | def writestate(repo, state): | |
53 | """rewrite .hgsubstate in (outer) repo with these subrepo states""" |
|
64 | """rewrite .hgsubstate in (outer) repo with these subrepo states""" | |
54 | repo.wwrite('.hgsubstate', |
|
65 | repo.wwrite('.hgsubstate', | |
55 | ''.join(['%s %s\n' % (state[s][1], s) |
|
66 | ''.join(['%s %s\n' % (state[s][1], s) | |
56 | for s in sorted(state)]), '') |
|
67 | for s in sorted(state)]), '') | |
57 |
|
68 | |||
58 | def submerge(repo, wctx, mctx, actx): |
|
69 | def submerge(repo, wctx, mctx, actx): | |
59 | """delegated from merge.applyupdates: merging of .hgsubstate file |
|
70 | """delegated from merge.applyupdates: merging of .hgsubstate file | |
60 | in working context, merging context and ancestor context""" |
|
71 | in working context, merging context and ancestor context""" | |
61 | if mctx == actx: # backwards? |
|
72 | if mctx == actx: # backwards? | |
62 | actx = wctx.p1() |
|
73 | actx = wctx.p1() | |
63 | s1 = wctx.substate |
|
74 | s1 = wctx.substate | |
64 | s2 = mctx.substate |
|
75 | s2 = mctx.substate | |
65 | sa = actx.substate |
|
76 | sa = actx.substate | |
66 | sm = {} |
|
77 | sm = {} | |
67 |
|
78 | |||
68 | repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx)) |
|
79 | repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx)) | |
69 |
|
80 | |||
70 | def debug(s, msg, r=""): |
|
81 | def debug(s, msg, r=""): | |
71 | if r: |
|
82 | if r: | |
72 | r = "%s:%s:%s" % r |
|
83 | r = "%s:%s:%s" % r | |
73 | repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r)) |
|
84 | repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r)) | |
74 |
|
85 | |||
75 | for s, l in s1.items(): |
|
86 | for s, l in s1.items(): | |
76 | a = sa.get(s, nullstate) |
|
87 | a = sa.get(s, nullstate) | |
77 | ld = l # local state with possible dirty flag for compares |
|
88 | ld = l # local state with possible dirty flag for compares | |
78 | if wctx.sub(s).dirty(): |
|
89 | if wctx.sub(s).dirty(): | |
79 | ld = (l[0], l[1] + "+") |
|
90 | ld = (l[0], l[1] + "+") | |
80 | if wctx == actx: # overwrite |
|
91 | if wctx == actx: # overwrite | |
81 | a = ld |
|
92 | a = ld | |
82 |
|
93 | |||
83 | if s in s2: |
|
94 | if s in s2: | |
84 | r = s2[s] |
|
95 | r = s2[s] | |
85 | if ld == r or r == a: # no change or local is newer |
|
96 | if ld == r or r == a: # no change or local is newer | |
86 | sm[s] = l |
|
97 | sm[s] = l | |
87 | continue |
|
98 | continue | |
88 | elif ld == a: # other side changed |
|
99 | elif ld == a: # other side changed | |
89 | debug(s, "other changed, get", r) |
|
100 | debug(s, "other changed, get", r) | |
90 | wctx.sub(s).get(r) |
|
101 | wctx.sub(s).get(r) | |
91 | sm[s] = r |
|
102 | sm[s] = r | |
92 | elif ld[0] != r[0]: # sources differ |
|
103 | elif ld[0] != r[0]: # sources differ | |
93 | if repo.ui.promptchoice( |
|
104 | if repo.ui.promptchoice( | |
94 | _(' subrepository sources for %s differ\n' |
|
105 | _(' subrepository sources for %s differ\n' | |
95 | 'use (l)ocal source (%s) or (r)emote source (%s)?') |
|
106 | 'use (l)ocal source (%s) or (r)emote source (%s)?') | |
96 | % (s, l[0], r[0]), |
|
107 | % (s, l[0], r[0]), | |
97 | (_('&Local'), _('&Remote')), 0): |
|
108 | (_('&Local'), _('&Remote')), 0): | |
98 | debug(s, "prompt changed, get", r) |
|
109 | debug(s, "prompt changed, get", r) | |
99 | wctx.sub(s).get(r) |
|
110 | wctx.sub(s).get(r) | |
100 | sm[s] = r |
|
111 | sm[s] = r | |
101 | elif ld[1] == a[1]: # local side is unchanged |
|
112 | elif ld[1] == a[1]: # local side is unchanged | |
102 | debug(s, "other side changed, get", r) |
|
113 | debug(s, "other side changed, get", r) | |
103 | wctx.sub(s).get(r) |
|
114 | wctx.sub(s).get(r) | |
104 | sm[s] = r |
|
115 | sm[s] = r | |
105 | else: |
|
116 | else: | |
106 | debug(s, "both sides changed, merge with", r) |
|
117 | debug(s, "both sides changed, merge with", r) | |
107 | wctx.sub(s).merge(r) |
|
118 | wctx.sub(s).merge(r) | |
108 | sm[s] = l |
|
119 | sm[s] = l | |
109 | elif ld == a: # remote removed, local unchanged |
|
120 | elif ld == a: # remote removed, local unchanged | |
110 | debug(s, "remote removed, remove") |
|
121 | debug(s, "remote removed, remove") | |
111 | wctx.sub(s).remove() |
|
122 | wctx.sub(s).remove() | |
112 | else: |
|
123 | else: | |
113 | if repo.ui.promptchoice( |
|
124 | if repo.ui.promptchoice( | |
114 | _(' local changed subrepository %s which remote removed\n' |
|
125 | _(' local changed subrepository %s which remote removed\n' | |
115 | 'use (c)hanged version or (d)elete?') % s, |
|
126 | 'use (c)hanged version or (d)elete?') % s, | |
116 | (_('&Changed'), _('&Delete')), 0): |
|
127 | (_('&Changed'), _('&Delete')), 0): | |
117 | debug(s, "prompt remove") |
|
128 | debug(s, "prompt remove") | |
118 | wctx.sub(s).remove() |
|
129 | wctx.sub(s).remove() | |
119 |
|
130 | |||
120 | for s, r in s2.items(): |
|
131 | for s, r in s2.items(): | |
121 | if s in s1: |
|
132 | if s in s1: | |
122 | continue |
|
133 | continue | |
123 | elif s not in sa: |
|
134 | elif s not in sa: | |
124 | debug(s, "remote added, get", r) |
|
135 | debug(s, "remote added, get", r) | |
125 | mctx.sub(s).get(r) |
|
136 | mctx.sub(s).get(r) | |
126 | sm[s] = r |
|
137 | sm[s] = r | |
127 | elif r != sa[s]: |
|
138 | elif r != sa[s]: | |
128 | if repo.ui.promptchoice( |
|
139 | if repo.ui.promptchoice( | |
129 | _(' remote changed subrepository %s which local removed\n' |
|
140 | _(' remote changed subrepository %s which local removed\n' | |
130 | 'use (c)hanged version or (d)elete?') % s, |
|
141 | 'use (c)hanged version or (d)elete?') % s, | |
131 | (_('&Changed'), _('&Delete')), 0) == 0: |
|
142 | (_('&Changed'), _('&Delete')), 0) == 0: | |
132 | debug(s, "prompt recreate", r) |
|
143 | debug(s, "prompt recreate", r) | |
133 | wctx.sub(s).get(r) |
|
144 | wctx.sub(s).get(r) | |
134 | sm[s] = r |
|
145 | sm[s] = r | |
135 |
|
146 | |||
136 | # record merged .hgsubstate |
|
147 | # record merged .hgsubstate | |
137 | writestate(repo, sm) |
|
148 | writestate(repo, sm) | |
138 |
|
149 | |||
139 | def relpath(sub): |
|
150 | def relpath(sub): | |
140 | """return path to this subrepo as seen from outermost repo""" |
|
151 | """return path to this subrepo as seen from outermost repo""" | |
141 | if not hasattr(sub, '_repo'): |
|
152 | if not hasattr(sub, '_repo'): | |
142 | return sub._path |
|
153 | return sub._path | |
143 | parent = sub._repo |
|
154 | parent = sub._repo | |
144 | while hasattr(parent, '_subparent'): |
|
155 | while hasattr(parent, '_subparent'): | |
145 | parent = parent._subparent |
|
156 | parent = parent._subparent | |
146 | return sub._repo.root[len(parent.root)+1:] |
|
157 | return sub._repo.root[len(parent.root)+1:] | |
147 |
|
158 | |||
148 | def _abssource(repo, push=False): |
|
159 | def _abssource(repo, push=False): | |
149 | """return pull/push path of repo - either based on parent repo |
|
160 | """return pull/push path of repo - either based on parent repo | |
150 | .hgsub info or on the subrepos own config""" |
|
161 | .hgsub info or on the subrepos own config""" | |
151 | if hasattr(repo, '_subparent'): |
|
162 | if hasattr(repo, '_subparent'): | |
152 | source = repo._subsource |
|
163 | source = repo._subsource | |
153 | if source.startswith('/') or '://' in source: |
|
164 | if source.startswith('/') or '://' in source: | |
154 | return source |
|
165 | return source | |
155 | parent = _abssource(repo._subparent, push) |
|
166 | parent = _abssource(repo._subparent, push) | |
156 | if '://' in parent: |
|
167 | if '://' in parent: | |
157 | if parent[-1] == '/': |
|
168 | if parent[-1] == '/': | |
158 | parent = parent[:-1] |
|
169 | parent = parent[:-1] | |
159 | r = urlparse.urlparse(parent + '/' + source) |
|
170 | r = urlparse.urlparse(parent + '/' + source) | |
160 | r = urlparse.urlunparse((r[0], r[1], |
|
171 | r = urlparse.urlunparse((r[0], r[1], | |
161 | posixpath.normpath(r[2]), |
|
172 | posixpath.normpath(r[2]), | |
162 | r[3], r[4], r[5])) |
|
173 | r[3], r[4], r[5])) | |
163 | return r |
|
174 | return r | |
164 | return posixpath.normpath(os.path.join(parent, repo._subsource)) |
|
175 | return posixpath.normpath(os.path.join(parent, repo._subsource)) | |
165 | if push and repo.ui.config('paths', 'default-push'): |
|
176 | if push and repo.ui.config('paths', 'default-push'): | |
166 | return repo.ui.config('paths', 'default-push', repo.root) |
|
177 | return repo.ui.config('paths', 'default-push', repo.root) | |
167 | return repo.ui.config('paths', 'default', repo.root) |
|
178 | return repo.ui.config('paths', 'default', repo.root) | |
168 |
|
179 | |||
169 | def subrepo(ctx, path): |
|
180 | def subrepo(ctx, path): | |
170 | """return instance of the right subrepo class for subrepo in path""" |
|
181 | """return instance of the right subrepo class for subrepo in path""" | |
171 | # subrepo inherently violates our import layering rules |
|
182 | # subrepo inherently violates our import layering rules | |
172 | # because it wants to make repo objects from deep inside the stack |
|
183 | # because it wants to make repo objects from deep inside the stack | |
173 | # so we manually delay the circular imports to not break |
|
184 | # so we manually delay the circular imports to not break | |
174 | # scripts that don't use our demand-loading |
|
185 | # scripts that don't use our demand-loading | |
175 | global hg |
|
186 | global hg | |
176 | import hg as h |
|
187 | import hg as h | |
177 | hg = h |
|
188 | hg = h | |
178 |
|
189 | |||
179 | util.path_auditor(ctx._repo.root)(path) |
|
190 | util.path_auditor(ctx._repo.root)(path) | |
180 | state = ctx.substate.get(path, nullstate) |
|
191 | state = ctx.substate.get(path, nullstate) | |
181 | if state[2] not in types: |
|
192 | if state[2] not in types: | |
182 | raise util.Abort(_('unknown subrepo type %s') % state[2]) |
|
193 | raise util.Abort(_('unknown subrepo type %s') % state[2]) | |
183 | return types[state[2]](ctx, path, state[:2]) |
|
194 | return types[state[2]](ctx, path, state[:2]) | |
184 |
|
195 | |||
185 | # subrepo classes need to implement the following abstract class: |
|
196 | # subrepo classes need to implement the following abstract class: | |
186 |
|
197 | |||
187 | class abstractsubrepo(object): |
|
198 | class abstractsubrepo(object): | |
188 |
|
199 | |||
189 | def dirty(self): |
|
200 | def dirty(self): | |
190 | """returns true if the dirstate of the subrepo does not match |
|
201 | """returns true if the dirstate of the subrepo does not match | |
191 | current stored state |
|
202 | current stored state | |
192 | """ |
|
203 | """ | |
193 | raise NotImplementedError |
|
204 | raise NotImplementedError | |
194 |
|
205 | |||
195 | def commit(self, text, user, date): |
|
206 | def commit(self, text, user, date): | |
196 | """commit the current changes to the subrepo with the given |
|
207 | """commit the current changes to the subrepo with the given | |
197 | log message. Use given user and date if possible. Return the |
|
208 | log message. Use given user and date if possible. Return the | |
198 | new state of the subrepo. |
|
209 | new state of the subrepo. | |
199 | """ |
|
210 | """ | |
200 | raise NotImplementedError |
|
211 | raise NotImplementedError | |
201 |
|
212 | |||
202 | def remove(self): |
|
213 | def remove(self): | |
203 | """remove the subrepo |
|
214 | """remove the subrepo | |
204 |
|
215 | |||
205 | (should verify the dirstate is not dirty first) |
|
216 | (should verify the dirstate is not dirty first) | |
206 | """ |
|
217 | """ | |
207 | raise NotImplementedError |
|
218 | raise NotImplementedError | |
208 |
|
219 | |||
209 | def get(self, state): |
|
220 | def get(self, state): | |
210 | """run whatever commands are needed to put the subrepo into |
|
221 | """run whatever commands are needed to put the subrepo into | |
211 | this state |
|
222 | this state | |
212 | """ |
|
223 | """ | |
213 | raise NotImplementedError |
|
224 | raise NotImplementedError | |
214 |
|
225 | |||
215 | def merge(self, state): |
|
226 | def merge(self, state): | |
216 | """merge currently-saved state with the new state.""" |
|
227 | """merge currently-saved state with the new state.""" | |
217 | raise NotImplementedError |
|
228 | raise NotImplementedError | |
218 |
|
229 | |||
219 | def push(self, force): |
|
230 | def push(self, force): | |
220 | """perform whatever action is analogous to 'hg push' |
|
231 | """perform whatever action is analogous to 'hg push' | |
221 |
|
232 | |||
222 | This may be a no-op on some systems. |
|
233 | This may be a no-op on some systems. | |
223 | """ |
|
234 | """ | |
224 | raise NotImplementedError |
|
235 | raise NotImplementedError | |
225 |
|
236 | |||
226 |
|
237 | |||
227 | class hgsubrepo(abstractsubrepo): |
|
238 | class hgsubrepo(abstractsubrepo): | |
228 | def __init__(self, ctx, path, state): |
|
239 | def __init__(self, ctx, path, state): | |
229 | self._path = path |
|
240 | self._path = path | |
230 | self._state = state |
|
241 | self._state = state | |
231 | r = ctx._repo |
|
242 | r = ctx._repo | |
232 | root = r.wjoin(path) |
|
243 | root = r.wjoin(path) | |
233 | create = False |
|
244 | create = False | |
234 | if not os.path.exists(os.path.join(root, '.hg')): |
|
245 | if not os.path.exists(os.path.join(root, '.hg')): | |
235 | create = True |
|
246 | create = True | |
236 | util.makedirs(root) |
|
247 | util.makedirs(root) | |
237 | self._repo = hg.repository(r.ui, root, create=create) |
|
248 | self._repo = hg.repository(r.ui, root, create=create) | |
238 | self._repo._subparent = r |
|
249 | self._repo._subparent = r | |
239 | self._repo._subsource = state[0] |
|
250 | self._repo._subsource = state[0] | |
240 |
|
251 | |||
241 | if create: |
|
252 | if create: | |
242 | fp = self._repo.opener("hgrc", "w", text=True) |
|
253 | fp = self._repo.opener("hgrc", "w", text=True) | |
243 | fp.write('[paths]\n') |
|
254 | fp.write('[paths]\n') | |
244 |
|
255 | |||
245 | def addpathconfig(key, value): |
|
256 | def addpathconfig(key, value): | |
246 | fp.write('%s = %s\n' % (key, value)) |
|
257 | fp.write('%s = %s\n' % (key, value)) | |
247 | self._repo.ui.setconfig('paths', key, value) |
|
258 | self._repo.ui.setconfig('paths', key, value) | |
248 |
|
259 | |||
249 | defpath = _abssource(self._repo) |
|
260 | defpath = _abssource(self._repo) | |
250 | defpushpath = _abssource(self._repo, True) |
|
261 | defpushpath = _abssource(self._repo, True) | |
251 | addpathconfig('default', defpath) |
|
262 | addpathconfig('default', defpath) | |
252 | if defpath != defpushpath: |
|
263 | if defpath != defpushpath: | |
253 | addpathconfig('default-push', defpushpath) |
|
264 | addpathconfig('default-push', defpushpath) | |
254 | fp.close() |
|
265 | fp.close() | |
255 |
|
266 | |||
256 | def dirty(self): |
|
267 | def dirty(self): | |
257 | r = self._state[1] |
|
268 | r = self._state[1] | |
258 | if r == '': |
|
269 | if r == '': | |
259 | return True |
|
270 | return True | |
260 | w = self._repo[None] |
|
271 | w = self._repo[None] | |
261 | if w.p1() != self._repo[r]: # version checked out change |
|
272 | if w.p1() != self._repo[r]: # version checked out change | |
262 | return True |
|
273 | return True | |
263 | return w.dirty() # working directory changed |
|
274 | return w.dirty() # working directory changed | |
264 |
|
275 | |||
265 | def commit(self, text, user, date): |
|
276 | def commit(self, text, user, date): | |
266 | self._repo.ui.debug("committing subrepo %s\n" % relpath(self)) |
|
277 | self._repo.ui.debug("committing subrepo %s\n" % relpath(self)) | |
267 | n = self._repo.commit(text, user, date) |
|
278 | n = self._repo.commit(text, user, date) | |
268 | if not n: |
|
279 | if not n: | |
269 | return self._repo['.'].hex() # different version checked out |
|
280 | return self._repo['.'].hex() # different version checked out | |
270 | return node.hex(n) |
|
281 | return node.hex(n) | |
271 |
|
282 | |||
272 | def remove(self): |
|
283 | def remove(self): | |
273 | # we can't fully delete the repository as it may contain |
|
284 | # we can't fully delete the repository as it may contain | |
274 | # local-only history |
|
285 | # local-only history | |
275 | self._repo.ui.note(_('removing subrepo %s\n') % relpath(self)) |
|
286 | self._repo.ui.note(_('removing subrepo %s\n') % relpath(self)) | |
276 | hg.clean(self._repo, node.nullid, False) |
|
287 | hg.clean(self._repo, node.nullid, False) | |
277 |
|
288 | |||
278 | def _get(self, state): |
|
289 | def _get(self, state): | |
279 | source, revision, kind = state |
|
290 | source, revision, kind = state | |
280 | try: |
|
291 | try: | |
281 | self._repo.lookup(revision) |
|
292 | self._repo.lookup(revision) | |
282 | except error.RepoError: |
|
293 | except error.RepoError: | |
283 | self._repo._subsource = source |
|
294 | self._repo._subsource = source | |
284 | srcurl = _abssource(self._repo) |
|
295 | srcurl = _abssource(self._repo) | |
285 | self._repo.ui.status(_('pulling subrepo %s from %s\n') |
|
296 | self._repo.ui.status(_('pulling subrepo %s from %s\n') | |
286 | % (relpath(self), srcurl)) |
|
297 | % (relpath(self), srcurl)) | |
287 | other = hg.repository(self._repo.ui, srcurl) |
|
298 | other = hg.repository(self._repo.ui, srcurl) | |
288 | self._repo.pull(other) |
|
299 | self._repo.pull(other) | |
289 |
|
300 | |||
290 | def get(self, state): |
|
301 | def get(self, state): | |
291 | self._get(state) |
|
302 | self._get(state) | |
292 | source, revision, kind = state |
|
303 | source, revision, kind = state | |
293 | self._repo.ui.debug("getting subrepo %s\n" % self._path) |
|
304 | self._repo.ui.debug("getting subrepo %s\n" % self._path) | |
294 | hg.clean(self._repo, revision, False) |
|
305 | hg.clean(self._repo, revision, False) | |
295 |
|
306 | |||
296 | def merge(self, state): |
|
307 | def merge(self, state): | |
297 | self._get(state) |
|
308 | self._get(state) | |
298 | cur = self._repo['.'] |
|
309 | cur = self._repo['.'] | |
299 | dst = self._repo[state[1]] |
|
310 | dst = self._repo[state[1]] | |
300 | anc = dst.ancestor(cur) |
|
311 | anc = dst.ancestor(cur) | |
301 | if anc == cur: |
|
312 | if anc == cur: | |
302 | self._repo.ui.debug("updating subrepo %s\n" % relpath(self)) |
|
313 | self._repo.ui.debug("updating subrepo %s\n" % relpath(self)) | |
303 | hg.update(self._repo, state[1]) |
|
314 | hg.update(self._repo, state[1]) | |
304 | elif anc == dst: |
|
315 | elif anc == dst: | |
305 | self._repo.ui.debug("skipping subrepo %s\n" % relpath(self)) |
|
316 | self._repo.ui.debug("skipping subrepo %s\n" % relpath(self)) | |
306 | else: |
|
317 | else: | |
307 | self._repo.ui.debug("merging subrepo %s\n" % relpath(self)) |
|
318 | self._repo.ui.debug("merging subrepo %s\n" % relpath(self)) | |
308 | hg.merge(self._repo, state[1], remind=False) |
|
319 | hg.merge(self._repo, state[1], remind=False) | |
309 |
|
320 | |||
310 | def push(self, force): |
|
321 | def push(self, force): | |
311 | # push subrepos depth-first for coherent ordering |
|
322 | # push subrepos depth-first for coherent ordering | |
312 | c = self._repo[''] |
|
323 | c = self._repo[''] | |
313 | subs = c.substate # only repos that are committed |
|
324 | subs = c.substate # only repos that are committed | |
314 | for s in sorted(subs): |
|
325 | for s in sorted(subs): | |
315 | if not c.sub(s).push(force): |
|
326 | if not c.sub(s).push(force): | |
316 | return False |
|
327 | return False | |
317 |
|
328 | |||
318 | dsturl = _abssource(self._repo, True) |
|
329 | dsturl = _abssource(self._repo, True) | |
319 | self._repo.ui.status(_('pushing subrepo %s to %s\n') % |
|
330 | self._repo.ui.status(_('pushing subrepo %s to %s\n') % | |
320 | (relpath(self), dsturl)) |
|
331 | (relpath(self), dsturl)) | |
321 | other = hg.repository(self._repo.ui, dsturl) |
|
332 | other = hg.repository(self._repo.ui, dsturl) | |
322 | return self._repo.push(other, force) |
|
333 | return self._repo.push(other, force) | |
323 |
|
334 | |||
324 | class svnsubrepo(abstractsubrepo): |
|
335 | class svnsubrepo(abstractsubrepo): | |
325 | def __init__(self, ctx, path, state): |
|
336 | def __init__(self, ctx, path, state): | |
326 | self._path = path |
|
337 | self._path = path | |
327 | self._state = state |
|
338 | self._state = state | |
328 | self._ctx = ctx |
|
339 | self._ctx = ctx | |
329 | self._ui = ctx._repo.ui |
|
340 | self._ui = ctx._repo.ui | |
330 |
|
341 | |||
331 | def _svncommand(self, commands, filename=''): |
|
342 | def _svncommand(self, commands, filename=''): | |
332 | path = os.path.join(self._ctx._repo.origroot, self._path, filename) |
|
343 | path = os.path.join(self._ctx._repo.origroot, self._path, filename) | |
333 | cmd = ['svn'] + commands + [path] |
|
344 | cmd = ['svn'] + commands + [path] | |
334 | cmd = [util.shellquote(arg) for arg in cmd] |
|
345 | cmd = [util.shellquote(arg) for arg in cmd] | |
335 | cmd = util.quotecommand(' '.join(cmd)) |
|
346 | cmd = util.quotecommand(' '.join(cmd)) | |
336 | env = dict(os.environ) |
|
347 | env = dict(os.environ) | |
337 | # Avoid localized output, preserve current locale for everything else. |
|
348 | # Avoid localized output, preserve current locale for everything else. | |
338 | env['LC_MESSAGES'] = 'C' |
|
349 | env['LC_MESSAGES'] = 'C' | |
339 | write, read, err = util.popen3(cmd, env=env, newlines=True) |
|
350 | write, read, err = util.popen3(cmd, env=env, newlines=True) | |
340 | retdata = read.read() |
|
351 | retdata = read.read() | |
341 | err = err.read().strip() |
|
352 | err = err.read().strip() | |
342 | if err: |
|
353 | if err: | |
343 | raise util.Abort(err) |
|
354 | raise util.Abort(err) | |
344 | return retdata |
|
355 | return retdata | |
345 |
|
356 | |||
346 | def _wcrev(self): |
|
357 | def _wcrev(self): | |
347 | output = self._svncommand(['info', '--xml']) |
|
358 | output = self._svncommand(['info', '--xml']) | |
348 | doc = xml.dom.minidom.parseString(output) |
|
359 | doc = xml.dom.minidom.parseString(output) | |
349 | entries = doc.getElementsByTagName('entry') |
|
360 | entries = doc.getElementsByTagName('entry') | |
350 | if not entries: |
|
361 | if not entries: | |
351 | return 0 |
|
362 | return 0 | |
352 | return int(entries[0].getAttribute('revision') or 0) |
|
363 | return int(entries[0].getAttribute('revision') or 0) | |
353 |
|
364 | |||
354 | def _wcchanged(self): |
|
365 | def _wcchanged(self): | |
355 | """Return (changes, extchanges) where changes is True |
|
366 | """Return (changes, extchanges) where changes is True | |
356 | if the working directory was changed, and extchanges is |
|
367 | if the working directory was changed, and extchanges is | |
357 | True if any of these changes concern an external entry. |
|
368 | True if any of these changes concern an external entry. | |
358 | """ |
|
369 | """ | |
359 | output = self._svncommand(['status', '--xml']) |
|
370 | output = self._svncommand(['status', '--xml']) | |
360 | externals, changes = [], [] |
|
371 | externals, changes = [], [] | |
361 | doc = xml.dom.minidom.parseString(output) |
|
372 | doc = xml.dom.minidom.parseString(output) | |
362 | for e in doc.getElementsByTagName('entry'): |
|
373 | for e in doc.getElementsByTagName('entry'): | |
363 | s = e.getElementsByTagName('wc-status') |
|
374 | s = e.getElementsByTagName('wc-status') | |
364 | if not s: |
|
375 | if not s: | |
365 | continue |
|
376 | continue | |
366 | item = s[0].getAttribute('item') |
|
377 | item = s[0].getAttribute('item') | |
367 | props = s[0].getAttribute('props') |
|
378 | props = s[0].getAttribute('props') | |
368 | path = e.getAttribute('path') |
|
379 | path = e.getAttribute('path') | |
369 | if item == 'external': |
|
380 | if item == 'external': | |
370 | externals.append(path) |
|
381 | externals.append(path) | |
371 | if (item not in ('', 'normal', 'unversioned', 'external') |
|
382 | if (item not in ('', 'normal', 'unversioned', 'external') | |
372 | or props not in ('', 'none')): |
|
383 | or props not in ('', 'none')): | |
373 | changes.append(path) |
|
384 | changes.append(path) | |
374 | for path in changes: |
|
385 | for path in changes: | |
375 | for ext in externals: |
|
386 | for ext in externals: | |
376 | if path == ext or path.startswith(ext + os.sep): |
|
387 | if path == ext or path.startswith(ext + os.sep): | |
377 | return True, True |
|
388 | return True, True | |
378 | return bool(changes), False |
|
389 | return bool(changes), False | |
379 |
|
390 | |||
380 | def dirty(self): |
|
391 | def dirty(self): | |
381 | if self._wcrev() == self._state[1] and not self._wcchanged()[0]: |
|
392 | if self._wcrev() == self._state[1] and not self._wcchanged()[0]: | |
382 | return False |
|
393 | return False | |
383 | return True |
|
394 | return True | |
384 |
|
395 | |||
385 | def commit(self, text, user, date): |
|
396 | def commit(self, text, user, date): | |
386 | # user and date are out of our hands since svn is centralized |
|
397 | # user and date are out of our hands since svn is centralized | |
387 | changed, extchanged = self._wcchanged() |
|
398 | changed, extchanged = self._wcchanged() | |
388 | if not changed: |
|
399 | if not changed: | |
389 | return self._wcrev() |
|
400 | return self._wcrev() | |
390 | if extchanged: |
|
401 | if extchanged: | |
391 | # Do not try to commit externals |
|
402 | # Do not try to commit externals | |
392 | raise util.Abort(_('cannot commit svn externals')) |
|
403 | raise util.Abort(_('cannot commit svn externals')) | |
393 | commitinfo = self._svncommand(['commit', '-m', text]) |
|
404 | commitinfo = self._svncommand(['commit', '-m', text]) | |
394 | self._ui.status(commitinfo) |
|
405 | self._ui.status(commitinfo) | |
395 | newrev = re.search('Committed revision ([\d]+).', commitinfo) |
|
406 | newrev = re.search('Committed revision ([\d]+).', commitinfo) | |
396 | if not newrev: |
|
407 | if not newrev: | |
397 | raise util.Abort(commitinfo.splitlines()[-1]) |
|
408 | raise util.Abort(commitinfo.splitlines()[-1]) | |
398 | newrev = newrev.groups()[0] |
|
409 | newrev = newrev.groups()[0] | |
399 | self._ui.status(self._svncommand(['update', '-r', newrev])) |
|
410 | self._ui.status(self._svncommand(['update', '-r', newrev])) | |
400 | return newrev |
|
411 | return newrev | |
401 |
|
412 | |||
402 | def remove(self): |
|
413 | def remove(self): | |
403 | if self.dirty(): |
|
414 | if self.dirty(): | |
404 | self._ui.warn(_('not removing repo %s because ' |
|
415 | self._ui.warn(_('not removing repo %s because ' | |
405 | 'it has changes.\n' % self._path)) |
|
416 | 'it has changes.\n' % self._path)) | |
406 | return |
|
417 | return | |
407 | self._ui.note(_('removing subrepo %s\n') % self._path) |
|
418 | self._ui.note(_('removing subrepo %s\n') % self._path) | |
408 | shutil.rmtree(self._ctx.repo.join(self._path)) |
|
419 | shutil.rmtree(self._ctx.repo.join(self._path)) | |
409 |
|
420 | |||
410 | def get(self, state): |
|
421 | def get(self, state): | |
411 | status = self._svncommand(['checkout', state[0], '--revision', state[1]]) |
|
422 | status = self._svncommand(['checkout', state[0], '--revision', state[1]]) | |
412 | if not re.search('Checked out revision [\d]+.', status): |
|
423 | if not re.search('Checked out revision [\d]+.', status): | |
413 | raise util.Abort(status.splitlines()[-1]) |
|
424 | raise util.Abort(status.splitlines()[-1]) | |
414 | self._ui.status(status) |
|
425 | self._ui.status(status) | |
415 |
|
426 | |||
416 | def merge(self, state): |
|
427 | def merge(self, state): | |
417 | old = int(self._state[1]) |
|
428 | old = int(self._state[1]) | |
418 | new = int(state[1]) |
|
429 | new = int(state[1]) | |
419 | if new > old: |
|
430 | if new > old: | |
420 | self.get(state) |
|
431 | self.get(state) | |
421 |
|
432 | |||
422 | def push(self, force): |
|
433 | def push(self, force): | |
423 | # push is a no-op for SVN |
|
434 | # push is a no-op for SVN | |
424 | return True |
|
435 | return True | |
425 |
|
436 | |||
426 | types = { |
|
437 | types = { | |
427 | 'hg': hgsubrepo, |
|
438 | 'hg': hgsubrepo, | |
428 | 'svn': svnsubrepo, |
|
439 | 'svn': svnsubrepo, | |
429 | } |
|
440 | } |
General Comments 0
You need to be logged in to leave comments.
Login now