]> git.ipfire.org Git - thirdparty/git.git/blobdiff - help.c
Merge branches 'bw/ls-files-sans-the-index' and 'bw/config-h' into bw/repo-object
[thirdparty/git.git] / help.c
diff --git a/help.c b/help.c
index b8f3a98e4cbe09dd903dfb86653938c1d7604e3d..8ba0777410bd6377a1325622f7d73a53a0aa5a60 100644 (file)
--- a/help.c
+++ b/help.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
+#include "run-command.h"
 #include "levenshtein.h"
 #include "help.h"
 #include "common-cmds.h"
@@ -9,6 +10,7 @@
 #include "column.h"
 #include "version.h"
 #include "refs.h"
+#include "parse-options.h"
 
 void add_cmdname(struct cmdnames *cmds, const char *name, int len)
 {
@@ -97,48 +99,6 @@ static void pretty_print_cmdnames(struct cmdnames *cmds, unsigned int colopts)
        string_list_clear(&list, 0);
 }
 
-static int is_executable(const char *name)
-{
-       struct stat st;
-
-       if (stat(name, &st) || /* stat, not lstat */
-           !S_ISREG(st.st_mode))
-               return 0;
-
-#if defined(GIT_WINDOWS_NATIVE)
-       /*
-        * 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);
-       st.st_mode &= ~S_IXUSR;
-       if (fd >= 0) {
-               n = read(fd, buf, 2);
-               if (n == 2)
-                       /* look for a she-bang */
-                       if (!strcmp(buf, "#!"))
-                               st.st_mode |= S_IXUSR;
-               close(fd);
-       }
-}
-#endif
-       return st.st_mode & S_IXUSR;
-}
-
 static void list_commands_in_dir(struct cmdnames *cmds,
                                         const char *path,
                                         const char *prefix)
@@ -412,8 +372,8 @@ const char *help_unknown_cmd(const char *cmd)
 
        if (SIMILAR_ENOUGH(best_similarity)) {
                fprintf_ln(stderr,
-                          Q_("\nDid you mean this?",
-                             "\nDid you mean one of these?",
+                          Q_("\nThe most similar command is",
+                             "\nThe most similar commands are",
                           n));
 
                for (i = 0; i < n; i++)
@@ -425,16 +385,30 @@ const char *help_unknown_cmd(const char *cmd)
 
 int cmd_version(int argc, const char **argv, const char *prefix)
 {
+       int build_options = 0;
+       const char * const usage[] = {
+               N_("git version [<options>]"),
+               NULL
+       };
+       struct option options[] = {
+               OPT_BOOL(0, "build-options", &build_options,
+                        "also print build options"),
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
+
        /*
         * The format of this string should be kept stable for compatibility
         * with external projects that rely on the output of "git version".
+        *
+        * Always show the version, even if other options are given.
         */
        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? */
-               }
+
+       if (build_options) {
+               printf("sizeof-long: %d\n", (int)sizeof(long));
+               /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
        }
        return 0;
 }