[PATCH] NUL terminate diff-tree header lines under -z.
[git.git] / diff-tree.c
index 0b629d2..2ec0d6f 100644 (file)
@@ -262,7 +262,7 @@ static void call_diff_setup(void)
        diff_setup(reverse_diff);
 }
 
-static int call_diff_flush()
+static int call_diff_flush(void)
 {
        if (detect_rename)
                diffcore_rename(detect_rename, diff_score_opt);
@@ -277,7 +277,18 @@ static int call_diff_flush()
        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);