{"thread":{"id":"4191","subject":"[PATCH] Provide a way to flush git-diff-tree's output","startedAt":"2006-05-18T06:58:51Z","lastAt":"2006-05-18T09:43:01Z","messageCount":3,"participants":["Paul Mackerras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"20211","messageId":"17516.6955.282732.460675@cargo.ozlabs.ibm.com","threadId":"4191","inReplyTo":null,"subject":"[PATCH] Provide a way to flush git-diff-tree's output","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2006-05-18T06:58:51Z","receivedAt":"2006-05-18T06:58:51Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"Gitk wants to use git-diff-tree as a filter to tell it which ids from\na given list affect a set of files or directories.  We don't want to\nfork and exec a new git-diff-tree process for each batch of ids, since\nthere could be a lot of relatively small batches.  For example, a\nbatch could contain as many ids as fit in gitk's headline display\nwindow, i.e. 20 or so, and we would be processing a new batch every\ntime the user scrolls that window.\n\nThe --stdin flag to git-diff-tree is suitable for this, but the main\ndifficulty is that the output of git-diff-tree gets buffered and\ndoesn't get sent until the buffer is full.\n\nThis provides a way to get git-diff-tree to flush its output buffers.\nIf a blank line is supplied on git-diff-tree's standard input, it will\nflush its output buffers and then accept further input.\n\nSigned-off-by: Paul Mackerras <paulus@samba.org>\n---\ndiff --git a/diff-tree.c b/diff-tree.c\nindex 7207867..69bb74b 100644\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -138,7 +138,10 @@ int main(int argc, const char **argv)\n \t\topt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |\n \t\t\t\t       DIFF_SETUP_USE_CACHE);\n \twhile (fgets(line, sizeof(line), stdin))\n-\t\tdiff_tree_stdin(line);\n+\t\tif (line[0] == '\\n')\n+\t\t\tfflush(stdout);\n+\t\telse\n+\t\t\tdiff_tree_stdin(line);\n \n \treturn 0;\n }\n"},{"id":"20212","messageId":"7vmzdf6bj5.fsf@assigned-by-dhcp.cox.net","threadId":"4191","inReplyTo":"17516.6955.282732.460675@cargo.ozlabs.ibm.com","subject":"Re: [PATCH] Provide a way to flush git-diff-tree's output","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-18T07:24:14Z","receivedAt":"2006-05-18T07:24:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul Mackerras <paulus@samba.org> writes:\n\n> The --stdin flag to git-diff-tree is suitable for this, but the main\n> difficulty is that the output of git-diff-tree gets buffered and\n> doesn't get sent until the buffer is full.\n>\n> This provides a way to get git-diff-tree to flush its output buffers.\n> If a blank line is supplied on git-diff-tree's standard input, it will\n> flush its output buffers and then accept further input.\n\nSounds low impact and sane.\n\nI suspect the usual caveat on bidirectional pipe deadlock\napplies to the caller.  Does gitk do that?  The current code\nseems to feed a pre-generated list with \"open | cmd <<\"\nconstruct to the command, so perhaps you are planning to change\nthat?\n"},{"id":"20222","messageId":"17516.16805.281168.662330@cargo.ozlabs.ibm.com","threadId":"4191","inReplyTo":"7vmzdf6bj5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Provide a way to flush git-diff-tree's output","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2006-05-18T09:43:01Z","receivedAt":"2006-05-18T09:43:01Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"Junio C Hamano writes:\n\n> Sounds low impact and sane.\n> \n> I suspect the usual caveat on bidirectional pipe deadlock\n> applies to the caller.  Does gitk do that?  The current code\n\nGitk will use non-blocking mode on the pipes to/from the git-diff-tree\nprocess, so there isn't a possibility of deadlock that I can see.\n\n> seems to feed a pre-generated list with \"open | cmd <<\"\n> construct to the command, so perhaps you are planning to change\n> that?\n\nThat's for the \"Find\" function.  I'm in the process of adding the code\nto let users enter a list of paths and have gitk highlight the commits\naffecting those paths.  That will involve a separate invocation of\ngit-diff-tree.  To make it responsive, I'm only going to ask\ngit-diff-tree about the commits that are visible on the screen - but I\nneed git-diff-tree to give me an answer quickly, i.e. in less time\nthan a human can perceive.\n\nThanks,\nPaul.\n"}]}