+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "autocorrect.h"
#include "config.h"
return AUTOCORRECT_DELAY;
}
-void autocorrect_resolve_config(const char *var, const char *value,
- const struct config_context *ctx, void *data)
+static int resolve_autocorrect(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
struct autocorrect *conf = data;
if (strcmp(var, "help.autocorrect"))
- return;
+ return 0;
conf->mode = parse_autocorrect(value);
else if (conf->delay < 0 || conf->delay == 1)
conf->mode = AUTOCORRECT_IMMEDIATELY;
}
+
+ return 0;
+}
+
+void autocorrect_resolve(struct autocorrect *conf)
+{
+ read_early_config(the_repository, resolve_autocorrect, conf);
}
void autocorrect_confirm(struct autocorrect *conf, const char *assumed)
return 0;
}
-struct help_unknown_cmd_config {
- struct autocorrect autocorrect;
- struct cmdnames aliases;
-};
-
-static int git_unknown_cmd_config(const char *var, const char *value,
- const struct config_context *ctx,
- void *cb)
+static int resolve_aliases(const char *var, const char *value UNUSED,
+ const struct config_context *ctx UNUSED, void *data)
{
- struct help_unknown_cmd_config *cfg = cb;
+ struct cmdnames *aliases = data;
const char *subsection, *key;
size_t subsection_len;
- autocorrect_resolve_config(var, value, ctx, &cfg->autocorrect);
-
- /* Also use aliases for command lookup */
if (!parse_config_key(var, "alias", &subsection, &subsection_len,
&key)) {
if (subsection) {
/* [alias "name"] command = value */
if (!strcmp(key, "command"))
- add_cmdname(&cfg->aliases, subsection,
+ add_cmdname(aliases, subsection,
subsection_len);
} else {
/* alias.name = value */
- add_cmdname(&cfg->aliases, key, strlen(key));
+ add_cmdname(aliases, key, strlen(key));
}
}
char *help_unknown_cmd(const char *cmd)
{
- struct help_unknown_cmd_config cfg = { 0 };
+ struct cmdnames aliases = { 0 };
+ struct autocorrect autocorrect = { 0 };
int i, n, best_similarity = 0;
struct cmdnames main_cmds = { 0 };
struct cmdnames other_cmds = { 0 };
struct cmdname_help *common_cmds;
- read_early_config(the_repository, git_unknown_cmd_config, &cfg);
+ autocorrect_resolve(&autocorrect);
- if (cfg.autocorrect.mode == AUTOCORRECT_NEVER) {
+ if (autocorrect.mode == 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, &cfg.aliases);
+ /* Also use aliases for command lookup */
+ read_early_config(the_repository, resolve_aliases, &aliases);
+
+ add_cmd_list(&main_cmds, &aliases);
add_cmd_list(&main_cmds, &other_cmds);
QSORT(main_cmds.names, main_cmds.cnt, cmdname_compare);
uniq(&main_cmds);
; /* still counting */
}
- if (cfg.autocorrect.mode != AUTOCORRECT_HINT && n == 1 &&
+ if (autocorrect.mode != AUTOCORRECT_HINT && 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."),
+ _("WARNING: You called a Git command named '%s', which does not exist."),
cmd);
- autocorrect_confirm(&cfg.autocorrect, assumed);
+ autocorrect_confirm(&autocorrect, assumed);
- cmdnames_release(&cfg.aliases);
+ cmdnames_release(&aliases);
cmdnames_release(&main_cmds);
cmdnames_release(&other_cmds);
return assumed;