Using generators for feeding chunks into I/O is more flexible than
passing a file object or write function around.
This commit refactors the patch exporting code to emit a series a data
chunks instead of doing push-based I/O. As a side-effect, we could now
obtain the patch representation of a changeset without having to use
a file object. Yay!
Code around the management of the file handles has also been cleaned up
a bit.