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