X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=alias.c;h=c4715380205b5f8dd032b16ade846842fa3c23b9;hb=a78305ffbca58e49a7cdad901df0ae779bbed8fb;hp=3b90397a99d9f7ed4a0c1c5a83f5e69c879e752f;hpb=d834fa901eea94428ea656a6127f303bc95fb73f;p=platform%2Fupstream%2Fgit.git diff --git a/alias.c b/alias.c index 3b90397..c471538 100644 --- a/alias.c +++ b/alias.c @@ -1,21 +1,54 @@ #include "cache.h" +#include "alias.h" +#include "config.h" +#include "string-list.h" + +struct config_alias_data { + const char *alias; + char *v; + struct string_list *list; +}; + +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)) + return 0; + + if (data->alias) { + if (!strcasecmp(p, data->alias)) + return git_config_string((const char **)&data->v, + key, value); + } else if (data->list) { + string_list_append(data->list, p); + } + + 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; +} + +void list_aliases(struct string_list *list) +{ + struct config_alias_data data = { NULL, NULL, list }; + + read_early_config(config_alias_cb, &data); } #define SPLIT_CMDLINE_BAD_ENDING 1 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 static const char *split_cmdline_errors[] = { - "cmdline ends with \\", - "unclosed quote" + N_("cmdline ends with \\"), + N_("unclosed quote") }; int split_cmdline(char *cmdline, const char ***argv) @@ -47,8 +80,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 +92,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; }