diff options
| author | Junio C Hamano <gitster@pobox.com> | 2017-06-24 14:28:39 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2017-06-24 14:28:40 -0700 |
| commit | 1c3d87cf5594cc7e57d71c7b2d99dd4982285951 (patch) | |
| tree | 9a461af87a2e6c7191cd158093b37f0eea6f0c2a /alias.c | |
| parent | 9bca0e5513579386384c064c5cdc45980b6774df (diff) | |
| parent | a9bcf6586d1a4888aea91553d73cda20494b8335 (diff) | |
| download | git-1c3d87cf5594cc7e57d71c7b2d99dd4982285951.tar.gz | |
Merge branch 'js/alias-early-config'
The code to pick up and execute command alias definition from the
configuration used to switch to the top of the working tree and
then come back when the expanded alias was executed, which was
unnecessarilyl complex. Attempt to simplify the logic by using the
early-config mechanism that does not chdir around.
* js/alias-early-config:
alias: use the early config machinery to expand aliases
t7006: demonstrate a problem with aliases in subdirectories
t1308: relax the test verifying that empty alias values are disallowed
help: use early config when autocorrecting aliases
config: report correct line number upon error
discover_git_directory(): avoid setting invalid git_dir
Diffstat (limited to 'alias.c')
| -rw-r--r-- | alias.c | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -1,14 +1,28 @@ #include "cache.h" +struct config_alias_data { + const char *alias; + char *v; +}; + +static int config_alias_cb(const char *key, const char *value, void *d) +{ + struct config_alias_data *data = d; + const char *p; + + if (skip_prefix(key, "alias.", &p) && !strcmp(p, data->alias)) + return git_config_string((const char **)&data->v, key, value); + + return 0; +} + char *alias_lookup(const char *alias) { - char *v = NULL; - struct strbuf key = STRBUF_INIT; - strbuf_addf(&key, "alias.%s", alias); - if (git_config_key_is_valid(key.buf)) - git_config_get_string(key.buf, &v); - strbuf_release(&key); - return v; + struct config_alias_data data = { alias, NULL }; + + read_early_config(config_alias_cb, &data); + + return data.v; } #define SPLIT_CMDLINE_BAD_ENDING 1 |
