Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 42374:65fa61ca20af
context: add ctx.files{modified,added,removed}() methods
Changeset-centric copy tracing is currently very slow because it often
reads manifests. One place it needs the manifest is in _chain(), where
it removes a copy X->Y if Y has subsequently gotten removed. I want to
speed that up by keeping track directly in the changeset of which
files are removed in the changeset. These methods will be similar to
ctx.p[12]copies() in that way: they will either read from the
changeset or calculate the information from the manifests otherwise.
Note that these are different from ctx.{modified,added,removed}() on
merge commits. Those functions always compare to p1, but the new ones
compare to both parents. filesadded() means "file does not exist in
either parent but exists now", filesremoved() means "file existed in
either parent but does not exist now", and filesmodified() means "file
existed in either parent and still exists". The set of files in
ctx.files() is the union of the files from the three new functions
(and the three new ones are all disjoint sets).
Also note that uncommitted merges are weird as usual. The invariant
mentioned above still holds, but the functions compare to p1 (and are
thus identical to the existing methods).
Differential Revision: https://phab.mercurial-scm.org/D6367
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 18 Apr 2019 13:34:20 -0700 |
parents | 313812cbf4ca |
children | 602469a91550 |
comparison
equal
deleted
inserted
replaced
42373:f3d06d37e194 | 42374:65fa61ca20af |
---|---|
461 return self._changeset.user | 461 return self._changeset.user |
462 def date(self): | 462 def date(self): |
463 return self._changeset.date | 463 return self._changeset.date |
464 def files(self): | 464 def files(self): |
465 return self._changeset.files | 465 return self._changeset.files |
466 def filesmodified(self): | |
467 modified = set(self.files()) | |
468 modified.difference_update(self.filesadded()) | |
469 modified.difference_update(self.filesremoved()) | |
470 return sorted(modified) | |
471 def filesadded(self): | |
472 added = [] | |
473 for f in self.files(): | |
474 if not any(f in p for p in self.parents()): | |
475 added.append(f) | |
476 return added | |
477 def filesremoved(self): | |
478 removed = [] | |
479 for f in self.files(): | |
480 if f not in self: | |
481 removed.append(f) | |
482 return removed | |
483 | |
466 @propertycache | 484 @propertycache |
467 def _copies(self): | 485 def _copies(self): |
468 source = self._repo.ui.config('experimental', 'copies.read-from') | 486 source = self._repo.ui.config('experimental', 'copies.read-from') |
469 p1copies = self._changeset.p1copies | 487 p1copies = self._changeset.p1copies |
470 p2copies = self._changeset.p2copies | 488 p2copies = self._changeset.p2copies |
1168 return self._status.added | 1186 return self._status.added |
1169 def removed(self): | 1187 def removed(self): |
1170 return self._status.removed | 1188 return self._status.removed |
1171 def deleted(self): | 1189 def deleted(self): |
1172 return self._status.deleted | 1190 return self._status.deleted |
1191 filesmodified = modified | |
1192 filesadded = added | |
1193 filesremoved = removed | |
1194 | |
1173 def branch(self): | 1195 def branch(self): |
1174 return encoding.tolocal(self._extra['branch']) | 1196 return encoding.tolocal(self._extra['branch']) |
1175 def closesbranch(self): | 1197 def closesbranch(self): |
1176 return 'close' in self._extra | 1198 return 'close' in self._extra |
1177 def extra(self): | 1199 def extra(self): |