This is an archive of the discontinued Mercurial Phabricator instance.

util: add base class for transactional context managers
ClosedPublic

Authored by martinvonz on Aug 14 2017, 7:46 PM.

Details

Summary

We have at least three types with a close() and a release() method
where the close() method is supposed to be called on success and the
release() method is supposed to be called last, whether successful or
not. Two of them (transaction and dirstateguard) already have
identical implementations of enter and exit. Let's extract a
base class for this, so we reuse the code and so the third type
(transactionmanager) can also be used as a context manager.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

martinvonz created this revision.Aug 14 2017, 7:46 PM
indygreg requested changes to this revision.Aug 14 2017, 9:32 PM
indygreg added a subscriber: indygreg.
indygreg added inline comments.
mercurial/util.py
597–601

How do you feel about changing this to use abc.ABCMeta so the interface is enforced as type creation time? I'm doing this in D332 and people seem to be on board.

This revision now requires changes to proceed.Aug 14 2017, 9:32 PM
martinvonz edited edge metadata.Aug 15 2017, 1:58 AM
martinvonz updated this revision to Diff 914.
martinvonz added inline comments.Aug 15 2017, 1:59 AM
mercurial/util.py
597–601

Sounds good. I had heard you mention abc before, but I was simply too lazy to bother checking how to do it. Now that I have an example: done! Let me know how it looks.

We should probably do that for matchers too, in case someone feels like it...

indygreg accepted this revision.Aug 15 2017, 2:09 AM
This revision is now accepted and ready to land.Aug 15 2017, 2:09 AM
This revision was automatically updated to reflect the committed changes.