This is an archive of the discontinued Mercurial Phabricator instance.

hgweb: port archive command to modern response API
ClosedPublic

Authored by indygreg on Mar 11 2018, 12:23 AM.

Details

Summary

Well, I tried to go with PEP 3333's recommendations and only allow
our WSGI application to emit data via a response generator.
Unfortunately, the "archive" command calls into the zipfile and
tarfile modules and these operator on file objects and must send
their data to an object with write(). There's no easy way turn
these write() calls into a generator.

So, we teach our response type how to expose a file object like
object that can be used to write() output. We try to keep the API
consistent with how things work currently: callers must call a
setbody*(), then sendresponse() to trigger sending of headers,
and only then can they get a handle on the object to perform
writing.

This required overloading the return value of @webcommand functions
even more. Fortunately, we're almost completely ported off the
legacy API. So we should be able to simplify matters in the near
future.

A test relying on this functionality has also been updated to use
the new API.

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

indygreg created this revision.Mar 11 2018, 12:23 AM
durin42 accepted this revision.Mar 12 2018, 5:13 PM
This revision is now accepted and ready to land.Mar 12 2018, 5:13 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Mar 16 2018, 12:38 PM
yuja added inline comments.
mercurial/hgweb/webcommands.py
1220

assert may be deleted by -O, but this one is important.

Can you send a followup?