summaryrefslogtreecommitdiff
path: root/alias.c
diff options
context:
space:
mode:
Diffstat (limited to 'alias.c')
-rw-r--r--alias.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/alias.c b/alias.c
index 3b90397a99..39f622e414 100644
--- a/alias.c
+++ b/alias.c
@@ -1,14 +1,29 @@
#include "cache.h"
+#include "config.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
@@ -47,8 +62,7 @@ int split_cmdline(char *cmdline, const char ***argv)
src++;
c = cmdline[src];
if (!c) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_BAD_ENDING;
}
}
@@ -60,8 +74,7 @@ int split_cmdline(char *cmdline, const char ***argv)
cmdline[dst] = 0;
if (quoted) {
- free(*argv);
- *argv = NULL;
+ FREE_AND_NULL(*argv);
return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
}