Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-06-14 14:36:00 +0300
committerJunio C Hamano <gitster@pobox.com>2017-06-15 22:31:50 +0300
commita9bcf6586d1a4888aea91553d73cda20494b8335 (patch)
treeda27bd4c2204d171c8752abddb467447eac86cfb /alias.c
parent3f9c5dfb7118256747de5efbaa4b5cd3f0e02331 (diff)
alias: use the early config machinery to expand aliases
Instead of discovering the .git/ directory, reading the config and then trying to painstakingly reset all the global state if we did not find a matching alias, let's use the early config machinery instead. It may look like unnecessary work to discover the .git/ directory in the early config machinery and then call setup_git_directory_gently() in the case of a shell alias, repeating the very same discovery *again*. However, we have to do this as the early config machinery takes pains *not* to touch any global state, while shell aliases expect a possibly changed working directory and at least the GIT_PREFIX and GIT_DIR variables to be set. This change also fixes a known issue where Git tried to read the pager config from an incorrect path in a subdirectory of a Git worktree if an alias expanded to a shell command. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'alias.c')
-rw-r--r--alias.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/alias.c b/alias.c
index 3b90397a99..0526304661 100644
--- a/alias.c
+++ b/alias.c
@@ -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