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

[PATCH 1/3] Update mode-change strings in diff output.

From
Junio C Hamano <junkio@cox.net>
Date
May 14, 2005, 01:40 UTC
Message-ID
<7vhdh660w1.fsf@assigned-by-dhcp.cox.net>

This updates the mode change strings to be a bit more machine friendly. Although this might go against the spirit of readability for human consumption, these mode bits strings are shown only when unusual things (mode change, file creation and deletion) happens, output normalized for machine consumption would be permissible.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

diff.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-)

--- a/diff.c
+++ b/diff.c
@@ -83,6 +83,7 @@
 			 struct diff_tempfile *temp)
 {
 	int i, next_at;
+	const char *git_prefix = "# mode: ";
 	const char *diff_cmd = "diff -L'%s%s' -L'%s%s'";
 	const char *diff_arg  = "'%s' '%s'||:"; /* "||:" is to return 0 */
 	const char *input_name_sq[2];
@@ -123,17 +124,18 @@
 			    diff_arg, input_name_sq[0], input_name_sq[1]);
 
 	if (!path1[0][0])
-		printf("Created: %s (mode:%s)\n", name, temp[1].mode);
+		printf("%s. %s %s\n", git_prefix, temp[1].mode, name);
 	else if (!path1[1][0])
-		printf("Deleted: %s\n", name);
-	else if (strcmp(temp[0].mode, temp[1].mode)) {
-		printf("Mode changed: %s (%s->%s)\n", name,
-		       temp[0].mode, temp[1].mode);
-		/* Be careful.  We do not want to diff between
-		 * symlink and a file.
-		 */
-		if (strncmp(temp[0].mode, "120", 3) !=
-		    strncmp(temp[1].mode, "120", 3))
+		printf("%s%s . %s\n", git_prefix, temp[0].mode, name);
+	else {
+		if (strcmp(temp[0].mode, temp[1].mode))
+			printf("%s%s %s %s\n", git_prefix,
+			       temp[0].mode, temp[1].mode, name);
+
+		if (strncmp(temp[0].mode, temp[1].mode, 3))
+			/* we do not run diff between different kind
+			 * of objects.
+			 */
 			exit(0);
 	}
 	fflush(NULL);
Message 1 of 1 in “Update mode-change strings in diff output.”
  1. 1/3 Update mode-change strings in diff output.Junio C Hamano, May 14, 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.