Skip to content

Commit a557189

Browse files
committed
Merge 'fix-is-exe' into HEAD
2 parents 2dcd147 + 7d7aedb commit a557189

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

help.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,31 @@ static int is_executable(const char *name)
105105
return 0;
106106

107107
#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+
*/
109124
char buf[3] = { 0 };
110125
int n;
111126
int fd = open(name, O_RDONLY);
112127
st.st_mode &= ~S_IXUSR;
113128
if (fd >= 0) {
114129
n = read(fd, buf, 2);
115130
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, "#!"))
118133
st.st_mode |= S_IXUSR;
119134
close(fd);
120135
}

0 commit comments

Comments
 (0)