Skip to content

Commit 4243065

Browse files
jltoblergitster
authored andcommitted
builtin/diff-pairs: allow explicit diff queue flush
The diffs queued from git-diff-pairs(1) stdin are not flushed EOF is reached. 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 line terminator. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4078de5 commit 4243065

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Documentation/git-diff-pairs.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ compute diffs progressively over the course of multiple invocations of
3232
Each blob pair is fed to the diff machinery individually queued and the output
3333
is flushed on stdin EOF.
3434

35+
To explicitly flush the diff queue, a single nul byte can be written to stdin
36+
between filepairs. Diff output between flushes is separated by a single line
37+
terminator.
38+
3539
OPTIONS
3640
-------
3741

builtin/diff-pairs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ int cmd_diff_pairs(int argc, const char **argv, const char *prefix,
9999
break;
100100

101101
p = meta.buf;
102+
if (!*p) {
103+
flush_diff_queue(&revs.diffopt);
104+
/*
105+
* When the diff queue is explicitly flushed, append an
106+
* additional terminator to separate batches of diffs.
107+
*/
108+
fprintf(revs.diffopt.file, "%c",
109+
revs.diffopt.line_termination);
110+
continue;
111+
}
112+
102113
if (*p != ':')
103114
die("invalid raw diff input");
104115
p++;

t/t4070-diff-pairs.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,26 @@ test_expect_success 'split input across multiple diff-pairs' '
7777
test_cmp expect actual
7878
'
7979

80+
test_expect_success 'diff-pairs explicit queue flush' '
81+
git diff-tree -r -M -C -C -z base new >input &&
82+
printf "\0" >>input &&
83+
git diff-tree -r -M -C -C -z base new >>input &&
84+
85+
git diff-tree -r -M -C -C base new >expect &&
86+
printf "\n" >>expect &&
87+
git diff-tree -r -M -C -C base new >>expect &&
88+
89+
git diff-pairs <input >actual &&
90+
test_cmp expect actual
91+
'
92+
j
93+
test_expect_success 'diff-pairs explicit queue flush null terminated' '
94+
git diff-tree -r -M -C -C -z base new >expect &&
95+
printf "\0" >>expect &&
96+
git diff-tree -r -M -C -C -z base new >>expect &&
97+
98+
git diff-pairs -z <expect >actual &&
99+
test_cmp expect actual
100+
'
101+
80102
test_done

0 commit comments

Comments
 (0)