git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-diff-tree -z HEAD | git-diff-helper -z fails for me

From
Junio C Hamano <junkio@cox.net>
Date
May 23, 2005, 19:07 UTC
Message-ID
<7v7jhp3gms.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vpsvh3hp0.fsf@assigned-by-dhcp.cox.net>
>>>>> "JCH" == Junio C Hamano <junkio@cox.net> writes:
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

LT> How about instead making sure that any "extra" text be NUL-terminated and LT> never start with ':' after a NUL (which will automatically be true, since LT> it's either "diff-tree " + ascii for the verbose case, or just the tree LT> name).

JCH> Makes much more sense although it has certain amount of Yuck JCH> factor ;-).

------------ 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 <junkio@cox.net>
---

*** Against your head, not my head that already has the *** rename/copy fix. *** Only rightly tested with the exact command line Thomas used.

cd /opt/packrat/playpen/public/in-place/git/git.junio/ jit-diff # - linus: Don't care about st_dev in the index file # + (working tree)

diff --git a/diff-helper.c b/diff-helper.c
--- 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
--- 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);
Previous: Junio C HamanoNext: Linus Torvalds
Message 5 of 10 in “git-diff-tree -z HEAD | git-diff-helper -z fails for me”
  1. Thomas GlanzmannMay 23, 2005
  2. Junio C HamanoMay 23, 2005
  3. Linus TorvaldsMay 23, 2005
  4. Junio C HamanoMay 23, 2005
  5. Junio C HamanoMay 23, 2005
  6. Linus TorvaldsMay 23, 2005
  7. Junio C HamanoMay 24, 2005
  8. Fix diff-pruning logic which was running prune too early.Junio C Hamano, May 24, 2005
  9. interim report on a big screwup with diff -M and -C.Junio C Hamano, May 24, 2005
  10. Redo rename/copy detection logic.Junio C Hamano, May 24, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.