fetch-pack: always allow fetching of literal SHA1s
[gitweb.git] / help.c
diff --git a/help.c b/help.c
index d996b340669a66d0b1619472fedf5c11b940d7c5..bc6cd19cf3a5e4300e32cbdd437b2d9231fd2d89 100644 (file)
--- a/help.c
+++ b/help.c
 
 void add_cmdname(struct cmdnames *cmds, const char *name, int len)
 {
-       struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1);
-
+       struct cmdname *ent;
+       FLEX_ALLOC_MEM(ent, name, name, len);
        ent->len = len;
-       memcpy(ent->name, name, len);
-       ent->name[len] = 0;
 
        ALLOC_GROW(cmds->names, cmds->cnt + 1, cmds->alloc);
        cmds->names[cmds->cnt++] = ent;
@@ -107,7 +105,22 @@ static int is_executable(const char *name)
                return 0;
 
 #if defined(GIT_WINDOWS_NATIVE)
-{      /* cannot trust the executable bit, peek into the file instead */
+       /*
+        * On Windows there is no executable bit. The file extension
+        * indicates whether it can be run as an executable, and Git
+        * has special-handling to detect scripts and launch them
+        * through the indicated script interpreter. We test for the
+        * file extension first because virus scanners may make
+        * it quite expensive to open many files.
+        */
+       if (ends_with(name, ".exe"))
+               return S_IXUSR;
+
+{
+       /*
+        * Now that we know it does not have an executable extension,
+        * peek into the file instead.
+        */
        char buf[3] = { 0 };
        int n;
        int fd = open(name, O_RDONLY);
@@ -115,8 +128,8 @@ static int is_executable(const char *name)
        if (fd >= 0) {
                n = read(fd, buf, 2);
                if (n == 2)
-                       /* DOS executables start with "MZ" */
-                       if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+                       /* look for a she-bang */
+                       if (!strcmp(buf, "#!"))
                                st.st_mode |= S_IXUSR;
                close(fd);
        }
@@ -172,8 +185,7 @@ void load_command_list(const char *prefix,
 
        if (exec_path) {
                list_commands_in_dir(main_cmds, exec_path, prefix);
-               qsort(main_cmds->names, main_cmds->cnt,
-                     sizeof(*main_cmds->names), cmdname_compare);
+               QSORT(main_cmds->names, main_cmds->cnt, cmdname_compare);
                uniq(main_cmds);
        }
 
@@ -192,8 +204,7 @@ void load_command_list(const char *prefix,
                }
                free(paths);
 
-               qsort(other_cmds->names, other_cmds->cnt,
-                     sizeof(*other_cmds->names), cmdname_compare);
+               QSORT(other_cmds->names, other_cmds->cnt, cmdname_compare);
                uniq(other_cmds);
        }
        exclude_cmds(other_cmds, main_cmds);
@@ -240,8 +251,7 @@ void list_common_cmds_help(void)
                        longest = strlen(common_cmds[i].name);
        }
 
-       qsort(common_cmds, ARRAY_SIZE(common_cmds),
-               sizeof(common_cmds[0]), cmd_group_cmp);
+       QSORT(common_cmds, ARRAY_SIZE(common_cmds), cmd_group_cmp);
 
        puts(_("These are common Git commands used in various situations:"));
 
@@ -326,8 +336,7 @@ const char *help_unknown_cmd(const char *cmd)
 
        add_cmd_list(&main_cmds, &aliases);
        add_cmd_list(&main_cmds, &other_cmds);
-       qsort(main_cmds.names, main_cmds.cnt,
-             sizeof(*main_cmds.names), cmdname_compare);
+       QSORT(main_cmds.names, main_cmds.cnt, cmdname_compare);
        uniq(&main_cmds);
 
        /* This abuses cmdname->len for levenshtein distance */
@@ -361,8 +370,7 @@ const char *help_unknown_cmd(const char *cmd)
                        levenshtein(cmd, candidate, 0, 2, 1, 3) + 1;
        }
 
-       qsort(main_cmds.names, main_cmds.cnt,
-             sizeof(*main_cmds.names), levenshtein_compare);
+       QSORT(main_cmds.names, main_cmds.cnt, levenshtein_compare);
 
        if (!main_cmds.cnt)
                die(_("Uh oh. Your system reports no Git commands at all."));
@@ -421,6 +429,12 @@ int cmd_version(int argc, const char **argv, const char *prefix)
         * with external projects that rely on the output of "git version".
         */
        printf("git version %s\n", git_version_string);
+       while (*++argv) {
+               if (!strcmp(*argv, "--build-options")) {
+                       printf("sizeof-long: %d\n", (int)sizeof(long));
+                       /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
+               }
+       }
        return 0;
 }