Show More
@@ -1,761 +1,761 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 |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from node import nullid, nullrev, short |
|
8 | from node import nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import ancestor, bdiff, revlog, util, os, errno |
|
10 | import ancestor, bdiff, revlog, util, os, errno | |
11 |
|
11 | |||
12 | class changectx(object): |
|
12 | class changectx(object): | |
13 | """A changecontext object makes access to data related to a particular |
|
13 | """A changecontext object makes access to data related to a particular | |
14 | changeset convenient.""" |
|
14 | changeset convenient.""" | |
15 | def __init__(self, repo, changeid=None): |
|
15 | def __init__(self, repo, changeid=None): | |
16 | """changeid is a revision number, node, or tag""" |
|
16 | """changeid is a revision number, node, or tag""" | |
17 | self._repo = repo |
|
17 | self._repo = repo | |
18 |
|
18 | |||
19 | if not changeid and changeid != 0: |
|
19 | if not changeid and changeid != 0: | |
20 | p1, p2 = self._repo.dirstate.parents() |
|
20 | p1, p2 = self._repo.dirstate.parents() | |
21 | self._rev = self._repo.changelog.rev(p1) |
|
21 | self._rev = self._repo.changelog.rev(p1) | |
22 | if self._rev == -1: |
|
22 | if self._rev == -1: | |
23 | changeid = 'tip' |
|
23 | changeid = 'tip' | |
24 | else: |
|
24 | else: | |
25 | self._node = p1 |
|
25 | self._node = p1 | |
26 | return |
|
26 | return | |
27 |
|
27 | |||
28 | self._node = self._repo.lookup(changeid) |
|
28 | self._node = self._repo.lookup(changeid) | |
29 | self._rev = self._repo.changelog.rev(self._node) |
|
29 | self._rev = self._repo.changelog.rev(self._node) | |
30 |
|
30 | |||
31 | def __str__(self): |
|
31 | def __str__(self): | |
32 | return short(self.node()) |
|
32 | return short(self.node()) | |
33 |
|
33 | |||
34 | def __repr__(self): |
|
34 | def __repr__(self): | |
35 | return "<changectx %s>" % str(self) |
|
35 | return "<changectx %s>" % str(self) | |
36 |
|
36 | |||
37 | def __hash__(self): |
|
37 | def __hash__(self): | |
38 | try: |
|
38 | try: | |
39 | return hash(self._rev) |
|
39 | return hash(self._rev) | |
40 | except AttributeError: |
|
40 | except AttributeError: | |
41 | return id(self) |
|
41 | return id(self) | |
42 |
|
42 | |||
43 | def __eq__(self, other): |
|
43 | def __eq__(self, other): | |
44 | try: |
|
44 | try: | |
45 | return self._rev == other._rev |
|
45 | return self._rev == other._rev | |
46 | except AttributeError: |
|
46 | except AttributeError: | |
47 | return False |
|
47 | return False | |
48 |
|
48 | |||
49 | def __ne__(self, other): |
|
49 | def __ne__(self, other): | |
50 | return not (self == other) |
|
50 | return not (self == other) | |
51 |
|
51 | |||
52 | def __nonzero__(self): |
|
52 | def __nonzero__(self): | |
53 | return self._rev != nullrev |
|
53 | return self._rev != nullrev | |
54 |
|
54 | |||
55 | def __getattr__(self, name): |
|
55 | def __getattr__(self, name): | |
56 | if name == '_changeset': |
|
56 | if name == '_changeset': | |
57 | self._changeset = self._repo.changelog.read(self.node()) |
|
57 | self._changeset = self._repo.changelog.read(self.node()) | |
58 | return self._changeset |
|
58 | return self._changeset | |
59 | elif name == '_manifest': |
|
59 | elif name == '_manifest': | |
60 | self._manifest = self._repo.manifest.read(self._changeset[0]) |
|
60 | self._manifest = self._repo.manifest.read(self._changeset[0]) | |
61 | return self._manifest |
|
61 | return self._manifest | |
62 | elif name == '_manifestdelta': |
|
62 | elif name == '_manifestdelta': | |
63 | md = self._repo.manifest.readdelta(self._changeset[0]) |
|
63 | md = self._repo.manifest.readdelta(self._changeset[0]) | |
64 | self._manifestdelta = md |
|
64 | self._manifestdelta = md | |
65 | return self._manifestdelta |
|
65 | return self._manifestdelta | |
66 | else: |
|
66 | else: | |
67 | raise AttributeError, name |
|
67 | raise AttributeError, name | |
68 |
|
68 | |||
69 | def __contains__(self, key): |
|
69 | def __contains__(self, key): | |
70 | return key in self._manifest |
|
70 | return key in self._manifest | |
71 |
|
71 | |||
72 | def __getitem__(self, key): |
|
72 | def __getitem__(self, key): | |
73 | return self.filectx(key) |
|
73 | return self.filectx(key) | |
74 |
|
74 | |||
75 | def __iter__(self): |
|
75 | def __iter__(self): | |
76 | a = self._manifest.keys() |
|
76 | a = self._manifest.keys() | |
77 | a.sort() |
|
77 | a.sort() | |
78 | for f in a: |
|
78 | for f in a: | |
79 | yield f |
|
79 | yield f | |
80 |
|
80 | |||
81 | def changeset(self): return self._changeset |
|
81 | def changeset(self): return self._changeset | |
82 | def manifest(self): return self._manifest |
|
82 | def manifest(self): return self._manifest | |
83 |
|
83 | |||
84 | def rev(self): return self._rev |
|
84 | def rev(self): return self._rev | |
85 | def node(self): return self._node |
|
85 | def node(self): return self._node | |
86 | def user(self): return self._changeset[1] |
|
86 | def user(self): return self._changeset[1] | |
87 | def date(self): return self._changeset[2] |
|
87 | def date(self): return self._changeset[2] | |
88 | def files(self): return self._changeset[3] |
|
88 | def files(self): return self._changeset[3] | |
89 | def description(self): return self._changeset[4] |
|
89 | def description(self): return self._changeset[4] | |
90 | def branch(self): return self._changeset[5].get("branch") |
|
90 | def branch(self): return self._changeset[5].get("branch") | |
91 | def extra(self): return self._changeset[5] |
|
91 | def extra(self): return self._changeset[5] | |
92 | def tags(self): return self._repo.nodetags(self._node) |
|
92 | def tags(self): return self._repo.nodetags(self._node) | |
93 |
|
93 | |||
94 | def parents(self): |
|
94 | def parents(self): | |
95 | """return contexts for each parent changeset""" |
|
95 | """return contexts for each parent changeset""" | |
96 | p = self._repo.changelog.parents(self._node) |
|
96 | p = self._repo.changelog.parents(self._node) | |
97 | return [changectx(self._repo, x) for x in p] |
|
97 | return [changectx(self._repo, x) for x in p] | |
98 |
|
98 | |||
99 | def children(self): |
|
99 | def children(self): | |
100 | """return contexts for each child changeset""" |
|
100 | """return contexts for each child changeset""" | |
101 | c = self._repo.changelog.children(self._node) |
|
101 | c = self._repo.changelog.children(self._node) | |
102 | return [changectx(self._repo, x) for x in c] |
|
102 | return [changectx(self._repo, x) for x in c] | |
103 |
|
103 | |||
104 | def _fileinfo(self, path): |
|
104 | def _fileinfo(self, path): | |
105 | if '_manifest' in self.__dict__: |
|
105 | if '_manifest' in self.__dict__: | |
106 | try: |
|
106 | try: | |
107 | return self._manifest[path], self._manifest.flags(path) |
|
107 | return self._manifest[path], self._manifest.flags(path) | |
108 | except KeyError: |
|
108 | except KeyError: | |
109 | raise revlog.LookupError(self._node, path, |
|
109 | raise revlog.LookupError(self._node, path, | |
110 | _('not found in manifest')) |
|
110 | _('not found in manifest')) | |
111 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
111 | if '_manifestdelta' in self.__dict__ or path in self.files(): | |
112 | if path in self._manifestdelta: |
|
112 | if path in self._manifestdelta: | |
113 | return self._manifestdelta[path], self._manifestdelta.flags(path) |
|
113 | return self._manifestdelta[path], self._manifestdelta.flags(path) | |
114 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
114 | node, flag = self._repo.manifest.find(self._changeset[0], path) | |
115 | if not node: |
|
115 | if not node: | |
116 | raise revlog.LookupError(self._node, path, |
|
116 | raise revlog.LookupError(self._node, path, | |
117 | _('not found in manifest')) |
|
117 | _('not found in manifest')) | |
118 |
|
118 | |||
119 | return node, flag |
|
119 | return node, flag | |
120 |
|
120 | |||
121 | def filenode(self, path): |
|
121 | def filenode(self, path): | |
122 | return self._fileinfo(path)[0] |
|
122 | return self._fileinfo(path)[0] | |
123 |
|
123 | |||
124 | def fileflags(self, path): |
|
124 | def fileflags(self, path): | |
125 | try: |
|
125 | try: | |
126 | return self._fileinfo(path)[1] |
|
126 | return self._fileinfo(path)[1] | |
127 | except revlog.LookupError: |
|
127 | except revlog.LookupError: | |
128 | return '' |
|
128 | return '' | |
129 |
|
129 | |||
130 | def filectx(self, path, fileid=None, filelog=None): |
|
130 | def filectx(self, path, fileid=None, filelog=None): | |
131 | """get a file context from this changeset""" |
|
131 | """get a file context from this changeset""" | |
132 | if fileid is None: |
|
132 | if fileid is None: | |
133 | fileid = self.filenode(path) |
|
133 | fileid = self.filenode(path) | |
134 | return filectx(self._repo, path, fileid=fileid, |
|
134 | return filectx(self._repo, path, fileid=fileid, | |
135 | changectx=self, filelog=filelog) |
|
135 | changectx=self, filelog=filelog) | |
136 |
|
136 | |||
137 | def filectxs(self): |
|
137 | def filectxs(self): | |
138 | """generate a file context for each file in this changeset's |
|
138 | """generate a file context for each file in this changeset's | |
139 | manifest""" |
|
139 | manifest""" | |
140 | mf = self.manifest() |
|
140 | mf = self.manifest() | |
141 | m = mf.keys() |
|
141 | m = mf.keys() | |
142 | m.sort() |
|
142 | m.sort() | |
143 | for f in m: |
|
143 | for f in m: | |
144 | yield self.filectx(f, fileid=mf[f]) |
|
144 | yield self.filectx(f, fileid=mf[f]) | |
145 |
|
145 | |||
146 | def ancestor(self, c2): |
|
146 | def ancestor(self, c2): | |
147 | """ |
|
147 | """ | |
148 | return the ancestor context of self and c2 |
|
148 | return the ancestor context of self and c2 | |
149 | """ |
|
149 | """ | |
150 | n = self._repo.changelog.ancestor(self._node, c2._node) |
|
150 | n = self._repo.changelog.ancestor(self._node, c2._node) | |
151 | return changectx(self._repo, n) |
|
151 | return changectx(self._repo, n) | |
152 |
|
152 | |||
153 | class filectx(object): |
|
153 | class filectx(object): | |
154 | """A filecontext object makes access to data related to a particular |
|
154 | """A filecontext object makes access to data related to a particular | |
155 | filerevision convenient.""" |
|
155 | filerevision convenient.""" | |
156 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
156 | def __init__(self, repo, path, changeid=None, fileid=None, | |
157 | filelog=None, changectx=None): |
|
157 | filelog=None, changectx=None): | |
158 | """changeid can be a changeset revision, node, or tag. |
|
158 | """changeid can be a changeset revision, node, or tag. | |
159 | fileid can be a file revision or node.""" |
|
159 | fileid can be a file revision or node.""" | |
160 | self._repo = repo |
|
160 | self._repo = repo | |
161 | self._path = path |
|
161 | self._path = path | |
162 |
|
162 | |||
163 | assert (changeid is not None |
|
163 | assert (changeid is not None | |
164 | or fileid is not None |
|
164 | or fileid is not None | |
165 | or changectx is not None) |
|
165 | or changectx is not None) | |
166 |
|
166 | |||
167 | if filelog: |
|
167 | if filelog: | |
168 | self._filelog = filelog |
|
168 | self._filelog = filelog | |
169 |
|
169 | |||
170 | if changeid is not None: |
|
170 | if changeid is not None: | |
171 | self._changeid = changeid |
|
171 | self._changeid = changeid | |
172 | if changectx is not None: |
|
172 | if changectx is not None: | |
173 | self._changectx = changectx |
|
173 | self._changectx = changectx | |
174 | if fileid is not None: |
|
174 | if fileid is not None: | |
175 | self._fileid = fileid |
|
175 | self._fileid = fileid | |
176 |
|
176 | |||
177 | def __getattr__(self, name): |
|
177 | def __getattr__(self, name): | |
178 | if name == '_changectx': |
|
178 | if name == '_changectx': | |
179 | self._changectx = changectx(self._repo, self._changeid) |
|
179 | self._changectx = changectx(self._repo, self._changeid) | |
180 | return self._changectx |
|
180 | return self._changectx | |
181 | elif name == '_filelog': |
|
181 | elif name == '_filelog': | |
182 | self._filelog = self._repo.file(self._path) |
|
182 | self._filelog = self._repo.file(self._path) | |
183 | return self._filelog |
|
183 | return self._filelog | |
184 | elif name == '_changeid': |
|
184 | elif name == '_changeid': | |
185 | if '_changectx' in self.__dict__: |
|
185 | if '_changectx' in self.__dict__: | |
186 | self._changeid = self._changectx.rev() |
|
186 | self._changeid = self._changectx.rev() | |
187 | else: |
|
187 | else: | |
188 | self._changeid = self._filelog.linkrev(self._filenode) |
|
188 | self._changeid = self._filelog.linkrev(self._filenode) | |
189 | return self._changeid |
|
189 | return self._changeid | |
190 | elif name == '_filenode': |
|
190 | elif name == '_filenode': | |
191 | if '_fileid' in self.__dict__: |
|
191 | if '_fileid' in self.__dict__: | |
192 | self._filenode = self._filelog.lookup(self._fileid) |
|
192 | self._filenode = self._filelog.lookup(self._fileid) | |
193 | else: |
|
193 | else: | |
194 | self._filenode = self._changectx.filenode(self._path) |
|
194 | self._filenode = self._changectx.filenode(self._path) | |
195 | return self._filenode |
|
195 | return self._filenode | |
196 | elif name == '_filerev': |
|
196 | elif name == '_filerev': | |
197 | self._filerev = self._filelog.rev(self._filenode) |
|
197 | self._filerev = self._filelog.rev(self._filenode) | |
198 | return self._filerev |
|
198 | return self._filerev | |
199 | elif name == '_repopath': |
|
199 | elif name == '_repopath': | |
200 | self._repopath = self._path |
|
200 | self._repopath = self._path | |
201 | return self._repopath |
|
201 | return self._repopath | |
202 | else: |
|
202 | else: | |
203 | raise AttributeError, name |
|
203 | raise AttributeError, name | |
204 |
|
204 | |||
205 | def __nonzero__(self): |
|
205 | def __nonzero__(self): | |
206 | try: |
|
206 | try: | |
207 | n = self._filenode |
|
207 | n = self._filenode | |
208 | return True |
|
208 | return True | |
209 | except revlog.LookupError: |
|
209 | except revlog.LookupError: | |
210 | # file is missing |
|
210 | # file is missing | |
211 | return False |
|
211 | return False | |
212 |
|
212 | |||
213 | def __str__(self): |
|
213 | def __str__(self): | |
214 | return "%s@%s" % (self.path(), short(self.node())) |
|
214 | return "%s@%s" % (self.path(), short(self.node())) | |
215 |
|
215 | |||
216 | def __repr__(self): |
|
216 | def __repr__(self): | |
217 | return "<filectx %s>" % str(self) |
|
217 | return "<filectx %s>" % str(self) | |
218 |
|
218 | |||
219 | def __hash__(self): |
|
219 | def __hash__(self): | |
220 | try: |
|
220 | try: | |
221 | return hash((self._path, self._fileid)) |
|
221 | return hash((self._path, self._fileid)) | |
222 | except AttributeError: |
|
222 | except AttributeError: | |
223 | return id(self) |
|
223 | return id(self) | |
224 |
|
224 | |||
225 | def __eq__(self, other): |
|
225 | def __eq__(self, other): | |
226 | try: |
|
226 | try: | |
227 | return (self._path == other._path |
|
227 | return (self._path == other._path | |
228 | and self._fileid == other._fileid) |
|
228 | and self._fileid == other._fileid) | |
229 | except AttributeError: |
|
229 | except AttributeError: | |
230 | return False |
|
230 | return False | |
231 |
|
231 | |||
232 | def __ne__(self, other): |
|
232 | def __ne__(self, other): | |
233 | return not (self == other) |
|
233 | return not (self == other) | |
234 |
|
234 | |||
235 | def filectx(self, fileid): |
|
235 | def filectx(self, fileid): | |
236 | '''opens an arbitrary revision of the file without |
|
236 | '''opens an arbitrary revision of the file without | |
237 | opening a new filelog''' |
|
237 | opening a new filelog''' | |
238 | return filectx(self._repo, self._path, fileid=fileid, |
|
238 | return filectx(self._repo, self._path, fileid=fileid, | |
239 | filelog=self._filelog) |
|
239 | filelog=self._filelog) | |
240 |
|
240 | |||
241 | def filerev(self): return self._filerev |
|
241 | def filerev(self): return self._filerev | |
242 | def filenode(self): return self._filenode |
|
242 | def filenode(self): return self._filenode | |
243 | def fileflags(self): return self._changectx.fileflags(self._path) |
|
243 | def fileflags(self): return self._changectx.fileflags(self._path) | |
244 | def isexec(self): return 'x' in self.fileflags() |
|
244 | def isexec(self): return 'x' in self.fileflags() | |
245 | def islink(self): return 'l' in self.fileflags() |
|
245 | def islink(self): return 'l' in self.fileflags() | |
246 | def filelog(self): return self._filelog |
|
246 | def filelog(self): return self._filelog | |
247 |
|
247 | |||
248 | def rev(self): |
|
248 | def rev(self): | |
249 | if '_changectx' in self.__dict__: |
|
249 | if '_changectx' in self.__dict__: | |
250 | return self._changectx.rev() |
|
250 | return self._changectx.rev() | |
251 | if '_changeid' in self.__dict__: |
|
251 | if '_changeid' in self.__dict__: | |
252 | return self._changectx.rev() |
|
252 | return self._changectx.rev() | |
253 | return self._filelog.linkrev(self._filenode) |
|
253 | return self._filelog.linkrev(self._filenode) | |
254 |
|
254 | |||
255 | def linkrev(self): return self._filelog.linkrev(self._filenode) |
|
255 | def linkrev(self): return self._filelog.linkrev(self._filenode) | |
256 | def node(self): return self._changectx.node() |
|
256 | def node(self): return self._changectx.node() | |
257 | def user(self): return self._changectx.user() |
|
257 | def user(self): return self._changectx.user() | |
258 | def date(self): return self._changectx.date() |
|
258 | def date(self): return self._changectx.date() | |
259 | def files(self): return self._changectx.files() |
|
259 | def files(self): return self._changectx.files() | |
260 | def description(self): return self._changectx.description() |
|
260 | def description(self): return self._changectx.description() | |
261 | def branch(self): return self._changectx.branch() |
|
261 | def branch(self): return self._changectx.branch() | |
262 | def manifest(self): return self._changectx.manifest() |
|
262 | def manifest(self): return self._changectx.manifest() | |
263 | def changectx(self): return self._changectx |
|
263 | def changectx(self): return self._changectx | |
264 |
|
264 | |||
265 | def data(self): return self._filelog.read(self._filenode) |
|
265 | def data(self): return self._filelog.read(self._filenode) | |
266 | def path(self): return self._path |
|
266 | def path(self): return self._path | |
267 | def size(self): return self._filelog.size(self._filerev) |
|
267 | def size(self): return self._filelog.size(self._filerev) | |
268 |
|
268 | |||
269 | def cmp(self, text): return self._filelog.cmp(self._filenode, text) |
|
269 | def cmp(self, text): return self._filelog.cmp(self._filenode, text) | |
270 |
|
270 | |||
271 | def renamed(self): |
|
271 | def renamed(self): | |
272 | """check if file was actually renamed in this changeset revision |
|
272 | """check if file was actually renamed in this changeset revision | |
273 |
|
273 | |||
274 | If rename logged in file revision, we report copy for changeset only |
|
274 | If rename logged in file revision, we report copy for changeset only | |
275 | if file revisions linkrev points back to the changeset in question |
|
275 | if file revisions linkrev points back to the changeset in question | |
276 | or both changeset parents contain different file revisions. |
|
276 | or both changeset parents contain different file revisions. | |
277 | """ |
|
277 | """ | |
278 |
|
278 | |||
279 | renamed = self._filelog.renamed(self._filenode) |
|
279 | renamed = self._filelog.renamed(self._filenode) | |
280 | if not renamed: |
|
280 | if not renamed: | |
281 | return renamed |
|
281 | return renamed | |
282 |
|
282 | |||
283 | if self.rev() == self.linkrev(): |
|
283 | if self.rev() == self.linkrev(): | |
284 | return renamed |
|
284 | return renamed | |
285 |
|
285 | |||
286 | name = self.path() |
|
286 | name = self.path() | |
287 | fnode = self._filenode |
|
287 | fnode = self._filenode | |
288 | for p in self._changectx.parents(): |
|
288 | for p in self._changectx.parents(): | |
289 | try: |
|
289 | try: | |
290 | if fnode == p.filenode(name): |
|
290 | if fnode == p.filenode(name): | |
291 | return None |
|
291 | return None | |
292 | except revlog.LookupError: |
|
292 | except revlog.LookupError: | |
293 | pass |
|
293 | pass | |
294 | return renamed |
|
294 | return renamed | |
295 |
|
295 | |||
296 | def parents(self): |
|
296 | def parents(self): | |
297 | p = self._path |
|
297 | p = self._path | |
298 | fl = self._filelog |
|
298 | fl = self._filelog | |
299 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
299 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] | |
300 |
|
300 | |||
301 | r = self._filelog.renamed(self._filenode) |
|
301 | r = self._filelog.renamed(self._filenode) | |
302 | if r: |
|
302 | if r: | |
303 | pl[0] = (r[0], r[1], None) |
|
303 | pl[0] = (r[0], r[1], None) | |
304 |
|
304 | |||
305 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
305 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
306 | for p,n,l in pl if n != nullid] |
|
306 | for p,n,l in pl if n != nullid] | |
307 |
|
307 | |||
308 | def children(self): |
|
308 | def children(self): | |
309 | # hard for renames |
|
309 | # hard for renames | |
310 | c = self._filelog.children(self._filenode) |
|
310 | c = self._filelog.children(self._filenode) | |
311 | return [filectx(self._repo, self._path, fileid=x, |
|
311 | return [filectx(self._repo, self._path, fileid=x, | |
312 | filelog=self._filelog) for x in c] |
|
312 | filelog=self._filelog) for x in c] | |
313 |
|
313 | |||
314 | def annotate(self, follow=False, linenumber=None): |
|
314 | def annotate(self, follow=False, linenumber=None): | |
315 | '''returns a list of tuples of (ctx, line) for each line |
|
315 | '''returns a list of tuples of (ctx, line) for each line | |
316 | in the file, where ctx is the filectx of the node where |
|
316 | in the file, where ctx is the filectx of the node where | |
317 | that line was last changed. |
|
317 | that line was last changed. | |
318 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
318 | This returns tuples of ((ctx, linenumber), line) for each line, | |
319 | if "linenumber" parameter is NOT "None". |
|
319 | if "linenumber" parameter is NOT "None". | |
320 | In such tuples, linenumber means one at the first appearance |
|
320 | In such tuples, linenumber means one at the first appearance | |
321 | in the managed file. |
|
321 | in the managed file. | |
322 | To reduce annotation cost, |
|
322 | To reduce annotation cost, | |
323 | this returns fixed value(False is used) as linenumber, |
|
323 | this returns fixed value(False is used) as linenumber, | |
324 | if "linenumber" parameter is "False".''' |
|
324 | if "linenumber" parameter is "False".''' | |
325 |
|
325 | |||
326 | def decorate_compat(text, rev): |
|
326 | def decorate_compat(text, rev): | |
327 | return ([rev] * len(text.splitlines()), text) |
|
327 | return ([rev] * len(text.splitlines()), text) | |
328 |
|
328 | |||
329 | def without_linenumber(text, rev): |
|
329 | def without_linenumber(text, rev): | |
330 | return ([(rev, False)] * len(text.splitlines()), text) |
|
330 | return ([(rev, False)] * len(text.splitlines()), text) | |
331 |
|
331 | |||
332 | def with_linenumber(text, rev): |
|
332 | def with_linenumber(text, rev): | |
333 | size = len(text.splitlines()) |
|
333 | size = len(text.splitlines()) | |
334 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
334 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
335 |
|
335 | |||
336 | decorate = (((linenumber is None) and decorate_compat) or |
|
336 | decorate = (((linenumber is None) and decorate_compat) or | |
337 | (linenumber and with_linenumber) or |
|
337 | (linenumber and with_linenumber) or | |
338 | without_linenumber) |
|
338 | without_linenumber) | |
339 |
|
339 | |||
340 | def pair(parent, child): |
|
340 | def pair(parent, child): | |
341 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
|
341 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): | |
342 | child[0][b1:b2] = parent[0][a1:a2] |
|
342 | child[0][b1:b2] = parent[0][a1:a2] | |
343 | return child |
|
343 | return child | |
344 |
|
344 | |||
345 | getlog = util.cachefunc(lambda x: self._repo.file(x)) |
|
345 | getlog = util.cachefunc(lambda x: self._repo.file(x)) | |
346 | def getctx(path, fileid): |
|
346 | def getctx(path, fileid): | |
347 | log = path == self._path and self._filelog or getlog(path) |
|
347 | log = path == self._path and self._filelog or getlog(path) | |
348 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
348 | return filectx(self._repo, path, fileid=fileid, filelog=log) | |
349 | getctx = util.cachefunc(getctx) |
|
349 | getctx = util.cachefunc(getctx) | |
350 |
|
350 | |||
351 | def parents(f): |
|
351 | def parents(f): | |
352 | # we want to reuse filectx objects as much as possible |
|
352 | # we want to reuse filectx objects as much as possible | |
353 | p = f._path |
|
353 | p = f._path | |
354 | if f._filerev is None: # working dir |
|
354 | if f._filerev is None: # working dir | |
355 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
355 | pl = [(n.path(), n.filerev()) for n in f.parents()] | |
356 | else: |
|
356 | else: | |
357 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
357 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] | |
358 |
|
358 | |||
359 | if follow: |
|
359 | if follow: | |
360 | r = f.renamed() |
|
360 | r = f.renamed() | |
361 | if r: |
|
361 | if r: | |
362 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
362 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) | |
363 |
|
363 | |||
364 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
364 | return [getctx(p, n) for p, n in pl if n != nullrev] | |
365 |
|
365 | |||
366 | # use linkrev to find the first changeset where self appeared |
|
366 | # use linkrev to find the first changeset where self appeared | |
367 | if self.rev() != self.linkrev(): |
|
367 | if self.rev() != self.linkrev(): | |
368 | base = self.filectx(self.filerev()) |
|
368 | base = self.filectx(self.filerev()) | |
369 | else: |
|
369 | else: | |
370 | base = self |
|
370 | base = self | |
371 |
|
371 | |||
372 | # find all ancestors |
|
372 | # find all ancestors | |
373 | needed = {base: 1} |
|
373 | needed = {base: 1} | |
374 | visit = [base] |
|
374 | visit = [base] | |
375 | files = [base._path] |
|
375 | files = [base._path] | |
376 | while visit: |
|
376 | while visit: | |
377 | f = visit.pop(0) |
|
377 | f = visit.pop(0) | |
378 | for p in parents(f): |
|
378 | for p in parents(f): | |
379 | if p not in needed: |
|
379 | if p not in needed: | |
380 | needed[p] = 1 |
|
380 | needed[p] = 1 | |
381 | visit.append(p) |
|
381 | visit.append(p) | |
382 | if p._path not in files: |
|
382 | if p._path not in files: | |
383 | files.append(p._path) |
|
383 | files.append(p._path) | |
384 | else: |
|
384 | else: | |
385 | # count how many times we'll use this |
|
385 | # count how many times we'll use this | |
386 | needed[p] += 1 |
|
386 | needed[p] += 1 | |
387 |
|
387 | |||
388 | # sort by revision (per file) which is a topological order |
|
388 | # sort by revision (per file) which is a topological order | |
389 | visit = [] |
|
389 | visit = [] | |
390 | for f in files: |
|
390 | for f in files: | |
391 | fn = [(n.rev(), n) for n in needed.keys() if n._path == f] |
|
391 | fn = [(n.rev(), n) for n in needed.keys() if n._path == f] | |
392 | visit.extend(fn) |
|
392 | visit.extend(fn) | |
393 | visit.sort() |
|
393 | visit.sort() | |
394 | hist = {} |
|
394 | hist = {} | |
395 |
|
395 | |||
396 | for r, f in visit: |
|
396 | for r, f in visit: | |
397 | curr = decorate(f.data(), f) |
|
397 | curr = decorate(f.data(), f) | |
398 | for p in parents(f): |
|
398 | for p in parents(f): | |
399 | if p != nullid: |
|
399 | if p != nullid: | |
400 | curr = pair(hist[p], curr) |
|
400 | curr = pair(hist[p], curr) | |
401 | # trim the history of unneeded revs |
|
401 | # trim the history of unneeded revs | |
402 | needed[p] -= 1 |
|
402 | needed[p] -= 1 | |
403 | if not needed[p]: |
|
403 | if not needed[p]: | |
404 | del hist[p] |
|
404 | del hist[p] | |
405 | hist[f] = curr |
|
405 | hist[f] = curr | |
406 |
|
406 | |||
407 | return zip(hist[f][0], hist[f][1].splitlines(1)) |
|
407 | return zip(hist[f][0], hist[f][1].splitlines(1)) | |
408 |
|
408 | |||
409 | def ancestor(self, fc2): |
|
409 | def ancestor(self, fc2): | |
410 | """ |
|
410 | """ | |
411 | find the common ancestor file context, if any, of self, and fc2 |
|
411 | find the common ancestor file context, if any, of self, and fc2 | |
412 | """ |
|
412 | """ | |
413 |
|
413 | |||
414 | acache = {} |
|
414 | acache = {} | |
415 |
|
415 | |||
416 | # prime the ancestor cache for the working directory |
|
416 | # prime the ancestor cache for the working directory | |
417 | for c in (self, fc2): |
|
417 | for c in (self, fc2): | |
418 | if c._filerev == None: |
|
418 | if c._filerev == None: | |
419 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
419 | pl = [(n.path(), n.filenode()) for n in c.parents()] | |
420 | acache[(c._path, None)] = pl |
|
420 | acache[(c._path, None)] = pl | |
421 |
|
421 | |||
422 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
|
422 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} | |
423 | def parents(vertex): |
|
423 | def parents(vertex): | |
424 | if vertex in acache: |
|
424 | if vertex in acache: | |
425 | return acache[vertex] |
|
425 | return acache[vertex] | |
426 | f, n = vertex |
|
426 | f, n = vertex | |
427 | if f not in flcache: |
|
427 | if f not in flcache: | |
428 | flcache[f] = self._repo.file(f) |
|
428 | flcache[f] = self._repo.file(f) | |
429 | fl = flcache[f] |
|
429 | fl = flcache[f] | |
430 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
430 | pl = [(f, p) for p in fl.parents(n) if p != nullid] | |
431 | re = fl.renamed(n) |
|
431 | re = fl.renamed(n) | |
432 | if re: |
|
432 | if re: | |
433 | pl.append(re) |
|
433 | pl.append(re) | |
434 | acache[vertex] = pl |
|
434 | acache[vertex] = pl | |
435 | return pl |
|
435 | return pl | |
436 |
|
436 | |||
437 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
437 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) | |
438 | v = ancestor.ancestor(a, b, parents) |
|
438 | v = ancestor.ancestor(a, b, parents) | |
439 | if v: |
|
439 | if v: | |
440 | f, n = v |
|
440 | f, n = v | |
441 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
441 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) | |
442 |
|
442 | |||
443 | return None |
|
443 | return None | |
444 |
|
444 | |||
445 | class workingctx(changectx): |
|
445 | class workingctx(changectx): | |
446 | """A workingctx object makes access to data related to |
|
446 | """A workingctx object makes access to data related to | |
447 | the current working directory convenient. |
|
447 | the current working directory convenient. | |
448 | parents - a pair of parent nodeids, or None to use the dirstate. |
|
448 | parents - a pair of parent nodeids, or None to use the dirstate. | |
449 | date - any valid date string or (unixtime, offset), or None. |
|
449 | date - any valid date string or (unixtime, offset), or None. | |
450 | user - username string, or None. |
|
450 | user - username string, or None. | |
451 | extra - a dictionary of extra values, or None. |
|
451 | extra - a dictionary of extra values, or None. | |
452 | changes - a list of file lists as returned by localrepo.status() |
|
452 | changes - a list of file lists as returned by localrepo.status() | |
453 | or None to use the repository status. |
|
453 | or None to use the repository status. | |
454 | """ |
|
454 | """ | |
455 | def __init__(self, repo, parents=None, text="", user=None, date=None, |
|
455 | def __init__(self, repo, parents=None, text="", user=None, date=None, | |
456 | extra=None, changes=None): |
|
456 | extra=None, changes=None): | |
457 | self._repo = repo |
|
457 | self._repo = repo | |
458 | self._rev = None |
|
458 | self._rev = None | |
459 | self._node = None |
|
459 | self._node = None | |
460 | self._text = text |
|
460 | self._text = text | |
461 |
if date |
|
461 | if date: | |
462 | self._date = util.parsedate(date) |
|
462 | self._date = util.parsedate(date) | |
463 | else: |
|
463 | else: | |
464 | self._date = util.makedate() |
|
464 | self._date = util.makedate() | |
465 | if user: |
|
465 | if user: | |
466 | self._user = user |
|
466 | self._user = user | |
467 | else: |
|
467 | else: | |
468 | self._user = self._repo.ui.username() |
|
468 | self._user = self._repo.ui.username() | |
469 | if parents: |
|
469 | if parents: | |
470 | p1, p2 = parents |
|
470 | p1, p2 = parents | |
471 | self._parents = [self._repo.changectx(p) for p in (p1, p2)] |
|
471 | self._parents = [self._repo.changectx(p) for p in (p1, p2)] | |
472 | if changes: |
|
472 | if changes: | |
473 | self._status = list(changes) |
|
473 | self._status = list(changes) | |
474 |
|
474 | |||
475 | self._extra = {} |
|
475 | self._extra = {} | |
476 | if extra: |
|
476 | if extra: | |
477 | self._extra = extra.copy() |
|
477 | self._extra = extra.copy() | |
478 | if 'branch' not in self._extra: |
|
478 | if 'branch' not in self._extra: | |
479 | branch = self._repo.dirstate.branch() |
|
479 | branch = self._repo.dirstate.branch() | |
480 | try: |
|
480 | try: | |
481 | branch = branch.decode('UTF-8').encode('UTF-8') |
|
481 | branch = branch.decode('UTF-8').encode('UTF-8') | |
482 | except UnicodeDecodeError: |
|
482 | except UnicodeDecodeError: | |
483 | raise util.Abort(_('branch name not in UTF-8!')) |
|
483 | raise util.Abort(_('branch name not in UTF-8!')) | |
484 | self._extra['branch'] = branch |
|
484 | self._extra['branch'] = branch | |
485 | if self._extra['branch'] == '': |
|
485 | if self._extra['branch'] == '': | |
486 | self._extra['branch'] = 'default' |
|
486 | self._extra['branch'] = 'default' | |
487 |
|
487 | |||
488 | def __str__(self): |
|
488 | def __str__(self): | |
489 | return str(self._parents[0]) + "+" |
|
489 | return str(self._parents[0]) + "+" | |
490 |
|
490 | |||
491 | def __nonzero__(self): |
|
491 | def __nonzero__(self): | |
492 | return True |
|
492 | return True | |
493 |
|
493 | |||
494 | def __getattr__(self, name): |
|
494 | def __getattr__(self, name): | |
495 | if name == '_parents': |
|
495 | if name == '_parents': | |
496 | self._parents = self._repo.parents() |
|
496 | self._parents = self._repo.parents() | |
497 | return self._parents |
|
497 | return self._parents | |
498 | if name == '_status': |
|
498 | if name == '_status': | |
499 | self._status = self._repo.status() |
|
499 | self._status = self._repo.status() | |
500 | return self._status |
|
500 | return self._status | |
501 | if name == '_manifest': |
|
501 | if name == '_manifest': | |
502 | self._buildmanifest() |
|
502 | self._buildmanifest() | |
503 | return self._manifest |
|
503 | return self._manifest | |
504 | else: |
|
504 | else: | |
505 | raise AttributeError, name |
|
505 | raise AttributeError, name | |
506 |
|
506 | |||
507 | def _buildmanifest(self): |
|
507 | def _buildmanifest(self): | |
508 | """generate a manifest corresponding to the working directory""" |
|
508 | """generate a manifest corresponding to the working directory""" | |
509 |
|
509 | |||
510 | man = self._parents[0].manifest().copy() |
|
510 | man = self._parents[0].manifest().copy() | |
511 | copied = self._repo.dirstate.copies() |
|
511 | copied = self._repo.dirstate.copies() | |
512 | is_exec = util.execfunc(self._repo.root, |
|
512 | is_exec = util.execfunc(self._repo.root, | |
513 | lambda p: man.execf(copied.get(p,p))) |
|
513 | lambda p: man.execf(copied.get(p,p))) | |
514 | is_link = util.linkfunc(self._repo.root, |
|
514 | is_link = util.linkfunc(self._repo.root, | |
515 | lambda p: man.linkf(copied.get(p,p))) |
|
515 | lambda p: man.linkf(copied.get(p,p))) | |
516 | modified, added, removed, deleted, unknown = self._status[:5] |
|
516 | modified, added, removed, deleted, unknown = self._status[:5] | |
517 | for i, l in (("a", added), ("m", modified), ("u", unknown)): |
|
517 | for i, l in (("a", added), ("m", modified), ("u", unknown)): | |
518 | for f in l: |
|
518 | for f in l: | |
519 | man[f] = man.get(copied.get(f, f), nullid) + i |
|
519 | man[f] = man.get(copied.get(f, f), nullid) + i | |
520 | try: |
|
520 | try: | |
521 | man.set(f, is_exec(f), is_link(f)) |
|
521 | man.set(f, is_exec(f), is_link(f)) | |
522 | except OSError: |
|
522 | except OSError: | |
523 | pass |
|
523 | pass | |
524 |
|
524 | |||
525 | for f in deleted + removed: |
|
525 | for f in deleted + removed: | |
526 | if f in man: |
|
526 | if f in man: | |
527 | del man[f] |
|
527 | del man[f] | |
528 |
|
528 | |||
529 | self._manifest = man |
|
529 | self._manifest = man | |
530 |
|
530 | |||
531 | def manifest(self): return self._manifest |
|
531 | def manifest(self): return self._manifest | |
532 |
|
532 | |||
533 | def user(self): return self._user |
|
533 | def user(self): return self._user | |
534 | def date(self): return self._date |
|
534 | def date(self): return self._date | |
535 | def description(self): return self._text |
|
535 | def description(self): return self._text | |
536 | def files(self): |
|
536 | def files(self): | |
537 | f = self.modified() + self.added() + self.removed() |
|
537 | f = self.modified() + self.added() + self.removed() | |
538 | f.sort() |
|
538 | f.sort() | |
539 | return f |
|
539 | return f | |
540 |
|
540 | |||
541 | def modified(self): return self._status[0] |
|
541 | def modified(self): return self._status[0] | |
542 | def added(self): return self._status[1] |
|
542 | def added(self): return self._status[1] | |
543 | def removed(self): return self._status[2] |
|
543 | def removed(self): return self._status[2] | |
544 | def deleted(self): return self._status[3] |
|
544 | def deleted(self): return self._status[3] | |
545 | def unknown(self): return self._status[4] |
|
545 | def unknown(self): return self._status[4] | |
546 | def clean(self): return self._status[5] |
|
546 | def clean(self): return self._status[5] | |
547 | def branch(self): return self._extra['branch'] |
|
547 | def branch(self): return self._extra['branch'] | |
548 | def extra(self): return self._extra |
|
548 | def extra(self): return self._extra | |
549 |
|
549 | |||
550 | def tags(self): |
|
550 | def tags(self): | |
551 | t = [] |
|
551 | t = [] | |
552 | [t.extend(p.tags()) for p in self.parents()] |
|
552 | [t.extend(p.tags()) for p in self.parents()] | |
553 | return t |
|
553 | return t | |
554 |
|
554 | |||
555 | def parents(self): |
|
555 | def parents(self): | |
556 | """return contexts for each parent changeset""" |
|
556 | """return contexts for each parent changeset""" | |
557 | return self._parents |
|
557 | return self._parents | |
558 |
|
558 | |||
559 | def children(self): |
|
559 | def children(self): | |
560 | return [] |
|
560 | return [] | |
561 |
|
561 | |||
562 | def fileflags(self, path): |
|
562 | def fileflags(self, path): | |
563 | if '_manifest' in self.__dict__: |
|
563 | if '_manifest' in self.__dict__: | |
564 | try: |
|
564 | try: | |
565 | return self._manifest.flags(path) |
|
565 | return self._manifest.flags(path) | |
566 | except KeyError: |
|
566 | except KeyError: | |
567 | return '' |
|
567 | return '' | |
568 |
|
568 | |||
569 | pnode = self._parents[0].changeset()[0] |
|
569 | pnode = self._parents[0].changeset()[0] | |
570 | orig = self._repo.dirstate.copies().get(path, path) |
|
570 | orig = self._repo.dirstate.copies().get(path, path) | |
571 | node, flag = self._repo.manifest.find(pnode, orig) |
|
571 | node, flag = self._repo.manifest.find(pnode, orig) | |
572 | is_link = util.linkfunc(self._repo.root, |
|
572 | is_link = util.linkfunc(self._repo.root, | |
573 | lambda p: flag and 'l' in flag) |
|
573 | lambda p: flag and 'l' in flag) | |
574 | is_exec = util.execfunc(self._repo.root, |
|
574 | is_exec = util.execfunc(self._repo.root, | |
575 | lambda p: flag and 'x' in flag) |
|
575 | lambda p: flag and 'x' in flag) | |
576 | try: |
|
576 | try: | |
577 | return (is_link(path) and 'l' or '') + (is_exec(path) and 'x' or '') |
|
577 | return (is_link(path) and 'l' or '') + (is_exec(path) and 'x' or '') | |
578 | except OSError: |
|
578 | except OSError: | |
579 | pass |
|
579 | pass | |
580 |
|
580 | |||
581 | if not node or path in self.deleted() or path in self.removed(): |
|
581 | if not node or path in self.deleted() or path in self.removed(): | |
582 | return '' |
|
582 | return '' | |
583 | return flag |
|
583 | return flag | |
584 |
|
584 | |||
585 | def filectx(self, path, filelog=None): |
|
585 | def filectx(self, path, filelog=None): | |
586 | """get a file context from the working directory""" |
|
586 | """get a file context from the working directory""" | |
587 | return workingfilectx(self._repo, path, workingctx=self, |
|
587 | return workingfilectx(self._repo, path, workingctx=self, | |
588 | filelog=filelog) |
|
588 | filelog=filelog) | |
589 |
|
589 | |||
590 | def ancestor(self, c2): |
|
590 | def ancestor(self, c2): | |
591 | """return the ancestor context of self and c2""" |
|
591 | """return the ancestor context of self and c2""" | |
592 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
592 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
593 |
|
593 | |||
594 | class workingfilectx(filectx): |
|
594 | class workingfilectx(filectx): | |
595 | """A workingfilectx object makes access to data related to a particular |
|
595 | """A workingfilectx object makes access to data related to a particular | |
596 | file in the working directory convenient.""" |
|
596 | file in the working directory convenient.""" | |
597 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
597 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
598 | """changeid can be a changeset revision, node, or tag. |
|
598 | """changeid can be a changeset revision, node, or tag. | |
599 | fileid can be a file revision or node.""" |
|
599 | fileid can be a file revision or node.""" | |
600 | self._repo = repo |
|
600 | self._repo = repo | |
601 | self._path = path |
|
601 | self._path = path | |
602 | self._changeid = None |
|
602 | self._changeid = None | |
603 | self._filerev = self._filenode = None |
|
603 | self._filerev = self._filenode = None | |
604 |
|
604 | |||
605 | if filelog: |
|
605 | if filelog: | |
606 | self._filelog = filelog |
|
606 | self._filelog = filelog | |
607 | if workingctx: |
|
607 | if workingctx: | |
608 | self._changectx = workingctx |
|
608 | self._changectx = workingctx | |
609 |
|
609 | |||
610 | def __getattr__(self, name): |
|
610 | def __getattr__(self, name): | |
611 | if name == '_changectx': |
|
611 | if name == '_changectx': | |
612 | self._changectx = workingctx(self._repo) |
|
612 | self._changectx = workingctx(self._repo) | |
613 | return self._changectx |
|
613 | return self._changectx | |
614 | elif name == '_repopath': |
|
614 | elif name == '_repopath': | |
615 | self._repopath = (self._repo.dirstate.copied(self._path) |
|
615 | self._repopath = (self._repo.dirstate.copied(self._path) | |
616 | or self._path) |
|
616 | or self._path) | |
617 | return self._repopath |
|
617 | return self._repopath | |
618 | elif name == '_filelog': |
|
618 | elif name == '_filelog': | |
619 | self._filelog = self._repo.file(self._repopath) |
|
619 | self._filelog = self._repo.file(self._repopath) | |
620 | return self._filelog |
|
620 | return self._filelog | |
621 | else: |
|
621 | else: | |
622 | raise AttributeError, name |
|
622 | raise AttributeError, name | |
623 |
|
623 | |||
624 | def __nonzero__(self): |
|
624 | def __nonzero__(self): | |
625 | return True |
|
625 | return True | |
626 |
|
626 | |||
627 | def __str__(self): |
|
627 | def __str__(self): | |
628 | return "%s@%s" % (self.path(), self._changectx) |
|
628 | return "%s@%s" % (self.path(), self._changectx) | |
629 |
|
629 | |||
630 | def filectx(self, fileid): |
|
630 | def filectx(self, fileid): | |
631 | '''opens an arbitrary revision of the file without |
|
631 | '''opens an arbitrary revision of the file without | |
632 | opening a new filelog''' |
|
632 | opening a new filelog''' | |
633 | return filectx(self._repo, self._repopath, fileid=fileid, |
|
633 | return filectx(self._repo, self._repopath, fileid=fileid, | |
634 | filelog=self._filelog) |
|
634 | filelog=self._filelog) | |
635 |
|
635 | |||
636 | def rev(self): |
|
636 | def rev(self): | |
637 | if '_changectx' in self.__dict__: |
|
637 | if '_changectx' in self.__dict__: | |
638 | return self._changectx.rev() |
|
638 | return self._changectx.rev() | |
639 | return self._filelog.linkrev(self._filenode) |
|
639 | return self._filelog.linkrev(self._filenode) | |
640 |
|
640 | |||
641 | def data(self): return self._repo.wread(self._path) |
|
641 | def data(self): return self._repo.wread(self._path) | |
642 | def renamed(self): |
|
642 | def renamed(self): | |
643 | rp = self._repopath |
|
643 | rp = self._repopath | |
644 | if rp == self._path: |
|
644 | if rp == self._path: | |
645 | return None |
|
645 | return None | |
646 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
646 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
647 |
|
647 | |||
648 | def parents(self): |
|
648 | def parents(self): | |
649 | '''return parent filectxs, following copies if necessary''' |
|
649 | '''return parent filectxs, following copies if necessary''' | |
650 | p = self._path |
|
650 | p = self._path | |
651 | rp = self._repopath |
|
651 | rp = self._repopath | |
652 | pcl = self._changectx._parents |
|
652 | pcl = self._changectx._parents | |
653 | fl = self._filelog |
|
653 | fl = self._filelog | |
654 | pl = [(rp, pcl[0]._manifest.get(rp, nullid), fl)] |
|
654 | pl = [(rp, pcl[0]._manifest.get(rp, nullid), fl)] | |
655 | if len(pcl) > 1: |
|
655 | if len(pcl) > 1: | |
656 | if rp != p: |
|
656 | if rp != p: | |
657 | fl = None |
|
657 | fl = None | |
658 | pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) |
|
658 | pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) | |
659 |
|
659 | |||
660 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
660 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
661 | for p,n,l in pl if n != nullid] |
|
661 | for p,n,l in pl if n != nullid] | |
662 |
|
662 | |||
663 | def children(self): |
|
663 | def children(self): | |
664 | return [] |
|
664 | return [] | |
665 |
|
665 | |||
666 | def size(self): return os.stat(self._repo.wjoin(self._path)).st_size |
|
666 | def size(self): return os.stat(self._repo.wjoin(self._path)).st_size | |
667 | def date(self): |
|
667 | def date(self): | |
668 | t, tz = self._changectx.date() |
|
668 | t, tz = self._changectx.date() | |
669 | try: |
|
669 | try: | |
670 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
|
670 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) | |
671 | except OSError, err: |
|
671 | except OSError, err: | |
672 | if err.errno != errno.ENOENT: raise |
|
672 | if err.errno != errno.ENOENT: raise | |
673 | return (t, tz) |
|
673 | return (t, tz) | |
674 |
|
674 | |||
675 | def cmp(self, text): return self._repo.wread(self._path) == text |
|
675 | def cmp(self, text): return self._repo.wread(self._path) == text | |
676 |
|
676 | |||
677 | class memctx(object): |
|
677 | class memctx(object): | |
678 | """A memctx is a subset of changectx supposed to be built on memory |
|
678 | """A memctx is a subset of changectx supposed to be built on memory | |
679 | and passed to commit functions. |
|
679 | and passed to commit functions. | |
680 |
|
680 | |||
681 | NOTE: this interface and the related memfilectx are experimental and |
|
681 | NOTE: this interface and the related memfilectx are experimental and | |
682 | may change without notice. |
|
682 | may change without notice. | |
683 |
|
683 | |||
684 | parents - a pair of parent nodeids. |
|
684 | parents - a pair of parent nodeids. | |
685 | filectxfn - a callable taking (repo, memctx, path) arguments and |
|
685 | filectxfn - a callable taking (repo, memctx, path) arguments and | |
686 | returning a memctx object. |
|
686 | returning a memctx object. | |
687 | date - any valid date string or (unixtime, offset), or None. |
|
687 | date - any valid date string or (unixtime, offset), or None. | |
688 | user - username string, or None. |
|
688 | user - username string, or None. | |
689 | extra - a dictionary of extra values, or None. |
|
689 | extra - a dictionary of extra values, or None. | |
690 | """ |
|
690 | """ | |
691 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
691 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
692 | date=None, extra=None): |
|
692 | date=None, extra=None): | |
693 | self._repo = repo |
|
693 | self._repo = repo | |
694 | self._rev = None |
|
694 | self._rev = None | |
695 | self._node = None |
|
695 | self._node = None | |
696 | self._text = text |
|
696 | self._text = text | |
697 | self._date = date and util.parsedate(date) or util.makedate() |
|
697 | self._date = date and util.parsedate(date) or util.makedate() | |
698 | self._user = user or self._repo.ui.username() |
|
698 | self._user = user or self._repo.ui.username() | |
699 | parents = [(p or nullid) for p in parents] |
|
699 | parents = [(p or nullid) for p in parents] | |
700 | p1, p2 = parents |
|
700 | p1, p2 = parents | |
701 | self._parents = [self._repo.changectx(p) for p in (p1, p2)] |
|
701 | self._parents = [self._repo.changectx(p) for p in (p1, p2)] | |
702 | files = list(files) |
|
702 | files = list(files) | |
703 | files.sort() |
|
703 | files.sort() | |
704 | self._status = [files, [], [], [], []] |
|
704 | self._status = [files, [], [], [], []] | |
705 | self._filectxfn = filectxfn |
|
705 | self._filectxfn = filectxfn | |
706 |
|
706 | |||
707 | self._extra = extra and extra.copy() or {} |
|
707 | self._extra = extra and extra.copy() or {} | |
708 | if 'branch' not in self._extra: |
|
708 | if 'branch' not in self._extra: | |
709 | self._extra['branch'] = 'default' |
|
709 | self._extra['branch'] = 'default' | |
710 | elif self._extra.get('branch') == '': |
|
710 | elif self._extra.get('branch') == '': | |
711 | self._extra['branch'] = 'default' |
|
711 | self._extra['branch'] = 'default' | |
712 |
|
712 | |||
713 | def __str__(self): |
|
713 | def __str__(self): | |
714 | return str(self._parents[0]) + "+" |
|
714 | return str(self._parents[0]) + "+" | |
715 |
|
715 | |||
716 | def __nonzero__(self): |
|
716 | def __nonzero__(self): | |
717 | return True |
|
717 | return True | |
718 |
|
718 | |||
719 | def user(self): return self._user |
|
719 | def user(self): return self._user | |
720 | def date(self): return self._date |
|
720 | def date(self): return self._date | |
721 | def description(self): return self._text |
|
721 | def description(self): return self._text | |
722 | def files(self): return self.modified() |
|
722 | def files(self): return self.modified() | |
723 | def modified(self): return self._status[0] |
|
723 | def modified(self): return self._status[0] | |
724 | def added(self): return self._status[1] |
|
724 | def added(self): return self._status[1] | |
725 | def removed(self): return self._status[2] |
|
725 | def removed(self): return self._status[2] | |
726 | def deleted(self): return self._status[3] |
|
726 | def deleted(self): return self._status[3] | |
727 | def unknown(self): return self._status[4] |
|
727 | def unknown(self): return self._status[4] | |
728 | def clean(self): return self._status[5] |
|
728 | def clean(self): return self._status[5] | |
729 | def branch(self): return self._extra['branch'] |
|
729 | def branch(self): return self._extra['branch'] | |
730 | def extra(self): return self._extra |
|
730 | def extra(self): return self._extra | |
731 |
|
731 | |||
732 | def parents(self): |
|
732 | def parents(self): | |
733 | """return contexts for each parent changeset""" |
|
733 | """return contexts for each parent changeset""" | |
734 | return self._parents |
|
734 | return self._parents | |
735 |
|
735 | |||
736 | def filectx(self, path, filelog=None): |
|
736 | def filectx(self, path, filelog=None): | |
737 | """get a file context from the working directory""" |
|
737 | """get a file context from the working directory""" | |
738 | return self._filectxfn(self._repo, self, path) |
|
738 | return self._filectxfn(self._repo, self, path) | |
739 |
|
739 | |||
740 | class memfilectx(object): |
|
740 | class memfilectx(object): | |
741 | """A memfilectx is a subset of filectx supposed to be built by client |
|
741 | """A memfilectx is a subset of filectx supposed to be built by client | |
742 | code and passed to commit functions. |
|
742 | code and passed to commit functions. | |
743 | """ |
|
743 | """ | |
744 | def __init__(self, path, data, islink, isexec, copied): |
|
744 | def __init__(self, path, data, islink, isexec, copied): | |
745 | """copied is the source file path, or None.""" |
|
745 | """copied is the source file path, or None.""" | |
746 | self._path = path |
|
746 | self._path = path | |
747 | self._data = data |
|
747 | self._data = data | |
748 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
748 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
749 | self._copied = None |
|
749 | self._copied = None | |
750 | if copied: |
|
750 | if copied: | |
751 | self._copied = (copied, nullid) |
|
751 | self._copied = (copied, nullid) | |
752 |
|
752 | |||
753 | def __nonzero__(self): return True |
|
753 | def __nonzero__(self): return True | |
754 | def __str__(self): return "%s@%s" % (self.path(), self._changectx) |
|
754 | def __str__(self): return "%s@%s" % (self.path(), self._changectx) | |
755 | def path(self): return self._path |
|
755 | def path(self): return self._path | |
756 | def data(self): return self._data |
|
756 | def data(self): return self._data | |
757 | def fileflags(self): return self._flags |
|
757 | def fileflags(self): return self._flags | |
758 | def isexec(self): return 'x' in self._flags |
|
758 | def isexec(self): return 'x' in self._flags | |
759 | def islink(self): return 'l' in self._flags |
|
759 | def islink(self): return 'l' in self._flags | |
760 | def renamed(self): return self._copied |
|
760 | def renamed(self): return self._copied | |
761 |
|
761 |
General Comments 0
You need to be logged in to leave comments.
Login now