comparison mercurial/localrepo.py @ 37174:bb47dc2f71a0

context: move reuse of context object to repo.__getitem__ (API) As an example of how weird the basectx.__new__ is: whenever you create a workingctx, basectx.__new__ gets called first. Since our __new__ has a "changeid" argument as second parameter, when create the workingctx(repo, text="blah"), the text gets bound to "changeid". Since a string isn't a basectx, our __new__ ends up not doing anything funny, but that's still very confusing code. Another case is metadataonlyctx.__new__(), which I think exists in order to prevent metadataonlyctx.__init__'s third argument (originalctx) from being interpreted as a changeid in basectx.__new__(), thereby getting reused. Let's move this to repo.__getitem__ instead, where it will be pretty obvious what the code does. After this patch, changectx(ctx) will be an error (it will fail when trying to see if it's a 20-byte string). Differential Revision: https://phab.mercurial-scm.org/D2969
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 29 Mar 2018 22:51:45 -0700
parents daef13da66fe
children 0dfb5672f015
comparison
equal deleted inserted replaced
37173:05ff1a155a21 37174:bb47dc2f71a0
780 self.invalidate(clearfilecache=True) 780 self.invalidate(clearfilecache=True)
781 781
782 def __getitem__(self, changeid): 782 def __getitem__(self, changeid):
783 if changeid is None: 783 if changeid is None:
784 return context.workingctx(self) 784 return context.workingctx(self)
785 if isinstance(changeid, context.basectx):
786 return changeid
785 if isinstance(changeid, slice): 787 if isinstance(changeid, slice):
786 # wdirrev isn't contiguous so the slice shouldn't include it 788 # wdirrev isn't contiguous so the slice shouldn't include it
787 return [context.changectx(self, i) 789 return [context.changectx(self, i)
788 for i in xrange(*changeid.indices(len(self))) 790 for i in xrange(*changeid.indices(len(self)))
789 if i not in self.changelog.filteredrevs] 791 if i not in self.changelog.filteredrevs]