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