From: Junio C Hamano Date: Mon, 23 May 2005 19:07:55 +0000 (-0700) Subject: [PATCH] NUL terminate diff-tree header lines under -z. X-Git-Tag: v0.99~488 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5831b563a442e7c3198a444a51d8caba4d072506;p=git.git [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 Signed-off-by: Linus Torvalds --- diff --git a/diff-helper.c b/diff-helper.c index 23855759e..c977a1b85 100644 --- a/diff-helper.c +++ b/diff-helper.c @@ -121,7 +121,7 @@ int main(int ac, const char **av) { if (status) { unrecognized: diff_flush(diff_output_style); - printf("%s%c", sb1.buf, line_termination); + printf("%s\n", sb1.buf); } } if (detect_rename) diff --git a/diff-tree.c b/diff-tree.c index 0fd28f128..2ec0d6fa8 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -277,7 +277,18 @@ static int call_diff_flush(void) if (nr_paths) diffcore_pathspec(paths); if (header) { - printf("%s", header); + if (diff_output_format == DIFF_FORMAT_MACHINE) { + const char *ep, *cp; + for (cp = header; *cp; cp = ep) { + ep = strchr(cp, '\n'); + if (ep == 0) ep = cp + strlen(cp); + printf("%.*s%c", ep-cp, cp, 0); + if (*ep) ep++; + } + } + else { + printf("%s", header); + } header = NULL; } diff_flush(diff_output_format);