@matheusbsbs / matheus-bagliano / commits / 94351118c0
Fork 0

make alias lookup a public, procedural function

This converts git_config_alias to the public alias_lookup function. Because of the nature of our config parser, we still have to rely on setting static data. However, that interface is wrapped so that you can just say value = alias_lookup(key); Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 24, 2008 at 17:17 UTC 94351118c0a820002b093598e7fac5bdf3c0291f
4 files changed +29 -15
Makefile
+2 -1
@@ -327,7 +327,8 @@ LIB_OBJS = \
327 alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
328 color.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \
329 convert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \
330 - transport.o bundle.o walker.o parse-options.o ws.o archive.o
330 + transport.o bundle.o walker.o parse-options.o ws.o archive.o \
331 + alias.o
332
333 BUILTIN_OBJS = \
334 builtin-add.o \
alias.c new
+22
@@ -0,0 +1,22 @@
1 +#include "cache.h"
2 +
3 +static const char *alias_key;
4 +static char *alias_val;
5 +static int alias_lookup_cb(const char *k, const char *v)
6 +{
7 + if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
8 + if (!v)
9 + return config_error_nonbool(k);
10 + alias_val = xstrdup(v);
11 + return 0;
12 + }
13 + return 0;
14 +}
15 +
16 +char *alias_lookup(const char *alias)
17 +{
18 + alias_key = alias;
19 + alias_val = NULL;
20 + git_config(alias_lookup_cb);
21 + return alias_val;
22 +}
cache.h
+2
@@ -765,4 +765,6 @@ int pathspec_match(const char **spec, char *matched, const char *filename, int s
765 int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
766 void overlay_tree_on_cache(const char *tree_name, const char *prefix);
767
768 +char *alias_lookup(const char *alias);
769 +
770 #endif /* CACHE_H */
git.c
+3 -14
@@ -87,19 +87,6 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
87 return handled;
88 }
89
90 -static const char *alias_command;
91 -static char *alias_string;
92 -
93 -static int git_alias_config(const char *var, const char *value)
94 -{
95 - if (!prefixcmp(var, "alias.") && !strcmp(var + 6, alias_command)) {
96 - if (!value)
97 - return config_error_nonbool(var);
98 - alias_string = xstrdup(value);
99 - }
100 - return 0;
101 -}
102 -
90 static int split_cmdline(char *cmdline, const char ***argv)
91 {
92 int src, dst, count = 0, size = 16;
@@ -159,11 +146,13 @@ static int handle_alias(int *argcp, const char ***argv)
146 const char *subdir;
147 int count, option_count;
148 const char** new_argv;
149 + const char *alias_command;
150 + char *alias_string;
151
152 subdir = setup_git_directory_gently(&nongit);
153
154 alias_command = (*argv)[0];
166 - git_config(git_alias_config);
155 + alias_string = alias_lookup(alias_command);
156 if (alias_string) {
157 if (alias_string[0] == '!') {
158 if (*argcp > 1) {