Show More
@@ -1,1873 +1,1872 b'' | |||||
1 | # context.py - changeset and file context objects for mercurial |
|
1 | # context.py - changeset and file context objects for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import nullid, nullrev, short, hex, 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 | # for dirstate.walk, files=['.'] means "walk the whole tree". |
|
|||
592 | # follow that here, too |
|
|||
593 | fset.discard('.') |
|
|||
594 |
|
||||
595 | # 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 | |
596 | if fset and not match.anypats(): |
|
592 | if fset and not match.anypats(): | |
597 | if util.all(fn in self for fn in fset): |
|
593 | if util.all(fn in self for fn in fset): | |
598 | for fn in sorted(fset): |
|
594 | for fn in sorted(fset): | |
599 | if match(fn): |
|
595 | if match(fn): | |
600 | yield fn |
|
596 | yield fn | |
601 | raise StopIteration |
|
597 | raise StopIteration | |
602 |
|
598 | |||
603 | for fn in self: |
|
599 | for fn in self: | |
604 | if fn in fset: |
|
600 | if fn in fset: | |
605 | # specified pattern is the exact name |
|
601 | # specified pattern is the exact name | |
606 | fset.remove(fn) |
|
602 | fset.remove(fn) | |
607 | if match(fn): |
|
603 | if match(fn): | |
608 | yield fn |
|
604 | yield fn | |
|
605 | # for dirstate.walk, files=['.'] means "walk the whole tree". | |||
|
606 | # follow that here, too | |||
|
607 | fset.discard('.') | |||
609 | for fn in sorted(fset): |
|
608 | for fn in sorted(fset): | |
610 | if not self.hasdir(fn): |
|
609 | if not self.hasdir(fn): | |
611 | match.bad(fn, _('no such file in rev %s') % self) |
|
610 | match.bad(fn, _('no such file in rev %s') % self) | |
612 |
|
611 | |||
613 | def matches(self, match): |
|
612 | def matches(self, match): | |
614 | return self.walk(match) |
|
613 | return self.walk(match) | |
615 |
|
614 | |||
616 | class basefilectx(object): |
|
615 | class basefilectx(object): | |
617 | """A filecontext object represents the common logic for its children: |
|
616 | """A filecontext object represents the common logic for its children: | |
618 | filectx: read-only access to a filerevision that is already present |
|
617 | filectx: read-only access to a filerevision that is already present | |
619 | in the repo, |
|
618 | in the repo, | |
620 | workingfilectx: a filecontext that represents files from the working |
|
619 | workingfilectx: a filecontext that represents files from the working | |
621 | directory, |
|
620 | directory, | |
622 | memfilectx: a filecontext that represents files in-memory.""" |
|
621 | memfilectx: a filecontext that represents files in-memory.""" | |
623 | def __new__(cls, repo, path, *args, **kwargs): |
|
622 | def __new__(cls, repo, path, *args, **kwargs): | |
624 | return super(basefilectx, cls).__new__(cls) |
|
623 | return super(basefilectx, cls).__new__(cls) | |
625 |
|
624 | |||
626 | @propertycache |
|
625 | @propertycache | |
627 | def _filelog(self): |
|
626 | def _filelog(self): | |
628 | return self._repo.file(self._path) |
|
627 | return self._repo.file(self._path) | |
629 |
|
628 | |||
630 | @propertycache |
|
629 | @propertycache | |
631 | def _changeid(self): |
|
630 | def _changeid(self): | |
632 | if '_changeid' in self.__dict__: |
|
631 | if '_changeid' in self.__dict__: | |
633 | return self._changeid |
|
632 | return self._changeid | |
634 | elif '_changectx' in self.__dict__: |
|
633 | elif '_changectx' in self.__dict__: | |
635 | return self._changectx.rev() |
|
634 | return self._changectx.rev() | |
636 | elif '_descendantrev' in self.__dict__: |
|
635 | elif '_descendantrev' in self.__dict__: | |
637 | # this file context was created from a revision with a known |
|
636 | # this file context was created from a revision with a known | |
638 | # descendant, we can (lazily) correct for linkrev aliases |
|
637 | # descendant, we can (lazily) correct for linkrev aliases | |
639 | return self._adjustlinkrev(self._path, self._filelog, |
|
638 | return self._adjustlinkrev(self._path, self._filelog, | |
640 | self._filenode, self._descendantrev) |
|
639 | self._filenode, self._descendantrev) | |
641 | else: |
|
640 | else: | |
642 | return self._filelog.linkrev(self._filerev) |
|
641 | return self._filelog.linkrev(self._filerev) | |
643 |
|
642 | |||
644 | @propertycache |
|
643 | @propertycache | |
645 | def _filenode(self): |
|
644 | def _filenode(self): | |
646 | if '_fileid' in self.__dict__: |
|
645 | if '_fileid' in self.__dict__: | |
647 | return self._filelog.lookup(self._fileid) |
|
646 | return self._filelog.lookup(self._fileid) | |
648 | else: |
|
647 | else: | |
649 | return self._changectx.filenode(self._path) |
|
648 | return self._changectx.filenode(self._path) | |
650 |
|
649 | |||
651 | @propertycache |
|
650 | @propertycache | |
652 | def _filerev(self): |
|
651 | def _filerev(self): | |
653 | return self._filelog.rev(self._filenode) |
|
652 | return self._filelog.rev(self._filenode) | |
654 |
|
653 | |||
655 | @propertycache |
|
654 | @propertycache | |
656 | def _repopath(self): |
|
655 | def _repopath(self): | |
657 | return self._path |
|
656 | return self._path | |
658 |
|
657 | |||
659 | def __nonzero__(self): |
|
658 | def __nonzero__(self): | |
660 | try: |
|
659 | try: | |
661 | self._filenode |
|
660 | self._filenode | |
662 | return True |
|
661 | return True | |
663 | except error.LookupError: |
|
662 | except error.LookupError: | |
664 | # file is missing |
|
663 | # file is missing | |
665 | return False |
|
664 | return False | |
666 |
|
665 | |||
667 | def __str__(self): |
|
666 | def __str__(self): | |
668 | return "%s@%s" % (self.path(), self._changectx) |
|
667 | return "%s@%s" % (self.path(), self._changectx) | |
669 |
|
668 | |||
670 | def __repr__(self): |
|
669 | def __repr__(self): | |
671 | return "<%s %s>" % (type(self).__name__, str(self)) |
|
670 | return "<%s %s>" % (type(self).__name__, str(self)) | |
672 |
|
671 | |||
673 | def __hash__(self): |
|
672 | def __hash__(self): | |
674 | try: |
|
673 | try: | |
675 | return hash((self._path, self._filenode)) |
|
674 | return hash((self._path, self._filenode)) | |
676 | except AttributeError: |
|
675 | except AttributeError: | |
677 | return id(self) |
|
676 | return id(self) | |
678 |
|
677 | |||
679 | def __eq__(self, other): |
|
678 | def __eq__(self, other): | |
680 | try: |
|
679 | try: | |
681 | return (type(self) == type(other) and self._path == other._path |
|
680 | return (type(self) == type(other) and self._path == other._path | |
682 | and self._filenode == other._filenode) |
|
681 | and self._filenode == other._filenode) | |
683 | except AttributeError: |
|
682 | except AttributeError: | |
684 | return False |
|
683 | return False | |
685 |
|
684 | |||
686 | def __ne__(self, other): |
|
685 | def __ne__(self, other): | |
687 | return not (self == other) |
|
686 | return not (self == other) | |
688 |
|
687 | |||
689 | def filerev(self): |
|
688 | def filerev(self): | |
690 | return self._filerev |
|
689 | return self._filerev | |
691 | def filenode(self): |
|
690 | def filenode(self): | |
692 | return self._filenode |
|
691 | return self._filenode | |
693 | def flags(self): |
|
692 | def flags(self): | |
694 | return self._changectx.flags(self._path) |
|
693 | return self._changectx.flags(self._path) | |
695 | def filelog(self): |
|
694 | def filelog(self): | |
696 | return self._filelog |
|
695 | return self._filelog | |
697 | def rev(self): |
|
696 | def rev(self): | |
698 | return self._changeid |
|
697 | return self._changeid | |
699 | def linkrev(self): |
|
698 | def linkrev(self): | |
700 | return self._filelog.linkrev(self._filerev) |
|
699 | return self._filelog.linkrev(self._filerev) | |
701 | def node(self): |
|
700 | def node(self): | |
702 | return self._changectx.node() |
|
701 | return self._changectx.node() | |
703 | def hex(self): |
|
702 | def hex(self): | |
704 | return self._changectx.hex() |
|
703 | return self._changectx.hex() | |
705 | def user(self): |
|
704 | def user(self): | |
706 | return self._changectx.user() |
|
705 | return self._changectx.user() | |
707 | def date(self): |
|
706 | def date(self): | |
708 | return self._changectx.date() |
|
707 | return self._changectx.date() | |
709 | def files(self): |
|
708 | def files(self): | |
710 | return self._changectx.files() |
|
709 | return self._changectx.files() | |
711 | def description(self): |
|
710 | def description(self): | |
712 | return self._changectx.description() |
|
711 | return self._changectx.description() | |
713 | def branch(self): |
|
712 | def branch(self): | |
714 | return self._changectx.branch() |
|
713 | return self._changectx.branch() | |
715 | def extra(self): |
|
714 | def extra(self): | |
716 | return self._changectx.extra() |
|
715 | return self._changectx.extra() | |
717 | def phase(self): |
|
716 | def phase(self): | |
718 | return self._changectx.phase() |
|
717 | return self._changectx.phase() | |
719 | def phasestr(self): |
|
718 | def phasestr(self): | |
720 | return self._changectx.phasestr() |
|
719 | return self._changectx.phasestr() | |
721 | def manifest(self): |
|
720 | def manifest(self): | |
722 | return self._changectx.manifest() |
|
721 | return self._changectx.manifest() | |
723 | def changectx(self): |
|
722 | def changectx(self): | |
724 | return self._changectx |
|
723 | return self._changectx | |
725 | def repo(self): |
|
724 | def repo(self): | |
726 | return self._repo |
|
725 | return self._repo | |
727 |
|
726 | |||
728 | def path(self): |
|
727 | def path(self): | |
729 | return self._path |
|
728 | return self._path | |
730 |
|
729 | |||
731 | def isbinary(self): |
|
730 | def isbinary(self): | |
732 | try: |
|
731 | try: | |
733 | return util.binary(self.data()) |
|
732 | return util.binary(self.data()) | |
734 | except IOError: |
|
733 | except IOError: | |
735 | return False |
|
734 | return False | |
736 | def isexec(self): |
|
735 | def isexec(self): | |
737 | return 'x' in self.flags() |
|
736 | return 'x' in self.flags() | |
738 | def islink(self): |
|
737 | def islink(self): | |
739 | return 'l' in self.flags() |
|
738 | return 'l' in self.flags() | |
740 |
|
739 | |||
741 | def cmp(self, fctx): |
|
740 | def cmp(self, fctx): | |
742 | """compare with other file context |
|
741 | """compare with other file context | |
743 |
|
742 | |||
744 | returns True if different than fctx. |
|
743 | returns True if different than fctx. | |
745 | """ |
|
744 | """ | |
746 | if (fctx._filerev is None |
|
745 | if (fctx._filerev is None | |
747 | and (self._repo._encodefilterpats |
|
746 | and (self._repo._encodefilterpats | |
748 | # if file data starts with '\1\n', empty metadata block is |
|
747 | # if file data starts with '\1\n', empty metadata block is | |
749 | # prepended, which adds 4 bytes to filelog.size(). |
|
748 | # prepended, which adds 4 bytes to filelog.size(). | |
750 | or self.size() - 4 == fctx.size()) |
|
749 | or self.size() - 4 == fctx.size()) | |
751 | or self.size() == fctx.size()): |
|
750 | or self.size() == fctx.size()): | |
752 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
751 | return self._filelog.cmp(self._filenode, fctx.data()) | |
753 |
|
752 | |||
754 | return True |
|
753 | return True | |
755 |
|
754 | |||
756 | def _adjustlinkrev(self, path, filelog, fnode, srcrev, inclusive=False): |
|
755 | def _adjustlinkrev(self, path, filelog, fnode, srcrev, inclusive=False): | |
757 | """return the first ancestor of <srcrev> introducing <fnode> |
|
756 | """return the first ancestor of <srcrev> introducing <fnode> | |
758 |
|
757 | |||
759 | 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 | |
760 | 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 | |
761 | this file revision. |
|
760 | this file revision. | |
762 |
|
761 | |||
763 | :repo: a localrepository object (used to access changelog and manifest) |
|
762 | :repo: a localrepository object (used to access changelog and manifest) | |
764 | :path: the file path |
|
763 | :path: the file path | |
765 | :fnode: the nodeid of the file revision |
|
764 | :fnode: the nodeid of the file revision | |
766 | :filelog: the filelog of this path |
|
765 | :filelog: the filelog of this path | |
767 | :srcrev: the changeset revision we search ancestors from |
|
766 | :srcrev: the changeset revision we search ancestors from | |
768 | :inclusive: if true, the src revision will also be checked |
|
767 | :inclusive: if true, the src revision will also be checked | |
769 | """ |
|
768 | """ | |
770 | repo = self._repo |
|
769 | repo = self._repo | |
771 | cl = repo.unfiltered().changelog |
|
770 | cl = repo.unfiltered().changelog | |
772 | ma = repo.manifest |
|
771 | ma = repo.manifest | |
773 | # fetch the linkrev |
|
772 | # fetch the linkrev | |
774 | fr = filelog.rev(fnode) |
|
773 | fr = filelog.rev(fnode) | |
775 | lkr = filelog.linkrev(fr) |
|
774 | lkr = filelog.linkrev(fr) | |
776 | # hack to reuse ancestor computation when searching for renames |
|
775 | # hack to reuse ancestor computation when searching for renames | |
777 | memberanc = getattr(self, '_ancestrycontext', None) |
|
776 | memberanc = getattr(self, '_ancestrycontext', None) | |
778 | iteranc = None |
|
777 | iteranc = None | |
779 | if memberanc is None: |
|
778 | if memberanc is None: | |
780 | memberanc = iteranc = cl.ancestors([srcrev], lkr, |
|
779 | memberanc = iteranc = cl.ancestors([srcrev], lkr, | |
781 | inclusive=inclusive) |
|
780 | inclusive=inclusive) | |
782 | # check if this linkrev is an ancestor of srcrev |
|
781 | # check if this linkrev is an ancestor of srcrev | |
783 | if lkr not in memberanc: |
|
782 | if lkr not in memberanc: | |
784 | if iteranc is None: |
|
783 | if iteranc is None: | |
785 | iteranc = cl.ancestors([srcrev], lkr, inclusive=inclusive) |
|
784 | iteranc = cl.ancestors([srcrev], lkr, inclusive=inclusive) | |
786 | for a in iteranc: |
|
785 | for a in iteranc: | |
787 | ac = cl.read(a) # get changeset data (we avoid object creation) |
|
786 | ac = cl.read(a) # get changeset data (we avoid object creation) | |
788 | if path in ac[3]: # checking the 'files' field. |
|
787 | if path in ac[3]: # checking the 'files' field. | |
789 | # The file has been touched, check if the content is |
|
788 | # The file has been touched, check if the content is | |
790 | # similar to the one we search for. |
|
789 | # similar to the one we search for. | |
791 | if fnode == ma.readfast(ac[0]).get(path): |
|
790 | if fnode == ma.readfast(ac[0]).get(path): | |
792 | return a |
|
791 | return a | |
793 | # In theory, we should never get out of that loop without a result. |
|
792 | # In theory, we should never get out of that loop without a result. | |
794 | # But if manifest uses a buggy file revision (not children of the |
|
793 | # But if manifest uses a buggy file revision (not children of the | |
795 | # one it replaces) we could. Such a buggy situation will likely |
|
794 | # one it replaces) we could. Such a buggy situation will likely | |
796 | # result is crash somewhere else at to some point. |
|
795 | # result is crash somewhere else at to some point. | |
797 | return lkr |
|
796 | return lkr | |
798 |
|
797 | |||
799 | def introrev(self): |
|
798 | def introrev(self): | |
800 | """return the rev of the changeset which introduced this file revision |
|
799 | """return the rev of the changeset which introduced this file revision | |
801 |
|
800 | |||
802 | This method is different from linkrev because it take into account the |
|
801 | This method is different from linkrev because it take into account the | |
803 | changeset the filectx was created from. It ensures the returned |
|
802 | changeset the filectx was created from. It ensures the returned | |
804 | revision is one of its ancestors. This prevents bugs from |
|
803 | revision is one of its ancestors. This prevents bugs from | |
805 | 'linkrev-shadowing' when a file revision is used by multiple |
|
804 | 'linkrev-shadowing' when a file revision is used by multiple | |
806 | changesets. |
|
805 | changesets. | |
807 | """ |
|
806 | """ | |
808 | lkr = self.linkrev() |
|
807 | lkr = self.linkrev() | |
809 | attrs = vars(self) |
|
808 | attrs = vars(self) | |
810 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) |
|
809 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) | |
811 | if noctx or self.rev() == lkr: |
|
810 | if noctx or self.rev() == lkr: | |
812 | return self.linkrev() |
|
811 | return self.linkrev() | |
813 | return self._adjustlinkrev(self._path, self._filelog, self._filenode, |
|
812 | return self._adjustlinkrev(self._path, self._filelog, self._filenode, | |
814 | self.rev(), inclusive=True) |
|
813 | self.rev(), inclusive=True) | |
815 |
|
814 | |||
816 | def parents(self): |
|
815 | def parents(self): | |
817 | _path = self._path |
|
816 | _path = self._path | |
818 | fl = self._filelog |
|
817 | fl = self._filelog | |
819 | parents = self._filelog.parents(self._filenode) |
|
818 | parents = self._filelog.parents(self._filenode) | |
820 | pl = [(_path, node, fl) for node in parents if node != nullid] |
|
819 | pl = [(_path, node, fl) for node in parents if node != nullid] | |
821 |
|
820 | |||
822 | r = fl.renamed(self._filenode) |
|
821 | r = fl.renamed(self._filenode) | |
823 | if r: |
|
822 | if r: | |
824 | # - In the simple rename case, both parent are nullid, pl is empty. |
|
823 | # - In the simple rename case, both parent are nullid, pl is empty. | |
825 | # - In case of merge, only one of the parent is null id and should |
|
824 | # - In case of merge, only one of the parent is null id and should | |
826 | # be replaced with the rename information. This parent is -always- |
|
825 | # be replaced with the rename information. This parent is -always- | |
827 | # the first one. |
|
826 | # the first one. | |
828 | # |
|
827 | # | |
829 | # As null id have always been filtered out in the previous list |
|
828 | # As null id have always been filtered out in the previous list | |
830 | # comprehension, inserting to 0 will always result in "replacing |
|
829 | # comprehension, inserting to 0 will always result in "replacing | |
831 | # first nullid parent with rename information. |
|
830 | # first nullid parent with rename information. | |
832 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) |
|
831 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) | |
833 |
|
832 | |||
834 | ret = [] |
|
833 | ret = [] | |
835 | for path, fnode, l in pl: |
|
834 | for path, fnode, l in pl: | |
836 | if '_changeid' in vars(self) or '_changectx' in vars(self): |
|
835 | if '_changeid' in vars(self) or '_changectx' in vars(self): | |
837 | # If self is associated with a changeset (probably explicitly |
|
836 | # If self is associated with a changeset (probably explicitly | |
838 | # fed), ensure the created filectx is associated with a |
|
837 | # fed), ensure the created filectx is associated with a | |
839 | # changeset that is an ancestor of self.changectx. |
|
838 | # changeset that is an ancestor of self.changectx. | |
840 | # This lets us later use _adjustlinkrev to get a correct link. |
|
839 | # This lets us later use _adjustlinkrev to get a correct link. | |
841 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
840 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
842 | fctx._descendantrev = self.rev() |
|
841 | fctx._descendantrev = self.rev() | |
843 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
842 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
844 | elif '_descendantrev' in vars(self): |
|
843 | elif '_descendantrev' in vars(self): | |
845 | # Otherwise propagate _descendantrev if we have one associated. |
|
844 | # Otherwise propagate _descendantrev if we have one associated. | |
846 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
845 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
847 | fctx._descendantrev = self._descendantrev |
|
846 | fctx._descendantrev = self._descendantrev | |
848 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
847 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
849 | else: |
|
848 | else: | |
850 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) |
|
849 | fctx = filectx(self._repo, path, fileid=fnode, filelog=l) | |
851 | ret.append(fctx) |
|
850 | ret.append(fctx) | |
852 | return ret |
|
851 | return ret | |
853 |
|
852 | |||
854 | def p1(self): |
|
853 | def p1(self): | |
855 | return self.parents()[0] |
|
854 | return self.parents()[0] | |
856 |
|
855 | |||
857 | def p2(self): |
|
856 | def p2(self): | |
858 | p = self.parents() |
|
857 | p = self.parents() | |
859 | if len(p) == 2: |
|
858 | if len(p) == 2: | |
860 | return p[1] |
|
859 | return p[1] | |
861 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
860 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) | |
862 |
|
861 | |||
863 | def annotate(self, follow=False, linenumber=None, diffopts=None): |
|
862 | def annotate(self, follow=False, linenumber=None, diffopts=None): | |
864 | '''returns a list of tuples of (ctx, line) for each line |
|
863 | '''returns a list of tuples of (ctx, line) for each line | |
865 | in the file, where ctx is the filectx of the node where |
|
864 | in the file, where ctx is the filectx of the node where | |
866 | that line was last changed. |
|
865 | that line was last changed. | |
867 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
866 | This returns tuples of ((ctx, linenumber), line) for each line, | |
868 | if "linenumber" parameter is NOT "None". |
|
867 | if "linenumber" parameter is NOT "None". | |
869 | In such tuples, linenumber means one at the first appearance |
|
868 | In such tuples, linenumber means one at the first appearance | |
870 | in the managed file. |
|
869 | in the managed file. | |
871 | To reduce annotation cost, |
|
870 | To reduce annotation cost, | |
872 | this returns fixed value(False is used) as linenumber, |
|
871 | this returns fixed value(False is used) as linenumber, | |
873 | if "linenumber" parameter is "False".''' |
|
872 | if "linenumber" parameter is "False".''' | |
874 |
|
873 | |||
875 | if linenumber is None: |
|
874 | if linenumber is None: | |
876 | def decorate(text, rev): |
|
875 | def decorate(text, rev): | |
877 | return ([rev] * len(text.splitlines()), text) |
|
876 | return ([rev] * len(text.splitlines()), text) | |
878 | elif linenumber: |
|
877 | elif linenumber: | |
879 | def decorate(text, rev): |
|
878 | def decorate(text, rev): | |
880 | size = len(text.splitlines()) |
|
879 | size = len(text.splitlines()) | |
881 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
880 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
882 | else: |
|
881 | else: | |
883 | def decorate(text, rev): |
|
882 | def decorate(text, rev): | |
884 | return ([(rev, False)] * len(text.splitlines()), text) |
|
883 | return ([(rev, False)] * len(text.splitlines()), text) | |
885 |
|
884 | |||
886 | def pair(parent, child): |
|
885 | def pair(parent, child): | |
887 | blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts, |
|
886 | blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts, | |
888 | refine=True) |
|
887 | refine=True) | |
889 | for (a1, a2, b1, b2), t in blocks: |
|
888 | for (a1, a2, b1, b2), t in blocks: | |
890 | # Changed blocks ('!') or blocks made only of blank lines ('~') |
|
889 | # Changed blocks ('!') or blocks made only of blank lines ('~') | |
891 | # belong to the child. |
|
890 | # belong to the child. | |
892 | if t == '=': |
|
891 | if t == '=': | |
893 | child[0][b1:b2] = parent[0][a1:a2] |
|
892 | child[0][b1:b2] = parent[0][a1:a2] | |
894 | return child |
|
893 | return child | |
895 |
|
894 | |||
896 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
895 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
897 |
|
896 | |||
898 | def parents(f): |
|
897 | def parents(f): | |
899 | pl = f.parents() |
|
898 | pl = f.parents() | |
900 |
|
899 | |||
901 | # Don't return renamed parents if we aren't following. |
|
900 | # Don't return renamed parents if we aren't following. | |
902 | if not follow: |
|
901 | if not follow: | |
903 | pl = [p for p in pl if p.path() == f.path()] |
|
902 | pl = [p for p in pl if p.path() == f.path()] | |
904 |
|
903 | |||
905 | # renamed filectx won't have a filelog yet, so set it |
|
904 | # renamed filectx won't have a filelog yet, so set it | |
906 | # from the cache to save time |
|
905 | # from the cache to save time | |
907 | for p in pl: |
|
906 | for p in pl: | |
908 | if not '_filelog' in p.__dict__: |
|
907 | if not '_filelog' in p.__dict__: | |
909 | p._filelog = getlog(p.path()) |
|
908 | p._filelog = getlog(p.path()) | |
910 |
|
909 | |||
911 | return pl |
|
910 | return pl | |
912 |
|
911 | |||
913 | # use linkrev to find the first changeset where self appeared |
|
912 | # use linkrev to find the first changeset where self appeared | |
914 | base = self |
|
913 | base = self | |
915 | introrev = self.introrev() |
|
914 | introrev = self.introrev() | |
916 | if self.rev() != introrev: |
|
915 | if self.rev() != introrev: | |
917 | base = self.filectx(self.filenode(), changeid=introrev) |
|
916 | base = self.filectx(self.filenode(), changeid=introrev) | |
918 |
|
917 | |||
919 | # This algorithm would prefer to be recursive, but Python is a |
|
918 | # This algorithm would prefer to be recursive, but Python is a | |
920 | # bit recursion-hostile. Instead we do an iterative |
|
919 | # bit recursion-hostile. Instead we do an iterative | |
921 | # depth-first search. |
|
920 | # depth-first search. | |
922 |
|
921 | |||
923 | visit = [base] |
|
922 | visit = [base] | |
924 | hist = {} |
|
923 | hist = {} | |
925 | pcache = {} |
|
924 | pcache = {} | |
926 | needed = {base: 1} |
|
925 | needed = {base: 1} | |
927 | while visit: |
|
926 | while visit: | |
928 | f = visit[-1] |
|
927 | f = visit[-1] | |
929 | pcached = f in pcache |
|
928 | pcached = f in pcache | |
930 | if not pcached: |
|
929 | if not pcached: | |
931 | pcache[f] = parents(f) |
|
930 | pcache[f] = parents(f) | |
932 |
|
931 | |||
933 | ready = True |
|
932 | ready = True | |
934 | pl = pcache[f] |
|
933 | pl = pcache[f] | |
935 | for p in pl: |
|
934 | for p in pl: | |
936 | if p not in hist: |
|
935 | if p not in hist: | |
937 | ready = False |
|
936 | ready = False | |
938 | visit.append(p) |
|
937 | visit.append(p) | |
939 | if not pcached: |
|
938 | if not pcached: | |
940 | needed[p] = needed.get(p, 0) + 1 |
|
939 | needed[p] = needed.get(p, 0) + 1 | |
941 | if ready: |
|
940 | if ready: | |
942 | visit.pop() |
|
941 | visit.pop() | |
943 | reusable = f in hist |
|
942 | reusable = f in hist | |
944 | if reusable: |
|
943 | if reusable: | |
945 | curr = hist[f] |
|
944 | curr = hist[f] | |
946 | else: |
|
945 | else: | |
947 | curr = decorate(f.data(), f) |
|
946 | curr = decorate(f.data(), f) | |
948 | for p in pl: |
|
947 | for p in pl: | |
949 | if not reusable: |
|
948 | if not reusable: | |
950 | curr = pair(hist[p], curr) |
|
949 | curr = pair(hist[p], curr) | |
951 | if needed[p] == 1: |
|
950 | if needed[p] == 1: | |
952 | del hist[p] |
|
951 | del hist[p] | |
953 | del needed[p] |
|
952 | del needed[p] | |
954 | else: |
|
953 | else: | |
955 | needed[p] -= 1 |
|
954 | needed[p] -= 1 | |
956 |
|
955 | |||
957 | hist[f] = curr |
|
956 | hist[f] = curr | |
958 | pcache[f] = [] |
|
957 | pcache[f] = [] | |
959 |
|
958 | |||
960 | return zip(hist[base][0], hist[base][1].splitlines(True)) |
|
959 | return zip(hist[base][0], hist[base][1].splitlines(True)) | |
961 |
|
960 | |||
962 | def ancestors(self, followfirst=False): |
|
961 | def ancestors(self, followfirst=False): | |
963 | visit = {} |
|
962 | visit = {} | |
964 | c = self |
|
963 | c = self | |
965 | if followfirst: |
|
964 | if followfirst: | |
966 | cut = 1 |
|
965 | cut = 1 | |
967 | else: |
|
966 | else: | |
968 | cut = None |
|
967 | cut = None | |
969 |
|
968 | |||
970 | while True: |
|
969 | while True: | |
971 | for parent in c.parents()[:cut]: |
|
970 | for parent in c.parents()[:cut]: | |
972 | visit[(parent.linkrev(), parent.filenode())] = parent |
|
971 | visit[(parent.linkrev(), parent.filenode())] = parent | |
973 | if not visit: |
|
972 | if not visit: | |
974 | break |
|
973 | break | |
975 | c = visit.pop(max(visit)) |
|
974 | c = visit.pop(max(visit)) | |
976 | yield c |
|
975 | yield c | |
977 |
|
976 | |||
978 | class filectx(basefilectx): |
|
977 | class filectx(basefilectx): | |
979 | """A filecontext object makes access to data related to a particular |
|
978 | """A filecontext object makes access to data related to a particular | |
980 | filerevision convenient.""" |
|
979 | filerevision convenient.""" | |
981 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
980 | def __init__(self, repo, path, changeid=None, fileid=None, | |
982 | filelog=None, changectx=None): |
|
981 | filelog=None, changectx=None): | |
983 | """changeid can be a changeset revision, node, or tag. |
|
982 | """changeid can be a changeset revision, node, or tag. | |
984 | fileid can be a file revision or node.""" |
|
983 | fileid can be a file revision or node.""" | |
985 | self._repo = repo |
|
984 | self._repo = repo | |
986 | self._path = path |
|
985 | self._path = path | |
987 |
|
986 | |||
988 | assert (changeid is not None |
|
987 | assert (changeid is not None | |
989 | or fileid is not None |
|
988 | or fileid is not None | |
990 | or changectx is not None), \ |
|
989 | or changectx is not None), \ | |
991 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
990 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
992 | % (changeid, fileid, changectx)) |
|
991 | % (changeid, fileid, changectx)) | |
993 |
|
992 | |||
994 | if filelog is not None: |
|
993 | if filelog is not None: | |
995 | self._filelog = filelog |
|
994 | self._filelog = filelog | |
996 |
|
995 | |||
997 | if changeid is not None: |
|
996 | if changeid is not None: | |
998 | self._changeid = changeid |
|
997 | self._changeid = changeid | |
999 | if changectx is not None: |
|
998 | if changectx is not None: | |
1000 | self._changectx = changectx |
|
999 | self._changectx = changectx | |
1001 | if fileid is not None: |
|
1000 | if fileid is not None: | |
1002 | self._fileid = fileid |
|
1001 | self._fileid = fileid | |
1003 |
|
1002 | |||
1004 | @propertycache |
|
1003 | @propertycache | |
1005 | def _changectx(self): |
|
1004 | def _changectx(self): | |
1006 | try: |
|
1005 | try: | |
1007 | return changectx(self._repo, self._changeid) |
|
1006 | return changectx(self._repo, self._changeid) | |
1008 | except error.FilteredRepoLookupError: |
|
1007 | except error.FilteredRepoLookupError: | |
1009 | # Linkrev may point to any revision in the repository. When the |
|
1008 | # Linkrev may point to any revision in the repository. When the | |
1010 | # repository is filtered this may lead to `filectx` trying to build |
|
1009 | # repository is filtered this may lead to `filectx` trying to build | |
1011 | # `changectx` for filtered revision. In such case we fallback to |
|
1010 | # `changectx` for filtered revision. In such case we fallback to | |
1012 | # creating `changectx` on the unfiltered version of the reposition. |
|
1011 | # creating `changectx` on the unfiltered version of the reposition. | |
1013 | # This fallback should not be an issue because `changectx` from |
|
1012 | # This fallback should not be an issue because `changectx` from | |
1014 | # `filectx` are not used in complex operations that care about |
|
1013 | # `filectx` are not used in complex operations that care about | |
1015 | # filtering. |
|
1014 | # filtering. | |
1016 | # |
|
1015 | # | |
1017 | # This fallback is a cheap and dirty fix that prevent several |
|
1016 | # This fallback is a cheap and dirty fix that prevent several | |
1018 | # crashes. It does not ensure the behavior is correct. However the |
|
1017 | # crashes. It does not ensure the behavior is correct. However the | |
1019 | # behavior was not correct before filtering either and "incorrect |
|
1018 | # behavior was not correct before filtering either and "incorrect | |
1020 | # behavior" is seen as better as "crash" |
|
1019 | # behavior" is seen as better as "crash" | |
1021 | # |
|
1020 | # | |
1022 | # Linkrevs have several serious troubles with filtering that are |
|
1021 | # Linkrevs have several serious troubles with filtering that are | |
1023 | # complicated to solve. Proper handling of the issue here should be |
|
1022 | # complicated to solve. Proper handling of the issue here should be | |
1024 | # considered when solving linkrev issue are on the table. |
|
1023 | # considered when solving linkrev issue are on the table. | |
1025 | return changectx(self._repo.unfiltered(), self._changeid) |
|
1024 | return changectx(self._repo.unfiltered(), self._changeid) | |
1026 |
|
1025 | |||
1027 | def filectx(self, fileid, changeid=None): |
|
1026 | def filectx(self, fileid, changeid=None): | |
1028 | '''opens an arbitrary revision of the file without |
|
1027 | '''opens an arbitrary revision of the file without | |
1029 | opening a new filelog''' |
|
1028 | opening a new filelog''' | |
1030 | return filectx(self._repo, self._path, fileid=fileid, |
|
1029 | return filectx(self._repo, self._path, fileid=fileid, | |
1031 | filelog=self._filelog, changeid=changeid) |
|
1030 | filelog=self._filelog, changeid=changeid) | |
1032 |
|
1031 | |||
1033 | def data(self): |
|
1032 | def data(self): | |
1034 | try: |
|
1033 | try: | |
1035 | return self._filelog.read(self._filenode) |
|
1034 | return self._filelog.read(self._filenode) | |
1036 | except error.CensoredNodeError: |
|
1035 | except error.CensoredNodeError: | |
1037 | if self._repo.ui.config("censor", "policy", "abort") == "ignore": |
|
1036 | if self._repo.ui.config("censor", "policy", "abort") == "ignore": | |
1038 | return "" |
|
1037 | return "" | |
1039 | raise util.Abort(_("censored node: %s") % short(self._filenode), |
|
1038 | raise util.Abort(_("censored node: %s") % short(self._filenode), | |
1040 | hint=_("set censor.policy to ignore errors")) |
|
1039 | hint=_("set censor.policy to ignore errors")) | |
1041 |
|
1040 | |||
1042 | def size(self): |
|
1041 | def size(self): | |
1043 | return self._filelog.size(self._filerev) |
|
1042 | return self._filelog.size(self._filerev) | |
1044 |
|
1043 | |||
1045 | def renamed(self): |
|
1044 | def renamed(self): | |
1046 | """check if file was actually renamed in this changeset revision |
|
1045 | """check if file was actually renamed in this changeset revision | |
1047 |
|
1046 | |||
1048 | If rename logged in file revision, we report copy for changeset only |
|
1047 | If rename logged in file revision, we report copy for changeset only | |
1049 | if file revisions linkrev points back to the changeset in question |
|
1048 | if file revisions linkrev points back to the changeset in question | |
1050 | or both changeset parents contain different file revisions. |
|
1049 | or both changeset parents contain different file revisions. | |
1051 | """ |
|
1050 | """ | |
1052 |
|
1051 | |||
1053 | renamed = self._filelog.renamed(self._filenode) |
|
1052 | renamed = self._filelog.renamed(self._filenode) | |
1054 | if not renamed: |
|
1053 | if not renamed: | |
1055 | return renamed |
|
1054 | return renamed | |
1056 |
|
1055 | |||
1057 | if self.rev() == self.linkrev(): |
|
1056 | if self.rev() == self.linkrev(): | |
1058 | return renamed |
|
1057 | return renamed | |
1059 |
|
1058 | |||
1060 | name = self.path() |
|
1059 | name = self.path() | |
1061 | fnode = self._filenode |
|
1060 | fnode = self._filenode | |
1062 | for p in self._changectx.parents(): |
|
1061 | for p in self._changectx.parents(): | |
1063 | try: |
|
1062 | try: | |
1064 | if fnode == p.filenode(name): |
|
1063 | if fnode == p.filenode(name): | |
1065 | return None |
|
1064 | return None | |
1066 | except error.LookupError: |
|
1065 | except error.LookupError: | |
1067 | pass |
|
1066 | pass | |
1068 | return renamed |
|
1067 | return renamed | |
1069 |
|
1068 | |||
1070 | def children(self): |
|
1069 | def children(self): | |
1071 | # hard for renames |
|
1070 | # hard for renames | |
1072 | c = self._filelog.children(self._filenode) |
|
1071 | c = self._filelog.children(self._filenode) | |
1073 | return [filectx(self._repo, self._path, fileid=x, |
|
1072 | return [filectx(self._repo, self._path, fileid=x, | |
1074 | filelog=self._filelog) for x in c] |
|
1073 | filelog=self._filelog) for x in c] | |
1075 |
|
1074 | |||
1076 | class committablectx(basectx): |
|
1075 | class committablectx(basectx): | |
1077 | """A committablectx object provides common functionality for a context that |
|
1076 | """A committablectx object provides common functionality for a context that | |
1078 | wants the ability to commit, e.g. workingctx or memctx.""" |
|
1077 | wants the ability to commit, e.g. workingctx or memctx.""" | |
1079 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1078 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1080 | changes=None): |
|
1079 | changes=None): | |
1081 | self._repo = repo |
|
1080 | self._repo = repo | |
1082 | self._rev = None |
|
1081 | self._rev = None | |
1083 | self._node = None |
|
1082 | self._node = None | |
1084 | self._text = text |
|
1083 | self._text = text | |
1085 | if date: |
|
1084 | if date: | |
1086 | self._date = util.parsedate(date) |
|
1085 | self._date = util.parsedate(date) | |
1087 | if user: |
|
1086 | if user: | |
1088 | self._user = user |
|
1087 | self._user = user | |
1089 | if changes: |
|
1088 | if changes: | |
1090 | self._status = changes |
|
1089 | self._status = changes | |
1091 |
|
1090 | |||
1092 | self._extra = {} |
|
1091 | self._extra = {} | |
1093 | if extra: |
|
1092 | if extra: | |
1094 | self._extra = extra.copy() |
|
1093 | self._extra = extra.copy() | |
1095 | if 'branch' not in self._extra: |
|
1094 | if 'branch' not in self._extra: | |
1096 | try: |
|
1095 | try: | |
1097 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
1096 | branch = encoding.fromlocal(self._repo.dirstate.branch()) | |
1098 | except UnicodeDecodeError: |
|
1097 | except UnicodeDecodeError: | |
1099 | raise util.Abort(_('branch name not in UTF-8!')) |
|
1098 | raise util.Abort(_('branch name not in UTF-8!')) | |
1100 | self._extra['branch'] = branch |
|
1099 | self._extra['branch'] = branch | |
1101 | if self._extra['branch'] == '': |
|
1100 | if self._extra['branch'] == '': | |
1102 | self._extra['branch'] = 'default' |
|
1101 | self._extra['branch'] = 'default' | |
1103 |
|
1102 | |||
1104 | def __str__(self): |
|
1103 | def __str__(self): | |
1105 | return str(self._parents[0]) + "+" |
|
1104 | return str(self._parents[0]) + "+" | |
1106 |
|
1105 | |||
1107 | def __nonzero__(self): |
|
1106 | def __nonzero__(self): | |
1108 | return True |
|
1107 | return True | |
1109 |
|
1108 | |||
1110 | def _buildflagfunc(self): |
|
1109 | def _buildflagfunc(self): | |
1111 | # Create a fallback function for getting file flags when the |
|
1110 | # Create a fallback function for getting file flags when the | |
1112 | # filesystem doesn't support them |
|
1111 | # filesystem doesn't support them | |
1113 |
|
1112 | |||
1114 | copiesget = self._repo.dirstate.copies().get |
|
1113 | copiesget = self._repo.dirstate.copies().get | |
1115 |
|
1114 | |||
1116 | if len(self._parents) < 2: |
|
1115 | if len(self._parents) < 2: | |
1117 | # when we have one parent, it's easy: copy from parent |
|
1116 | # when we have one parent, it's easy: copy from parent | |
1118 | man = self._parents[0].manifest() |
|
1117 | man = self._parents[0].manifest() | |
1119 | def func(f): |
|
1118 | def func(f): | |
1120 | f = copiesget(f, f) |
|
1119 | f = copiesget(f, f) | |
1121 | return man.flags(f) |
|
1120 | return man.flags(f) | |
1122 | else: |
|
1121 | else: | |
1123 | # merges are tricky: we try to reconstruct the unstored |
|
1122 | # merges are tricky: we try to reconstruct the unstored | |
1124 | # result from the merge (issue1802) |
|
1123 | # result from the merge (issue1802) | |
1125 | p1, p2 = self._parents |
|
1124 | p1, p2 = self._parents | |
1126 | pa = p1.ancestor(p2) |
|
1125 | pa = p1.ancestor(p2) | |
1127 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
1126 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1128 |
|
1127 | |||
1129 | def func(f): |
|
1128 | def func(f): | |
1130 | f = copiesget(f, f) # may be wrong for merges with copies |
|
1129 | f = copiesget(f, f) # may be wrong for merges with copies | |
1131 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
1130 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1132 | if fl1 == fl2: |
|
1131 | if fl1 == fl2: | |
1133 | return fl1 |
|
1132 | return fl1 | |
1134 | if fl1 == fla: |
|
1133 | if fl1 == fla: | |
1135 | return fl2 |
|
1134 | return fl2 | |
1136 | if fl2 == fla: |
|
1135 | if fl2 == fla: | |
1137 | return fl1 |
|
1136 | return fl1 | |
1138 | return '' # punt for conflicts |
|
1137 | return '' # punt for conflicts | |
1139 |
|
1138 | |||
1140 | return func |
|
1139 | return func | |
1141 |
|
1140 | |||
1142 | @propertycache |
|
1141 | @propertycache | |
1143 | def _flagfunc(self): |
|
1142 | def _flagfunc(self): | |
1144 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
1143 | return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1145 |
|
1144 | |||
1146 | @propertycache |
|
1145 | @propertycache | |
1147 | def _manifest(self): |
|
1146 | def _manifest(self): | |
1148 | """generate a manifest corresponding to the values in self._status |
|
1147 | """generate a manifest corresponding to the values in self._status | |
1149 |
|
1148 | |||
1150 | This reuse the file nodeid from parent, but we append an extra letter |
|
1149 | This reuse the file nodeid from parent, but we append an extra letter | |
1151 | when modified. Modified files get an extra 'm' while added files get |
|
1150 | when modified. Modified files get an extra 'm' while added files get | |
1152 | an extra 'a'. This is used by manifests merge to see that files |
|
1151 | an extra 'a'. This is used by manifests merge to see that files | |
1153 | are different and by update logic to avoid deleting newly added files. |
|
1152 | are different and by update logic to avoid deleting newly added files. | |
1154 | """ |
|
1153 | """ | |
1155 |
|
1154 | |||
1156 | man1 = self._parents[0].manifest() |
|
1155 | man1 = self._parents[0].manifest() | |
1157 | man = man1.copy() |
|
1156 | man = man1.copy() | |
1158 | if len(self._parents) > 1: |
|
1157 | if len(self._parents) > 1: | |
1159 | man2 = self.p2().manifest() |
|
1158 | man2 = self.p2().manifest() | |
1160 | def getman(f): |
|
1159 | def getman(f): | |
1161 | if f in man1: |
|
1160 | if f in man1: | |
1162 | return man1 |
|
1161 | return man1 | |
1163 | return man2 |
|
1162 | return man2 | |
1164 | else: |
|
1163 | else: | |
1165 | getman = lambda f: man1 |
|
1164 | getman = lambda f: man1 | |
1166 |
|
1165 | |||
1167 | copied = self._repo.dirstate.copies() |
|
1166 | copied = self._repo.dirstate.copies() | |
1168 | ff = self._flagfunc |
|
1167 | ff = self._flagfunc | |
1169 | for i, l in (("a", self._status.added), ("m", self._status.modified)): |
|
1168 | for i, l in (("a", self._status.added), ("m", self._status.modified)): | |
1170 | for f in l: |
|
1169 | for f in l: | |
1171 | orig = copied.get(f, f) |
|
1170 | orig = copied.get(f, f) | |
1172 | man[f] = getman(orig).get(orig, nullid) + i |
|
1171 | man[f] = getman(orig).get(orig, nullid) + i | |
1173 | try: |
|
1172 | try: | |
1174 | man.setflag(f, ff(f)) |
|
1173 | man.setflag(f, ff(f)) | |
1175 | except OSError: |
|
1174 | except OSError: | |
1176 | pass |
|
1175 | pass | |
1177 |
|
1176 | |||
1178 | for f in self._status.deleted + self._status.removed: |
|
1177 | for f in self._status.deleted + self._status.removed: | |
1179 | if f in man: |
|
1178 | if f in man: | |
1180 | del man[f] |
|
1179 | del man[f] | |
1181 |
|
1180 | |||
1182 | return man |
|
1181 | return man | |
1183 |
|
1182 | |||
1184 | @propertycache |
|
1183 | @propertycache | |
1185 | def _status(self): |
|
1184 | def _status(self): | |
1186 | return self._repo.status() |
|
1185 | return self._repo.status() | |
1187 |
|
1186 | |||
1188 | @propertycache |
|
1187 | @propertycache | |
1189 | def _user(self): |
|
1188 | def _user(self): | |
1190 | return self._repo.ui.username() |
|
1189 | return self._repo.ui.username() | |
1191 |
|
1190 | |||
1192 | @propertycache |
|
1191 | @propertycache | |
1193 | def _date(self): |
|
1192 | def _date(self): | |
1194 | return util.makedate() |
|
1193 | return util.makedate() | |
1195 |
|
1194 | |||
1196 | def subrev(self, subpath): |
|
1195 | def subrev(self, subpath): | |
1197 | return None |
|
1196 | return None | |
1198 |
|
1197 | |||
1199 | def user(self): |
|
1198 | def user(self): | |
1200 | return self._user or self._repo.ui.username() |
|
1199 | return self._user or self._repo.ui.username() | |
1201 | def date(self): |
|
1200 | def date(self): | |
1202 | return self._date |
|
1201 | return self._date | |
1203 | def description(self): |
|
1202 | def description(self): | |
1204 | return self._text |
|
1203 | return self._text | |
1205 | def files(self): |
|
1204 | def files(self): | |
1206 | return sorted(self._status.modified + self._status.added + |
|
1205 | return sorted(self._status.modified + self._status.added + | |
1207 | self._status.removed) |
|
1206 | self._status.removed) | |
1208 |
|
1207 | |||
1209 | def modified(self): |
|
1208 | def modified(self): | |
1210 | return self._status.modified |
|
1209 | return self._status.modified | |
1211 | def added(self): |
|
1210 | def added(self): | |
1212 | return self._status.added |
|
1211 | return self._status.added | |
1213 | def removed(self): |
|
1212 | def removed(self): | |
1214 | return self._status.removed |
|
1213 | return self._status.removed | |
1215 | def deleted(self): |
|
1214 | def deleted(self): | |
1216 | return self._status.deleted |
|
1215 | return self._status.deleted | |
1217 | def branch(self): |
|
1216 | def branch(self): | |
1218 | return encoding.tolocal(self._extra['branch']) |
|
1217 | return encoding.tolocal(self._extra['branch']) | |
1219 | def closesbranch(self): |
|
1218 | def closesbranch(self): | |
1220 | return 'close' in self._extra |
|
1219 | return 'close' in self._extra | |
1221 | def extra(self): |
|
1220 | def extra(self): | |
1222 | return self._extra |
|
1221 | return self._extra | |
1223 |
|
1222 | |||
1224 | def tags(self): |
|
1223 | def tags(self): | |
1225 | t = [] |
|
1224 | t = [] | |
1226 | for p in self.parents(): |
|
1225 | for p in self.parents(): | |
1227 | t.extend(p.tags()) |
|
1226 | t.extend(p.tags()) | |
1228 | return t |
|
1227 | return t | |
1229 |
|
1228 | |||
1230 | def bookmarks(self): |
|
1229 | def bookmarks(self): | |
1231 | b = [] |
|
1230 | b = [] | |
1232 | for p in self.parents(): |
|
1231 | for p in self.parents(): | |
1233 | b.extend(p.bookmarks()) |
|
1232 | b.extend(p.bookmarks()) | |
1234 | return b |
|
1233 | return b | |
1235 |
|
1234 | |||
1236 | def phase(self): |
|
1235 | def phase(self): | |
1237 | phase = phases.draft # default phase to draft |
|
1236 | phase = phases.draft # default phase to draft | |
1238 | for p in self.parents(): |
|
1237 | for p in self.parents(): | |
1239 | phase = max(phase, p.phase()) |
|
1238 | phase = max(phase, p.phase()) | |
1240 | return phase |
|
1239 | return phase | |
1241 |
|
1240 | |||
1242 | def hidden(self): |
|
1241 | def hidden(self): | |
1243 | return False |
|
1242 | return False | |
1244 |
|
1243 | |||
1245 | def children(self): |
|
1244 | def children(self): | |
1246 | return [] |
|
1245 | return [] | |
1247 |
|
1246 | |||
1248 | def flags(self, path): |
|
1247 | def flags(self, path): | |
1249 | if '_manifest' in self.__dict__: |
|
1248 | if '_manifest' in self.__dict__: | |
1250 | try: |
|
1249 | try: | |
1251 | return self._manifest.flags(path) |
|
1250 | return self._manifest.flags(path) | |
1252 | except KeyError: |
|
1251 | except KeyError: | |
1253 | return '' |
|
1252 | return '' | |
1254 |
|
1253 | |||
1255 | try: |
|
1254 | try: | |
1256 | return self._flagfunc(path) |
|
1255 | return self._flagfunc(path) | |
1257 | except OSError: |
|
1256 | except OSError: | |
1258 | return '' |
|
1257 | return '' | |
1259 |
|
1258 | |||
1260 | def ancestor(self, c2): |
|
1259 | def ancestor(self, c2): | |
1261 | """return the "best" ancestor context of self and c2""" |
|
1260 | """return the "best" ancestor context of self and c2""" | |
1262 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
1261 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
1263 |
|
1262 | |||
1264 | def walk(self, match): |
|
1263 | def walk(self, match): | |
1265 | return sorted(self._repo.dirstate.walk(match, sorted(self.substate), |
|
1264 | return sorted(self._repo.dirstate.walk(match, sorted(self.substate), | |
1266 | True, False)) |
|
1265 | True, False)) | |
1267 |
|
1266 | |||
1268 | def matches(self, match): |
|
1267 | def matches(self, match): | |
1269 | return sorted(self._repo.dirstate.matches(match)) |
|
1268 | return sorted(self._repo.dirstate.matches(match)) | |
1270 |
|
1269 | |||
1271 | def ancestors(self): |
|
1270 | def ancestors(self): | |
1272 | for p in self._parents: |
|
1271 | for p in self._parents: | |
1273 | yield p |
|
1272 | yield p | |
1274 | for a in self._repo.changelog.ancestors( |
|
1273 | for a in self._repo.changelog.ancestors( | |
1275 | [p.rev() for p in self._parents]): |
|
1274 | [p.rev() for p in self._parents]): | |
1276 | yield changectx(self._repo, a) |
|
1275 | yield changectx(self._repo, a) | |
1277 |
|
1276 | |||
1278 | def markcommitted(self, node): |
|
1277 | def markcommitted(self, node): | |
1279 | """Perform post-commit cleanup necessary after committing this ctx |
|
1278 | """Perform post-commit cleanup necessary after committing this ctx | |
1280 |
|
1279 | |||
1281 | Specifically, this updates backing stores this working context |
|
1280 | Specifically, this updates backing stores this working context | |
1282 | wraps to reflect the fact that the changes reflected by this |
|
1281 | wraps to reflect the fact that the changes reflected by this | |
1283 | workingctx have been committed. For example, it marks |
|
1282 | workingctx have been committed. For example, it marks | |
1284 | modified and added files as normal in the dirstate. |
|
1283 | modified and added files as normal in the dirstate. | |
1285 |
|
1284 | |||
1286 | """ |
|
1285 | """ | |
1287 |
|
1286 | |||
1288 | self._repo.dirstate.beginparentchange() |
|
1287 | self._repo.dirstate.beginparentchange() | |
1289 | for f in self.modified() + self.added(): |
|
1288 | for f in self.modified() + self.added(): | |
1290 | self._repo.dirstate.normal(f) |
|
1289 | self._repo.dirstate.normal(f) | |
1291 | for f in self.removed(): |
|
1290 | for f in self.removed(): | |
1292 | self._repo.dirstate.drop(f) |
|
1291 | self._repo.dirstate.drop(f) | |
1293 | self._repo.dirstate.setparents(node) |
|
1292 | self._repo.dirstate.setparents(node) | |
1294 | self._repo.dirstate.endparentchange() |
|
1293 | self._repo.dirstate.endparentchange() | |
1295 |
|
1294 | |||
1296 | class workingctx(committablectx): |
|
1295 | class workingctx(committablectx): | |
1297 | """A workingctx object makes access to data related to |
|
1296 | """A workingctx object makes access to data related to | |
1298 | the current working directory convenient. |
|
1297 | the current working directory convenient. | |
1299 | date - any valid date string or (unixtime, offset), or None. |
|
1298 | date - any valid date string or (unixtime, offset), or None. | |
1300 | user - username string, or None. |
|
1299 | user - username string, or None. | |
1301 | extra - a dictionary of extra values, or None. |
|
1300 | extra - a dictionary of extra values, or None. | |
1302 | changes - a list of file lists as returned by localrepo.status() |
|
1301 | changes - a list of file lists as returned by localrepo.status() | |
1303 | or None to use the repository status. |
|
1302 | or None to use the repository status. | |
1304 | """ |
|
1303 | """ | |
1305 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1304 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1306 | changes=None): |
|
1305 | changes=None): | |
1307 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
|
1306 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) | |
1308 |
|
1307 | |||
1309 | def __iter__(self): |
|
1308 | def __iter__(self): | |
1310 | d = self._repo.dirstate |
|
1309 | d = self._repo.dirstate | |
1311 | for f in d: |
|
1310 | for f in d: | |
1312 | if d[f] != 'r': |
|
1311 | if d[f] != 'r': | |
1313 | yield f |
|
1312 | yield f | |
1314 |
|
1313 | |||
1315 | def __contains__(self, key): |
|
1314 | def __contains__(self, key): | |
1316 | return self._repo.dirstate[key] not in "?r" |
|
1315 | return self._repo.dirstate[key] not in "?r" | |
1317 |
|
1316 | |||
1318 | @propertycache |
|
1317 | @propertycache | |
1319 | def _parents(self): |
|
1318 | def _parents(self): | |
1320 | p = self._repo.dirstate.parents() |
|
1319 | p = self._repo.dirstate.parents() | |
1321 | if p[1] == nullid: |
|
1320 | if p[1] == nullid: | |
1322 | p = p[:-1] |
|
1321 | p = p[:-1] | |
1323 | return [changectx(self._repo, x) for x in p] |
|
1322 | return [changectx(self._repo, x) for x in p] | |
1324 |
|
1323 | |||
1325 | def filectx(self, path, filelog=None): |
|
1324 | def filectx(self, path, filelog=None): | |
1326 | """get a file context from the working directory""" |
|
1325 | """get a file context from the working directory""" | |
1327 | return workingfilectx(self._repo, path, workingctx=self, |
|
1326 | return workingfilectx(self._repo, path, workingctx=self, | |
1328 | filelog=filelog) |
|
1327 | filelog=filelog) | |
1329 |
|
1328 | |||
1330 | def dirty(self, missing=False, merge=True, branch=True): |
|
1329 | def dirty(self, missing=False, merge=True, branch=True): | |
1331 | "check whether a working directory is modified" |
|
1330 | "check whether a working directory is modified" | |
1332 | # check subrepos first |
|
1331 | # check subrepos first | |
1333 | for s in sorted(self.substate): |
|
1332 | for s in sorted(self.substate): | |
1334 | if self.sub(s).dirty(): |
|
1333 | if self.sub(s).dirty(): | |
1335 | return True |
|
1334 | return True | |
1336 | # check current working dir |
|
1335 | # check current working dir | |
1337 | return ((merge and self.p2()) or |
|
1336 | return ((merge and self.p2()) or | |
1338 | (branch and self.branch() != self.p1().branch()) or |
|
1337 | (branch and self.branch() != self.p1().branch()) or | |
1339 | self.modified() or self.added() or self.removed() or |
|
1338 | self.modified() or self.added() or self.removed() or | |
1340 | (missing and self.deleted())) |
|
1339 | (missing and self.deleted())) | |
1341 |
|
1340 | |||
1342 | def add(self, list, prefix=""): |
|
1341 | def add(self, list, prefix=""): | |
1343 | join = lambda f: os.path.join(prefix, f) |
|
1342 | join = lambda f: os.path.join(prefix, f) | |
1344 | wlock = self._repo.wlock() |
|
1343 | wlock = self._repo.wlock() | |
1345 | ui, ds = self._repo.ui, self._repo.dirstate |
|
1344 | ui, ds = self._repo.ui, self._repo.dirstate | |
1346 | try: |
|
1345 | try: | |
1347 | rejected = [] |
|
1346 | rejected = [] | |
1348 | lstat = self._repo.wvfs.lstat |
|
1347 | lstat = self._repo.wvfs.lstat | |
1349 | for f in list: |
|
1348 | for f in list: | |
1350 | scmutil.checkportable(ui, join(f)) |
|
1349 | scmutil.checkportable(ui, join(f)) | |
1351 | try: |
|
1350 | try: | |
1352 | st = lstat(f) |
|
1351 | st = lstat(f) | |
1353 | except OSError: |
|
1352 | except OSError: | |
1354 | ui.warn(_("%s does not exist!\n") % join(f)) |
|
1353 | ui.warn(_("%s does not exist!\n") % join(f)) | |
1355 | rejected.append(f) |
|
1354 | rejected.append(f) | |
1356 | continue |
|
1355 | continue | |
1357 | if st.st_size > 10000000: |
|
1356 | if st.st_size > 10000000: | |
1358 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1357 | ui.warn(_("%s: up to %d MB of RAM may be required " | |
1359 | "to manage this file\n" |
|
1358 | "to manage this file\n" | |
1360 | "(use 'hg revert %s' to cancel the " |
|
1359 | "(use 'hg revert %s' to cancel the " | |
1361 | "pending addition)\n") |
|
1360 | "pending addition)\n") | |
1362 | % (f, 3 * st.st_size // 1000000, join(f))) |
|
1361 | % (f, 3 * st.st_size // 1000000, join(f))) | |
1363 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1362 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1364 | ui.warn(_("%s not added: only files and symlinks " |
|
1363 | ui.warn(_("%s not added: only files and symlinks " | |
1365 | "supported currently\n") % join(f)) |
|
1364 | "supported currently\n") % join(f)) | |
1366 | rejected.append(f) |
|
1365 | rejected.append(f) | |
1367 | elif ds[f] in 'amn': |
|
1366 | elif ds[f] in 'amn': | |
1368 | ui.warn(_("%s already tracked!\n") % join(f)) |
|
1367 | ui.warn(_("%s already tracked!\n") % join(f)) | |
1369 | elif ds[f] == 'r': |
|
1368 | elif ds[f] == 'r': | |
1370 | ds.normallookup(f) |
|
1369 | ds.normallookup(f) | |
1371 | else: |
|
1370 | else: | |
1372 | ds.add(f) |
|
1371 | ds.add(f) | |
1373 | return rejected |
|
1372 | return rejected | |
1374 | finally: |
|
1373 | finally: | |
1375 | wlock.release() |
|
1374 | wlock.release() | |
1376 |
|
1375 | |||
1377 | def forget(self, files, prefix=""): |
|
1376 | def forget(self, files, prefix=""): | |
1378 | join = lambda f: os.path.join(prefix, f) |
|
1377 | join = lambda f: os.path.join(prefix, f) | |
1379 | wlock = self._repo.wlock() |
|
1378 | wlock = self._repo.wlock() | |
1380 | try: |
|
1379 | try: | |
1381 | rejected = [] |
|
1380 | rejected = [] | |
1382 | for f in files: |
|
1381 | for f in files: | |
1383 | if f not in self._repo.dirstate: |
|
1382 | if f not in self._repo.dirstate: | |
1384 | self._repo.ui.warn(_("%s not tracked!\n") % join(f)) |
|
1383 | self._repo.ui.warn(_("%s not tracked!\n") % join(f)) | |
1385 | rejected.append(f) |
|
1384 | rejected.append(f) | |
1386 | elif self._repo.dirstate[f] != 'a': |
|
1385 | elif self._repo.dirstate[f] != 'a': | |
1387 | self._repo.dirstate.remove(f) |
|
1386 | self._repo.dirstate.remove(f) | |
1388 | else: |
|
1387 | else: | |
1389 | self._repo.dirstate.drop(f) |
|
1388 | self._repo.dirstate.drop(f) | |
1390 | return rejected |
|
1389 | return rejected | |
1391 | finally: |
|
1390 | finally: | |
1392 | wlock.release() |
|
1391 | wlock.release() | |
1393 |
|
1392 | |||
1394 | def undelete(self, list): |
|
1393 | def undelete(self, list): | |
1395 | pctxs = self.parents() |
|
1394 | pctxs = self.parents() | |
1396 | wlock = self._repo.wlock() |
|
1395 | wlock = self._repo.wlock() | |
1397 | try: |
|
1396 | try: | |
1398 | for f in list: |
|
1397 | for f in list: | |
1399 | if self._repo.dirstate[f] != 'r': |
|
1398 | if self._repo.dirstate[f] != 'r': | |
1400 | self._repo.ui.warn(_("%s not removed!\n") % f) |
|
1399 | self._repo.ui.warn(_("%s not removed!\n") % f) | |
1401 | else: |
|
1400 | else: | |
1402 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
1401 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] | |
1403 | t = fctx.data() |
|
1402 | t = fctx.data() | |
1404 | self._repo.wwrite(f, t, fctx.flags()) |
|
1403 | self._repo.wwrite(f, t, fctx.flags()) | |
1405 | self._repo.dirstate.normal(f) |
|
1404 | self._repo.dirstate.normal(f) | |
1406 | finally: |
|
1405 | finally: | |
1407 | wlock.release() |
|
1406 | wlock.release() | |
1408 |
|
1407 | |||
1409 | def copy(self, source, dest): |
|
1408 | def copy(self, source, dest): | |
1410 | try: |
|
1409 | try: | |
1411 | st = self._repo.wvfs.lstat(dest) |
|
1410 | st = self._repo.wvfs.lstat(dest) | |
1412 | except OSError, err: |
|
1411 | except OSError, err: | |
1413 | if err.errno != errno.ENOENT: |
|
1412 | if err.errno != errno.ENOENT: | |
1414 | raise |
|
1413 | raise | |
1415 | self._repo.ui.warn(_("%s does not exist!\n") % dest) |
|
1414 | self._repo.ui.warn(_("%s does not exist!\n") % dest) | |
1416 | return |
|
1415 | return | |
1417 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1416 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1418 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
1417 | self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
1419 | "symbolic link\n") % dest) |
|
1418 | "symbolic link\n") % dest) | |
1420 | else: |
|
1419 | else: | |
1421 | wlock = self._repo.wlock() |
|
1420 | wlock = self._repo.wlock() | |
1422 | try: |
|
1421 | try: | |
1423 | if self._repo.dirstate[dest] in '?': |
|
1422 | if self._repo.dirstate[dest] in '?': | |
1424 | self._repo.dirstate.add(dest) |
|
1423 | self._repo.dirstate.add(dest) | |
1425 | elif self._repo.dirstate[dest] in 'r': |
|
1424 | elif self._repo.dirstate[dest] in 'r': | |
1426 | self._repo.dirstate.normallookup(dest) |
|
1425 | self._repo.dirstate.normallookup(dest) | |
1427 | self._repo.dirstate.copy(source, dest) |
|
1426 | self._repo.dirstate.copy(source, dest) | |
1428 | finally: |
|
1427 | finally: | |
1429 | wlock.release() |
|
1428 | wlock.release() | |
1430 |
|
1429 | |||
1431 | def _filtersuspectsymlink(self, files): |
|
1430 | def _filtersuspectsymlink(self, files): | |
1432 | if not files or self._repo.dirstate._checklink: |
|
1431 | if not files or self._repo.dirstate._checklink: | |
1433 | return files |
|
1432 | return files | |
1434 |
|
1433 | |||
1435 | # Symlink placeholders may get non-symlink-like contents |
|
1434 | # Symlink placeholders may get non-symlink-like contents | |
1436 | # via user error or dereferencing by NFS or Samba servers, |
|
1435 | # via user error or dereferencing by NFS or Samba servers, | |
1437 | # so we filter out any placeholders that don't look like a |
|
1436 | # so we filter out any placeholders that don't look like a | |
1438 | # symlink |
|
1437 | # symlink | |
1439 | sane = [] |
|
1438 | sane = [] | |
1440 | for f in files: |
|
1439 | for f in files: | |
1441 | if self.flags(f) == 'l': |
|
1440 | if self.flags(f) == 'l': | |
1442 | d = self[f].data() |
|
1441 | d = self[f].data() | |
1443 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): |
|
1442 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): | |
1444 | self._repo.ui.debug('ignoring suspect symlink placeholder' |
|
1443 | self._repo.ui.debug('ignoring suspect symlink placeholder' | |
1445 | ' "%s"\n' % f) |
|
1444 | ' "%s"\n' % f) | |
1446 | continue |
|
1445 | continue | |
1447 | sane.append(f) |
|
1446 | sane.append(f) | |
1448 | return sane |
|
1447 | return sane | |
1449 |
|
1448 | |||
1450 | def _checklookup(self, files): |
|
1449 | def _checklookup(self, files): | |
1451 | # check for any possibly clean files |
|
1450 | # check for any possibly clean files | |
1452 | if not files: |
|
1451 | if not files: | |
1453 | return [], [] |
|
1452 | return [], [] | |
1454 |
|
1453 | |||
1455 | modified = [] |
|
1454 | modified = [] | |
1456 | fixup = [] |
|
1455 | fixup = [] | |
1457 | pctx = self._parents[0] |
|
1456 | pctx = self._parents[0] | |
1458 | # do a full compare of any files that might have changed |
|
1457 | # do a full compare of any files that might have changed | |
1459 | for f in sorted(files): |
|
1458 | for f in sorted(files): | |
1460 | if (f not in pctx or self.flags(f) != pctx.flags(f) |
|
1459 | if (f not in pctx or self.flags(f) != pctx.flags(f) | |
1461 | or pctx[f].cmp(self[f])): |
|
1460 | or pctx[f].cmp(self[f])): | |
1462 | modified.append(f) |
|
1461 | modified.append(f) | |
1463 | else: |
|
1462 | else: | |
1464 | fixup.append(f) |
|
1463 | fixup.append(f) | |
1465 |
|
1464 | |||
1466 | # update dirstate for files that are actually clean |
|
1465 | # update dirstate for files that are actually clean | |
1467 | if fixup: |
|
1466 | if fixup: | |
1468 | try: |
|
1467 | try: | |
1469 | # updating the dirstate is optional |
|
1468 | # updating the dirstate is optional | |
1470 | # so we don't wait on the lock |
|
1469 | # so we don't wait on the lock | |
1471 | # wlock can invalidate the dirstate, so cache normal _after_ |
|
1470 | # wlock can invalidate the dirstate, so cache normal _after_ | |
1472 | # taking the lock |
|
1471 | # taking the lock | |
1473 | wlock = self._repo.wlock(False) |
|
1472 | wlock = self._repo.wlock(False) | |
1474 | normal = self._repo.dirstate.normal |
|
1473 | normal = self._repo.dirstate.normal | |
1475 | try: |
|
1474 | try: | |
1476 | for f in fixup: |
|
1475 | for f in fixup: | |
1477 | normal(f) |
|
1476 | normal(f) | |
1478 | finally: |
|
1477 | finally: | |
1479 | wlock.release() |
|
1478 | wlock.release() | |
1480 | except error.LockError: |
|
1479 | except error.LockError: | |
1481 | pass |
|
1480 | pass | |
1482 | return modified, fixup |
|
1481 | return modified, fixup | |
1483 |
|
1482 | |||
1484 | def _manifestmatches(self, match, s): |
|
1483 | def _manifestmatches(self, match, s): | |
1485 | """Slow path for workingctx |
|
1484 | """Slow path for workingctx | |
1486 |
|
1485 | |||
1487 | The fast path is when we compare the working directory to its parent |
|
1486 | The fast path is when we compare the working directory to its parent | |
1488 | which means this function is comparing with a non-parent; therefore we |
|
1487 | which means this function is comparing with a non-parent; therefore we | |
1489 | need to build a manifest and return what matches. |
|
1488 | need to build a manifest and return what matches. | |
1490 | """ |
|
1489 | """ | |
1491 | mf = self._repo['.']._manifestmatches(match, s) |
|
1490 | mf = self._repo['.']._manifestmatches(match, s) | |
1492 | for f in s.modified + s.added: |
|
1491 | for f in s.modified + s.added: | |
1493 | mf[f] = _newnode |
|
1492 | mf[f] = _newnode | |
1494 | mf.setflag(f, self.flags(f)) |
|
1493 | mf.setflag(f, self.flags(f)) | |
1495 | for f in s.removed: |
|
1494 | for f in s.removed: | |
1496 | if f in mf: |
|
1495 | if f in mf: | |
1497 | del mf[f] |
|
1496 | del mf[f] | |
1498 | return mf |
|
1497 | return mf | |
1499 |
|
1498 | |||
1500 | def _dirstatestatus(self, match=None, ignored=False, clean=False, |
|
1499 | def _dirstatestatus(self, match=None, ignored=False, clean=False, | |
1501 | unknown=False): |
|
1500 | unknown=False): | |
1502 | '''Gets the status from the dirstate -- internal use only.''' |
|
1501 | '''Gets the status from the dirstate -- internal use only.''' | |
1503 | listignored, listclean, listunknown = ignored, clean, unknown |
|
1502 | listignored, listclean, listunknown = ignored, clean, unknown | |
1504 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
1503 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
1505 | subrepos = [] |
|
1504 | subrepos = [] | |
1506 | if '.hgsub' in self: |
|
1505 | if '.hgsub' in self: | |
1507 | subrepos = sorted(self.substate) |
|
1506 | subrepos = sorted(self.substate) | |
1508 | cmp, s = self._repo.dirstate.status(match, subrepos, listignored, |
|
1507 | cmp, s = self._repo.dirstate.status(match, subrepos, listignored, | |
1509 | listclean, listunknown) |
|
1508 | listclean, listunknown) | |
1510 |
|
1509 | |||
1511 | # check for any possibly clean files |
|
1510 | # check for any possibly clean files | |
1512 | if cmp: |
|
1511 | if cmp: | |
1513 | modified2, fixup = self._checklookup(cmp) |
|
1512 | modified2, fixup = self._checklookup(cmp) | |
1514 | s.modified.extend(modified2) |
|
1513 | s.modified.extend(modified2) | |
1515 |
|
1514 | |||
1516 | # update dirstate for files that are actually clean |
|
1515 | # update dirstate for files that are actually clean | |
1517 | if fixup and listclean: |
|
1516 | if fixup and listclean: | |
1518 | s.clean.extend(fixup) |
|
1517 | s.clean.extend(fixup) | |
1519 |
|
1518 | |||
1520 | if match.always(): |
|
1519 | if match.always(): | |
1521 | # cache for performance |
|
1520 | # cache for performance | |
1522 | if s.unknown or s.ignored or s.clean: |
|
1521 | if s.unknown or s.ignored or s.clean: | |
1523 | # "_status" is cached with list*=False in the normal route |
|
1522 | # "_status" is cached with list*=False in the normal route | |
1524 | self._status = scmutil.status(s.modified, s.added, s.removed, |
|
1523 | self._status = scmutil.status(s.modified, s.added, s.removed, | |
1525 | s.deleted, [], [], []) |
|
1524 | s.deleted, [], [], []) | |
1526 | else: |
|
1525 | else: | |
1527 | self._status = s |
|
1526 | self._status = s | |
1528 |
|
1527 | |||
1529 | return s |
|
1528 | return s | |
1530 |
|
1529 | |||
1531 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
1530 | def _buildstatus(self, other, s, match, listignored, listclean, | |
1532 | listunknown): |
|
1531 | listunknown): | |
1533 | """build a status with respect to another context |
|
1532 | """build a status with respect to another context | |
1534 |
|
1533 | |||
1535 | This includes logic for maintaining the fast path of status when |
|
1534 | This includes logic for maintaining the fast path of status when | |
1536 | comparing the working directory against its parent, which is to skip |
|
1535 | comparing the working directory against its parent, which is to skip | |
1537 | building a new manifest if self (working directory) is not comparing |
|
1536 | building a new manifest if self (working directory) is not comparing | |
1538 | against its parent (repo['.']). |
|
1537 | against its parent (repo['.']). | |
1539 | """ |
|
1538 | """ | |
1540 | s = self._dirstatestatus(match, listignored, listclean, listunknown) |
|
1539 | s = self._dirstatestatus(match, listignored, listclean, listunknown) | |
1541 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, |
|
1540 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, | |
1542 | # might have accidentally ended up with the entire contents of the file |
|
1541 | # might have accidentally ended up with the entire contents of the file | |
1543 | # they are supposed to be linking to. |
|
1542 | # they are supposed to be linking to. | |
1544 | s.modified[:] = self._filtersuspectsymlink(s.modified) |
|
1543 | s.modified[:] = self._filtersuspectsymlink(s.modified) | |
1545 | if other != self._repo['.']: |
|
1544 | if other != self._repo['.']: | |
1546 | s = super(workingctx, self)._buildstatus(other, s, match, |
|
1545 | s = super(workingctx, self)._buildstatus(other, s, match, | |
1547 | listignored, listclean, |
|
1546 | listignored, listclean, | |
1548 | listunknown) |
|
1547 | listunknown) | |
1549 | return s |
|
1548 | return s | |
1550 |
|
1549 | |||
1551 | def _matchstatus(self, other, match): |
|
1550 | def _matchstatus(self, other, match): | |
1552 | """override the match method with a filter for directory patterns |
|
1551 | """override the match method with a filter for directory patterns | |
1553 |
|
1552 | |||
1554 | We use inheritance to customize the match.bad method only in cases of |
|
1553 | We use inheritance to customize the match.bad method only in cases of | |
1555 | workingctx since it belongs only to the working directory when |
|
1554 | workingctx since it belongs only to the working directory when | |
1556 | comparing against the parent changeset. |
|
1555 | comparing against the parent changeset. | |
1557 |
|
1556 | |||
1558 | If we aren't comparing against the working directory's parent, then we |
|
1557 | If we aren't comparing against the working directory's parent, then we | |
1559 | just use the default match object sent to us. |
|
1558 | just use the default match object sent to us. | |
1560 | """ |
|
1559 | """ | |
1561 | superself = super(workingctx, self) |
|
1560 | superself = super(workingctx, self) | |
1562 | match = superself._matchstatus(other, match) |
|
1561 | match = superself._matchstatus(other, match) | |
1563 | if other != self._repo['.']: |
|
1562 | if other != self._repo['.']: | |
1564 | def bad(f, msg): |
|
1563 | def bad(f, msg): | |
1565 | # 'f' may be a directory pattern from 'match.files()', |
|
1564 | # 'f' may be a directory pattern from 'match.files()', | |
1566 | # so 'f not in ctx1' is not enough |
|
1565 | # so 'f not in ctx1' is not enough | |
1567 | if f not in other and not other.hasdir(f): |
|
1566 | if f not in other and not other.hasdir(f): | |
1568 | self._repo.ui.warn('%s: %s\n' % |
|
1567 | self._repo.ui.warn('%s: %s\n' % | |
1569 | (self._repo.dirstate.pathto(f), msg)) |
|
1568 | (self._repo.dirstate.pathto(f), msg)) | |
1570 | match.bad = bad |
|
1569 | match.bad = bad | |
1571 | return match |
|
1570 | return match | |
1572 |
|
1571 | |||
1573 | class committablefilectx(basefilectx): |
|
1572 | class committablefilectx(basefilectx): | |
1574 | """A committablefilectx provides common functionality for a file context |
|
1573 | """A committablefilectx provides common functionality for a file context | |
1575 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" |
|
1574 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" | |
1576 | def __init__(self, repo, path, filelog=None, ctx=None): |
|
1575 | def __init__(self, repo, path, filelog=None, ctx=None): | |
1577 | self._repo = repo |
|
1576 | self._repo = repo | |
1578 | self._path = path |
|
1577 | self._path = path | |
1579 | self._changeid = None |
|
1578 | self._changeid = None | |
1580 | self._filerev = self._filenode = None |
|
1579 | self._filerev = self._filenode = None | |
1581 |
|
1580 | |||
1582 | if filelog is not None: |
|
1581 | if filelog is not None: | |
1583 | self._filelog = filelog |
|
1582 | self._filelog = filelog | |
1584 | if ctx: |
|
1583 | if ctx: | |
1585 | self._changectx = ctx |
|
1584 | self._changectx = ctx | |
1586 |
|
1585 | |||
1587 | def __nonzero__(self): |
|
1586 | def __nonzero__(self): | |
1588 | return True |
|
1587 | return True | |
1589 |
|
1588 | |||
1590 | def parents(self): |
|
1589 | def parents(self): | |
1591 | '''return parent filectxs, following copies if necessary''' |
|
1590 | '''return parent filectxs, following copies if necessary''' | |
1592 | def filenode(ctx, path): |
|
1591 | def filenode(ctx, path): | |
1593 | return ctx._manifest.get(path, nullid) |
|
1592 | return ctx._manifest.get(path, nullid) | |
1594 |
|
1593 | |||
1595 | path = self._path |
|
1594 | path = self._path | |
1596 | fl = self._filelog |
|
1595 | fl = self._filelog | |
1597 | pcl = self._changectx._parents |
|
1596 | pcl = self._changectx._parents | |
1598 | renamed = self.renamed() |
|
1597 | renamed = self.renamed() | |
1599 |
|
1598 | |||
1600 | if renamed: |
|
1599 | if renamed: | |
1601 | pl = [renamed + (None,)] |
|
1600 | pl = [renamed + (None,)] | |
1602 | else: |
|
1601 | else: | |
1603 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1602 | pl = [(path, filenode(pcl[0], path), fl)] | |
1604 |
|
1603 | |||
1605 | for pc in pcl[1:]: |
|
1604 | for pc in pcl[1:]: | |
1606 | pl.append((path, filenode(pc, path), fl)) |
|
1605 | pl.append((path, filenode(pc, path), fl)) | |
1607 |
|
1606 | |||
1608 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
1607 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
1609 | for p, n, l in pl if n != nullid] |
|
1608 | for p, n, l in pl if n != nullid] | |
1610 |
|
1609 | |||
1611 | def children(self): |
|
1610 | def children(self): | |
1612 | return [] |
|
1611 | return [] | |
1613 |
|
1612 | |||
1614 | class workingfilectx(committablefilectx): |
|
1613 | class workingfilectx(committablefilectx): | |
1615 | """A workingfilectx object makes access to data related to a particular |
|
1614 | """A workingfilectx object makes access to data related to a particular | |
1616 | file in the working directory convenient.""" |
|
1615 | file in the working directory convenient.""" | |
1617 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
1616 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
1618 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) |
|
1617 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) | |
1619 |
|
1618 | |||
1620 | @propertycache |
|
1619 | @propertycache | |
1621 | def _changectx(self): |
|
1620 | def _changectx(self): | |
1622 | return workingctx(self._repo) |
|
1621 | return workingctx(self._repo) | |
1623 |
|
1622 | |||
1624 | def data(self): |
|
1623 | def data(self): | |
1625 | return self._repo.wread(self._path) |
|
1624 | return self._repo.wread(self._path) | |
1626 | def renamed(self): |
|
1625 | def renamed(self): | |
1627 | rp = self._repo.dirstate.copied(self._path) |
|
1626 | rp = self._repo.dirstate.copied(self._path) | |
1628 | if not rp: |
|
1627 | if not rp: | |
1629 | return None |
|
1628 | return None | |
1630 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1629 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
1631 |
|
1630 | |||
1632 | def size(self): |
|
1631 | def size(self): | |
1633 | return self._repo.wvfs.lstat(self._path).st_size |
|
1632 | return self._repo.wvfs.lstat(self._path).st_size | |
1634 | def date(self): |
|
1633 | def date(self): | |
1635 | t, tz = self._changectx.date() |
|
1634 | t, tz = self._changectx.date() | |
1636 | try: |
|
1635 | try: | |
1637 | return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz) |
|
1636 | return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz) | |
1638 | except OSError, err: |
|
1637 | except OSError, err: | |
1639 | if err.errno != errno.ENOENT: |
|
1638 | if err.errno != errno.ENOENT: | |
1640 | raise |
|
1639 | raise | |
1641 | return (t, tz) |
|
1640 | return (t, tz) | |
1642 |
|
1641 | |||
1643 | def cmp(self, fctx): |
|
1642 | def cmp(self, fctx): | |
1644 | """compare with other file context |
|
1643 | """compare with other file context | |
1645 |
|
1644 | |||
1646 | returns True if different than fctx. |
|
1645 | returns True if different than fctx. | |
1647 | """ |
|
1646 | """ | |
1648 | # fctx should be a filectx (not a workingfilectx) |
|
1647 | # fctx should be a filectx (not a workingfilectx) | |
1649 | # invert comparison to reuse the same code path |
|
1648 | # invert comparison to reuse the same code path | |
1650 | return fctx.cmp(self) |
|
1649 | return fctx.cmp(self) | |
1651 |
|
1650 | |||
1652 | def remove(self, ignoremissing=False): |
|
1651 | def remove(self, ignoremissing=False): | |
1653 | """wraps unlink for a repo's working directory""" |
|
1652 | """wraps unlink for a repo's working directory""" | |
1654 | util.unlinkpath(self._repo.wjoin(self._path), ignoremissing) |
|
1653 | util.unlinkpath(self._repo.wjoin(self._path), ignoremissing) | |
1655 |
|
1654 | |||
1656 | def write(self, data, flags): |
|
1655 | def write(self, data, flags): | |
1657 | """wraps repo.wwrite""" |
|
1656 | """wraps repo.wwrite""" | |
1658 | self._repo.wwrite(self._path, data, flags) |
|
1657 | self._repo.wwrite(self._path, data, flags) | |
1659 |
|
1658 | |||
1660 | class workingcommitctx(workingctx): |
|
1659 | class workingcommitctx(workingctx): | |
1661 | """A workingcommitctx object makes access to data related to |
|
1660 | """A workingcommitctx object makes access to data related to | |
1662 | the revision being committed convenient. |
|
1661 | the revision being committed convenient. | |
1663 |
|
1662 | |||
1664 | This hides changes in the working directory, if they aren't |
|
1663 | This hides changes in the working directory, if they aren't | |
1665 | committed in this context. |
|
1664 | committed in this context. | |
1666 | """ |
|
1665 | """ | |
1667 | def __init__(self, repo, changes, |
|
1666 | def __init__(self, repo, changes, | |
1668 | text="", user=None, date=None, extra=None): |
|
1667 | text="", user=None, date=None, extra=None): | |
1669 | super(workingctx, self).__init__(repo, text, user, date, extra, |
|
1668 | super(workingctx, self).__init__(repo, text, user, date, extra, | |
1670 | changes) |
|
1669 | changes) | |
1671 |
|
1670 | |||
1672 | def _dirstatestatus(self, match=None, ignored=False, clean=False, |
|
1671 | def _dirstatestatus(self, match=None, ignored=False, clean=False, | |
1673 | unknown=False): |
|
1672 | unknown=False): | |
1674 | """Return matched files only in ``self._status`` |
|
1673 | """Return matched files only in ``self._status`` | |
1675 |
|
1674 | |||
1676 | Uncommitted files appear "clean" via this context, even if |
|
1675 | Uncommitted files appear "clean" via this context, even if | |
1677 | they aren't actually so in the working directory. |
|
1676 | they aren't actually so in the working directory. | |
1678 | """ |
|
1677 | """ | |
1679 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
1678 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
1680 | if clean: |
|
1679 | if clean: | |
1681 | clean = [f for f in self._manifest if f not in self._changedset] |
|
1680 | clean = [f for f in self._manifest if f not in self._changedset] | |
1682 | else: |
|
1681 | else: | |
1683 | clean = [] |
|
1682 | clean = [] | |
1684 | return scmutil.status([f for f in self._status.modified if match(f)], |
|
1683 | return scmutil.status([f for f in self._status.modified if match(f)], | |
1685 | [f for f in self._status.added if match(f)], |
|
1684 | [f for f in self._status.added if match(f)], | |
1686 | [f for f in self._status.removed if match(f)], |
|
1685 | [f for f in self._status.removed if match(f)], | |
1687 | [], [], [], clean) |
|
1686 | [], [], [], clean) | |
1688 |
|
1687 | |||
1689 | @propertycache |
|
1688 | @propertycache | |
1690 | def _changedset(self): |
|
1689 | def _changedset(self): | |
1691 | """Return the set of files changed in this context |
|
1690 | """Return the set of files changed in this context | |
1692 | """ |
|
1691 | """ | |
1693 | changed = set(self._status.modified) |
|
1692 | changed = set(self._status.modified) | |
1694 | changed.update(self._status.added) |
|
1693 | changed.update(self._status.added) | |
1695 | changed.update(self._status.removed) |
|
1694 | changed.update(self._status.removed) | |
1696 | return changed |
|
1695 | return changed | |
1697 |
|
1696 | |||
1698 | class memctx(committablectx): |
|
1697 | class memctx(committablectx): | |
1699 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
1698 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
1700 |
|
1699 | |||
1701 | Revision information is supplied at initialization time while |
|
1700 | Revision information is supplied at initialization time while | |
1702 | related files data and is made available through a callback |
|
1701 | related files data and is made available through a callback | |
1703 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
1702 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
1704 | sequence of two parent revisions identifiers (pass None for every |
|
1703 | sequence of two parent revisions identifiers (pass None for every | |
1705 | missing parent), 'text' is the commit message and 'files' lists |
|
1704 | missing parent), 'text' is the commit message and 'files' lists | |
1706 | names of files touched by the revision (normalized and relative to |
|
1705 | names of files touched by the revision (normalized and relative to | |
1707 | repository root). |
|
1706 | repository root). | |
1708 |
|
1707 | |||
1709 | filectxfn(repo, memctx, path) is a callable receiving the |
|
1708 | filectxfn(repo, memctx, path) is a callable receiving the | |
1710 | repository, the current memctx object and the normalized path of |
|
1709 | repository, the current memctx object and the normalized path of | |
1711 | requested file, relative to repository root. It is fired by the |
|
1710 | requested file, relative to repository root. It is fired by the | |
1712 | commit function for every file in 'files', but calls order is |
|
1711 | commit function for every file in 'files', but calls order is | |
1713 | undefined. If the file is available in the revision being |
|
1712 | undefined. If the file is available in the revision being | |
1714 | committed (updated or added), filectxfn returns a memfilectx |
|
1713 | committed (updated or added), filectxfn returns a memfilectx | |
1715 | object. If the file was removed, filectxfn raises an |
|
1714 | object. If the file was removed, filectxfn raises an | |
1716 | IOError. Moved files are represented by marking the source file |
|
1715 | IOError. Moved files are represented by marking the source file | |
1717 | removed and the new file added with copy information (see |
|
1716 | removed and the new file added with copy information (see | |
1718 | memfilectx). |
|
1717 | memfilectx). | |
1719 |
|
1718 | |||
1720 | user receives the committer name and defaults to current |
|
1719 | user receives the committer name and defaults to current | |
1721 | repository username, date is the commit date in any format |
|
1720 | repository username, date is the commit date in any format | |
1722 | supported by util.parsedate() and defaults to current date, extra |
|
1721 | supported by util.parsedate() and defaults to current date, extra | |
1723 | is a dictionary of metadata or is left empty. |
|
1722 | is a dictionary of metadata or is left empty. | |
1724 | """ |
|
1723 | """ | |
1725 |
|
1724 | |||
1726 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. |
|
1725 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. | |
1727 | # Extensions that need to retain compatibility across Mercurial 3.1 can use |
|
1726 | # Extensions that need to retain compatibility across Mercurial 3.1 can use | |
1728 | # this field to determine what to do in filectxfn. |
|
1727 | # this field to determine what to do in filectxfn. | |
1729 | _returnnoneformissingfiles = True |
|
1728 | _returnnoneformissingfiles = True | |
1730 |
|
1729 | |||
1731 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
1730 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
1732 | date=None, extra=None, editor=False): |
|
1731 | date=None, extra=None, editor=False): | |
1733 | super(memctx, self).__init__(repo, text, user, date, extra) |
|
1732 | super(memctx, self).__init__(repo, text, user, date, extra) | |
1734 | self._rev = None |
|
1733 | self._rev = None | |
1735 | self._node = None |
|
1734 | self._node = None | |
1736 | parents = [(p or nullid) for p in parents] |
|
1735 | parents = [(p or nullid) for p in parents] | |
1737 | p1, p2 = parents |
|
1736 | p1, p2 = parents | |
1738 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
1737 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
1739 | files = sorted(set(files)) |
|
1738 | files = sorted(set(files)) | |
1740 | self._files = files |
|
1739 | self._files = files | |
1741 | self.substate = {} |
|
1740 | self.substate = {} | |
1742 |
|
1741 | |||
1743 | # if store is not callable, wrap it in a function |
|
1742 | # if store is not callable, wrap it in a function | |
1744 | if not callable(filectxfn): |
|
1743 | if not callable(filectxfn): | |
1745 | def getfilectx(repo, memctx, path): |
|
1744 | def getfilectx(repo, memctx, path): | |
1746 | fctx = filectxfn[path] |
|
1745 | fctx = filectxfn[path] | |
1747 | # this is weird but apparently we only keep track of one parent |
|
1746 | # this is weird but apparently we only keep track of one parent | |
1748 | # (why not only store that instead of a tuple?) |
|
1747 | # (why not only store that instead of a tuple?) | |
1749 | copied = fctx.renamed() |
|
1748 | copied = fctx.renamed() | |
1750 | if copied: |
|
1749 | if copied: | |
1751 | copied = copied[0] |
|
1750 | copied = copied[0] | |
1752 | return memfilectx(repo, path, fctx.data(), |
|
1751 | return memfilectx(repo, path, fctx.data(), | |
1753 | islink=fctx.islink(), isexec=fctx.isexec(), |
|
1752 | islink=fctx.islink(), isexec=fctx.isexec(), | |
1754 | copied=copied, memctx=memctx) |
|
1753 | copied=copied, memctx=memctx) | |
1755 | self._filectxfn = getfilectx |
|
1754 | self._filectxfn = getfilectx | |
1756 | else: |
|
1755 | else: | |
1757 | # "util.cachefunc" reduces invocation of possibly expensive |
|
1756 | # "util.cachefunc" reduces invocation of possibly expensive | |
1758 | # "filectxfn" for performance (e.g. converting from another VCS) |
|
1757 | # "filectxfn" for performance (e.g. converting from another VCS) | |
1759 | self._filectxfn = util.cachefunc(filectxfn) |
|
1758 | self._filectxfn = util.cachefunc(filectxfn) | |
1760 |
|
1759 | |||
1761 | if extra: |
|
1760 | if extra: | |
1762 | self._extra = extra.copy() |
|
1761 | self._extra = extra.copy() | |
1763 | else: |
|
1762 | else: | |
1764 | self._extra = {} |
|
1763 | self._extra = {} | |
1765 |
|
1764 | |||
1766 | if self._extra.get('branch', '') == '': |
|
1765 | if self._extra.get('branch', '') == '': | |
1767 | self._extra['branch'] = 'default' |
|
1766 | self._extra['branch'] = 'default' | |
1768 |
|
1767 | |||
1769 | if editor: |
|
1768 | if editor: | |
1770 | self._text = editor(self._repo, self, []) |
|
1769 | self._text = editor(self._repo, self, []) | |
1771 | self._repo.savecommitmessage(self._text) |
|
1770 | self._repo.savecommitmessage(self._text) | |
1772 |
|
1771 | |||
1773 | def filectx(self, path, filelog=None): |
|
1772 | def filectx(self, path, filelog=None): | |
1774 | """get a file context from the working directory |
|
1773 | """get a file context from the working directory | |
1775 |
|
1774 | |||
1776 | Returns None if file doesn't exist and should be removed.""" |
|
1775 | Returns None if file doesn't exist and should be removed.""" | |
1777 | return self._filectxfn(self._repo, self, path) |
|
1776 | return self._filectxfn(self._repo, self, path) | |
1778 |
|
1777 | |||
1779 | def commit(self): |
|
1778 | def commit(self): | |
1780 | """commit context to the repo""" |
|
1779 | """commit context to the repo""" | |
1781 | return self._repo.commitctx(self) |
|
1780 | return self._repo.commitctx(self) | |
1782 |
|
1781 | |||
1783 | @propertycache |
|
1782 | @propertycache | |
1784 | def _manifest(self): |
|
1783 | def _manifest(self): | |
1785 | """generate a manifest based on the return values of filectxfn""" |
|
1784 | """generate a manifest based on the return values of filectxfn""" | |
1786 |
|
1785 | |||
1787 | # keep this simple for now; just worry about p1 |
|
1786 | # keep this simple for now; just worry about p1 | |
1788 | pctx = self._parents[0] |
|
1787 | pctx = self._parents[0] | |
1789 | man = pctx.manifest().copy() |
|
1788 | man = pctx.manifest().copy() | |
1790 |
|
1789 | |||
1791 | for f in self._status.modified: |
|
1790 | for f in self._status.modified: | |
1792 | p1node = nullid |
|
1791 | p1node = nullid | |
1793 | p2node = nullid |
|
1792 | p2node = nullid | |
1794 | p = pctx[f].parents() # if file isn't in pctx, check p2? |
|
1793 | p = pctx[f].parents() # if file isn't in pctx, check p2? | |
1795 | if len(p) > 0: |
|
1794 | if len(p) > 0: | |
1796 | p1node = p[0].node() |
|
1795 | p1node = p[0].node() | |
1797 | if len(p) > 1: |
|
1796 | if len(p) > 1: | |
1798 | p2node = p[1].node() |
|
1797 | p2node = p[1].node() | |
1799 | man[f] = revlog.hash(self[f].data(), p1node, p2node) |
|
1798 | man[f] = revlog.hash(self[f].data(), p1node, p2node) | |
1800 |
|
1799 | |||
1801 | for f in self._status.added: |
|
1800 | for f in self._status.added: | |
1802 | man[f] = revlog.hash(self[f].data(), nullid, nullid) |
|
1801 | man[f] = revlog.hash(self[f].data(), nullid, nullid) | |
1803 |
|
1802 | |||
1804 | for f in self._status.removed: |
|
1803 | for f in self._status.removed: | |
1805 | if f in man: |
|
1804 | if f in man: | |
1806 | del man[f] |
|
1805 | del man[f] | |
1807 |
|
1806 | |||
1808 | return man |
|
1807 | return man | |
1809 |
|
1808 | |||
1810 | @propertycache |
|
1809 | @propertycache | |
1811 | def _status(self): |
|
1810 | def _status(self): | |
1812 | """Calculate exact status from ``files`` specified at construction |
|
1811 | """Calculate exact status from ``files`` specified at construction | |
1813 | """ |
|
1812 | """ | |
1814 | man1 = self.p1().manifest() |
|
1813 | man1 = self.p1().manifest() | |
1815 | p2 = self._parents[1] |
|
1814 | p2 = self._parents[1] | |
1816 | # "1 < len(self._parents)" can't be used for checking |
|
1815 | # "1 < len(self._parents)" can't be used for checking | |
1817 | # existence of the 2nd parent, because "memctx._parents" is |
|
1816 | # existence of the 2nd parent, because "memctx._parents" is | |
1818 | # explicitly initialized by the list, of which length is 2. |
|
1817 | # explicitly initialized by the list, of which length is 2. | |
1819 | if p2.node() != nullid: |
|
1818 | if p2.node() != nullid: | |
1820 | man2 = p2.manifest() |
|
1819 | man2 = p2.manifest() | |
1821 | managing = lambda f: f in man1 or f in man2 |
|
1820 | managing = lambda f: f in man1 or f in man2 | |
1822 | else: |
|
1821 | else: | |
1823 | managing = lambda f: f in man1 |
|
1822 | managing = lambda f: f in man1 | |
1824 |
|
1823 | |||
1825 | modified, added, removed = [], [], [] |
|
1824 | modified, added, removed = [], [], [] | |
1826 | for f in self._files: |
|
1825 | for f in self._files: | |
1827 | if not managing(f): |
|
1826 | if not managing(f): | |
1828 | added.append(f) |
|
1827 | added.append(f) | |
1829 | elif self[f]: |
|
1828 | elif self[f]: | |
1830 | modified.append(f) |
|
1829 | modified.append(f) | |
1831 | else: |
|
1830 | else: | |
1832 | removed.append(f) |
|
1831 | removed.append(f) | |
1833 |
|
1832 | |||
1834 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
1833 | return scmutil.status(modified, added, removed, [], [], [], []) | |
1835 |
|
1834 | |||
1836 | class memfilectx(committablefilectx): |
|
1835 | class memfilectx(committablefilectx): | |
1837 | """memfilectx represents an in-memory file to commit. |
|
1836 | """memfilectx represents an in-memory file to commit. | |
1838 |
|
1837 | |||
1839 | See memctx and committablefilectx for more details. |
|
1838 | See memctx and committablefilectx for more details. | |
1840 | """ |
|
1839 | """ | |
1841 | def __init__(self, repo, path, data, islink=False, |
|
1840 | def __init__(self, repo, path, data, islink=False, | |
1842 | isexec=False, copied=None, memctx=None): |
|
1841 | isexec=False, copied=None, memctx=None): | |
1843 | """ |
|
1842 | """ | |
1844 | path is the normalized file path relative to repository root. |
|
1843 | path is the normalized file path relative to repository root. | |
1845 | data is the file content as a string. |
|
1844 | data is the file content as a string. | |
1846 | islink is True if the file is a symbolic link. |
|
1845 | islink is True if the file is a symbolic link. | |
1847 | isexec is True if the file is executable. |
|
1846 | isexec is True if the file is executable. | |
1848 | copied is the source file path if current file was copied in the |
|
1847 | copied is the source file path if current file was copied in the | |
1849 | revision being committed, or None.""" |
|
1848 | revision being committed, or None.""" | |
1850 | super(memfilectx, self).__init__(repo, path, None, memctx) |
|
1849 | super(memfilectx, self).__init__(repo, path, None, memctx) | |
1851 | self._data = data |
|
1850 | self._data = data | |
1852 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
1851 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
1853 | self._copied = None |
|
1852 | self._copied = None | |
1854 | if copied: |
|
1853 | if copied: | |
1855 | self._copied = (copied, nullid) |
|
1854 | self._copied = (copied, nullid) | |
1856 |
|
1855 | |||
1857 | def data(self): |
|
1856 | def data(self): | |
1858 | return self._data |
|
1857 | return self._data | |
1859 | def size(self): |
|
1858 | def size(self): | |
1860 | return len(self.data()) |
|
1859 | return len(self.data()) | |
1861 | def flags(self): |
|
1860 | def flags(self): | |
1862 | return self._flags |
|
1861 | return self._flags | |
1863 | def renamed(self): |
|
1862 | def renamed(self): | |
1864 | return self._copied |
|
1863 | return self._copied | |
1865 |
|
1864 | |||
1866 | def remove(self, ignoremissing=False): |
|
1865 | def remove(self, ignoremissing=False): | |
1867 | """wraps unlink for a repo's working directory""" |
|
1866 | """wraps unlink for a repo's working directory""" | |
1868 | # need to figure out what to do here |
|
1867 | # need to figure out what to do here | |
1869 | del self._changectx[self._path] |
|
1868 | del self._changectx[self._path] | |
1870 |
|
1869 | |||
1871 | def write(self, data, flags): |
|
1870 | def write(self, data, flags): | |
1872 | """wraps repo.wwrite""" |
|
1871 | """wraps repo.wwrite""" | |
1873 | self._data = data |
|
1872 | self._data = data |
@@ -1,53 +1,65 b'' | |||||
1 | $ hg init |
|
1 | $ hg init | |
2 | $ echo 0 > a |
|
2 | $ echo 0 > a | |
3 | $ echo 0 > b |
|
3 | $ echo 0 > b | |
4 | $ hg ci -A -m m |
|
4 | $ hg ci -A -m m | |
5 | adding a |
|
5 | adding a | |
6 | adding b |
|
6 | adding b | |
7 | $ hg rm a |
|
7 | $ hg rm a | |
8 | $ hg cat a |
|
8 | $ hg cat a | |
9 | 0 |
|
9 | 0 | |
10 | $ hg cat --decode a # more tests in test-encode |
|
10 | $ hg cat --decode a # more tests in test-encode | |
11 | 0 |
|
11 | 0 | |
12 | $ echo 1 > b |
|
12 | $ echo 1 > b | |
13 | $ hg ci -m m |
|
13 | $ hg ci -m m | |
14 | $ echo 2 > b |
|
14 | $ echo 2 > b | |
15 | $ hg cat -r 0 a |
|
15 | $ hg cat -r 0 a | |
16 | 0 |
|
16 | 0 | |
17 | $ hg cat -r 0 b |
|
17 | $ hg cat -r 0 b | |
18 | 0 |
|
18 | 0 | |
19 | $ hg cat -r 1 a |
|
19 | $ hg cat -r 1 a | |
20 | a: no such file in rev 7040230c159c |
|
20 | a: no such file in rev 7040230c159c | |
21 | [1] |
|
21 | [1] | |
22 | $ hg cat -r 1 b |
|
22 | $ hg cat -r 1 b | |
23 | 1 |
|
23 | 1 | |
24 |
|
24 | |||
25 |
Test files |
|
25 | Test multiple files | |
26 |
|
26 | |||
27 | $ echo 3 > c |
|
27 | $ echo 3 > c | |
28 | $ hg ci -Am addmore c |
|
28 | $ hg ci -Am addmore c | |
|
29 | $ hg cat b c | |||
|
30 | 1 | |||
|
31 | 3 | |||
|
32 | $ hg cat . | |||
|
33 | 1 | |||
|
34 | 3 | |||
|
35 | $ hg cat . c | |||
|
36 | 1 | |||
|
37 | 3 | |||
|
38 | ||||
|
39 | Test fileset | |||
|
40 | ||||
29 | $ hg cat 'set:not(b) or a' |
|
41 | $ hg cat 'set:not(b) or a' | |
30 | 3 |
|
42 | 3 | |
31 | $ hg cat 'set:c or b' |
|
43 | $ hg cat 'set:c or b' | |
32 | 1 |
|
44 | 1 | |
33 | 3 |
|
45 | 3 | |
34 |
|
46 | |||
35 | $ mkdir tmp |
|
47 | $ mkdir tmp | |
36 | $ hg cat --output tmp/HH_%H c |
|
48 | $ hg cat --output tmp/HH_%H c | |
37 | $ hg cat --output tmp/RR_%R c |
|
49 | $ hg cat --output tmp/RR_%R c | |
38 | $ hg cat --output tmp/h_%h c |
|
50 | $ hg cat --output tmp/h_%h c | |
39 | $ hg cat --output tmp/r_%r c |
|
51 | $ hg cat --output tmp/r_%r c | |
40 | $ hg cat --output tmp/%s_s c |
|
52 | $ hg cat --output tmp/%s_s c | |
41 | $ hg cat --output tmp/%d%%_d c |
|
53 | $ hg cat --output tmp/%d%%_d c | |
42 | $ hg cat --output tmp/%p_p c |
|
54 | $ hg cat --output tmp/%p_p c | |
43 | $ hg log -r . --template "{rev}: {node|short}\n" |
|
55 | $ hg log -r . --template "{rev}: {node|short}\n" | |
44 | 2: 45116003780e |
|
56 | 2: 45116003780e | |
45 | $ find tmp -type f | sort |
|
57 | $ find tmp -type f | sort | |
46 | tmp/.%_d |
|
58 | tmp/.%_d | |
47 | tmp/HH_45116003780e3678b333fb2c99fa7d559c8457e9 |
|
59 | tmp/HH_45116003780e3678b333fb2c99fa7d559c8457e9 | |
48 | tmp/RR_2 |
|
60 | tmp/RR_2 | |
49 | tmp/c_p |
|
61 | tmp/c_p | |
50 | tmp/c_s |
|
62 | tmp/c_s | |
51 | tmp/h_45116003780e |
|
63 | tmp/h_45116003780e | |
52 | tmp/r_2 |
|
64 | tmp/r_2 | |
53 |
|
65 |
General Comments 0
You need to be logged in to leave comments.
Login now