This is an archive of the discontinued Mercurial Phabricator instance.

context: move reuse of context object to repo.__getitem__ (API)
ClosedPublic

Authored by martinvonz on Mar 30 2018, 2:09 AM.

Details

Summary

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).

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

martinvonz created this revision.Mar 30 2018, 2:09 AM
yuja added subscribers: smf, yuja.Mar 30 2018, 8:26 AM

+1, but I don't remember why we made that hack.

@smf Any thoughts?

indygreg accepted this revision.Mar 30 2018, 1:27 PM
indygreg added a subscriber: indygreg.

That's 2 of us who think this is a good idea. I'm going to queue it.

If @smf knows of a reason why this is bad, we can always drop it or revert it.

This revision is now accepted and ready to land.Mar 30 2018, 1:27 PM
This revision was automatically updated to reflect the committed changes.