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