diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Render each diff body while its file is open
Diffstat (limited to '')
-rw-r--r--source/html.c27
1 file changed, 27 insertions, 0 deletions
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();