Show More
@@ -1,2789 +1,2789 | |||||
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 filecmp |
|
11 | import filecmp | |
12 | import os |
|
12 | import os | |
13 | import re |
|
13 | import re | |
14 | import stat |
|
14 | import stat | |
15 |
|
15 | |||
16 | from .i18n import _ |
|
16 | from .i18n import _ | |
17 | from .node import ( |
|
17 | from .node import ( | |
18 | addednodeid, |
|
18 | addednodeid, | |
19 | bin, |
|
19 | bin, | |
20 | hex, |
|
20 | hex, | |
21 | modifiednodeid, |
|
21 | modifiednodeid, | |
22 | nullid, |
|
22 | nullid, | |
23 | nullrev, |
|
23 | nullrev, | |
24 | short, |
|
24 | short, | |
25 | wdirid, |
|
25 | wdirid, | |
26 | wdirnodes, |
|
26 | wdirnodes, | |
27 | wdirrev, |
|
27 | wdirrev, | |
28 | ) |
|
28 | ) | |
29 | from .thirdparty import ( |
|
29 | from .thirdparty import ( | |
30 | attr, |
|
30 | attr, | |
31 | ) |
|
31 | ) | |
32 | from . import ( |
|
32 | from . import ( | |
33 | encoding, |
|
33 | encoding, | |
34 | error, |
|
34 | error, | |
35 | fileset, |
|
35 | fileset, | |
36 | match as matchmod, |
|
36 | match as matchmod, | |
37 | mdiff, |
|
37 | mdiff, | |
38 | obsolete as obsmod, |
|
38 | obsolete as obsmod, | |
39 | obsutil, |
|
39 | obsutil, | |
40 | patch, |
|
40 | patch, | |
41 | pathutil, |
|
41 | pathutil, | |
42 | phases, |
|
42 | phases, | |
43 | pycompat, |
|
43 | pycompat, | |
44 | repoview, |
|
44 | repoview, | |
45 | revlog, |
|
45 | revlog, | |
46 | scmutil, |
|
46 | scmutil, | |
47 | sparse, |
|
47 | sparse, | |
48 | subrepo, |
|
48 | subrepo, | |
49 | util, |
|
49 | util, | |
50 | ) |
|
50 | ) | |
51 |
|
51 | |||
52 | propertycache = util.propertycache |
|
52 | propertycache = util.propertycache | |
53 |
|
53 | |||
54 | nonascii = re.compile(r'[^\x21-\x7f]').search |
|
54 | nonascii = re.compile(r'[^\x21-\x7f]').search | |
55 |
|
55 | |||
56 | class basectx(object): |
|
56 | class basectx(object): | |
57 | """A basectx object represents the common logic for its children: |
|
57 | """A basectx object represents the common logic for its children: | |
58 | changectx: read-only context that is already present in the repo, |
|
58 | changectx: read-only context that is already present in the repo, | |
59 | workingctx: a context that represents the working directory and can |
|
59 | workingctx: a context that represents the working directory and can | |
60 | be committed, |
|
60 | be committed, | |
61 | memctx: a context that represents changes in-memory and can also |
|
61 | memctx: a context that represents changes in-memory and can also | |
62 | be committed.""" |
|
62 | be committed.""" | |
63 | def __new__(cls, repo, changeid='', *args, **kwargs): |
|
63 | def __new__(cls, repo, changeid='', *args, **kwargs): | |
64 | if isinstance(changeid, basectx): |
|
64 | if isinstance(changeid, basectx): | |
65 | return changeid |
|
65 | return changeid | |
66 |
|
66 | |||
67 | o = super(basectx, cls).__new__(cls) |
|
67 | o = super(basectx, cls).__new__(cls) | |
68 |
|
68 | |||
69 | o._repo = repo |
|
69 | o._repo = repo | |
70 | o._rev = nullrev |
|
70 | o._rev = nullrev | |
71 | o._node = nullid |
|
71 | o._node = nullid | |
72 |
|
72 | |||
73 | return o |
|
73 | return o | |
74 |
|
74 | |||
75 | def __bytes__(self): |
|
75 | def __bytes__(self): | |
76 | return short(self.node()) |
|
76 | return short(self.node()) | |
77 |
|
77 | |||
78 | __str__ = encoding.strmethod(__bytes__) |
|
78 | __str__ = encoding.strmethod(__bytes__) | |
79 |
|
79 | |||
80 | def __int__(self): |
|
80 | def __int__(self): | |
81 | return self.rev() |
|
81 | return self.rev() | |
82 |
|
82 | |||
83 | def __repr__(self): |
|
83 | def __repr__(self): | |
84 | return r"<%s %s>" % (type(self).__name__, str(self)) |
|
84 | return r"<%s %s>" % (type(self).__name__, str(self)) | |
85 |
|
85 | |||
86 | def __eq__(self, other): |
|
86 | def __eq__(self, other): | |
87 | try: |
|
87 | try: | |
88 | return type(self) == type(other) and self._rev == other._rev |
|
88 | return type(self) == type(other) and self._rev == other._rev | |
89 | except AttributeError: |
|
89 | except AttributeError: | |
90 | return False |
|
90 | return False | |
91 |
|
91 | |||
92 | def __ne__(self, other): |
|
92 | def __ne__(self, other): | |
93 | return not (self == other) |
|
93 | return not (self == other) | |
94 |
|
94 | |||
95 | def __contains__(self, key): |
|
95 | def __contains__(self, key): | |
96 | return key in self._manifest |
|
96 | return key in self._manifest | |
97 |
|
97 | |||
98 | def __getitem__(self, key): |
|
98 | def __getitem__(self, key): | |
99 | return self.filectx(key) |
|
99 | return self.filectx(key) | |
100 |
|
100 | |||
101 | def __iter__(self): |
|
101 | def __iter__(self): | |
102 | return iter(self._manifest) |
|
102 | return iter(self._manifest) | |
103 |
|
103 | |||
104 | def _buildstatusmanifest(self, status): |
|
104 | def _buildstatusmanifest(self, status): | |
105 | """Builds a manifest that includes the given status results, if this is |
|
105 | """Builds a manifest that includes the given status results, if this is | |
106 | a working copy context. For non-working copy contexts, it just returns |
|
106 | a working copy context. For non-working copy contexts, it just returns | |
107 | the normal manifest.""" |
|
107 | the normal manifest.""" | |
108 | return self.manifest() |
|
108 | return self.manifest() | |
109 |
|
109 | |||
110 | def _matchstatus(self, other, match): |
|
110 | def _matchstatus(self, other, match): | |
111 | """This internal method provides a way for child objects to override the |
|
111 | """This internal method provides a way for child objects to override the | |
112 | match operator. |
|
112 | match operator. | |
113 | """ |
|
113 | """ | |
114 | return match |
|
114 | return match | |
115 |
|
115 | |||
116 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
116 | def _buildstatus(self, other, s, match, listignored, listclean, | |
117 | listunknown): |
|
117 | listunknown): | |
118 | """build a status with respect to another context""" |
|
118 | """build a status with respect to another context""" | |
119 | # Load earliest manifest first for caching reasons. More specifically, |
|
119 | # Load earliest manifest first for caching reasons. More specifically, | |
120 | # if you have revisions 1000 and 1001, 1001 is probably stored as a |
|
120 | # if you have revisions 1000 and 1001, 1001 is probably stored as a | |
121 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct |
|
121 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct | |
122 | # 1000 and cache it so that when you read 1001, we just need to apply a |
|
122 | # 1000 and cache it so that when you read 1001, we just need to apply a | |
123 | # delta to what's in the cache. So that's one full reconstruction + one |
|
123 | # delta to what's in the cache. So that's one full reconstruction + one | |
124 | # delta application. |
|
124 | # delta application. | |
125 | mf2 = None |
|
125 | mf2 = None | |
126 | if self.rev() is not None and self.rev() < other.rev(): |
|
126 | if self.rev() is not None and self.rev() < other.rev(): | |
127 | mf2 = self._buildstatusmanifest(s) |
|
127 | mf2 = self._buildstatusmanifest(s) | |
128 | mf1 = other._buildstatusmanifest(s) |
|
128 | mf1 = other._buildstatusmanifest(s) | |
129 | if mf2 is None: |
|
129 | if mf2 is None: | |
130 | mf2 = self._buildstatusmanifest(s) |
|
130 | mf2 = self._buildstatusmanifest(s) | |
131 |
|
131 | |||
132 | modified, added = [], [] |
|
132 | modified, added = [], [] | |
133 | removed = [] |
|
133 | removed = [] | |
134 | clean = [] |
|
134 | clean = [] | |
135 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored |
|
135 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored | |
136 | deletedset = set(deleted) |
|
136 | deletedset = set(deleted) | |
137 | d = mf1.diff(mf2, match=match, clean=listclean) |
|
137 | d = mf1.diff(mf2, match=match, clean=listclean) | |
138 | for fn, value in d.iteritems(): |
|
138 | for fn, value in d.iteritems(): | |
139 | if fn in deletedset: |
|
139 | if fn in deletedset: | |
140 | continue |
|
140 | continue | |
141 | if value is None: |
|
141 | if value is None: | |
142 | clean.append(fn) |
|
142 | clean.append(fn) | |
143 | continue |
|
143 | continue | |
144 | (node1, flag1), (node2, flag2) = value |
|
144 | (node1, flag1), (node2, flag2) = value | |
145 | if node1 is None: |
|
145 | if node1 is None: | |
146 | added.append(fn) |
|
146 | added.append(fn) | |
147 | elif node2 is None: |
|
147 | elif node2 is None: | |
148 | removed.append(fn) |
|
148 | removed.append(fn) | |
149 | elif flag1 != flag2: |
|
149 | elif flag1 != flag2: | |
150 | modified.append(fn) |
|
150 | modified.append(fn) | |
151 | elif node2 not in wdirnodes: |
|
151 | elif node2 not in wdirnodes: | |
152 | # When comparing files between two commits, we save time by |
|
152 | # When comparing files between two commits, we save time by | |
153 | # not comparing the file contents when the nodeids differ. |
|
153 | # not comparing the file contents when the nodeids differ. | |
154 | # Note that this means we incorrectly report a reverted change |
|
154 | # Note that this means we incorrectly report a reverted change | |
155 | # to a file as a modification. |
|
155 | # to a file as a modification. | |
156 | modified.append(fn) |
|
156 | modified.append(fn) | |
157 | elif self[fn].cmp(other[fn]): |
|
157 | elif self[fn].cmp(other[fn]): | |
158 | modified.append(fn) |
|
158 | modified.append(fn) | |
159 | else: |
|
159 | else: | |
160 | clean.append(fn) |
|
160 | clean.append(fn) | |
161 |
|
161 | |||
162 | if removed: |
|
162 | if removed: | |
163 | # need to filter files if they are already reported as removed |
|
163 | # need to filter files if they are already reported as removed | |
164 | unknown = [fn for fn in unknown if fn not in mf1 and |
|
164 | unknown = [fn for fn in unknown if fn not in mf1 and | |
165 | (not match or match(fn))] |
|
165 | (not match or match(fn))] | |
166 | ignored = [fn for fn in ignored if fn not in mf1 and |
|
166 | ignored = [fn for fn in ignored if fn not in mf1 and | |
167 | (not match or match(fn))] |
|
167 | (not match or match(fn))] | |
168 | # if they're deleted, don't report them as removed |
|
168 | # if they're deleted, don't report them as removed | |
169 | removed = [fn for fn in removed if fn not in deletedset] |
|
169 | removed = [fn for fn in removed if fn not in deletedset] | |
170 |
|
170 | |||
171 | return scmutil.status(modified, added, removed, deleted, unknown, |
|
171 | return scmutil.status(modified, added, removed, deleted, unknown, | |
172 | ignored, clean) |
|
172 | ignored, clean) | |
173 |
|
173 | |||
174 | @propertycache |
|
174 | @propertycache | |
175 | def substate(self): |
|
175 | def substate(self): | |
176 | return subrepo.state(self, self._repo.ui) |
|
176 | return subrepo.state(self, self._repo.ui) | |
177 |
|
177 | |||
178 | def subrev(self, subpath): |
|
178 | def subrev(self, subpath): | |
179 | return self.substate[subpath][1] |
|
179 | return self.substate[subpath][1] | |
180 |
|
180 | |||
181 | def rev(self): |
|
181 | def rev(self): | |
182 | return self._rev |
|
182 | return self._rev | |
183 | def node(self): |
|
183 | def node(self): | |
184 | return self._node |
|
184 | return self._node | |
185 | def hex(self): |
|
185 | def hex(self): | |
186 | return hex(self.node()) |
|
186 | return hex(self.node()) | |
187 | def manifest(self): |
|
187 | def manifest(self): | |
188 | return self._manifest |
|
188 | return self._manifest | |
189 | def manifestctx(self): |
|
189 | def manifestctx(self): | |
190 | return self._manifestctx |
|
190 | return self._manifestctx | |
191 | def repo(self): |
|
191 | def repo(self): | |
192 | return self._repo |
|
192 | return self._repo | |
193 | def phasestr(self): |
|
193 | def phasestr(self): | |
194 | return phases.phasenames[self.phase()] |
|
194 | return phases.phasenames[self.phase()] | |
195 | def mutable(self): |
|
195 | def mutable(self): | |
196 | return self.phase() > phases.public |
|
196 | return self.phase() > phases.public | |
197 |
|
197 | |||
198 | def getfileset(self, expr): |
|
198 | def getfileset(self, expr): | |
199 | return fileset.getfileset(self, expr) |
|
199 | return fileset.getfileset(self, expr) | |
200 |
|
200 | |||
201 | def obsolete(self): |
|
201 | def obsolete(self): | |
202 | """True if the changeset is obsolete""" |
|
202 | """True if the changeset is obsolete""" | |
203 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') |
|
203 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') | |
204 |
|
204 | |||
205 | def extinct(self): |
|
205 | def extinct(self): | |
206 | """True if the changeset is extinct""" |
|
206 | """True if the changeset is extinct""" | |
207 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') |
|
207 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') | |
208 |
|
208 | |||
209 | def unstable(self): |
|
209 | def unstable(self): | |
210 | msg = ("'context.unstable' is deprecated, " |
|
210 | msg = ("'context.unstable' is deprecated, " | |
211 | "use 'context.orphan'") |
|
211 | "use 'context.orphan'") | |
212 | self._repo.ui.deprecwarn(msg, '4.4') |
|
212 | self._repo.ui.deprecwarn(msg, '4.4') | |
213 | return self.orphan() |
|
213 | return self.orphan() | |
214 |
|
214 | |||
215 | def orphan(self): |
|
215 | def orphan(self): | |
216 | """True if the changeset is not obsolete but it's ancestor are""" |
|
216 | """True if the changeset is not obsolete but it's ancestor are""" | |
217 | return self.rev() in obsmod.getrevs(self._repo, 'orphan') |
|
217 | return self.rev() in obsmod.getrevs(self._repo, 'orphan') | |
218 |
|
218 | |||
219 | def bumped(self): |
|
219 | def bumped(self): | |
220 | msg = ("'context.bumped' is deprecated, " |
|
220 | msg = ("'context.bumped' is deprecated, " | |
221 | "use 'context.phasedivergent'") |
|
221 | "use 'context.phasedivergent'") | |
222 | self._repo.ui.deprecwarn(msg, '4.4') |
|
222 | self._repo.ui.deprecwarn(msg, '4.4') | |
223 | return self.phasedivergent() |
|
223 | return self.phasedivergent() | |
224 |
|
224 | |||
225 | def phasedivergent(self): |
|
225 | def phasedivergent(self): | |
226 | """True if the changeset try to be a successor of a public changeset |
|
226 | """True if the changeset try to be a successor of a public changeset | |
227 |
|
227 | |||
228 | Only non-public and non-obsolete changesets may be bumped. |
|
228 | Only non-public and non-obsolete changesets may be bumped. | |
229 | """ |
|
229 | """ | |
230 | return self.rev() in obsmod.getrevs(self._repo, 'phasedivergent') |
|
230 | return self.rev() in obsmod.getrevs(self._repo, 'phasedivergent') | |
231 |
|
231 | |||
232 | def divergent(self): |
|
232 | def divergent(self): | |
233 | msg = ("'context.divergent' is deprecated, " |
|
233 | msg = ("'context.divergent' is deprecated, " | |
234 | "use 'context.contentdivergent'") |
|
234 | "use 'context.contentdivergent'") | |
235 | self._repo.ui.deprecwarn(msg, '4.4') |
|
235 | self._repo.ui.deprecwarn(msg, '4.4') | |
236 | return self.contentdivergent() |
|
236 | return self.contentdivergent() | |
237 |
|
237 | |||
238 | def contentdivergent(self): |
|
238 | def contentdivergent(self): | |
239 | """Is a successors of a changeset with multiple possible successors set |
|
239 | """Is a successors of a changeset with multiple possible successors set | |
240 |
|
240 | |||
241 | Only non-public and non-obsolete changesets may be divergent. |
|
241 | Only non-public and non-obsolete changesets may be divergent. | |
242 | """ |
|
242 | """ | |
243 | return self.rev() in obsmod.getrevs(self._repo, 'contentdivergent') |
|
243 | return self.rev() in obsmod.getrevs(self._repo, 'contentdivergent') | |
244 |
|
244 | |||
245 | def troubled(self): |
|
245 | def troubled(self): | |
246 | msg = ("'context.troubled' is deprecated, " |
|
246 | msg = ("'context.troubled' is deprecated, " | |
247 | "use 'context.isunstable'") |
|
247 | "use 'context.isunstable'") | |
248 | self._repo.ui.deprecwarn(msg, '4.4') |
|
248 | self._repo.ui.deprecwarn(msg, '4.4') | |
249 | return self.isunstable() |
|
249 | return self.isunstable() | |
250 |
|
250 | |||
251 | def isunstable(self): |
|
251 | def isunstable(self): | |
252 | """True if the changeset is either unstable, bumped or divergent""" |
|
252 | """True if the changeset is either unstable, bumped or divergent""" | |
253 | return self.orphan() or self.phasedivergent() or self.contentdivergent() |
|
253 | return self.orphan() or self.phasedivergent() or self.contentdivergent() | |
254 |
|
254 | |||
255 | def troubles(self): |
|
255 | def troubles(self): | |
256 | """Keep the old version around in order to avoid breaking extensions |
|
256 | """Keep the old version around in order to avoid breaking extensions | |
257 | about different return values. |
|
257 | about different return values. | |
258 | """ |
|
258 | """ | |
259 | msg = ("'context.troubles' is deprecated, " |
|
259 | msg = ("'context.troubles' is deprecated, " | |
260 | "use 'context.instabilities'") |
|
260 | "use 'context.instabilities'") | |
261 | self._repo.ui.deprecwarn(msg, '4.4') |
|
261 | self._repo.ui.deprecwarn(msg, '4.4') | |
262 |
|
262 | |||
263 | troubles = [] |
|
263 | troubles = [] | |
264 | if self.orphan(): |
|
264 | if self.orphan(): | |
265 | troubles.append('orphan') |
|
265 | troubles.append('orphan') | |
266 | if self.phasedivergent(): |
|
266 | if self.phasedivergent(): | |
267 | troubles.append('bumped') |
|
267 | troubles.append('bumped') | |
268 | if self.contentdivergent(): |
|
268 | if self.contentdivergent(): | |
269 | troubles.append('divergent') |
|
269 | troubles.append('divergent') | |
270 | return troubles |
|
270 | return troubles | |
271 |
|
271 | |||
272 | def instabilities(self): |
|
272 | def instabilities(self): | |
273 | """return the list of instabilities affecting this changeset. |
|
273 | """return the list of instabilities affecting this changeset. | |
274 |
|
274 | |||
275 | Instabilities are returned as strings. possible values are: |
|
275 | Instabilities are returned as strings. possible values are: | |
276 | - orphan, |
|
276 | - orphan, | |
277 | - phase-divergent, |
|
277 | - phase-divergent, | |
278 | - content-divergent. |
|
278 | - content-divergent. | |
279 | """ |
|
279 | """ | |
280 | instabilities = [] |
|
280 | instabilities = [] | |
281 | if self.orphan(): |
|
281 | if self.orphan(): | |
282 | instabilities.append('orphan') |
|
282 | instabilities.append('orphan') | |
283 | if self.phasedivergent(): |
|
283 | if self.phasedivergent(): | |
284 | instabilities.append('phase-divergent') |
|
284 | instabilities.append('phase-divergent') | |
285 | if self.contentdivergent(): |
|
285 | if self.contentdivergent(): | |
286 | instabilities.append('content-divergent') |
|
286 | instabilities.append('content-divergent') | |
287 | return instabilities |
|
287 | return instabilities | |
288 |
|
288 | |||
289 | def parents(self): |
|
289 | def parents(self): | |
290 | """return contexts for each parent changeset""" |
|
290 | """return contexts for each parent changeset""" | |
291 | return self._parents |
|
291 | return self._parents | |
292 |
|
292 | |||
293 | def p1(self): |
|
293 | def p1(self): | |
294 | return self._parents[0] |
|
294 | return self._parents[0] | |
295 |
|
295 | |||
296 | def p2(self): |
|
296 | def p2(self): | |
297 | parents = self._parents |
|
297 | parents = self._parents | |
298 | if len(parents) == 2: |
|
298 | if len(parents) == 2: | |
299 | return parents[1] |
|
299 | return parents[1] | |
300 | return changectx(self._repo, nullrev) |
|
300 | return changectx(self._repo, nullrev) | |
301 |
|
301 | |||
302 | def _fileinfo(self, path): |
|
302 | def _fileinfo(self, path): | |
303 | if r'_manifest' in self.__dict__: |
|
303 | if r'_manifest' in self.__dict__: | |
304 | try: |
|
304 | try: | |
305 | return self._manifest[path], self._manifest.flags(path) |
|
305 | return self._manifest[path], self._manifest.flags(path) | |
306 | except KeyError: |
|
306 | except KeyError: | |
307 | raise error.ManifestLookupError(self._node, path, |
|
307 | raise error.ManifestLookupError(self._node, path, | |
308 | _('not found in manifest')) |
|
308 | _('not found in manifest')) | |
309 | if r'_manifestdelta' in self.__dict__ or path in self.files(): |
|
309 | if r'_manifestdelta' in self.__dict__ or path in self.files(): | |
310 | if path in self._manifestdelta: |
|
310 | if path in self._manifestdelta: | |
311 | return (self._manifestdelta[path], |
|
311 | return (self._manifestdelta[path], | |
312 | self._manifestdelta.flags(path)) |
|
312 | self._manifestdelta.flags(path)) | |
313 | mfl = self._repo.manifestlog |
|
313 | mfl = self._repo.manifestlog | |
314 | try: |
|
314 | try: | |
315 | node, flag = mfl[self._changeset.manifest].find(path) |
|
315 | node, flag = mfl[self._changeset.manifest].find(path) | |
316 | except KeyError: |
|
316 | except KeyError: | |
317 | raise error.ManifestLookupError(self._node, path, |
|
317 | raise error.ManifestLookupError(self._node, path, | |
318 | _('not found in manifest')) |
|
318 | _('not found in manifest')) | |
319 |
|
319 | |||
320 | return node, flag |
|
320 | return node, flag | |
321 |
|
321 | |||
322 | def filenode(self, path): |
|
322 | def filenode(self, path): | |
323 | return self._fileinfo(path)[0] |
|
323 | return self._fileinfo(path)[0] | |
324 |
|
324 | |||
325 | def flags(self, path): |
|
325 | def flags(self, path): | |
326 | try: |
|
326 | try: | |
327 | return self._fileinfo(path)[1] |
|
327 | return self._fileinfo(path)[1] | |
328 | except error.LookupError: |
|
328 | except error.LookupError: | |
329 | return '' |
|
329 | return '' | |
330 |
|
330 | |||
331 | def sub(self, path, allowcreate=True): |
|
331 | def sub(self, path, allowcreate=True): | |
332 | '''return a subrepo for the stored revision of path, never wdir()''' |
|
332 | '''return a subrepo for the stored revision of path, never wdir()''' | |
333 | return subrepo.subrepo(self, path, allowcreate=allowcreate) |
|
333 | return subrepo.subrepo(self, path, allowcreate=allowcreate) | |
334 |
|
334 | |||
335 | def nullsub(self, path, pctx): |
|
335 | def nullsub(self, path, pctx): | |
336 | return subrepo.nullsubrepo(self, path, pctx) |
|
336 | return subrepo.nullsubrepo(self, path, pctx) | |
337 |
|
337 | |||
338 | def workingsub(self, path): |
|
338 | def workingsub(self, path): | |
339 | '''return a subrepo for the stored revision, or wdir if this is a wdir |
|
339 | '''return a subrepo for the stored revision, or wdir if this is a wdir | |
340 | context. |
|
340 | context. | |
341 | ''' |
|
341 | ''' | |
342 | return subrepo.subrepo(self, path, allowwdir=True) |
|
342 | return subrepo.subrepo(self, path, allowwdir=True) | |
343 |
|
343 | |||
344 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
344 | def match(self, pats=None, include=None, exclude=None, default='glob', | |
345 | listsubrepos=False, badfn=None): |
|
345 | listsubrepos=False, badfn=None): | |
346 | r = self._repo |
|
346 | r = self._repo | |
347 | return matchmod.match(r.root, r.getcwd(), pats, |
|
347 | return matchmod.match(r.root, r.getcwd(), pats, | |
348 | include, exclude, default, |
|
348 | include, exclude, default, | |
349 | auditor=r.nofsauditor, ctx=self, |
|
349 | auditor=r.nofsauditor, ctx=self, | |
350 | listsubrepos=listsubrepos, badfn=badfn) |
|
350 | listsubrepos=listsubrepos, badfn=badfn) | |
351 |
|
351 | |||
352 | def diff(self, ctx2=None, match=None, **opts): |
|
352 | def diff(self, ctx2=None, match=None, **opts): | |
353 | """Returns a diff generator for the given contexts and matcher""" |
|
353 | """Returns a diff generator for the given contexts and matcher""" | |
354 | if ctx2 is None: |
|
354 | if ctx2 is None: | |
355 | ctx2 = self.p1() |
|
355 | ctx2 = self.p1() | |
356 | if ctx2 is not None: |
|
356 | if ctx2 is not None: | |
357 | ctx2 = self._repo[ctx2] |
|
357 | ctx2 = self._repo[ctx2] | |
358 | diffopts = patch.diffopts(self._repo.ui, pycompat.byteskwargs(opts)) |
|
358 | diffopts = patch.diffopts(self._repo.ui, pycompat.byteskwargs(opts)) | |
359 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) |
|
359 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) | |
360 |
|
360 | |||
361 | def dirs(self): |
|
361 | def dirs(self): | |
362 | return self._manifest.dirs() |
|
362 | return self._manifest.dirs() | |
363 |
|
363 | |||
364 | def hasdir(self, dir): |
|
364 | def hasdir(self, dir): | |
365 | return self._manifest.hasdir(dir) |
|
365 | return self._manifest.hasdir(dir) | |
366 |
|
366 | |||
367 | def status(self, other=None, match=None, listignored=False, |
|
367 | def status(self, other=None, match=None, listignored=False, | |
368 | listclean=False, listunknown=False, listsubrepos=False): |
|
368 | listclean=False, listunknown=False, listsubrepos=False): | |
369 | """return status of files between two nodes or node and working |
|
369 | """return status of files between two nodes or node and working | |
370 | directory. |
|
370 | directory. | |
371 |
|
371 | |||
372 | If other is None, compare this node with working directory. |
|
372 | If other is None, compare this node with working directory. | |
373 |
|
373 | |||
374 | returns (modified, added, removed, deleted, unknown, ignored, clean) |
|
374 | returns (modified, added, removed, deleted, unknown, ignored, clean) | |
375 | """ |
|
375 | """ | |
376 |
|
376 | |||
377 | ctx1 = self |
|
377 | ctx1 = self | |
378 | ctx2 = self._repo[other] |
|
378 | ctx2 = self._repo[other] | |
379 |
|
379 | |||
380 | # This next code block is, admittedly, fragile logic that tests for |
|
380 | # This next code block is, admittedly, fragile logic that tests for | |
381 | # reversing the contexts and wouldn't need to exist if it weren't for |
|
381 | # reversing the contexts and wouldn't need to exist if it weren't for | |
382 | # the fast (and common) code path of comparing the working directory |
|
382 | # the fast (and common) code path of comparing the working directory | |
383 | # with its first parent. |
|
383 | # with its first parent. | |
384 | # |
|
384 | # | |
385 | # What we're aiming for here is the ability to call: |
|
385 | # What we're aiming for here is the ability to call: | |
386 | # |
|
386 | # | |
387 | # workingctx.status(parentctx) |
|
387 | # workingctx.status(parentctx) | |
388 | # |
|
388 | # | |
389 | # If we always built the manifest for each context and compared those, |
|
389 | # If we always built the manifest for each context and compared those, | |
390 | # then we'd be done. But the special case of the above call means we |
|
390 | # then we'd be done. But the special case of the above call means we | |
391 | # just copy the manifest of the parent. |
|
391 | # just copy the manifest of the parent. | |
392 | reversed = False |
|
392 | reversed = False | |
393 | if (not isinstance(ctx1, changectx) |
|
393 | if (not isinstance(ctx1, changectx) | |
394 | and isinstance(ctx2, changectx)): |
|
394 | and isinstance(ctx2, changectx)): | |
395 | reversed = True |
|
395 | reversed = True | |
396 | ctx1, ctx2 = ctx2, ctx1 |
|
396 | ctx1, ctx2 = ctx2, ctx1 | |
397 |
|
397 | |||
398 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
398 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
399 | match = ctx2._matchstatus(ctx1, match) |
|
399 | match = ctx2._matchstatus(ctx1, match) | |
400 | r = scmutil.status([], [], [], [], [], [], []) |
|
400 | r = scmutil.status([], [], [], [], [], [], []) | |
401 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, |
|
401 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, | |
402 | listunknown) |
|
402 | listunknown) | |
403 |
|
403 | |||
404 | if reversed: |
|
404 | if reversed: | |
405 | # Reverse added and removed. Clear deleted, unknown and ignored as |
|
405 | # Reverse added and removed. Clear deleted, unknown and ignored as | |
406 | # these make no sense to reverse. |
|
406 | # these make no sense to reverse. | |
407 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], |
|
407 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], | |
408 | r.clean) |
|
408 | r.clean) | |
409 |
|
409 | |||
410 | if listsubrepos: |
|
410 | if listsubrepos: | |
411 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
411 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): | |
412 | try: |
|
412 | try: | |
413 | rev2 = ctx2.subrev(subpath) |
|
413 | rev2 = ctx2.subrev(subpath) | |
414 | except KeyError: |
|
414 | except KeyError: | |
415 | # A subrepo that existed in node1 was deleted between |
|
415 | # A subrepo that existed in node1 was deleted between | |
416 | # node1 and node2 (inclusive). Thus, ctx2's substate |
|
416 | # node1 and node2 (inclusive). Thus, ctx2's substate | |
417 | # won't contain that subpath. The best we can do ignore it. |
|
417 | # won't contain that subpath. The best we can do ignore it. | |
418 | rev2 = None |
|
418 | rev2 = None | |
419 | submatch = matchmod.subdirmatcher(subpath, match) |
|
419 | submatch = matchmod.subdirmatcher(subpath, match) | |
420 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
420 | s = sub.status(rev2, match=submatch, ignored=listignored, | |
421 | clean=listclean, unknown=listunknown, |
|
421 | clean=listclean, unknown=listunknown, | |
422 | listsubrepos=True) |
|
422 | listsubrepos=True) | |
423 | for rfiles, sfiles in zip(r, s): |
|
423 | for rfiles, sfiles in zip(r, s): | |
424 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
424 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) | |
425 |
|
425 | |||
426 | for l in r: |
|
426 | for l in r: | |
427 | l.sort() |
|
427 | l.sort() | |
428 |
|
428 | |||
429 | return r |
|
429 | return r | |
430 |
|
430 | |||
431 | def _filterederror(repo, changeid): |
|
431 | def _filterederror(repo, changeid): | |
432 | """build an exception to be raised about a filtered changeid |
|
432 | """build an exception to be raised about a filtered changeid | |
433 |
|
433 | |||
434 | This is extracted in a function to help extensions (eg: evolve) to |
|
434 | This is extracted in a function to help extensions (eg: evolve) to | |
435 | experiment with various message variants.""" |
|
435 | experiment with various message variants.""" | |
436 | if repo.filtername.startswith('visible'): |
|
436 | if repo.filtername.startswith('visible'): | |
437 |
|
437 | |||
438 | # Check if the changeset is obsolete |
|
438 | # Check if the changeset is obsolete | |
439 | unfilteredrepo = repo.unfiltered() |
|
439 | unfilteredrepo = repo.unfiltered() | |
440 | ctx = unfilteredrepo[changeid] |
|
440 | ctx = unfilteredrepo[changeid] | |
441 |
|
441 | |||
442 | # If the changeset is obsolete, enrich the message with the reason |
|
442 | # If the changeset is obsolete, enrich the message with the reason | |
443 | # that made this changeset not visible |
|
443 | # that made this changeset not visible | |
444 | if ctx.obsolete(): |
|
444 | if ctx.obsolete(): | |
445 |
msg = obsutil._getfilteredreason( |
|
445 | msg = obsutil._getfilteredreason(repo, changeid, ctx) | |
446 | else: |
|
446 | else: | |
447 | msg = _("hidden revision '%s'") % changeid |
|
447 | msg = _("hidden revision '%s'") % changeid | |
448 |
|
448 | |||
449 | hint = _('use --hidden to access hidden revisions') |
|
449 | hint = _('use --hidden to access hidden revisions') | |
450 |
|
450 | |||
451 | return error.FilteredRepoLookupError(msg, hint=hint) |
|
451 | return error.FilteredRepoLookupError(msg, hint=hint) | |
452 | msg = _("filtered revision '%s' (not in '%s' subset)") |
|
452 | msg = _("filtered revision '%s' (not in '%s' subset)") | |
453 | msg %= (changeid, repo.filtername) |
|
453 | msg %= (changeid, repo.filtername) | |
454 | return error.FilteredRepoLookupError(msg) |
|
454 | return error.FilteredRepoLookupError(msg) | |
455 |
|
455 | |||
456 | class changectx(basectx): |
|
456 | class changectx(basectx): | |
457 | """A changecontext object makes access to data related to a particular |
|
457 | """A changecontext object makes access to data related to a particular | |
458 | changeset convenient. It represents a read-only context already present in |
|
458 | changeset convenient. It represents a read-only context already present in | |
459 | the repo.""" |
|
459 | the repo.""" | |
460 | def __init__(self, repo, changeid=''): |
|
460 | def __init__(self, repo, changeid=''): | |
461 | """changeid is a revision number, node, or tag""" |
|
461 | """changeid is a revision number, node, or tag""" | |
462 |
|
462 | |||
463 | # since basectx.__new__ already took care of copying the object, we |
|
463 | # since basectx.__new__ already took care of copying the object, we | |
464 | # don't need to do anything in __init__, so we just exit here |
|
464 | # don't need to do anything in __init__, so we just exit here | |
465 | if isinstance(changeid, basectx): |
|
465 | if isinstance(changeid, basectx): | |
466 | return |
|
466 | return | |
467 |
|
467 | |||
468 | if changeid == '': |
|
468 | if changeid == '': | |
469 | changeid = '.' |
|
469 | changeid = '.' | |
470 | self._repo = repo |
|
470 | self._repo = repo | |
471 |
|
471 | |||
472 | try: |
|
472 | try: | |
473 | if isinstance(changeid, int): |
|
473 | if isinstance(changeid, int): | |
474 | self._node = repo.changelog.node(changeid) |
|
474 | self._node = repo.changelog.node(changeid) | |
475 | self._rev = changeid |
|
475 | self._rev = changeid | |
476 | return |
|
476 | return | |
477 | if not pycompat.ispy3 and isinstance(changeid, long): |
|
477 | if not pycompat.ispy3 and isinstance(changeid, long): | |
478 | changeid = str(changeid) |
|
478 | changeid = str(changeid) | |
479 | if changeid == 'null': |
|
479 | if changeid == 'null': | |
480 | self._node = nullid |
|
480 | self._node = nullid | |
481 | self._rev = nullrev |
|
481 | self._rev = nullrev | |
482 | return |
|
482 | return | |
483 | if changeid == 'tip': |
|
483 | if changeid == 'tip': | |
484 | self._node = repo.changelog.tip() |
|
484 | self._node = repo.changelog.tip() | |
485 | self._rev = repo.changelog.rev(self._node) |
|
485 | self._rev = repo.changelog.rev(self._node) | |
486 | return |
|
486 | return | |
487 | if (changeid == '.' |
|
487 | if (changeid == '.' | |
488 | or repo.local() and changeid == repo.dirstate.p1()): |
|
488 | or repo.local() and changeid == repo.dirstate.p1()): | |
489 | # this is a hack to delay/avoid loading obsmarkers |
|
489 | # this is a hack to delay/avoid loading obsmarkers | |
490 | # when we know that '.' won't be hidden |
|
490 | # when we know that '.' won't be hidden | |
491 | self._node = repo.dirstate.p1() |
|
491 | self._node = repo.dirstate.p1() | |
492 | self._rev = repo.unfiltered().changelog.rev(self._node) |
|
492 | self._rev = repo.unfiltered().changelog.rev(self._node) | |
493 | return |
|
493 | return | |
494 | if len(changeid) == 20: |
|
494 | if len(changeid) == 20: | |
495 | try: |
|
495 | try: | |
496 | self._node = changeid |
|
496 | self._node = changeid | |
497 | self._rev = repo.changelog.rev(changeid) |
|
497 | self._rev = repo.changelog.rev(changeid) | |
498 | return |
|
498 | return | |
499 | except error.FilteredRepoLookupError: |
|
499 | except error.FilteredRepoLookupError: | |
500 | raise |
|
500 | raise | |
501 | except LookupError: |
|
501 | except LookupError: | |
502 | pass |
|
502 | pass | |
503 |
|
503 | |||
504 | try: |
|
504 | try: | |
505 | r = int(changeid) |
|
505 | r = int(changeid) | |
506 | if '%d' % r != changeid: |
|
506 | if '%d' % r != changeid: | |
507 | raise ValueError |
|
507 | raise ValueError | |
508 | l = len(repo.changelog) |
|
508 | l = len(repo.changelog) | |
509 | if r < 0: |
|
509 | if r < 0: | |
510 | r += l |
|
510 | r += l | |
511 | if r < 0 or r >= l and r != wdirrev: |
|
511 | if r < 0 or r >= l and r != wdirrev: | |
512 | raise ValueError |
|
512 | raise ValueError | |
513 | self._rev = r |
|
513 | self._rev = r | |
514 | self._node = repo.changelog.node(r) |
|
514 | self._node = repo.changelog.node(r) | |
515 | return |
|
515 | return | |
516 | except error.FilteredIndexError: |
|
516 | except error.FilteredIndexError: | |
517 | raise |
|
517 | raise | |
518 | except (ValueError, OverflowError, IndexError): |
|
518 | except (ValueError, OverflowError, IndexError): | |
519 | pass |
|
519 | pass | |
520 |
|
520 | |||
521 | if len(changeid) == 40: |
|
521 | if len(changeid) == 40: | |
522 | try: |
|
522 | try: | |
523 | self._node = bin(changeid) |
|
523 | self._node = bin(changeid) | |
524 | self._rev = repo.changelog.rev(self._node) |
|
524 | self._rev = repo.changelog.rev(self._node) | |
525 | return |
|
525 | return | |
526 | except error.FilteredLookupError: |
|
526 | except error.FilteredLookupError: | |
527 | raise |
|
527 | raise | |
528 | except (TypeError, LookupError): |
|
528 | except (TypeError, LookupError): | |
529 | pass |
|
529 | pass | |
530 |
|
530 | |||
531 | # lookup bookmarks through the name interface |
|
531 | # lookup bookmarks through the name interface | |
532 | try: |
|
532 | try: | |
533 | self._node = repo.names.singlenode(repo, changeid) |
|
533 | self._node = repo.names.singlenode(repo, changeid) | |
534 | self._rev = repo.changelog.rev(self._node) |
|
534 | self._rev = repo.changelog.rev(self._node) | |
535 | return |
|
535 | return | |
536 | except KeyError: |
|
536 | except KeyError: | |
537 | pass |
|
537 | pass | |
538 | except error.FilteredRepoLookupError: |
|
538 | except error.FilteredRepoLookupError: | |
539 | raise |
|
539 | raise | |
540 | except error.RepoLookupError: |
|
540 | except error.RepoLookupError: | |
541 | pass |
|
541 | pass | |
542 |
|
542 | |||
543 | self._node = repo.unfiltered().changelog._partialmatch(changeid) |
|
543 | self._node = repo.unfiltered().changelog._partialmatch(changeid) | |
544 | if self._node is not None: |
|
544 | if self._node is not None: | |
545 | self._rev = repo.changelog.rev(self._node) |
|
545 | self._rev = repo.changelog.rev(self._node) | |
546 | return |
|
546 | return | |
547 |
|
547 | |||
548 | # lookup failed |
|
548 | # lookup failed | |
549 | # check if it might have come from damaged dirstate |
|
549 | # check if it might have come from damaged dirstate | |
550 | # |
|
550 | # | |
551 | # XXX we could avoid the unfiltered if we had a recognizable |
|
551 | # XXX we could avoid the unfiltered if we had a recognizable | |
552 | # exception for filtered changeset access |
|
552 | # exception for filtered changeset access | |
553 | if (repo.local() |
|
553 | if (repo.local() | |
554 | and changeid in repo.unfiltered().dirstate.parents()): |
|
554 | and changeid in repo.unfiltered().dirstate.parents()): | |
555 | msg = _("working directory has unknown parent '%s'!") |
|
555 | msg = _("working directory has unknown parent '%s'!") | |
556 | raise error.Abort(msg % short(changeid)) |
|
556 | raise error.Abort(msg % short(changeid)) | |
557 | try: |
|
557 | try: | |
558 | if len(changeid) == 20 and nonascii(changeid): |
|
558 | if len(changeid) == 20 and nonascii(changeid): | |
559 | changeid = hex(changeid) |
|
559 | changeid = hex(changeid) | |
560 | except TypeError: |
|
560 | except TypeError: | |
561 | pass |
|
561 | pass | |
562 | except (error.FilteredIndexError, error.FilteredLookupError, |
|
562 | except (error.FilteredIndexError, error.FilteredLookupError, | |
563 | error.FilteredRepoLookupError): |
|
563 | error.FilteredRepoLookupError): | |
564 | raise _filterederror(repo, changeid) |
|
564 | raise _filterederror(repo, changeid) | |
565 | except IndexError: |
|
565 | except IndexError: | |
566 | pass |
|
566 | pass | |
567 | raise error.RepoLookupError( |
|
567 | raise error.RepoLookupError( | |
568 | _("unknown revision '%s'") % changeid) |
|
568 | _("unknown revision '%s'") % changeid) | |
569 |
|
569 | |||
570 | def __hash__(self): |
|
570 | def __hash__(self): | |
571 | try: |
|
571 | try: | |
572 | return hash(self._rev) |
|
572 | return hash(self._rev) | |
573 | except AttributeError: |
|
573 | except AttributeError: | |
574 | return id(self) |
|
574 | return id(self) | |
575 |
|
575 | |||
576 | def __nonzero__(self): |
|
576 | def __nonzero__(self): | |
577 | return self._rev != nullrev |
|
577 | return self._rev != nullrev | |
578 |
|
578 | |||
579 | __bool__ = __nonzero__ |
|
579 | __bool__ = __nonzero__ | |
580 |
|
580 | |||
581 | @propertycache |
|
581 | @propertycache | |
582 | def _changeset(self): |
|
582 | def _changeset(self): | |
583 | return self._repo.changelog.changelogrevision(self.rev()) |
|
583 | return self._repo.changelog.changelogrevision(self.rev()) | |
584 |
|
584 | |||
585 | @propertycache |
|
585 | @propertycache | |
586 | def _manifest(self): |
|
586 | def _manifest(self): | |
587 | return self._manifestctx.read() |
|
587 | return self._manifestctx.read() | |
588 |
|
588 | |||
589 | @property |
|
589 | @property | |
590 | def _manifestctx(self): |
|
590 | def _manifestctx(self): | |
591 | return self._repo.manifestlog[self._changeset.manifest] |
|
591 | return self._repo.manifestlog[self._changeset.manifest] | |
592 |
|
592 | |||
593 | @propertycache |
|
593 | @propertycache | |
594 | def _manifestdelta(self): |
|
594 | def _manifestdelta(self): | |
595 | return self._manifestctx.readdelta() |
|
595 | return self._manifestctx.readdelta() | |
596 |
|
596 | |||
597 | @propertycache |
|
597 | @propertycache | |
598 | def _parents(self): |
|
598 | def _parents(self): | |
599 | repo = self._repo |
|
599 | repo = self._repo | |
600 | p1, p2 = repo.changelog.parentrevs(self._rev) |
|
600 | p1, p2 = repo.changelog.parentrevs(self._rev) | |
601 | if p2 == nullrev: |
|
601 | if p2 == nullrev: | |
602 | return [changectx(repo, p1)] |
|
602 | return [changectx(repo, p1)] | |
603 | return [changectx(repo, p1), changectx(repo, p2)] |
|
603 | return [changectx(repo, p1), changectx(repo, p2)] | |
604 |
|
604 | |||
605 | def changeset(self): |
|
605 | def changeset(self): | |
606 | c = self._changeset |
|
606 | c = self._changeset | |
607 | return ( |
|
607 | return ( | |
608 | c.manifest, |
|
608 | c.manifest, | |
609 | c.user, |
|
609 | c.user, | |
610 | c.date, |
|
610 | c.date, | |
611 | c.files, |
|
611 | c.files, | |
612 | c.description, |
|
612 | c.description, | |
613 | c.extra, |
|
613 | c.extra, | |
614 | ) |
|
614 | ) | |
615 | def manifestnode(self): |
|
615 | def manifestnode(self): | |
616 | return self._changeset.manifest |
|
616 | return self._changeset.manifest | |
617 |
|
617 | |||
618 | def user(self): |
|
618 | def user(self): | |
619 | return self._changeset.user |
|
619 | return self._changeset.user | |
620 | def date(self): |
|
620 | def date(self): | |
621 | return self._changeset.date |
|
621 | return self._changeset.date | |
622 | def files(self): |
|
622 | def files(self): | |
623 | return self._changeset.files |
|
623 | return self._changeset.files | |
624 | def description(self): |
|
624 | def description(self): | |
625 | return self._changeset.description |
|
625 | return self._changeset.description | |
626 | def branch(self): |
|
626 | def branch(self): | |
627 | return encoding.tolocal(self._changeset.extra.get("branch")) |
|
627 | return encoding.tolocal(self._changeset.extra.get("branch")) | |
628 | def closesbranch(self): |
|
628 | def closesbranch(self): | |
629 | return 'close' in self._changeset.extra |
|
629 | return 'close' in self._changeset.extra | |
630 | def extra(self): |
|
630 | def extra(self): | |
631 | """Return a dict of extra information.""" |
|
631 | """Return a dict of extra information.""" | |
632 | return self._changeset.extra |
|
632 | return self._changeset.extra | |
633 | def tags(self): |
|
633 | def tags(self): | |
634 | """Return a list of byte tag names""" |
|
634 | """Return a list of byte tag names""" | |
635 | return self._repo.nodetags(self._node) |
|
635 | return self._repo.nodetags(self._node) | |
636 | def bookmarks(self): |
|
636 | def bookmarks(self): | |
637 | """Return a list of byte bookmark names.""" |
|
637 | """Return a list of byte bookmark names.""" | |
638 | return self._repo.nodebookmarks(self._node) |
|
638 | return self._repo.nodebookmarks(self._node) | |
639 | def phase(self): |
|
639 | def phase(self): | |
640 | return self._repo._phasecache.phase(self._repo, self._rev) |
|
640 | return self._repo._phasecache.phase(self._repo, self._rev) | |
641 | def hidden(self): |
|
641 | def hidden(self): | |
642 | return self._rev in repoview.filterrevs(self._repo, 'visible') |
|
642 | return self._rev in repoview.filterrevs(self._repo, 'visible') | |
643 |
|
643 | |||
644 | def isinmemory(self): |
|
644 | def isinmemory(self): | |
645 | return False |
|
645 | return False | |
646 |
|
646 | |||
647 | def children(self): |
|
647 | def children(self): | |
648 | """return list of changectx contexts for each child changeset. |
|
648 | """return list of changectx contexts for each child changeset. | |
649 |
|
649 | |||
650 | This returns only the immediate child changesets. Use descendants() to |
|
650 | This returns only the immediate child changesets. Use descendants() to | |
651 | recursively walk children. |
|
651 | recursively walk children. | |
652 | """ |
|
652 | """ | |
653 | c = self._repo.changelog.children(self._node) |
|
653 | c = self._repo.changelog.children(self._node) | |
654 | return [changectx(self._repo, x) for x in c] |
|
654 | return [changectx(self._repo, x) for x in c] | |
655 |
|
655 | |||
656 | def ancestors(self): |
|
656 | def ancestors(self): | |
657 | for a in self._repo.changelog.ancestors([self._rev]): |
|
657 | for a in self._repo.changelog.ancestors([self._rev]): | |
658 | yield changectx(self._repo, a) |
|
658 | yield changectx(self._repo, a) | |
659 |
|
659 | |||
660 | def descendants(self): |
|
660 | def descendants(self): | |
661 | """Recursively yield all children of the changeset. |
|
661 | """Recursively yield all children of the changeset. | |
662 |
|
662 | |||
663 | For just the immediate children, use children() |
|
663 | For just the immediate children, use children() | |
664 | """ |
|
664 | """ | |
665 | for d in self._repo.changelog.descendants([self._rev]): |
|
665 | for d in self._repo.changelog.descendants([self._rev]): | |
666 | yield changectx(self._repo, d) |
|
666 | yield changectx(self._repo, d) | |
667 |
|
667 | |||
668 | def filectx(self, path, fileid=None, filelog=None): |
|
668 | def filectx(self, path, fileid=None, filelog=None): | |
669 | """get a file context from this changeset""" |
|
669 | """get a file context from this changeset""" | |
670 | if fileid is None: |
|
670 | if fileid is None: | |
671 | fileid = self.filenode(path) |
|
671 | fileid = self.filenode(path) | |
672 | return filectx(self._repo, path, fileid=fileid, |
|
672 | return filectx(self._repo, path, fileid=fileid, | |
673 | changectx=self, filelog=filelog) |
|
673 | changectx=self, filelog=filelog) | |
674 |
|
674 | |||
675 | def ancestor(self, c2, warn=False): |
|
675 | def ancestor(self, c2, warn=False): | |
676 | """return the "best" ancestor context of self and c2 |
|
676 | """return the "best" ancestor context of self and c2 | |
677 |
|
677 | |||
678 | If there are multiple candidates, it will show a message and check |
|
678 | If there are multiple candidates, it will show a message and check | |
679 | merge.preferancestor configuration before falling back to the |
|
679 | merge.preferancestor configuration before falling back to the | |
680 | revlog ancestor.""" |
|
680 | revlog ancestor.""" | |
681 | # deal with workingctxs |
|
681 | # deal with workingctxs | |
682 | n2 = c2._node |
|
682 | n2 = c2._node | |
683 | if n2 is None: |
|
683 | if n2 is None: | |
684 | n2 = c2._parents[0]._node |
|
684 | n2 = c2._parents[0]._node | |
685 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) |
|
685 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) | |
686 | if not cahs: |
|
686 | if not cahs: | |
687 | anc = nullid |
|
687 | anc = nullid | |
688 | elif len(cahs) == 1: |
|
688 | elif len(cahs) == 1: | |
689 | anc = cahs[0] |
|
689 | anc = cahs[0] | |
690 | else: |
|
690 | else: | |
691 | # experimental config: merge.preferancestor |
|
691 | # experimental config: merge.preferancestor | |
692 | for r in self._repo.ui.configlist('merge', 'preferancestor'): |
|
692 | for r in self._repo.ui.configlist('merge', 'preferancestor'): | |
693 | try: |
|
693 | try: | |
694 | ctx = changectx(self._repo, r) |
|
694 | ctx = changectx(self._repo, r) | |
695 | except error.RepoLookupError: |
|
695 | except error.RepoLookupError: | |
696 | continue |
|
696 | continue | |
697 | anc = ctx.node() |
|
697 | anc = ctx.node() | |
698 | if anc in cahs: |
|
698 | if anc in cahs: | |
699 | break |
|
699 | break | |
700 | else: |
|
700 | else: | |
701 | anc = self._repo.changelog.ancestor(self._node, n2) |
|
701 | anc = self._repo.changelog.ancestor(self._node, n2) | |
702 | if warn: |
|
702 | if warn: | |
703 | self._repo.ui.status( |
|
703 | self._repo.ui.status( | |
704 | (_("note: using %s as ancestor of %s and %s\n") % |
|
704 | (_("note: using %s as ancestor of %s and %s\n") % | |
705 | (short(anc), short(self._node), short(n2))) + |
|
705 | (short(anc), short(self._node), short(n2))) + | |
706 | ''.join(_(" alternatively, use --config " |
|
706 | ''.join(_(" alternatively, use --config " | |
707 | "merge.preferancestor=%s\n") % |
|
707 | "merge.preferancestor=%s\n") % | |
708 | short(n) for n in sorted(cahs) if n != anc)) |
|
708 | short(n) for n in sorted(cahs) if n != anc)) | |
709 | return changectx(self._repo, anc) |
|
709 | return changectx(self._repo, anc) | |
710 |
|
710 | |||
711 | def descendant(self, other): |
|
711 | def descendant(self, other): | |
712 | """True if other is descendant of this changeset""" |
|
712 | """True if other is descendant of this changeset""" | |
713 | return self._repo.changelog.descendant(self._rev, other._rev) |
|
713 | return self._repo.changelog.descendant(self._rev, other._rev) | |
714 |
|
714 | |||
715 | def walk(self, match): |
|
715 | def walk(self, match): | |
716 | '''Generates matching file names.''' |
|
716 | '''Generates matching file names.''' | |
717 |
|
717 | |||
718 | # Wrap match.bad method to have message with nodeid |
|
718 | # Wrap match.bad method to have message with nodeid | |
719 | def bad(fn, msg): |
|
719 | def bad(fn, msg): | |
720 | # The manifest doesn't know about subrepos, so don't complain about |
|
720 | # The manifest doesn't know about subrepos, so don't complain about | |
721 | # paths into valid subrepos. |
|
721 | # paths into valid subrepos. | |
722 | if any(fn == s or fn.startswith(s + '/') |
|
722 | if any(fn == s or fn.startswith(s + '/') | |
723 | for s in self.substate): |
|
723 | for s in self.substate): | |
724 | return |
|
724 | return | |
725 | match.bad(fn, _('no such file in rev %s') % self) |
|
725 | match.bad(fn, _('no such file in rev %s') % self) | |
726 |
|
726 | |||
727 | m = matchmod.badmatch(match, bad) |
|
727 | m = matchmod.badmatch(match, bad) | |
728 | return self._manifest.walk(m) |
|
728 | return self._manifest.walk(m) | |
729 |
|
729 | |||
730 | def matches(self, match): |
|
730 | def matches(self, match): | |
731 | return self.walk(match) |
|
731 | return self.walk(match) | |
732 |
|
732 | |||
733 | class basefilectx(object): |
|
733 | class basefilectx(object): | |
734 | """A filecontext object represents the common logic for its children: |
|
734 | """A filecontext object represents the common logic for its children: | |
735 | filectx: read-only access to a filerevision that is already present |
|
735 | filectx: read-only access to a filerevision that is already present | |
736 | in the repo, |
|
736 | in the repo, | |
737 | workingfilectx: a filecontext that represents files from the working |
|
737 | workingfilectx: a filecontext that represents files from the working | |
738 | directory, |
|
738 | directory, | |
739 | memfilectx: a filecontext that represents files in-memory, |
|
739 | memfilectx: a filecontext that represents files in-memory, | |
740 | overlayfilectx: duplicate another filecontext with some fields overridden. |
|
740 | overlayfilectx: duplicate another filecontext with some fields overridden. | |
741 | """ |
|
741 | """ | |
742 | @propertycache |
|
742 | @propertycache | |
743 | def _filelog(self): |
|
743 | def _filelog(self): | |
744 | return self._repo.file(self._path) |
|
744 | return self._repo.file(self._path) | |
745 |
|
745 | |||
746 | @propertycache |
|
746 | @propertycache | |
747 | def _changeid(self): |
|
747 | def _changeid(self): | |
748 | if r'_changeid' in self.__dict__: |
|
748 | if r'_changeid' in self.__dict__: | |
749 | return self._changeid |
|
749 | return self._changeid | |
750 | elif r'_changectx' in self.__dict__: |
|
750 | elif r'_changectx' in self.__dict__: | |
751 | return self._changectx.rev() |
|
751 | return self._changectx.rev() | |
752 | elif r'_descendantrev' in self.__dict__: |
|
752 | elif r'_descendantrev' in self.__dict__: | |
753 | # this file context was created from a revision with a known |
|
753 | # this file context was created from a revision with a known | |
754 | # descendant, we can (lazily) correct for linkrev aliases |
|
754 | # descendant, we can (lazily) correct for linkrev aliases | |
755 | return self._adjustlinkrev(self._descendantrev) |
|
755 | return self._adjustlinkrev(self._descendantrev) | |
756 | else: |
|
756 | else: | |
757 | return self._filelog.linkrev(self._filerev) |
|
757 | return self._filelog.linkrev(self._filerev) | |
758 |
|
758 | |||
759 | @propertycache |
|
759 | @propertycache | |
760 | def _filenode(self): |
|
760 | def _filenode(self): | |
761 | if r'_fileid' in self.__dict__: |
|
761 | if r'_fileid' in self.__dict__: | |
762 | return self._filelog.lookup(self._fileid) |
|
762 | return self._filelog.lookup(self._fileid) | |
763 | else: |
|
763 | else: | |
764 | return self._changectx.filenode(self._path) |
|
764 | return self._changectx.filenode(self._path) | |
765 |
|
765 | |||
766 | @propertycache |
|
766 | @propertycache | |
767 | def _filerev(self): |
|
767 | def _filerev(self): | |
768 | return self._filelog.rev(self._filenode) |
|
768 | return self._filelog.rev(self._filenode) | |
769 |
|
769 | |||
770 | @propertycache |
|
770 | @propertycache | |
771 | def _repopath(self): |
|
771 | def _repopath(self): | |
772 | return self._path |
|
772 | return self._path | |
773 |
|
773 | |||
774 | def __nonzero__(self): |
|
774 | def __nonzero__(self): | |
775 | try: |
|
775 | try: | |
776 | self._filenode |
|
776 | self._filenode | |
777 | return True |
|
777 | return True | |
778 | except error.LookupError: |
|
778 | except error.LookupError: | |
779 | # file is missing |
|
779 | # file is missing | |
780 | return False |
|
780 | return False | |
781 |
|
781 | |||
782 | __bool__ = __nonzero__ |
|
782 | __bool__ = __nonzero__ | |
783 |
|
783 | |||
784 | def __bytes__(self): |
|
784 | def __bytes__(self): | |
785 | try: |
|
785 | try: | |
786 | return "%s@%s" % (self.path(), self._changectx) |
|
786 | return "%s@%s" % (self.path(), self._changectx) | |
787 | except error.LookupError: |
|
787 | except error.LookupError: | |
788 | return "%s@???" % self.path() |
|
788 | return "%s@???" % self.path() | |
789 |
|
789 | |||
790 | __str__ = encoding.strmethod(__bytes__) |
|
790 | __str__ = encoding.strmethod(__bytes__) | |
791 |
|
791 | |||
792 | def __repr__(self): |
|
792 | def __repr__(self): | |
793 | return "<%s %s>" % (type(self).__name__, str(self)) |
|
793 | return "<%s %s>" % (type(self).__name__, str(self)) | |
794 |
|
794 | |||
795 | def __hash__(self): |
|
795 | def __hash__(self): | |
796 | try: |
|
796 | try: | |
797 | return hash((self._path, self._filenode)) |
|
797 | return hash((self._path, self._filenode)) | |
798 | except AttributeError: |
|
798 | except AttributeError: | |
799 | return id(self) |
|
799 | return id(self) | |
800 |
|
800 | |||
801 | def __eq__(self, other): |
|
801 | def __eq__(self, other): | |
802 | try: |
|
802 | try: | |
803 | return (type(self) == type(other) and self._path == other._path |
|
803 | return (type(self) == type(other) and self._path == other._path | |
804 | and self._filenode == other._filenode) |
|
804 | and self._filenode == other._filenode) | |
805 | except AttributeError: |
|
805 | except AttributeError: | |
806 | return False |
|
806 | return False | |
807 |
|
807 | |||
808 | def __ne__(self, other): |
|
808 | def __ne__(self, other): | |
809 | return not (self == other) |
|
809 | return not (self == other) | |
810 |
|
810 | |||
811 | def filerev(self): |
|
811 | def filerev(self): | |
812 | return self._filerev |
|
812 | return self._filerev | |
813 | def filenode(self): |
|
813 | def filenode(self): | |
814 | return self._filenode |
|
814 | return self._filenode | |
815 | @propertycache |
|
815 | @propertycache | |
816 | def _flags(self): |
|
816 | def _flags(self): | |
817 | return self._changectx.flags(self._path) |
|
817 | return self._changectx.flags(self._path) | |
818 | def flags(self): |
|
818 | def flags(self): | |
819 | return self._flags |
|
819 | return self._flags | |
820 | def filelog(self): |
|
820 | def filelog(self): | |
821 | return self._filelog |
|
821 | return self._filelog | |
822 | def rev(self): |
|
822 | def rev(self): | |
823 | return self._changeid |
|
823 | return self._changeid | |
824 | def linkrev(self): |
|
824 | def linkrev(self): | |
825 | return self._filelog.linkrev(self._filerev) |
|
825 | return self._filelog.linkrev(self._filerev) | |
826 | def node(self): |
|
826 | def node(self): | |
827 | return self._changectx.node() |
|
827 | return self._changectx.node() | |
828 | def hex(self): |
|
828 | def hex(self): | |
829 | return self._changectx.hex() |
|
829 | return self._changectx.hex() | |
830 | def user(self): |
|
830 | def user(self): | |
831 | return self._changectx.user() |
|
831 | return self._changectx.user() | |
832 | def date(self): |
|
832 | def date(self): | |
833 | return self._changectx.date() |
|
833 | return self._changectx.date() | |
834 | def files(self): |
|
834 | def files(self): | |
835 | return self._changectx.files() |
|
835 | return self._changectx.files() | |
836 | def description(self): |
|
836 | def description(self): | |
837 | return self._changectx.description() |
|
837 | return self._changectx.description() | |
838 | def branch(self): |
|
838 | def branch(self): | |
839 | return self._changectx.branch() |
|
839 | return self._changectx.branch() | |
840 | def extra(self): |
|
840 | def extra(self): | |
841 | return self._changectx.extra() |
|
841 | return self._changectx.extra() | |
842 | def phase(self): |
|
842 | def phase(self): | |
843 | return self._changectx.phase() |
|
843 | return self._changectx.phase() | |
844 | def phasestr(self): |
|
844 | def phasestr(self): | |
845 | return self._changectx.phasestr() |
|
845 | return self._changectx.phasestr() | |
846 | def obsolete(self): |
|
846 | def obsolete(self): | |
847 | return self._changectx.obsolete() |
|
847 | return self._changectx.obsolete() | |
848 | def instabilities(self): |
|
848 | def instabilities(self): | |
849 | return self._changectx.instabilities() |
|
849 | return self._changectx.instabilities() | |
850 | def manifest(self): |
|
850 | def manifest(self): | |
851 | return self._changectx.manifest() |
|
851 | return self._changectx.manifest() | |
852 | def changectx(self): |
|
852 | def changectx(self): | |
853 | return self._changectx |
|
853 | return self._changectx | |
854 | def renamed(self): |
|
854 | def renamed(self): | |
855 | return self._copied |
|
855 | return self._copied | |
856 | def repo(self): |
|
856 | def repo(self): | |
857 | return self._repo |
|
857 | return self._repo | |
858 | def size(self): |
|
858 | def size(self): | |
859 | return len(self.data()) |
|
859 | return len(self.data()) | |
860 |
|
860 | |||
861 | def path(self): |
|
861 | def path(self): | |
862 | return self._path |
|
862 | return self._path | |
863 |
|
863 | |||
864 | def isbinary(self): |
|
864 | def isbinary(self): | |
865 | try: |
|
865 | try: | |
866 | return util.binary(self.data()) |
|
866 | return util.binary(self.data()) | |
867 | except IOError: |
|
867 | except IOError: | |
868 | return False |
|
868 | return False | |
869 | def isexec(self): |
|
869 | def isexec(self): | |
870 | return 'x' in self.flags() |
|
870 | return 'x' in self.flags() | |
871 | def islink(self): |
|
871 | def islink(self): | |
872 | return 'l' in self.flags() |
|
872 | return 'l' in self.flags() | |
873 |
|
873 | |||
874 | def isabsent(self): |
|
874 | def isabsent(self): | |
875 | """whether this filectx represents a file not in self._changectx |
|
875 | """whether this filectx represents a file not in self._changectx | |
876 |
|
876 | |||
877 | This is mainly for merge code to detect change/delete conflicts. This is |
|
877 | This is mainly for merge code to detect change/delete conflicts. This is | |
878 | expected to be True for all subclasses of basectx.""" |
|
878 | expected to be True for all subclasses of basectx.""" | |
879 | return False |
|
879 | return False | |
880 |
|
880 | |||
881 | _customcmp = False |
|
881 | _customcmp = False | |
882 | def cmp(self, fctx): |
|
882 | def cmp(self, fctx): | |
883 | """compare with other file context |
|
883 | """compare with other file context | |
884 |
|
884 | |||
885 | returns True if different than fctx. |
|
885 | returns True if different than fctx. | |
886 | """ |
|
886 | """ | |
887 | if fctx._customcmp: |
|
887 | if fctx._customcmp: | |
888 | return fctx.cmp(self) |
|
888 | return fctx.cmp(self) | |
889 |
|
889 | |||
890 | if (fctx._filenode is None |
|
890 | if (fctx._filenode is None | |
891 | and (self._repo._encodefilterpats |
|
891 | and (self._repo._encodefilterpats | |
892 | # if file data starts with '\1\n', empty metadata block is |
|
892 | # if file data starts with '\1\n', empty metadata block is | |
893 | # prepended, which adds 4 bytes to filelog.size(). |
|
893 | # prepended, which adds 4 bytes to filelog.size(). | |
894 | or self.size() - 4 == fctx.size()) |
|
894 | or self.size() - 4 == fctx.size()) | |
895 | or self.size() == fctx.size()): |
|
895 | or self.size() == fctx.size()): | |
896 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
896 | return self._filelog.cmp(self._filenode, fctx.data()) | |
897 |
|
897 | |||
898 | return True |
|
898 | return True | |
899 |
|
899 | |||
900 | def _adjustlinkrev(self, srcrev, inclusive=False): |
|
900 | def _adjustlinkrev(self, srcrev, inclusive=False): | |
901 | """return the first ancestor of <srcrev> introducing <fnode> |
|
901 | """return the first ancestor of <srcrev> introducing <fnode> | |
902 |
|
902 | |||
903 | If the linkrev of the file revision does not point to an ancestor of |
|
903 | If the linkrev of the file revision does not point to an ancestor of | |
904 | srcrev, we'll walk down the ancestors until we find one introducing |
|
904 | srcrev, we'll walk down the ancestors until we find one introducing | |
905 | this file revision. |
|
905 | this file revision. | |
906 |
|
906 | |||
907 | :srcrev: the changeset revision we search ancestors from |
|
907 | :srcrev: the changeset revision we search ancestors from | |
908 | :inclusive: if true, the src revision will also be checked |
|
908 | :inclusive: if true, the src revision will also be checked | |
909 | """ |
|
909 | """ | |
910 | repo = self._repo |
|
910 | repo = self._repo | |
911 | cl = repo.unfiltered().changelog |
|
911 | cl = repo.unfiltered().changelog | |
912 | mfl = repo.manifestlog |
|
912 | mfl = repo.manifestlog | |
913 | # fetch the linkrev |
|
913 | # fetch the linkrev | |
914 | lkr = self.linkrev() |
|
914 | lkr = self.linkrev() | |
915 | # hack to reuse ancestor computation when searching for renames |
|
915 | # hack to reuse ancestor computation when searching for renames | |
916 | memberanc = getattr(self, '_ancestrycontext', None) |
|
916 | memberanc = getattr(self, '_ancestrycontext', None) | |
917 | iteranc = None |
|
917 | iteranc = None | |
918 | if srcrev is None: |
|
918 | if srcrev is None: | |
919 | # wctx case, used by workingfilectx during mergecopy |
|
919 | # wctx case, used by workingfilectx during mergecopy | |
920 | revs = [p.rev() for p in self._repo[None].parents()] |
|
920 | revs = [p.rev() for p in self._repo[None].parents()] | |
921 | inclusive = True # we skipped the real (revless) source |
|
921 | inclusive = True # we skipped the real (revless) source | |
922 | else: |
|
922 | else: | |
923 | revs = [srcrev] |
|
923 | revs = [srcrev] | |
924 | if memberanc is None: |
|
924 | if memberanc is None: | |
925 | memberanc = iteranc = cl.ancestors(revs, lkr, |
|
925 | memberanc = iteranc = cl.ancestors(revs, lkr, | |
926 | inclusive=inclusive) |
|
926 | inclusive=inclusive) | |
927 | # check if this linkrev is an ancestor of srcrev |
|
927 | # check if this linkrev is an ancestor of srcrev | |
928 | if lkr not in memberanc: |
|
928 | if lkr not in memberanc: | |
929 | if iteranc is None: |
|
929 | if iteranc is None: | |
930 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) |
|
930 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) | |
931 | fnode = self._filenode |
|
931 | fnode = self._filenode | |
932 | path = self._path |
|
932 | path = self._path | |
933 | for a in iteranc: |
|
933 | for a in iteranc: | |
934 | ac = cl.read(a) # get changeset data (we avoid object creation) |
|
934 | ac = cl.read(a) # get changeset data (we avoid object creation) | |
935 | if path in ac[3]: # checking the 'files' field. |
|
935 | if path in ac[3]: # checking the 'files' field. | |
936 | # The file has been touched, check if the content is |
|
936 | # The file has been touched, check if the content is | |
937 | # similar to the one we search for. |
|
937 | # similar to the one we search for. | |
938 | if fnode == mfl[ac[0]].readfast().get(path): |
|
938 | if fnode == mfl[ac[0]].readfast().get(path): | |
939 | return a |
|
939 | return a | |
940 | # In theory, we should never get out of that loop without a result. |
|
940 | # In theory, we should never get out of that loop without a result. | |
941 | # But if manifest uses a buggy file revision (not children of the |
|
941 | # But if manifest uses a buggy file revision (not children of the | |
942 | # one it replaces) we could. Such a buggy situation will likely |
|
942 | # one it replaces) we could. Such a buggy situation will likely | |
943 | # result is crash somewhere else at to some point. |
|
943 | # result is crash somewhere else at to some point. | |
944 | return lkr |
|
944 | return lkr | |
945 |
|
945 | |||
946 | def introrev(self): |
|
946 | def introrev(self): | |
947 | """return the rev of the changeset which introduced this file revision |
|
947 | """return the rev of the changeset which introduced this file revision | |
948 |
|
948 | |||
949 | This method is different from linkrev because it take into account the |
|
949 | This method is different from linkrev because it take into account the | |
950 | changeset the filectx was created from. It ensures the returned |
|
950 | changeset the filectx was created from. It ensures the returned | |
951 | revision is one of its ancestors. This prevents bugs from |
|
951 | revision is one of its ancestors. This prevents bugs from | |
952 | 'linkrev-shadowing' when a file revision is used by multiple |
|
952 | 'linkrev-shadowing' when a file revision is used by multiple | |
953 | changesets. |
|
953 | changesets. | |
954 | """ |
|
954 | """ | |
955 | lkr = self.linkrev() |
|
955 | lkr = self.linkrev() | |
956 | attrs = vars(self) |
|
956 | attrs = vars(self) | |
957 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) |
|
957 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) | |
958 | if noctx or self.rev() == lkr: |
|
958 | if noctx or self.rev() == lkr: | |
959 | return self.linkrev() |
|
959 | return self.linkrev() | |
960 | return self._adjustlinkrev(self.rev(), inclusive=True) |
|
960 | return self._adjustlinkrev(self.rev(), inclusive=True) | |
961 |
|
961 | |||
962 | def introfilectx(self): |
|
962 | def introfilectx(self): | |
963 | """Return filectx having identical contents, but pointing to the |
|
963 | """Return filectx having identical contents, but pointing to the | |
964 | changeset revision where this filectx was introduced""" |
|
964 | changeset revision where this filectx was introduced""" | |
965 | introrev = self.introrev() |
|
965 | introrev = self.introrev() | |
966 | if self.rev() == introrev: |
|
966 | if self.rev() == introrev: | |
967 | return self |
|
967 | return self | |
968 | return self.filectx(self.filenode(), changeid=introrev) |
|
968 | return self.filectx(self.filenode(), changeid=introrev) | |
969 |
|
969 | |||
970 | def _parentfilectx(self, path, fileid, filelog): |
|
970 | def _parentfilectx(self, path, fileid, filelog): | |
971 | """create parent filectx keeping ancestry info for _adjustlinkrev()""" |
|
971 | """create parent filectx keeping ancestry info for _adjustlinkrev()""" | |
972 | fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) |
|
972 | fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) | |
973 | if '_changeid' in vars(self) or '_changectx' in vars(self): |
|
973 | if '_changeid' in vars(self) or '_changectx' in vars(self): | |
974 | # If self is associated with a changeset (probably explicitly |
|
974 | # If self is associated with a changeset (probably explicitly | |
975 | # fed), ensure the created filectx is associated with a |
|
975 | # fed), ensure the created filectx is associated with a | |
976 | # changeset that is an ancestor of self.changectx. |
|
976 | # changeset that is an ancestor of self.changectx. | |
977 | # This lets us later use _adjustlinkrev to get a correct link. |
|
977 | # This lets us later use _adjustlinkrev to get a correct link. | |
978 | fctx._descendantrev = self.rev() |
|
978 | fctx._descendantrev = self.rev() | |
979 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
979 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
980 | elif '_descendantrev' in vars(self): |
|
980 | elif '_descendantrev' in vars(self): | |
981 | # Otherwise propagate _descendantrev if we have one associated. |
|
981 | # Otherwise propagate _descendantrev if we have one associated. | |
982 | fctx._descendantrev = self._descendantrev |
|
982 | fctx._descendantrev = self._descendantrev | |
983 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
983 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
984 | return fctx |
|
984 | return fctx | |
985 |
|
985 | |||
986 | def parents(self): |
|
986 | def parents(self): | |
987 | _path = self._path |
|
987 | _path = self._path | |
988 | fl = self._filelog |
|
988 | fl = self._filelog | |
989 | parents = self._filelog.parents(self._filenode) |
|
989 | parents = self._filelog.parents(self._filenode) | |
990 | pl = [(_path, node, fl) for node in parents if node != nullid] |
|
990 | pl = [(_path, node, fl) for node in parents if node != nullid] | |
991 |
|
991 | |||
992 | r = fl.renamed(self._filenode) |
|
992 | r = fl.renamed(self._filenode) | |
993 | if r: |
|
993 | if r: | |
994 | # - In the simple rename case, both parent are nullid, pl is empty. |
|
994 | # - In the simple rename case, both parent are nullid, pl is empty. | |
995 | # - In case of merge, only one of the parent is null id and should |
|
995 | # - In case of merge, only one of the parent is null id and should | |
996 | # be replaced with the rename information. This parent is -always- |
|
996 | # be replaced with the rename information. This parent is -always- | |
997 | # the first one. |
|
997 | # the first one. | |
998 | # |
|
998 | # | |
999 | # As null id have always been filtered out in the previous list |
|
999 | # As null id have always been filtered out in the previous list | |
1000 | # comprehension, inserting to 0 will always result in "replacing |
|
1000 | # comprehension, inserting to 0 will always result in "replacing | |
1001 | # first nullid parent with rename information. |
|
1001 | # first nullid parent with rename information. | |
1002 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) |
|
1002 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) | |
1003 |
|
1003 | |||
1004 | return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] |
|
1004 | return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] | |
1005 |
|
1005 | |||
1006 | def p1(self): |
|
1006 | def p1(self): | |
1007 | return self.parents()[0] |
|
1007 | return self.parents()[0] | |
1008 |
|
1008 | |||
1009 | def p2(self): |
|
1009 | def p2(self): | |
1010 | p = self.parents() |
|
1010 | p = self.parents() | |
1011 | if len(p) == 2: |
|
1011 | if len(p) == 2: | |
1012 | return p[1] |
|
1012 | return p[1] | |
1013 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
1013 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) | |
1014 |
|
1014 | |||
1015 | def annotate(self, follow=False, linenumber=False, skiprevs=None, |
|
1015 | def annotate(self, follow=False, linenumber=False, skiprevs=None, | |
1016 | diffopts=None): |
|
1016 | diffopts=None): | |
1017 | '''returns a list of tuples of ((ctx, number), line) for each line |
|
1017 | '''returns a list of tuples of ((ctx, number), line) for each line | |
1018 | in the file, where ctx is the filectx of the node where |
|
1018 | in the file, where ctx is the filectx of the node where | |
1019 | that line was last changed; if linenumber parameter is true, number is |
|
1019 | that line was last changed; if linenumber parameter is true, number is | |
1020 | the line number at the first appearance in the managed file, otherwise, |
|
1020 | the line number at the first appearance in the managed file, otherwise, | |
1021 | number has a fixed value of False. |
|
1021 | number has a fixed value of False. | |
1022 | ''' |
|
1022 | ''' | |
1023 |
|
1023 | |||
1024 | def lines(text): |
|
1024 | def lines(text): | |
1025 | if text.endswith("\n"): |
|
1025 | if text.endswith("\n"): | |
1026 | return text.count("\n") |
|
1026 | return text.count("\n") | |
1027 | return text.count("\n") + int(bool(text)) |
|
1027 | return text.count("\n") + int(bool(text)) | |
1028 |
|
1028 | |||
1029 | if linenumber: |
|
1029 | if linenumber: | |
1030 | def decorate(text, rev): |
|
1030 | def decorate(text, rev): | |
1031 | return ([annotateline(fctx=rev, lineno=i) |
|
1031 | return ([annotateline(fctx=rev, lineno=i) | |
1032 | for i in xrange(1, lines(text) + 1)], text) |
|
1032 | for i in xrange(1, lines(text) + 1)], text) | |
1033 | else: |
|
1033 | else: | |
1034 | def decorate(text, rev): |
|
1034 | def decorate(text, rev): | |
1035 | return ([annotateline(fctx=rev)] * lines(text), text) |
|
1035 | return ([annotateline(fctx=rev)] * lines(text), text) | |
1036 |
|
1036 | |||
1037 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
1037 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
1038 |
|
1038 | |||
1039 | def parents(f): |
|
1039 | def parents(f): | |
1040 | # Cut _descendantrev here to mitigate the penalty of lazy linkrev |
|
1040 | # Cut _descendantrev here to mitigate the penalty of lazy linkrev | |
1041 | # adjustment. Otherwise, p._adjustlinkrev() would walk changelog |
|
1041 | # adjustment. Otherwise, p._adjustlinkrev() would walk changelog | |
1042 | # from the topmost introrev (= srcrev) down to p.linkrev() if it |
|
1042 | # from the topmost introrev (= srcrev) down to p.linkrev() if it | |
1043 | # isn't an ancestor of the srcrev. |
|
1043 | # isn't an ancestor of the srcrev. | |
1044 | f._changeid |
|
1044 | f._changeid | |
1045 | pl = f.parents() |
|
1045 | pl = f.parents() | |
1046 |
|
1046 | |||
1047 | # Don't return renamed parents if we aren't following. |
|
1047 | # Don't return renamed parents if we aren't following. | |
1048 | if not follow: |
|
1048 | if not follow: | |
1049 | pl = [p for p in pl if p.path() == f.path()] |
|
1049 | pl = [p for p in pl if p.path() == f.path()] | |
1050 |
|
1050 | |||
1051 | # renamed filectx won't have a filelog yet, so set it |
|
1051 | # renamed filectx won't have a filelog yet, so set it | |
1052 | # from the cache to save time |
|
1052 | # from the cache to save time | |
1053 | for p in pl: |
|
1053 | for p in pl: | |
1054 | if not '_filelog' in p.__dict__: |
|
1054 | if not '_filelog' in p.__dict__: | |
1055 | p._filelog = getlog(p.path()) |
|
1055 | p._filelog = getlog(p.path()) | |
1056 |
|
1056 | |||
1057 | return pl |
|
1057 | return pl | |
1058 |
|
1058 | |||
1059 | # use linkrev to find the first changeset where self appeared |
|
1059 | # use linkrev to find the first changeset where self appeared | |
1060 | base = self.introfilectx() |
|
1060 | base = self.introfilectx() | |
1061 | if getattr(base, '_ancestrycontext', None) is None: |
|
1061 | if getattr(base, '_ancestrycontext', None) is None: | |
1062 | cl = self._repo.changelog |
|
1062 | cl = self._repo.changelog | |
1063 | if base.rev() is None: |
|
1063 | if base.rev() is None: | |
1064 | # wctx is not inclusive, but works because _ancestrycontext |
|
1064 | # wctx is not inclusive, but works because _ancestrycontext | |
1065 | # is used to test filelog revisions |
|
1065 | # is used to test filelog revisions | |
1066 | ac = cl.ancestors([p.rev() for p in base.parents()], |
|
1066 | ac = cl.ancestors([p.rev() for p in base.parents()], | |
1067 | inclusive=True) |
|
1067 | inclusive=True) | |
1068 | else: |
|
1068 | else: | |
1069 | ac = cl.ancestors([base.rev()], inclusive=True) |
|
1069 | ac = cl.ancestors([base.rev()], inclusive=True) | |
1070 | base._ancestrycontext = ac |
|
1070 | base._ancestrycontext = ac | |
1071 |
|
1071 | |||
1072 | # This algorithm would prefer to be recursive, but Python is a |
|
1072 | # This algorithm would prefer to be recursive, but Python is a | |
1073 | # bit recursion-hostile. Instead we do an iterative |
|
1073 | # bit recursion-hostile. Instead we do an iterative | |
1074 | # depth-first search. |
|
1074 | # depth-first search. | |
1075 |
|
1075 | |||
1076 | # 1st DFS pre-calculates pcache and needed |
|
1076 | # 1st DFS pre-calculates pcache and needed | |
1077 | visit = [base] |
|
1077 | visit = [base] | |
1078 | pcache = {} |
|
1078 | pcache = {} | |
1079 | needed = {base: 1} |
|
1079 | needed = {base: 1} | |
1080 | while visit: |
|
1080 | while visit: | |
1081 | f = visit.pop() |
|
1081 | f = visit.pop() | |
1082 | if f in pcache: |
|
1082 | if f in pcache: | |
1083 | continue |
|
1083 | continue | |
1084 | pl = parents(f) |
|
1084 | pl = parents(f) | |
1085 | pcache[f] = pl |
|
1085 | pcache[f] = pl | |
1086 | for p in pl: |
|
1086 | for p in pl: | |
1087 | needed[p] = needed.get(p, 0) + 1 |
|
1087 | needed[p] = needed.get(p, 0) + 1 | |
1088 | if p not in pcache: |
|
1088 | if p not in pcache: | |
1089 | visit.append(p) |
|
1089 | visit.append(p) | |
1090 |
|
1090 | |||
1091 | # 2nd DFS does the actual annotate |
|
1091 | # 2nd DFS does the actual annotate | |
1092 | visit[:] = [base] |
|
1092 | visit[:] = [base] | |
1093 | hist = {} |
|
1093 | hist = {} | |
1094 | while visit: |
|
1094 | while visit: | |
1095 | f = visit[-1] |
|
1095 | f = visit[-1] | |
1096 | if f in hist: |
|
1096 | if f in hist: | |
1097 | visit.pop() |
|
1097 | visit.pop() | |
1098 | continue |
|
1098 | continue | |
1099 |
|
1099 | |||
1100 | ready = True |
|
1100 | ready = True | |
1101 | pl = pcache[f] |
|
1101 | pl = pcache[f] | |
1102 | for p in pl: |
|
1102 | for p in pl: | |
1103 | if p not in hist: |
|
1103 | if p not in hist: | |
1104 | ready = False |
|
1104 | ready = False | |
1105 | visit.append(p) |
|
1105 | visit.append(p) | |
1106 | if ready: |
|
1106 | if ready: | |
1107 | visit.pop() |
|
1107 | visit.pop() | |
1108 | curr = decorate(f.data(), f) |
|
1108 | curr = decorate(f.data(), f) | |
1109 | skipchild = False |
|
1109 | skipchild = False | |
1110 | if skiprevs is not None: |
|
1110 | if skiprevs is not None: | |
1111 | skipchild = f._changeid in skiprevs |
|
1111 | skipchild = f._changeid in skiprevs | |
1112 | curr = _annotatepair([hist[p] for p in pl], f, curr, skipchild, |
|
1112 | curr = _annotatepair([hist[p] for p in pl], f, curr, skipchild, | |
1113 | diffopts) |
|
1113 | diffopts) | |
1114 | for p in pl: |
|
1114 | for p in pl: | |
1115 | if needed[p] == 1: |
|
1115 | if needed[p] == 1: | |
1116 | del hist[p] |
|
1116 | del hist[p] | |
1117 | del needed[p] |
|
1117 | del needed[p] | |
1118 | else: |
|
1118 | else: | |
1119 | needed[p] -= 1 |
|
1119 | needed[p] -= 1 | |
1120 |
|
1120 | |||
1121 | hist[f] = curr |
|
1121 | hist[f] = curr | |
1122 | del pcache[f] |
|
1122 | del pcache[f] | |
1123 |
|
1123 | |||
1124 | return pycompat.ziplist(hist[base][0], hist[base][1].splitlines(True)) |
|
1124 | return pycompat.ziplist(hist[base][0], hist[base][1].splitlines(True)) | |
1125 |
|
1125 | |||
1126 | def ancestors(self, followfirst=False): |
|
1126 | def ancestors(self, followfirst=False): | |
1127 | visit = {} |
|
1127 | visit = {} | |
1128 | c = self |
|
1128 | c = self | |
1129 | if followfirst: |
|
1129 | if followfirst: | |
1130 | cut = 1 |
|
1130 | cut = 1 | |
1131 | else: |
|
1131 | else: | |
1132 | cut = None |
|
1132 | cut = None | |
1133 |
|
1133 | |||
1134 | while True: |
|
1134 | while True: | |
1135 | for parent in c.parents()[:cut]: |
|
1135 | for parent in c.parents()[:cut]: | |
1136 | visit[(parent.linkrev(), parent.filenode())] = parent |
|
1136 | visit[(parent.linkrev(), parent.filenode())] = parent | |
1137 | if not visit: |
|
1137 | if not visit: | |
1138 | break |
|
1138 | break | |
1139 | c = visit.pop(max(visit)) |
|
1139 | c = visit.pop(max(visit)) | |
1140 | yield c |
|
1140 | yield c | |
1141 |
|
1141 | |||
1142 | def decodeddata(self): |
|
1142 | def decodeddata(self): | |
1143 | """Returns `data()` after running repository decoding filters. |
|
1143 | """Returns `data()` after running repository decoding filters. | |
1144 |
|
1144 | |||
1145 | This is often equivalent to how the data would be expressed on disk. |
|
1145 | This is often equivalent to how the data would be expressed on disk. | |
1146 | """ |
|
1146 | """ | |
1147 | return self._repo.wwritedata(self.path(), self.data()) |
|
1147 | return self._repo.wwritedata(self.path(), self.data()) | |
1148 |
|
1148 | |||
1149 | @attr.s(slots=True, frozen=True) |
|
1149 | @attr.s(slots=True, frozen=True) | |
1150 | class annotateline(object): |
|
1150 | class annotateline(object): | |
1151 | fctx = attr.ib() |
|
1151 | fctx = attr.ib() | |
1152 | lineno = attr.ib(default=False) |
|
1152 | lineno = attr.ib(default=False) | |
1153 | # Whether this annotation was the result of a skip-annotate. |
|
1153 | # Whether this annotation was the result of a skip-annotate. | |
1154 | skip = attr.ib(default=False) |
|
1154 | skip = attr.ib(default=False) | |
1155 |
|
1155 | |||
1156 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): |
|
1156 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): | |
1157 | r''' |
|
1157 | r''' | |
1158 | Given parent and child fctxes and annotate data for parents, for all lines |
|
1158 | Given parent and child fctxes and annotate data for parents, for all lines | |
1159 | in either parent that match the child, annotate the child with the parent's |
|
1159 | in either parent that match the child, annotate the child with the parent's | |
1160 | data. |
|
1160 | data. | |
1161 |
|
1161 | |||
1162 | Additionally, if `skipchild` is True, replace all other lines with parent |
|
1162 | Additionally, if `skipchild` is True, replace all other lines with parent | |
1163 | annotate data as well such that child is never blamed for any lines. |
|
1163 | annotate data as well such that child is never blamed for any lines. | |
1164 |
|
1164 | |||
1165 | See test-annotate.py for unit tests. |
|
1165 | See test-annotate.py for unit tests. | |
1166 | ''' |
|
1166 | ''' | |
1167 | pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts)) |
|
1167 | pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts)) | |
1168 | for parent in parents] |
|
1168 | for parent in parents] | |
1169 |
|
1169 | |||
1170 | if skipchild: |
|
1170 | if skipchild: | |
1171 | # Need to iterate over the blocks twice -- make it a list |
|
1171 | # Need to iterate over the blocks twice -- make it a list | |
1172 | pblocks = [(p, list(blocks)) for (p, blocks) in pblocks] |
|
1172 | pblocks = [(p, list(blocks)) for (p, blocks) in pblocks] | |
1173 | # Mercurial currently prefers p2 over p1 for annotate. |
|
1173 | # Mercurial currently prefers p2 over p1 for annotate. | |
1174 | # TODO: change this? |
|
1174 | # TODO: change this? | |
1175 | for parent, blocks in pblocks: |
|
1175 | for parent, blocks in pblocks: | |
1176 | for (a1, a2, b1, b2), t in blocks: |
|
1176 | for (a1, a2, b1, b2), t in blocks: | |
1177 | # Changed blocks ('!') or blocks made only of blank lines ('~') |
|
1177 | # Changed blocks ('!') or blocks made only of blank lines ('~') | |
1178 | # belong to the child. |
|
1178 | # belong to the child. | |
1179 | if t == '=': |
|
1179 | if t == '=': | |
1180 | child[0][b1:b2] = parent[0][a1:a2] |
|
1180 | child[0][b1:b2] = parent[0][a1:a2] | |
1181 |
|
1181 | |||
1182 | if skipchild: |
|
1182 | if skipchild: | |
1183 | # Now try and match up anything that couldn't be matched, |
|
1183 | # Now try and match up anything that couldn't be matched, | |
1184 | # Reversing pblocks maintains bias towards p2, matching above |
|
1184 | # Reversing pblocks maintains bias towards p2, matching above | |
1185 | # behavior. |
|
1185 | # behavior. | |
1186 | pblocks.reverse() |
|
1186 | pblocks.reverse() | |
1187 |
|
1187 | |||
1188 | # The heuristics are: |
|
1188 | # The heuristics are: | |
1189 | # * Work on blocks of changed lines (effectively diff hunks with -U0). |
|
1189 | # * Work on blocks of changed lines (effectively diff hunks with -U0). | |
1190 | # This could potentially be smarter but works well enough. |
|
1190 | # This could potentially be smarter but works well enough. | |
1191 | # * For a non-matching section, do a best-effort fit. Match lines in |
|
1191 | # * For a non-matching section, do a best-effort fit. Match lines in | |
1192 | # diff hunks 1:1, dropping lines as necessary. |
|
1192 | # diff hunks 1:1, dropping lines as necessary. | |
1193 | # * Repeat the last line as a last resort. |
|
1193 | # * Repeat the last line as a last resort. | |
1194 |
|
1194 | |||
1195 | # First, replace as much as possible without repeating the last line. |
|
1195 | # First, replace as much as possible without repeating the last line. | |
1196 | remaining = [(parent, []) for parent, _blocks in pblocks] |
|
1196 | remaining = [(parent, []) for parent, _blocks in pblocks] | |
1197 | for idx, (parent, blocks) in enumerate(pblocks): |
|
1197 | for idx, (parent, blocks) in enumerate(pblocks): | |
1198 | for (a1, a2, b1, b2), _t in blocks: |
|
1198 | for (a1, a2, b1, b2), _t in blocks: | |
1199 | if a2 - a1 >= b2 - b1: |
|
1199 | if a2 - a1 >= b2 - b1: | |
1200 | for bk in xrange(b1, b2): |
|
1200 | for bk in xrange(b1, b2): | |
1201 | if child[0][bk].fctx == childfctx: |
|
1201 | if child[0][bk].fctx == childfctx: | |
1202 | ak = min(a1 + (bk - b1), a2 - 1) |
|
1202 | ak = min(a1 + (bk - b1), a2 - 1) | |
1203 | child[0][bk] = attr.evolve(parent[0][ak], skip=True) |
|
1203 | child[0][bk] = attr.evolve(parent[0][ak], skip=True) | |
1204 | else: |
|
1204 | else: | |
1205 | remaining[idx][1].append((a1, a2, b1, b2)) |
|
1205 | remaining[idx][1].append((a1, a2, b1, b2)) | |
1206 |
|
1206 | |||
1207 | # Then, look at anything left, which might involve repeating the last |
|
1207 | # Then, look at anything left, which might involve repeating the last | |
1208 | # line. |
|
1208 | # line. | |
1209 | for parent, blocks in remaining: |
|
1209 | for parent, blocks in remaining: | |
1210 | for a1, a2, b1, b2 in blocks: |
|
1210 | for a1, a2, b1, b2 in blocks: | |
1211 | for bk in xrange(b1, b2): |
|
1211 | for bk in xrange(b1, b2): | |
1212 | if child[0][bk].fctx == childfctx: |
|
1212 | if child[0][bk].fctx == childfctx: | |
1213 | ak = min(a1 + (bk - b1), a2 - 1) |
|
1213 | ak = min(a1 + (bk - b1), a2 - 1) | |
1214 | child[0][bk] = attr.evolve(parent[0][ak], skip=True) |
|
1214 | child[0][bk] = attr.evolve(parent[0][ak], skip=True) | |
1215 | return child |
|
1215 | return child | |
1216 |
|
1216 | |||
1217 | class filectx(basefilectx): |
|
1217 | class filectx(basefilectx): | |
1218 | """A filecontext object makes access to data related to a particular |
|
1218 | """A filecontext object makes access to data related to a particular | |
1219 | filerevision convenient.""" |
|
1219 | filerevision convenient.""" | |
1220 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
1220 | def __init__(self, repo, path, changeid=None, fileid=None, | |
1221 | filelog=None, changectx=None): |
|
1221 | filelog=None, changectx=None): | |
1222 | """changeid can be a changeset revision, node, or tag. |
|
1222 | """changeid can be a changeset revision, node, or tag. | |
1223 | fileid can be a file revision or node.""" |
|
1223 | fileid can be a file revision or node.""" | |
1224 | self._repo = repo |
|
1224 | self._repo = repo | |
1225 | self._path = path |
|
1225 | self._path = path | |
1226 |
|
1226 | |||
1227 | assert (changeid is not None |
|
1227 | assert (changeid is not None | |
1228 | or fileid is not None |
|
1228 | or fileid is not None | |
1229 | or changectx is not None), \ |
|
1229 | or changectx is not None), \ | |
1230 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
1230 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
1231 | % (changeid, fileid, changectx)) |
|
1231 | % (changeid, fileid, changectx)) | |
1232 |
|
1232 | |||
1233 | if filelog is not None: |
|
1233 | if filelog is not None: | |
1234 | self._filelog = filelog |
|
1234 | self._filelog = filelog | |
1235 |
|
1235 | |||
1236 | if changeid is not None: |
|
1236 | if changeid is not None: | |
1237 | self._changeid = changeid |
|
1237 | self._changeid = changeid | |
1238 | if changectx is not None: |
|
1238 | if changectx is not None: | |
1239 | self._changectx = changectx |
|
1239 | self._changectx = changectx | |
1240 | if fileid is not None: |
|
1240 | if fileid is not None: | |
1241 | self._fileid = fileid |
|
1241 | self._fileid = fileid | |
1242 |
|
1242 | |||
1243 | @propertycache |
|
1243 | @propertycache | |
1244 | def _changectx(self): |
|
1244 | def _changectx(self): | |
1245 | try: |
|
1245 | try: | |
1246 | return changectx(self._repo, self._changeid) |
|
1246 | return changectx(self._repo, self._changeid) | |
1247 | except error.FilteredRepoLookupError: |
|
1247 | except error.FilteredRepoLookupError: | |
1248 | # Linkrev may point to any revision in the repository. When the |
|
1248 | # Linkrev may point to any revision in the repository. When the | |
1249 | # repository is filtered this may lead to `filectx` trying to build |
|
1249 | # repository is filtered this may lead to `filectx` trying to build | |
1250 | # `changectx` for filtered revision. In such case we fallback to |
|
1250 | # `changectx` for filtered revision. In such case we fallback to | |
1251 | # creating `changectx` on the unfiltered version of the reposition. |
|
1251 | # creating `changectx` on the unfiltered version of the reposition. | |
1252 | # This fallback should not be an issue because `changectx` from |
|
1252 | # This fallback should not be an issue because `changectx` from | |
1253 | # `filectx` are not used in complex operations that care about |
|
1253 | # `filectx` are not used in complex operations that care about | |
1254 | # filtering. |
|
1254 | # filtering. | |
1255 | # |
|
1255 | # | |
1256 | # This fallback is a cheap and dirty fix that prevent several |
|
1256 | # This fallback is a cheap and dirty fix that prevent several | |
1257 | # crashes. It does not ensure the behavior is correct. However the |
|
1257 | # crashes. It does not ensure the behavior is correct. However the | |
1258 | # behavior was not correct before filtering either and "incorrect |
|
1258 | # behavior was not correct before filtering either and "incorrect | |
1259 | # behavior" is seen as better as "crash" |
|
1259 | # behavior" is seen as better as "crash" | |
1260 | # |
|
1260 | # | |
1261 | # Linkrevs have several serious troubles with filtering that are |
|
1261 | # Linkrevs have several serious troubles with filtering that are | |
1262 | # complicated to solve. Proper handling of the issue here should be |
|
1262 | # complicated to solve. Proper handling of the issue here should be | |
1263 | # considered when solving linkrev issue are on the table. |
|
1263 | # considered when solving linkrev issue are on the table. | |
1264 | return changectx(self._repo.unfiltered(), self._changeid) |
|
1264 | return changectx(self._repo.unfiltered(), self._changeid) | |
1265 |
|
1265 | |||
1266 | def filectx(self, fileid, changeid=None): |
|
1266 | def filectx(self, fileid, changeid=None): | |
1267 | '''opens an arbitrary revision of the file without |
|
1267 | '''opens an arbitrary revision of the file without | |
1268 | opening a new filelog''' |
|
1268 | opening a new filelog''' | |
1269 | return filectx(self._repo, self._path, fileid=fileid, |
|
1269 | return filectx(self._repo, self._path, fileid=fileid, | |
1270 | filelog=self._filelog, changeid=changeid) |
|
1270 | filelog=self._filelog, changeid=changeid) | |
1271 |
|
1271 | |||
1272 | def rawdata(self): |
|
1272 | def rawdata(self): | |
1273 | return self._filelog.revision(self._filenode, raw=True) |
|
1273 | return self._filelog.revision(self._filenode, raw=True) | |
1274 |
|
1274 | |||
1275 | def rawflags(self): |
|
1275 | def rawflags(self): | |
1276 | """low-level revlog flags""" |
|
1276 | """low-level revlog flags""" | |
1277 | return self._filelog.flags(self._filerev) |
|
1277 | return self._filelog.flags(self._filerev) | |
1278 |
|
1278 | |||
1279 | def data(self): |
|
1279 | def data(self): | |
1280 | try: |
|
1280 | try: | |
1281 | return self._filelog.read(self._filenode) |
|
1281 | return self._filelog.read(self._filenode) | |
1282 | except error.CensoredNodeError: |
|
1282 | except error.CensoredNodeError: | |
1283 | if self._repo.ui.config("censor", "policy") == "ignore": |
|
1283 | if self._repo.ui.config("censor", "policy") == "ignore": | |
1284 | return "" |
|
1284 | return "" | |
1285 | raise error.Abort(_("censored node: %s") % short(self._filenode), |
|
1285 | raise error.Abort(_("censored node: %s") % short(self._filenode), | |
1286 | hint=_("set censor.policy to ignore errors")) |
|
1286 | hint=_("set censor.policy to ignore errors")) | |
1287 |
|
1287 | |||
1288 | def size(self): |
|
1288 | def size(self): | |
1289 | return self._filelog.size(self._filerev) |
|
1289 | return self._filelog.size(self._filerev) | |
1290 |
|
1290 | |||
1291 | @propertycache |
|
1291 | @propertycache | |
1292 | def _copied(self): |
|
1292 | def _copied(self): | |
1293 | """check if file was actually renamed in this changeset revision |
|
1293 | """check if file was actually renamed in this changeset revision | |
1294 |
|
1294 | |||
1295 | If rename logged in file revision, we report copy for changeset only |
|
1295 | If rename logged in file revision, we report copy for changeset only | |
1296 | if file revisions linkrev points back to the changeset in question |
|
1296 | if file revisions linkrev points back to the changeset in question | |
1297 | or both changeset parents contain different file revisions. |
|
1297 | or both changeset parents contain different file revisions. | |
1298 | """ |
|
1298 | """ | |
1299 |
|
1299 | |||
1300 | renamed = self._filelog.renamed(self._filenode) |
|
1300 | renamed = self._filelog.renamed(self._filenode) | |
1301 | if not renamed: |
|
1301 | if not renamed: | |
1302 | return renamed |
|
1302 | return renamed | |
1303 |
|
1303 | |||
1304 | if self.rev() == self.linkrev(): |
|
1304 | if self.rev() == self.linkrev(): | |
1305 | return renamed |
|
1305 | return renamed | |
1306 |
|
1306 | |||
1307 | name = self.path() |
|
1307 | name = self.path() | |
1308 | fnode = self._filenode |
|
1308 | fnode = self._filenode | |
1309 | for p in self._changectx.parents(): |
|
1309 | for p in self._changectx.parents(): | |
1310 | try: |
|
1310 | try: | |
1311 | if fnode == p.filenode(name): |
|
1311 | if fnode == p.filenode(name): | |
1312 | return None |
|
1312 | return None | |
1313 | except error.LookupError: |
|
1313 | except error.LookupError: | |
1314 | pass |
|
1314 | pass | |
1315 | return renamed |
|
1315 | return renamed | |
1316 |
|
1316 | |||
1317 | def children(self): |
|
1317 | def children(self): | |
1318 | # hard for renames |
|
1318 | # hard for renames | |
1319 | c = self._filelog.children(self._filenode) |
|
1319 | c = self._filelog.children(self._filenode) | |
1320 | return [filectx(self._repo, self._path, fileid=x, |
|
1320 | return [filectx(self._repo, self._path, fileid=x, | |
1321 | filelog=self._filelog) for x in c] |
|
1321 | filelog=self._filelog) for x in c] | |
1322 |
|
1322 | |||
1323 | class committablectx(basectx): |
|
1323 | class committablectx(basectx): | |
1324 | """A committablectx object provides common functionality for a context that |
|
1324 | """A committablectx object provides common functionality for a context that | |
1325 | wants the ability to commit, e.g. workingctx or memctx.""" |
|
1325 | wants the ability to commit, e.g. workingctx or memctx.""" | |
1326 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1326 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1327 | changes=None): |
|
1327 | changes=None): | |
1328 | self._repo = repo |
|
1328 | self._repo = repo | |
1329 | self._rev = None |
|
1329 | self._rev = None | |
1330 | self._node = None |
|
1330 | self._node = None | |
1331 | self._text = text |
|
1331 | self._text = text | |
1332 | if date: |
|
1332 | if date: | |
1333 | self._date = util.parsedate(date) |
|
1333 | self._date = util.parsedate(date) | |
1334 | if user: |
|
1334 | if user: | |
1335 | self._user = user |
|
1335 | self._user = user | |
1336 | if changes: |
|
1336 | if changes: | |
1337 | self._status = changes |
|
1337 | self._status = changes | |
1338 |
|
1338 | |||
1339 | self._extra = {} |
|
1339 | self._extra = {} | |
1340 | if extra: |
|
1340 | if extra: | |
1341 | self._extra = extra.copy() |
|
1341 | self._extra = extra.copy() | |
1342 | if 'branch' not in self._extra: |
|
1342 | if 'branch' not in self._extra: | |
1343 | try: |
|
1343 | try: | |
1344 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
1344 | branch = encoding.fromlocal(self._repo.dirstate.branch()) | |
1345 | except UnicodeDecodeError: |
|
1345 | except UnicodeDecodeError: | |
1346 | raise error.Abort(_('branch name not in UTF-8!')) |
|
1346 | raise error.Abort(_('branch name not in UTF-8!')) | |
1347 | self._extra['branch'] = branch |
|
1347 | self._extra['branch'] = branch | |
1348 | if self._extra['branch'] == '': |
|
1348 | if self._extra['branch'] == '': | |
1349 | self._extra['branch'] = 'default' |
|
1349 | self._extra['branch'] = 'default' | |
1350 |
|
1350 | |||
1351 | def __bytes__(self): |
|
1351 | def __bytes__(self): | |
1352 | return bytes(self._parents[0]) + "+" |
|
1352 | return bytes(self._parents[0]) + "+" | |
1353 |
|
1353 | |||
1354 | __str__ = encoding.strmethod(__bytes__) |
|
1354 | __str__ = encoding.strmethod(__bytes__) | |
1355 |
|
1355 | |||
1356 | def __nonzero__(self): |
|
1356 | def __nonzero__(self): | |
1357 | return True |
|
1357 | return True | |
1358 |
|
1358 | |||
1359 | __bool__ = __nonzero__ |
|
1359 | __bool__ = __nonzero__ | |
1360 |
|
1360 | |||
1361 | def _buildflagfunc(self): |
|
1361 | def _buildflagfunc(self): | |
1362 | # Create a fallback function for getting file flags when the |
|
1362 | # Create a fallback function for getting file flags when the | |
1363 | # filesystem doesn't support them |
|
1363 | # filesystem doesn't support them | |
1364 |
|
1364 | |||
1365 | copiesget = self._repo.dirstate.copies().get |
|
1365 | copiesget = self._repo.dirstate.copies().get | |
1366 | parents = self.parents() |
|
1366 | parents = self.parents() | |
1367 | if len(parents) < 2: |
|
1367 | if len(parents) < 2: | |
1368 | # when we have one parent, it's easy: copy from parent |
|
1368 | # when we have one parent, it's easy: copy from parent | |
1369 | man = parents[0].manifest() |
|
1369 | man = parents[0].manifest() | |
1370 | def func(f): |
|
1370 | def func(f): | |
1371 | f = copiesget(f, f) |
|
1371 | f = copiesget(f, f) | |
1372 | return man.flags(f) |
|
1372 | return man.flags(f) | |
1373 | else: |
|
1373 | else: | |
1374 | # merges are tricky: we try to reconstruct the unstored |
|
1374 | # merges are tricky: we try to reconstruct the unstored | |
1375 | # result from the merge (issue1802) |
|
1375 | # result from the merge (issue1802) | |
1376 | p1, p2 = parents |
|
1376 | p1, p2 = parents | |
1377 | pa = p1.ancestor(p2) |
|
1377 | pa = p1.ancestor(p2) | |
1378 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
1378 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1379 |
|
1379 | |||
1380 | def func(f): |
|
1380 | def func(f): | |
1381 | f = copiesget(f, f) # may be wrong for merges with copies |
|
1381 | f = copiesget(f, f) # may be wrong for merges with copies | |
1382 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
1382 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1383 | if fl1 == fl2: |
|
1383 | if fl1 == fl2: | |
1384 | return fl1 |
|
1384 | return fl1 | |
1385 | if fl1 == fla: |
|
1385 | if fl1 == fla: | |
1386 | return fl2 |
|
1386 | return fl2 | |
1387 | if fl2 == fla: |
|
1387 | if fl2 == fla: | |
1388 | return fl1 |
|
1388 | return fl1 | |
1389 | return '' # punt for conflicts |
|
1389 | return '' # punt for conflicts | |
1390 |
|
1390 | |||
1391 | return func |
|
1391 | return func | |
1392 |
|
1392 | |||
1393 | @propertycache |
|
1393 | @propertycache | |
1394 | def _flagfunc(self): |
|
1394 | def _flagfunc(self): | |
1395 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
1395 | return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1396 |
|
1396 | |||
1397 | @propertycache |
|
1397 | @propertycache | |
1398 | def _status(self): |
|
1398 | def _status(self): | |
1399 | return self._repo.status() |
|
1399 | return self._repo.status() | |
1400 |
|
1400 | |||
1401 | @propertycache |
|
1401 | @propertycache | |
1402 | def _user(self): |
|
1402 | def _user(self): | |
1403 | return self._repo.ui.username() |
|
1403 | return self._repo.ui.username() | |
1404 |
|
1404 | |||
1405 | @propertycache |
|
1405 | @propertycache | |
1406 | def _date(self): |
|
1406 | def _date(self): | |
1407 | ui = self._repo.ui |
|
1407 | ui = self._repo.ui | |
1408 | date = ui.configdate('devel', 'default-date') |
|
1408 | date = ui.configdate('devel', 'default-date') | |
1409 | if date is None: |
|
1409 | if date is None: | |
1410 | date = util.makedate() |
|
1410 | date = util.makedate() | |
1411 | return date |
|
1411 | return date | |
1412 |
|
1412 | |||
1413 | def subrev(self, subpath): |
|
1413 | def subrev(self, subpath): | |
1414 | return None |
|
1414 | return None | |
1415 |
|
1415 | |||
1416 | def manifestnode(self): |
|
1416 | def manifestnode(self): | |
1417 | return None |
|
1417 | return None | |
1418 | def user(self): |
|
1418 | def user(self): | |
1419 | return self._user or self._repo.ui.username() |
|
1419 | return self._user or self._repo.ui.username() | |
1420 | def date(self): |
|
1420 | def date(self): | |
1421 | return self._date |
|
1421 | return self._date | |
1422 | def description(self): |
|
1422 | def description(self): | |
1423 | return self._text |
|
1423 | return self._text | |
1424 | def files(self): |
|
1424 | def files(self): | |
1425 | return sorted(self._status.modified + self._status.added + |
|
1425 | return sorted(self._status.modified + self._status.added + | |
1426 | self._status.removed) |
|
1426 | self._status.removed) | |
1427 |
|
1427 | |||
1428 | def modified(self): |
|
1428 | def modified(self): | |
1429 | return self._status.modified |
|
1429 | return self._status.modified | |
1430 | def added(self): |
|
1430 | def added(self): | |
1431 | return self._status.added |
|
1431 | return self._status.added | |
1432 | def removed(self): |
|
1432 | def removed(self): | |
1433 | return self._status.removed |
|
1433 | return self._status.removed | |
1434 | def deleted(self): |
|
1434 | def deleted(self): | |
1435 | return self._status.deleted |
|
1435 | return self._status.deleted | |
1436 | def branch(self): |
|
1436 | def branch(self): | |
1437 | return encoding.tolocal(self._extra['branch']) |
|
1437 | return encoding.tolocal(self._extra['branch']) | |
1438 | def closesbranch(self): |
|
1438 | def closesbranch(self): | |
1439 | return 'close' in self._extra |
|
1439 | return 'close' in self._extra | |
1440 | def extra(self): |
|
1440 | def extra(self): | |
1441 | return self._extra |
|
1441 | return self._extra | |
1442 |
|
1442 | |||
1443 | def isinmemory(self): |
|
1443 | def isinmemory(self): | |
1444 | return False |
|
1444 | return False | |
1445 |
|
1445 | |||
1446 | def tags(self): |
|
1446 | def tags(self): | |
1447 | return [] |
|
1447 | return [] | |
1448 |
|
1448 | |||
1449 | def bookmarks(self): |
|
1449 | def bookmarks(self): | |
1450 | b = [] |
|
1450 | b = [] | |
1451 | for p in self.parents(): |
|
1451 | for p in self.parents(): | |
1452 | b.extend(p.bookmarks()) |
|
1452 | b.extend(p.bookmarks()) | |
1453 | return b |
|
1453 | return b | |
1454 |
|
1454 | |||
1455 | def phase(self): |
|
1455 | def phase(self): | |
1456 | phase = phases.draft # default phase to draft |
|
1456 | phase = phases.draft # default phase to draft | |
1457 | for p in self.parents(): |
|
1457 | for p in self.parents(): | |
1458 | phase = max(phase, p.phase()) |
|
1458 | phase = max(phase, p.phase()) | |
1459 | return phase |
|
1459 | return phase | |
1460 |
|
1460 | |||
1461 | def hidden(self): |
|
1461 | def hidden(self): | |
1462 | return False |
|
1462 | return False | |
1463 |
|
1463 | |||
1464 | def children(self): |
|
1464 | def children(self): | |
1465 | return [] |
|
1465 | return [] | |
1466 |
|
1466 | |||
1467 | def flags(self, path): |
|
1467 | def flags(self, path): | |
1468 | if r'_manifest' in self.__dict__: |
|
1468 | if r'_manifest' in self.__dict__: | |
1469 | try: |
|
1469 | try: | |
1470 | return self._manifest.flags(path) |
|
1470 | return self._manifest.flags(path) | |
1471 | except KeyError: |
|
1471 | except KeyError: | |
1472 | return '' |
|
1472 | return '' | |
1473 |
|
1473 | |||
1474 | try: |
|
1474 | try: | |
1475 | return self._flagfunc(path) |
|
1475 | return self._flagfunc(path) | |
1476 | except OSError: |
|
1476 | except OSError: | |
1477 | return '' |
|
1477 | return '' | |
1478 |
|
1478 | |||
1479 | def ancestor(self, c2): |
|
1479 | def ancestor(self, c2): | |
1480 | """return the "best" ancestor context of self and c2""" |
|
1480 | """return the "best" ancestor context of self and c2""" | |
1481 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
1481 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
1482 |
|
1482 | |||
1483 | def walk(self, match): |
|
1483 | def walk(self, match): | |
1484 | '''Generates matching file names.''' |
|
1484 | '''Generates matching file names.''' | |
1485 | return sorted(self._repo.dirstate.walk(match, |
|
1485 | return sorted(self._repo.dirstate.walk(match, | |
1486 | subrepos=sorted(self.substate), |
|
1486 | subrepos=sorted(self.substate), | |
1487 | unknown=True, ignored=False)) |
|
1487 | unknown=True, ignored=False)) | |
1488 |
|
1488 | |||
1489 | def matches(self, match): |
|
1489 | def matches(self, match): | |
1490 | return sorted(self._repo.dirstate.matches(match)) |
|
1490 | return sorted(self._repo.dirstate.matches(match)) | |
1491 |
|
1491 | |||
1492 | def ancestors(self): |
|
1492 | def ancestors(self): | |
1493 | for p in self._parents: |
|
1493 | for p in self._parents: | |
1494 | yield p |
|
1494 | yield p | |
1495 | for a in self._repo.changelog.ancestors( |
|
1495 | for a in self._repo.changelog.ancestors( | |
1496 | [p.rev() for p in self._parents]): |
|
1496 | [p.rev() for p in self._parents]): | |
1497 | yield changectx(self._repo, a) |
|
1497 | yield changectx(self._repo, a) | |
1498 |
|
1498 | |||
1499 | def markcommitted(self, node): |
|
1499 | def markcommitted(self, node): | |
1500 | """Perform post-commit cleanup necessary after committing this ctx |
|
1500 | """Perform post-commit cleanup necessary after committing this ctx | |
1501 |
|
1501 | |||
1502 | Specifically, this updates backing stores this working context |
|
1502 | Specifically, this updates backing stores this working context | |
1503 | wraps to reflect the fact that the changes reflected by this |
|
1503 | wraps to reflect the fact that the changes reflected by this | |
1504 | workingctx have been committed. For example, it marks |
|
1504 | workingctx have been committed. For example, it marks | |
1505 | modified and added files as normal in the dirstate. |
|
1505 | modified and added files as normal in the dirstate. | |
1506 |
|
1506 | |||
1507 | """ |
|
1507 | """ | |
1508 |
|
1508 | |||
1509 | with self._repo.dirstate.parentchange(): |
|
1509 | with self._repo.dirstate.parentchange(): | |
1510 | for f in self.modified() + self.added(): |
|
1510 | for f in self.modified() + self.added(): | |
1511 | self._repo.dirstate.normal(f) |
|
1511 | self._repo.dirstate.normal(f) | |
1512 | for f in self.removed(): |
|
1512 | for f in self.removed(): | |
1513 | self._repo.dirstate.drop(f) |
|
1513 | self._repo.dirstate.drop(f) | |
1514 | self._repo.dirstate.setparents(node) |
|
1514 | self._repo.dirstate.setparents(node) | |
1515 |
|
1515 | |||
1516 | # write changes out explicitly, because nesting wlock at |
|
1516 | # write changes out explicitly, because nesting wlock at | |
1517 | # runtime may prevent 'wlock.release()' in 'repo.commit()' |
|
1517 | # runtime may prevent 'wlock.release()' in 'repo.commit()' | |
1518 | # from immediately doing so for subsequent changing files |
|
1518 | # from immediately doing so for subsequent changing files | |
1519 | self._repo.dirstate.write(self._repo.currenttransaction()) |
|
1519 | self._repo.dirstate.write(self._repo.currenttransaction()) | |
1520 |
|
1520 | |||
1521 | def dirty(self, missing=False, merge=True, branch=True): |
|
1521 | def dirty(self, missing=False, merge=True, branch=True): | |
1522 | return False |
|
1522 | return False | |
1523 |
|
1523 | |||
1524 | class workingctx(committablectx): |
|
1524 | class workingctx(committablectx): | |
1525 | """A workingctx object makes access to data related to |
|
1525 | """A workingctx object makes access to data related to | |
1526 | the current working directory convenient. |
|
1526 | the current working directory convenient. | |
1527 | date - any valid date string or (unixtime, offset), or None. |
|
1527 | date - any valid date string or (unixtime, offset), or None. | |
1528 | user - username string, or None. |
|
1528 | user - username string, or None. | |
1529 | extra - a dictionary of extra values, or None. |
|
1529 | extra - a dictionary of extra values, or None. | |
1530 | changes - a list of file lists as returned by localrepo.status() |
|
1530 | changes - a list of file lists as returned by localrepo.status() | |
1531 | or None to use the repository status. |
|
1531 | or None to use the repository status. | |
1532 | """ |
|
1532 | """ | |
1533 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1533 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1534 | changes=None): |
|
1534 | changes=None): | |
1535 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
|
1535 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) | |
1536 |
|
1536 | |||
1537 | def __iter__(self): |
|
1537 | def __iter__(self): | |
1538 | d = self._repo.dirstate |
|
1538 | d = self._repo.dirstate | |
1539 | for f in d: |
|
1539 | for f in d: | |
1540 | if d[f] != 'r': |
|
1540 | if d[f] != 'r': | |
1541 | yield f |
|
1541 | yield f | |
1542 |
|
1542 | |||
1543 | def __contains__(self, key): |
|
1543 | def __contains__(self, key): | |
1544 | return self._repo.dirstate[key] not in "?r" |
|
1544 | return self._repo.dirstate[key] not in "?r" | |
1545 |
|
1545 | |||
1546 | def hex(self): |
|
1546 | def hex(self): | |
1547 | return hex(wdirid) |
|
1547 | return hex(wdirid) | |
1548 |
|
1548 | |||
1549 | @propertycache |
|
1549 | @propertycache | |
1550 | def _parents(self): |
|
1550 | def _parents(self): | |
1551 | p = self._repo.dirstate.parents() |
|
1551 | p = self._repo.dirstate.parents() | |
1552 | if p[1] == nullid: |
|
1552 | if p[1] == nullid: | |
1553 | p = p[:-1] |
|
1553 | p = p[:-1] | |
1554 | return [changectx(self._repo, x) for x in p] |
|
1554 | return [changectx(self._repo, x) for x in p] | |
1555 |
|
1555 | |||
1556 | def filectx(self, path, filelog=None): |
|
1556 | def filectx(self, path, filelog=None): | |
1557 | """get a file context from the working directory""" |
|
1557 | """get a file context from the working directory""" | |
1558 | return workingfilectx(self._repo, path, workingctx=self, |
|
1558 | return workingfilectx(self._repo, path, workingctx=self, | |
1559 | filelog=filelog) |
|
1559 | filelog=filelog) | |
1560 |
|
1560 | |||
1561 | def dirty(self, missing=False, merge=True, branch=True): |
|
1561 | def dirty(self, missing=False, merge=True, branch=True): | |
1562 | "check whether a working directory is modified" |
|
1562 | "check whether a working directory is modified" | |
1563 | # check subrepos first |
|
1563 | # check subrepos first | |
1564 | for s in sorted(self.substate): |
|
1564 | for s in sorted(self.substate): | |
1565 | if self.sub(s).dirty(missing=missing): |
|
1565 | if self.sub(s).dirty(missing=missing): | |
1566 | return True |
|
1566 | return True | |
1567 | # check current working dir |
|
1567 | # check current working dir | |
1568 | return ((merge and self.p2()) or |
|
1568 | return ((merge and self.p2()) or | |
1569 | (branch and self.branch() != self.p1().branch()) or |
|
1569 | (branch and self.branch() != self.p1().branch()) or | |
1570 | self.modified() or self.added() or self.removed() or |
|
1570 | self.modified() or self.added() or self.removed() or | |
1571 | (missing and self.deleted())) |
|
1571 | (missing and self.deleted())) | |
1572 |
|
1572 | |||
1573 | def add(self, list, prefix=""): |
|
1573 | def add(self, list, prefix=""): | |
1574 | with self._repo.wlock(): |
|
1574 | with self._repo.wlock(): | |
1575 | ui, ds = self._repo.ui, self._repo.dirstate |
|
1575 | ui, ds = self._repo.ui, self._repo.dirstate | |
1576 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1576 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) | |
1577 | rejected = [] |
|
1577 | rejected = [] | |
1578 | lstat = self._repo.wvfs.lstat |
|
1578 | lstat = self._repo.wvfs.lstat | |
1579 | for f in list: |
|
1579 | for f in list: | |
1580 | # ds.pathto() returns an absolute file when this is invoked from |
|
1580 | # ds.pathto() returns an absolute file when this is invoked from | |
1581 | # the keyword extension. That gets flagged as non-portable on |
|
1581 | # the keyword extension. That gets flagged as non-portable on | |
1582 | # Windows, since it contains the drive letter and colon. |
|
1582 | # Windows, since it contains the drive letter and colon. | |
1583 | scmutil.checkportable(ui, os.path.join(prefix, f)) |
|
1583 | scmutil.checkportable(ui, os.path.join(prefix, f)) | |
1584 | try: |
|
1584 | try: | |
1585 | st = lstat(f) |
|
1585 | st = lstat(f) | |
1586 | except OSError: |
|
1586 | except OSError: | |
1587 | ui.warn(_("%s does not exist!\n") % uipath(f)) |
|
1587 | ui.warn(_("%s does not exist!\n") % uipath(f)) | |
1588 | rejected.append(f) |
|
1588 | rejected.append(f) | |
1589 | continue |
|
1589 | continue | |
1590 | if st.st_size > 10000000: |
|
1590 | if st.st_size > 10000000: | |
1591 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1591 | ui.warn(_("%s: up to %d MB of RAM may be required " | |
1592 | "to manage this file\n" |
|
1592 | "to manage this file\n" | |
1593 | "(use 'hg revert %s' to cancel the " |
|
1593 | "(use 'hg revert %s' to cancel the " | |
1594 | "pending addition)\n") |
|
1594 | "pending addition)\n") | |
1595 | % (f, 3 * st.st_size // 1000000, uipath(f))) |
|
1595 | % (f, 3 * st.st_size // 1000000, uipath(f))) | |
1596 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1596 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1597 | ui.warn(_("%s not added: only files and symlinks " |
|
1597 | ui.warn(_("%s not added: only files and symlinks " | |
1598 | "supported currently\n") % uipath(f)) |
|
1598 | "supported currently\n") % uipath(f)) | |
1599 | rejected.append(f) |
|
1599 | rejected.append(f) | |
1600 | elif ds[f] in 'amn': |
|
1600 | elif ds[f] in 'amn': | |
1601 | ui.warn(_("%s already tracked!\n") % uipath(f)) |
|
1601 | ui.warn(_("%s already tracked!\n") % uipath(f)) | |
1602 | elif ds[f] == 'r': |
|
1602 | elif ds[f] == 'r': | |
1603 | ds.normallookup(f) |
|
1603 | ds.normallookup(f) | |
1604 | else: |
|
1604 | else: | |
1605 | ds.add(f) |
|
1605 | ds.add(f) | |
1606 | return rejected |
|
1606 | return rejected | |
1607 |
|
1607 | |||
1608 | def forget(self, files, prefix=""): |
|
1608 | def forget(self, files, prefix=""): | |
1609 | with self._repo.wlock(): |
|
1609 | with self._repo.wlock(): | |
1610 | ds = self._repo.dirstate |
|
1610 | ds = self._repo.dirstate | |
1611 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1611 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) | |
1612 | rejected = [] |
|
1612 | rejected = [] | |
1613 | for f in files: |
|
1613 | for f in files: | |
1614 | if f not in self._repo.dirstate: |
|
1614 | if f not in self._repo.dirstate: | |
1615 | self._repo.ui.warn(_("%s not tracked!\n") % uipath(f)) |
|
1615 | self._repo.ui.warn(_("%s not tracked!\n") % uipath(f)) | |
1616 | rejected.append(f) |
|
1616 | rejected.append(f) | |
1617 | elif self._repo.dirstate[f] != 'a': |
|
1617 | elif self._repo.dirstate[f] != 'a': | |
1618 | self._repo.dirstate.remove(f) |
|
1618 | self._repo.dirstate.remove(f) | |
1619 | else: |
|
1619 | else: | |
1620 | self._repo.dirstate.drop(f) |
|
1620 | self._repo.dirstate.drop(f) | |
1621 | return rejected |
|
1621 | return rejected | |
1622 |
|
1622 | |||
1623 | def undelete(self, list): |
|
1623 | def undelete(self, list): | |
1624 | pctxs = self.parents() |
|
1624 | pctxs = self.parents() | |
1625 | with self._repo.wlock(): |
|
1625 | with self._repo.wlock(): | |
1626 | ds = self._repo.dirstate |
|
1626 | ds = self._repo.dirstate | |
1627 | for f in list: |
|
1627 | for f in list: | |
1628 | if self._repo.dirstate[f] != 'r': |
|
1628 | if self._repo.dirstate[f] != 'r': | |
1629 | self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f)) |
|
1629 | self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f)) | |
1630 | else: |
|
1630 | else: | |
1631 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
1631 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] | |
1632 | t = fctx.data() |
|
1632 | t = fctx.data() | |
1633 | self._repo.wwrite(f, t, fctx.flags()) |
|
1633 | self._repo.wwrite(f, t, fctx.flags()) | |
1634 | self._repo.dirstate.normal(f) |
|
1634 | self._repo.dirstate.normal(f) | |
1635 |
|
1635 | |||
1636 | def copy(self, source, dest): |
|
1636 | def copy(self, source, dest): | |
1637 | try: |
|
1637 | try: | |
1638 | st = self._repo.wvfs.lstat(dest) |
|
1638 | st = self._repo.wvfs.lstat(dest) | |
1639 | except OSError as err: |
|
1639 | except OSError as err: | |
1640 | if err.errno != errno.ENOENT: |
|
1640 | if err.errno != errno.ENOENT: | |
1641 | raise |
|
1641 | raise | |
1642 | self._repo.ui.warn(_("%s does not exist!\n") |
|
1642 | self._repo.ui.warn(_("%s does not exist!\n") | |
1643 | % self._repo.dirstate.pathto(dest)) |
|
1643 | % self._repo.dirstate.pathto(dest)) | |
1644 | return |
|
1644 | return | |
1645 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1645 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1646 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
1646 | self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
1647 | "symbolic link\n") |
|
1647 | "symbolic link\n") | |
1648 | % self._repo.dirstate.pathto(dest)) |
|
1648 | % self._repo.dirstate.pathto(dest)) | |
1649 | else: |
|
1649 | else: | |
1650 | with self._repo.wlock(): |
|
1650 | with self._repo.wlock(): | |
1651 | if self._repo.dirstate[dest] in '?': |
|
1651 | if self._repo.dirstate[dest] in '?': | |
1652 | self._repo.dirstate.add(dest) |
|
1652 | self._repo.dirstate.add(dest) | |
1653 | elif self._repo.dirstate[dest] in 'r': |
|
1653 | elif self._repo.dirstate[dest] in 'r': | |
1654 | self._repo.dirstate.normallookup(dest) |
|
1654 | self._repo.dirstate.normallookup(dest) | |
1655 | self._repo.dirstate.copy(source, dest) |
|
1655 | self._repo.dirstate.copy(source, dest) | |
1656 |
|
1656 | |||
1657 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
1657 | def match(self, pats=None, include=None, exclude=None, default='glob', | |
1658 | listsubrepos=False, badfn=None): |
|
1658 | listsubrepos=False, badfn=None): | |
1659 | r = self._repo |
|
1659 | r = self._repo | |
1660 |
|
1660 | |||
1661 | # Only a case insensitive filesystem needs magic to translate user input |
|
1661 | # Only a case insensitive filesystem needs magic to translate user input | |
1662 | # to actual case in the filesystem. |
|
1662 | # to actual case in the filesystem. | |
1663 | icasefs = not util.fscasesensitive(r.root) |
|
1663 | icasefs = not util.fscasesensitive(r.root) | |
1664 | return matchmod.match(r.root, r.getcwd(), pats, include, exclude, |
|
1664 | return matchmod.match(r.root, r.getcwd(), pats, include, exclude, | |
1665 | default, auditor=r.auditor, ctx=self, |
|
1665 | default, auditor=r.auditor, ctx=self, | |
1666 | listsubrepos=listsubrepos, badfn=badfn, |
|
1666 | listsubrepos=listsubrepos, badfn=badfn, | |
1667 | icasefs=icasefs) |
|
1667 | icasefs=icasefs) | |
1668 |
|
1668 | |||
1669 | def _filtersuspectsymlink(self, files): |
|
1669 | def _filtersuspectsymlink(self, files): | |
1670 | if not files or self._repo.dirstate._checklink: |
|
1670 | if not files or self._repo.dirstate._checklink: | |
1671 | return files |
|
1671 | return files | |
1672 |
|
1672 | |||
1673 | # Symlink placeholders may get non-symlink-like contents |
|
1673 | # Symlink placeholders may get non-symlink-like contents | |
1674 | # via user error or dereferencing by NFS or Samba servers, |
|
1674 | # via user error or dereferencing by NFS or Samba servers, | |
1675 | # so we filter out any placeholders that don't look like a |
|
1675 | # so we filter out any placeholders that don't look like a | |
1676 | # symlink |
|
1676 | # symlink | |
1677 | sane = [] |
|
1677 | sane = [] | |
1678 | for f in files: |
|
1678 | for f in files: | |
1679 | if self.flags(f) == 'l': |
|
1679 | if self.flags(f) == 'l': | |
1680 | d = self[f].data() |
|
1680 | d = self[f].data() | |
1681 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): |
|
1681 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): | |
1682 | self._repo.ui.debug('ignoring suspect symlink placeholder' |
|
1682 | self._repo.ui.debug('ignoring suspect symlink placeholder' | |
1683 | ' "%s"\n' % f) |
|
1683 | ' "%s"\n' % f) | |
1684 | continue |
|
1684 | continue | |
1685 | sane.append(f) |
|
1685 | sane.append(f) | |
1686 | return sane |
|
1686 | return sane | |
1687 |
|
1687 | |||
1688 | def _checklookup(self, files): |
|
1688 | def _checklookup(self, files): | |
1689 | # check for any possibly clean files |
|
1689 | # check for any possibly clean files | |
1690 | if not files: |
|
1690 | if not files: | |
1691 | return [], [], [] |
|
1691 | return [], [], [] | |
1692 |
|
1692 | |||
1693 | modified = [] |
|
1693 | modified = [] | |
1694 | deleted = [] |
|
1694 | deleted = [] | |
1695 | fixup = [] |
|
1695 | fixup = [] | |
1696 | pctx = self._parents[0] |
|
1696 | pctx = self._parents[0] | |
1697 | # do a full compare of any files that might have changed |
|
1697 | # do a full compare of any files that might have changed | |
1698 | for f in sorted(files): |
|
1698 | for f in sorted(files): | |
1699 | try: |
|
1699 | try: | |
1700 | # This will return True for a file that got replaced by a |
|
1700 | # This will return True for a file that got replaced by a | |
1701 | # directory in the interim, but fixing that is pretty hard. |
|
1701 | # directory in the interim, but fixing that is pretty hard. | |
1702 | if (f not in pctx or self.flags(f) != pctx.flags(f) |
|
1702 | if (f not in pctx or self.flags(f) != pctx.flags(f) | |
1703 | or pctx[f].cmp(self[f])): |
|
1703 | or pctx[f].cmp(self[f])): | |
1704 | modified.append(f) |
|
1704 | modified.append(f) | |
1705 | else: |
|
1705 | else: | |
1706 | fixup.append(f) |
|
1706 | fixup.append(f) | |
1707 | except (IOError, OSError): |
|
1707 | except (IOError, OSError): | |
1708 | # A file become inaccessible in between? Mark it as deleted, |
|
1708 | # A file become inaccessible in between? Mark it as deleted, | |
1709 | # matching dirstate behavior (issue5584). |
|
1709 | # matching dirstate behavior (issue5584). | |
1710 | # The dirstate has more complex behavior around whether a |
|
1710 | # The dirstate has more complex behavior around whether a | |
1711 | # missing file matches a directory, etc, but we don't need to |
|
1711 | # missing file matches a directory, etc, but we don't need to | |
1712 | # bother with that: if f has made it to this point, we're sure |
|
1712 | # bother with that: if f has made it to this point, we're sure | |
1713 | # it's in the dirstate. |
|
1713 | # it's in the dirstate. | |
1714 | deleted.append(f) |
|
1714 | deleted.append(f) | |
1715 |
|
1715 | |||
1716 | return modified, deleted, fixup |
|
1716 | return modified, deleted, fixup | |
1717 |
|
1717 | |||
1718 | def _poststatusfixup(self, status, fixup): |
|
1718 | def _poststatusfixup(self, status, fixup): | |
1719 | """update dirstate for files that are actually clean""" |
|
1719 | """update dirstate for files that are actually clean""" | |
1720 | poststatus = self._repo.postdsstatus() |
|
1720 | poststatus = self._repo.postdsstatus() | |
1721 | if fixup or poststatus: |
|
1721 | if fixup or poststatus: | |
1722 | try: |
|
1722 | try: | |
1723 | oldid = self._repo.dirstate.identity() |
|
1723 | oldid = self._repo.dirstate.identity() | |
1724 |
|
1724 | |||
1725 | # updating the dirstate is optional |
|
1725 | # updating the dirstate is optional | |
1726 | # so we don't wait on the lock |
|
1726 | # so we don't wait on the lock | |
1727 | # wlock can invalidate the dirstate, so cache normal _after_ |
|
1727 | # wlock can invalidate the dirstate, so cache normal _after_ | |
1728 | # taking the lock |
|
1728 | # taking the lock | |
1729 | with self._repo.wlock(False): |
|
1729 | with self._repo.wlock(False): | |
1730 | if self._repo.dirstate.identity() == oldid: |
|
1730 | if self._repo.dirstate.identity() == oldid: | |
1731 | if fixup: |
|
1731 | if fixup: | |
1732 | normal = self._repo.dirstate.normal |
|
1732 | normal = self._repo.dirstate.normal | |
1733 | for f in fixup: |
|
1733 | for f in fixup: | |
1734 | normal(f) |
|
1734 | normal(f) | |
1735 | # write changes out explicitly, because nesting |
|
1735 | # write changes out explicitly, because nesting | |
1736 | # wlock at runtime may prevent 'wlock.release()' |
|
1736 | # wlock at runtime may prevent 'wlock.release()' | |
1737 | # after this block from doing so for subsequent |
|
1737 | # after this block from doing so for subsequent | |
1738 | # changing files |
|
1738 | # changing files | |
1739 | tr = self._repo.currenttransaction() |
|
1739 | tr = self._repo.currenttransaction() | |
1740 | self._repo.dirstate.write(tr) |
|
1740 | self._repo.dirstate.write(tr) | |
1741 |
|
1741 | |||
1742 | if poststatus: |
|
1742 | if poststatus: | |
1743 | for ps in poststatus: |
|
1743 | for ps in poststatus: | |
1744 | ps(self, status) |
|
1744 | ps(self, status) | |
1745 | else: |
|
1745 | else: | |
1746 | # in this case, writing changes out breaks |
|
1746 | # in this case, writing changes out breaks | |
1747 | # consistency, because .hg/dirstate was |
|
1747 | # consistency, because .hg/dirstate was | |
1748 | # already changed simultaneously after last |
|
1748 | # already changed simultaneously after last | |
1749 | # caching (see also issue5584 for detail) |
|
1749 | # caching (see also issue5584 for detail) | |
1750 | self._repo.ui.debug('skip updating dirstate: ' |
|
1750 | self._repo.ui.debug('skip updating dirstate: ' | |
1751 | 'identity mismatch\n') |
|
1751 | 'identity mismatch\n') | |
1752 | except error.LockError: |
|
1752 | except error.LockError: | |
1753 | pass |
|
1753 | pass | |
1754 | finally: |
|
1754 | finally: | |
1755 | # Even if the wlock couldn't be grabbed, clear out the list. |
|
1755 | # Even if the wlock couldn't be grabbed, clear out the list. | |
1756 | self._repo.clearpostdsstatus() |
|
1756 | self._repo.clearpostdsstatus() | |
1757 |
|
1757 | |||
1758 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
1758 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): | |
1759 | '''Gets the status from the dirstate -- internal use only.''' |
|
1759 | '''Gets the status from the dirstate -- internal use only.''' | |
1760 | subrepos = [] |
|
1760 | subrepos = [] | |
1761 | if '.hgsub' in self: |
|
1761 | if '.hgsub' in self: | |
1762 | subrepos = sorted(self.substate) |
|
1762 | subrepos = sorted(self.substate) | |
1763 | cmp, s = self._repo.dirstate.status(match, subrepos, ignored=ignored, |
|
1763 | cmp, s = self._repo.dirstate.status(match, subrepos, ignored=ignored, | |
1764 | clean=clean, unknown=unknown) |
|
1764 | clean=clean, unknown=unknown) | |
1765 |
|
1765 | |||
1766 | # check for any possibly clean files |
|
1766 | # check for any possibly clean files | |
1767 | fixup = [] |
|
1767 | fixup = [] | |
1768 | if cmp: |
|
1768 | if cmp: | |
1769 | modified2, deleted2, fixup = self._checklookup(cmp) |
|
1769 | modified2, deleted2, fixup = self._checklookup(cmp) | |
1770 | s.modified.extend(modified2) |
|
1770 | s.modified.extend(modified2) | |
1771 | s.deleted.extend(deleted2) |
|
1771 | s.deleted.extend(deleted2) | |
1772 |
|
1772 | |||
1773 | if fixup and clean: |
|
1773 | if fixup and clean: | |
1774 | s.clean.extend(fixup) |
|
1774 | s.clean.extend(fixup) | |
1775 |
|
1775 | |||
1776 | self._poststatusfixup(s, fixup) |
|
1776 | self._poststatusfixup(s, fixup) | |
1777 |
|
1777 | |||
1778 | if match.always(): |
|
1778 | if match.always(): | |
1779 | # cache for performance |
|
1779 | # cache for performance | |
1780 | if s.unknown or s.ignored or s.clean: |
|
1780 | if s.unknown or s.ignored or s.clean: | |
1781 | # "_status" is cached with list*=False in the normal route |
|
1781 | # "_status" is cached with list*=False in the normal route | |
1782 | self._status = scmutil.status(s.modified, s.added, s.removed, |
|
1782 | self._status = scmutil.status(s.modified, s.added, s.removed, | |
1783 | s.deleted, [], [], []) |
|
1783 | s.deleted, [], [], []) | |
1784 | else: |
|
1784 | else: | |
1785 | self._status = s |
|
1785 | self._status = s | |
1786 |
|
1786 | |||
1787 | return s |
|
1787 | return s | |
1788 |
|
1788 | |||
1789 | @propertycache |
|
1789 | @propertycache | |
1790 | def _manifest(self): |
|
1790 | def _manifest(self): | |
1791 | """generate a manifest corresponding to the values in self._status |
|
1791 | """generate a manifest corresponding to the values in self._status | |
1792 |
|
1792 | |||
1793 | This reuse the file nodeid from parent, but we use special node |
|
1793 | This reuse the file nodeid from parent, but we use special node | |
1794 | identifiers for added and modified files. This is used by manifests |
|
1794 | identifiers for added and modified files. This is used by manifests | |
1795 | merge to see that files are different and by update logic to avoid |
|
1795 | merge to see that files are different and by update logic to avoid | |
1796 | deleting newly added files. |
|
1796 | deleting newly added files. | |
1797 | """ |
|
1797 | """ | |
1798 | return self._buildstatusmanifest(self._status) |
|
1798 | return self._buildstatusmanifest(self._status) | |
1799 |
|
1799 | |||
1800 | def _buildstatusmanifest(self, status): |
|
1800 | def _buildstatusmanifest(self, status): | |
1801 | """Builds a manifest that includes the given status results.""" |
|
1801 | """Builds a manifest that includes the given status results.""" | |
1802 | parents = self.parents() |
|
1802 | parents = self.parents() | |
1803 |
|
1803 | |||
1804 | man = parents[0].manifest().copy() |
|
1804 | man = parents[0].manifest().copy() | |
1805 |
|
1805 | |||
1806 | ff = self._flagfunc |
|
1806 | ff = self._flagfunc | |
1807 | for i, l in ((addednodeid, status.added), |
|
1807 | for i, l in ((addednodeid, status.added), | |
1808 | (modifiednodeid, status.modified)): |
|
1808 | (modifiednodeid, status.modified)): | |
1809 | for f in l: |
|
1809 | for f in l: | |
1810 | man[f] = i |
|
1810 | man[f] = i | |
1811 | try: |
|
1811 | try: | |
1812 | man.setflag(f, ff(f)) |
|
1812 | man.setflag(f, ff(f)) | |
1813 | except OSError: |
|
1813 | except OSError: | |
1814 | pass |
|
1814 | pass | |
1815 |
|
1815 | |||
1816 | for f in status.deleted + status.removed: |
|
1816 | for f in status.deleted + status.removed: | |
1817 | if f in man: |
|
1817 | if f in man: | |
1818 | del man[f] |
|
1818 | del man[f] | |
1819 |
|
1819 | |||
1820 | return man |
|
1820 | return man | |
1821 |
|
1821 | |||
1822 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
1822 | def _buildstatus(self, other, s, match, listignored, listclean, | |
1823 | listunknown): |
|
1823 | listunknown): | |
1824 | """build a status with respect to another context |
|
1824 | """build a status with respect to another context | |
1825 |
|
1825 | |||
1826 | This includes logic for maintaining the fast path of status when |
|
1826 | This includes logic for maintaining the fast path of status when | |
1827 | comparing the working directory against its parent, which is to skip |
|
1827 | comparing the working directory against its parent, which is to skip | |
1828 | building a new manifest if self (working directory) is not comparing |
|
1828 | building a new manifest if self (working directory) is not comparing | |
1829 | against its parent (repo['.']). |
|
1829 | against its parent (repo['.']). | |
1830 | """ |
|
1830 | """ | |
1831 | s = self._dirstatestatus(match, listignored, listclean, listunknown) |
|
1831 | s = self._dirstatestatus(match, listignored, listclean, listunknown) | |
1832 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, |
|
1832 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, | |
1833 | # might have accidentally ended up with the entire contents of the file |
|
1833 | # might have accidentally ended up with the entire contents of the file | |
1834 | # they are supposed to be linking to. |
|
1834 | # they are supposed to be linking to. | |
1835 | s.modified[:] = self._filtersuspectsymlink(s.modified) |
|
1835 | s.modified[:] = self._filtersuspectsymlink(s.modified) | |
1836 | if other != self._repo['.']: |
|
1836 | if other != self._repo['.']: | |
1837 | s = super(workingctx, self)._buildstatus(other, s, match, |
|
1837 | s = super(workingctx, self)._buildstatus(other, s, match, | |
1838 | listignored, listclean, |
|
1838 | listignored, listclean, | |
1839 | listunknown) |
|
1839 | listunknown) | |
1840 | return s |
|
1840 | return s | |
1841 |
|
1841 | |||
1842 | def _matchstatus(self, other, match): |
|
1842 | def _matchstatus(self, other, match): | |
1843 | """override the match method with a filter for directory patterns |
|
1843 | """override the match method with a filter for directory patterns | |
1844 |
|
1844 | |||
1845 | We use inheritance to customize the match.bad method only in cases of |
|
1845 | We use inheritance to customize the match.bad method only in cases of | |
1846 | workingctx since it belongs only to the working directory when |
|
1846 | workingctx since it belongs only to the working directory when | |
1847 | comparing against the parent changeset. |
|
1847 | comparing against the parent changeset. | |
1848 |
|
1848 | |||
1849 | If we aren't comparing against the working directory's parent, then we |
|
1849 | If we aren't comparing against the working directory's parent, then we | |
1850 | just use the default match object sent to us. |
|
1850 | just use the default match object sent to us. | |
1851 | """ |
|
1851 | """ | |
1852 | if other != self._repo['.']: |
|
1852 | if other != self._repo['.']: | |
1853 | def bad(f, msg): |
|
1853 | def bad(f, msg): | |
1854 | # 'f' may be a directory pattern from 'match.files()', |
|
1854 | # 'f' may be a directory pattern from 'match.files()', | |
1855 | # so 'f not in ctx1' is not enough |
|
1855 | # so 'f not in ctx1' is not enough | |
1856 | if f not in other and not other.hasdir(f): |
|
1856 | if f not in other and not other.hasdir(f): | |
1857 | self._repo.ui.warn('%s: %s\n' % |
|
1857 | self._repo.ui.warn('%s: %s\n' % | |
1858 | (self._repo.dirstate.pathto(f), msg)) |
|
1858 | (self._repo.dirstate.pathto(f), msg)) | |
1859 | match.bad = bad |
|
1859 | match.bad = bad | |
1860 | return match |
|
1860 | return match | |
1861 |
|
1861 | |||
1862 | def markcommitted(self, node): |
|
1862 | def markcommitted(self, node): | |
1863 | super(workingctx, self).markcommitted(node) |
|
1863 | super(workingctx, self).markcommitted(node) | |
1864 |
|
1864 | |||
1865 | sparse.aftercommit(self._repo, node) |
|
1865 | sparse.aftercommit(self._repo, node) | |
1866 |
|
1866 | |||
1867 | class committablefilectx(basefilectx): |
|
1867 | class committablefilectx(basefilectx): | |
1868 | """A committablefilectx provides common functionality for a file context |
|
1868 | """A committablefilectx provides common functionality for a file context | |
1869 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" |
|
1869 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" | |
1870 | def __init__(self, repo, path, filelog=None, ctx=None): |
|
1870 | def __init__(self, repo, path, filelog=None, ctx=None): | |
1871 | self._repo = repo |
|
1871 | self._repo = repo | |
1872 | self._path = path |
|
1872 | self._path = path | |
1873 | self._changeid = None |
|
1873 | self._changeid = None | |
1874 | self._filerev = self._filenode = None |
|
1874 | self._filerev = self._filenode = None | |
1875 |
|
1875 | |||
1876 | if filelog is not None: |
|
1876 | if filelog is not None: | |
1877 | self._filelog = filelog |
|
1877 | self._filelog = filelog | |
1878 | if ctx: |
|
1878 | if ctx: | |
1879 | self._changectx = ctx |
|
1879 | self._changectx = ctx | |
1880 |
|
1880 | |||
1881 | def __nonzero__(self): |
|
1881 | def __nonzero__(self): | |
1882 | return True |
|
1882 | return True | |
1883 |
|
1883 | |||
1884 | __bool__ = __nonzero__ |
|
1884 | __bool__ = __nonzero__ | |
1885 |
|
1885 | |||
1886 | def linkrev(self): |
|
1886 | def linkrev(self): | |
1887 | # linked to self._changectx no matter if file is modified or not |
|
1887 | # linked to self._changectx no matter if file is modified or not | |
1888 | return self.rev() |
|
1888 | return self.rev() | |
1889 |
|
1889 | |||
1890 | def parents(self): |
|
1890 | def parents(self): | |
1891 | '''return parent filectxs, following copies if necessary''' |
|
1891 | '''return parent filectxs, following copies if necessary''' | |
1892 | def filenode(ctx, path): |
|
1892 | def filenode(ctx, path): | |
1893 | return ctx._manifest.get(path, nullid) |
|
1893 | return ctx._manifest.get(path, nullid) | |
1894 |
|
1894 | |||
1895 | path = self._path |
|
1895 | path = self._path | |
1896 | fl = self._filelog |
|
1896 | fl = self._filelog | |
1897 | pcl = self._changectx._parents |
|
1897 | pcl = self._changectx._parents | |
1898 | renamed = self.renamed() |
|
1898 | renamed = self.renamed() | |
1899 |
|
1899 | |||
1900 | if renamed: |
|
1900 | if renamed: | |
1901 | pl = [renamed + (None,)] |
|
1901 | pl = [renamed + (None,)] | |
1902 | else: |
|
1902 | else: | |
1903 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1903 | pl = [(path, filenode(pcl[0], path), fl)] | |
1904 |
|
1904 | |||
1905 | for pc in pcl[1:]: |
|
1905 | for pc in pcl[1:]: | |
1906 | pl.append((path, filenode(pc, path), fl)) |
|
1906 | pl.append((path, filenode(pc, path), fl)) | |
1907 |
|
1907 | |||
1908 | return [self._parentfilectx(p, fileid=n, filelog=l) |
|
1908 | return [self._parentfilectx(p, fileid=n, filelog=l) | |
1909 | for p, n, l in pl if n != nullid] |
|
1909 | for p, n, l in pl if n != nullid] | |
1910 |
|
1910 | |||
1911 | def children(self): |
|
1911 | def children(self): | |
1912 | return [] |
|
1912 | return [] | |
1913 |
|
1913 | |||
1914 | class workingfilectx(committablefilectx): |
|
1914 | class workingfilectx(committablefilectx): | |
1915 | """A workingfilectx object makes access to data related to a particular |
|
1915 | """A workingfilectx object makes access to data related to a particular | |
1916 | file in the working directory convenient.""" |
|
1916 | file in the working directory convenient.""" | |
1917 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
1917 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
1918 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) |
|
1918 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) | |
1919 |
|
1919 | |||
1920 | @propertycache |
|
1920 | @propertycache | |
1921 | def _changectx(self): |
|
1921 | def _changectx(self): | |
1922 | return workingctx(self._repo) |
|
1922 | return workingctx(self._repo) | |
1923 |
|
1923 | |||
1924 | def data(self): |
|
1924 | def data(self): | |
1925 | return self._repo.wread(self._path) |
|
1925 | return self._repo.wread(self._path) | |
1926 | def renamed(self): |
|
1926 | def renamed(self): | |
1927 | rp = self._repo.dirstate.copied(self._path) |
|
1927 | rp = self._repo.dirstate.copied(self._path) | |
1928 | if not rp: |
|
1928 | if not rp: | |
1929 | return None |
|
1929 | return None | |
1930 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1930 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
1931 |
|
1931 | |||
1932 | def size(self): |
|
1932 | def size(self): | |
1933 | return self._repo.wvfs.lstat(self._path).st_size |
|
1933 | return self._repo.wvfs.lstat(self._path).st_size | |
1934 | def date(self): |
|
1934 | def date(self): | |
1935 | t, tz = self._changectx.date() |
|
1935 | t, tz = self._changectx.date() | |
1936 | try: |
|
1936 | try: | |
1937 | return (self._repo.wvfs.lstat(self._path).st_mtime, tz) |
|
1937 | return (self._repo.wvfs.lstat(self._path).st_mtime, tz) | |
1938 | except OSError as err: |
|
1938 | except OSError as err: | |
1939 | if err.errno != errno.ENOENT: |
|
1939 | if err.errno != errno.ENOENT: | |
1940 | raise |
|
1940 | raise | |
1941 | return (t, tz) |
|
1941 | return (t, tz) | |
1942 |
|
1942 | |||
1943 | def exists(self): |
|
1943 | def exists(self): | |
1944 | return self._repo.wvfs.exists(self._path) |
|
1944 | return self._repo.wvfs.exists(self._path) | |
1945 |
|
1945 | |||
1946 | def lexists(self): |
|
1946 | def lexists(self): | |
1947 | return self._repo.wvfs.lexists(self._path) |
|
1947 | return self._repo.wvfs.lexists(self._path) | |
1948 |
|
1948 | |||
1949 | def audit(self): |
|
1949 | def audit(self): | |
1950 | return self._repo.wvfs.audit(self._path) |
|
1950 | return self._repo.wvfs.audit(self._path) | |
1951 |
|
1951 | |||
1952 | def cmp(self, fctx): |
|
1952 | def cmp(self, fctx): | |
1953 | """compare with other file context |
|
1953 | """compare with other file context | |
1954 |
|
1954 | |||
1955 | returns True if different than fctx. |
|
1955 | returns True if different than fctx. | |
1956 | """ |
|
1956 | """ | |
1957 | # fctx should be a filectx (not a workingfilectx) |
|
1957 | # fctx should be a filectx (not a workingfilectx) | |
1958 | # invert comparison to reuse the same code path |
|
1958 | # invert comparison to reuse the same code path | |
1959 | return fctx.cmp(self) |
|
1959 | return fctx.cmp(self) | |
1960 |
|
1960 | |||
1961 | def remove(self, ignoremissing=False): |
|
1961 | def remove(self, ignoremissing=False): | |
1962 | """wraps unlink for a repo's working directory""" |
|
1962 | """wraps unlink for a repo's working directory""" | |
1963 | self._repo.wvfs.unlinkpath(self._path, ignoremissing=ignoremissing) |
|
1963 | self._repo.wvfs.unlinkpath(self._path, ignoremissing=ignoremissing) | |
1964 |
|
1964 | |||
1965 | def write(self, data, flags, backgroundclose=False): |
|
1965 | def write(self, data, flags, backgroundclose=False): | |
1966 | """wraps repo.wwrite""" |
|
1966 | """wraps repo.wwrite""" | |
1967 | self._repo.wwrite(self._path, data, flags, |
|
1967 | self._repo.wwrite(self._path, data, flags, | |
1968 | backgroundclose=backgroundclose) |
|
1968 | backgroundclose=backgroundclose) | |
1969 |
|
1969 | |||
1970 | def markcopied(self, src): |
|
1970 | def markcopied(self, src): | |
1971 | """marks this file a copy of `src`""" |
|
1971 | """marks this file a copy of `src`""" | |
1972 | if self._repo.dirstate[self._path] in "nma": |
|
1972 | if self._repo.dirstate[self._path] in "nma": | |
1973 | self._repo.dirstate.copy(src, self._path) |
|
1973 | self._repo.dirstate.copy(src, self._path) | |
1974 |
|
1974 | |||
1975 | def clearunknown(self): |
|
1975 | def clearunknown(self): | |
1976 | """Removes conflicting items in the working directory so that |
|
1976 | """Removes conflicting items in the working directory so that | |
1977 | ``write()`` can be called successfully. |
|
1977 | ``write()`` can be called successfully. | |
1978 | """ |
|
1978 | """ | |
1979 | wvfs = self._repo.wvfs |
|
1979 | wvfs = self._repo.wvfs | |
1980 | f = self._path |
|
1980 | f = self._path | |
1981 | wvfs.audit(f) |
|
1981 | wvfs.audit(f) | |
1982 | if wvfs.isdir(f) and not wvfs.islink(f): |
|
1982 | if wvfs.isdir(f) and not wvfs.islink(f): | |
1983 | wvfs.rmtree(f, forcibly=True) |
|
1983 | wvfs.rmtree(f, forcibly=True) | |
1984 | for p in reversed(list(util.finddirs(f))): |
|
1984 | for p in reversed(list(util.finddirs(f))): | |
1985 | if wvfs.isfileorlink(p): |
|
1985 | if wvfs.isfileorlink(p): | |
1986 | wvfs.unlink(p) |
|
1986 | wvfs.unlink(p) | |
1987 | break |
|
1987 | break | |
1988 |
|
1988 | |||
1989 | def setflags(self, l, x): |
|
1989 | def setflags(self, l, x): | |
1990 | self._repo.wvfs.setflags(self._path, l, x) |
|
1990 | self._repo.wvfs.setflags(self._path, l, x) | |
1991 |
|
1991 | |||
1992 | class overlayworkingctx(committablectx): |
|
1992 | class overlayworkingctx(committablectx): | |
1993 | """Wraps another mutable context with a write-back cache that can be |
|
1993 | """Wraps another mutable context with a write-back cache that can be | |
1994 | converted into a commit context. |
|
1994 | converted into a commit context. | |
1995 |
|
1995 | |||
1996 | self._cache[path] maps to a dict with keys: { |
|
1996 | self._cache[path] maps to a dict with keys: { | |
1997 | 'exists': bool? |
|
1997 | 'exists': bool? | |
1998 | 'date': date? |
|
1998 | 'date': date? | |
1999 | 'data': str? |
|
1999 | 'data': str? | |
2000 | 'flags': str? |
|
2000 | 'flags': str? | |
2001 | 'copied': str? (path or None) |
|
2001 | 'copied': str? (path or None) | |
2002 | } |
|
2002 | } | |
2003 | If `exists` is True, `flags` must be non-None and 'date' is non-None. If it |
|
2003 | If `exists` is True, `flags` must be non-None and 'date' is non-None. If it | |
2004 | is `False`, the file was deleted. |
|
2004 | is `False`, the file was deleted. | |
2005 | """ |
|
2005 | """ | |
2006 |
|
2006 | |||
2007 | def __init__(self, repo): |
|
2007 | def __init__(self, repo): | |
2008 | super(overlayworkingctx, self).__init__(repo) |
|
2008 | super(overlayworkingctx, self).__init__(repo) | |
2009 | self._repo = repo |
|
2009 | self._repo = repo | |
2010 | self.clean() |
|
2010 | self.clean() | |
2011 |
|
2011 | |||
2012 | def setbase(self, wrappedctx): |
|
2012 | def setbase(self, wrappedctx): | |
2013 | self._wrappedctx = wrappedctx |
|
2013 | self._wrappedctx = wrappedctx | |
2014 | self._parents = [wrappedctx] |
|
2014 | self._parents = [wrappedctx] | |
2015 | # Drop old manifest cache as it is now out of date. |
|
2015 | # Drop old manifest cache as it is now out of date. | |
2016 | # This is necessary when, e.g., rebasing several nodes with one |
|
2016 | # This is necessary when, e.g., rebasing several nodes with one | |
2017 | # ``overlayworkingctx`` (e.g. with --collapse). |
|
2017 | # ``overlayworkingctx`` (e.g. with --collapse). | |
2018 | util.clearcachedproperty(self, '_manifest') |
|
2018 | util.clearcachedproperty(self, '_manifest') | |
2019 |
|
2019 | |||
2020 | def data(self, path): |
|
2020 | def data(self, path): | |
2021 | if self.isdirty(path): |
|
2021 | if self.isdirty(path): | |
2022 | if self._cache[path]['exists']: |
|
2022 | if self._cache[path]['exists']: | |
2023 | if self._cache[path]['data']: |
|
2023 | if self._cache[path]['data']: | |
2024 | return self._cache[path]['data'] |
|
2024 | return self._cache[path]['data'] | |
2025 | else: |
|
2025 | else: | |
2026 | # Must fallback here, too, because we only set flags. |
|
2026 | # Must fallback here, too, because we only set flags. | |
2027 | return self._wrappedctx[path].data() |
|
2027 | return self._wrappedctx[path].data() | |
2028 | else: |
|
2028 | else: | |
2029 | raise error.ProgrammingError("No such file or directory: %s" % |
|
2029 | raise error.ProgrammingError("No such file or directory: %s" % | |
2030 | path) |
|
2030 | path) | |
2031 | else: |
|
2031 | else: | |
2032 | return self._wrappedctx[path].data() |
|
2032 | return self._wrappedctx[path].data() | |
2033 |
|
2033 | |||
2034 | @propertycache |
|
2034 | @propertycache | |
2035 | def _manifest(self): |
|
2035 | def _manifest(self): | |
2036 | parents = self.parents() |
|
2036 | parents = self.parents() | |
2037 | man = parents[0].manifest().copy() |
|
2037 | man = parents[0].manifest().copy() | |
2038 |
|
2038 | |||
2039 | flag = self._flagfunc |
|
2039 | flag = self._flagfunc | |
2040 | for path in self.added(): |
|
2040 | for path in self.added(): | |
2041 | man[path] = addednodeid |
|
2041 | man[path] = addednodeid | |
2042 | man.setflag(path, flag(path)) |
|
2042 | man.setflag(path, flag(path)) | |
2043 | for path in self.modified(): |
|
2043 | for path in self.modified(): | |
2044 | man[path] = modifiednodeid |
|
2044 | man[path] = modifiednodeid | |
2045 | man.setflag(path, flag(path)) |
|
2045 | man.setflag(path, flag(path)) | |
2046 | for path in self.removed(): |
|
2046 | for path in self.removed(): | |
2047 | del man[path] |
|
2047 | del man[path] | |
2048 | return man |
|
2048 | return man | |
2049 |
|
2049 | |||
2050 | @propertycache |
|
2050 | @propertycache | |
2051 | def _flagfunc(self): |
|
2051 | def _flagfunc(self): | |
2052 | def f(path): |
|
2052 | def f(path): | |
2053 | return self._cache[path]['flags'] |
|
2053 | return self._cache[path]['flags'] | |
2054 | return f |
|
2054 | return f | |
2055 |
|
2055 | |||
2056 | def files(self): |
|
2056 | def files(self): | |
2057 | return sorted(self.added() + self.modified() + self.removed()) |
|
2057 | return sorted(self.added() + self.modified() + self.removed()) | |
2058 |
|
2058 | |||
2059 | def modified(self): |
|
2059 | def modified(self): | |
2060 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and |
|
2060 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and | |
2061 | self._existsinparent(f)] |
|
2061 | self._existsinparent(f)] | |
2062 |
|
2062 | |||
2063 | def added(self): |
|
2063 | def added(self): | |
2064 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and |
|
2064 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and | |
2065 | not self._existsinparent(f)] |
|
2065 | not self._existsinparent(f)] | |
2066 |
|
2066 | |||
2067 | def removed(self): |
|
2067 | def removed(self): | |
2068 | return [f for f in self._cache.keys() if |
|
2068 | return [f for f in self._cache.keys() if | |
2069 | not self._cache[f]['exists'] and self._existsinparent(f)] |
|
2069 | not self._cache[f]['exists'] and self._existsinparent(f)] | |
2070 |
|
2070 | |||
2071 | def isinmemory(self): |
|
2071 | def isinmemory(self): | |
2072 | return True |
|
2072 | return True | |
2073 |
|
2073 | |||
2074 | def filedate(self, path): |
|
2074 | def filedate(self, path): | |
2075 | if self.isdirty(path): |
|
2075 | if self.isdirty(path): | |
2076 | return self._cache[path]['date'] |
|
2076 | return self._cache[path]['date'] | |
2077 | else: |
|
2077 | else: | |
2078 | return self._wrappedctx[path].date() |
|
2078 | return self._wrappedctx[path].date() | |
2079 |
|
2079 | |||
2080 | def markcopied(self, path, origin): |
|
2080 | def markcopied(self, path, origin): | |
2081 | if self.isdirty(path): |
|
2081 | if self.isdirty(path): | |
2082 | self._cache[path]['copied'] = origin |
|
2082 | self._cache[path]['copied'] = origin | |
2083 | else: |
|
2083 | else: | |
2084 | raise error.ProgrammingError('markcopied() called on clean context') |
|
2084 | raise error.ProgrammingError('markcopied() called on clean context') | |
2085 |
|
2085 | |||
2086 | def copydata(self, path): |
|
2086 | def copydata(self, path): | |
2087 | if self.isdirty(path): |
|
2087 | if self.isdirty(path): | |
2088 | return self._cache[path]['copied'] |
|
2088 | return self._cache[path]['copied'] | |
2089 | else: |
|
2089 | else: | |
2090 | raise error.ProgrammingError('copydata() called on clean context') |
|
2090 | raise error.ProgrammingError('copydata() called on clean context') | |
2091 |
|
2091 | |||
2092 | def flags(self, path): |
|
2092 | def flags(self, path): | |
2093 | if self.isdirty(path): |
|
2093 | if self.isdirty(path): | |
2094 | if self._cache[path]['exists']: |
|
2094 | if self._cache[path]['exists']: | |
2095 | return self._cache[path]['flags'] |
|
2095 | return self._cache[path]['flags'] | |
2096 | else: |
|
2096 | else: | |
2097 | raise error.ProgrammingError("No such file or directory: %s" % |
|
2097 | raise error.ProgrammingError("No such file or directory: %s" % | |
2098 | self._path) |
|
2098 | self._path) | |
2099 | else: |
|
2099 | else: | |
2100 | return self._wrappedctx[path].flags() |
|
2100 | return self._wrappedctx[path].flags() | |
2101 |
|
2101 | |||
2102 | def _existsinparent(self, path): |
|
2102 | def _existsinparent(self, path): | |
2103 | try: |
|
2103 | try: | |
2104 | # ``commitctx` raises a ``ManifestLookupError`` if a path does not |
|
2104 | # ``commitctx` raises a ``ManifestLookupError`` if a path does not | |
2105 | # exist, unlike ``workingctx``, which returns a ``workingfilectx`` |
|
2105 | # exist, unlike ``workingctx``, which returns a ``workingfilectx`` | |
2106 | # with an ``exists()`` function. |
|
2106 | # with an ``exists()`` function. | |
2107 | self._wrappedctx[path] |
|
2107 | self._wrappedctx[path] | |
2108 | return True |
|
2108 | return True | |
2109 | except error.ManifestLookupError: |
|
2109 | except error.ManifestLookupError: | |
2110 | return False |
|
2110 | return False | |
2111 |
|
2111 | |||
2112 | def _auditconflicts(self, path): |
|
2112 | def _auditconflicts(self, path): | |
2113 | """Replicates conflict checks done by wvfs.write(). |
|
2113 | """Replicates conflict checks done by wvfs.write(). | |
2114 |
|
2114 | |||
2115 | Since we never write to the filesystem and never call `applyupdates` in |
|
2115 | Since we never write to the filesystem and never call `applyupdates` in | |
2116 | IMM, we'll never check that a path is actually writable -- e.g., because |
|
2116 | IMM, we'll never check that a path is actually writable -- e.g., because | |
2117 | it adds `a/foo`, but `a` is actually a file in the other commit. |
|
2117 | it adds `a/foo`, but `a` is actually a file in the other commit. | |
2118 | """ |
|
2118 | """ | |
2119 | def fail(path, component): |
|
2119 | def fail(path, component): | |
2120 | # p1() is the base and we're receiving "writes" for p2()'s |
|
2120 | # p1() is the base and we're receiving "writes" for p2()'s | |
2121 | # files. |
|
2121 | # files. | |
2122 | if 'l' in self.p1()[component].flags(): |
|
2122 | if 'l' in self.p1()[component].flags(): | |
2123 | raise error.Abort("error: %s conflicts with symlink %s " |
|
2123 | raise error.Abort("error: %s conflicts with symlink %s " | |
2124 | "in %s." % (path, component, |
|
2124 | "in %s." % (path, component, | |
2125 | self.p1().rev())) |
|
2125 | self.p1().rev())) | |
2126 | else: |
|
2126 | else: | |
2127 | raise error.Abort("error: '%s' conflicts with file '%s' in " |
|
2127 | raise error.Abort("error: '%s' conflicts with file '%s' in " | |
2128 | "%s." % (path, component, |
|
2128 | "%s." % (path, component, | |
2129 | self.p1().rev())) |
|
2129 | self.p1().rev())) | |
2130 |
|
2130 | |||
2131 | # Test that each new directory to be created to write this path from p2 |
|
2131 | # Test that each new directory to be created to write this path from p2 | |
2132 | # is not a file in p1. |
|
2132 | # is not a file in p1. | |
2133 | components = path.split('/') |
|
2133 | components = path.split('/') | |
2134 | for i in xrange(len(components)): |
|
2134 | for i in xrange(len(components)): | |
2135 | component = "/".join(components[0:i]) |
|
2135 | component = "/".join(components[0:i]) | |
2136 | if component in self.p1(): |
|
2136 | if component in self.p1(): | |
2137 | fail(path, component) |
|
2137 | fail(path, component) | |
2138 |
|
2138 | |||
2139 | # Test the other direction -- that this path from p2 isn't a directory |
|
2139 | # Test the other direction -- that this path from p2 isn't a directory | |
2140 | # in p1 (test that p1 doesn't any paths matching `path/*`). |
|
2140 | # in p1 (test that p1 doesn't any paths matching `path/*`). | |
2141 | match = matchmod.match('/', '', [path + '/'], default=b'relpath') |
|
2141 | match = matchmod.match('/', '', [path + '/'], default=b'relpath') | |
2142 | matches = self.p1().manifest().matches(match) |
|
2142 | matches = self.p1().manifest().matches(match) | |
2143 | if len(matches) > 0: |
|
2143 | if len(matches) > 0: | |
2144 | if len(matches) == 1 and matches.keys()[0] == path: |
|
2144 | if len(matches) == 1 and matches.keys()[0] == path: | |
2145 | return |
|
2145 | return | |
2146 | raise error.Abort("error: file '%s' cannot be written because " |
|
2146 | raise error.Abort("error: file '%s' cannot be written because " | |
2147 | " '%s/' is a folder in %s (containing %d " |
|
2147 | " '%s/' is a folder in %s (containing %d " | |
2148 | "entries: %s)" |
|
2148 | "entries: %s)" | |
2149 | % (path, path, self.p1(), len(matches), |
|
2149 | % (path, path, self.p1(), len(matches), | |
2150 | ', '.join(matches.keys()))) |
|
2150 | ', '.join(matches.keys()))) | |
2151 |
|
2151 | |||
2152 | def write(self, path, data, flags=''): |
|
2152 | def write(self, path, data, flags=''): | |
2153 | if data is None: |
|
2153 | if data is None: | |
2154 | raise error.ProgrammingError("data must be non-None") |
|
2154 | raise error.ProgrammingError("data must be non-None") | |
2155 | self._auditconflicts(path) |
|
2155 | self._auditconflicts(path) | |
2156 | self._markdirty(path, exists=True, data=data, date=util.makedate(), |
|
2156 | self._markdirty(path, exists=True, data=data, date=util.makedate(), | |
2157 | flags=flags) |
|
2157 | flags=flags) | |
2158 |
|
2158 | |||
2159 | def setflags(self, path, l, x): |
|
2159 | def setflags(self, path, l, x): | |
2160 | self._markdirty(path, exists=True, date=util.makedate(), |
|
2160 | self._markdirty(path, exists=True, date=util.makedate(), | |
2161 | flags=(l and 'l' or '') + (x and 'x' or '')) |
|
2161 | flags=(l and 'l' or '') + (x and 'x' or '')) | |
2162 |
|
2162 | |||
2163 | def remove(self, path): |
|
2163 | def remove(self, path): | |
2164 | self._markdirty(path, exists=False) |
|
2164 | self._markdirty(path, exists=False) | |
2165 |
|
2165 | |||
2166 | def exists(self, path): |
|
2166 | def exists(self, path): | |
2167 | """exists behaves like `lexists`, but needs to follow symlinks and |
|
2167 | """exists behaves like `lexists`, but needs to follow symlinks and | |
2168 | return False if they are broken. |
|
2168 | return False if they are broken. | |
2169 | """ |
|
2169 | """ | |
2170 | if self.isdirty(path): |
|
2170 | if self.isdirty(path): | |
2171 | # If this path exists and is a symlink, "follow" it by calling |
|
2171 | # If this path exists and is a symlink, "follow" it by calling | |
2172 | # exists on the destination path. |
|
2172 | # exists on the destination path. | |
2173 | if (self._cache[path]['exists'] and |
|
2173 | if (self._cache[path]['exists'] and | |
2174 | 'l' in self._cache[path]['flags']): |
|
2174 | 'l' in self._cache[path]['flags']): | |
2175 | return self.exists(self._cache[path]['data'].strip()) |
|
2175 | return self.exists(self._cache[path]['data'].strip()) | |
2176 | else: |
|
2176 | else: | |
2177 | return self._cache[path]['exists'] |
|
2177 | return self._cache[path]['exists'] | |
2178 |
|
2178 | |||
2179 | return self._existsinparent(path) |
|
2179 | return self._existsinparent(path) | |
2180 |
|
2180 | |||
2181 | def lexists(self, path): |
|
2181 | def lexists(self, path): | |
2182 | """lexists returns True if the path exists""" |
|
2182 | """lexists returns True if the path exists""" | |
2183 | if self.isdirty(path): |
|
2183 | if self.isdirty(path): | |
2184 | return self._cache[path]['exists'] |
|
2184 | return self._cache[path]['exists'] | |
2185 |
|
2185 | |||
2186 | return self._existsinparent(path) |
|
2186 | return self._existsinparent(path) | |
2187 |
|
2187 | |||
2188 | def size(self, path): |
|
2188 | def size(self, path): | |
2189 | if self.isdirty(path): |
|
2189 | if self.isdirty(path): | |
2190 | if self._cache[path]['exists']: |
|
2190 | if self._cache[path]['exists']: | |
2191 | return len(self._cache[path]['data']) |
|
2191 | return len(self._cache[path]['data']) | |
2192 | else: |
|
2192 | else: | |
2193 | raise error.ProgrammingError("No such file or directory: %s" % |
|
2193 | raise error.ProgrammingError("No such file or directory: %s" % | |
2194 | self._path) |
|
2194 | self._path) | |
2195 | return self._wrappedctx[path].size() |
|
2195 | return self._wrappedctx[path].size() | |
2196 |
|
2196 | |||
2197 | def tomemctx(self, text, branch=None, extra=None, date=None, parents=None, |
|
2197 | def tomemctx(self, text, branch=None, extra=None, date=None, parents=None, | |
2198 | user=None, editor=None): |
|
2198 | user=None, editor=None): | |
2199 | """Converts this ``overlayworkingctx`` into a ``memctx`` ready to be |
|
2199 | """Converts this ``overlayworkingctx`` into a ``memctx`` ready to be | |
2200 | committed. |
|
2200 | committed. | |
2201 |
|
2201 | |||
2202 | ``text`` is the commit message. |
|
2202 | ``text`` is the commit message. | |
2203 | ``parents`` (optional) are rev numbers. |
|
2203 | ``parents`` (optional) are rev numbers. | |
2204 | """ |
|
2204 | """ | |
2205 | # Default parents to the wrapped contexts' if not passed. |
|
2205 | # Default parents to the wrapped contexts' if not passed. | |
2206 | if parents is None: |
|
2206 | if parents is None: | |
2207 | parents = self._wrappedctx.parents() |
|
2207 | parents = self._wrappedctx.parents() | |
2208 | if len(parents) == 1: |
|
2208 | if len(parents) == 1: | |
2209 | parents = (parents[0], None) |
|
2209 | parents = (parents[0], None) | |
2210 |
|
2210 | |||
2211 | # ``parents`` is passed as rev numbers; convert to ``commitctxs``. |
|
2211 | # ``parents`` is passed as rev numbers; convert to ``commitctxs``. | |
2212 | if parents[1] is None: |
|
2212 | if parents[1] is None: | |
2213 | parents = (self._repo[parents[0]], None) |
|
2213 | parents = (self._repo[parents[0]], None) | |
2214 | else: |
|
2214 | else: | |
2215 | parents = (self._repo[parents[0]], self._repo[parents[1]]) |
|
2215 | parents = (self._repo[parents[0]], self._repo[parents[1]]) | |
2216 |
|
2216 | |||
2217 | files = self._cache.keys() |
|
2217 | files = self._cache.keys() | |
2218 | def getfile(repo, memctx, path): |
|
2218 | def getfile(repo, memctx, path): | |
2219 | if self._cache[path]['exists']: |
|
2219 | if self._cache[path]['exists']: | |
2220 | return memfilectx(repo, memctx, path, |
|
2220 | return memfilectx(repo, memctx, path, | |
2221 | self._cache[path]['data'], |
|
2221 | self._cache[path]['data'], | |
2222 | 'l' in self._cache[path]['flags'], |
|
2222 | 'l' in self._cache[path]['flags'], | |
2223 | 'x' in self._cache[path]['flags'], |
|
2223 | 'x' in self._cache[path]['flags'], | |
2224 | self._cache[path]['copied']) |
|
2224 | self._cache[path]['copied']) | |
2225 | else: |
|
2225 | else: | |
2226 | # Returning None, but including the path in `files`, is |
|
2226 | # Returning None, but including the path in `files`, is | |
2227 | # necessary for memctx to register a deletion. |
|
2227 | # necessary for memctx to register a deletion. | |
2228 | return None |
|
2228 | return None | |
2229 | return memctx(self._repo, parents, text, files, getfile, date=date, |
|
2229 | return memctx(self._repo, parents, text, files, getfile, date=date, | |
2230 | extra=extra, user=user, branch=branch, editor=editor) |
|
2230 | extra=extra, user=user, branch=branch, editor=editor) | |
2231 |
|
2231 | |||
2232 | def isdirty(self, path): |
|
2232 | def isdirty(self, path): | |
2233 | return path in self._cache |
|
2233 | return path in self._cache | |
2234 |
|
2234 | |||
2235 | def isempty(self): |
|
2235 | def isempty(self): | |
2236 | # We need to discard any keys that are actually clean before the empty |
|
2236 | # We need to discard any keys that are actually clean before the empty | |
2237 | # commit check. |
|
2237 | # commit check. | |
2238 | self._compact() |
|
2238 | self._compact() | |
2239 | return len(self._cache) == 0 |
|
2239 | return len(self._cache) == 0 | |
2240 |
|
2240 | |||
2241 | def clean(self): |
|
2241 | def clean(self): | |
2242 | self._cache = {} |
|
2242 | self._cache = {} | |
2243 |
|
2243 | |||
2244 | def _compact(self): |
|
2244 | def _compact(self): | |
2245 | """Removes keys from the cache that are actually clean, by comparing |
|
2245 | """Removes keys from the cache that are actually clean, by comparing | |
2246 | them with the underlying context. |
|
2246 | them with the underlying context. | |
2247 |
|
2247 | |||
2248 | This can occur during the merge process, e.g. by passing --tool :local |
|
2248 | This can occur during the merge process, e.g. by passing --tool :local | |
2249 | to resolve a conflict. |
|
2249 | to resolve a conflict. | |
2250 | """ |
|
2250 | """ | |
2251 | keys = [] |
|
2251 | keys = [] | |
2252 | for path in self._cache.keys(): |
|
2252 | for path in self._cache.keys(): | |
2253 | cache = self._cache[path] |
|
2253 | cache = self._cache[path] | |
2254 | try: |
|
2254 | try: | |
2255 | underlying = self._wrappedctx[path] |
|
2255 | underlying = self._wrappedctx[path] | |
2256 | if (underlying.data() == cache['data'] and |
|
2256 | if (underlying.data() == cache['data'] and | |
2257 | underlying.flags() == cache['flags']): |
|
2257 | underlying.flags() == cache['flags']): | |
2258 | keys.append(path) |
|
2258 | keys.append(path) | |
2259 | except error.ManifestLookupError: |
|
2259 | except error.ManifestLookupError: | |
2260 | # Path not in the underlying manifest (created). |
|
2260 | # Path not in the underlying manifest (created). | |
2261 | continue |
|
2261 | continue | |
2262 |
|
2262 | |||
2263 | for path in keys: |
|
2263 | for path in keys: | |
2264 | del self._cache[path] |
|
2264 | del self._cache[path] | |
2265 | return keys |
|
2265 | return keys | |
2266 |
|
2266 | |||
2267 | def _markdirty(self, path, exists, data=None, date=None, flags=''): |
|
2267 | def _markdirty(self, path, exists, data=None, date=None, flags=''): | |
2268 | self._cache[path] = { |
|
2268 | self._cache[path] = { | |
2269 | 'exists': exists, |
|
2269 | 'exists': exists, | |
2270 | 'data': data, |
|
2270 | 'data': data, | |
2271 | 'date': date, |
|
2271 | 'date': date, | |
2272 | 'flags': flags, |
|
2272 | 'flags': flags, | |
2273 | 'copied': None, |
|
2273 | 'copied': None, | |
2274 | } |
|
2274 | } | |
2275 |
|
2275 | |||
2276 | def filectx(self, path, filelog=None): |
|
2276 | def filectx(self, path, filelog=None): | |
2277 | return overlayworkingfilectx(self._repo, path, parent=self, |
|
2277 | return overlayworkingfilectx(self._repo, path, parent=self, | |
2278 | filelog=filelog) |
|
2278 | filelog=filelog) | |
2279 |
|
2279 | |||
2280 | class overlayworkingfilectx(committablefilectx): |
|
2280 | class overlayworkingfilectx(committablefilectx): | |
2281 | """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory |
|
2281 | """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory | |
2282 | cache, which can be flushed through later by calling ``flush()``.""" |
|
2282 | cache, which can be flushed through later by calling ``flush()``.""" | |
2283 |
|
2283 | |||
2284 | def __init__(self, repo, path, filelog=None, parent=None): |
|
2284 | def __init__(self, repo, path, filelog=None, parent=None): | |
2285 | super(overlayworkingfilectx, self).__init__(repo, path, filelog, |
|
2285 | super(overlayworkingfilectx, self).__init__(repo, path, filelog, | |
2286 | parent) |
|
2286 | parent) | |
2287 | self._repo = repo |
|
2287 | self._repo = repo | |
2288 | self._parent = parent |
|
2288 | self._parent = parent | |
2289 | self._path = path |
|
2289 | self._path = path | |
2290 |
|
2290 | |||
2291 | def cmp(self, fctx): |
|
2291 | def cmp(self, fctx): | |
2292 | return self.data() != fctx.data() |
|
2292 | return self.data() != fctx.data() | |
2293 |
|
2293 | |||
2294 | def changectx(self): |
|
2294 | def changectx(self): | |
2295 | return self._parent |
|
2295 | return self._parent | |
2296 |
|
2296 | |||
2297 | def data(self): |
|
2297 | def data(self): | |
2298 | return self._parent.data(self._path) |
|
2298 | return self._parent.data(self._path) | |
2299 |
|
2299 | |||
2300 | def date(self): |
|
2300 | def date(self): | |
2301 | return self._parent.filedate(self._path) |
|
2301 | return self._parent.filedate(self._path) | |
2302 |
|
2302 | |||
2303 | def exists(self): |
|
2303 | def exists(self): | |
2304 | return self.lexists() |
|
2304 | return self.lexists() | |
2305 |
|
2305 | |||
2306 | def lexists(self): |
|
2306 | def lexists(self): | |
2307 | return self._parent.exists(self._path) |
|
2307 | return self._parent.exists(self._path) | |
2308 |
|
2308 | |||
2309 | def renamed(self): |
|
2309 | def renamed(self): | |
2310 | path = self._parent.copydata(self._path) |
|
2310 | path = self._parent.copydata(self._path) | |
2311 | if not path: |
|
2311 | if not path: | |
2312 | return None |
|
2312 | return None | |
2313 | return path, self._changectx._parents[0]._manifest.get(path, nullid) |
|
2313 | return path, self._changectx._parents[0]._manifest.get(path, nullid) | |
2314 |
|
2314 | |||
2315 | def size(self): |
|
2315 | def size(self): | |
2316 | return self._parent.size(self._path) |
|
2316 | return self._parent.size(self._path) | |
2317 |
|
2317 | |||
2318 | def markcopied(self, origin): |
|
2318 | def markcopied(self, origin): | |
2319 | self._parent.markcopied(self._path, origin) |
|
2319 | self._parent.markcopied(self._path, origin) | |
2320 |
|
2320 | |||
2321 | def audit(self): |
|
2321 | def audit(self): | |
2322 | pass |
|
2322 | pass | |
2323 |
|
2323 | |||
2324 | def flags(self): |
|
2324 | def flags(self): | |
2325 | return self._parent.flags(self._path) |
|
2325 | return self._parent.flags(self._path) | |
2326 |
|
2326 | |||
2327 | def setflags(self, islink, isexec): |
|
2327 | def setflags(self, islink, isexec): | |
2328 | return self._parent.setflags(self._path, islink, isexec) |
|
2328 | return self._parent.setflags(self._path, islink, isexec) | |
2329 |
|
2329 | |||
2330 | def write(self, data, flags, backgroundclose=False): |
|
2330 | def write(self, data, flags, backgroundclose=False): | |
2331 | return self._parent.write(self._path, data, flags) |
|
2331 | return self._parent.write(self._path, data, flags) | |
2332 |
|
2332 | |||
2333 | def remove(self, ignoremissing=False): |
|
2333 | def remove(self, ignoremissing=False): | |
2334 | return self._parent.remove(self._path) |
|
2334 | return self._parent.remove(self._path) | |
2335 |
|
2335 | |||
2336 | def clearunknown(self): |
|
2336 | def clearunknown(self): | |
2337 | pass |
|
2337 | pass | |
2338 |
|
2338 | |||
2339 | class workingcommitctx(workingctx): |
|
2339 | class workingcommitctx(workingctx): | |
2340 | """A workingcommitctx object makes access to data related to |
|
2340 | """A workingcommitctx object makes access to data related to | |
2341 | the revision being committed convenient. |
|
2341 | the revision being committed convenient. | |
2342 |
|
2342 | |||
2343 | This hides changes in the working directory, if they aren't |
|
2343 | This hides changes in the working directory, if they aren't | |
2344 | committed in this context. |
|
2344 | committed in this context. | |
2345 | """ |
|
2345 | """ | |
2346 | def __init__(self, repo, changes, |
|
2346 | def __init__(self, repo, changes, | |
2347 | text="", user=None, date=None, extra=None): |
|
2347 | text="", user=None, date=None, extra=None): | |
2348 | super(workingctx, self).__init__(repo, text, user, date, extra, |
|
2348 | super(workingctx, self).__init__(repo, text, user, date, extra, | |
2349 | changes) |
|
2349 | changes) | |
2350 |
|
2350 | |||
2351 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
2351 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): | |
2352 | """Return matched files only in ``self._status`` |
|
2352 | """Return matched files only in ``self._status`` | |
2353 |
|
2353 | |||
2354 | Uncommitted files appear "clean" via this context, even if |
|
2354 | Uncommitted files appear "clean" via this context, even if | |
2355 | they aren't actually so in the working directory. |
|
2355 | they aren't actually so in the working directory. | |
2356 | """ |
|
2356 | """ | |
2357 | if clean: |
|
2357 | if clean: | |
2358 | clean = [f for f in self._manifest if f not in self._changedset] |
|
2358 | clean = [f for f in self._manifest if f not in self._changedset] | |
2359 | else: |
|
2359 | else: | |
2360 | clean = [] |
|
2360 | clean = [] | |
2361 | return scmutil.status([f for f in self._status.modified if match(f)], |
|
2361 | return scmutil.status([f for f in self._status.modified if match(f)], | |
2362 | [f for f in self._status.added if match(f)], |
|
2362 | [f for f in self._status.added if match(f)], | |
2363 | [f for f in self._status.removed if match(f)], |
|
2363 | [f for f in self._status.removed if match(f)], | |
2364 | [], [], [], clean) |
|
2364 | [], [], [], clean) | |
2365 |
|
2365 | |||
2366 | @propertycache |
|
2366 | @propertycache | |
2367 | def _changedset(self): |
|
2367 | def _changedset(self): | |
2368 | """Return the set of files changed in this context |
|
2368 | """Return the set of files changed in this context | |
2369 | """ |
|
2369 | """ | |
2370 | changed = set(self._status.modified) |
|
2370 | changed = set(self._status.modified) | |
2371 | changed.update(self._status.added) |
|
2371 | changed.update(self._status.added) | |
2372 | changed.update(self._status.removed) |
|
2372 | changed.update(self._status.removed) | |
2373 | return changed |
|
2373 | return changed | |
2374 |
|
2374 | |||
2375 | def makecachingfilectxfn(func): |
|
2375 | def makecachingfilectxfn(func): | |
2376 | """Create a filectxfn that caches based on the path. |
|
2376 | """Create a filectxfn that caches based on the path. | |
2377 |
|
2377 | |||
2378 | We can't use util.cachefunc because it uses all arguments as the cache |
|
2378 | We can't use util.cachefunc because it uses all arguments as the cache | |
2379 | key and this creates a cycle since the arguments include the repo and |
|
2379 | key and this creates a cycle since the arguments include the repo and | |
2380 | memctx. |
|
2380 | memctx. | |
2381 | """ |
|
2381 | """ | |
2382 | cache = {} |
|
2382 | cache = {} | |
2383 |
|
2383 | |||
2384 | def getfilectx(repo, memctx, path): |
|
2384 | def getfilectx(repo, memctx, path): | |
2385 | if path not in cache: |
|
2385 | if path not in cache: | |
2386 | cache[path] = func(repo, memctx, path) |
|
2386 | cache[path] = func(repo, memctx, path) | |
2387 | return cache[path] |
|
2387 | return cache[path] | |
2388 |
|
2388 | |||
2389 | return getfilectx |
|
2389 | return getfilectx | |
2390 |
|
2390 | |||
2391 | def memfilefromctx(ctx): |
|
2391 | def memfilefromctx(ctx): | |
2392 | """Given a context return a memfilectx for ctx[path] |
|
2392 | """Given a context return a memfilectx for ctx[path] | |
2393 |
|
2393 | |||
2394 | This is a convenience method for building a memctx based on another |
|
2394 | This is a convenience method for building a memctx based on another | |
2395 | context. |
|
2395 | context. | |
2396 | """ |
|
2396 | """ | |
2397 | def getfilectx(repo, memctx, path): |
|
2397 | def getfilectx(repo, memctx, path): | |
2398 | fctx = ctx[path] |
|
2398 | fctx = ctx[path] | |
2399 | # this is weird but apparently we only keep track of one parent |
|
2399 | # this is weird but apparently we only keep track of one parent | |
2400 | # (why not only store that instead of a tuple?) |
|
2400 | # (why not only store that instead of a tuple?) | |
2401 | copied = fctx.renamed() |
|
2401 | copied = fctx.renamed() | |
2402 | if copied: |
|
2402 | if copied: | |
2403 | copied = copied[0] |
|
2403 | copied = copied[0] | |
2404 | return memfilectx(repo, memctx, path, fctx.data(), |
|
2404 | return memfilectx(repo, memctx, path, fctx.data(), | |
2405 | islink=fctx.islink(), isexec=fctx.isexec(), |
|
2405 | islink=fctx.islink(), isexec=fctx.isexec(), | |
2406 | copied=copied) |
|
2406 | copied=copied) | |
2407 |
|
2407 | |||
2408 | return getfilectx |
|
2408 | return getfilectx | |
2409 |
|
2409 | |||
2410 | def memfilefrompatch(patchstore): |
|
2410 | def memfilefrompatch(patchstore): | |
2411 | """Given a patch (e.g. patchstore object) return a memfilectx |
|
2411 | """Given a patch (e.g. patchstore object) return a memfilectx | |
2412 |
|
2412 | |||
2413 | This is a convenience method for building a memctx based on a patchstore. |
|
2413 | This is a convenience method for building a memctx based on a patchstore. | |
2414 | """ |
|
2414 | """ | |
2415 | def getfilectx(repo, memctx, path): |
|
2415 | def getfilectx(repo, memctx, path): | |
2416 | data, mode, copied = patchstore.getfile(path) |
|
2416 | data, mode, copied = patchstore.getfile(path) | |
2417 | if data is None: |
|
2417 | if data is None: | |
2418 | return None |
|
2418 | return None | |
2419 | islink, isexec = mode |
|
2419 | islink, isexec = mode | |
2420 | return memfilectx(repo, memctx, path, data, islink=islink, |
|
2420 | return memfilectx(repo, memctx, path, data, islink=islink, | |
2421 | isexec=isexec, copied=copied) |
|
2421 | isexec=isexec, copied=copied) | |
2422 |
|
2422 | |||
2423 | return getfilectx |
|
2423 | return getfilectx | |
2424 |
|
2424 | |||
2425 | class memctx(committablectx): |
|
2425 | class memctx(committablectx): | |
2426 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
2426 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
2427 |
|
2427 | |||
2428 | Revision information is supplied at initialization time while |
|
2428 | Revision information is supplied at initialization time while | |
2429 | related files data and is made available through a callback |
|
2429 | related files data and is made available through a callback | |
2430 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
2430 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
2431 | sequence of two parent revisions identifiers (pass None for every |
|
2431 | sequence of two parent revisions identifiers (pass None for every | |
2432 | missing parent), 'text' is the commit message and 'files' lists |
|
2432 | missing parent), 'text' is the commit message and 'files' lists | |
2433 | names of files touched by the revision (normalized and relative to |
|
2433 | names of files touched by the revision (normalized and relative to | |
2434 | repository root). |
|
2434 | repository root). | |
2435 |
|
2435 | |||
2436 | filectxfn(repo, memctx, path) is a callable receiving the |
|
2436 | filectxfn(repo, memctx, path) is a callable receiving the | |
2437 | repository, the current memctx object and the normalized path of |
|
2437 | repository, the current memctx object and the normalized path of | |
2438 | requested file, relative to repository root. It is fired by the |
|
2438 | requested file, relative to repository root. It is fired by the | |
2439 | commit function for every file in 'files', but calls order is |
|
2439 | commit function for every file in 'files', but calls order is | |
2440 | undefined. If the file is available in the revision being |
|
2440 | undefined. If the file is available in the revision being | |
2441 | committed (updated or added), filectxfn returns a memfilectx |
|
2441 | committed (updated or added), filectxfn returns a memfilectx | |
2442 | object. If the file was removed, filectxfn return None for recent |
|
2442 | object. If the file was removed, filectxfn return None for recent | |
2443 | Mercurial. Moved files are represented by marking the source file |
|
2443 | Mercurial. Moved files are represented by marking the source file | |
2444 | removed and the new file added with copy information (see |
|
2444 | removed and the new file added with copy information (see | |
2445 | memfilectx). |
|
2445 | memfilectx). | |
2446 |
|
2446 | |||
2447 | user receives the committer name and defaults to current |
|
2447 | user receives the committer name and defaults to current | |
2448 | repository username, date is the commit date in any format |
|
2448 | repository username, date is the commit date in any format | |
2449 | supported by util.parsedate() and defaults to current date, extra |
|
2449 | supported by util.parsedate() and defaults to current date, extra | |
2450 | is a dictionary of metadata or is left empty. |
|
2450 | is a dictionary of metadata or is left empty. | |
2451 | """ |
|
2451 | """ | |
2452 |
|
2452 | |||
2453 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. |
|
2453 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. | |
2454 | # Extensions that need to retain compatibility across Mercurial 3.1 can use |
|
2454 | # Extensions that need to retain compatibility across Mercurial 3.1 can use | |
2455 | # this field to determine what to do in filectxfn. |
|
2455 | # this field to determine what to do in filectxfn. | |
2456 | _returnnoneformissingfiles = True |
|
2456 | _returnnoneformissingfiles = True | |
2457 |
|
2457 | |||
2458 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
2458 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
2459 | date=None, extra=None, branch=None, editor=False): |
|
2459 | date=None, extra=None, branch=None, editor=False): | |
2460 | super(memctx, self).__init__(repo, text, user, date, extra) |
|
2460 | super(memctx, self).__init__(repo, text, user, date, extra) | |
2461 | self._rev = None |
|
2461 | self._rev = None | |
2462 | self._node = None |
|
2462 | self._node = None | |
2463 | parents = [(p or nullid) for p in parents] |
|
2463 | parents = [(p or nullid) for p in parents] | |
2464 | p1, p2 = parents |
|
2464 | p1, p2 = parents | |
2465 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
2465 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
2466 | files = sorted(set(files)) |
|
2466 | files = sorted(set(files)) | |
2467 | self._files = files |
|
2467 | self._files = files | |
2468 | if branch is not None: |
|
2468 | if branch is not None: | |
2469 | self._extra['branch'] = encoding.fromlocal(branch) |
|
2469 | self._extra['branch'] = encoding.fromlocal(branch) | |
2470 | self.substate = {} |
|
2470 | self.substate = {} | |
2471 |
|
2471 | |||
2472 | if isinstance(filectxfn, patch.filestore): |
|
2472 | if isinstance(filectxfn, patch.filestore): | |
2473 | filectxfn = memfilefrompatch(filectxfn) |
|
2473 | filectxfn = memfilefrompatch(filectxfn) | |
2474 | elif not callable(filectxfn): |
|
2474 | elif not callable(filectxfn): | |
2475 | # if store is not callable, wrap it in a function |
|
2475 | # if store is not callable, wrap it in a function | |
2476 | filectxfn = memfilefromctx(filectxfn) |
|
2476 | filectxfn = memfilefromctx(filectxfn) | |
2477 |
|
2477 | |||
2478 | # memoizing increases performance for e.g. vcs convert scenarios. |
|
2478 | # memoizing increases performance for e.g. vcs convert scenarios. | |
2479 | self._filectxfn = makecachingfilectxfn(filectxfn) |
|
2479 | self._filectxfn = makecachingfilectxfn(filectxfn) | |
2480 |
|
2480 | |||
2481 | if editor: |
|
2481 | if editor: | |
2482 | self._text = editor(self._repo, self, []) |
|
2482 | self._text = editor(self._repo, self, []) | |
2483 | self._repo.savecommitmessage(self._text) |
|
2483 | self._repo.savecommitmessage(self._text) | |
2484 |
|
2484 | |||
2485 | def filectx(self, path, filelog=None): |
|
2485 | def filectx(self, path, filelog=None): | |
2486 | """get a file context from the working directory |
|
2486 | """get a file context from the working directory | |
2487 |
|
2487 | |||
2488 | Returns None if file doesn't exist and should be removed.""" |
|
2488 | Returns None if file doesn't exist and should be removed.""" | |
2489 | return self._filectxfn(self._repo, self, path) |
|
2489 | return self._filectxfn(self._repo, self, path) | |
2490 |
|
2490 | |||
2491 | def commit(self): |
|
2491 | def commit(self): | |
2492 | """commit context to the repo""" |
|
2492 | """commit context to the repo""" | |
2493 | return self._repo.commitctx(self) |
|
2493 | return self._repo.commitctx(self) | |
2494 |
|
2494 | |||
2495 | @propertycache |
|
2495 | @propertycache | |
2496 | def _manifest(self): |
|
2496 | def _manifest(self): | |
2497 | """generate a manifest based on the return values of filectxfn""" |
|
2497 | """generate a manifest based on the return values of filectxfn""" | |
2498 |
|
2498 | |||
2499 | # keep this simple for now; just worry about p1 |
|
2499 | # keep this simple for now; just worry about p1 | |
2500 | pctx = self._parents[0] |
|
2500 | pctx = self._parents[0] | |
2501 | man = pctx.manifest().copy() |
|
2501 | man = pctx.manifest().copy() | |
2502 |
|
2502 | |||
2503 | for f in self._status.modified: |
|
2503 | for f in self._status.modified: | |
2504 | p1node = nullid |
|
2504 | p1node = nullid | |
2505 | p2node = nullid |
|
2505 | p2node = nullid | |
2506 | p = pctx[f].parents() # if file isn't in pctx, check p2? |
|
2506 | p = pctx[f].parents() # if file isn't in pctx, check p2? | |
2507 | if len(p) > 0: |
|
2507 | if len(p) > 0: | |
2508 | p1node = p[0].filenode() |
|
2508 | p1node = p[0].filenode() | |
2509 | if len(p) > 1: |
|
2509 | if len(p) > 1: | |
2510 | p2node = p[1].filenode() |
|
2510 | p2node = p[1].filenode() | |
2511 | man[f] = revlog.hash(self[f].data(), p1node, p2node) |
|
2511 | man[f] = revlog.hash(self[f].data(), p1node, p2node) | |
2512 |
|
2512 | |||
2513 | for f in self._status.added: |
|
2513 | for f in self._status.added: | |
2514 | man[f] = revlog.hash(self[f].data(), nullid, nullid) |
|
2514 | man[f] = revlog.hash(self[f].data(), nullid, nullid) | |
2515 |
|
2515 | |||
2516 | for f in self._status.removed: |
|
2516 | for f in self._status.removed: | |
2517 | if f in man: |
|
2517 | if f in man: | |
2518 | del man[f] |
|
2518 | del man[f] | |
2519 |
|
2519 | |||
2520 | return man |
|
2520 | return man | |
2521 |
|
2521 | |||
2522 | @propertycache |
|
2522 | @propertycache | |
2523 | def _status(self): |
|
2523 | def _status(self): | |
2524 | """Calculate exact status from ``files`` specified at construction |
|
2524 | """Calculate exact status from ``files`` specified at construction | |
2525 | """ |
|
2525 | """ | |
2526 | man1 = self.p1().manifest() |
|
2526 | man1 = self.p1().manifest() | |
2527 | p2 = self._parents[1] |
|
2527 | p2 = self._parents[1] | |
2528 | # "1 < len(self._parents)" can't be used for checking |
|
2528 | # "1 < len(self._parents)" can't be used for checking | |
2529 | # existence of the 2nd parent, because "memctx._parents" is |
|
2529 | # existence of the 2nd parent, because "memctx._parents" is | |
2530 | # explicitly initialized by the list, of which length is 2. |
|
2530 | # explicitly initialized by the list, of which length is 2. | |
2531 | if p2.node() != nullid: |
|
2531 | if p2.node() != nullid: | |
2532 | man2 = p2.manifest() |
|
2532 | man2 = p2.manifest() | |
2533 | managing = lambda f: f in man1 or f in man2 |
|
2533 | managing = lambda f: f in man1 or f in man2 | |
2534 | else: |
|
2534 | else: | |
2535 | managing = lambda f: f in man1 |
|
2535 | managing = lambda f: f in man1 | |
2536 |
|
2536 | |||
2537 | modified, added, removed = [], [], [] |
|
2537 | modified, added, removed = [], [], [] | |
2538 | for f in self._files: |
|
2538 | for f in self._files: | |
2539 | if not managing(f): |
|
2539 | if not managing(f): | |
2540 | added.append(f) |
|
2540 | added.append(f) | |
2541 | elif self[f]: |
|
2541 | elif self[f]: | |
2542 | modified.append(f) |
|
2542 | modified.append(f) | |
2543 | else: |
|
2543 | else: | |
2544 | removed.append(f) |
|
2544 | removed.append(f) | |
2545 |
|
2545 | |||
2546 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2546 | return scmutil.status(modified, added, removed, [], [], [], []) | |
2547 |
|
2547 | |||
2548 | class memfilectx(committablefilectx): |
|
2548 | class memfilectx(committablefilectx): | |
2549 | """memfilectx represents an in-memory file to commit. |
|
2549 | """memfilectx represents an in-memory file to commit. | |
2550 |
|
2550 | |||
2551 | See memctx and committablefilectx for more details. |
|
2551 | See memctx and committablefilectx for more details. | |
2552 | """ |
|
2552 | """ | |
2553 | def __init__(self, repo, changectx, path, data, islink=False, |
|
2553 | def __init__(self, repo, changectx, path, data, islink=False, | |
2554 | isexec=False, copied=None): |
|
2554 | isexec=False, copied=None): | |
2555 | """ |
|
2555 | """ | |
2556 | path is the normalized file path relative to repository root. |
|
2556 | path is the normalized file path relative to repository root. | |
2557 | data is the file content as a string. |
|
2557 | data is the file content as a string. | |
2558 | islink is True if the file is a symbolic link. |
|
2558 | islink is True if the file is a symbolic link. | |
2559 | isexec is True if the file is executable. |
|
2559 | isexec is True if the file is executable. | |
2560 | copied is the source file path if current file was copied in the |
|
2560 | copied is the source file path if current file was copied in the | |
2561 | revision being committed, or None.""" |
|
2561 | revision being committed, or None.""" | |
2562 | super(memfilectx, self).__init__(repo, path, None, changectx) |
|
2562 | super(memfilectx, self).__init__(repo, path, None, changectx) | |
2563 | self._data = data |
|
2563 | self._data = data | |
2564 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
2564 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
2565 | self._copied = None |
|
2565 | self._copied = None | |
2566 | if copied: |
|
2566 | if copied: | |
2567 | self._copied = (copied, nullid) |
|
2567 | self._copied = (copied, nullid) | |
2568 |
|
2568 | |||
2569 | def data(self): |
|
2569 | def data(self): | |
2570 | return self._data |
|
2570 | return self._data | |
2571 |
|
2571 | |||
2572 | def remove(self, ignoremissing=False): |
|
2572 | def remove(self, ignoremissing=False): | |
2573 | """wraps unlink for a repo's working directory""" |
|
2573 | """wraps unlink for a repo's working directory""" | |
2574 | # need to figure out what to do here |
|
2574 | # need to figure out what to do here | |
2575 | del self._changectx[self._path] |
|
2575 | del self._changectx[self._path] | |
2576 |
|
2576 | |||
2577 | def write(self, data, flags): |
|
2577 | def write(self, data, flags): | |
2578 | """wraps repo.wwrite""" |
|
2578 | """wraps repo.wwrite""" | |
2579 | self._data = data |
|
2579 | self._data = data | |
2580 |
|
2580 | |||
2581 | class overlayfilectx(committablefilectx): |
|
2581 | class overlayfilectx(committablefilectx): | |
2582 | """Like memfilectx but take an original filectx and optional parameters to |
|
2582 | """Like memfilectx but take an original filectx and optional parameters to | |
2583 | override parts of it. This is useful when fctx.data() is expensive (i.e. |
|
2583 | override parts of it. This is useful when fctx.data() is expensive (i.e. | |
2584 | flag processor is expensive) and raw data, flags, and filenode could be |
|
2584 | flag processor is expensive) and raw data, flags, and filenode could be | |
2585 | reused (ex. rebase or mode-only amend a REVIDX_EXTSTORED file). |
|
2585 | reused (ex. rebase or mode-only amend a REVIDX_EXTSTORED file). | |
2586 | """ |
|
2586 | """ | |
2587 |
|
2587 | |||
2588 | def __init__(self, originalfctx, datafunc=None, path=None, flags=None, |
|
2588 | def __init__(self, originalfctx, datafunc=None, path=None, flags=None, | |
2589 | copied=None, ctx=None): |
|
2589 | copied=None, ctx=None): | |
2590 | """originalfctx: filecontext to duplicate |
|
2590 | """originalfctx: filecontext to duplicate | |
2591 |
|
2591 | |||
2592 | datafunc: None or a function to override data (file content). It is a |
|
2592 | datafunc: None or a function to override data (file content). It is a | |
2593 | function to be lazy. path, flags, copied, ctx: None or overridden value |
|
2593 | function to be lazy. path, flags, copied, ctx: None or overridden value | |
2594 |
|
2594 | |||
2595 | copied could be (path, rev), or False. copied could also be just path, |
|
2595 | copied could be (path, rev), or False. copied could also be just path, | |
2596 | and will be converted to (path, nullid). This simplifies some callers. |
|
2596 | and will be converted to (path, nullid). This simplifies some callers. | |
2597 | """ |
|
2597 | """ | |
2598 |
|
2598 | |||
2599 | if path is None: |
|
2599 | if path is None: | |
2600 | path = originalfctx.path() |
|
2600 | path = originalfctx.path() | |
2601 | if ctx is None: |
|
2601 | if ctx is None: | |
2602 | ctx = originalfctx.changectx() |
|
2602 | ctx = originalfctx.changectx() | |
2603 | ctxmatch = lambda: True |
|
2603 | ctxmatch = lambda: True | |
2604 | else: |
|
2604 | else: | |
2605 | ctxmatch = lambda: ctx == originalfctx.changectx() |
|
2605 | ctxmatch = lambda: ctx == originalfctx.changectx() | |
2606 |
|
2606 | |||
2607 | repo = originalfctx.repo() |
|
2607 | repo = originalfctx.repo() | |
2608 | flog = originalfctx.filelog() |
|
2608 | flog = originalfctx.filelog() | |
2609 | super(overlayfilectx, self).__init__(repo, path, flog, ctx) |
|
2609 | super(overlayfilectx, self).__init__(repo, path, flog, ctx) | |
2610 |
|
2610 | |||
2611 | if copied is None: |
|
2611 | if copied is None: | |
2612 | copied = originalfctx.renamed() |
|
2612 | copied = originalfctx.renamed() | |
2613 | copiedmatch = lambda: True |
|
2613 | copiedmatch = lambda: True | |
2614 | else: |
|
2614 | else: | |
2615 | if copied and not isinstance(copied, tuple): |
|
2615 | if copied and not isinstance(copied, tuple): | |
2616 | # repo._filecommit will recalculate copyrev so nullid is okay |
|
2616 | # repo._filecommit will recalculate copyrev so nullid is okay | |
2617 | copied = (copied, nullid) |
|
2617 | copied = (copied, nullid) | |
2618 | copiedmatch = lambda: copied == originalfctx.renamed() |
|
2618 | copiedmatch = lambda: copied == originalfctx.renamed() | |
2619 |
|
2619 | |||
2620 | # When data, copied (could affect data), ctx (could affect filelog |
|
2620 | # When data, copied (could affect data), ctx (could affect filelog | |
2621 | # parents) are not overridden, rawdata, rawflags, and filenode may be |
|
2621 | # parents) are not overridden, rawdata, rawflags, and filenode may be | |
2622 | # reused (repo._filecommit should double check filelog parents). |
|
2622 | # reused (repo._filecommit should double check filelog parents). | |
2623 | # |
|
2623 | # | |
2624 | # path, flags are not hashed in filelog (but in manifestlog) so they do |
|
2624 | # path, flags are not hashed in filelog (but in manifestlog) so they do | |
2625 | # not affect reusable here. |
|
2625 | # not affect reusable here. | |
2626 | # |
|
2626 | # | |
2627 | # If ctx or copied is overridden to a same value with originalfctx, |
|
2627 | # If ctx or copied is overridden to a same value with originalfctx, | |
2628 | # still consider it's reusable. originalfctx.renamed() may be a bit |
|
2628 | # still consider it's reusable. originalfctx.renamed() may be a bit | |
2629 | # expensive so it's not called unless necessary. Assuming datafunc is |
|
2629 | # expensive so it's not called unless necessary. Assuming datafunc is | |
2630 | # always expensive, do not call it for this "reusable" test. |
|
2630 | # always expensive, do not call it for this "reusable" test. | |
2631 | reusable = datafunc is None and ctxmatch() and copiedmatch() |
|
2631 | reusable = datafunc is None and ctxmatch() and copiedmatch() | |
2632 |
|
2632 | |||
2633 | if datafunc is None: |
|
2633 | if datafunc is None: | |
2634 | datafunc = originalfctx.data |
|
2634 | datafunc = originalfctx.data | |
2635 | if flags is None: |
|
2635 | if flags is None: | |
2636 | flags = originalfctx.flags() |
|
2636 | flags = originalfctx.flags() | |
2637 |
|
2637 | |||
2638 | self._datafunc = datafunc |
|
2638 | self._datafunc = datafunc | |
2639 | self._flags = flags |
|
2639 | self._flags = flags | |
2640 | self._copied = copied |
|
2640 | self._copied = copied | |
2641 |
|
2641 | |||
2642 | if reusable: |
|
2642 | if reusable: | |
2643 | # copy extra fields from originalfctx |
|
2643 | # copy extra fields from originalfctx | |
2644 | attrs = ['rawdata', 'rawflags', '_filenode', '_filerev'] |
|
2644 | attrs = ['rawdata', 'rawflags', '_filenode', '_filerev'] | |
2645 | for attr_ in attrs: |
|
2645 | for attr_ in attrs: | |
2646 | if util.safehasattr(originalfctx, attr_): |
|
2646 | if util.safehasattr(originalfctx, attr_): | |
2647 | setattr(self, attr_, getattr(originalfctx, attr_)) |
|
2647 | setattr(self, attr_, getattr(originalfctx, attr_)) | |
2648 |
|
2648 | |||
2649 | def data(self): |
|
2649 | def data(self): | |
2650 | return self._datafunc() |
|
2650 | return self._datafunc() | |
2651 |
|
2651 | |||
2652 | class metadataonlyctx(committablectx): |
|
2652 | class metadataonlyctx(committablectx): | |
2653 | """Like memctx but it's reusing the manifest of different commit. |
|
2653 | """Like memctx but it's reusing the manifest of different commit. | |
2654 | Intended to be used by lightweight operations that are creating |
|
2654 | Intended to be used by lightweight operations that are creating | |
2655 | metadata-only changes. |
|
2655 | metadata-only changes. | |
2656 |
|
2656 | |||
2657 | Revision information is supplied at initialization time. 'repo' is the |
|
2657 | Revision information is supplied at initialization time. 'repo' is the | |
2658 | current localrepo, 'ctx' is original revision which manifest we're reuisng |
|
2658 | current localrepo, 'ctx' is original revision which manifest we're reuisng | |
2659 | 'parents' is a sequence of two parent revisions identifiers (pass None for |
|
2659 | 'parents' is a sequence of two parent revisions identifiers (pass None for | |
2660 | every missing parent), 'text' is the commit. |
|
2660 | every missing parent), 'text' is the commit. | |
2661 |
|
2661 | |||
2662 | user receives the committer name and defaults to current repository |
|
2662 | user receives the committer name and defaults to current repository | |
2663 | username, date is the commit date in any format supported by |
|
2663 | username, date is the commit date in any format supported by | |
2664 | util.parsedate() and defaults to current date, extra is a dictionary of |
|
2664 | util.parsedate() and defaults to current date, extra is a dictionary of | |
2665 | metadata or is left empty. |
|
2665 | metadata or is left empty. | |
2666 | """ |
|
2666 | """ | |
2667 | def __new__(cls, repo, originalctx, *args, **kwargs): |
|
2667 | def __new__(cls, repo, originalctx, *args, **kwargs): | |
2668 | return super(metadataonlyctx, cls).__new__(cls, repo) |
|
2668 | return super(metadataonlyctx, cls).__new__(cls, repo) | |
2669 |
|
2669 | |||
2670 | def __init__(self, repo, originalctx, parents=None, text=None, user=None, |
|
2670 | def __init__(self, repo, originalctx, parents=None, text=None, user=None, | |
2671 | date=None, extra=None, editor=False): |
|
2671 | date=None, extra=None, editor=False): | |
2672 | if text is None: |
|
2672 | if text is None: | |
2673 | text = originalctx.description() |
|
2673 | text = originalctx.description() | |
2674 | super(metadataonlyctx, self).__init__(repo, text, user, date, extra) |
|
2674 | super(metadataonlyctx, self).__init__(repo, text, user, date, extra) | |
2675 | self._rev = None |
|
2675 | self._rev = None | |
2676 | self._node = None |
|
2676 | self._node = None | |
2677 | self._originalctx = originalctx |
|
2677 | self._originalctx = originalctx | |
2678 | self._manifestnode = originalctx.manifestnode() |
|
2678 | self._manifestnode = originalctx.manifestnode() | |
2679 | if parents is None: |
|
2679 | if parents is None: | |
2680 | parents = originalctx.parents() |
|
2680 | parents = originalctx.parents() | |
2681 | else: |
|
2681 | else: | |
2682 | parents = [repo[p] for p in parents if p is not None] |
|
2682 | parents = [repo[p] for p in parents if p is not None] | |
2683 | parents = parents[:] |
|
2683 | parents = parents[:] | |
2684 | while len(parents) < 2: |
|
2684 | while len(parents) < 2: | |
2685 | parents.append(repo[nullid]) |
|
2685 | parents.append(repo[nullid]) | |
2686 | p1, p2 = self._parents = parents |
|
2686 | p1, p2 = self._parents = parents | |
2687 |
|
2687 | |||
2688 | # sanity check to ensure that the reused manifest parents are |
|
2688 | # sanity check to ensure that the reused manifest parents are | |
2689 | # manifests of our commit parents |
|
2689 | # manifests of our commit parents | |
2690 | mp1, mp2 = self.manifestctx().parents |
|
2690 | mp1, mp2 = self.manifestctx().parents | |
2691 | if p1 != nullid and p1.manifestnode() != mp1: |
|
2691 | if p1 != nullid and p1.manifestnode() != mp1: | |
2692 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2692 | raise RuntimeError('can\'t reuse the manifest: ' | |
2693 | 'its p1 doesn\'t match the new ctx p1') |
|
2693 | 'its p1 doesn\'t match the new ctx p1') | |
2694 | if p2 != nullid and p2.manifestnode() != mp2: |
|
2694 | if p2 != nullid and p2.manifestnode() != mp2: | |
2695 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2695 | raise RuntimeError('can\'t reuse the manifest: ' | |
2696 | 'its p2 doesn\'t match the new ctx p2') |
|
2696 | 'its p2 doesn\'t match the new ctx p2') | |
2697 |
|
2697 | |||
2698 | self._files = originalctx.files() |
|
2698 | self._files = originalctx.files() | |
2699 | self.substate = {} |
|
2699 | self.substate = {} | |
2700 |
|
2700 | |||
2701 | if editor: |
|
2701 | if editor: | |
2702 | self._text = editor(self._repo, self, []) |
|
2702 | self._text = editor(self._repo, self, []) | |
2703 | self._repo.savecommitmessage(self._text) |
|
2703 | self._repo.savecommitmessage(self._text) | |
2704 |
|
2704 | |||
2705 | def manifestnode(self): |
|
2705 | def manifestnode(self): | |
2706 | return self._manifestnode |
|
2706 | return self._manifestnode | |
2707 |
|
2707 | |||
2708 | @property |
|
2708 | @property | |
2709 | def _manifestctx(self): |
|
2709 | def _manifestctx(self): | |
2710 | return self._repo.manifestlog[self._manifestnode] |
|
2710 | return self._repo.manifestlog[self._manifestnode] | |
2711 |
|
2711 | |||
2712 | def filectx(self, path, filelog=None): |
|
2712 | def filectx(self, path, filelog=None): | |
2713 | return self._originalctx.filectx(path, filelog=filelog) |
|
2713 | return self._originalctx.filectx(path, filelog=filelog) | |
2714 |
|
2714 | |||
2715 | def commit(self): |
|
2715 | def commit(self): | |
2716 | """commit context to the repo""" |
|
2716 | """commit context to the repo""" | |
2717 | return self._repo.commitctx(self) |
|
2717 | return self._repo.commitctx(self) | |
2718 |
|
2718 | |||
2719 | @property |
|
2719 | @property | |
2720 | def _manifest(self): |
|
2720 | def _manifest(self): | |
2721 | return self._originalctx.manifest() |
|
2721 | return self._originalctx.manifest() | |
2722 |
|
2722 | |||
2723 | @propertycache |
|
2723 | @propertycache | |
2724 | def _status(self): |
|
2724 | def _status(self): | |
2725 | """Calculate exact status from ``files`` specified in the ``origctx`` |
|
2725 | """Calculate exact status from ``files`` specified in the ``origctx`` | |
2726 | and parents manifests. |
|
2726 | and parents manifests. | |
2727 | """ |
|
2727 | """ | |
2728 | man1 = self.p1().manifest() |
|
2728 | man1 = self.p1().manifest() | |
2729 | p2 = self._parents[1] |
|
2729 | p2 = self._parents[1] | |
2730 | # "1 < len(self._parents)" can't be used for checking |
|
2730 | # "1 < len(self._parents)" can't be used for checking | |
2731 | # existence of the 2nd parent, because "metadataonlyctx._parents" is |
|
2731 | # existence of the 2nd parent, because "metadataonlyctx._parents" is | |
2732 | # explicitly initialized by the list, of which length is 2. |
|
2732 | # explicitly initialized by the list, of which length is 2. | |
2733 | if p2.node() != nullid: |
|
2733 | if p2.node() != nullid: | |
2734 | man2 = p2.manifest() |
|
2734 | man2 = p2.manifest() | |
2735 | managing = lambda f: f in man1 or f in man2 |
|
2735 | managing = lambda f: f in man1 or f in man2 | |
2736 | else: |
|
2736 | else: | |
2737 | managing = lambda f: f in man1 |
|
2737 | managing = lambda f: f in man1 | |
2738 |
|
2738 | |||
2739 | modified, added, removed = [], [], [] |
|
2739 | modified, added, removed = [], [], [] | |
2740 | for f in self._files: |
|
2740 | for f in self._files: | |
2741 | if not managing(f): |
|
2741 | if not managing(f): | |
2742 | added.append(f) |
|
2742 | added.append(f) | |
2743 | elif f in self: |
|
2743 | elif f in self: | |
2744 | modified.append(f) |
|
2744 | modified.append(f) | |
2745 | else: |
|
2745 | else: | |
2746 | removed.append(f) |
|
2746 | removed.append(f) | |
2747 |
|
2747 | |||
2748 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2748 | return scmutil.status(modified, added, removed, [], [], [], []) | |
2749 |
|
2749 | |||
2750 | class arbitraryfilectx(object): |
|
2750 | class arbitraryfilectx(object): | |
2751 | """Allows you to use filectx-like functions on a file in an arbitrary |
|
2751 | """Allows you to use filectx-like functions on a file in an arbitrary | |
2752 | location on disk, possibly not in the working directory. |
|
2752 | location on disk, possibly not in the working directory. | |
2753 | """ |
|
2753 | """ | |
2754 | def __init__(self, path, repo=None): |
|
2754 | def __init__(self, path, repo=None): | |
2755 | # Repo is optional because contrib/simplemerge uses this class. |
|
2755 | # Repo is optional because contrib/simplemerge uses this class. | |
2756 | self._repo = repo |
|
2756 | self._repo = repo | |
2757 | self._path = path |
|
2757 | self._path = path | |
2758 |
|
2758 | |||
2759 | def cmp(self, fctx): |
|
2759 | def cmp(self, fctx): | |
2760 | # filecmp follows symlinks whereas `cmp` should not, so skip the fast |
|
2760 | # filecmp follows symlinks whereas `cmp` should not, so skip the fast | |
2761 | # path if either side is a symlink. |
|
2761 | # path if either side is a symlink. | |
2762 | symlinks = ('l' in self.flags() or 'l' in fctx.flags()) |
|
2762 | symlinks = ('l' in self.flags() or 'l' in fctx.flags()) | |
2763 | if not symlinks and isinstance(fctx, workingfilectx) and self._repo: |
|
2763 | if not symlinks and isinstance(fctx, workingfilectx) and self._repo: | |
2764 | # Add a fast-path for merge if both sides are disk-backed. |
|
2764 | # Add a fast-path for merge if both sides are disk-backed. | |
2765 | # Note that filecmp uses the opposite return values (True if same) |
|
2765 | # Note that filecmp uses the opposite return values (True if same) | |
2766 | # from our cmp functions (True if different). |
|
2766 | # from our cmp functions (True if different). | |
2767 | return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path())) |
|
2767 | return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path())) | |
2768 | return self.data() != fctx.data() |
|
2768 | return self.data() != fctx.data() | |
2769 |
|
2769 | |||
2770 | def path(self): |
|
2770 | def path(self): | |
2771 | return self._path |
|
2771 | return self._path | |
2772 |
|
2772 | |||
2773 | def flags(self): |
|
2773 | def flags(self): | |
2774 | return '' |
|
2774 | return '' | |
2775 |
|
2775 | |||
2776 | def data(self): |
|
2776 | def data(self): | |
2777 | return util.readfile(self._path) |
|
2777 | return util.readfile(self._path) | |
2778 |
|
2778 | |||
2779 | def decodeddata(self): |
|
2779 | def decodeddata(self): | |
2780 | with open(self._path, "rb") as f: |
|
2780 | with open(self._path, "rb") as f: | |
2781 | return f.read() |
|
2781 | return f.read() | |
2782 |
|
2782 | |||
2783 | def remove(self): |
|
2783 | def remove(self): | |
2784 | util.unlink(self._path) |
|
2784 | util.unlink(self._path) | |
2785 |
|
2785 | |||
2786 | def write(self, data, flags): |
|
2786 | def write(self, data, flags): | |
2787 | assert not flags |
|
2787 | assert not flags | |
2788 | with open(self._path, "w") as f: |
|
2788 | with open(self._path, "w") as f: | |
2789 | f.write(data) |
|
2789 | f.write(data) |
@@ -1,906 +1,906 | |||||
1 | # obsutil.py - utility functions for obsolescence |
|
1 | # obsutil.py - utility functions for obsolescence | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Boris Feld <boris.feld@octobus.net> |
|
3 | # Copyright 2017 Boris Feld <boris.feld@octobus.net> | |
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 re |
|
10 | import re | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import ( |
|
13 | from . import ( | |
14 | node as nodemod, |
|
14 | node as nodemod, | |
15 | phases, |
|
15 | phases, | |
16 | util, |
|
16 | util, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
19 | class marker(object): |
|
19 | class marker(object): | |
20 | """Wrap obsolete marker raw data""" |
|
20 | """Wrap obsolete marker raw data""" | |
21 |
|
21 | |||
22 | def __init__(self, repo, data): |
|
22 | def __init__(self, repo, data): | |
23 | # the repo argument will be used to create changectx in later version |
|
23 | # the repo argument will be used to create changectx in later version | |
24 | self._repo = repo |
|
24 | self._repo = repo | |
25 | self._data = data |
|
25 | self._data = data | |
26 | self._decodedmeta = None |
|
26 | self._decodedmeta = None | |
27 |
|
27 | |||
28 | def __hash__(self): |
|
28 | def __hash__(self): | |
29 | return hash(self._data) |
|
29 | return hash(self._data) | |
30 |
|
30 | |||
31 | def __eq__(self, other): |
|
31 | def __eq__(self, other): | |
32 | if type(other) != type(self): |
|
32 | if type(other) != type(self): | |
33 | return False |
|
33 | return False | |
34 | return self._data == other._data |
|
34 | return self._data == other._data | |
35 |
|
35 | |||
36 | def precnode(self): |
|
36 | def precnode(self): | |
37 | msg = ("'marker.precnode' is deprecated, " |
|
37 | msg = ("'marker.precnode' is deprecated, " | |
38 | "use 'marker.prednode'") |
|
38 | "use 'marker.prednode'") | |
39 | util.nouideprecwarn(msg, '4.4') |
|
39 | util.nouideprecwarn(msg, '4.4') | |
40 | return self.prednode() |
|
40 | return self.prednode() | |
41 |
|
41 | |||
42 | def prednode(self): |
|
42 | def prednode(self): | |
43 | """Predecessor changeset node identifier""" |
|
43 | """Predecessor changeset node identifier""" | |
44 | return self._data[0] |
|
44 | return self._data[0] | |
45 |
|
45 | |||
46 | def succnodes(self): |
|
46 | def succnodes(self): | |
47 | """List of successor changesets node identifiers""" |
|
47 | """List of successor changesets node identifiers""" | |
48 | return self._data[1] |
|
48 | return self._data[1] | |
49 |
|
49 | |||
50 | def parentnodes(self): |
|
50 | def parentnodes(self): | |
51 | """Parents of the predecessors (None if not recorded)""" |
|
51 | """Parents of the predecessors (None if not recorded)""" | |
52 | return self._data[5] |
|
52 | return self._data[5] | |
53 |
|
53 | |||
54 | def metadata(self): |
|
54 | def metadata(self): | |
55 | """Decoded metadata dictionary""" |
|
55 | """Decoded metadata dictionary""" | |
56 | return dict(self._data[3]) |
|
56 | return dict(self._data[3]) | |
57 |
|
57 | |||
58 | def date(self): |
|
58 | def date(self): | |
59 | """Creation date as (unixtime, offset)""" |
|
59 | """Creation date as (unixtime, offset)""" | |
60 | return self._data[4] |
|
60 | return self._data[4] | |
61 |
|
61 | |||
62 | def flags(self): |
|
62 | def flags(self): | |
63 | """The flags field of the marker""" |
|
63 | """The flags field of the marker""" | |
64 | return self._data[2] |
|
64 | return self._data[2] | |
65 |
|
65 | |||
66 | def getmarkers(repo, nodes=None, exclusive=False): |
|
66 | def getmarkers(repo, nodes=None, exclusive=False): | |
67 | """returns markers known in a repository |
|
67 | """returns markers known in a repository | |
68 |
|
68 | |||
69 | If <nodes> is specified, only markers "relevant" to those nodes are are |
|
69 | If <nodes> is specified, only markers "relevant" to those nodes are are | |
70 | returned""" |
|
70 | returned""" | |
71 | if nodes is None: |
|
71 | if nodes is None: | |
72 | rawmarkers = repo.obsstore |
|
72 | rawmarkers = repo.obsstore | |
73 | elif exclusive: |
|
73 | elif exclusive: | |
74 | rawmarkers = exclusivemarkers(repo, nodes) |
|
74 | rawmarkers = exclusivemarkers(repo, nodes) | |
75 | else: |
|
75 | else: | |
76 | rawmarkers = repo.obsstore.relevantmarkers(nodes) |
|
76 | rawmarkers = repo.obsstore.relevantmarkers(nodes) | |
77 |
|
77 | |||
78 | for markerdata in rawmarkers: |
|
78 | for markerdata in rawmarkers: | |
79 | yield marker(repo, markerdata) |
|
79 | yield marker(repo, markerdata) | |
80 |
|
80 | |||
81 | def closestpredecessors(repo, nodeid): |
|
81 | def closestpredecessors(repo, nodeid): | |
82 | """yield the list of next predecessors pointing on visible changectx nodes |
|
82 | """yield the list of next predecessors pointing on visible changectx nodes | |
83 |
|
83 | |||
84 | This function respect the repoview filtering, filtered revision will be |
|
84 | This function respect the repoview filtering, filtered revision will be | |
85 | considered missing. |
|
85 | considered missing. | |
86 | """ |
|
86 | """ | |
87 |
|
87 | |||
88 | precursors = repo.obsstore.predecessors |
|
88 | precursors = repo.obsstore.predecessors | |
89 | stack = [nodeid] |
|
89 | stack = [nodeid] | |
90 | seen = set(stack) |
|
90 | seen = set(stack) | |
91 |
|
91 | |||
92 | while stack: |
|
92 | while stack: | |
93 | current = stack.pop() |
|
93 | current = stack.pop() | |
94 | currentpreccs = precursors.get(current, ()) |
|
94 | currentpreccs = precursors.get(current, ()) | |
95 |
|
95 | |||
96 | for prec in currentpreccs: |
|
96 | for prec in currentpreccs: | |
97 | precnodeid = prec[0] |
|
97 | precnodeid = prec[0] | |
98 |
|
98 | |||
99 | # Basic cycle protection |
|
99 | # Basic cycle protection | |
100 | if precnodeid in seen: |
|
100 | if precnodeid in seen: | |
101 | continue |
|
101 | continue | |
102 | seen.add(precnodeid) |
|
102 | seen.add(precnodeid) | |
103 |
|
103 | |||
104 | if precnodeid in repo: |
|
104 | if precnodeid in repo: | |
105 | yield precnodeid |
|
105 | yield precnodeid | |
106 | else: |
|
106 | else: | |
107 | stack.append(precnodeid) |
|
107 | stack.append(precnodeid) | |
108 |
|
108 | |||
109 | def allprecursors(*args, **kwargs): |
|
109 | def allprecursors(*args, **kwargs): | |
110 | """ (DEPRECATED) |
|
110 | """ (DEPRECATED) | |
111 | """ |
|
111 | """ | |
112 | msg = ("'obsutil.allprecursors' is deprecated, " |
|
112 | msg = ("'obsutil.allprecursors' is deprecated, " | |
113 | "use 'obsutil.allpredecessors'") |
|
113 | "use 'obsutil.allpredecessors'") | |
114 | util.nouideprecwarn(msg, '4.4') |
|
114 | util.nouideprecwarn(msg, '4.4') | |
115 |
|
115 | |||
116 | return allpredecessors(*args, **kwargs) |
|
116 | return allpredecessors(*args, **kwargs) | |
117 |
|
117 | |||
118 | def allpredecessors(obsstore, nodes, ignoreflags=0): |
|
118 | def allpredecessors(obsstore, nodes, ignoreflags=0): | |
119 | """Yield node for every precursors of <nodes>. |
|
119 | """Yield node for every precursors of <nodes>. | |
120 |
|
120 | |||
121 | Some precursors may be unknown locally. |
|
121 | Some precursors may be unknown locally. | |
122 |
|
122 | |||
123 | This is a linear yield unsuited to detecting folded changesets. It includes |
|
123 | This is a linear yield unsuited to detecting folded changesets. It includes | |
124 | initial nodes too.""" |
|
124 | initial nodes too.""" | |
125 |
|
125 | |||
126 | remaining = set(nodes) |
|
126 | remaining = set(nodes) | |
127 | seen = set(remaining) |
|
127 | seen = set(remaining) | |
128 | while remaining: |
|
128 | while remaining: | |
129 | current = remaining.pop() |
|
129 | current = remaining.pop() | |
130 | yield current |
|
130 | yield current | |
131 | for mark in obsstore.predecessors.get(current, ()): |
|
131 | for mark in obsstore.predecessors.get(current, ()): | |
132 | # ignore marker flagged with specified flag |
|
132 | # ignore marker flagged with specified flag | |
133 | if mark[2] & ignoreflags: |
|
133 | if mark[2] & ignoreflags: | |
134 | continue |
|
134 | continue | |
135 | suc = mark[0] |
|
135 | suc = mark[0] | |
136 | if suc not in seen: |
|
136 | if suc not in seen: | |
137 | seen.add(suc) |
|
137 | seen.add(suc) | |
138 | remaining.add(suc) |
|
138 | remaining.add(suc) | |
139 |
|
139 | |||
140 | def allsuccessors(obsstore, nodes, ignoreflags=0): |
|
140 | def allsuccessors(obsstore, nodes, ignoreflags=0): | |
141 | """Yield node for every successor of <nodes>. |
|
141 | """Yield node for every successor of <nodes>. | |
142 |
|
142 | |||
143 | Some successors may be unknown locally. |
|
143 | Some successors may be unknown locally. | |
144 |
|
144 | |||
145 | This is a linear yield unsuited to detecting split changesets. It includes |
|
145 | This is a linear yield unsuited to detecting split changesets. It includes | |
146 | initial nodes too.""" |
|
146 | initial nodes too.""" | |
147 | remaining = set(nodes) |
|
147 | remaining = set(nodes) | |
148 | seen = set(remaining) |
|
148 | seen = set(remaining) | |
149 | while remaining: |
|
149 | while remaining: | |
150 | current = remaining.pop() |
|
150 | current = remaining.pop() | |
151 | yield current |
|
151 | yield current | |
152 | for mark in obsstore.successors.get(current, ()): |
|
152 | for mark in obsstore.successors.get(current, ()): | |
153 | # ignore marker flagged with specified flag |
|
153 | # ignore marker flagged with specified flag | |
154 | if mark[2] & ignoreflags: |
|
154 | if mark[2] & ignoreflags: | |
155 | continue |
|
155 | continue | |
156 | for suc in mark[1]: |
|
156 | for suc in mark[1]: | |
157 | if suc not in seen: |
|
157 | if suc not in seen: | |
158 | seen.add(suc) |
|
158 | seen.add(suc) | |
159 | remaining.add(suc) |
|
159 | remaining.add(suc) | |
160 |
|
160 | |||
161 | def _filterprunes(markers): |
|
161 | def _filterprunes(markers): | |
162 | """return a set with no prune markers""" |
|
162 | """return a set with no prune markers""" | |
163 | return set(m for m in markers if m[1]) |
|
163 | return set(m for m in markers if m[1]) | |
164 |
|
164 | |||
165 | def exclusivemarkers(repo, nodes): |
|
165 | def exclusivemarkers(repo, nodes): | |
166 | """set of markers relevant to "nodes" but no other locally-known nodes |
|
166 | """set of markers relevant to "nodes" but no other locally-known nodes | |
167 |
|
167 | |||
168 | This function compute the set of markers "exclusive" to a locally-known |
|
168 | This function compute the set of markers "exclusive" to a locally-known | |
169 | node. This means we walk the markers starting from <nodes> until we reach a |
|
169 | node. This means we walk the markers starting from <nodes> until we reach a | |
170 | locally-known precursors outside of <nodes>. Element of <nodes> with |
|
170 | locally-known precursors outside of <nodes>. Element of <nodes> with | |
171 | locally-known successors outside of <nodes> are ignored (since their |
|
171 | locally-known successors outside of <nodes> are ignored (since their | |
172 | precursors markers are also relevant to these successors). |
|
172 | precursors markers are also relevant to these successors). | |
173 |
|
173 | |||
174 | For example: |
|
174 | For example: | |
175 |
|
175 | |||
176 | # (A0 rewritten as A1) |
|
176 | # (A0 rewritten as A1) | |
177 | # |
|
177 | # | |
178 | # A0 <-1- A1 # Marker "1" is exclusive to A1 |
|
178 | # A0 <-1- A1 # Marker "1" is exclusive to A1 | |
179 |
|
179 | |||
180 | or |
|
180 | or | |
181 |
|
181 | |||
182 | # (A0 rewritten as AX; AX rewritten as A1; AX is unkown locally) |
|
182 | # (A0 rewritten as AX; AX rewritten as A1; AX is unkown locally) | |
183 | # |
|
183 | # | |
184 | # <-1- A0 <-2- AX <-3- A1 # Marker "2,3" are exclusive to A1 |
|
184 | # <-1- A0 <-2- AX <-3- A1 # Marker "2,3" are exclusive to A1 | |
185 |
|
185 | |||
186 | or |
|
186 | or | |
187 |
|
187 | |||
188 | # (A0 has unknown precursors, A0 rewritten as A1 and A2 (divergence)) |
|
188 | # (A0 has unknown precursors, A0 rewritten as A1 and A2 (divergence)) | |
189 | # |
|
189 | # | |
190 | # <-2- A1 # Marker "2" is exclusive to A0,A1 |
|
190 | # <-2- A1 # Marker "2" is exclusive to A0,A1 | |
191 | # / |
|
191 | # / | |
192 | # <-1- A0 |
|
192 | # <-1- A0 | |
193 | # \ |
|
193 | # \ | |
194 | # <-3- A2 # Marker "3" is exclusive to A0,A2 |
|
194 | # <-3- A2 # Marker "3" is exclusive to A0,A2 | |
195 | # |
|
195 | # | |
196 | # in addition: |
|
196 | # in addition: | |
197 | # |
|
197 | # | |
198 | # Markers "2,3" are exclusive to A1,A2 |
|
198 | # Markers "2,3" are exclusive to A1,A2 | |
199 | # Markers "1,2,3" are exclusive to A0,A1,A2 |
|
199 | # Markers "1,2,3" are exclusive to A0,A1,A2 | |
200 |
|
200 | |||
201 | See test/test-obsolete-bundle-strip.t for more examples. |
|
201 | See test/test-obsolete-bundle-strip.t for more examples. | |
202 |
|
202 | |||
203 | An example usage is strip. When stripping a changeset, we also want to |
|
203 | An example usage is strip. When stripping a changeset, we also want to | |
204 | strip the markers exclusive to this changeset. Otherwise we would have |
|
204 | strip the markers exclusive to this changeset. Otherwise we would have | |
205 | "dangling"" obsolescence markers from its precursors: Obsolescence markers |
|
205 | "dangling"" obsolescence markers from its precursors: Obsolescence markers | |
206 | marking a node as obsolete without any successors available locally. |
|
206 | marking a node as obsolete without any successors available locally. | |
207 |
|
207 | |||
208 | As for relevant markers, the prune markers for children will be followed. |
|
208 | As for relevant markers, the prune markers for children will be followed. | |
209 | Of course, they will only be followed if the pruned children is |
|
209 | Of course, they will only be followed if the pruned children is | |
210 | locally-known. Since the prune markers are relevant to the pruned node. |
|
210 | locally-known. Since the prune markers are relevant to the pruned node. | |
211 | However, while prune markers are considered relevant to the parent of the |
|
211 | However, while prune markers are considered relevant to the parent of the | |
212 | pruned changesets, prune markers for locally-known changeset (with no |
|
212 | pruned changesets, prune markers for locally-known changeset (with no | |
213 | successors) are considered exclusive to the pruned nodes. This allows |
|
213 | successors) are considered exclusive to the pruned nodes. This allows | |
214 | to strip the prune markers (with the rest of the exclusive chain) alongside |
|
214 | to strip the prune markers (with the rest of the exclusive chain) alongside | |
215 | the pruned changesets. |
|
215 | the pruned changesets. | |
216 | """ |
|
216 | """ | |
217 | # running on a filtered repository would be dangerous as markers could be |
|
217 | # running on a filtered repository would be dangerous as markers could be | |
218 | # reported as exclusive when they are relevant for other filtered nodes. |
|
218 | # reported as exclusive when they are relevant for other filtered nodes. | |
219 | unfi = repo.unfiltered() |
|
219 | unfi = repo.unfiltered() | |
220 |
|
220 | |||
221 | # shortcut to various useful item |
|
221 | # shortcut to various useful item | |
222 | nm = unfi.changelog.nodemap |
|
222 | nm = unfi.changelog.nodemap | |
223 | precursorsmarkers = unfi.obsstore.predecessors |
|
223 | precursorsmarkers = unfi.obsstore.predecessors | |
224 | successormarkers = unfi.obsstore.successors |
|
224 | successormarkers = unfi.obsstore.successors | |
225 | childrenmarkers = unfi.obsstore.children |
|
225 | childrenmarkers = unfi.obsstore.children | |
226 |
|
226 | |||
227 | # exclusive markers (return of the function) |
|
227 | # exclusive markers (return of the function) | |
228 | exclmarkers = set() |
|
228 | exclmarkers = set() | |
229 | # we need fast membership testing |
|
229 | # we need fast membership testing | |
230 | nodes = set(nodes) |
|
230 | nodes = set(nodes) | |
231 | # looking for head in the obshistory |
|
231 | # looking for head in the obshistory | |
232 | # |
|
232 | # | |
233 | # XXX we are ignoring all issues in regard with cycle for now. |
|
233 | # XXX we are ignoring all issues in regard with cycle for now. | |
234 | stack = [n for n in nodes if not _filterprunes(successormarkers.get(n, ()))] |
|
234 | stack = [n for n in nodes if not _filterprunes(successormarkers.get(n, ()))] | |
235 | stack.sort() |
|
235 | stack.sort() | |
236 | # nodes already stacked |
|
236 | # nodes already stacked | |
237 | seennodes = set(stack) |
|
237 | seennodes = set(stack) | |
238 | while stack: |
|
238 | while stack: | |
239 | current = stack.pop() |
|
239 | current = stack.pop() | |
240 | # fetch precursors markers |
|
240 | # fetch precursors markers | |
241 | markers = list(precursorsmarkers.get(current, ())) |
|
241 | markers = list(precursorsmarkers.get(current, ())) | |
242 | # extend the list with prune markers |
|
242 | # extend the list with prune markers | |
243 | for mark in successormarkers.get(current, ()): |
|
243 | for mark in successormarkers.get(current, ()): | |
244 | if not mark[1]: |
|
244 | if not mark[1]: | |
245 | markers.append(mark) |
|
245 | markers.append(mark) | |
246 | # and markers from children (looking for prune) |
|
246 | # and markers from children (looking for prune) | |
247 | for mark in childrenmarkers.get(current, ()): |
|
247 | for mark in childrenmarkers.get(current, ()): | |
248 | if not mark[1]: |
|
248 | if not mark[1]: | |
249 | markers.append(mark) |
|
249 | markers.append(mark) | |
250 | # traverse the markers |
|
250 | # traverse the markers | |
251 | for mark in markers: |
|
251 | for mark in markers: | |
252 | if mark in exclmarkers: |
|
252 | if mark in exclmarkers: | |
253 | # markers already selected |
|
253 | # markers already selected | |
254 | continue |
|
254 | continue | |
255 |
|
255 | |||
256 | # If the markers is about the current node, select it |
|
256 | # If the markers is about the current node, select it | |
257 | # |
|
257 | # | |
258 | # (this delay the addition of markers from children) |
|
258 | # (this delay the addition of markers from children) | |
259 | if mark[1] or mark[0] == current: |
|
259 | if mark[1] or mark[0] == current: | |
260 | exclmarkers.add(mark) |
|
260 | exclmarkers.add(mark) | |
261 |
|
261 | |||
262 | # should we keep traversing through the precursors? |
|
262 | # should we keep traversing through the precursors? | |
263 | prec = mark[0] |
|
263 | prec = mark[0] | |
264 |
|
264 | |||
265 | # nodes in the stack or already processed |
|
265 | # nodes in the stack or already processed | |
266 | if prec in seennodes: |
|
266 | if prec in seennodes: | |
267 | continue |
|
267 | continue | |
268 |
|
268 | |||
269 | # is this a locally known node ? |
|
269 | # is this a locally known node ? | |
270 | known = prec in nm |
|
270 | known = prec in nm | |
271 | # if locally-known and not in the <nodes> set the traversal |
|
271 | # if locally-known and not in the <nodes> set the traversal | |
272 | # stop here. |
|
272 | # stop here. | |
273 | if known and prec not in nodes: |
|
273 | if known and prec not in nodes: | |
274 | continue |
|
274 | continue | |
275 |
|
275 | |||
276 | # do not keep going if there are unselected markers pointing to this |
|
276 | # do not keep going if there are unselected markers pointing to this | |
277 | # nodes. If we end up traversing these unselected markers later the |
|
277 | # nodes. If we end up traversing these unselected markers later the | |
278 | # node will be taken care of at that point. |
|
278 | # node will be taken care of at that point. | |
279 | precmarkers = _filterprunes(successormarkers.get(prec)) |
|
279 | precmarkers = _filterprunes(successormarkers.get(prec)) | |
280 | if precmarkers.issubset(exclmarkers): |
|
280 | if precmarkers.issubset(exclmarkers): | |
281 | seennodes.add(prec) |
|
281 | seennodes.add(prec) | |
282 | stack.append(prec) |
|
282 | stack.append(prec) | |
283 |
|
283 | |||
284 | return exclmarkers |
|
284 | return exclmarkers | |
285 |
|
285 | |||
286 | def foreground(repo, nodes): |
|
286 | def foreground(repo, nodes): | |
287 | """return all nodes in the "foreground" of other node |
|
287 | """return all nodes in the "foreground" of other node | |
288 |
|
288 | |||
289 | The foreground of a revision is anything reachable using parent -> children |
|
289 | The foreground of a revision is anything reachable using parent -> children | |
290 | or precursor -> successor relation. It is very similar to "descendant" but |
|
290 | or precursor -> successor relation. It is very similar to "descendant" but | |
291 | augmented with obsolescence information. |
|
291 | augmented with obsolescence information. | |
292 |
|
292 | |||
293 | Beware that possible obsolescence cycle may result if complex situation. |
|
293 | Beware that possible obsolescence cycle may result if complex situation. | |
294 | """ |
|
294 | """ | |
295 | repo = repo.unfiltered() |
|
295 | repo = repo.unfiltered() | |
296 | foreground = set(repo.set('%ln::', nodes)) |
|
296 | foreground = set(repo.set('%ln::', nodes)) | |
297 | if repo.obsstore: |
|
297 | if repo.obsstore: | |
298 | # We only need this complicated logic if there is obsolescence |
|
298 | # We only need this complicated logic if there is obsolescence | |
299 | # XXX will probably deserve an optimised revset. |
|
299 | # XXX will probably deserve an optimised revset. | |
300 | nm = repo.changelog.nodemap |
|
300 | nm = repo.changelog.nodemap | |
301 | plen = -1 |
|
301 | plen = -1 | |
302 | # compute the whole set of successors or descendants |
|
302 | # compute the whole set of successors or descendants | |
303 | while len(foreground) != plen: |
|
303 | while len(foreground) != plen: | |
304 | plen = len(foreground) |
|
304 | plen = len(foreground) | |
305 | succs = set(c.node() for c in foreground) |
|
305 | succs = set(c.node() for c in foreground) | |
306 | mutable = [c.node() for c in foreground if c.mutable()] |
|
306 | mutable = [c.node() for c in foreground if c.mutable()] | |
307 | succs.update(allsuccessors(repo.obsstore, mutable)) |
|
307 | succs.update(allsuccessors(repo.obsstore, mutable)) | |
308 | known = (n for n in succs if n in nm) |
|
308 | known = (n for n in succs if n in nm) | |
309 | foreground = set(repo.set('%ln::', known)) |
|
309 | foreground = set(repo.set('%ln::', known)) | |
310 | return set(c.node() for c in foreground) |
|
310 | return set(c.node() for c in foreground) | |
311 |
|
311 | |||
312 | # effectflag field |
|
312 | # effectflag field | |
313 | # |
|
313 | # | |
314 | # Effect-flag is a 1-byte bit field used to store what changed between a |
|
314 | # Effect-flag is a 1-byte bit field used to store what changed between a | |
315 | # changeset and its successor(s). |
|
315 | # changeset and its successor(s). | |
316 | # |
|
316 | # | |
317 | # The effect flag is stored in obs-markers metadata while we iterate on the |
|
317 | # The effect flag is stored in obs-markers metadata while we iterate on the | |
318 | # information design. That's why we have the EFFECTFLAGFIELD. If we come up |
|
318 | # information design. That's why we have the EFFECTFLAGFIELD. If we come up | |
319 | # with an incompatible design for effect flag, we can store a new design under |
|
319 | # with an incompatible design for effect flag, we can store a new design under | |
320 | # another field name so we don't break readers. We plan to extend the existing |
|
320 | # another field name so we don't break readers. We plan to extend the existing | |
321 | # obsmarkers bit-field when the effect flag design will be stabilized. |
|
321 | # obsmarkers bit-field when the effect flag design will be stabilized. | |
322 | # |
|
322 | # | |
323 | # The effect-flag is placed behind an experimental flag |
|
323 | # The effect-flag is placed behind an experimental flag | |
324 | # `effect-flags` set to off by default. |
|
324 | # `effect-flags` set to off by default. | |
325 | # |
|
325 | # | |
326 |
|
326 | |||
327 | EFFECTFLAGFIELD = "ef1" |
|
327 | EFFECTFLAGFIELD = "ef1" | |
328 |
|
328 | |||
329 | DESCCHANGED = 1 << 0 # action changed the description |
|
329 | DESCCHANGED = 1 << 0 # action changed the description | |
330 | METACHANGED = 1 << 1 # action change the meta |
|
330 | METACHANGED = 1 << 1 # action change the meta | |
331 | DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset |
|
331 | DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset | |
332 | PARENTCHANGED = 1 << 2 # action change the parent |
|
332 | PARENTCHANGED = 1 << 2 # action change the parent | |
333 | USERCHANGED = 1 << 4 # the user changed |
|
333 | USERCHANGED = 1 << 4 # the user changed | |
334 | DATECHANGED = 1 << 5 # the date changed |
|
334 | DATECHANGED = 1 << 5 # the date changed | |
335 | BRANCHCHANGED = 1 << 6 # the branch changed |
|
335 | BRANCHCHANGED = 1 << 6 # the branch changed | |
336 |
|
336 | |||
337 | METABLACKLIST = [ |
|
337 | METABLACKLIST = [ | |
338 | re.compile('^branch$'), |
|
338 | re.compile('^branch$'), | |
339 | re.compile('^.*-source$'), |
|
339 | re.compile('^.*-source$'), | |
340 | re.compile('^.*_source$'), |
|
340 | re.compile('^.*_source$'), | |
341 | re.compile('^source$'), |
|
341 | re.compile('^source$'), | |
342 | ] |
|
342 | ] | |
343 |
|
343 | |||
344 | def metanotblacklisted(metaitem): |
|
344 | def metanotblacklisted(metaitem): | |
345 | """ Check that the key of a meta item (extrakey, extravalue) does not |
|
345 | """ Check that the key of a meta item (extrakey, extravalue) does not | |
346 | match at least one of the blacklist pattern |
|
346 | match at least one of the blacklist pattern | |
347 | """ |
|
347 | """ | |
348 | metakey = metaitem[0] |
|
348 | metakey = metaitem[0] | |
349 |
|
349 | |||
350 | return not any(pattern.match(metakey) for pattern in METABLACKLIST) |
|
350 | return not any(pattern.match(metakey) for pattern in METABLACKLIST) | |
351 |
|
351 | |||
352 | def _prepare_hunk(hunk): |
|
352 | def _prepare_hunk(hunk): | |
353 | """Drop all information but the username and patch""" |
|
353 | """Drop all information but the username and patch""" | |
354 | cleanhunk = [] |
|
354 | cleanhunk = [] | |
355 | for line in hunk.splitlines(): |
|
355 | for line in hunk.splitlines(): | |
356 | if line.startswith(b'# User') or not line.startswith(b'#'): |
|
356 | if line.startswith(b'# User') or not line.startswith(b'#'): | |
357 | if line.startswith(b'@@'): |
|
357 | if line.startswith(b'@@'): | |
358 | line = b'@@\n' |
|
358 | line = b'@@\n' | |
359 | cleanhunk.append(line) |
|
359 | cleanhunk.append(line) | |
360 | return cleanhunk |
|
360 | return cleanhunk | |
361 |
|
361 | |||
362 | def _getdifflines(iterdiff): |
|
362 | def _getdifflines(iterdiff): | |
363 | """return a cleaned up lines""" |
|
363 | """return a cleaned up lines""" | |
364 | lines = next(iterdiff, None) |
|
364 | lines = next(iterdiff, None) | |
365 |
|
365 | |||
366 | if lines is None: |
|
366 | if lines is None: | |
367 | return lines |
|
367 | return lines | |
368 |
|
368 | |||
369 | return _prepare_hunk(lines) |
|
369 | return _prepare_hunk(lines) | |
370 |
|
370 | |||
371 | def _cmpdiff(leftctx, rightctx): |
|
371 | def _cmpdiff(leftctx, rightctx): | |
372 | """return True if both ctx introduce the "same diff" |
|
372 | """return True if both ctx introduce the "same diff" | |
373 |
|
373 | |||
374 | This is a first and basic implementation, with many shortcoming. |
|
374 | This is a first and basic implementation, with many shortcoming. | |
375 | """ |
|
375 | """ | |
376 |
|
376 | |||
377 | # Leftctx or right ctx might be filtered, so we need to use the contexts |
|
377 | # Leftctx or right ctx might be filtered, so we need to use the contexts | |
378 | # with an unfiltered repository to safely compute the diff |
|
378 | # with an unfiltered repository to safely compute the diff | |
379 | leftunfi = leftctx._repo.unfiltered()[leftctx.rev()] |
|
379 | leftunfi = leftctx._repo.unfiltered()[leftctx.rev()] | |
380 | leftdiff = leftunfi.diff(git=1) |
|
380 | leftdiff = leftunfi.diff(git=1) | |
381 | rightunfi = rightctx._repo.unfiltered()[rightctx.rev()] |
|
381 | rightunfi = rightctx._repo.unfiltered()[rightctx.rev()] | |
382 | rightdiff = rightunfi.diff(git=1) |
|
382 | rightdiff = rightunfi.diff(git=1) | |
383 |
|
383 | |||
384 | left, right = (0, 0) |
|
384 | left, right = (0, 0) | |
385 | while None not in (left, right): |
|
385 | while None not in (left, right): | |
386 | left = _getdifflines(leftdiff) |
|
386 | left = _getdifflines(leftdiff) | |
387 | right = _getdifflines(rightdiff) |
|
387 | right = _getdifflines(rightdiff) | |
388 |
|
388 | |||
389 | if left != right: |
|
389 | if left != right: | |
390 | return False |
|
390 | return False | |
391 | return True |
|
391 | return True | |
392 |
|
392 | |||
393 | def geteffectflag(relation): |
|
393 | def geteffectflag(relation): | |
394 | """ From an obs-marker relation, compute what changed between the |
|
394 | """ From an obs-marker relation, compute what changed between the | |
395 | predecessor and the successor. |
|
395 | predecessor and the successor. | |
396 | """ |
|
396 | """ | |
397 | effects = 0 |
|
397 | effects = 0 | |
398 |
|
398 | |||
399 | source = relation[0] |
|
399 | source = relation[0] | |
400 |
|
400 | |||
401 | for changectx in relation[1]: |
|
401 | for changectx in relation[1]: | |
402 | # Check if description has changed |
|
402 | # Check if description has changed | |
403 | if changectx.description() != source.description(): |
|
403 | if changectx.description() != source.description(): | |
404 | effects |= DESCCHANGED |
|
404 | effects |= DESCCHANGED | |
405 |
|
405 | |||
406 | # Check if user has changed |
|
406 | # Check if user has changed | |
407 | if changectx.user() != source.user(): |
|
407 | if changectx.user() != source.user(): | |
408 | effects |= USERCHANGED |
|
408 | effects |= USERCHANGED | |
409 |
|
409 | |||
410 | # Check if date has changed |
|
410 | # Check if date has changed | |
411 | if changectx.date() != source.date(): |
|
411 | if changectx.date() != source.date(): | |
412 | effects |= DATECHANGED |
|
412 | effects |= DATECHANGED | |
413 |
|
413 | |||
414 | # Check if branch has changed |
|
414 | # Check if branch has changed | |
415 | if changectx.branch() != source.branch(): |
|
415 | if changectx.branch() != source.branch(): | |
416 | effects |= BRANCHCHANGED |
|
416 | effects |= BRANCHCHANGED | |
417 |
|
417 | |||
418 | # Check if at least one of the parent has changed |
|
418 | # Check if at least one of the parent has changed | |
419 | if changectx.parents() != source.parents(): |
|
419 | if changectx.parents() != source.parents(): | |
420 | effects |= PARENTCHANGED |
|
420 | effects |= PARENTCHANGED | |
421 |
|
421 | |||
422 | # Check if other meta has changed |
|
422 | # Check if other meta has changed | |
423 | changeextra = changectx.extra().items() |
|
423 | changeextra = changectx.extra().items() | |
424 | ctxmeta = filter(metanotblacklisted, changeextra) |
|
424 | ctxmeta = filter(metanotblacklisted, changeextra) | |
425 |
|
425 | |||
426 | sourceextra = source.extra().items() |
|
426 | sourceextra = source.extra().items() | |
427 | srcmeta = filter(metanotblacklisted, sourceextra) |
|
427 | srcmeta = filter(metanotblacklisted, sourceextra) | |
428 |
|
428 | |||
429 | if ctxmeta != srcmeta: |
|
429 | if ctxmeta != srcmeta: | |
430 | effects |= METACHANGED |
|
430 | effects |= METACHANGED | |
431 |
|
431 | |||
432 | # Check if the diff has changed |
|
432 | # Check if the diff has changed | |
433 | if not _cmpdiff(source, changectx): |
|
433 | if not _cmpdiff(source, changectx): | |
434 | effects |= DIFFCHANGED |
|
434 | effects |= DIFFCHANGED | |
435 |
|
435 | |||
436 | return effects |
|
436 | return effects | |
437 |
|
437 | |||
438 | def getobsoleted(repo, tr): |
|
438 | def getobsoleted(repo, tr): | |
439 | """return the set of pre-existing revisions obsoleted by a transaction""" |
|
439 | """return the set of pre-existing revisions obsoleted by a transaction""" | |
440 | torev = repo.unfiltered().changelog.nodemap.get |
|
440 | torev = repo.unfiltered().changelog.nodemap.get | |
441 | phase = repo._phasecache.phase |
|
441 | phase = repo._phasecache.phase | |
442 | succsmarkers = repo.obsstore.successors.get |
|
442 | succsmarkers = repo.obsstore.successors.get | |
443 | public = phases.public |
|
443 | public = phases.public | |
444 | addedmarkers = tr.changes.get('obsmarkers') |
|
444 | addedmarkers = tr.changes.get('obsmarkers') | |
445 | addedrevs = tr.changes.get('revs') |
|
445 | addedrevs = tr.changes.get('revs') | |
446 | seenrevs = set() |
|
446 | seenrevs = set() | |
447 | obsoleted = set() |
|
447 | obsoleted = set() | |
448 | for mark in addedmarkers: |
|
448 | for mark in addedmarkers: | |
449 | node = mark[0] |
|
449 | node = mark[0] | |
450 | rev = torev(node) |
|
450 | rev = torev(node) | |
451 | if rev is None or rev in seenrevs or rev in addedrevs: |
|
451 | if rev is None or rev in seenrevs or rev in addedrevs: | |
452 | continue |
|
452 | continue | |
453 | seenrevs.add(rev) |
|
453 | seenrevs.add(rev) | |
454 | if phase(repo, rev) == public: |
|
454 | if phase(repo, rev) == public: | |
455 | continue |
|
455 | continue | |
456 | if set(succsmarkers(node) or []).issubset(addedmarkers): |
|
456 | if set(succsmarkers(node) or []).issubset(addedmarkers): | |
457 | obsoleted.add(rev) |
|
457 | obsoleted.add(rev) | |
458 | return obsoleted |
|
458 | return obsoleted | |
459 |
|
459 | |||
460 | class _succs(list): |
|
460 | class _succs(list): | |
461 | """small class to represent a successors with some metadata about it""" |
|
461 | """small class to represent a successors with some metadata about it""" | |
462 |
|
462 | |||
463 | def __init__(self, *args, **kwargs): |
|
463 | def __init__(self, *args, **kwargs): | |
464 | super(_succs, self).__init__(*args, **kwargs) |
|
464 | super(_succs, self).__init__(*args, **kwargs) | |
465 | self.markers = set() |
|
465 | self.markers = set() | |
466 |
|
466 | |||
467 | def copy(self): |
|
467 | def copy(self): | |
468 | new = _succs(self) |
|
468 | new = _succs(self) | |
469 | new.markers = self.markers.copy() |
|
469 | new.markers = self.markers.copy() | |
470 | return new |
|
470 | return new | |
471 |
|
471 | |||
472 | @util.propertycache |
|
472 | @util.propertycache | |
473 | def _set(self): |
|
473 | def _set(self): | |
474 | # immutable |
|
474 | # immutable | |
475 | return set(self) |
|
475 | return set(self) | |
476 |
|
476 | |||
477 | def canmerge(self, other): |
|
477 | def canmerge(self, other): | |
478 | return self._set.issubset(other._set) |
|
478 | return self._set.issubset(other._set) | |
479 |
|
479 | |||
480 | def successorssets(repo, initialnode, closest=False, cache=None): |
|
480 | def successorssets(repo, initialnode, closest=False, cache=None): | |
481 | """Return set of all latest successors of initial nodes |
|
481 | """Return set of all latest successors of initial nodes | |
482 |
|
482 | |||
483 | The successors set of a changeset A are the group of revisions that succeed |
|
483 | The successors set of a changeset A are the group of revisions that succeed | |
484 | A. It succeeds A as a consistent whole, each revision being only a partial |
|
484 | A. It succeeds A as a consistent whole, each revision being only a partial | |
485 | replacement. By default, the successors set contains non-obsolete |
|
485 | replacement. By default, the successors set contains non-obsolete | |
486 | changesets only, walking the obsolescence graph until reaching a leaf. If |
|
486 | changesets only, walking the obsolescence graph until reaching a leaf. If | |
487 | 'closest' is set to True, closest successors-sets are return (the |
|
487 | 'closest' is set to True, closest successors-sets are return (the | |
488 | obsolescence walk stops on known changesets). |
|
488 | obsolescence walk stops on known changesets). | |
489 |
|
489 | |||
490 | This function returns the full list of successor sets which is why it |
|
490 | This function returns the full list of successor sets which is why it | |
491 | returns a list of tuples and not just a single tuple. Each tuple is a valid |
|
491 | returns a list of tuples and not just a single tuple. Each tuple is a valid | |
492 | successors set. Note that (A,) may be a valid successors set for changeset A |
|
492 | successors set. Note that (A,) may be a valid successors set for changeset A | |
493 | (see below). |
|
493 | (see below). | |
494 |
|
494 | |||
495 | In most cases, a changeset A will have a single element (e.g. the changeset |
|
495 | In most cases, a changeset A will have a single element (e.g. the changeset | |
496 | A is replaced by A') in its successors set. Though, it is also common for a |
|
496 | A is replaced by A') in its successors set. Though, it is also common for a | |
497 | changeset A to have no elements in its successor set (e.g. the changeset |
|
497 | changeset A to have no elements in its successor set (e.g. the changeset | |
498 | has been pruned). Therefore, the returned list of successors sets will be |
|
498 | has been pruned). Therefore, the returned list of successors sets will be | |
499 | [(A',)] or [], respectively. |
|
499 | [(A',)] or [], respectively. | |
500 |
|
500 | |||
501 | When a changeset A is split into A' and B', however, it will result in a |
|
501 | When a changeset A is split into A' and B', however, it will result in a | |
502 | successors set containing more than a single element, i.e. [(A',B')]. |
|
502 | successors set containing more than a single element, i.e. [(A',B')]. | |
503 | Divergent changesets will result in multiple successors sets, i.e. [(A',), |
|
503 | Divergent changesets will result in multiple successors sets, i.e. [(A',), | |
504 | (A'')]. |
|
504 | (A'')]. | |
505 |
|
505 | |||
506 | If a changeset A is not obsolete, then it will conceptually have no |
|
506 | If a changeset A is not obsolete, then it will conceptually have no | |
507 | successors set. To distinguish this from a pruned changeset, the successor |
|
507 | successors set. To distinguish this from a pruned changeset, the successor | |
508 | set will contain itself only, i.e. [(A,)]. |
|
508 | set will contain itself only, i.e. [(A,)]. | |
509 |
|
509 | |||
510 | Finally, final successors unknown locally are considered to be pruned |
|
510 | Finally, final successors unknown locally are considered to be pruned | |
511 | (pruned: obsoleted without any successors). (Final: successors not affected |
|
511 | (pruned: obsoleted without any successors). (Final: successors not affected | |
512 | by markers). |
|
512 | by markers). | |
513 |
|
513 | |||
514 | The 'closest' mode respect the repoview filtering. For example, without |
|
514 | The 'closest' mode respect the repoview filtering. For example, without | |
515 | filter it will stop at the first locally known changeset, with 'visible' |
|
515 | filter it will stop at the first locally known changeset, with 'visible' | |
516 | filter it will stop on visible changesets). |
|
516 | filter it will stop on visible changesets). | |
517 |
|
517 | |||
518 | The optional `cache` parameter is a dictionary that may contains |
|
518 | The optional `cache` parameter is a dictionary that may contains | |
519 | precomputed successors sets. It is meant to reuse the computation of a |
|
519 | precomputed successors sets. It is meant to reuse the computation of a | |
520 | previous call to `successorssets` when multiple calls are made at the same |
|
520 | previous call to `successorssets` when multiple calls are made at the same | |
521 | time. The cache dictionary is updated in place. The caller is responsible |
|
521 | time. The cache dictionary is updated in place. The caller is responsible | |
522 | for its life span. Code that makes multiple calls to `successorssets` |
|
522 | for its life span. Code that makes multiple calls to `successorssets` | |
523 | *should* use this cache mechanism or risk a performance hit. |
|
523 | *should* use this cache mechanism or risk a performance hit. | |
524 |
|
524 | |||
525 | Since results are different depending of the 'closest' most, the same cache |
|
525 | Since results are different depending of the 'closest' most, the same cache | |
526 | cannot be reused for both mode. |
|
526 | cannot be reused for both mode. | |
527 | """ |
|
527 | """ | |
528 |
|
528 | |||
529 | succmarkers = repo.obsstore.successors |
|
529 | succmarkers = repo.obsstore.successors | |
530 |
|
530 | |||
531 | # Stack of nodes we search successors sets for |
|
531 | # Stack of nodes we search successors sets for | |
532 | toproceed = [initialnode] |
|
532 | toproceed = [initialnode] | |
533 | # set version of above list for fast loop detection |
|
533 | # set version of above list for fast loop detection | |
534 | # element added to "toproceed" must be added here |
|
534 | # element added to "toproceed" must be added here | |
535 | stackedset = set(toproceed) |
|
535 | stackedset = set(toproceed) | |
536 | if cache is None: |
|
536 | if cache is None: | |
537 | cache = {} |
|
537 | cache = {} | |
538 |
|
538 | |||
539 | # This while loop is the flattened version of a recursive search for |
|
539 | # This while loop is the flattened version of a recursive search for | |
540 | # successors sets |
|
540 | # successors sets | |
541 | # |
|
541 | # | |
542 | # def successorssets(x): |
|
542 | # def successorssets(x): | |
543 | # successors = directsuccessors(x) |
|
543 | # successors = directsuccessors(x) | |
544 | # ss = [[]] |
|
544 | # ss = [[]] | |
545 | # for succ in directsuccessors(x): |
|
545 | # for succ in directsuccessors(x): | |
546 | # # product as in itertools cartesian product |
|
546 | # # product as in itertools cartesian product | |
547 | # ss = product(ss, successorssets(succ)) |
|
547 | # ss = product(ss, successorssets(succ)) | |
548 | # return ss |
|
548 | # return ss | |
549 | # |
|
549 | # | |
550 | # But we can not use plain recursive calls here: |
|
550 | # But we can not use plain recursive calls here: | |
551 | # - that would blow the python call stack |
|
551 | # - that would blow the python call stack | |
552 | # - obsolescence markers may have cycles, we need to handle them. |
|
552 | # - obsolescence markers may have cycles, we need to handle them. | |
553 | # |
|
553 | # | |
554 | # The `toproceed` list act as our call stack. Every node we search |
|
554 | # The `toproceed` list act as our call stack. Every node we search | |
555 | # successors set for are stacked there. |
|
555 | # successors set for are stacked there. | |
556 | # |
|
556 | # | |
557 | # The `stackedset` is set version of this stack used to check if a node is |
|
557 | # The `stackedset` is set version of this stack used to check if a node is | |
558 | # already stacked. This check is used to detect cycles and prevent infinite |
|
558 | # already stacked. This check is used to detect cycles and prevent infinite | |
559 | # loop. |
|
559 | # loop. | |
560 | # |
|
560 | # | |
561 | # successors set of all nodes are stored in the `cache` dictionary. |
|
561 | # successors set of all nodes are stored in the `cache` dictionary. | |
562 | # |
|
562 | # | |
563 | # After this while loop ends we use the cache to return the successors sets |
|
563 | # After this while loop ends we use the cache to return the successors sets | |
564 | # for the node requested by the caller. |
|
564 | # for the node requested by the caller. | |
565 | while toproceed: |
|
565 | while toproceed: | |
566 | # Every iteration tries to compute the successors sets of the topmost |
|
566 | # Every iteration tries to compute the successors sets of the topmost | |
567 | # node of the stack: CURRENT. |
|
567 | # node of the stack: CURRENT. | |
568 | # |
|
568 | # | |
569 | # There are four possible outcomes: |
|
569 | # There are four possible outcomes: | |
570 | # |
|
570 | # | |
571 | # 1) We already know the successors sets of CURRENT: |
|
571 | # 1) We already know the successors sets of CURRENT: | |
572 | # -> mission accomplished, pop it from the stack. |
|
572 | # -> mission accomplished, pop it from the stack. | |
573 | # 2) Stop the walk: |
|
573 | # 2) Stop the walk: | |
574 | # default case: Node is not obsolete |
|
574 | # default case: Node is not obsolete | |
575 | # closest case: Node is known at this repo filter level |
|
575 | # closest case: Node is known at this repo filter level | |
576 | # -> the node is its own successors sets. Add it to the cache. |
|
576 | # -> the node is its own successors sets. Add it to the cache. | |
577 | # 3) We do not know successors set of direct successors of CURRENT: |
|
577 | # 3) We do not know successors set of direct successors of CURRENT: | |
578 | # -> We add those successors to the stack. |
|
578 | # -> We add those successors to the stack. | |
579 | # 4) We know successors sets of all direct successors of CURRENT: |
|
579 | # 4) We know successors sets of all direct successors of CURRENT: | |
580 | # -> We can compute CURRENT successors set and add it to the |
|
580 | # -> We can compute CURRENT successors set and add it to the | |
581 | # cache. |
|
581 | # cache. | |
582 | # |
|
582 | # | |
583 | current = toproceed[-1] |
|
583 | current = toproceed[-1] | |
584 |
|
584 | |||
585 | # case 2 condition is a bit hairy because of closest, |
|
585 | # case 2 condition is a bit hairy because of closest, | |
586 | # we compute it on its own |
|
586 | # we compute it on its own | |
587 | case2condition = ((current not in succmarkers) |
|
587 | case2condition = ((current not in succmarkers) | |
588 | or (closest and current != initialnode |
|
588 | or (closest and current != initialnode | |
589 | and current in repo)) |
|
589 | and current in repo)) | |
590 |
|
590 | |||
591 | if current in cache: |
|
591 | if current in cache: | |
592 | # case (1): We already know the successors sets |
|
592 | # case (1): We already know the successors sets | |
593 | stackedset.remove(toproceed.pop()) |
|
593 | stackedset.remove(toproceed.pop()) | |
594 | elif case2condition: |
|
594 | elif case2condition: | |
595 | # case (2): end of walk. |
|
595 | # case (2): end of walk. | |
596 | if current in repo: |
|
596 | if current in repo: | |
597 | # We have a valid successors. |
|
597 | # We have a valid successors. | |
598 | cache[current] = [_succs((current,))] |
|
598 | cache[current] = [_succs((current,))] | |
599 | else: |
|
599 | else: | |
600 | # Final obsolete version is unknown locally. |
|
600 | # Final obsolete version is unknown locally. | |
601 | # Do not count that as a valid successors |
|
601 | # Do not count that as a valid successors | |
602 | cache[current] = [] |
|
602 | cache[current] = [] | |
603 | else: |
|
603 | else: | |
604 | # cases (3) and (4) |
|
604 | # cases (3) and (4) | |
605 | # |
|
605 | # | |
606 | # We proceed in two phases. Phase 1 aims to distinguish case (3) |
|
606 | # We proceed in two phases. Phase 1 aims to distinguish case (3) | |
607 | # from case (4): |
|
607 | # from case (4): | |
608 | # |
|
608 | # | |
609 | # For each direct successors of CURRENT, we check whether its |
|
609 | # For each direct successors of CURRENT, we check whether its | |
610 | # successors sets are known. If they are not, we stack the |
|
610 | # successors sets are known. If they are not, we stack the | |
611 | # unknown node and proceed to the next iteration of the while |
|
611 | # unknown node and proceed to the next iteration of the while | |
612 | # loop. (case 3) |
|
612 | # loop. (case 3) | |
613 | # |
|
613 | # | |
614 | # During this step, we may detect obsolescence cycles: a node |
|
614 | # During this step, we may detect obsolescence cycles: a node | |
615 | # with unknown successors sets but already in the call stack. |
|
615 | # with unknown successors sets but already in the call stack. | |
616 | # In such a situation, we arbitrary set the successors sets of |
|
616 | # In such a situation, we arbitrary set the successors sets of | |
617 | # the node to nothing (node pruned) to break the cycle. |
|
617 | # the node to nothing (node pruned) to break the cycle. | |
618 | # |
|
618 | # | |
619 | # If no break was encountered we proceed to phase 2. |
|
619 | # If no break was encountered we proceed to phase 2. | |
620 | # |
|
620 | # | |
621 | # Phase 2 computes successors sets of CURRENT (case 4); see details |
|
621 | # Phase 2 computes successors sets of CURRENT (case 4); see details | |
622 | # in phase 2 itself. |
|
622 | # in phase 2 itself. | |
623 | # |
|
623 | # | |
624 | # Note the two levels of iteration in each phase. |
|
624 | # Note the two levels of iteration in each phase. | |
625 | # - The first one handles obsolescence markers using CURRENT as |
|
625 | # - The first one handles obsolescence markers using CURRENT as | |
626 | # precursor (successors markers of CURRENT). |
|
626 | # precursor (successors markers of CURRENT). | |
627 | # |
|
627 | # | |
628 | # Having multiple entry here means divergence. |
|
628 | # Having multiple entry here means divergence. | |
629 | # |
|
629 | # | |
630 | # - The second one handles successors defined in each marker. |
|
630 | # - The second one handles successors defined in each marker. | |
631 | # |
|
631 | # | |
632 | # Having none means pruned node, multiple successors means split, |
|
632 | # Having none means pruned node, multiple successors means split, | |
633 | # single successors are standard replacement. |
|
633 | # single successors are standard replacement. | |
634 | # |
|
634 | # | |
635 | for mark in sorted(succmarkers[current]): |
|
635 | for mark in sorted(succmarkers[current]): | |
636 | for suc in mark[1]: |
|
636 | for suc in mark[1]: | |
637 | if suc not in cache: |
|
637 | if suc not in cache: | |
638 | if suc in stackedset: |
|
638 | if suc in stackedset: | |
639 | # cycle breaking |
|
639 | # cycle breaking | |
640 | cache[suc] = [] |
|
640 | cache[suc] = [] | |
641 | else: |
|
641 | else: | |
642 | # case (3) If we have not computed successors sets |
|
642 | # case (3) If we have not computed successors sets | |
643 | # of one of those successors we add it to the |
|
643 | # of one of those successors we add it to the | |
644 | # `toproceed` stack and stop all work for this |
|
644 | # `toproceed` stack and stop all work for this | |
645 | # iteration. |
|
645 | # iteration. | |
646 | toproceed.append(suc) |
|
646 | toproceed.append(suc) | |
647 | stackedset.add(suc) |
|
647 | stackedset.add(suc) | |
648 | break |
|
648 | break | |
649 | else: |
|
649 | else: | |
650 | continue |
|
650 | continue | |
651 | break |
|
651 | break | |
652 | else: |
|
652 | else: | |
653 | # case (4): we know all successors sets of all direct |
|
653 | # case (4): we know all successors sets of all direct | |
654 | # successors |
|
654 | # successors | |
655 | # |
|
655 | # | |
656 | # Successors set contributed by each marker depends on the |
|
656 | # Successors set contributed by each marker depends on the | |
657 | # successors sets of all its "successors" node. |
|
657 | # successors sets of all its "successors" node. | |
658 | # |
|
658 | # | |
659 | # Each different marker is a divergence in the obsolescence |
|
659 | # Each different marker is a divergence in the obsolescence | |
660 | # history. It contributes successors sets distinct from other |
|
660 | # history. It contributes successors sets distinct from other | |
661 | # markers. |
|
661 | # markers. | |
662 | # |
|
662 | # | |
663 | # Within a marker, a successor may have divergent successors |
|
663 | # Within a marker, a successor may have divergent successors | |
664 | # sets. In such a case, the marker will contribute multiple |
|
664 | # sets. In such a case, the marker will contribute multiple | |
665 | # divergent successors sets. If multiple successors have |
|
665 | # divergent successors sets. If multiple successors have | |
666 | # divergent successors sets, a Cartesian product is used. |
|
666 | # divergent successors sets, a Cartesian product is used. | |
667 | # |
|
667 | # | |
668 | # At the end we post-process successors sets to remove |
|
668 | # At the end we post-process successors sets to remove | |
669 | # duplicated entry and successors set that are strict subset of |
|
669 | # duplicated entry and successors set that are strict subset of | |
670 | # another one. |
|
670 | # another one. | |
671 | succssets = [] |
|
671 | succssets = [] | |
672 | for mark in sorted(succmarkers[current]): |
|
672 | for mark in sorted(succmarkers[current]): | |
673 | # successors sets contributed by this marker |
|
673 | # successors sets contributed by this marker | |
674 | base = _succs() |
|
674 | base = _succs() | |
675 | base.markers.add(mark) |
|
675 | base.markers.add(mark) | |
676 | markss = [base] |
|
676 | markss = [base] | |
677 | for suc in mark[1]: |
|
677 | for suc in mark[1]: | |
678 | # cardinal product with previous successors |
|
678 | # cardinal product with previous successors | |
679 | productresult = [] |
|
679 | productresult = [] | |
680 | for prefix in markss: |
|
680 | for prefix in markss: | |
681 | for suffix in cache[suc]: |
|
681 | for suffix in cache[suc]: | |
682 | newss = prefix.copy() |
|
682 | newss = prefix.copy() | |
683 | newss.markers.update(suffix.markers) |
|
683 | newss.markers.update(suffix.markers) | |
684 | for part in suffix: |
|
684 | for part in suffix: | |
685 | # do not duplicated entry in successors set |
|
685 | # do not duplicated entry in successors set | |
686 | # first entry wins. |
|
686 | # first entry wins. | |
687 | if part not in newss: |
|
687 | if part not in newss: | |
688 | newss.append(part) |
|
688 | newss.append(part) | |
689 | productresult.append(newss) |
|
689 | productresult.append(newss) | |
690 | markss = productresult |
|
690 | markss = productresult | |
691 | succssets.extend(markss) |
|
691 | succssets.extend(markss) | |
692 | # remove duplicated and subset |
|
692 | # remove duplicated and subset | |
693 | seen = [] |
|
693 | seen = [] | |
694 | final = [] |
|
694 | final = [] | |
695 | candidates = sorted((s for s in succssets if s), |
|
695 | candidates = sorted((s for s in succssets if s), | |
696 | key=len, reverse=True) |
|
696 | key=len, reverse=True) | |
697 | for cand in candidates: |
|
697 | for cand in candidates: | |
698 | for seensuccs in seen: |
|
698 | for seensuccs in seen: | |
699 | if cand.canmerge(seensuccs): |
|
699 | if cand.canmerge(seensuccs): | |
700 | seensuccs.markers.update(cand.markers) |
|
700 | seensuccs.markers.update(cand.markers) | |
701 | break |
|
701 | break | |
702 | else: |
|
702 | else: | |
703 | final.append(cand) |
|
703 | final.append(cand) | |
704 | seen.append(cand) |
|
704 | seen.append(cand) | |
705 | final.reverse() # put small successors set first |
|
705 | final.reverse() # put small successors set first | |
706 | cache[current] = final |
|
706 | cache[current] = final | |
707 | return cache[initialnode] |
|
707 | return cache[initialnode] | |
708 |
|
708 | |||
709 | def successorsandmarkers(repo, ctx): |
|
709 | def successorsandmarkers(repo, ctx): | |
710 | """compute the raw data needed for computing obsfate |
|
710 | """compute the raw data needed for computing obsfate | |
711 | Returns a list of dict, one dict per successors set |
|
711 | Returns a list of dict, one dict per successors set | |
712 | """ |
|
712 | """ | |
713 | if not ctx.obsolete(): |
|
713 | if not ctx.obsolete(): | |
714 | return None |
|
714 | return None | |
715 |
|
715 | |||
716 | ssets = successorssets(repo, ctx.node(), closest=True) |
|
716 | ssets = successorssets(repo, ctx.node(), closest=True) | |
717 |
|
717 | |||
718 | # closestsuccessors returns an empty list for pruned revisions, remap it |
|
718 | # closestsuccessors returns an empty list for pruned revisions, remap it | |
719 | # into a list containing an empty list for future processing |
|
719 | # into a list containing an empty list for future processing | |
720 | if ssets == []: |
|
720 | if ssets == []: | |
721 | ssets = [[]] |
|
721 | ssets = [[]] | |
722 |
|
722 | |||
723 | # Try to recover pruned markers |
|
723 | # Try to recover pruned markers | |
724 | succsmap = repo.obsstore.successors |
|
724 | succsmap = repo.obsstore.successors | |
725 | fullsuccessorsets = [] # successor set + markers |
|
725 | fullsuccessorsets = [] # successor set + markers | |
726 | for sset in ssets: |
|
726 | for sset in ssets: | |
727 | if sset: |
|
727 | if sset: | |
728 | fullsuccessorsets.append(sset) |
|
728 | fullsuccessorsets.append(sset) | |
729 | else: |
|
729 | else: | |
730 | # successorsset return an empty set() when ctx or one of its |
|
730 | # successorsset return an empty set() when ctx or one of its | |
731 | # successors is pruned. |
|
731 | # successors is pruned. | |
732 | # In this case, walk the obs-markers tree again starting with ctx |
|
732 | # In this case, walk the obs-markers tree again starting with ctx | |
733 | # and find the relevant pruning obs-makers, the ones without |
|
733 | # and find the relevant pruning obs-makers, the ones without | |
734 | # successors. |
|
734 | # successors. | |
735 | # Having these markers allow us to compute some information about |
|
735 | # Having these markers allow us to compute some information about | |
736 | # its fate, like who pruned this changeset and when. |
|
736 | # its fate, like who pruned this changeset and when. | |
737 |
|
737 | |||
738 | # XXX we do not catch all prune markers (eg rewritten then pruned) |
|
738 | # XXX we do not catch all prune markers (eg rewritten then pruned) | |
739 | # (fix me later) |
|
739 | # (fix me later) | |
740 | foundany = False |
|
740 | foundany = False | |
741 | for mark in succsmap.get(ctx.node(), ()): |
|
741 | for mark in succsmap.get(ctx.node(), ()): | |
742 | if not mark[1]: |
|
742 | if not mark[1]: | |
743 | foundany = True |
|
743 | foundany = True | |
744 | sset = _succs() |
|
744 | sset = _succs() | |
745 | sset.markers.add(mark) |
|
745 | sset.markers.add(mark) | |
746 | fullsuccessorsets.append(sset) |
|
746 | fullsuccessorsets.append(sset) | |
747 | if not foundany: |
|
747 | if not foundany: | |
748 | fullsuccessorsets.append(_succs()) |
|
748 | fullsuccessorsets.append(_succs()) | |
749 |
|
749 | |||
750 | values = [] |
|
750 | values = [] | |
751 | for sset in fullsuccessorsets: |
|
751 | for sset in fullsuccessorsets: | |
752 | values.append({'successors': sset, 'markers': sset.markers}) |
|
752 | values.append({'successors': sset, 'markers': sset.markers}) | |
753 |
|
753 | |||
754 | return values |
|
754 | return values | |
755 |
|
755 | |||
756 | def _getobsfate(successorssets): |
|
756 | def _getobsfate(successorssets): | |
757 | """ Compute a changeset obsolescence fate based on its successorssets. |
|
757 | """ Compute a changeset obsolescence fate based on its successorssets. | |
758 | Successors can be the tipmost ones or the immediate ones. This function |
|
758 | Successors can be the tipmost ones or the immediate ones. This function | |
759 | return values are not meant to be shown directly to users, it is meant to |
|
759 | return values are not meant to be shown directly to users, it is meant to | |
760 | be used by internal functions only. |
|
760 | be used by internal functions only. | |
761 | Returns one fate from the following values: |
|
761 | Returns one fate from the following values: | |
762 | - pruned |
|
762 | - pruned | |
763 | - diverged |
|
763 | - diverged | |
764 | - superseded |
|
764 | - superseded | |
765 | - superseded_split |
|
765 | - superseded_split | |
766 | """ |
|
766 | """ | |
767 |
|
767 | |||
768 | if len(successorssets) == 0: |
|
768 | if len(successorssets) == 0: | |
769 | # The commit has been pruned |
|
769 | # The commit has been pruned | |
770 | return 'pruned' |
|
770 | return 'pruned' | |
771 | elif len(successorssets) > 1: |
|
771 | elif len(successorssets) > 1: | |
772 | return 'diverged' |
|
772 | return 'diverged' | |
773 | else: |
|
773 | else: | |
774 | # No divergence, only one set of successors |
|
774 | # No divergence, only one set of successors | |
775 | successors = successorssets[0] |
|
775 | successors = successorssets[0] | |
776 |
|
776 | |||
777 | if len(successors) == 1: |
|
777 | if len(successors) == 1: | |
778 | return 'superseded' |
|
778 | return 'superseded' | |
779 | else: |
|
779 | else: | |
780 | return 'superseded_split' |
|
780 | return 'superseded_split' | |
781 |
|
781 | |||
782 | def obsfateverb(successorset, markers): |
|
782 | def obsfateverb(successorset, markers): | |
783 | """ Return the verb summarizing the successorset and potentially using |
|
783 | """ Return the verb summarizing the successorset and potentially using | |
784 | information from the markers |
|
784 | information from the markers | |
785 | """ |
|
785 | """ | |
786 | if not successorset: |
|
786 | if not successorset: | |
787 | verb = 'pruned' |
|
787 | verb = 'pruned' | |
788 | elif len(successorset) == 1: |
|
788 | elif len(successorset) == 1: | |
789 | verb = 'rewritten' |
|
789 | verb = 'rewritten' | |
790 | else: |
|
790 | else: | |
791 | verb = 'split' |
|
791 | verb = 'split' | |
792 | return verb |
|
792 | return verb | |
793 |
|
793 | |||
794 | def markersdates(markers): |
|
794 | def markersdates(markers): | |
795 | """returns the list of dates for a list of markers |
|
795 | """returns the list of dates for a list of markers | |
796 | """ |
|
796 | """ | |
797 | return [m[4] for m in markers] |
|
797 | return [m[4] for m in markers] | |
798 |
|
798 | |||
799 | def markersusers(markers): |
|
799 | def markersusers(markers): | |
800 | """ Returns a sorted list of markers users without duplicates |
|
800 | """ Returns a sorted list of markers users without duplicates | |
801 | """ |
|
801 | """ | |
802 | markersmeta = [dict(m[3]) for m in markers] |
|
802 | markersmeta = [dict(m[3]) for m in markers] | |
803 | users = set(meta.get('user') for meta in markersmeta if meta.get('user')) |
|
803 | users = set(meta.get('user') for meta in markersmeta if meta.get('user')) | |
804 |
|
804 | |||
805 | return sorted(users) |
|
805 | return sorted(users) | |
806 |
|
806 | |||
807 | def markersoperations(markers): |
|
807 | def markersoperations(markers): | |
808 | """ Returns a sorted list of markers operations without duplicates |
|
808 | """ Returns a sorted list of markers operations without duplicates | |
809 | """ |
|
809 | """ | |
810 | markersmeta = [dict(m[3]) for m in markers] |
|
810 | markersmeta = [dict(m[3]) for m in markers] | |
811 | operations = set(meta.get('operation') for meta in markersmeta |
|
811 | operations = set(meta.get('operation') for meta in markersmeta | |
812 | if meta.get('operation')) |
|
812 | if meta.get('operation')) | |
813 |
|
813 | |||
814 | return sorted(operations) |
|
814 | return sorted(operations) | |
815 |
|
815 | |||
816 | def obsfateprinter(successors, markers, ui): |
|
816 | def obsfateprinter(successors, markers, ui): | |
817 | """ Build a obsfate string for a single successorset using all obsfate |
|
817 | """ Build a obsfate string for a single successorset using all obsfate | |
818 | related function defined in obsutil |
|
818 | related function defined in obsutil | |
819 | """ |
|
819 | """ | |
820 | quiet = ui.quiet |
|
820 | quiet = ui.quiet | |
821 | verbose = ui.verbose |
|
821 | verbose = ui.verbose | |
822 | normal = not verbose and not quiet |
|
822 | normal = not verbose and not quiet | |
823 |
|
823 | |||
824 | line = [] |
|
824 | line = [] | |
825 |
|
825 | |||
826 | # Verb |
|
826 | # Verb | |
827 | line.append(obsfateverb(successors, markers)) |
|
827 | line.append(obsfateverb(successors, markers)) | |
828 |
|
828 | |||
829 | # Operations |
|
829 | # Operations | |
830 | operations = markersoperations(markers) |
|
830 | operations = markersoperations(markers) | |
831 | if operations: |
|
831 | if operations: | |
832 | line.append(" using %s" % ", ".join(operations)) |
|
832 | line.append(" using %s" % ", ".join(operations)) | |
833 |
|
833 | |||
834 | # Successors |
|
834 | # Successors | |
835 | if successors: |
|
835 | if successors: | |
836 | fmtsuccessors = [successors.joinfmt(succ) for succ in successors] |
|
836 | fmtsuccessors = [successors.joinfmt(succ) for succ in successors] | |
837 | line.append(" as %s" % ", ".join(fmtsuccessors)) |
|
837 | line.append(" as %s" % ", ".join(fmtsuccessors)) | |
838 |
|
838 | |||
839 | # Users |
|
839 | # Users | |
840 | users = markersusers(markers) |
|
840 | users = markersusers(markers) | |
841 | # Filter out current user in not verbose mode to reduce amount of |
|
841 | # Filter out current user in not verbose mode to reduce amount of | |
842 | # information |
|
842 | # information | |
843 | if not verbose: |
|
843 | if not verbose: | |
844 | currentuser = ui.username(acceptempty=True) |
|
844 | currentuser = ui.username(acceptempty=True) | |
845 | if len(users) == 1 and currentuser in users: |
|
845 | if len(users) == 1 and currentuser in users: | |
846 | users = None |
|
846 | users = None | |
847 |
|
847 | |||
848 | if (verbose or normal) and users: |
|
848 | if (verbose or normal) and users: | |
849 | line.append(" by %s" % ", ".join(users)) |
|
849 | line.append(" by %s" % ", ".join(users)) | |
850 |
|
850 | |||
851 | # Date |
|
851 | # Date | |
852 | dates = markersdates(markers) |
|
852 | dates = markersdates(markers) | |
853 |
|
853 | |||
854 | if dates and verbose: |
|
854 | if dates and verbose: | |
855 | min_date = min(dates) |
|
855 | min_date = min(dates) | |
856 | max_date = max(dates) |
|
856 | max_date = max(dates) | |
857 |
|
857 | |||
858 | if min_date == max_date: |
|
858 | if min_date == max_date: | |
859 | fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') |
|
859 | fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') | |
860 | line.append(" (at %s)" % fmtmin_date) |
|
860 | line.append(" (at %s)" % fmtmin_date) | |
861 | else: |
|
861 | else: | |
862 | fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') |
|
862 | fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') | |
863 | fmtmax_date = util.datestr(max_date, '%Y-%m-%d %H:%M %1%2') |
|
863 | fmtmax_date = util.datestr(max_date, '%Y-%m-%d %H:%M %1%2') | |
864 | line.append(" (between %s and %s)" % (fmtmin_date, fmtmax_date)) |
|
864 | line.append(" (between %s and %s)" % (fmtmin_date, fmtmax_date)) | |
865 |
|
865 | |||
866 | return "".join(line) |
|
866 | return "".join(line) | |
867 |
|
867 | |||
868 |
|
868 | |||
869 | filteredmsgtable = { |
|
869 | filteredmsgtable = { | |
870 | "pruned": _("hidden revision '%s' is pruned"), |
|
870 | "pruned": _("hidden revision '%s' is pruned"), | |
871 | "diverged": _("hidden revision '%s' has diverged"), |
|
871 | "diverged": _("hidden revision '%s' has diverged"), | |
872 | "superseded": _("hidden revision '%s' was rewritten as: %s"), |
|
872 | "superseded": _("hidden revision '%s' was rewritten as: %s"), | |
873 | "superseded_split": _("hidden revision '%s' was split as: %s"), |
|
873 | "superseded_split": _("hidden revision '%s' was split as: %s"), | |
874 | "superseded_split_several": _("hidden revision '%s' was split as: %s and " |
|
874 | "superseded_split_several": _("hidden revision '%s' was split as: %s and " | |
875 | "%d more"), |
|
875 | "%d more"), | |
876 | } |
|
876 | } | |
877 |
|
877 | |||
878 |
def _getfilteredreason( |
|
878 | def _getfilteredreason(repo, changeid, ctx): | |
879 | """return a human-friendly string on why a obsolete changeset is hidden |
|
879 | """return a human-friendly string on why a obsolete changeset is hidden | |
880 | """ |
|
880 | """ | |
881 |
successors = successorssets( |
|
881 | successors = successorssets(repo, ctx.node()) | |
882 | fate = _getobsfate(successors) |
|
882 | fate = _getobsfate(successors) | |
883 |
|
883 | |||
884 | # Be more precise in case the revision is superseded |
|
884 | # Be more precise in case the revision is superseded | |
885 | if fate == 'pruned': |
|
885 | if fate == 'pruned': | |
886 | return filteredmsgtable['pruned'] % changeid |
|
886 | return filteredmsgtable['pruned'] % changeid | |
887 | elif fate == 'diverged': |
|
887 | elif fate == 'diverged': | |
888 | return filteredmsgtable['diverged'] % changeid |
|
888 | return filteredmsgtable['diverged'] % changeid | |
889 | elif fate == 'superseded': |
|
889 | elif fate == 'superseded': | |
890 | single_successor = nodemod.short(successors[0][0]) |
|
890 | single_successor = nodemod.short(successors[0][0]) | |
891 | return filteredmsgtable['superseded'] % (changeid, single_successor) |
|
891 | return filteredmsgtable['superseded'] % (changeid, single_successor) | |
892 | elif fate == 'superseded_split': |
|
892 | elif fate == 'superseded_split': | |
893 |
|
893 | |||
894 | succs = [] |
|
894 | succs = [] | |
895 | for node_id in successors[0]: |
|
895 | for node_id in successors[0]: | |
896 | succs.append(nodemod.short(node_id)) |
|
896 | succs.append(nodemod.short(node_id)) | |
897 |
|
897 | |||
898 | if len(succs) <= 2: |
|
898 | if len(succs) <= 2: | |
899 | fmtsuccs = ', '.join(succs) |
|
899 | fmtsuccs = ', '.join(succs) | |
900 | return filteredmsgtable['superseded_split'] % (changeid, fmtsuccs) |
|
900 | return filteredmsgtable['superseded_split'] % (changeid, fmtsuccs) | |
901 | else: |
|
901 | else: | |
902 | firstsuccessors = ', '.join(succs[:2]) |
|
902 | firstsuccessors = ', '.join(succs[:2]) | |
903 | remainingnumber = len(succs) - 2 |
|
903 | remainingnumber = len(succs) - 2 | |
904 |
|
904 | |||
905 | args = (changeid, firstsuccessors, remainingnumber) |
|
905 | args = (changeid, firstsuccessors, remainingnumber) | |
906 | return filteredmsgtable['superseded_split_several'] % args |
|
906 | return filteredmsgtable['superseded_split_several'] % args |
General Comments 0
You need to be logged in to leave comments.
Login now