Show More
@@ -1,1880 +1,1884 | |||||
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, bin |
|
8 | from node import nullid, nullrev, short, hex, bin | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import mdiff, error, util, scmutil, subrepo, patch, encoding, phases |
|
10 | import mdiff, error, util, scmutil, subrepo, patch, encoding, phases | |
11 | import match as matchmod |
|
11 | import match as matchmod | |
12 | import os, errno, stat |
|
12 | import os, errno, stat | |
13 | import obsolete as obsmod |
|
13 | import obsolete as obsmod | |
14 | import repoview |
|
14 | import repoview | |
15 | import fileset |
|
15 | import fileset | |
16 | import revlog |
|
16 | import revlog | |
17 |
|
17 | |||
18 | propertycache = util.propertycache |
|
18 | propertycache = util.propertycache | |
19 |
|
19 | |||
20 | # Phony node value to stand-in for new files in some uses of |
|
20 | # Phony node value to stand-in for new files in some uses of | |
21 | # manifests. Manifests support 21-byte hashes for nodes which are |
|
21 | # manifests. Manifests support 21-byte hashes for nodes which are | |
22 | # dirty in the working copy. |
|
22 | # dirty in the working copy. | |
23 | _newnode = '!' * 21 |
|
23 | _newnode = '!' * 21 | |
24 |
|
24 | |||
25 | class basectx(object): |
|
25 | class basectx(object): | |
26 | """A basectx object represents the common logic for its children: |
|
26 | """A basectx object represents the common logic for its children: | |
27 | changectx: read-only context that is already present in the repo, |
|
27 | changectx: read-only context that is already present in the repo, | |
28 | workingctx: a context that represents the working directory and can |
|
28 | workingctx: a context that represents the working directory and can | |
29 | be committed, |
|
29 | be committed, | |
30 | memctx: a context that represents changes in-memory and can also |
|
30 | memctx: a context that represents changes in-memory and can also | |
31 | be committed.""" |
|
31 | be committed.""" | |
32 | def __new__(cls, repo, changeid='', *args, **kwargs): |
|
32 | def __new__(cls, repo, changeid='', *args, **kwargs): | |
33 | if isinstance(changeid, basectx): |
|
33 | if isinstance(changeid, basectx): | |
34 | return changeid |
|
34 | return changeid | |
35 |
|
35 | |||
36 | o = super(basectx, cls).__new__(cls) |
|
36 | o = super(basectx, cls).__new__(cls) | |
37 |
|
37 | |||
38 | o._repo = repo |
|
38 | o._repo = repo | |
39 | o._rev = nullrev |
|
39 | o._rev = nullrev | |
40 | o._node = nullid |
|
40 | o._node = nullid | |
41 |
|
41 | |||
42 | return o |
|
42 | return o | |
43 |
|
43 | |||
44 | def __str__(self): |
|
44 | def __str__(self): | |
45 | return short(self.node()) |
|
45 | return short(self.node()) | |
46 |
|
46 | |||
47 | def __int__(self): |
|
47 | def __int__(self): | |
48 | return self.rev() |
|
48 | return self.rev() | |
49 |
|
49 | |||
50 | def __repr__(self): |
|
50 | def __repr__(self): | |
51 | return "<%s %s>" % (type(self).__name__, str(self)) |
|
51 | return "<%s %s>" % (type(self).__name__, str(self)) | |
52 |
|
52 | |||
53 | def __eq__(self, other): |
|
53 | def __eq__(self, other): | |
54 | try: |
|
54 | try: | |
55 | return type(self) == type(other) and self._rev == other._rev |
|
55 | return type(self) == type(other) and self._rev == other._rev | |
56 | except AttributeError: |
|
56 | except AttributeError: | |
57 | return False |
|
57 | return False | |
58 |
|
58 | |||
59 | def __ne__(self, other): |
|
59 | def __ne__(self, other): | |
60 | return not (self == other) |
|
60 | return not (self == other) | |
61 |
|
61 | |||
62 | def __contains__(self, key): |
|
62 | def __contains__(self, key): | |
63 | return key in self._manifest |
|
63 | return key in self._manifest | |
64 |
|
64 | |||
65 | def __getitem__(self, key): |
|
65 | def __getitem__(self, key): | |
66 | return self.filectx(key) |
|
66 | return self.filectx(key) | |
67 |
|
67 | |||
68 | def __iter__(self): |
|
68 | def __iter__(self): | |
69 | return iter(self._manifest) |
|
69 | return iter(self._manifest) | |
70 |
|
70 | |||
71 | def _manifestmatches(self, match, s): |
|
71 | def _manifestmatches(self, match, s): | |
72 | """generate a new manifest filtered by the match argument |
|
72 | """generate a new manifest filtered by the match argument | |
73 |
|
73 | |||
74 | This method is for internal use only and mainly exists to provide an |
|
74 | This method is for internal use only and mainly exists to provide an | |
75 | object oriented way for other contexts to customize the manifest |
|
75 | object oriented way for other contexts to customize the manifest | |
76 | generation. |
|
76 | generation. | |
77 | """ |
|
77 | """ | |
78 | return self.manifest().matches(match) |
|
78 | return self.manifest().matches(match) | |
79 |
|
79 | |||
80 | def _matchstatus(self, other, match): |
|
80 | def _matchstatus(self, other, match): | |
81 | """return match.always if match is none |
|
81 | """return match.always if match is none | |
82 |
|
82 | |||
83 | This internal method provides a way for child objects to override the |
|
83 | This internal method provides a way for child objects to override the | |
84 | match operator. |
|
84 | match operator. | |
85 | """ |
|
85 | """ | |
86 | return match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
86 | return match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
87 |
|
87 | |||
88 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
88 | def _buildstatus(self, other, s, match, listignored, listclean, | |
89 | listunknown): |
|
89 | listunknown): | |
90 | """build a status with respect to another context""" |
|
90 | """build a status with respect to another context""" | |
91 | # Load earliest manifest first for caching reasons. More specifically, |
|
91 | # Load earliest manifest first for caching reasons. More specifically, | |
92 | # if you have revisions 1000 and 1001, 1001 is probably stored as a |
|
92 | # if you have revisions 1000 and 1001, 1001 is probably stored as a | |
93 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct |
|
93 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct | |
94 | # 1000 and cache it so that when you read 1001, we just need to apply a |
|
94 | # 1000 and cache it so that when you read 1001, we just need to apply a | |
95 | # delta to what's in the cache. So that's one full reconstruction + one |
|
95 | # delta to what's in the cache. So that's one full reconstruction + one | |
96 | # delta application. |
|
96 | # delta application. | |
97 | if self.rev() is not None and self.rev() < other.rev(): |
|
97 | if self.rev() is not None and self.rev() < other.rev(): | |
98 | self.manifest() |
|
98 | self.manifest() | |
99 | mf1 = other._manifestmatches(match, s) |
|
99 | mf1 = other._manifestmatches(match, s) | |
100 | mf2 = self._manifestmatches(match, s) |
|
100 | mf2 = self._manifestmatches(match, s) | |
101 |
|
101 | |||
102 | modified, added = [], [] |
|
102 | modified, added = [], [] | |
103 | removed = [] |
|
103 | removed = [] | |
104 | clean = [] |
|
104 | clean = [] | |
105 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored |
|
105 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored | |
106 | deletedset = set(deleted) |
|
106 | deletedset = set(deleted) | |
107 | d = mf1.diff(mf2, clean=listclean) |
|
107 | d = mf1.diff(mf2, clean=listclean) | |
108 | for fn, value in d.iteritems(): |
|
108 | for fn, value in d.iteritems(): | |
109 | if fn in deletedset: |
|
109 | if fn in deletedset: | |
110 | continue |
|
110 | continue | |
111 | if value is None: |
|
111 | if value is None: | |
112 | clean.append(fn) |
|
112 | clean.append(fn) | |
113 | continue |
|
113 | continue | |
114 | (node1, flag1), (node2, flag2) = value |
|
114 | (node1, flag1), (node2, flag2) = value | |
115 | if node1 is None: |
|
115 | if node1 is None: | |
116 | added.append(fn) |
|
116 | added.append(fn) | |
117 | elif node2 is None: |
|
117 | elif node2 is None: | |
118 | removed.append(fn) |
|
118 | removed.append(fn) | |
119 | elif node2 != _newnode: |
|
119 | elif node2 != _newnode: | |
120 | # The file was not a new file in mf2, so an entry |
|
120 | # The file was not a new file in mf2, so an entry | |
121 | # from diff is really a difference. |
|
121 | # from diff is really a difference. | |
122 | modified.append(fn) |
|
122 | modified.append(fn) | |
123 | elif self[fn].cmp(other[fn]): |
|
123 | elif self[fn].cmp(other[fn]): | |
124 | # node2 was newnode, but the working file doesn't |
|
124 | # node2 was newnode, but the working file doesn't | |
125 | # match the one in mf1. |
|
125 | # match the one in mf1. | |
126 | modified.append(fn) |
|
126 | modified.append(fn) | |
127 | else: |
|
127 | else: | |
128 | clean.append(fn) |
|
128 | clean.append(fn) | |
129 |
|
129 | |||
130 | if removed: |
|
130 | if removed: | |
131 | # need to filter files if they are already reported as removed |
|
131 | # need to filter files if they are already reported as removed | |
132 | unknown = [fn for fn in unknown if fn not in mf1] |
|
132 | unknown = [fn for fn in unknown if fn not in mf1] | |
133 | ignored = [fn for fn in ignored if fn not in mf1] |
|
133 | ignored = [fn for fn in ignored if fn not in mf1] | |
134 | # if they're deleted, don't report them as removed |
|
134 | # if they're deleted, don't report them as removed | |
135 | removed = [fn for fn in removed if fn not in deletedset] |
|
135 | removed = [fn for fn in removed if fn not in deletedset] | |
136 |
|
136 | |||
137 | return scmutil.status(modified, added, removed, deleted, unknown, |
|
137 | return scmutil.status(modified, added, removed, deleted, unknown, | |
138 | ignored, clean) |
|
138 | ignored, clean) | |
139 |
|
139 | |||
140 | @propertycache |
|
140 | @propertycache | |
141 | def substate(self): |
|
141 | def substate(self): | |
142 | return subrepo.state(self, self._repo.ui) |
|
142 | return subrepo.state(self, self._repo.ui) | |
143 |
|
143 | |||
144 | def subrev(self, subpath): |
|
144 | def subrev(self, subpath): | |
145 | return self.substate[subpath][1] |
|
145 | return self.substate[subpath][1] | |
146 |
|
146 | |||
147 | def rev(self): |
|
147 | def rev(self): | |
148 | return self._rev |
|
148 | return self._rev | |
149 | def node(self): |
|
149 | def node(self): | |
150 | return self._node |
|
150 | return self._node | |
151 | def hex(self): |
|
151 | def hex(self): | |
152 | return hex(self.node()) |
|
152 | return hex(self.node()) | |
153 | def manifest(self): |
|
153 | def manifest(self): | |
154 | return self._manifest |
|
154 | return self._manifest | |
155 | def repo(self): |
|
155 | def repo(self): | |
156 | return self._repo |
|
156 | return self._repo | |
157 | def phasestr(self): |
|
157 | def phasestr(self): | |
158 | return phases.phasenames[self.phase()] |
|
158 | return phases.phasenames[self.phase()] | |
159 | def mutable(self): |
|
159 | def mutable(self): | |
160 | return self.phase() > phases.public |
|
160 | return self.phase() > phases.public | |
161 |
|
161 | |||
162 | def getfileset(self, expr): |
|
162 | def getfileset(self, expr): | |
163 | return fileset.getfileset(self, expr) |
|
163 | return fileset.getfileset(self, expr) | |
164 |
|
164 | |||
165 | def obsolete(self): |
|
165 | def obsolete(self): | |
166 | """True if the changeset is obsolete""" |
|
166 | """True if the changeset is obsolete""" | |
167 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') |
|
167 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') | |
168 |
|
168 | |||
169 | def extinct(self): |
|
169 | def extinct(self): | |
170 | """True if the changeset is extinct""" |
|
170 | """True if the changeset is extinct""" | |
171 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') |
|
171 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') | |
172 |
|
172 | |||
173 | def unstable(self): |
|
173 | def unstable(self): | |
174 | """True if the changeset is not obsolete but it's ancestor are""" |
|
174 | """True if the changeset is not obsolete but it's ancestor are""" | |
175 | return self.rev() in obsmod.getrevs(self._repo, 'unstable') |
|
175 | return self.rev() in obsmod.getrevs(self._repo, 'unstable') | |
176 |
|
176 | |||
177 | def bumped(self): |
|
177 | def bumped(self): | |
178 | """True if the changeset try to be a successor of a public changeset |
|
178 | """True if the changeset try to be a successor of a public changeset | |
179 |
|
179 | |||
180 | Only non-public and non-obsolete changesets may be bumped. |
|
180 | Only non-public and non-obsolete changesets may be bumped. | |
181 | """ |
|
181 | """ | |
182 | return self.rev() in obsmod.getrevs(self._repo, 'bumped') |
|
182 | return self.rev() in obsmod.getrevs(self._repo, 'bumped') | |
183 |
|
183 | |||
184 | def divergent(self): |
|
184 | def divergent(self): | |
185 | """Is a successors of a changeset with multiple possible successors set |
|
185 | """Is a successors of a changeset with multiple possible successors set | |
186 |
|
186 | |||
187 | Only non-public and non-obsolete changesets may be divergent. |
|
187 | Only non-public and non-obsolete changesets may be divergent. | |
188 | """ |
|
188 | """ | |
189 | return self.rev() in obsmod.getrevs(self._repo, 'divergent') |
|
189 | return self.rev() in obsmod.getrevs(self._repo, 'divergent') | |
190 |
|
190 | |||
191 | def troubled(self): |
|
191 | def troubled(self): | |
192 | """True if the changeset is either unstable, bumped or divergent""" |
|
192 | """True if the changeset is either unstable, bumped or divergent""" | |
193 | return self.unstable() or self.bumped() or self.divergent() |
|
193 | return self.unstable() or self.bumped() or self.divergent() | |
194 |
|
194 | |||
195 | def troubles(self): |
|
195 | def troubles(self): | |
196 | """return the list of troubles affecting this changesets. |
|
196 | """return the list of troubles affecting this changesets. | |
197 |
|
197 | |||
198 | Troubles are returned as strings. possible values are: |
|
198 | Troubles are returned as strings. possible values are: | |
199 | - unstable, |
|
199 | - unstable, | |
200 | - bumped, |
|
200 | - bumped, | |
201 | - divergent. |
|
201 | - divergent. | |
202 | """ |
|
202 | """ | |
203 | troubles = [] |
|
203 | troubles = [] | |
204 | if self.unstable(): |
|
204 | if self.unstable(): | |
205 | troubles.append('unstable') |
|
205 | troubles.append('unstable') | |
206 | if self.bumped(): |
|
206 | if self.bumped(): | |
207 | troubles.append('bumped') |
|
207 | troubles.append('bumped') | |
208 | if self.divergent(): |
|
208 | if self.divergent(): | |
209 | troubles.append('divergent') |
|
209 | troubles.append('divergent') | |
210 | return troubles |
|
210 | return troubles | |
211 |
|
211 | |||
212 | def parents(self): |
|
212 | def parents(self): | |
213 | """return contexts for each parent changeset""" |
|
213 | """return contexts for each parent changeset""" | |
214 | return self._parents |
|
214 | return self._parents | |
215 |
|
215 | |||
216 | def p1(self): |
|
216 | def p1(self): | |
217 | return self._parents[0] |
|
217 | return self._parents[0] | |
218 |
|
218 | |||
219 | def p2(self): |
|
219 | def p2(self): | |
220 | if len(self._parents) == 2: |
|
220 | if len(self._parents) == 2: | |
221 | return self._parents[1] |
|
221 | return self._parents[1] | |
222 | return changectx(self._repo, -1) |
|
222 | return changectx(self._repo, -1) | |
223 |
|
223 | |||
224 | def _fileinfo(self, path): |
|
224 | def _fileinfo(self, path): | |
225 | if '_manifest' in self.__dict__: |
|
225 | if '_manifest' in self.__dict__: | |
226 | try: |
|
226 | try: | |
227 | return self._manifest[path], self._manifest.flags(path) |
|
227 | return self._manifest[path], self._manifest.flags(path) | |
228 | except KeyError: |
|
228 | except KeyError: | |
229 | raise error.ManifestLookupError(self._node, path, |
|
229 | raise error.ManifestLookupError(self._node, path, | |
230 | _('not found in manifest')) |
|
230 | _('not found in manifest')) | |
231 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
231 | if '_manifestdelta' in self.__dict__ or path in self.files(): | |
232 | if path in self._manifestdelta: |
|
232 | if path in self._manifestdelta: | |
233 | return (self._manifestdelta[path], |
|
233 | return (self._manifestdelta[path], | |
234 | self._manifestdelta.flags(path)) |
|
234 | self._manifestdelta.flags(path)) | |
235 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
235 | node, flag = self._repo.manifest.find(self._changeset[0], path) | |
236 | if not node: |
|
236 | if not node: | |
237 | raise error.ManifestLookupError(self._node, path, |
|
237 | raise error.ManifestLookupError(self._node, path, | |
238 | _('not found in manifest')) |
|
238 | _('not found in manifest')) | |
239 |
|
239 | |||
240 | return node, flag |
|
240 | return node, flag | |
241 |
|
241 | |||
242 | def filenode(self, path): |
|
242 | def filenode(self, path): | |
243 | return self._fileinfo(path)[0] |
|
243 | return self._fileinfo(path)[0] | |
244 |
|
244 | |||
245 | def flags(self, path): |
|
245 | def flags(self, path): | |
246 | try: |
|
246 | try: | |
247 | return self._fileinfo(path)[1] |
|
247 | return self._fileinfo(path)[1] | |
248 | except error.LookupError: |
|
248 | except error.LookupError: | |
249 | return '' |
|
249 | return '' | |
250 |
|
250 | |||
251 | def sub(self, path): |
|
251 | def sub(self, path): | |
252 | return subrepo.subrepo(self, path) |
|
252 | return subrepo.subrepo(self, path) | |
253 |
|
253 | |||
254 | def match(self, pats=[], include=None, exclude=None, default='glob'): |
|
254 | def match(self, pats=[], include=None, exclude=None, default='glob'): | |
255 | r = self._repo |
|
255 | r = self._repo | |
256 | return matchmod.match(r.root, r.getcwd(), pats, |
|
256 | return matchmod.match(r.root, r.getcwd(), pats, | |
257 | include, exclude, default, |
|
257 | include, exclude, default, | |
258 | auditor=r.auditor, ctx=self) |
|
258 | auditor=r.auditor, ctx=self) | |
259 |
|
259 | |||
260 | def diff(self, ctx2=None, match=None, **opts): |
|
260 | def diff(self, ctx2=None, match=None, **opts): | |
261 | """Returns a diff generator for the given contexts and matcher""" |
|
261 | """Returns a diff generator for the given contexts and matcher""" | |
262 | if ctx2 is None: |
|
262 | if ctx2 is None: | |
263 | ctx2 = self.p1() |
|
263 | ctx2 = self.p1() | |
264 | if ctx2 is not None: |
|
264 | if ctx2 is not None: | |
265 | ctx2 = self._repo[ctx2] |
|
265 | ctx2 = self._repo[ctx2] | |
266 | diffopts = patch.diffopts(self._repo.ui, opts) |
|
266 | diffopts = patch.diffopts(self._repo.ui, opts) | |
267 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) |
|
267 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) | |
268 |
|
268 | |||
269 | def dirs(self): |
|
269 | def dirs(self): | |
270 | return self._manifest.dirs() |
|
270 | return self._manifest.dirs() | |
271 |
|
271 | |||
272 | def hasdir(self, dir): |
|
272 | def hasdir(self, dir): | |
273 | return self._manifest.hasdir(dir) |
|
273 | return self._manifest.hasdir(dir) | |
274 |
|
274 | |||
275 | def dirty(self, missing=False, merge=True, branch=True): |
|
275 | def dirty(self, missing=False, merge=True, branch=True): | |
276 | return False |
|
276 | return False | |
277 |
|
277 | |||
278 | def status(self, other=None, match=None, listignored=False, |
|
278 | def status(self, other=None, match=None, listignored=False, | |
279 | listclean=False, listunknown=False, listsubrepos=False): |
|
279 | listclean=False, listunknown=False, listsubrepos=False): | |
280 | """return status of files between two nodes or node and working |
|
280 | """return status of files between two nodes or node and working | |
281 | directory. |
|
281 | directory. | |
282 |
|
282 | |||
283 | If other is None, compare this node with working directory. |
|
283 | If other is None, compare this node with working directory. | |
284 |
|
284 | |||
285 | returns (modified, added, removed, deleted, unknown, ignored, clean) |
|
285 | returns (modified, added, removed, deleted, unknown, ignored, clean) | |
286 | """ |
|
286 | """ | |
287 |
|
287 | |||
288 | ctx1 = self |
|
288 | ctx1 = self | |
289 | ctx2 = self._repo[other] |
|
289 | ctx2 = self._repo[other] | |
290 |
|
290 | |||
291 | # This next code block is, admittedly, fragile logic that tests for |
|
291 | # This next code block is, admittedly, fragile logic that tests for | |
292 | # reversing the contexts and wouldn't need to exist if it weren't for |
|
292 | # reversing the contexts and wouldn't need to exist if it weren't for | |
293 | # the fast (and common) code path of comparing the working directory |
|
293 | # the fast (and common) code path of comparing the working directory | |
294 | # with its first parent. |
|
294 | # with its first parent. | |
295 | # |
|
295 | # | |
296 | # What we're aiming for here is the ability to call: |
|
296 | # What we're aiming for here is the ability to call: | |
297 | # |
|
297 | # | |
298 | # workingctx.status(parentctx) |
|
298 | # workingctx.status(parentctx) | |
299 | # |
|
299 | # | |
300 | # If we always built the manifest for each context and compared those, |
|
300 | # If we always built the manifest for each context and compared those, | |
301 | # then we'd be done. But the special case of the above call means we |
|
301 | # then we'd be done. But the special case of the above call means we | |
302 | # just copy the manifest of the parent. |
|
302 | # just copy the manifest of the parent. | |
303 | reversed = False |
|
303 | reversed = False | |
304 | if (not isinstance(ctx1, changectx) |
|
304 | if (not isinstance(ctx1, changectx) | |
305 | and isinstance(ctx2, changectx)): |
|
305 | and isinstance(ctx2, changectx)): | |
306 | reversed = True |
|
306 | reversed = True | |
307 | ctx1, ctx2 = ctx2, ctx1 |
|
307 | ctx1, ctx2 = ctx2, ctx1 | |
308 |
|
308 | |||
309 | match = ctx2._matchstatus(ctx1, match) |
|
309 | match = ctx2._matchstatus(ctx1, match) | |
310 | r = scmutil.status([], [], [], [], [], [], []) |
|
310 | r = scmutil.status([], [], [], [], [], [], []) | |
311 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, |
|
311 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, | |
312 | listunknown) |
|
312 | listunknown) | |
313 |
|
313 | |||
314 | if reversed: |
|
314 | if reversed: | |
315 | # Reverse added and removed. Clear deleted, unknown and ignored as |
|
315 | # Reverse added and removed. Clear deleted, unknown and ignored as | |
316 | # these make no sense to reverse. |
|
316 | # these make no sense to reverse. | |
317 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], |
|
317 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], | |
318 | r.clean) |
|
318 | r.clean) | |
319 |
|
319 | |||
320 | if listsubrepos: |
|
320 | if listsubrepos: | |
321 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
321 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): | |
322 | rev2 = ctx2.subrev(subpath) |
|
322 | rev2 = ctx2.subrev(subpath) | |
323 | try: |
|
323 | try: | |
324 | submatch = matchmod.narrowmatcher(subpath, match) |
|
324 | submatch = matchmod.narrowmatcher(subpath, match) | |
325 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
325 | s = sub.status(rev2, match=submatch, ignored=listignored, | |
326 | clean=listclean, unknown=listunknown, |
|
326 | clean=listclean, unknown=listunknown, | |
327 | listsubrepos=True) |
|
327 | listsubrepos=True) | |
328 | for rfiles, sfiles in zip(r, s): |
|
328 | for rfiles, sfiles in zip(r, s): | |
329 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
329 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) | |
330 | except error.LookupError: |
|
330 | except error.LookupError: | |
331 | self._repo.ui.status(_("skipping missing " |
|
331 | self._repo.ui.status(_("skipping missing " | |
332 | "subrepository: %s\n") % subpath) |
|
332 | "subrepository: %s\n") % subpath) | |
333 |
|
333 | |||
334 | for l in r: |
|
334 | for l in r: | |
335 | l.sort() |
|
335 | l.sort() | |
336 |
|
336 | |||
337 | return r |
|
337 | return r | |
338 |
|
338 | |||
339 |
|
339 | |||
340 | def makememctx(repo, parents, text, user, date, branch, files, store, |
|
340 | def makememctx(repo, parents, text, user, date, branch, files, store, | |
341 | editor=None): |
|
341 | editor=None): | |
342 | def getfilectx(repo, memctx, path): |
|
342 | def getfilectx(repo, memctx, path): | |
343 | data, mode, copied = store.getfile(path) |
|
343 | data, mode, copied = store.getfile(path) | |
344 | if data is None: |
|
344 | if data is None: | |
345 | return None |
|
345 | return None | |
346 | islink, isexec = mode |
|
346 | islink, isexec = mode | |
347 | return memfilectx(repo, path, data, islink=islink, isexec=isexec, |
|
347 | return memfilectx(repo, path, data, islink=islink, isexec=isexec, | |
348 | copied=copied, memctx=memctx) |
|
348 | copied=copied, memctx=memctx) | |
349 | extra = {} |
|
349 | extra = {} | |
350 | if branch: |
|
350 | if branch: | |
351 | extra['branch'] = encoding.fromlocal(branch) |
|
351 | extra['branch'] = encoding.fromlocal(branch) | |
352 | ctx = memctx(repo, parents, text, files, getfilectx, user, |
|
352 | ctx = memctx(repo, parents, text, files, getfilectx, user, | |
353 | date, extra, editor) |
|
353 | date, extra, editor) | |
354 | return ctx |
|
354 | return ctx | |
355 |
|
355 | |||
356 | class changectx(basectx): |
|
356 | class changectx(basectx): | |
357 | """A changecontext object makes access to data related to a particular |
|
357 | """A changecontext object makes access to data related to a particular | |
358 | changeset convenient. It represents a read-only context already present in |
|
358 | changeset convenient. It represents a read-only context already present in | |
359 | the repo.""" |
|
359 | the repo.""" | |
360 | def __init__(self, repo, changeid=''): |
|
360 | def __init__(self, repo, changeid=''): | |
361 | """changeid is a revision number, node, or tag""" |
|
361 | """changeid is a revision number, node, or tag""" | |
362 |
|
362 | |||
363 | # since basectx.__new__ already took care of copying the object, we |
|
363 | # since basectx.__new__ already took care of copying the object, we | |
364 | # don't need to do anything in __init__, so we just exit here |
|
364 | # don't need to do anything in __init__, so we just exit here | |
365 | if isinstance(changeid, basectx): |
|
365 | if isinstance(changeid, basectx): | |
366 | return |
|
366 | return | |
367 |
|
367 | |||
368 | if changeid == '': |
|
368 | if changeid == '': | |
369 | changeid = '.' |
|
369 | changeid = '.' | |
370 | self._repo = repo |
|
370 | self._repo = repo | |
371 |
|
371 | |||
372 | try: |
|
372 | try: | |
373 | if isinstance(changeid, int): |
|
373 | if isinstance(changeid, int): | |
374 | self._node = repo.changelog.node(changeid) |
|
374 | self._node = repo.changelog.node(changeid) | |
375 | self._rev = changeid |
|
375 | self._rev = changeid | |
376 | return |
|
376 | return | |
377 | if isinstance(changeid, long): |
|
377 | if isinstance(changeid, long): | |
378 | changeid = str(changeid) |
|
378 | changeid = str(changeid) | |
379 | if changeid == 'null': |
|
379 | if changeid == 'null': | |
380 | self._node = nullid |
|
380 | self._node = nullid | |
381 | self._rev = nullrev |
|
381 | self._rev = nullrev | |
382 | return |
|
382 | return | |
383 | if changeid == 'tip': |
|
383 | if changeid == 'tip': | |
384 | self._node = repo.changelog.tip() |
|
384 | self._node = repo.changelog.tip() | |
385 | self._rev = repo.changelog.rev(self._node) |
|
385 | self._rev = repo.changelog.rev(self._node) | |
386 | return |
|
386 | return | |
387 | if changeid == '.' or changeid == repo.dirstate.p1(): |
|
387 | if changeid == '.' or changeid == repo.dirstate.p1(): | |
388 | # this is a hack to delay/avoid loading obsmarkers |
|
388 | # this is a hack to delay/avoid loading obsmarkers | |
389 | # when we know that '.' won't be hidden |
|
389 | # when we know that '.' won't be hidden | |
390 | self._node = repo.dirstate.p1() |
|
390 | self._node = repo.dirstate.p1() | |
391 | self._rev = repo.unfiltered().changelog.rev(self._node) |
|
391 | self._rev = repo.unfiltered().changelog.rev(self._node) | |
392 | return |
|
392 | return | |
393 | if len(changeid) == 20: |
|
393 | if len(changeid) == 20: | |
394 | try: |
|
394 | try: | |
395 | self._node = changeid |
|
395 | self._node = changeid | |
396 | self._rev = repo.changelog.rev(changeid) |
|
396 | self._rev = repo.changelog.rev(changeid) | |
397 | return |
|
397 | return | |
398 | except error.FilteredRepoLookupError: |
|
398 | except error.FilteredRepoLookupError: | |
399 | raise |
|
399 | raise | |
400 | except LookupError: |
|
400 | except LookupError: | |
401 | pass |
|
401 | pass | |
402 |
|
402 | |||
403 | try: |
|
403 | try: | |
404 | r = int(changeid) |
|
404 | r = int(changeid) | |
405 | if str(r) != changeid: |
|
405 | if str(r) != changeid: | |
406 | raise ValueError |
|
406 | raise ValueError | |
407 | l = len(repo.changelog) |
|
407 | l = len(repo.changelog) | |
408 | if r < 0: |
|
408 | if r < 0: | |
409 | r += l |
|
409 | r += l | |
410 | if r < 0 or r >= l: |
|
410 | if r < 0 or r >= l: | |
411 | raise ValueError |
|
411 | raise ValueError | |
412 | self._rev = r |
|
412 | self._rev = r | |
413 | self._node = repo.changelog.node(r) |
|
413 | self._node = repo.changelog.node(r) | |
414 | return |
|
414 | return | |
415 | except error.FilteredIndexError: |
|
415 | except error.FilteredIndexError: | |
416 | raise |
|
416 | raise | |
417 | except (ValueError, OverflowError, IndexError): |
|
417 | except (ValueError, OverflowError, IndexError): | |
418 | pass |
|
418 | pass | |
419 |
|
419 | |||
420 | if len(changeid) == 40: |
|
420 | if len(changeid) == 40: | |
421 | try: |
|
421 | try: | |
422 | self._node = bin(changeid) |
|
422 | self._node = bin(changeid) | |
423 | self._rev = repo.changelog.rev(self._node) |
|
423 | self._rev = repo.changelog.rev(self._node) | |
424 | return |
|
424 | return | |
425 | except error.FilteredLookupError: |
|
425 | except error.FilteredLookupError: | |
426 | raise |
|
426 | raise | |
427 | except (TypeError, LookupError): |
|
427 | except (TypeError, LookupError): | |
428 | pass |
|
428 | pass | |
429 |
|
429 | |||
430 | # lookup bookmarks through the name interface |
|
430 | # lookup bookmarks through the name interface | |
431 | try: |
|
431 | try: | |
432 | self._node = repo.names.singlenode(repo, changeid) |
|
432 | self._node = repo.names.singlenode(repo, changeid) | |
433 | self._rev = repo.changelog.rev(self._node) |
|
433 | self._rev = repo.changelog.rev(self._node) | |
434 | return |
|
434 | return | |
435 | except KeyError: |
|
435 | except KeyError: | |
436 | pass |
|
436 | pass | |
437 | except error.FilteredRepoLookupError: |
|
437 | except error.FilteredRepoLookupError: | |
438 | raise |
|
438 | raise | |
439 | except error.RepoLookupError: |
|
439 | except error.RepoLookupError: | |
440 | pass |
|
440 | pass | |
441 |
|
441 | |||
442 | self._node = repo.unfiltered().changelog._partialmatch(changeid) |
|
442 | self._node = repo.unfiltered().changelog._partialmatch(changeid) | |
443 | if self._node is not None: |
|
443 | if self._node is not None: | |
444 | self._rev = repo.changelog.rev(self._node) |
|
444 | self._rev = repo.changelog.rev(self._node) | |
445 | return |
|
445 | return | |
446 |
|
446 | |||
447 | # lookup failed |
|
447 | # lookup failed | |
448 | # check if it might have come from damaged dirstate |
|
448 | # check if it might have come from damaged dirstate | |
449 | # |
|
449 | # | |
450 | # XXX we could avoid the unfiltered if we had a recognizable |
|
450 | # XXX we could avoid the unfiltered if we had a recognizable | |
451 | # exception for filtered changeset access |
|
451 | # exception for filtered changeset access | |
452 | if changeid in repo.unfiltered().dirstate.parents(): |
|
452 | if changeid in repo.unfiltered().dirstate.parents(): | |
453 | msg = _("working directory has unknown parent '%s'!") |
|
453 | msg = _("working directory has unknown parent '%s'!") | |
454 | raise error.Abort(msg % short(changeid)) |
|
454 | raise error.Abort(msg % short(changeid)) | |
455 | try: |
|
455 | try: | |
456 | if len(changeid) == 20: |
|
456 | if len(changeid) == 20: | |
457 | changeid = hex(changeid) |
|
457 | changeid = hex(changeid) | |
458 | except TypeError: |
|
458 | except TypeError: | |
459 | pass |
|
459 | pass | |
460 | except (error.FilteredIndexError, error.FilteredLookupError, |
|
460 | except (error.FilteredIndexError, error.FilteredLookupError, | |
461 | error.FilteredRepoLookupError): |
|
461 | error.FilteredRepoLookupError): | |
462 | if repo.filtername == 'visible': |
|
462 | if repo.filtername == 'visible': | |
463 | msg = _("hidden revision '%s'") % changeid |
|
463 | msg = _("hidden revision '%s'") % changeid | |
464 | hint = _('use --hidden to access hidden revisions') |
|
464 | hint = _('use --hidden to access hidden revisions') | |
465 | raise error.FilteredRepoLookupError(msg, hint=hint) |
|
465 | raise error.FilteredRepoLookupError(msg, hint=hint) | |
466 | msg = _("filtered revision '%s' (not in '%s' subset)") |
|
466 | msg = _("filtered revision '%s' (not in '%s' subset)") | |
467 | msg %= (changeid, repo.filtername) |
|
467 | msg %= (changeid, repo.filtername) | |
468 | raise error.FilteredRepoLookupError(msg) |
|
468 | raise error.FilteredRepoLookupError(msg) | |
469 | except IndexError: |
|
469 | except IndexError: | |
470 | pass |
|
470 | pass | |
471 | raise error.RepoLookupError( |
|
471 | raise error.RepoLookupError( | |
472 | _("unknown revision '%s'") % changeid) |
|
472 | _("unknown revision '%s'") % changeid) | |
473 |
|
473 | |||
474 | def __hash__(self): |
|
474 | def __hash__(self): | |
475 | try: |
|
475 | try: | |
476 | return hash(self._rev) |
|
476 | return hash(self._rev) | |
477 | except AttributeError: |
|
477 | except AttributeError: | |
478 | return id(self) |
|
478 | return id(self) | |
479 |
|
479 | |||
480 | def __nonzero__(self): |
|
480 | def __nonzero__(self): | |
481 | return self._rev != nullrev |
|
481 | return self._rev != nullrev | |
482 |
|
482 | |||
483 | @propertycache |
|
483 | @propertycache | |
484 | def _changeset(self): |
|
484 | def _changeset(self): | |
485 | return self._repo.changelog.read(self.rev()) |
|
485 | return self._repo.changelog.read(self.rev()) | |
486 |
|
486 | |||
487 | @propertycache |
|
487 | @propertycache | |
488 | def _manifest(self): |
|
488 | def _manifest(self): | |
489 | return self._repo.manifest.read(self._changeset[0]) |
|
489 | return self._repo.manifest.read(self._changeset[0]) | |
490 |
|
490 | |||
491 | @propertycache |
|
491 | @propertycache | |
492 | def _manifestdelta(self): |
|
492 | def _manifestdelta(self): | |
493 | return self._repo.manifest.readdelta(self._changeset[0]) |
|
493 | return self._repo.manifest.readdelta(self._changeset[0]) | |
494 |
|
494 | |||
495 | @propertycache |
|
495 | @propertycache | |
496 | def _parents(self): |
|
496 | def _parents(self): | |
497 | p = self._repo.changelog.parentrevs(self._rev) |
|
497 | p = self._repo.changelog.parentrevs(self._rev) | |
498 | if p[1] == nullrev: |
|
498 | if p[1] == nullrev: | |
499 | p = p[:-1] |
|
499 | p = p[:-1] | |
500 | return [changectx(self._repo, x) for x in p] |
|
500 | return [changectx(self._repo, x) for x in p] | |
501 |
|
501 | |||
502 | def changeset(self): |
|
502 | def changeset(self): | |
503 | return self._changeset |
|
503 | return self._changeset | |
504 | def manifestnode(self): |
|
504 | def manifestnode(self): | |
505 | return self._changeset[0] |
|
505 | return self._changeset[0] | |
506 |
|
506 | |||
507 | def user(self): |
|
507 | def user(self): | |
508 | return self._changeset[1] |
|
508 | return self._changeset[1] | |
509 | def date(self): |
|
509 | def date(self): | |
510 | return self._changeset[2] |
|
510 | return self._changeset[2] | |
511 | def files(self): |
|
511 | def files(self): | |
512 | return self._changeset[3] |
|
512 | return self._changeset[3] | |
513 | def description(self): |
|
513 | def description(self): | |
514 | return self._changeset[4] |
|
514 | return self._changeset[4] | |
515 | def branch(self): |
|
515 | def branch(self): | |
516 | return encoding.tolocal(self._changeset[5].get("branch")) |
|
516 | return encoding.tolocal(self._changeset[5].get("branch")) | |
517 | def closesbranch(self): |
|
517 | def closesbranch(self): | |
518 | return 'close' in self._changeset[5] |
|
518 | return 'close' in self._changeset[5] | |
519 | def extra(self): |
|
519 | def extra(self): | |
520 | return self._changeset[5] |
|
520 | return self._changeset[5] | |
521 | def tags(self): |
|
521 | def tags(self): | |
522 | return self._repo.nodetags(self._node) |
|
522 | return self._repo.nodetags(self._node) | |
523 | def bookmarks(self): |
|
523 | def bookmarks(self): | |
524 | return self._repo.nodebookmarks(self._node) |
|
524 | return self._repo.nodebookmarks(self._node) | |
525 | def phase(self): |
|
525 | def phase(self): | |
526 | return self._repo._phasecache.phase(self._repo, self._rev) |
|
526 | return self._repo._phasecache.phase(self._repo, self._rev) | |
527 | def hidden(self): |
|
527 | def hidden(self): | |
528 | return self._rev in repoview.filterrevs(self._repo, 'visible') |
|
528 | return self._rev in repoview.filterrevs(self._repo, 'visible') | |
529 |
|
529 | |||
530 | def children(self): |
|
530 | def children(self): | |
531 | """return contexts for each child changeset""" |
|
531 | """return contexts for each child changeset""" | |
532 | c = self._repo.changelog.children(self._node) |
|
532 | c = self._repo.changelog.children(self._node) | |
533 | return [changectx(self._repo, x) for x in c] |
|
533 | return [changectx(self._repo, x) for x in c] | |
534 |
|
534 | |||
535 | def ancestors(self): |
|
535 | def ancestors(self): | |
536 | for a in self._repo.changelog.ancestors([self._rev]): |
|
536 | for a in self._repo.changelog.ancestors([self._rev]): | |
537 | yield changectx(self._repo, a) |
|
537 | yield changectx(self._repo, a) | |
538 |
|
538 | |||
539 | def descendants(self): |
|
539 | def descendants(self): | |
540 | for d in self._repo.changelog.descendants([self._rev]): |
|
540 | for d in self._repo.changelog.descendants([self._rev]): | |
541 | yield changectx(self._repo, d) |
|
541 | yield changectx(self._repo, d) | |
542 |
|
542 | |||
543 | def filectx(self, path, fileid=None, filelog=None): |
|
543 | def filectx(self, path, fileid=None, filelog=None): | |
544 | """get a file context from this changeset""" |
|
544 | """get a file context from this changeset""" | |
545 | if fileid is None: |
|
545 | if fileid is None: | |
546 | fileid = self.filenode(path) |
|
546 | fileid = self.filenode(path) | |
547 | return filectx(self._repo, path, fileid=fileid, |
|
547 | return filectx(self._repo, path, fileid=fileid, | |
548 | changectx=self, filelog=filelog) |
|
548 | changectx=self, filelog=filelog) | |
549 |
|
549 | |||
550 | def ancestor(self, c2, warn=False): |
|
550 | def ancestor(self, c2, warn=False): | |
551 | """return the "best" ancestor context of self and c2 |
|
551 | """return the "best" ancestor context of self and c2 | |
552 |
|
552 | |||
553 | If there are multiple candidates, it will show a message and check |
|
553 | If there are multiple candidates, it will show a message and check | |
554 | merge.preferancestor configuration before falling back to the |
|
554 | merge.preferancestor configuration before falling back to the | |
555 | revlog ancestor.""" |
|
555 | revlog ancestor.""" | |
556 | # deal with workingctxs |
|
556 | # deal with workingctxs | |
557 | n2 = c2._node |
|
557 | n2 = c2._node | |
558 | if n2 is None: |
|
558 | if n2 is None: | |
559 | n2 = c2._parents[0]._node |
|
559 | n2 = c2._parents[0]._node | |
560 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) |
|
560 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) | |
561 | if not cahs: |
|
561 | if not cahs: | |
562 | anc = nullid |
|
562 | anc = nullid | |
563 | elif len(cahs) == 1: |
|
563 | elif len(cahs) == 1: | |
564 | anc = cahs[0] |
|
564 | anc = cahs[0] | |
565 | else: |
|
565 | else: | |
566 | for r in self._repo.ui.configlist('merge', 'preferancestor'): |
|
566 | for r in self._repo.ui.configlist('merge', 'preferancestor'): | |
567 | try: |
|
567 | try: | |
568 | ctx = changectx(self._repo, r) |
|
568 | ctx = changectx(self._repo, r) | |
569 | except error.RepoLookupError: |
|
569 | except error.RepoLookupError: | |
570 | continue |
|
570 | continue | |
571 | anc = ctx.node() |
|
571 | anc = ctx.node() | |
572 | if anc in cahs: |
|
572 | if anc in cahs: | |
573 | break |
|
573 | break | |
574 | else: |
|
574 | else: | |
575 | anc = self._repo.changelog.ancestor(self._node, n2) |
|
575 | anc = self._repo.changelog.ancestor(self._node, n2) | |
576 | if warn: |
|
576 | if warn: | |
577 | self._repo.ui.status( |
|
577 | self._repo.ui.status( | |
578 | (_("note: using %s as ancestor of %s and %s\n") % |
|
578 | (_("note: using %s as ancestor of %s and %s\n") % | |
579 | (short(anc), short(self._node), short(n2))) + |
|
579 | (short(anc), short(self._node), short(n2))) + | |
580 | ''.join(_(" alternatively, use --config " |
|
580 | ''.join(_(" alternatively, use --config " | |
581 | "merge.preferancestor=%s\n") % |
|
581 | "merge.preferancestor=%s\n") % | |
582 | short(n) for n in sorted(cahs) if n != anc)) |
|
582 | short(n) for n in sorted(cahs) if n != anc)) | |
583 | return changectx(self._repo, anc) |
|
583 | return changectx(self._repo, anc) | |
584 |
|
584 | |||
585 | def descendant(self, other): |
|
585 | def descendant(self, other): | |
586 | """True if other is descendant of this changeset""" |
|
586 | """True if other is descendant of this changeset""" | |
587 | return self._repo.changelog.descendant(self._rev, other._rev) |
|
587 | return self._repo.changelog.descendant(self._rev, other._rev) | |
588 |
|
588 | |||
589 | def walk(self, match): |
|
589 | def walk(self, match): | |
590 | fset = set(match.files()) |
|
590 | fset = set(match.files()) | |
591 | # avoid the entire walk if we're only looking for specific files |
|
591 | # avoid the entire walk if we're only looking for specific files | |
592 | if fset and not match.anypats(): |
|
592 | if fset and not match.anypats(): | |
593 | if util.all(fn in self for fn in fset): |
|
593 | if util.all(fn in self for fn in fset): | |
594 | for fn in sorted(fset): |
|
594 | for fn in sorted(fset): | |
595 | if match(fn): |
|
595 | if match(fn): | |
596 | yield fn |
|
596 | yield fn | |
597 | raise StopIteration |
|
597 | raise StopIteration | |
598 |
|
598 | |||
599 | for fn in self: |
|
599 | for fn in self: | |
600 | if fn in fset: |
|
600 | if fn in fset: | |
601 | # specified pattern is the exact name |
|
601 | # specified pattern is the exact name | |
602 | fset.remove(fn) |
|
602 | fset.remove(fn) | |
603 | if match(fn): |
|
603 | if match(fn): | |
604 | yield fn |
|
604 | yield fn | |
605 | # for dirstate.walk, files=['.'] means "walk the whole tree". |
|
605 | # for dirstate.walk, files=['.'] means "walk the whole tree". | |
606 | # follow that here, too |
|
606 | # follow that here, too | |
607 | fset.discard('.') |
|
607 | fset.discard('.') | |
608 | for fn in sorted(fset): |
|
608 | for fn in sorted(fset): | |
609 | if not self.hasdir(fn): |
|
609 | if not self.hasdir(fn): | |
610 | match.bad(fn, _('no such file in rev %s') % self) |
|
610 | match.bad(fn, _('no such file in rev %s') % self) | |
611 |
|
611 | |||
612 | def matches(self, match): |
|
612 | def matches(self, match): | |
613 | return self.walk(match) |
|
613 | return self.walk(match) | |
614 |
|
614 | |||
615 | class basefilectx(object): |
|
615 | class basefilectx(object): | |
616 | """A filecontext object represents the common logic for its children: |
|
616 | """A filecontext object represents the common logic for its children: | |
617 | filectx: read-only access to a filerevision that is already present |
|
617 | filectx: read-only access to a filerevision that is already present | |
618 | in the repo, |
|
618 | in the repo, | |
619 | workingfilectx: a filecontext that represents files from the working |
|
619 | workingfilectx: a filecontext that represents files from the working | |
620 | directory, |
|
620 | directory, | |
621 | memfilectx: a filecontext that represents files in-memory.""" |
|
621 | memfilectx: a filecontext that represents files in-memory.""" | |
622 | def __new__(cls, repo, path, *args, **kwargs): |
|
622 | def __new__(cls, repo, path, *args, **kwargs): | |
623 | return super(basefilectx, cls).__new__(cls) |
|
623 | return super(basefilectx, cls).__new__(cls) | |
624 |
|
624 | |||
625 | @propertycache |
|
625 | @propertycache | |
626 | def _filelog(self): |
|
626 | def _filelog(self): | |
627 | return self._repo.file(self._path) |
|
627 | return self._repo.file(self._path) | |
628 |
|
628 | |||
629 | @propertycache |
|
629 | @propertycache | |
630 | def _changeid(self): |
|
630 | def _changeid(self): | |
631 | if '_changeid' in self.__dict__: |
|
631 | if '_changeid' in self.__dict__: | |
632 | return self._changeid |
|
632 | return self._changeid | |
633 | elif '_changectx' in self.__dict__: |
|
633 | elif '_changectx' in self.__dict__: | |
634 | return self._changectx.rev() |
|
634 | return self._changectx.rev() | |
635 | elif '_descendantrev' in self.__dict__: |
|
635 | elif '_descendantrev' in self.__dict__: | |
636 | # this file context was created from a revision with a known |
|
636 | # this file context was created from a revision with a known | |
637 | # descendant, we can (lazily) correct for linkrev aliases |
|
637 | # descendant, we can (lazily) correct for linkrev aliases | |
638 | return self._adjustlinkrev(self._path, self._filelog, |
|
638 | return self._adjustlinkrev(self._path, self._filelog, | |
639 | self._filenode, self._descendantrev) |
|
639 | self._filenode, self._descendantrev) | |
640 | else: |
|
640 | else: | |
641 | return self._filelog.linkrev(self._filerev) |
|
641 | return self._filelog.linkrev(self._filerev) | |
642 |
|
642 | |||
643 | @propertycache |
|
643 | @propertycache | |
644 | def _filenode(self): |
|
644 | def _filenode(self): | |
645 | if '_fileid' in self.__dict__: |
|
645 | if '_fileid' in self.__dict__: | |
646 | return self._filelog.lookup(self._fileid) |
|
646 | return self._filelog.lookup(self._fileid) | |
647 | else: |
|
647 | else: | |
648 | return self._changectx.filenode(self._path) |
|
648 | return self._changectx.filenode(self._path) | |
649 |
|
649 | |||
650 | @propertycache |
|
650 | @propertycache | |
651 | def _filerev(self): |
|
651 | def _filerev(self): | |
652 | return self._filelog.rev(self._filenode) |
|
652 | return self._filelog.rev(self._filenode) | |
653 |
|
653 | |||
654 | @propertycache |
|
654 | @propertycache | |
655 | def _repopath(self): |
|
655 | def _repopath(self): | |
656 | return self._path |
|
656 | return self._path | |
657 |
|
657 | |||
658 | def __nonzero__(self): |
|
658 | def __nonzero__(self): | |
659 | try: |
|
659 | try: | |
660 | self._filenode |
|
660 | self._filenode | |
661 | return True |
|
661 | return True | |
662 | except error.LookupError: |
|
662 | except error.LookupError: | |
663 | # file is missing |
|
663 | # file is missing | |
664 | return False |
|
664 | return False | |
665 |
|
665 | |||
666 | def __str__(self): |
|
666 | def __str__(self): | |
667 | return "%s@%s" % (self.path(), self._changectx) |
|
667 | return "%s@%s" % (self.path(), self._changectx) | |
668 |
|
668 | |||
669 | def __repr__(self): |
|
669 | def __repr__(self): | |
670 | return "<%s %s>" % (type(self).__name__, str(self)) |
|
670 | return "<%s %s>" % (type(self).__name__, str(self)) | |
671 |
|
671 | |||
672 | def __hash__(self): |
|
672 | def __hash__(self): | |
673 | try: |
|
673 | try: | |
674 | return hash((self._path, self._filenode)) |
|
674 | return hash((self._path, self._filenode)) | |
675 | except AttributeError: |
|
675 | except AttributeError: | |
676 | return id(self) |
|
676 | return id(self) | |
677 |
|
677 | |||
678 | def __eq__(self, other): |
|
678 | def __eq__(self, other): | |
679 | try: |
|
679 | try: | |
680 | return (type(self) == type(other) and self._path == other._path |
|
680 | return (type(self) == type(other) and self._path == other._path | |
681 | and self._filenode == other._filenode) |
|
681 | and self._filenode == other._filenode) | |
682 | except AttributeError: |
|
682 | except AttributeError: | |
683 | return False |
|
683 | return False | |
684 |
|
684 | |||
685 | def __ne__(self, other): |
|
685 | def __ne__(self, other): | |
686 | return not (self == other) |
|
686 | return not (self == other) | |
687 |
|
687 | |||
688 | def filerev(self): |
|
688 | def filerev(self): | |
689 | return self._filerev |
|
689 | return self._filerev | |
690 | def filenode(self): |
|
690 | def filenode(self): | |
691 | return self._filenode |
|
691 | return self._filenode | |
692 | def flags(self): |
|
692 | def flags(self): | |
693 | return self._changectx.flags(self._path) |
|
693 | return self._changectx.flags(self._path) | |
694 | def filelog(self): |
|
694 | def filelog(self): | |
695 | return self._filelog |
|
695 | return self._filelog | |
696 | def rev(self): |
|
696 | def rev(self): | |
697 | return self._changeid |
|
697 | return self._changeid | |
698 | def linkrev(self): |
|
698 | def linkrev(self): | |
699 | return self._filelog.linkrev(self._filerev) |
|
699 | return self._filelog.linkrev(self._filerev) | |
700 | def node(self): |
|
700 | def node(self): | |
701 | return self._changectx.node() |
|
701 | return self._changectx.node() | |
702 | def hex(self): |
|
702 | def hex(self): | |
703 | return self._changectx.hex() |
|
703 | return self._changectx.hex() | |
704 | def user(self): |
|
704 | def user(self): | |
705 | return self._changectx.user() |
|
705 | return self._changectx.user() | |
706 | def date(self): |
|
706 | def date(self): | |
707 | return self._changectx.date() |
|
707 | return self._changectx.date() | |
708 | def files(self): |
|
708 | def files(self): | |
709 | return self._changectx.files() |
|
709 | return self._changectx.files() | |
710 | def description(self): |
|
710 | def description(self): | |
711 | return self._changectx.description() |
|
711 | return self._changectx.description() | |
712 | def branch(self): |
|
712 | def branch(self): | |
713 | return self._changectx.branch() |
|
713 | return self._changectx.branch() | |
714 | def extra(self): |
|
714 | def extra(self): | |
715 | return self._changectx.extra() |
|
715 | return self._changectx.extra() | |
716 | def phase(self): |
|
716 | def phase(self): | |
717 | return self._changectx.phase() |
|
717 | return self._changectx.phase() | |
718 | def phasestr(self): |
|
718 | def phasestr(self): | |
719 | return self._changectx.phasestr() |
|
719 | return self._changectx.phasestr() | |
720 | def manifest(self): |
|
720 | def manifest(self): | |
721 | return self._changectx.manifest() |
|
721 | return self._changectx.manifest() | |
722 | def changectx(self): |
|
722 | def changectx(self): | |
723 | return self._changectx |
|
723 | return self._changectx | |
724 | def repo(self): |
|
724 | def repo(self): | |
725 | return self._repo |
|
725 | return self._repo | |
726 |
|
726 | |||
727 | def path(self): |
|
727 | def path(self): | |
728 | return self._path |
|
728 | return self._path | |
729 |
|
729 | |||
730 | def isbinary(self): |
|
730 | def isbinary(self): | |
731 | try: |
|
731 | try: | |
732 | return util.binary(self.data()) |
|
732 | return util.binary(self.data()) | |
733 | except IOError: |
|
733 | except IOError: | |
734 | return False |
|
734 | return False | |
735 | def isexec(self): |
|
735 | def isexec(self): | |
736 | return 'x' in self.flags() |
|
736 | return 'x' in self.flags() | |
737 | def islink(self): |
|
737 | def islink(self): | |
738 | return 'l' in self.flags() |
|
738 | return 'l' in self.flags() | |
739 |
|
739 | |||
740 | def cmp(self, fctx): |
|
740 | def cmp(self, fctx): | |
741 | """compare with other file context |
|
741 | """compare with other file context | |
742 |
|
742 | |||
743 | returns True if different than fctx. |
|
743 | returns True if different than fctx. | |
744 | """ |
|
744 | """ | |
745 | if (fctx._filerev is None |
|
745 | if (fctx._filerev is None | |
746 | and (self._repo._encodefilterpats |
|
746 | and (self._repo._encodefilterpats | |
747 | # if file data starts with '\1\n', empty metadata block is |
|
747 | # if file data starts with '\1\n', empty metadata block is | |
748 | # prepended, which adds 4 bytes to filelog.size(). |
|
748 | # prepended, which adds 4 bytes to filelog.size(). | |
749 | or self.size() - 4 == fctx.size()) |
|
749 | or self.size() - 4 == fctx.size()) | |
750 | or self.size() == fctx.size()): |
|
750 | or self.size() == fctx.size()): | |
751 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
751 | return self._filelog.cmp(self._filenode, fctx.data()) | |
752 |
|
752 | |||
753 | return True |
|
753 | return True | |
754 |
|
754 | |||
755 | def _adjustlinkrev(self, path, filelog, fnode, srcrev, inclusive=False): |
|
755 | def _adjustlinkrev(self, path, filelog, fnode, srcrev, inclusive=False): | |
756 | """return the first ancestor of <srcrev> introducing <fnode> |
|
756 | """return the first ancestor of <srcrev> introducing <fnode> | |
757 |
|
757 | |||
758 | If the linkrev of the file revision does not point to an ancestor of |
|
758 | If the linkrev of the file revision does not point to an ancestor of | |
759 | srcrev, we'll walk down the ancestors until we find one introducing |
|
759 | srcrev, we'll walk down the ancestors until we find one introducing | |
760 | this file revision. |
|
760 | this file revision. | |
761 |
|
761 | |||
762 | :repo: a localrepository object (used to access changelog and manifest) |
|
762 | :repo: a localrepository object (used to access changelog and manifest) | |
763 | :path: the file path |
|
763 | :path: the file path | |
764 | :fnode: the nodeid of the file revision |
|
764 | :fnode: the nodeid of the file revision | |
765 | :filelog: the filelog of this path |
|
765 | :filelog: the filelog of this path | |
766 | :srcrev: the changeset revision we search ancestors from |
|
766 | :srcrev: the changeset revision we search ancestors from | |
767 | :inclusive: if true, the src revision will also be checked |
|
767 | :inclusive: if true, the src revision will also be checked | |
768 | """ |
|
768 | """ | |
769 | repo = self._repo |
|
769 | repo = self._repo | |
770 | cl = repo.unfiltered().changelog |
|
770 | cl = repo.unfiltered().changelog | |
771 | ma = repo.manifest |
|
771 | ma = repo.manifest | |
772 | # fetch the linkrev |
|
772 | # fetch the linkrev | |
773 | fr = filelog.rev(fnode) |
|
773 | fr = filelog.rev(fnode) | |
774 | lkr = filelog.linkrev(fr) |
|
774 | lkr = filelog.linkrev(fr) | |
775 | # hack to reuse ancestor computation when searching for renames |
|
775 | # hack to reuse ancestor computation when searching for renames | |
776 | memberanc = getattr(self, '_ancestrycontext', None) |
|
776 | memberanc = getattr(self, '_ancestrycontext', None) | |
777 | iteranc = None |
|
777 | iteranc = None | |
778 | if srcrev is None: |
|
778 | if srcrev is None: | |
779 | # wctx case, used by workingfilectx during mergecopy |
|
779 | # wctx case, used by workingfilectx during mergecopy | |
780 | revs = [p.rev() for p in self._repo[None].parents()] |
|
780 | revs = [p.rev() for p in self._repo[None].parents()] | |
781 | inclusive = True # we skipped the real (revless) source |
|
781 | inclusive = True # we skipped the real (revless) source | |
782 | else: |
|
782 | else: | |
783 | revs = [srcrev] |
|
783 | revs = [srcrev] | |
784 | if memberanc is None: |
|
784 | if memberanc is None: | |
785 | memberanc = iteranc = cl.ancestors(revs, lkr, |
|
785 | memberanc = iteranc = cl.ancestors(revs, lkr, | |
786 | inclusive=inclusive) |
|
786 | inclusive=inclusive) | |
787 | # check if this linkrev is an ancestor of srcrev |
|
787 | # check if this linkrev is an ancestor of srcrev | |
788 | if lkr not in memberanc: |
|
788 | if lkr not in memberanc: | |
789 | if iteranc is None: |
|
789 | if iteranc is None: | |
790 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) |
|
790 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) | |
791 | for a in iteranc: |
|
791 | for a in iteranc: | |
792 | ac = cl.read(a) # get changeset data (we avoid object creation) |
|
792 | ac = cl.read(a) # get changeset data (we avoid object creation) | |
793 | if path in ac[3]: # checking the 'files' field. |
|
793 | if path in ac[3]: # checking the 'files' field. | |
794 | # The file has been touched, check if the content is |
|
794 | # The file has been touched, check if the content is | |
795 | # similar to the one we search for. |
|
795 | # similar to the one we search for. | |
796 | if fnode == ma.readfast(ac[0]).get(path): |
|
796 | if fnode == ma.readfast(ac[0]).get(path): | |
797 | return a |
|
797 | return a | |
798 | # In theory, we should never get out of that loop without a result. |
|
798 | # In theory, we should never get out of that loop without a result. | |
799 | # But if manifest uses a buggy file revision (not children of the |
|
799 | # But if manifest uses a buggy file revision (not children of the | |
800 | # one it replaces) we could. Such a buggy situation will likely |
|
800 | # one it replaces) we could. Such a buggy situation will likely | |
801 | # result is crash somewhere else at to some point. |
|
801 | # result is crash somewhere else at to some point. | |
802 | return lkr |
|
802 | return lkr | |
803 |
|
803 | |||
804 | def introrev(self): |
|
804 | def introrev(self): | |
805 | """return the rev of the changeset which introduced this file revision |
|
805 | """return the rev of the changeset which introduced this file revision | |
806 |
|
806 | |||
807 | This method is different from linkrev because it take into account the |
|
807 | This method is different from linkrev because it take into account the | |
808 | changeset the filectx was created from. It ensures the returned |
|
808 | changeset the filectx was created from. It ensures the returned | |
809 | revision is one of its ancestors. This prevents bugs from |
|
809 | revision is one of its ancestors. This prevents bugs from | |
810 | 'linkrev-shadowing' when a file revision is used by multiple |
|
810 | 'linkrev-shadowing' when a file revision is used by multiple | |
811 | changesets. |
|
811 | changesets. | |
812 | """ |
|
812 | """ | |
813 | lkr = self.linkrev() |
|
813 | lkr = self.linkrev() | |
814 | attrs = vars(self) |
|
814 | attrs = vars(self) | |
815 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) |
|
815 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) | |
816 | if noctx or self.rev() == lkr: |
|
816 | if noctx or self.rev() == lkr: | |
817 | return self.linkrev() |
|
817 | return self.linkrev() | |
818 | return self._adjustlinkrev(self._path, self._filelog, self._filenode, |
|
818 | return self._adjustlinkrev(self._path, self._filelog, self._filenode, | |
819 | self.rev(), inclusive=True) |
|
819 | self.rev(), inclusive=True) | |
820 |
|
820 | |||
821 | def parents(self): |
|
821 | def parents(self): | |
822 | _path = self._path |
|
822 | _path = self._path | |
823 | fl = self._filelog |
|
823 | fl = self._filelog | |
824 | parents = self._filelog.parents(self._filenode) |
|
824 | parents = self._filelog.parents(self._filenode) | |
825 | pl = [(_path, node, fl) for node in parents if node != nullid] |
|
825 | pl = [(_path, node, fl) for node in parents if node != nullid] | |
826 |
|
826 | |||
827 | r = fl.renamed(self._filenode) |
|
827 | r = fl.renamed(self._filenode) | |
828 | if r: |
|
828 | if r: | |
829 | # - In the simple rename case, both parent are nullid, pl is empty. |
|
829 | # - In the simple rename case, both parent are nullid, pl is empty. | |
830 | # - In case of merge, only one of the parent is null id and should |
|
830 | # - In case of merge, only one of the parent is null id and should | |
831 | # be replaced with the rename information. This parent is -always- |
|
831 | # be replaced with the rename information. This parent is -always- | |
832 | # the first one. |
|
832 | # the first one. | |
833 | # |
|
833 | # | |
834 | # As null id have always been filtered out in the previous list |
|
834 | # As null id have always been filtered out in the previous list | |
835 | # comprehension, inserting to 0 will always result in "replacing |
|
835 | # comprehension, inserting to 0 will always result in "replacing | |
836 | # first nullid parent with rename information. |
|
836 | # first nullid parent with rename information. | |
837 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) |
|
837 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) | |
838 |
|
838 | |||
839 | ret = [] |
|
839 | ret = [] | |
840 | for path, fnode, l in pl: |
|
840 | for path, fnode, l in pl: | |
841 | if '_changeid' in vars(self) or '_changectx' in vars(self): |
|
841 | if '_changeid' in vars(self) or '_changectx' in vars(self): | |
842 | # If self is associated with a changeset (probably explicitly |
|
842 | # If self is associated with a changeset (probably explicitly | |
843 | # fed), ensure the created filectx is associated with a |
|
843 | # fed), ensure the created filectx is associated with a | |
844 | # changeset that is an ancestor of self.changectx. |
|
844 | # changeset that is an ancestor of self.changectx. | |
845 | # This lets us later use _adjustlinkrev to get a correct link. |
|
845 | # This lets us later use _adjustlinkrev to get a correct link. | |
846 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
846 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
847 | fctx._descendantrev = self.rev() |
|
847 | fctx._descendantrev = self.rev() | |
848 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
848 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
849 | elif '_descendantrev' in vars(self): |
|
849 | elif '_descendantrev' in vars(self): | |
850 | # Otherwise propagate _descendantrev if we have one associated. |
|
850 | # Otherwise propagate _descendantrev if we have one associated. | |
851 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
851 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
852 | fctx._descendantrev = self._descendantrev |
|
852 | fctx._descendantrev = self._descendantrev | |
853 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
853 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
854 | else: |
|
854 | else: | |
855 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
855 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
856 | ret.append(fctx) |
|
856 | ret.append(fctx) | |
857 | return ret |
|
857 | return ret | |
858 |
|
858 | |||
859 | def p1(self): |
|
859 | def p1(self): | |
860 | return self.parents()[0] |
|
860 | return self.parents()[0] | |
861 |
|
861 | |||
862 | def p2(self): |
|
862 | def p2(self): | |
863 | p = self.parents() |
|
863 | p = self.parents() | |
864 | if len(p) == 2: |
|
864 | if len(p) == 2: | |
865 | return p[1] |
|
865 | return p[1] | |
866 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
866 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) | |
867 |
|
867 | |||
868 | def annotate(self, follow=False, linenumber=None, diffopts=None): |
|
868 | def annotate(self, follow=False, linenumber=None, diffopts=None): | |
869 | '''returns a list of tuples of (ctx, line) for each line |
|
869 | '''returns a list of tuples of (ctx, line) for each line | |
870 | in the file, where ctx is the filectx of the node where |
|
870 | in the file, where ctx is the filectx of the node where | |
871 | that line was last changed. |
|
871 | that line was last changed. | |
872 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
872 | This returns tuples of ((ctx, linenumber), line) for each line, | |
873 | if "linenumber" parameter is NOT "None". |
|
873 | if "linenumber" parameter is NOT "None". | |
874 | In such tuples, linenumber means one at the first appearance |
|
874 | In such tuples, linenumber means one at the first appearance | |
875 | in the managed file. |
|
875 | in the managed file. | |
876 | To reduce annotation cost, |
|
876 | To reduce annotation cost, | |
877 | this returns fixed value(False is used) as linenumber, |
|
877 | this returns fixed value(False is used) as linenumber, | |
878 | if "linenumber" parameter is "False".''' |
|
878 | if "linenumber" parameter is "False".''' | |
879 |
|
879 | |||
880 | if linenumber is None: |
|
880 | if linenumber is None: | |
881 | def decorate(text, rev): |
|
881 | def decorate(text, rev): | |
882 | return ([rev] * len(text.splitlines()), text) |
|
882 | return ([rev] * len(text.splitlines()), text) | |
883 | elif linenumber: |
|
883 | elif linenumber: | |
884 | def decorate(text, rev): |
|
884 | def decorate(text, rev): | |
885 | size = len(text.splitlines()) |
|
885 | size = len(text.splitlines()) | |
886 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
886 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
887 | else: |
|
887 | else: | |
888 | def decorate(text, rev): |
|
888 | def decorate(text, rev): | |
889 | return ([(rev, False)] * len(text.splitlines()), text) |
|
889 | return ([(rev, False)] * len(text.splitlines()), text) | |
890 |
|
890 | |||
891 | def pair(parent, child): |
|
891 | def pair(parent, child): | |
892 | blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts, |
|
892 | blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts, | |
893 | refine=True) |
|
893 | refine=True) | |
894 | for (a1, a2, b1, b2), t in blocks: |
|
894 | for (a1, a2, b1, b2), t in blocks: | |
895 | # Changed blocks ('!') or blocks made only of blank lines ('~') |
|
895 | # Changed blocks ('!') or blocks made only of blank lines ('~') | |
896 | # belong to the child. |
|
896 | # belong to the child. | |
897 | if t == '=': |
|
897 | if t == '=': | |
898 | child[0][b1:b2] = parent[0][a1:a2] |
|
898 | child[0][b1:b2] = parent[0][a1:a2] | |
899 | return child |
|
899 | return child | |
900 |
|
900 | |||
901 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
901 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
902 |
|
902 | |||
903 | def parents(f): |
|
903 | def parents(f): | |
904 | pl = f.parents() |
|
904 | pl = f.parents() | |
905 |
|
905 | |||
906 | # Don't return renamed parents if we aren't following. |
|
906 | # Don't return renamed parents if we aren't following. | |
907 | if not follow: |
|
907 | if not follow: | |
908 | pl = [p for p in pl if p.path() == f.path()] |
|
908 | pl = [p for p in pl if p.path() == f.path()] | |
909 |
|
909 | |||
910 | # renamed filectx won't have a filelog yet, so set it |
|
910 | # renamed filectx won't have a filelog yet, so set it | |
911 | # from the cache to save time |
|
911 | # from the cache to save time | |
912 | for p in pl: |
|
912 | for p in pl: | |
913 | if not '_filelog' in p.__dict__: |
|
913 | if not '_filelog' in p.__dict__: | |
914 | p._filelog = getlog(p.path()) |
|
914 | p._filelog = getlog(p.path()) | |
915 |
|
915 | |||
916 | return pl |
|
916 | return pl | |
917 |
|
917 | |||
918 | # use linkrev to find the first changeset where self appeared |
|
918 | # use linkrev to find the first changeset where self appeared | |
919 | base = self |
|
919 | base = self | |
920 | introrev = self.introrev() |
|
920 | introrev = self.introrev() | |
921 | if self.rev() != introrev: |
|
921 | if self.rev() != introrev: | |
922 | base = self.filectx(self.filenode(), changeid=introrev) |
|
922 | base = self.filectx(self.filenode(), changeid=introrev) | |
923 | ac = self._repo.changelog.ancestors([introrev], inclusive=True) |
|
923 | ac = self._repo.changelog.ancestors([introrev], inclusive=True) | |
924 | base._ancestrycontext = ac |
|
924 | base._ancestrycontext = ac | |
925 |
|
925 | |||
926 | # This algorithm would prefer to be recursive, but Python is a |
|
926 | # This algorithm would prefer to be recursive, but Python is a | |
927 | # bit recursion-hostile. Instead we do an iterative |
|
927 | # bit recursion-hostile. Instead we do an iterative | |
928 | # depth-first search. |
|
928 | # depth-first search. | |
929 |
|
929 | |||
930 | visit = [base] |
|
930 | visit = [base] | |
931 | hist = {} |
|
931 | hist = {} | |
932 | pcache = {} |
|
932 | pcache = {} | |
933 | needed = {base: 1} |
|
933 | needed = {base: 1} | |
934 | while visit: |
|
934 | while visit: | |
935 | f = visit[-1] |
|
935 | f = visit[-1] | |
936 | pcached = f in pcache |
|
936 | pcached = f in pcache | |
937 | if not pcached: |
|
937 | if not pcached: | |
938 | pcache[f] = parents(f) |
|
938 | pcache[f] = parents(f) | |
939 |
|
939 | |||
940 | ready = True |
|
940 | ready = True | |
941 | pl = pcache[f] |
|
941 | pl = pcache[f] | |
942 | for p in pl: |
|
942 | for p in pl: | |
943 | if p not in hist: |
|
943 | if p not in hist: | |
944 | ready = False |
|
944 | ready = False | |
945 | visit.append(p) |
|
945 | visit.append(p) | |
946 | if not pcached: |
|
946 | if not pcached: | |
947 | needed[p] = needed.get(p, 0) + 1 |
|
947 | needed[p] = needed.get(p, 0) + 1 | |
948 | if ready: |
|
948 | if ready: | |
949 | visit.pop() |
|
949 | visit.pop() | |
950 | reusable = f in hist |
|
950 | reusable = f in hist | |
951 | if reusable: |
|
951 | if reusable: | |
952 | curr = hist[f] |
|
952 | curr = hist[f] | |
953 | else: |
|
953 | else: | |
954 | curr = decorate(f.data(), f) |
|
954 | curr = decorate(f.data(), f) | |
955 | for p in pl: |
|
955 | for p in pl: | |
956 | if not reusable: |
|
956 | if not reusable: | |
957 | curr = pair(hist[p], curr) |
|
957 | curr = pair(hist[p], curr) | |
958 | if needed[p] == 1: |
|
958 | if needed[p] == 1: | |
959 | del hist[p] |
|
959 | del hist[p] | |
960 | del needed[p] |
|
960 | del needed[p] | |
961 | else: |
|
961 | else: | |
962 | needed[p] -= 1 |
|
962 | needed[p] -= 1 | |
963 |
|
963 | |||
964 | hist[f] = curr |
|
964 | hist[f] = curr | |
965 | pcache[f] = [] |
|
965 | pcache[f] = [] | |
966 |
|
966 | |||
967 | return zip(hist[base][0], hist[base][1].splitlines(True)) |
|
967 | return zip(hist[base][0], hist[base][1].splitlines(True)) | |
968 |
|
968 | |||
969 | def ancestors(self, followfirst=False): |
|
969 | def ancestors(self, followfirst=False): | |
970 | visit = {} |
|
970 | visit = {} | |
971 | c = self |
|
971 | c = self | |
972 | if followfirst: |
|
972 | if followfirst: | |
973 | cut = 1 |
|
973 | cut = 1 | |
974 | else: |
|
974 | else: | |
975 | cut = None |
|
975 | cut = None | |
976 |
|
976 | |||
977 | while True: |
|
977 | while True: | |
978 | for parent in c.parents()[:cut]: |
|
978 | for parent in c.parents()[:cut]: | |
979 | visit[(parent.linkrev(), parent.filenode())] = parent |
|
979 | visit[(parent.linkrev(), parent.filenode())] = parent | |
980 | if not visit: |
|
980 | if not visit: | |
981 | break |
|
981 | break | |
982 | c = visit.pop(max(visit)) |
|
982 | c = visit.pop(max(visit)) | |
983 | yield c |
|
983 | yield c | |
984 |
|
984 | |||
985 | class filectx(basefilectx): |
|
985 | class filectx(basefilectx): | |
986 | """A filecontext object makes access to data related to a particular |
|
986 | """A filecontext object makes access to data related to a particular | |
987 | filerevision convenient.""" |
|
987 | filerevision convenient.""" | |
988 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
988 | def __init__(self, repo, path, changeid=None, fileid=None, | |
989 | filelog=None, changectx=None): |
|
989 | filelog=None, changectx=None): | |
990 | """changeid can be a changeset revision, node, or tag. |
|
990 | """changeid can be a changeset revision, node, or tag. | |
991 | fileid can be a file revision or node.""" |
|
991 | fileid can be a file revision or node.""" | |
992 | self._repo = repo |
|
992 | self._repo = repo | |
993 | self._path = path |
|
993 | self._path = path | |
994 |
|
994 | |||
995 | assert (changeid is not None |
|
995 | assert (changeid is not None | |
996 | or fileid is not None |
|
996 | or fileid is not None | |
997 | or changectx is not None), \ |
|
997 | or changectx is not None), \ | |
998 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
998 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
999 | % (changeid, fileid, changectx)) |
|
999 | % (changeid, fileid, changectx)) | |
1000 |
|
1000 | |||
1001 | if filelog is not None: |
|
1001 | if filelog is not None: | |
1002 | self._filelog = filelog |
|
1002 | self._filelog = filelog | |
1003 |
|
1003 | |||
1004 | if changeid is not None: |
|
1004 | if changeid is not None: | |
1005 | self._changeid = changeid |
|
1005 | self._changeid = changeid | |
1006 | if changectx is not None: |
|
1006 | if changectx is not None: | |
1007 | self._changectx = changectx |
|
1007 | self._changectx = changectx | |
1008 | if fileid is not None: |
|
1008 | if fileid is not None: | |
1009 | self._fileid = fileid |
|
1009 | self._fileid = fileid | |
1010 |
|
1010 | |||
1011 | @propertycache |
|
1011 | @propertycache | |
1012 | def _changectx(self): |
|
1012 | def _changectx(self): | |
1013 | try: |
|
1013 | try: | |
1014 | return changectx(self._repo, self._changeid) |
|
1014 | return changectx(self._repo, self._changeid) | |
1015 | except error.FilteredRepoLookupError: |
|
1015 | except error.FilteredRepoLookupError: | |
1016 | # Linkrev may point to any revision in the repository. When the |
|
1016 | # Linkrev may point to any revision in the repository. When the | |
1017 | # repository is filtered this may lead to `filectx` trying to build |
|
1017 | # repository is filtered this may lead to `filectx` trying to build | |
1018 | # `changectx` for filtered revision. In such case we fallback to |
|
1018 | # `changectx` for filtered revision. In such case we fallback to | |
1019 | # creating `changectx` on the unfiltered version of the reposition. |
|
1019 | # creating `changectx` on the unfiltered version of the reposition. | |
1020 | # This fallback should not be an issue because `changectx` from |
|
1020 | # This fallback should not be an issue because `changectx` from | |
1021 | # `filectx` are not used in complex operations that care about |
|
1021 | # `filectx` are not used in complex operations that care about | |
1022 | # filtering. |
|
1022 | # filtering. | |
1023 | # |
|
1023 | # | |
1024 | # This fallback is a cheap and dirty fix that prevent several |
|
1024 | # This fallback is a cheap and dirty fix that prevent several | |
1025 | # crashes. It does not ensure the behavior is correct. However the |
|
1025 | # crashes. It does not ensure the behavior is correct. However the | |
1026 | # behavior was not correct before filtering either and "incorrect |
|
1026 | # behavior was not correct before filtering either and "incorrect | |
1027 | # behavior" is seen as better as "crash" |
|
1027 | # behavior" is seen as better as "crash" | |
1028 | # |
|
1028 | # | |
1029 | # Linkrevs have several serious troubles with filtering that are |
|
1029 | # Linkrevs have several serious troubles with filtering that are | |
1030 | # complicated to solve. Proper handling of the issue here should be |
|
1030 | # complicated to solve. Proper handling of the issue here should be | |
1031 | # considered when solving linkrev issue are on the table. |
|
1031 | # considered when solving linkrev issue are on the table. | |
1032 | return changectx(self._repo.unfiltered(), self._changeid) |
|
1032 | return changectx(self._repo.unfiltered(), self._changeid) | |
1033 |
|
1033 | |||
1034 | def filectx(self, fileid, changeid=None): |
|
1034 | def filectx(self, fileid, changeid=None): | |
1035 | '''opens an arbitrary revision of the file without |
|
1035 | '''opens an arbitrary revision of the file without | |
1036 | opening a new filelog''' |
|
1036 | opening a new filelog''' | |
1037 | return filectx(self._repo, self._path, fileid=fileid, |
|
1037 | return filectx(self._repo, self._path, fileid=fileid, | |
1038 | filelog=self._filelog, changeid=changeid) |
|
1038 | filelog=self._filelog, changeid=changeid) | |
1039 |
|
1039 | |||
1040 | def data(self): |
|
1040 | def data(self): | |
1041 | try: |
|
1041 | try: | |
1042 | return self._filelog.read(self._filenode) |
|
1042 | return self._filelog.read(self._filenode) | |
1043 | except error.CensoredNodeError: |
|
1043 | except error.CensoredNodeError: | |
1044 | if self._repo.ui.config("censor", "policy", "abort") == "ignore": |
|
1044 | if self._repo.ui.config("censor", "policy", "abort") == "ignore": | |
1045 | return "" |
|
1045 | return "" | |
1046 | raise util.Abort(_("censored node: %s") % short(self._filenode), |
|
1046 | raise util.Abort(_("censored node: %s") % short(self._filenode), | |
1047 | hint=_("set censor.policy to ignore errors")) |
|
1047 | hint=_("set censor.policy to ignore errors")) | |
1048 |
|
1048 | |||
1049 | def size(self): |
|
1049 | def size(self): | |
1050 | return self._filelog.size(self._filerev) |
|
1050 | return self._filelog.size(self._filerev) | |
1051 |
|
1051 | |||
1052 | def renamed(self): |
|
1052 | def renamed(self): | |
1053 | """check if file was actually renamed in this changeset revision |
|
1053 | """check if file was actually renamed in this changeset revision | |
1054 |
|
1054 | |||
1055 | If rename logged in file revision, we report copy for changeset only |
|
1055 | If rename logged in file revision, we report copy for changeset only | |
1056 | if file revisions linkrev points back to the changeset in question |
|
1056 | if file revisions linkrev points back to the changeset in question | |
1057 | or both changeset parents contain different file revisions. |
|
1057 | or both changeset parents contain different file revisions. | |
1058 | """ |
|
1058 | """ | |
1059 |
|
1059 | |||
1060 | renamed = self._filelog.renamed(self._filenode) |
|
1060 | renamed = self._filelog.renamed(self._filenode) | |
1061 | if not renamed: |
|
1061 | if not renamed: | |
1062 | return renamed |
|
1062 | return renamed | |
1063 |
|
1063 | |||
1064 | if self.rev() == self.linkrev(): |
|
1064 | if self.rev() == self.linkrev(): | |
1065 | return renamed |
|
1065 | return renamed | |
1066 |
|
1066 | |||
1067 | name = self.path() |
|
1067 | name = self.path() | |
1068 | fnode = self._filenode |
|
1068 | fnode = self._filenode | |
1069 | for p in self._changectx.parents(): |
|
1069 | for p in self._changectx.parents(): | |
1070 | try: |
|
1070 | try: | |
1071 | if fnode == p.filenode(name): |
|
1071 | if fnode == p.filenode(name): | |
1072 | return None |
|
1072 | return None | |
1073 | except error.LookupError: |
|
1073 | except error.LookupError: | |
1074 | pass |
|
1074 | pass | |
1075 | return renamed |
|
1075 | return renamed | |
1076 |
|
1076 | |||
1077 | def children(self): |
|
1077 | def children(self): | |
1078 | # hard for renames |
|
1078 | # hard for renames | |
1079 | c = self._filelog.children(self._filenode) |
|
1079 | c = self._filelog.children(self._filenode) | |
1080 | return [filectx(self._repo, self._path, fileid=x, |
|
1080 | return [filectx(self._repo, self._path, fileid=x, | |
1081 | filelog=self._filelog) for x in c] |
|
1081 | filelog=self._filelog) for x in c] | |
1082 |
|
1082 | |||
1083 | class committablectx(basectx): |
|
1083 | class committablectx(basectx): | |
1084 | """A committablectx object provides common functionality for a context that |
|
1084 | """A committablectx object provides common functionality for a context that | |
1085 | wants the ability to commit, e.g. workingctx or memctx.""" |
|
1085 | wants the ability to commit, e.g. workingctx or memctx.""" | |
1086 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1086 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1087 | changes=None): |
|
1087 | changes=None): | |
1088 | self._repo = repo |
|
1088 | self._repo = repo | |
1089 | self._rev = None |
|
1089 | self._rev = None | |
1090 | self._node = None |
|
1090 | self._node = None | |
1091 | self._text = text |
|
1091 | self._text = text | |
1092 | if date: |
|
1092 | if date: | |
1093 | self._date = util.parsedate(date) |
|
1093 | self._date = util.parsedate(date) | |
1094 | if user: |
|
1094 | if user: | |
1095 | self._user = user |
|
1095 | self._user = user | |
1096 | if changes: |
|
1096 | if changes: | |
1097 | self._status = changes |
|
1097 | self._status = changes | |
1098 |
|
1098 | |||
1099 | self._extra = {} |
|
1099 | self._extra = {} | |
1100 | if extra: |
|
1100 | if extra: | |
1101 | self._extra = extra.copy() |
|
1101 | self._extra = extra.copy() | |
1102 | if 'branch' not in self._extra: |
|
1102 | if 'branch' not in self._extra: | |
1103 | try: |
|
1103 | try: | |
1104 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
1104 | branch = encoding.fromlocal(self._repo.dirstate.branch()) | |
1105 | except UnicodeDecodeError: |
|
1105 | except UnicodeDecodeError: | |
1106 | raise util.Abort(_('branch name not in UTF-8!')) |
|
1106 | raise util.Abort(_('branch name not in UTF-8!')) | |
1107 | self._extra['branch'] = branch |
|
1107 | self._extra['branch'] = branch | |
1108 | if self._extra['branch'] == '': |
|
1108 | if self._extra['branch'] == '': | |
1109 | self._extra['branch'] = 'default' |
|
1109 | self._extra['branch'] = 'default' | |
1110 |
|
1110 | |||
1111 | def __str__(self): |
|
1111 | def __str__(self): | |
1112 | return str(self._parents[0]) + "+" |
|
1112 | return str(self._parents[0]) + "+" | |
1113 |
|
1113 | |||
1114 | def __nonzero__(self): |
|
1114 | def __nonzero__(self): | |
1115 | return True |
|
1115 | return True | |
1116 |
|
1116 | |||
1117 | def _buildflagfunc(self): |
|
1117 | def _buildflagfunc(self): | |
1118 | # Create a fallback function for getting file flags when the |
|
1118 | # Create a fallback function for getting file flags when the | |
1119 | # filesystem doesn't support them |
|
1119 | # filesystem doesn't support them | |
1120 |
|
1120 | |||
1121 | copiesget = self._repo.dirstate.copies().get |
|
1121 | copiesget = self._repo.dirstate.copies().get | |
1122 |
|
1122 | |||
1123 | if len(self._parents) < 2: |
|
1123 | if len(self._parents) < 2: | |
1124 | # when we have one parent, it's easy: copy from parent |
|
1124 | # when we have one parent, it's easy: copy from parent | |
1125 | man = self._parents[0].manifest() |
|
1125 | man = self._parents[0].manifest() | |
1126 | def func(f): |
|
1126 | def func(f): | |
1127 | f = copiesget(f, f) |
|
1127 | f = copiesget(f, f) | |
1128 | return man.flags(f) |
|
1128 | return man.flags(f) | |
1129 | else: |
|
1129 | else: | |
1130 | # merges are tricky: we try to reconstruct the unstored |
|
1130 | # merges are tricky: we try to reconstruct the unstored | |
1131 | # result from the merge (issue1802) |
|
1131 | # result from the merge (issue1802) | |
1132 | p1, p2 = self._parents |
|
1132 | p1, p2 = self._parents | |
1133 | pa = p1.ancestor(p2) |
|
1133 | pa = p1.ancestor(p2) | |
1134 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
1134 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1135 |
|
1135 | |||
1136 | def func(f): |
|
1136 | def func(f): | |
1137 | f = copiesget(f, f) # may be wrong for merges with copies |
|
1137 | f = copiesget(f, f) # may be wrong for merges with copies | |
1138 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
1138 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1139 | if fl1 == fl2: |
|
1139 | if fl1 == fl2: | |
1140 | return fl1 |
|
1140 | return fl1 | |
1141 | if fl1 == fla: |
|
1141 | if fl1 == fla: | |
1142 | return fl2 |
|
1142 | return fl2 | |
1143 | if fl2 == fla: |
|
1143 | if fl2 == fla: | |
1144 | return fl1 |
|
1144 | return fl1 | |
1145 | return '' # punt for conflicts |
|
1145 | return '' # punt for conflicts | |
1146 |
|
1146 | |||
1147 | return func |
|
1147 | return func | |
1148 |
|
1148 | |||
1149 | @propertycache |
|
1149 | @propertycache | |
1150 | def _flagfunc(self): |
|
1150 | def _flagfunc(self): | |
1151 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
1151 | return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1152 |
|
1152 | |||
1153 | @propertycache |
|
1153 | @propertycache | |
1154 | def _manifest(self): |
|
1154 | def _manifest(self): | |
1155 | """generate a manifest corresponding to the values in self._status |
|
1155 | """generate a manifest corresponding to the values in self._status | |
1156 |
|
1156 | |||
1157 | This reuse the file nodeid from parent, but we append an extra letter |
|
1157 | This reuse the file nodeid from parent, but we append an extra letter | |
1158 | when modified. Modified files get an extra 'm' while added files get |
|
1158 | when modified. Modified files get an extra 'm' while added files get | |
1159 | an extra 'a'. This is used by manifests merge to see that files |
|
1159 | an extra 'a'. This is used by manifests merge to see that files | |
1160 | are different and by update logic to avoid deleting newly added files. |
|
1160 | are different and by update logic to avoid deleting newly added files. | |
1161 | """ |
|
1161 | """ | |
1162 |
|
1162 | |||
1163 | man1 = self._parents[0].manifest() |
|
1163 | man1 = self._parents[0].manifest() | |
1164 | man = man1.copy() |
|
1164 | man = man1.copy() | |
1165 | if len(self._parents) > 1: |
|
1165 | if len(self._parents) > 1: | |
1166 | man2 = self.p2().manifest() |
|
1166 | man2 = self.p2().manifest() | |
1167 | def getman(f): |
|
1167 | def getman(f): | |
1168 | if f in man1: |
|
1168 | if f in man1: | |
1169 | return man1 |
|
1169 | return man1 | |
1170 | return man2 |
|
1170 | return man2 | |
1171 | else: |
|
1171 | else: | |
1172 | getman = lambda f: man1 |
|
1172 | getman = lambda f: man1 | |
1173 |
|
1173 | |||
1174 | copied = self._repo.dirstate.copies() |
|
1174 | copied = self._repo.dirstate.copies() | |
1175 | ff = self._flagfunc |
|
1175 | ff = self._flagfunc | |
1176 | for i, l in (("a", self._status.added), ("m", self._status.modified)): |
|
1176 | for i, l in (("a", self._status.added), ("m", self._status.modified)): | |
1177 | for f in l: |
|
1177 | for f in l: | |
1178 | orig = copied.get(f, f) |
|
1178 | orig = copied.get(f, f) | |
1179 | man[f] = getman(orig).get(orig, nullid) + i |
|
1179 | man[f] = getman(orig).get(orig, nullid) + i | |
1180 | try: |
|
1180 | try: | |
1181 | man.setflag(f, ff(f)) |
|
1181 | man.setflag(f, ff(f)) | |
1182 | except OSError: |
|
1182 | except OSError: | |
1183 | pass |
|
1183 | pass | |
1184 |
|
1184 | |||
1185 | for f in self._status.deleted + self._status.removed: |
|
1185 | for f in self._status.deleted + self._status.removed: | |
1186 | if f in man: |
|
1186 | if f in man: | |
1187 | del man[f] |
|
1187 | del man[f] | |
1188 |
|
1188 | |||
1189 | return man |
|
1189 | return man | |
1190 |
|
1190 | |||
1191 | @propertycache |
|
1191 | @propertycache | |
1192 | def _status(self): |
|
1192 | def _status(self): | |
1193 | return self._repo.status() |
|
1193 | return self._repo.status() | |
1194 |
|
1194 | |||
1195 | @propertycache |
|
1195 | @propertycache | |
1196 | def _user(self): |
|
1196 | def _user(self): | |
1197 | return self._repo.ui.username() |
|
1197 | return self._repo.ui.username() | |
1198 |
|
1198 | |||
1199 | @propertycache |
|
1199 | @propertycache | |
1200 | def _date(self): |
|
1200 | def _date(self): | |
1201 | return util.makedate() |
|
1201 | return util.makedate() | |
1202 |
|
1202 | |||
1203 | def subrev(self, subpath): |
|
1203 | def subrev(self, subpath): | |
1204 | return None |
|
1204 | return None | |
1205 |
|
1205 | |||
1206 | def user(self): |
|
1206 | def user(self): | |
1207 | return self._user or self._repo.ui.username() |
|
1207 | return self._user or self._repo.ui.username() | |
1208 | def date(self): |
|
1208 | def date(self): | |
1209 | return self._date |
|
1209 | return self._date | |
1210 | def description(self): |
|
1210 | def description(self): | |
1211 | return self._text |
|
1211 | return self._text | |
1212 | def files(self): |
|
1212 | def files(self): | |
1213 | return sorted(self._status.modified + self._status.added + |
|
1213 | return sorted(self._status.modified + self._status.added + | |
1214 | self._status.removed) |
|
1214 | self._status.removed) | |
1215 |
|
1215 | |||
1216 | def modified(self): |
|
1216 | def modified(self): | |
1217 | return self._status.modified |
|
1217 | return self._status.modified | |
1218 | def added(self): |
|
1218 | def added(self): | |
1219 | return self._status.added |
|
1219 | return self._status.added | |
1220 | def removed(self): |
|
1220 | def removed(self): | |
1221 | return self._status.removed |
|
1221 | return self._status.removed | |
1222 | def deleted(self): |
|
1222 | def deleted(self): | |
1223 | return self._status.deleted |
|
1223 | return self._status.deleted | |
1224 | def branch(self): |
|
1224 | def branch(self): | |
1225 | return encoding.tolocal(self._extra['branch']) |
|
1225 | return encoding.tolocal(self._extra['branch']) | |
1226 | def closesbranch(self): |
|
1226 | def closesbranch(self): | |
1227 | return 'close' in self._extra |
|
1227 | return 'close' in self._extra | |
1228 | def extra(self): |
|
1228 | def extra(self): | |
1229 | return self._extra |
|
1229 | return self._extra | |
1230 |
|
1230 | |||
1231 | def tags(self): |
|
1231 | def tags(self): | |
1232 | t = [] |
|
1232 | t = [] | |
1233 | for p in self.parents(): |
|
1233 | for p in self.parents(): | |
1234 | t.extend(p.tags()) |
|
1234 | t.extend(p.tags()) | |
1235 | return t |
|
1235 | return t | |
1236 |
|
1236 | |||
1237 | def bookmarks(self): |
|
1237 | def bookmarks(self): | |
1238 | b = [] |
|
1238 | b = [] | |
1239 | for p in self.parents(): |
|
1239 | for p in self.parents(): | |
1240 | b.extend(p.bookmarks()) |
|
1240 | b.extend(p.bookmarks()) | |
1241 | return b |
|
1241 | return b | |
1242 |
|
1242 | |||
1243 | def phase(self): |
|
1243 | def phase(self): | |
1244 | phase = phases.draft # default phase to draft |
|
1244 | phase = phases.draft # default phase to draft | |
1245 | for p in self.parents(): |
|
1245 | for p in self.parents(): | |
1246 | phase = max(phase, p.phase()) |
|
1246 | phase = max(phase, p.phase()) | |
1247 | return phase |
|
1247 | return phase | |
1248 |
|
1248 | |||
1249 | def hidden(self): |
|
1249 | def hidden(self): | |
1250 | return False |
|
1250 | return False | |
1251 |
|
1251 | |||
1252 | def children(self): |
|
1252 | def children(self): | |
1253 | return [] |
|
1253 | return [] | |
1254 |
|
1254 | |||
1255 | def flags(self, path): |
|
1255 | def flags(self, path): | |
1256 | if '_manifest' in self.__dict__: |
|
1256 | if '_manifest' in self.__dict__: | |
1257 | try: |
|
1257 | try: | |
1258 | return self._manifest.flags(path) |
|
1258 | return self._manifest.flags(path) | |
1259 | except KeyError: |
|
1259 | except KeyError: | |
1260 | return '' |
|
1260 | return '' | |
1261 |
|
1261 | |||
1262 | try: |
|
1262 | try: | |
1263 | return self._flagfunc(path) |
|
1263 | return self._flagfunc(path) | |
1264 | except OSError: |
|
1264 | except OSError: | |
1265 | return '' |
|
1265 | return '' | |
1266 |
|
1266 | |||
1267 | def ancestor(self, c2): |
|
1267 | def ancestor(self, c2): | |
1268 | """return the "best" ancestor context of self and c2""" |
|
1268 | """return the "best" ancestor context of self and c2""" | |
1269 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
1269 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
1270 |
|
1270 | |||
1271 | def walk(self, match): |
|
1271 | def walk(self, match): | |
1272 | return sorted(self._repo.dirstate.walk(match, sorted(self.substate), |
|
1272 | return sorted(self._repo.dirstate.walk(match, sorted(self.substate), | |
1273 | True, False)) |
|
1273 | True, False)) | |
1274 |
|
1274 | |||
1275 | def matches(self, match): |
|
1275 | def matches(self, match): | |
1276 | return sorted(self._repo.dirstate.matches(match)) |
|
1276 | return sorted(self._repo.dirstate.matches(match)) | |
1277 |
|
1277 | |||
1278 | def ancestors(self): |
|
1278 | def ancestors(self): | |
1279 | for p in self._parents: |
|
1279 | for p in self._parents: | |
1280 | yield p |
|
1280 | yield p | |
1281 | for a in self._repo.changelog.ancestors( |
|
1281 | for a in self._repo.changelog.ancestors( | |
1282 | [p.rev() for p in self._parents]): |
|
1282 | [p.rev() for p in self._parents]): | |
1283 | yield changectx(self._repo, a) |
|
1283 | yield changectx(self._repo, a) | |
1284 |
|
1284 | |||
1285 | def markcommitted(self, node): |
|
1285 | def markcommitted(self, node): | |
1286 | """Perform post-commit cleanup necessary after committing this ctx |
|
1286 | """Perform post-commit cleanup necessary after committing this ctx | |
1287 |
|
1287 | |||
1288 | Specifically, this updates backing stores this working context |
|
1288 | Specifically, this updates backing stores this working context | |
1289 | wraps to reflect the fact that the changes reflected by this |
|
1289 | wraps to reflect the fact that the changes reflected by this | |
1290 | workingctx have been committed. For example, it marks |
|
1290 | workingctx have been committed. For example, it marks | |
1291 | modified and added files as normal in the dirstate. |
|
1291 | modified and added files as normal in the dirstate. | |
1292 |
|
1292 | |||
1293 | """ |
|
1293 | """ | |
1294 |
|
1294 | |||
1295 | self._repo.dirstate.beginparentchange() |
|
1295 | self._repo.dirstate.beginparentchange() | |
1296 | for f in self.modified() + self.added(): |
|
1296 | for f in self.modified() + self.added(): | |
1297 | self._repo.dirstate.normal(f) |
|
1297 | self._repo.dirstate.normal(f) | |
1298 | for f in self.removed(): |
|
1298 | for f in self.removed(): | |
1299 | self._repo.dirstate.drop(f) |
|
1299 | self._repo.dirstate.drop(f) | |
1300 | self._repo.dirstate.setparents(node) |
|
1300 | self._repo.dirstate.setparents(node) | |
1301 | self._repo.dirstate.endparentchange() |
|
1301 | self._repo.dirstate.endparentchange() | |
1302 |
|
1302 | |||
1303 | class workingctx(committablectx): |
|
1303 | class workingctx(committablectx): | |
1304 | """A workingctx object makes access to data related to |
|
1304 | """A workingctx object makes access to data related to | |
1305 | the current working directory convenient. |
|
1305 | the current working directory convenient. | |
1306 | date - any valid date string or (unixtime, offset), or None. |
|
1306 | date - any valid date string or (unixtime, offset), or None. | |
1307 | user - username string, or None. |
|
1307 | user - username string, or None. | |
1308 | extra - a dictionary of extra values, or None. |
|
1308 | extra - a dictionary of extra values, or None. | |
1309 | changes - a list of file lists as returned by localrepo.status() |
|
1309 | changes - a list of file lists as returned by localrepo.status() | |
1310 | or None to use the repository status. |
|
1310 | or None to use the repository status. | |
1311 | """ |
|
1311 | """ | |
1312 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1312 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1313 | changes=None): |
|
1313 | changes=None): | |
1314 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
|
1314 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) | |
1315 |
|
1315 | |||
1316 | def __iter__(self): |
|
1316 | def __iter__(self): | |
1317 | d = self._repo.dirstate |
|
1317 | d = self._repo.dirstate | |
1318 | for f in d: |
|
1318 | for f in d: | |
1319 | if d[f] != 'r': |
|
1319 | if d[f] != 'r': | |
1320 | yield f |
|
1320 | yield f | |
1321 |
|
1321 | |||
1322 | def __contains__(self, key): |
|
1322 | def __contains__(self, key): | |
1323 | return self._repo.dirstate[key] not in "?r" |
|
1323 | return self._repo.dirstate[key] not in "?r" | |
1324 |
|
1324 | |||
1325 | @propertycache |
|
1325 | @propertycache | |
1326 | def _parents(self): |
|
1326 | def _parents(self): | |
1327 | p = self._repo.dirstate.parents() |
|
1327 | p = self._repo.dirstate.parents() | |
1328 | if p[1] == nullid: |
|
1328 | if p[1] == nullid: | |
1329 | p = p[:-1] |
|
1329 | p = p[:-1] | |
1330 | return [changectx(self._repo, x) for x in p] |
|
1330 | return [changectx(self._repo, x) for x in p] | |
1331 |
|
1331 | |||
1332 | def filectx(self, path, filelog=None): |
|
1332 | def filectx(self, path, filelog=None): | |
1333 | """get a file context from the working directory""" |
|
1333 | """get a file context from the working directory""" | |
1334 | return workingfilectx(self._repo, path, workingctx=self, |
|
1334 | return workingfilectx(self._repo, path, workingctx=self, | |
1335 | filelog=filelog) |
|
1335 | filelog=filelog) | |
1336 |
|
1336 | |||
1337 | def dirty(self, missing=False, merge=True, branch=True): |
|
1337 | def dirty(self, missing=False, merge=True, branch=True): | |
1338 | "check whether a working directory is modified" |
|
1338 | "check whether a working directory is modified" | |
1339 | # check subrepos first |
|
1339 | # check subrepos first | |
1340 | for s in sorted(self.substate): |
|
1340 | for s in sorted(self.substate): | |
1341 | if self.sub(s).dirty(): |
|
1341 | if self.sub(s).dirty(): | |
1342 | return True |
|
1342 | return True | |
1343 | # check current working dir |
|
1343 | # check current working dir | |
1344 | return ((merge and self.p2()) or |
|
1344 | return ((merge and self.p2()) or | |
1345 | (branch and self.branch() != self.p1().branch()) or |
|
1345 | (branch and self.branch() != self.p1().branch()) or | |
1346 | self.modified() or self.added() or self.removed() or |
|
1346 | self.modified() or self.added() or self.removed() or | |
1347 | (missing and self.deleted())) |
|
1347 | (missing and self.deleted())) | |
1348 |
|
1348 | |||
1349 | def add(self, list, prefix=""): |
|
1349 | def add(self, list, prefix=""): | |
1350 | join = lambda f: os.path.join(prefix, f) |
|
1350 | join = lambda f: os.path.join(prefix, f) | |
1351 | wlock = self._repo.wlock() |
|
1351 | wlock = self._repo.wlock() | |
1352 | ui, ds = self._repo.ui, self._repo.dirstate |
|
1352 | ui, ds = self._repo.ui, self._repo.dirstate | |
1353 | try: |
|
1353 | try: | |
1354 | rejected = [] |
|
1354 | rejected = [] | |
1355 | lstat = self._repo.wvfs.lstat |
|
1355 | lstat = self._repo.wvfs.lstat | |
1356 | for f in list: |
|
1356 | for f in list: | |
1357 | scmutil.checkportable(ui, join(f)) |
|
1357 | scmutil.checkportable(ui, join(f)) | |
1358 | try: |
|
1358 | try: | |
1359 | st = lstat(f) |
|
1359 | st = lstat(f) | |
1360 | except OSError: |
|
1360 | except OSError: | |
1361 | ui.warn(_("%s does not exist!\n") % join(f)) |
|
1361 | ui.warn(_("%s does not exist!\n") % join(f)) | |
1362 | rejected.append(f) |
|
1362 | rejected.append(f) | |
1363 | continue |
|
1363 | continue | |
1364 | if st.st_size > 10000000: |
|
1364 | if st.st_size > 10000000: | |
1365 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1365 | ui.warn(_("%s: up to %d MB of RAM may be required " | |
1366 | "to manage this file\n" |
|
1366 | "to manage this file\n" | |
1367 | "(use 'hg revert %s' to cancel the " |
|
1367 | "(use 'hg revert %s' to cancel the " | |
1368 | "pending addition)\n") |
|
1368 | "pending addition)\n") | |
1369 | % (f, 3 * st.st_size // 1000000, join(f))) |
|
1369 | % (f, 3 * st.st_size // 1000000, join(f))) | |
1370 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1370 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1371 | ui.warn(_("%s not added: only files and symlinks " |
|
1371 | ui.warn(_("%s not added: only files and symlinks " | |
1372 | "supported currently\n") % join(f)) |
|
1372 | "supported currently\n") % join(f)) | |
1373 | rejected.append(f) |
|
1373 | rejected.append(f) | |
1374 | elif ds[f] in 'amn': |
|
1374 | elif ds[f] in 'amn': | |
1375 | ui.warn(_("%s already tracked!\n") % join(f)) |
|
1375 | ui.warn(_("%s already tracked!\n") % join(f)) | |
1376 | elif ds[f] == 'r': |
|
1376 | elif ds[f] == 'r': | |
1377 | ds.normallookup(f) |
|
1377 | ds.normallookup(f) | |
1378 | else: |
|
1378 | else: | |
1379 | ds.add(f) |
|
1379 | ds.add(f) | |
1380 | return rejected |
|
1380 | return rejected | |
1381 | finally: |
|
1381 | finally: | |
1382 | wlock.release() |
|
1382 | wlock.release() | |
1383 |
|
1383 | |||
1384 | def forget(self, files, prefix=""): |
|
1384 | def forget(self, files, prefix=""): | |
1385 | join = lambda f: os.path.join(prefix, f) |
|
1385 | join = lambda f: os.path.join(prefix, f) | |
1386 | wlock = self._repo.wlock() |
|
1386 | wlock = self._repo.wlock() | |
1387 | try: |
|
1387 | try: | |
1388 | rejected = [] |
|
1388 | rejected = [] | |
1389 | for f in files: |
|
1389 | for f in files: | |
1390 | if f not in self._repo.dirstate: |
|
1390 | if f not in self._repo.dirstate: | |
1391 | self._repo.ui.warn(_("%s not tracked!\n") % join(f)) |
|
1391 | self._repo.ui.warn(_("%s not tracked!\n") % join(f)) | |
1392 | rejected.append(f) |
|
1392 | rejected.append(f) | |
1393 | elif self._repo.dirstate[f] != 'a': |
|
1393 | elif self._repo.dirstate[f] != 'a': | |
1394 | self._repo.dirstate.remove(f) |
|
1394 | self._repo.dirstate.remove(f) | |
1395 | else: |
|
1395 | else: | |
1396 | self._repo.dirstate.drop(f) |
|
1396 | self._repo.dirstate.drop(f) | |
1397 | return rejected |
|
1397 | return rejected | |
1398 | finally: |
|
1398 | finally: | |
1399 | wlock.release() |
|
1399 | wlock.release() | |
1400 |
|
1400 | |||
1401 | def undelete(self, list): |
|
1401 | def undelete(self, list): | |
1402 | pctxs = self.parents() |
|
1402 | pctxs = self.parents() | |
1403 | wlock = self._repo.wlock() |
|
1403 | wlock = self._repo.wlock() | |
1404 | try: |
|
1404 | try: | |
1405 | for f in list: |
|
1405 | for f in list: | |
1406 | if self._repo.dirstate[f] != 'r': |
|
1406 | if self._repo.dirstate[f] != 'r': | |
1407 | self._repo.ui.warn(_("%s not removed!\n") % f) |
|
1407 | self._repo.ui.warn(_("%s not removed!\n") % f) | |
1408 | else: |
|
1408 | else: | |
1409 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
1409 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] | |
1410 | t = fctx.data() |
|
1410 | t = fctx.data() | |
1411 | self._repo.wwrite(f, t, fctx.flags()) |
|
1411 | self._repo.wwrite(f, t, fctx.flags()) | |
1412 | self._repo.dirstate.normal(f) |
|
1412 | self._repo.dirstate.normal(f) | |
1413 | finally: |
|
1413 | finally: | |
1414 | wlock.release() |
|
1414 | wlock.release() | |
1415 |
|
1415 | |||
1416 | def copy(self, source, dest): |
|
1416 | def copy(self, source, dest): | |
1417 | try: |
|
1417 | try: | |
1418 | st = self._repo.wvfs.lstat(dest) |
|
1418 | st = self._repo.wvfs.lstat(dest) | |
1419 | except OSError, err: |
|
1419 | except OSError, err: | |
1420 | if err.errno != errno.ENOENT: |
|
1420 | if err.errno != errno.ENOENT: | |
1421 | raise |
|
1421 | raise | |
1422 | self._repo.ui.warn(_("%s does not exist!\n") % dest) |
|
1422 | self._repo.ui.warn(_("%s does not exist!\n") % dest) | |
1423 | return |
|
1423 | return | |
1424 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1424 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1425 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
1425 | self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
1426 | "symbolic link\n") % dest) |
|
1426 | "symbolic link\n") % dest) | |
1427 | else: |
|
1427 | else: | |
1428 | wlock = self._repo.wlock() |
|
1428 | wlock = self._repo.wlock() | |
1429 | try: |
|
1429 | try: | |
1430 | if self._repo.dirstate[dest] in '?': |
|
1430 | if self._repo.dirstate[dest] in '?': | |
1431 | self._repo.dirstate.add(dest) |
|
1431 | self._repo.dirstate.add(dest) | |
1432 | elif self._repo.dirstate[dest] in 'r': |
|
1432 | elif self._repo.dirstate[dest] in 'r': | |
1433 | self._repo.dirstate.normallookup(dest) |
|
1433 | self._repo.dirstate.normallookup(dest) | |
1434 | self._repo.dirstate.copy(source, dest) |
|
1434 | self._repo.dirstate.copy(source, dest) | |
1435 | finally: |
|
1435 | finally: | |
1436 | wlock.release() |
|
1436 | wlock.release() | |
1437 |
|
1437 | |||
1438 | def _filtersuspectsymlink(self, files): |
|
1438 | def _filtersuspectsymlink(self, files): | |
1439 | if not files or self._repo.dirstate._checklink: |
|
1439 | if not files or self._repo.dirstate._checklink: | |
1440 | return files |
|
1440 | return files | |
1441 |
|
1441 | |||
1442 | # Symlink placeholders may get non-symlink-like contents |
|
1442 | # Symlink placeholders may get non-symlink-like contents | |
1443 | # via user error or dereferencing by NFS or Samba servers, |
|
1443 | # via user error or dereferencing by NFS or Samba servers, | |
1444 | # so we filter out any placeholders that don't look like a |
|
1444 | # so we filter out any placeholders that don't look like a | |
1445 | # symlink |
|
1445 | # symlink | |
1446 | sane = [] |
|
1446 | sane = [] | |
1447 | for f in files: |
|
1447 | for f in files: | |
1448 | if self.flags(f) == 'l': |
|
1448 | if self.flags(f) == 'l': | |
1449 | d = self[f].data() |
|
1449 | d = self[f].data() | |
1450 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): |
|
1450 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): | |
1451 | self._repo.ui.debug('ignoring suspect symlink placeholder' |
|
1451 | self._repo.ui.debug('ignoring suspect symlink placeholder' | |
1452 | ' "%s"\n' % f) |
|
1452 | ' "%s"\n' % f) | |
1453 | continue |
|
1453 | continue | |
1454 | sane.append(f) |
|
1454 | sane.append(f) | |
1455 | return sane |
|
1455 | return sane | |
1456 |
|
1456 | |||
1457 | def _checklookup(self, files): |
|
1457 | def _checklookup(self, files): | |
1458 | # check for any possibly clean files |
|
1458 | # check for any possibly clean files | |
1459 | if not files: |
|
1459 | if not files: | |
1460 | return [], [] |
|
1460 | return [], [] | |
1461 |
|
1461 | |||
1462 | modified = [] |
|
1462 | modified = [] | |
1463 | fixup = [] |
|
1463 | fixup = [] | |
1464 | pctx = self._parents[0] |
|
1464 | pctx = self._parents[0] | |
1465 | # do a full compare of any files that might have changed |
|
1465 | # do a full compare of any files that might have changed | |
1466 | for f in sorted(files): |
|
1466 | for f in sorted(files): | |
1467 | if (f not in pctx or self.flags(f) != pctx.flags(f) |
|
1467 | if (f not in pctx or self.flags(f) != pctx.flags(f) | |
1468 | or pctx[f].cmp(self[f])): |
|
1468 | or pctx[f].cmp(self[f])): | |
1469 | modified.append(f) |
|
1469 | modified.append(f) | |
1470 | else: |
|
1470 | else: | |
1471 | fixup.append(f) |
|
1471 | fixup.append(f) | |
1472 |
|
1472 | |||
1473 | # update dirstate for files that are actually clean |
|
1473 | # update dirstate for files that are actually clean | |
1474 | if fixup: |
|
1474 | if fixup: | |
1475 | try: |
|
1475 | try: | |
1476 | # updating the dirstate is optional |
|
1476 | # updating the dirstate is optional | |
1477 | # so we don't wait on the lock |
|
1477 | # so we don't wait on the lock | |
1478 | # wlock can invalidate the dirstate, so cache normal _after_ |
|
1478 | # wlock can invalidate the dirstate, so cache normal _after_ | |
1479 | # taking the lock |
|
1479 | # taking the lock | |
1480 | wlock = self._repo.wlock(False) |
|
1480 | wlock = self._repo.wlock(False) | |
1481 | normal = self._repo.dirstate.normal |
|
1481 | normal = self._repo.dirstate.normal | |
1482 | try: |
|
1482 | try: | |
1483 | for f in fixup: |
|
1483 | for f in fixup: | |
1484 | normal(f) |
|
1484 | normal(f) | |
1485 | finally: |
|
1485 | finally: | |
1486 | wlock.release() |
|
1486 | wlock.release() | |
1487 | except error.LockError: |
|
1487 | except error.LockError: | |
1488 | pass |
|
1488 | pass | |
1489 | return modified, fixup |
|
1489 | return modified, fixup | |
1490 |
|
1490 | |||
1491 | def _manifestmatches(self, match, s): |
|
1491 | def _manifestmatches(self, match, s): | |
1492 | """Slow path for workingctx |
|
1492 | """Slow path for workingctx | |
1493 |
|
1493 | |||
1494 | The fast path is when we compare the working directory to its parent |
|
1494 | The fast path is when we compare the working directory to its parent | |
1495 | which means this function is comparing with a non-parent; therefore we |
|
1495 | which means this function is comparing with a non-parent; therefore we | |
1496 | need to build a manifest and return what matches. |
|
1496 | need to build a manifest and return what matches. | |
1497 | """ |
|
1497 | """ | |
1498 | mf = self._repo['.']._manifestmatches(match, s) |
|
1498 | mf = self._repo['.']._manifestmatches(match, s) | |
1499 | for f in s.modified + s.added: |
|
1499 | for f in s.modified + s.added: | |
1500 | mf[f] = _newnode |
|
1500 | mf[f] = _newnode | |
1501 | mf.setflag(f, self.flags(f)) |
|
1501 | mf.setflag(f, self.flags(f)) | |
1502 | for f in s.removed: |
|
1502 | for f in s.removed: | |
1503 | if f in mf: |
|
1503 | if f in mf: | |
1504 | del mf[f] |
|
1504 | del mf[f] | |
1505 | return mf |
|
1505 | return mf | |
1506 |
|
1506 | |||
1507 | def _dirstatestatus(self, match=None, ignored=False, clean=False, |
|
1507 | def _dirstatestatus(self, match=None, ignored=False, clean=False, | |
1508 | unknown=False): |
|
1508 | unknown=False): | |
1509 | '''Gets the status from the dirstate -- internal use only.''' |
|
1509 | '''Gets the status from the dirstate -- internal use only.''' | |
1510 | listignored, listclean, listunknown = ignored, clean, unknown |
|
1510 | listignored, listclean, listunknown = ignored, clean, unknown | |
1511 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
1511 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
1512 | subrepos = [] |
|
1512 | subrepos = [] | |
1513 | if '.hgsub' in self: |
|
1513 | if '.hgsub' in self: | |
1514 | subrepos = sorted(self.substate) |
|
1514 | subrepos = sorted(self.substate) | |
1515 | cmp, s = self._repo.dirstate.status(match, subrepos, listignored, |
|
1515 | cmp, s = self._repo.dirstate.status(match, subrepos, listignored, | |
1516 | listclean, listunknown) |
|
1516 | listclean, listunknown) | |
1517 |
|
1517 | |||
1518 | # check for any possibly clean files |
|
1518 | # check for any possibly clean files | |
1519 | if cmp: |
|
1519 | if cmp: | |
1520 | modified2, fixup = self._checklookup(cmp) |
|
1520 | modified2, fixup = self._checklookup(cmp) | |
1521 | s.modified.extend(modified2) |
|
1521 | s.modified.extend(modified2) | |
1522 |
|
1522 | |||
1523 | # update dirstate for files that are actually clean |
|
1523 | # update dirstate for files that are actually clean | |
1524 | if fixup and listclean: |
|
1524 | if fixup and listclean: | |
1525 | s.clean.extend(fixup) |
|
1525 | s.clean.extend(fixup) | |
1526 |
|
1526 | |||
1527 | if match.always(): |
|
1527 | if match.always(): | |
1528 | # cache for performance |
|
1528 | # cache for performance | |
1529 | if s.unknown or s.ignored or s.clean: |
|
1529 | if s.unknown or s.ignored or s.clean: | |
1530 | # "_status" is cached with list*=False in the normal route |
|
1530 | # "_status" is cached with list*=False in the normal route | |
1531 | self._status = scmutil.status(s.modified, s.added, s.removed, |
|
1531 | self._status = scmutil.status(s.modified, s.added, s.removed, | |
1532 | s.deleted, [], [], []) |
|
1532 | s.deleted, [], [], []) | |
1533 | else: |
|
1533 | else: | |
1534 | self._status = s |
|
1534 | self._status = s | |
1535 |
|
1535 | |||
1536 | return s |
|
1536 | return s | |
1537 |
|
1537 | |||
1538 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
1538 | def _buildstatus(self, other, s, match, listignored, listclean, | |
1539 | listunknown): |
|
1539 | listunknown): | |
1540 | """build a status with respect to another context |
|
1540 | """build a status with respect to another context | |
1541 |
|
1541 | |||
1542 | This includes logic for maintaining the fast path of status when |
|
1542 | This includes logic for maintaining the fast path of status when | |
1543 | comparing the working directory against its parent, which is to skip |
|
1543 | comparing the working directory against its parent, which is to skip | |
1544 | building a new manifest if self (working directory) is not comparing |
|
1544 | building a new manifest if self (working directory) is not comparing | |
1545 | against its parent (repo['.']). |
|
1545 | against its parent (repo['.']). | |
1546 | """ |
|
1546 | """ | |
1547 | s = self._dirstatestatus(match, listignored, listclean, listunknown) |
|
1547 | s = self._dirstatestatus(match, listignored, listclean, listunknown) | |
1548 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, |
|
1548 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, | |
1549 | # might have accidentally ended up with the entire contents of the file |
|
1549 | # might have accidentally ended up with the entire contents of the file | |
1550 | # they are supposed to be linking to. |
|
1550 | # they are supposed to be linking to. | |
1551 | s.modified[:] = self._filtersuspectsymlink(s.modified) |
|
1551 | s.modified[:] = self._filtersuspectsymlink(s.modified) | |
1552 | if other != self._repo['.']: |
|
1552 | if other != self._repo['.']: | |
1553 | s = super(workingctx, self)._buildstatus(other, s, match, |
|
1553 | s = super(workingctx, self)._buildstatus(other, s, match, | |
1554 | listignored, listclean, |
|
1554 | listignored, listclean, | |
1555 | listunknown) |
|
1555 | listunknown) | |
1556 | return s |
|
1556 | return s | |
1557 |
|
1557 | |||
1558 | def _matchstatus(self, other, match): |
|
1558 | def _matchstatus(self, other, match): | |
1559 | """override the match method with a filter for directory patterns |
|
1559 | """override the match method with a filter for directory patterns | |
1560 |
|
1560 | |||
1561 | We use inheritance to customize the match.bad method only in cases of |
|
1561 | We use inheritance to customize the match.bad method only in cases of | |
1562 | workingctx since it belongs only to the working directory when |
|
1562 | workingctx since it belongs only to the working directory when | |
1563 | comparing against the parent changeset. |
|
1563 | comparing against the parent changeset. | |
1564 |
|
1564 | |||
1565 | If we aren't comparing against the working directory's parent, then we |
|
1565 | If we aren't comparing against the working directory's parent, then we | |
1566 | just use the default match object sent to us. |
|
1566 | just use the default match object sent to us. | |
1567 | """ |
|
1567 | """ | |
1568 | superself = super(workingctx, self) |
|
1568 | superself = super(workingctx, self) | |
1569 | match = superself._matchstatus(other, match) |
|
1569 | match = superself._matchstatus(other, match) | |
1570 | if other != self._repo['.']: |
|
1570 | if other != self._repo['.']: | |
1571 | def bad(f, msg): |
|
1571 | def bad(f, msg): | |
1572 | # 'f' may be a directory pattern from 'match.files()', |
|
1572 | # 'f' may be a directory pattern from 'match.files()', | |
1573 | # so 'f not in ctx1' is not enough |
|
1573 | # so 'f not in ctx1' is not enough | |
1574 | if f not in other and not other.hasdir(f): |
|
1574 | if f not in other and not other.hasdir(f): | |
1575 | self._repo.ui.warn('%s: %s\n' % |
|
1575 | self._repo.ui.warn('%s: %s\n' % | |
1576 | (self._repo.dirstate.pathto(f), msg)) |
|
1576 | (self._repo.dirstate.pathto(f), msg)) | |
1577 | match.bad = bad |
|
1577 | match.bad = bad | |
1578 | return match |
|
1578 | return match | |
1579 |
|
1579 | |||
1580 | class committablefilectx(basefilectx): |
|
1580 | class committablefilectx(basefilectx): | |
1581 | """A committablefilectx provides common functionality for a file context |
|
1581 | """A committablefilectx provides common functionality for a file context | |
1582 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" |
|
1582 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" | |
1583 | def __init__(self, repo, path, filelog=None, ctx=None): |
|
1583 | def __init__(self, repo, path, filelog=None, ctx=None): | |
1584 | self._repo = repo |
|
1584 | self._repo = repo | |
1585 | self._path = path |
|
1585 | self._path = path | |
1586 | self._changeid = None |
|
1586 | self._changeid = None | |
1587 | self._filerev = self._filenode = None |
|
1587 | self._filerev = self._filenode = None | |
1588 |
|
1588 | |||
1589 | if filelog is not None: |
|
1589 | if filelog is not None: | |
1590 | self._filelog = filelog |
|
1590 | self._filelog = filelog | |
1591 | if ctx: |
|
1591 | if ctx: | |
1592 | self._changectx = ctx |
|
1592 | self._changectx = ctx | |
1593 |
|
1593 | |||
1594 | def __nonzero__(self): |
|
1594 | def __nonzero__(self): | |
1595 | return True |
|
1595 | return True | |
1596 |
|
1596 | |||
|
1597 | def linkrev(self): | |||
|
1598 | # linked to self._changectx no matter if file is modified or not | |||
|
1599 | return self.rev() | |||
|
1600 | ||||
1597 | def parents(self): |
|
1601 | def parents(self): | |
1598 | '''return parent filectxs, following copies if necessary''' |
|
1602 | '''return parent filectxs, following copies if necessary''' | |
1599 | def filenode(ctx, path): |
|
1603 | def filenode(ctx, path): | |
1600 | return ctx._manifest.get(path, nullid) |
|
1604 | return ctx._manifest.get(path, nullid) | |
1601 |
|
1605 | |||
1602 | path = self._path |
|
1606 | path = self._path | |
1603 | fl = self._filelog |
|
1607 | fl = self._filelog | |
1604 | pcl = self._changectx._parents |
|
1608 | pcl = self._changectx._parents | |
1605 | renamed = self.renamed() |
|
1609 | renamed = self.renamed() | |
1606 |
|
1610 | |||
1607 | if renamed: |
|
1611 | if renamed: | |
1608 | pl = [renamed + (None,)] |
|
1612 | pl = [renamed + (None,)] | |
1609 | else: |
|
1613 | else: | |
1610 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1614 | pl = [(path, filenode(pcl[0], path), fl)] | |
1611 |
|
1615 | |||
1612 | for pc in pcl[1:]: |
|
1616 | for pc in pcl[1:]: | |
1613 | pl.append((path, filenode(pc, path), fl)) |
|
1617 | pl.append((path, filenode(pc, path), fl)) | |
1614 |
|
1618 | |||
1615 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
1619 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
1616 | for p, n, l in pl if n != nullid] |
|
1620 | for p, n, l in pl if n != nullid] | |
1617 |
|
1621 | |||
1618 | def children(self): |
|
1622 | def children(self): | |
1619 | return [] |
|
1623 | return [] | |
1620 |
|
1624 | |||
1621 | class workingfilectx(committablefilectx): |
|
1625 | class workingfilectx(committablefilectx): | |
1622 | """A workingfilectx object makes access to data related to a particular |
|
1626 | """A workingfilectx object makes access to data related to a particular | |
1623 | file in the working directory convenient.""" |
|
1627 | file in the working directory convenient.""" | |
1624 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
1628 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
1625 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) |
|
1629 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) | |
1626 |
|
1630 | |||
1627 | @propertycache |
|
1631 | @propertycache | |
1628 | def _changectx(self): |
|
1632 | def _changectx(self): | |
1629 | return workingctx(self._repo) |
|
1633 | return workingctx(self._repo) | |
1630 |
|
1634 | |||
1631 | def data(self): |
|
1635 | def data(self): | |
1632 | return self._repo.wread(self._path) |
|
1636 | return self._repo.wread(self._path) | |
1633 | def renamed(self): |
|
1637 | def renamed(self): | |
1634 | rp = self._repo.dirstate.copied(self._path) |
|
1638 | rp = self._repo.dirstate.copied(self._path) | |
1635 | if not rp: |
|
1639 | if not rp: | |
1636 | return None |
|
1640 | return None | |
1637 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1641 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
1638 |
|
1642 | |||
1639 | def size(self): |
|
1643 | def size(self): | |
1640 | return self._repo.wvfs.lstat(self._path).st_size |
|
1644 | return self._repo.wvfs.lstat(self._path).st_size | |
1641 | def date(self): |
|
1645 | def date(self): | |
1642 | t, tz = self._changectx.date() |
|
1646 | t, tz = self._changectx.date() | |
1643 | try: |
|
1647 | try: | |
1644 | return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz) |
|
1648 | return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz) | |
1645 | except OSError, err: |
|
1649 | except OSError, err: | |
1646 | if err.errno != errno.ENOENT: |
|
1650 | if err.errno != errno.ENOENT: | |
1647 | raise |
|
1651 | raise | |
1648 | return (t, tz) |
|
1652 | return (t, tz) | |
1649 |
|
1653 | |||
1650 | def cmp(self, fctx): |
|
1654 | def cmp(self, fctx): | |
1651 | """compare with other file context |
|
1655 | """compare with other file context | |
1652 |
|
1656 | |||
1653 | returns True if different than fctx. |
|
1657 | returns True if different than fctx. | |
1654 | """ |
|
1658 | """ | |
1655 | # fctx should be a filectx (not a workingfilectx) |
|
1659 | # fctx should be a filectx (not a workingfilectx) | |
1656 | # invert comparison to reuse the same code path |
|
1660 | # invert comparison to reuse the same code path | |
1657 | return fctx.cmp(self) |
|
1661 | return fctx.cmp(self) | |
1658 |
|
1662 | |||
1659 | def remove(self, ignoremissing=False): |
|
1663 | def remove(self, ignoremissing=False): | |
1660 | """wraps unlink for a repo's working directory""" |
|
1664 | """wraps unlink for a repo's working directory""" | |
1661 | util.unlinkpath(self._repo.wjoin(self._path), ignoremissing) |
|
1665 | util.unlinkpath(self._repo.wjoin(self._path), ignoremissing) | |
1662 |
|
1666 | |||
1663 | def write(self, data, flags): |
|
1667 | def write(self, data, flags): | |
1664 | """wraps repo.wwrite""" |
|
1668 | """wraps repo.wwrite""" | |
1665 | self._repo.wwrite(self._path, data, flags) |
|
1669 | self._repo.wwrite(self._path, data, flags) | |
1666 |
|
1670 | |||
1667 | class workingcommitctx(workingctx): |
|
1671 | class workingcommitctx(workingctx): | |
1668 | """A workingcommitctx object makes access to data related to |
|
1672 | """A workingcommitctx object makes access to data related to | |
1669 | the revision being committed convenient. |
|
1673 | the revision being committed convenient. | |
1670 |
|
1674 | |||
1671 | This hides changes in the working directory, if they aren't |
|
1675 | This hides changes in the working directory, if they aren't | |
1672 | committed in this context. |
|
1676 | committed in this context. | |
1673 | """ |
|
1677 | """ | |
1674 | def __init__(self, repo, changes, |
|
1678 | def __init__(self, repo, changes, | |
1675 | text="", user=None, date=None, extra=None): |
|
1679 | text="", user=None, date=None, extra=None): | |
1676 | super(workingctx, self).__init__(repo, text, user, date, extra, |
|
1680 | super(workingctx, self).__init__(repo, text, user, date, extra, | |
1677 | changes) |
|
1681 | changes) | |
1678 |
|
1682 | |||
1679 | def _dirstatestatus(self, match=None, ignored=False, clean=False, |
|
1683 | def _dirstatestatus(self, match=None, ignored=False, clean=False, | |
1680 | unknown=False): |
|
1684 | unknown=False): | |
1681 | """Return matched files only in ``self._status`` |
|
1685 | """Return matched files only in ``self._status`` | |
1682 |
|
1686 | |||
1683 | Uncommitted files appear "clean" via this context, even if |
|
1687 | Uncommitted files appear "clean" via this context, even if | |
1684 | they aren't actually so in the working directory. |
|
1688 | they aren't actually so in the working directory. | |
1685 | """ |
|
1689 | """ | |
1686 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
1690 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
1687 | if clean: |
|
1691 | if clean: | |
1688 | clean = [f for f in self._manifest if f not in self._changedset] |
|
1692 | clean = [f for f in self._manifest if f not in self._changedset] | |
1689 | else: |
|
1693 | else: | |
1690 | clean = [] |
|
1694 | clean = [] | |
1691 | return scmutil.status([f for f in self._status.modified if match(f)], |
|
1695 | return scmutil.status([f for f in self._status.modified if match(f)], | |
1692 | [f for f in self._status.added if match(f)], |
|
1696 | [f for f in self._status.added if match(f)], | |
1693 | [f for f in self._status.removed if match(f)], |
|
1697 | [f for f in self._status.removed if match(f)], | |
1694 | [], [], [], clean) |
|
1698 | [], [], [], clean) | |
1695 |
|
1699 | |||
1696 | @propertycache |
|
1700 | @propertycache | |
1697 | def _changedset(self): |
|
1701 | def _changedset(self): | |
1698 | """Return the set of files changed in this context |
|
1702 | """Return the set of files changed in this context | |
1699 | """ |
|
1703 | """ | |
1700 | changed = set(self._status.modified) |
|
1704 | changed = set(self._status.modified) | |
1701 | changed.update(self._status.added) |
|
1705 | changed.update(self._status.added) | |
1702 | changed.update(self._status.removed) |
|
1706 | changed.update(self._status.removed) | |
1703 | return changed |
|
1707 | return changed | |
1704 |
|
1708 | |||
1705 | class memctx(committablectx): |
|
1709 | class memctx(committablectx): | |
1706 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
1710 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
1707 |
|
1711 | |||
1708 | Revision information is supplied at initialization time while |
|
1712 | Revision information is supplied at initialization time while | |
1709 | related files data and is made available through a callback |
|
1713 | related files data and is made available through a callback | |
1710 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
1714 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
1711 | sequence of two parent revisions identifiers (pass None for every |
|
1715 | sequence of two parent revisions identifiers (pass None for every | |
1712 | missing parent), 'text' is the commit message and 'files' lists |
|
1716 | missing parent), 'text' is the commit message and 'files' lists | |
1713 | names of files touched by the revision (normalized and relative to |
|
1717 | names of files touched by the revision (normalized and relative to | |
1714 | repository root). |
|
1718 | repository root). | |
1715 |
|
1719 | |||
1716 | filectxfn(repo, memctx, path) is a callable receiving the |
|
1720 | filectxfn(repo, memctx, path) is a callable receiving the | |
1717 | repository, the current memctx object and the normalized path of |
|
1721 | repository, the current memctx object and the normalized path of | |
1718 | requested file, relative to repository root. It is fired by the |
|
1722 | requested file, relative to repository root. It is fired by the | |
1719 | commit function for every file in 'files', but calls order is |
|
1723 | commit function for every file in 'files', but calls order is | |
1720 | undefined. If the file is available in the revision being |
|
1724 | undefined. If the file is available in the revision being | |
1721 | committed (updated or added), filectxfn returns a memfilectx |
|
1725 | committed (updated or added), filectxfn returns a memfilectx | |
1722 | object. If the file was removed, filectxfn raises an |
|
1726 | object. If the file was removed, filectxfn raises an | |
1723 | IOError. Moved files are represented by marking the source file |
|
1727 | IOError. Moved files are represented by marking the source file | |
1724 | removed and the new file added with copy information (see |
|
1728 | removed and the new file added with copy information (see | |
1725 | memfilectx). |
|
1729 | memfilectx). | |
1726 |
|
1730 | |||
1727 | user receives the committer name and defaults to current |
|
1731 | user receives the committer name and defaults to current | |
1728 | repository username, date is the commit date in any format |
|
1732 | repository username, date is the commit date in any format | |
1729 | supported by util.parsedate() and defaults to current date, extra |
|
1733 | supported by util.parsedate() and defaults to current date, extra | |
1730 | is a dictionary of metadata or is left empty. |
|
1734 | is a dictionary of metadata or is left empty. | |
1731 | """ |
|
1735 | """ | |
1732 |
|
1736 | |||
1733 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. |
|
1737 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. | |
1734 | # Extensions that need to retain compatibility across Mercurial 3.1 can use |
|
1738 | # Extensions that need to retain compatibility across Mercurial 3.1 can use | |
1735 | # this field to determine what to do in filectxfn. |
|
1739 | # this field to determine what to do in filectxfn. | |
1736 | _returnnoneformissingfiles = True |
|
1740 | _returnnoneformissingfiles = True | |
1737 |
|
1741 | |||
1738 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
1742 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
1739 | date=None, extra=None, editor=False): |
|
1743 | date=None, extra=None, editor=False): | |
1740 | super(memctx, self).__init__(repo, text, user, date, extra) |
|
1744 | super(memctx, self).__init__(repo, text, user, date, extra) | |
1741 | self._rev = None |
|
1745 | self._rev = None | |
1742 | self._node = None |
|
1746 | self._node = None | |
1743 | parents = [(p or nullid) for p in parents] |
|
1747 | parents = [(p or nullid) for p in parents] | |
1744 | p1, p2 = parents |
|
1748 | p1, p2 = parents | |
1745 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
1749 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
1746 | files = sorted(set(files)) |
|
1750 | files = sorted(set(files)) | |
1747 | self._files = files |
|
1751 | self._files = files | |
1748 | self.substate = {} |
|
1752 | self.substate = {} | |
1749 |
|
1753 | |||
1750 | # if store is not callable, wrap it in a function |
|
1754 | # if store is not callable, wrap it in a function | |
1751 | if not callable(filectxfn): |
|
1755 | if not callable(filectxfn): | |
1752 | def getfilectx(repo, memctx, path): |
|
1756 | def getfilectx(repo, memctx, path): | |
1753 | fctx = filectxfn[path] |
|
1757 | fctx = filectxfn[path] | |
1754 | # this is weird but apparently we only keep track of one parent |
|
1758 | # this is weird but apparently we only keep track of one parent | |
1755 | # (why not only store that instead of a tuple?) |
|
1759 | # (why not only store that instead of a tuple?) | |
1756 | copied = fctx.renamed() |
|
1760 | copied = fctx.renamed() | |
1757 | if copied: |
|
1761 | if copied: | |
1758 | copied = copied[0] |
|
1762 | copied = copied[0] | |
1759 | return memfilectx(repo, path, fctx.data(), |
|
1763 | return memfilectx(repo, path, fctx.data(), | |
1760 | islink=fctx.islink(), isexec=fctx.isexec(), |
|
1764 | islink=fctx.islink(), isexec=fctx.isexec(), | |
1761 | copied=copied, memctx=memctx) |
|
1765 | copied=copied, memctx=memctx) | |
1762 | self._filectxfn = getfilectx |
|
1766 | self._filectxfn = getfilectx | |
1763 | else: |
|
1767 | else: | |
1764 | # "util.cachefunc" reduces invocation of possibly expensive |
|
1768 | # "util.cachefunc" reduces invocation of possibly expensive | |
1765 | # "filectxfn" for performance (e.g. converting from another VCS) |
|
1769 | # "filectxfn" for performance (e.g. converting from another VCS) | |
1766 | self._filectxfn = util.cachefunc(filectxfn) |
|
1770 | self._filectxfn = util.cachefunc(filectxfn) | |
1767 |
|
1771 | |||
1768 | if extra: |
|
1772 | if extra: | |
1769 | self._extra = extra.copy() |
|
1773 | self._extra = extra.copy() | |
1770 | else: |
|
1774 | else: | |
1771 | self._extra = {} |
|
1775 | self._extra = {} | |
1772 |
|
1776 | |||
1773 | if self._extra.get('branch', '') == '': |
|
1777 | if self._extra.get('branch', '') == '': | |
1774 | self._extra['branch'] = 'default' |
|
1778 | self._extra['branch'] = 'default' | |
1775 |
|
1779 | |||
1776 | if editor: |
|
1780 | if editor: | |
1777 | self._text = editor(self._repo, self, []) |
|
1781 | self._text = editor(self._repo, self, []) | |
1778 | self._repo.savecommitmessage(self._text) |
|
1782 | self._repo.savecommitmessage(self._text) | |
1779 |
|
1783 | |||
1780 | def filectx(self, path, filelog=None): |
|
1784 | def filectx(self, path, filelog=None): | |
1781 | """get a file context from the working directory |
|
1785 | """get a file context from the working directory | |
1782 |
|
1786 | |||
1783 | Returns None if file doesn't exist and should be removed.""" |
|
1787 | Returns None if file doesn't exist and should be removed.""" | |
1784 | return self._filectxfn(self._repo, self, path) |
|
1788 | return self._filectxfn(self._repo, self, path) | |
1785 |
|
1789 | |||
1786 | def commit(self): |
|
1790 | def commit(self): | |
1787 | """commit context to the repo""" |
|
1791 | """commit context to the repo""" | |
1788 | return self._repo.commitctx(self) |
|
1792 | return self._repo.commitctx(self) | |
1789 |
|
1793 | |||
1790 | @propertycache |
|
1794 | @propertycache | |
1791 | def _manifest(self): |
|
1795 | def _manifest(self): | |
1792 | """generate a manifest based on the return values of filectxfn""" |
|
1796 | """generate a manifest based on the return values of filectxfn""" | |
1793 |
|
1797 | |||
1794 | # keep this simple for now; just worry about p1 |
|
1798 | # keep this simple for now; just worry about p1 | |
1795 | pctx = self._parents[0] |
|
1799 | pctx = self._parents[0] | |
1796 | man = pctx.manifest().copy() |
|
1800 | man = pctx.manifest().copy() | |
1797 |
|
1801 | |||
1798 | for f in self._status.modified: |
|
1802 | for f in self._status.modified: | |
1799 | p1node = nullid |
|
1803 | p1node = nullid | |
1800 | p2node = nullid |
|
1804 | p2node = nullid | |
1801 | p = pctx[f].parents() # if file isn't in pctx, check p2? |
|
1805 | p = pctx[f].parents() # if file isn't in pctx, check p2? | |
1802 | if len(p) > 0: |
|
1806 | if len(p) > 0: | |
1803 | p1node = p[0].node() |
|
1807 | p1node = p[0].node() | |
1804 | if len(p) > 1: |
|
1808 | if len(p) > 1: | |
1805 | p2node = p[1].node() |
|
1809 | p2node = p[1].node() | |
1806 | man[f] = revlog.hash(self[f].data(), p1node, p2node) |
|
1810 | man[f] = revlog.hash(self[f].data(), p1node, p2node) | |
1807 |
|
1811 | |||
1808 | for f in self._status.added: |
|
1812 | for f in self._status.added: | |
1809 | man[f] = revlog.hash(self[f].data(), nullid, nullid) |
|
1813 | man[f] = revlog.hash(self[f].data(), nullid, nullid) | |
1810 |
|
1814 | |||
1811 | for f in self._status.removed: |
|
1815 | for f in self._status.removed: | |
1812 | if f in man: |
|
1816 | if f in man: | |
1813 | del man[f] |
|
1817 | del man[f] | |
1814 |
|
1818 | |||
1815 | return man |
|
1819 | return man | |
1816 |
|
1820 | |||
1817 | @propertycache |
|
1821 | @propertycache | |
1818 | def _status(self): |
|
1822 | def _status(self): | |
1819 | """Calculate exact status from ``files`` specified at construction |
|
1823 | """Calculate exact status from ``files`` specified at construction | |
1820 | """ |
|
1824 | """ | |
1821 | man1 = self.p1().manifest() |
|
1825 | man1 = self.p1().manifest() | |
1822 | p2 = self._parents[1] |
|
1826 | p2 = self._parents[1] | |
1823 | # "1 < len(self._parents)" can't be used for checking |
|
1827 | # "1 < len(self._parents)" can't be used for checking | |
1824 | # existence of the 2nd parent, because "memctx._parents" is |
|
1828 | # existence of the 2nd parent, because "memctx._parents" is | |
1825 | # explicitly initialized by the list, of which length is 2. |
|
1829 | # explicitly initialized by the list, of which length is 2. | |
1826 | if p2.node() != nullid: |
|
1830 | if p2.node() != nullid: | |
1827 | man2 = p2.manifest() |
|
1831 | man2 = p2.manifest() | |
1828 | managing = lambda f: f in man1 or f in man2 |
|
1832 | managing = lambda f: f in man1 or f in man2 | |
1829 | else: |
|
1833 | else: | |
1830 | managing = lambda f: f in man1 |
|
1834 | managing = lambda f: f in man1 | |
1831 |
|
1835 | |||
1832 | modified, added, removed = [], [], [] |
|
1836 | modified, added, removed = [], [], [] | |
1833 | for f in self._files: |
|
1837 | for f in self._files: | |
1834 | if not managing(f): |
|
1838 | if not managing(f): | |
1835 | added.append(f) |
|
1839 | added.append(f) | |
1836 | elif self[f]: |
|
1840 | elif self[f]: | |
1837 | modified.append(f) |
|
1841 | modified.append(f) | |
1838 | else: |
|
1842 | else: | |
1839 | removed.append(f) |
|
1843 | removed.append(f) | |
1840 |
|
1844 | |||
1841 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
1845 | return scmutil.status(modified, added, removed, [], [], [], []) | |
1842 |
|
1846 | |||
1843 | class memfilectx(committablefilectx): |
|
1847 | class memfilectx(committablefilectx): | |
1844 | """memfilectx represents an in-memory file to commit. |
|
1848 | """memfilectx represents an in-memory file to commit. | |
1845 |
|
1849 | |||
1846 | See memctx and committablefilectx for more details. |
|
1850 | See memctx and committablefilectx for more details. | |
1847 | """ |
|
1851 | """ | |
1848 | def __init__(self, repo, path, data, islink=False, |
|
1852 | def __init__(self, repo, path, data, islink=False, | |
1849 | isexec=False, copied=None, memctx=None): |
|
1853 | isexec=False, copied=None, memctx=None): | |
1850 | """ |
|
1854 | """ | |
1851 | path is the normalized file path relative to repository root. |
|
1855 | path is the normalized file path relative to repository root. | |
1852 | data is the file content as a string. |
|
1856 | data is the file content as a string. | |
1853 | islink is True if the file is a symbolic link. |
|
1857 | islink is True if the file is a symbolic link. | |
1854 | isexec is True if the file is executable. |
|
1858 | isexec is True if the file is executable. | |
1855 | copied is the source file path if current file was copied in the |
|
1859 | copied is the source file path if current file was copied in the | |
1856 | revision being committed, or None.""" |
|
1860 | revision being committed, or None.""" | |
1857 | super(memfilectx, self).__init__(repo, path, None, memctx) |
|
1861 | super(memfilectx, self).__init__(repo, path, None, memctx) | |
1858 | self._data = data |
|
1862 | self._data = data | |
1859 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
1863 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
1860 | self._copied = None |
|
1864 | self._copied = None | |
1861 | if copied: |
|
1865 | if copied: | |
1862 | self._copied = (copied, nullid) |
|
1866 | self._copied = (copied, nullid) | |
1863 |
|
1867 | |||
1864 | def data(self): |
|
1868 | def data(self): | |
1865 | return self._data |
|
1869 | return self._data | |
1866 | def size(self): |
|
1870 | def size(self): | |
1867 | return len(self.data()) |
|
1871 | return len(self.data()) | |
1868 | def flags(self): |
|
1872 | def flags(self): | |
1869 | return self._flags |
|
1873 | return self._flags | |
1870 | def renamed(self): |
|
1874 | def renamed(self): | |
1871 | return self._copied |
|
1875 | return self._copied | |
1872 |
|
1876 | |||
1873 | def remove(self, ignoremissing=False): |
|
1877 | def remove(self, ignoremissing=False): | |
1874 | """wraps unlink for a repo's working directory""" |
|
1878 | """wraps unlink for a repo's working directory""" | |
1875 | # need to figure out what to do here |
|
1879 | # need to figure out what to do here | |
1876 | del self._changectx[self._path] |
|
1880 | del self._changectx[self._path] | |
1877 |
|
1881 | |||
1878 | def write(self, data, flags): |
|
1882 | def write(self, data, flags): | |
1879 | """wraps repo.wwrite""" |
|
1883 | """wraps repo.wwrite""" | |
1880 | self._data = data |
|
1884 | self._data = data |
General Comments 0
You need to be logged in to leave comments.
Login now