This is an archive of the discontinued Mercurial Phabricator instance.

patch: make extract() a context manager (API)
ClosedPublic

Authored by indygreg on Apr 13 2018, 2:26 AM.

Details

Summary

Previously, this function was creating a temporary file and relying
on callers to unlink it. Yuck.

We convert the function to a context manager and tie the lifetime of
the temporary file to that of the context manager. This changed
indentation not only from the context manager, but also from the
elination of try blocks. It was just easier to split the heart of
extract() into its own function.

The single consumer of this function has been refactored to use it as
a context manager. Code for cleaning up the file in tryimportone()
has also been removed.

.. api::

``patch.extract()`` is now a context manager. Callers no longer have
to worry about deleting the temporary file it creates, as the file is
tied to the lifetime of the context manager.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Apr 13 2018, 2:26 AM
This revision was automatically updated to reflect the committed changes.