Merge branch 'mb/reword-autocomplete-message'
authorJunio C Hamano <gitster@pobox.com>
Mon, 26 Jun 2017 21:09:33 +0000 (14:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Jun 2017 21:09:33 +0000 (14:09 -0700)
Message update.

* mb/reword-autocomplete-message:
auto-correct: tweak phrasing

1  2 
help.c
diff --combined help.c
index 07b185389decdda8e8cc10a2cd18ece81d0eaf94,2a8ae9758db3a3dfe2d150089017eab972e5fb59..88a3aeaeb9f0b3983c9cd035fd371133506a54ec
--- 1/help.c
--- 2/help.c
+++ b/help.c
@@@ -1,8 -1,6 +1,8 @@@
  #include "cache.h"
 +#include "config.h"
  #include "builtin.h"
  #include "exec_cmd.h"
 +#include "run-command.h"
  #include "levenshtein.h"
  #include "help.h"
  #include "common-cmds.h"
@@@ -10,7 -8,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)
  {
@@@ -99,6 -96,33 +99,6 @@@ static void pretty_print_cmdnames(struc
        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)
 -{     /* cannot trust the executable bit, 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)
 -                      /* DOS executables start with "MZ" */
 -                      if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
 -                              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)
@@@ -146,7 -170,8 +146,7 @@@ void load_command_list(const char *pref
  
        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);
        }
  
                }
                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);
@@@ -212,7 -238,8 +212,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:"));
  
@@@ -269,8 -296,9 +269,8 @@@ static void add_cmd_list(struct cmdname
  
        for (i = 0; i < old->cnt; i++)
                cmds->names[cmds->cnt++] = old->names[i];
 -      free(old->names);
 +      FREE_AND_NULL(old->names);
        old->cnt = 0;
 -      old->names = NULL;
  }
  
  /* An empirically derived magic number */
@@@ -290,13 -318,14 +290,13 @@@ const char *help_unknown_cmd(const cha
        memset(&other_cmds, 0, sizeof(other_cmds));
        memset(&aliases, 0, sizeof(aliases));
  
 -      git_config(git_unknown_cmd_config, NULL);
 +      read_early_config(git_unknown_cmd_config, NULL);
  
        load_command_list("git-", &main_cmds, &other_cmds);
  
        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 */
                        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."));
                clean_cmdnames(&main_cmds);
                fprintf_ln(stderr,
                           _("WARNING: You called a Git command named '%s', "
-                            "which does not exist.\n"
-                            "Continuing under the assumption that you meant '%s'"),
-                       cmd, assumed);
-               if (autocorrect > 0) {
-                       fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
-                               (float)autocorrect/10.0);
+                            "which does not exist."),
+                          cmd);
+               if (autocorrect < 0)
+                       fprintf_ln(stderr,
+                                  _("Continuing under the assumption that "
+                                    "you meant '%s'."),
+                                  assumed);
+               else {
+                       fprintf_ln(stderr,
+                                  _("Continuing in %0.1f seconds, "
+                                    "assuming that you meant '%s'."),
+                                  (float)autocorrect/10.0, assumed);
                        sleep_millisec(autocorrect * 100);
                }
                return assumed;
  
        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++)
  
  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;
  }