Skip to content

Commit 34176d0

Browse files
jltoblergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9fddae commit 34176d0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Documentation/git-diff-pairs.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ in the NUL-terminated raw output format as generated by commands such as `git
1717
diff-tree -z -r --raw`. By default, the outputted diffs are computed and shown
1818
in the patch format when stdin closes.
1919

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+
2024
Usage of this command enables the traditional diff pipeline to be broken up
2125
into separate stages where `diff-pairs` acts as the output phase. Other
2226
commands, such as `diff-tree`, may serve as a frontend to compute the raw

builtin/diff-pairs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int cmd_diff_pairs(int argc, const char **argv, const char *prefix,
6363

6464
repo_init_revisions(repo, &revs, prefix);
6565
repo_config(repo, git_diff_basic_config, NULL);
66+
revs.diffopt.no_free = 1;
6667
revs.disable_stdin = 1;
6768
revs.abbrev = 0;
6869
revs.diff = 1;
@@ -106,6 +107,17 @@ int cmd_diff_pairs(int argc, const char **argv, const char *prefix,
106107
break;
107108

108109
p = meta.buf;
110+
if (!*p) {
111+
flush_diff_queue(&revs.diffopt);
112+
/*
113+
* When the diff queue is explicitly flushed, append a
114+
* NUL byte to separate batches of diffs.
115+
*/
116+
fputc('\0', revs.diffopt.file);
117+
fflush(revs.diffopt.file);
118+
continue;
119+
}
120+
109121
if (*p != ':')
110122
die(_("invalid raw diff input"));
111123
p++;
@@ -180,6 +192,7 @@ int cmd_diff_pairs(int argc, const char **argv, const char *prefix,
180192
}
181193
}
182194

195+
revs.diffopt.no_free = 0;
183196
flush_diff_queue(&revs.diffopt);
184197
ret = diff_result_code(&revs);
185198

t/t4070-diff-pairs.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ test_expect_success 'diff-pairs does not support pathspec arguments' '
7171
grep "error: pathspec arguments not supported" err
7272
'
7373

74+
test_expect_success 'diff-pairs explicit queue flush' '
75+
git diff-tree -r -M -C -C -z base new >expect &&
76+
printf "\0" >>expect &&
77+
git diff-tree -r -M -C -C -z base new >>expect &&
78+
79+
git diff-pairs --raw -z <expect >actual &&
80+
test_cmp expect actual
81+
'
82+
7483
test_done

0 commit comments

Comments
 (0)