Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 39957:e1e3d1b498d3
context: reduce dependence of changectx constructor
I want to change the constructor's signature and letting all creation
of changectx instances go through the repo simplifies that.
Differential Revision: https://phab.mercurial-scm.org/D4826
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 26 Sep 2018 22:44:51 -0700 |
parents | 8cef57031bbe |
children | 3d35304bd09b |
comparison
equal
deleted
inserted
replaced
39956:36e9d2c60837 | 39957:e1e3d1b498d3 |
---|---|
240 | 240 |
241 def p2(self): | 241 def p2(self): |
242 parents = self._parents | 242 parents = self._parents |
243 if len(parents) == 2: | 243 if len(parents) == 2: |
244 return parents[1] | 244 return parents[1] |
245 return changectx(self._repo, nullrev) | 245 return self._repo[nullrev] |
246 | 246 |
247 def _fileinfo(self, path): | 247 def _fileinfo(self, path): |
248 if r'_manifest' in self.__dict__: | 248 if r'_manifest' in self.__dict__: |
249 try: | 249 try: |
250 return self._manifest[path], self._manifest.flags(path) | 250 return self._manifest[path], self._manifest.flags(path) |
480 @propertycache | 480 @propertycache |
481 def _parents(self): | 481 def _parents(self): |
482 repo = self._repo | 482 repo = self._repo |
483 p1, p2 = repo.changelog.parentrevs(self._rev) | 483 p1, p2 = repo.changelog.parentrevs(self._rev) |
484 if p2 == nullrev: | 484 if p2 == nullrev: |
485 return [changectx(repo, p1)] | 485 return [repo[p1]] |
486 return [changectx(repo, p1), changectx(repo, p2)] | 486 return [repo[p1], repo[p2]] |
487 | 487 |
488 def changeset(self): | 488 def changeset(self): |
489 c = self._changeset | 489 c = self._changeset |
490 return ( | 490 return ( |
491 c.manifest, | 491 c.manifest, |
532 | 532 |
533 This returns only the immediate child changesets. Use descendants() to | 533 This returns only the immediate child changesets. Use descendants() to |
534 recursively walk children. | 534 recursively walk children. |
535 """ | 535 """ |
536 c = self._repo.changelog.children(self._node) | 536 c = self._repo.changelog.children(self._node) |
537 return [changectx(self._repo, x) for x in c] | 537 return [self._repo[x] for x in c] |
538 | 538 |
539 def ancestors(self): | 539 def ancestors(self): |
540 for a in self._repo.changelog.ancestors([self._rev]): | 540 for a in self._repo.changelog.ancestors([self._rev]): |
541 yield changectx(self._repo, a) | 541 yield self._repo[a] |
542 | 542 |
543 def descendants(self): | 543 def descendants(self): |
544 """Recursively yield all children of the changeset. | 544 """Recursively yield all children of the changeset. |
545 | 545 |
546 For just the immediate children, use children() | 546 For just the immediate children, use children() |
547 """ | 547 """ |
548 for d in self._repo.changelog.descendants([self._rev]): | 548 for d in self._repo.changelog.descendants([self._rev]): |
549 yield changectx(self._repo, d) | 549 yield self._repo[d] |
550 | 550 |
551 def filectx(self, path, fileid=None, filelog=None): | 551 def filectx(self, path, fileid=None, filelog=None): |
552 """get a file context from this changeset""" | 552 """get a file context from this changeset""" |
553 if fileid is None: | 553 if fileid is None: |
554 fileid = self.filenode(path) | 554 fileid = self.filenode(path) |
587 (_("note: using %s as ancestor of %s and %s\n") % | 587 (_("note: using %s as ancestor of %s and %s\n") % |
588 (short(anc), short(self._node), short(n2))) + | 588 (short(anc), short(self._node), short(n2))) + |
589 ''.join(_(" alternatively, use --config " | 589 ''.join(_(" alternatively, use --config " |
590 "merge.preferancestor=%s\n") % | 590 "merge.preferancestor=%s\n") % |
591 short(n) for n in sorted(cahs) if n != anc)) | 591 short(n) for n in sorted(cahs) if n != anc)) |
592 return changectx(self._repo, anc) | 592 return self._repo[anc] |
593 | 593 |
594 def isancestorof(self, other): | 594 def isancestorof(self, other): |
595 """True if this changeset is an ancestor of other""" | 595 """True if this changeset is an ancestor of other""" |
596 return self._repo.changelog.isancestorrev(self._rev, other._rev) | 596 return self._repo.changelog.isancestorrev(self._rev, other._rev) |
597 | 597 |
990 self._fileid = fileid | 990 self._fileid = fileid |
991 | 991 |
992 @propertycache | 992 @propertycache |
993 def _changectx(self): | 993 def _changectx(self): |
994 try: | 994 try: |
995 return changectx(self._repo, self._changeid) | 995 return self._repo[self._changeid] |
996 except error.FilteredRepoLookupError: | 996 except error.FilteredRepoLookupError: |
997 # Linkrev may point to any revision in the repository. When the | 997 # Linkrev may point to any revision in the repository. When the |
998 # repository is filtered this may lead to `filectx` trying to build | 998 # repository is filtered this may lead to `filectx` trying to build |
999 # `changectx` for filtered revision. In such case we fallback to | 999 # `changectx` for filtered revision. In such case we fallback to |
1000 # creating `changectx` on the unfiltered version of the reposition. | 1000 # creating `changectx` on the unfiltered version of the reposition. |
1008 # behavior" is seen as better as "crash" | 1008 # behavior" is seen as better as "crash" |
1009 # | 1009 # |
1010 # Linkrevs have several serious troubles with filtering that are | 1010 # Linkrevs have several serious troubles with filtering that are |
1011 # complicated to solve. Proper handling of the issue here should be | 1011 # complicated to solve. Proper handling of the issue here should be |
1012 # considered when solving linkrev issue are on the table. | 1012 # considered when solving linkrev issue are on the table. |
1013 return changectx(self._repo.unfiltered(), self._changeid) | 1013 return self._repo.unfiltered()[self._changeid] |
1014 | 1014 |
1015 def filectx(self, fileid, changeid=None): | 1015 def filectx(self, fileid, changeid=None): |
1016 '''opens an arbitrary revision of the file without | 1016 '''opens an arbitrary revision of the file without |
1017 opening a new filelog''' | 1017 opening a new filelog''' |
1018 return filectx(self._repo, self._path, fileid=fileid, | 1018 return filectx(self._repo, self._path, fileid=fileid, |
1242 def ancestors(self): | 1242 def ancestors(self): |
1243 for p in self._parents: | 1243 for p in self._parents: |
1244 yield p | 1244 yield p |
1245 for a in self._repo.changelog.ancestors( | 1245 for a in self._repo.changelog.ancestors( |
1246 [p.rev() for p in self._parents]): | 1246 [p.rev() for p in self._parents]): |
1247 yield changectx(self._repo, a) | 1247 yield self._repo[a] |
1248 | 1248 |
1249 def markcommitted(self, node): | 1249 def markcommitted(self, node): |
1250 """Perform post-commit cleanup necessary after committing this ctx | 1250 """Perform post-commit cleanup necessary after committing this ctx |
1251 | 1251 |
1252 Specifically, this updates backing stores this working context | 1252 Specifically, this updates backing stores this working context |
1299 @propertycache | 1299 @propertycache |
1300 def _parents(self): | 1300 def _parents(self): |
1301 p = self._repo.dirstate.parents() | 1301 p = self._repo.dirstate.parents() |
1302 if p[1] == nullid: | 1302 if p[1] == nullid: |
1303 p = p[:-1] | 1303 p = p[:-1] |
1304 return [changectx(self._repo, x) for x in p] | 1304 return [self._repo[x] for x in p] |
1305 | 1305 |
1306 def _fileinfo(self, path): | 1306 def _fileinfo(self, path): |
1307 # populate __dict__['_manifest'] as workingctx has no _manifestdelta | 1307 # populate __dict__['_manifest'] as workingctx has no _manifestdelta |
1308 self._manifest | 1308 self._manifest |
1309 return super(workingctx, self)._fileinfo(path) | 1309 return super(workingctx, self)._fileinfo(path) |