From f8eddb387ee5d6e6f9f751888d71ffd80974cb2d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 8 Aug 2026 12:50:00 -1000 Subject: Render each diff body while its file is open --- source/html.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/html.c') diff --git a/source/html.c b/source/html.c index dbb0a57..6e023d1 100644 --- a/source/html.c +++ b/source/html.c @@ -113,8 +113,35 @@ void html_flush(void) html_write(html_buf, len); } +/* + * While a capture is in effect, page output is collected into the caller's + * buffer instead of being written. The diff view uses this to render a file's + * body at the point it already has the file open, rather than walking the whole + * tree a second time to produce what the diffstat above it has to be printed + * before. + * + * A capture must not span anything that writes to stdout by another route, a + * filter in particular, since that output would escape the capture. + */ +static struct strbuf *html_capture; + +void html_capture_begin(struct strbuf *sb) +{ + html_flush(); + html_capture = sb; +} + +void html_capture_end(void) +{ + html_capture = NULL; +} + void html_raw(const char *data, size_t size) { + if (html_capture) { + strbuf_add(html_capture, data, size); + return; + } if (size >= HTML_WRITE_BUFSIZE) { // Nothing is gained by copying a blob through the buffer. html_flush(); -- cgit v2.8.0