Skip to content

Commit 9d429ff

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] diff: further cleanup.
When preparing data to feed the external diff, we should give the mode we obtained from the caller, even when we are dealing with a file with 0{40} SHA1 (i.e. the caller said "look at the filesystem"), since the mode passed by the caller via diff_addremove() or diff_change() is always trustworthy. This is _not_ a bugfix --- the existing code stat() on the file ifself and does the same computation on st.st_mode to compute the mode the same way the caller did to give the original mode. We cannot remove the stat() call from here, but the extra computation to create the mode value is unnecessary. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 01c4e70 commit 9d429ff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

diff.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,13 @@ static void prepare_temp_file(const char *name,
421421
strcpy(temp->hex, sha1_to_hex(null_sha1));
422422
else
423423
strcpy(temp->hex, sha1_to_hex(one->sha1));
424-
sprintf(temp->mode, "%06o",
425-
S_IFREG |ce_permissions(st.st_mode));
424+
/* Even though we may sometimes borrow the
425+
* contents from the work tree, we always want
426+
* one->mode. mode is trustworthy even when
427+
* !(one->sha1_valid), as long as
428+
* DIFF_FILE_VALID(one).
429+
*/
430+
sprintf(temp->mode, "%06o", one->mode);
426431
}
427432
return;
428433
}

0 commit comments

Comments
 (0)