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