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