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

[PATCH 5/5] use mode of the tree in git-diff, if <tree>:<file> syntax is used

From
MKMartin Koegler <mkoegler@auto.tuwien.ac.at>
Date
Apr 22, 2007, 16:44 UTC
Message-ID
<11772602403236-git-send-email-mkoegler@auto.tuwien.ac.at>
In-Reply-To
<11772602401214-git-send-email-mkoegler@auto.tuwien.ac.at>
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
 builtin-diff.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/builtin-diff.c b/builtin-diff.c
index 21d13f0..f7fb914 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -13,13 +13,10 @@
 #include "log-tree.h"
 #include "builtin.h"
 
-/* NEEDSWORK: struct object has place for name but we _do_
- * know mode when we extracted the blob out of a tree, which
- * we currently lose.
- */
 struct blobinfo {
 	unsigned char sha1[20];
 	const char *name;
+	unsigned mode;
 };
 
 static const char builtin_diff_usage[] =
@@ -70,8 +67,12 @@ static int builtin_diff_b_f(struct rev_info *revs,
 		die("'%s': %s", path, strerror(errno));
 	if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
 		die("'%s': not a regular file or symlink", path);
+
+	if (blob[0].mode == S_IFINVALID)
+		blob[0].mode = canon_mode(st.st_mode);
+
 	stuff_change(&revs->diffopt,
-		     canon_mode(st.st_mode), canon_mode(st.st_mode),
+		     blob[0].mode, canon_mode(st.st_mode),
 		     blob[0].sha1, null_sha1,
 		     path, path);
 	diffcore_std(&revs->diffopt);
@@ -88,8 +89,14 @@ static int builtin_diff_blobs(struct rev_info *revs,
 	if (argc > 1)
 		usage(builtin_diff_usage);
 
+	if (blob[0].mode == S_IFINVALID)
+		blob[0].mode = mode;
+
+	if (blob[1].mode == S_IFINVALID)
+		blob[1].mode = mode;
+
 	stuff_change(&revs->diffopt,
-		     mode, mode,
+		     blob[0].mode, blob[1].mode,
 		     blob[0].sha1, blob[1].sha1,
 		     blob[0].name, blob[1].name);
 	diffcore_std(&revs->diffopt);
@@ -271,6 +278,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 				die("more than two blobs given: '%s'", name);
 			hashcpy(blob[blobs].sha1, obj->sha1);
 			blob[blobs].name = name;
+			blob[blobs].mode = list->mode;
 			blobs++;
 			continue;
 
-- 
1.5.1.1.206.g4a12-dirty
Previous: Martin KoeglerNext: Junio C Hamano
Message 5 of 7 in “Add S_IFINVALID mode”
  1. 1/5 Add S_IFINVALID modeMartin Koegler, Apr 22, 2007
  2. 2/5 add get_sha1_with_modeMartin Koegler, Apr 22, 2007
  3. 3/5 add add_object_array_with_modeMartin Koegler, Apr 22, 2007
  4. 4/5 store mode in rev_list, if <tree>:<filename> syntax is usedMartin Koegler, Apr 22, 2007
  5. 5/5 use mode of the tree in git-diff, if <tree>:<file> syntax is usedMartin Koegler, Apr 22, 2007
  6. Junio C HamanoApr 23, 2007
  7. Junio C HamanoApr 22, 2007

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.