File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -105,16 +105,31 @@ static int is_executable(const char *name)
105
105
return 0 ;
106
106
107
107
#if defined(GIT_WINDOWS_NATIVE )
108
- { /* cannot trust the executable bit, peek into the file instead */
108
+ /*
109
+ * On Windows there is no executable bit. The file extension
110
+ * indicates whether it can be run as an executable, and Git
111
+ * has special-handling to detect scripts and launch them
112
+ * through the indicated script interpreter. We test for the
113
+ * file extension first because virus scanners may make
114
+ * opening an executable for reading expensive.
115
+ */
116
+ if (ends_with (name , ".exe" ))
117
+ return S_IXUSR ;
118
+
119
+ {
120
+ /*
121
+ * Now that we know it does not have an executable extension,
122
+ * peek into the file instead.
123
+ */
109
124
char buf [3 ] = { 0 };
110
125
int n ;
111
126
int fd = open (name , O_RDONLY );
112
127
st .st_mode &= ~S_IXUSR ;
113
128
if (fd >= 0 ) {
114
129
n = read (fd , buf , 2 );
115
130
if (n == 2 )
116
- /* DOS executables start with "MZ" */
117
- if (!strcmp (buf , "#!" ) || ! strcmp ( buf , "MZ" ) )
131
+ /* look for a she-bang */
132
+ if (!strcmp (buf , "#!" ))
118
133
st .st_mode |= S_IXUSR ;
119
134
close (fd );
120
135
}
You can’t perform that action at this time.
0 commit comments