Skip to content

Commit

Permalink
alias.c: replace git_config() with git_config_get_string()
Browse files Browse the repository at this point in the history
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 <tanayabh@gmail.com>
Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Tanay Abhra authored and Junio C Hamano committed Aug 7, 2014
1 parent ef7e1d0 commit 1117915
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions alias.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
#include "cache.h"

static const char *alias_key;
static char *alias_val;

static int alias_lookup_cb(const char *k, const char *v, void *cb)
{
const char *name;
if (skip_prefix(k, "alias.", &name) && !strcmp(name, alias_key)) {
if (!v)
return config_error_nonbool(k);
alias_val = xstrdup(v);
return 0;
}
return 0;
}

char *alias_lookup(const char *alias)
{
alias_key = alias;
alias_val = NULL;
git_config(alias_lookup_cb, NULL);
return alias_val;
char *v = NULL;
struct strbuf key = STRBUF_INIT;
strbuf_addf(&key, "alias.%s", alias);
git_config_get_string(key.buf, &v);
strbuf_release(&key);
return v;
}

#define SPLIT_CMDLINE_BAD_ENDING 1
Expand Down

0 comments on commit 1117915

Please sign in to comment.