summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
Diffstat (limited to 'help.c')
-rw-r--r--help.c102
1 files changed, 66 insertions, 36 deletions
diff --git a/help.c b/help.c
index 4ad4ebdd2c..c54bd9918a 100644
--- a/help.c
+++ b/help.c
@@ -1,6 +1,8 @@
#define USE_THE_REPOSITORY_VARIABLE
+#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
+#include "git-zlib.h"
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
@@ -546,37 +548,61 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
return 0;
}
-static int autocorrect;
-static struct cmdnames aliases;
+struct help_unknown_cmd_config {
+ int autocorrect;
+ struct cmdnames aliases;
+};
+#define AUTOCORRECT_SHOW (-4)
#define AUTOCORRECT_PROMPT (-3)
#define AUTOCORRECT_NEVER (-2)
#define AUTOCORRECT_IMMEDIATELY (-1)
+static int parse_autocorrect(const char *value)
+{
+ switch (git_parse_maybe_bool_text(value)) {
+ case 1:
+ return AUTOCORRECT_IMMEDIATELY;
+ case 0:
+ return AUTOCORRECT_SHOW;
+ default: /* other random text */
+ break;
+ }
+
+ if (!strcmp(value, "prompt"))
+ return AUTOCORRECT_PROMPT;
+ if (!strcmp(value, "never"))
+ return AUTOCORRECT_NEVER;
+ if (!strcmp(value, "immediate"))
+ return AUTOCORRECT_IMMEDIATELY;
+ if (!strcmp(value, "show"))
+ return AUTOCORRECT_SHOW;
+
+ return 0;
+}
+
static int git_unknown_cmd_config(const char *var, const char *value,
const struct config_context *ctx,
- void *cb UNUSED)
+ void *cb)
{
+ struct help_unknown_cmd_config *cfg = cb;
const char *p;
if (!strcmp(var, "help.autocorrect")) {
- if (!value)
- return config_error_nonbool(var);
- if (!strcmp(value, "never")) {
- autocorrect = AUTOCORRECT_NEVER;
- } else if (!strcmp(value, "immediate")) {
- autocorrect = AUTOCORRECT_IMMEDIATELY;
- } else if (!strcmp(value, "prompt")) {
- autocorrect = AUTOCORRECT_PROMPT;
- } else {
- int v = git_config_int(var, value, ctx->kvi);
- autocorrect = (v < 0)
- ? AUTOCORRECT_IMMEDIATELY : v;
+ int v = parse_autocorrect(value);
+
+ if (!v) {
+ v = git_config_int(var, value, ctx->kvi);
+ if (v < 0 || v == 1)
+ v = AUTOCORRECT_IMMEDIATELY;
}
+
+ cfg->autocorrect = v;
}
+
/* Also use aliases for command lookup */
if (skip_prefix(var, "alias.", &p))
- add_cmdname(&aliases, p, strlen(p));
+ add_cmdname(&cfg->aliases, p, strlen(p));
return 0;
}
@@ -609,32 +635,30 @@ static const char bad_interpreter_advice[] =
N_("'%s' appears to be a git command, but we were not\n"
"able to execute it. Maybe git-%s is broken?");
-const char *help_unknown_cmd(const char *cmd)
+char *help_unknown_cmd(const char *cmd)
{
+ struct help_unknown_cmd_config cfg = { 0 };
int i, n, best_similarity = 0;
- struct cmdnames main_cmds, other_cmds;
+ struct cmdnames main_cmds = { 0 };
+ struct cmdnames other_cmds = { 0 };
struct cmdname_help *common_cmds;
- memset(&main_cmds, 0, sizeof(main_cmds));
- memset(&other_cmds, 0, sizeof(other_cmds));
- memset(&aliases, 0, sizeof(aliases));
-
- read_early_config(the_repository, git_unknown_cmd_config, NULL);
+ read_early_config(the_repository, git_unknown_cmd_config, &cfg);
/*
* Disable autocorrection prompt in a non-interactive session
*/
- if ((autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
- autocorrect = AUTOCORRECT_NEVER;
+ if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
+ cfg.autocorrect = AUTOCORRECT_NEVER;
- if (autocorrect == AUTOCORRECT_NEVER) {
+ if (cfg.autocorrect == AUTOCORRECT_NEVER) {
fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
exit(1);
}
load_command_list("git-", &main_cmds, &other_cmds);
- add_cmd_list(&main_cmds, &aliases);
+ add_cmd_list(&main_cmds, &cfg.aliases);
add_cmd_list(&main_cmds, &other_cmds);
QSORT(main_cmds.names, main_cmds.cnt, cmdname_compare);
uniq(&main_cmds);
@@ -693,20 +717,20 @@ const char *help_unknown_cmd(const char *cmd)
n++)
; /* still counting */
}
- if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
- const char *assumed = main_cmds.names[0]->name;
- main_cmds.names[0] = NULL;
- cmdnames_release(&main_cmds);
+ if (cfg.autocorrect && cfg.autocorrect != AUTOCORRECT_SHOW && n == 1 &&
+ SIMILAR_ENOUGH(best_similarity)) {
+ char *assumed = xstrdup(main_cmds.names[0]->name);
+
fprintf_ln(stderr,
_("WARNING: You called a Git command named '%s', "
"which does not exist."),
cmd);
- if (autocorrect == AUTOCORRECT_IMMEDIATELY)
+ if (cfg.autocorrect == AUTOCORRECT_IMMEDIATELY)
fprintf_ln(stderr,
_("Continuing under the assumption that "
"you meant '%s'."),
assumed);
- else if (autocorrect == AUTOCORRECT_PROMPT) {
+ else if (cfg.autocorrect == AUTOCORRECT_PROMPT) {
char *answer;
struct strbuf msg = STRBUF_INIT;
strbuf_addf(&msg, _("Run '%s' instead [y/N]? "), assumed);
@@ -719,9 +743,13 @@ const char *help_unknown_cmd(const char *cmd)
fprintf_ln(stderr,
_("Continuing in %0.1f seconds, "
"assuming that you meant '%s'."),
- (float)autocorrect/10.0, assumed);
- sleep_millisec(autocorrect * 100);
+ (float)cfg.autocorrect/10.0, assumed);
+ sleep_millisec(cfg.autocorrect * 100);
}
+
+ cmdnames_release(&cfg.aliases);
+ cmdnames_release(&main_cmds);
+ cmdnames_release(&other_cmds);
return assumed;
}
@@ -770,7 +798,9 @@ void get_version_info(struct strbuf *buf, int show_build_options)
#if defined OPENSSL_VERSION_TEXT
strbuf_addf(buf, "OpenSSL: %s\n", OPENSSL_VERSION_TEXT);
#endif
-#if defined ZLIB_VERSION
+#if defined ZLIBNG_VERSION
+ strbuf_addf(buf, "zlib-ng: %s\n", ZLIBNG_VERSION);
+#elif defined ZLIB_VERSION
strbuf_addf(buf, "zlib: %s\n", ZLIB_VERSION);
#endif
}