Skip to content

Commit 1117915

Browse files
tanayabhgitster
authored andcommitted
alias.c: replace git_config() with git_config_get_string()
Use `git_config_get_string()` instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow. Signed-off-by: Tanay Abhra <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef7e1d0 commit 1117915

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

alias.c

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
#include "cache.h"
22

3-
static const char *alias_key;
4-
static char *alias_val;
5-
6-
static int alias_lookup_cb(const char *k, const char *v, void *cb)
7-
{
8-
const char *name;
9-
if (skip_prefix(k, "alias.", &name) && !strcmp(name, alias_key)) {
10-
if (!v)
11-
return config_error_nonbool(k);
12-
alias_val = xstrdup(v);
13-
return 0;
14-
}
15-
return 0;
16-
}
17-
183
char *alias_lookup(const char *alias)
194
{
20-
alias_key = alias;
21-
alias_val = NULL;
22-
git_config(alias_lookup_cb, NULL);
23-
return alias_val;
5+
char *v = NULL;
6+
struct strbuf key = STRBUF_INIT;
7+
strbuf_addf(&key, "alias.%s", alias);
8+
git_config_get_string(key.buf, &v);
9+
strbuf_release(&key);
10+
return v;
2411
}
2512

2613
#define SPLIT_CMDLINE_BAD_ENDING 1

0 commit comments

Comments
 (0)