Skip to content

Commit 5831b56

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] NUL terminate diff-tree header lines under -z.
Thomas Glanzmann noticed that diff-tree -z HEAD piped to diff-helper -z did not work. Since diff-helper -z expects NUL terminated lines, we should generate such. The output side of the diff-helper should always be using '\n' termination; earlier it used the same line_termination used for the input side, which was a mistake. Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 046aa64 commit 5831b56

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

diff-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int main(int ac, const char **av) {
121121
if (status) {
122122
unrecognized:
123123
diff_flush(diff_output_style);
124-
printf("%s%c", sb1.buf, line_termination);
124+
printf("%s\n", sb1.buf);
125125
}
126126
}
127127
if (detect_rename)

diff-tree.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,18 @@ static int call_diff_flush(void)
277277
if (nr_paths)
278278
diffcore_pathspec(paths);
279279
if (header) {
280-
printf("%s", header);
280+
if (diff_output_format == DIFF_FORMAT_MACHINE) {
281+
const char *ep, *cp;
282+
for (cp = header; *cp; cp = ep) {
283+
ep = strchr(cp, '\n');
284+
if (ep == 0) ep = cp + strlen(cp);
285+
printf("%.*s%c", ep-cp, cp, 0);
286+
if (*ep) ep++;
287+
}
288+
}
289+
else {
290+
printf("%s", header);
291+
}
281292
header = NULL;
282293
}
283294
diff_flush(diff_output_format);

0 commit comments

Comments
 (0)