Git fork

builtin/diff-pairs: allow explicit diff queue flush

The diffs queued from git-diff-pairs(1) are flushed when stdin is
closed. To enable greater flexibility, allow control over when the diff
queue is flushed by writing a single NUL byte on stdin between input
file pairs. Diff output between flushes is separated by a single NUL
byte.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Justin Tobler and committed by
Junio C Hamano
cf15095e 5bd10b2a

+27
+4
Documentation/git-diff-pairs.adoc
··· 17 17 diff-tree -z -r --raw`. By default, the outputted diffs are computed and shown 18 18 in the patch format when stdin closes. 19 19 20 + A single NUL byte may be written to stdin between raw input lines to compute 21 + file pair diffs up to that point instead of waiting for stdin to close. A NUL 22 + byte is also written to the output to delimit between these batches of diffs. 23 + 20 24 Usage of this command enables the traditional diff pipeline to be broken up 21 25 into separate stages where `diff-pairs` acts as the output phase. Other 22 26 commands, such as `diff-tree`, may serve as a frontend to compute the raw
+14
builtin/diff-pairs.c
··· 57 57 show_usage_with_options_if_asked(argc, argv, builtin_diff_pairs_usage, parseopts); 58 58 59 59 repo_config(repo, git_diff_basic_config, NULL); 60 + revs.diffopt.no_free = 1; 60 61 revs.disable_stdin = 1; 61 62 revs.abbrev = 0; 62 63 revs.diff = 1; ··· 106 107 break; 107 108 108 109 p = meta.buf; 110 + if (!*p) { 111 + diffcore_std(&revs.diffopt); 112 + diff_flush(&revs.diffopt); 113 + /* 114 + * When the diff queue is explicitly flushed, append a 115 + * NUL byte to separate batches of diffs. 116 + */ 117 + fputc('\0', revs.diffopt.file); 118 + fflush(revs.diffopt.file); 119 + continue; 120 + } 121 + 109 122 if (*p != ':') 110 123 die(_("invalid raw diff input")); 111 124 p++; ··· 179 192 } 180 193 } 181 194 195 + revs.diffopt.no_free = 0; 182 196 diffcore_std(&revs.diffopt); 183 197 diff_flush(&revs.diffopt); 184 198 ret = diff_result_code(&revs);
+9
t/t4070-diff-pairs.sh
··· 78 78 test_cmp expect err 79 79 ' 80 80 81 + test_expect_success 'diff-pairs explicit queue flush' ' 82 + git diff-tree -r -M -C -C -z base new >expect && 83 + printf "\0" >>expect && 84 + git diff-tree -r -M -C -C -z base new >>expect && 85 + 86 + git diff-pairs --raw -z <expect >actual && 87 + test_cmp expect actual 88 + ' 89 + 81 90 test_done