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