Re: [PATCH v3 1/6] alias.c: replace `git_config()` with `git_config_get_string()`
Ramsay Jones writes: > On 21/07/14 12:12, Tanay Abhra wrote: >> -char *alias_lookup(const char *alias) >> +char *alias_lookup(const char* alias) > > No, this is not C++. :-D Why would C++ make a difference? Shouldn't you *never* do that? -- Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread! -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 1/6] alias.c: replace `git_config()` with `git_config_get_string()`
On 21/07/14 12:12, Tanay Abhra wrote: > Use `git_config_get_string()` instead of `git_config()` to take advantage of > the config-set API which provides a cleaner control flow. > The function now raises an error instead of dying when a NULL value is found. > > Signed-off-by: Tanay Abhra > --- > alias.c | 27 +++ > 1 file changed, 7 insertions(+), 20 deletions(-) > > diff --git a/alias.c b/alias.c > index 758c867..a453bd8 100644 > --- a/alias.c > +++ b/alias.c > @@ -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) > +char *alias_lookup(const char* alias) No, this is not C++. :-D > { > - alias_key = alias; > - alias_val = NULL; > - git_config(alias_lookup_cb, NULL); > - return alias_val; > + const 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 (char*)v; > } > > #define SPLIT_CMDLINE_BAD_ENDING 1 > -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 1/6] alias.c: replace `git_config()` with `git_config_get_string()`
Tanay Abhra writes: > --- a/alias.c > +++ b/alias.c > @@ -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) > +char *alias_lookup(const char* alias) Style: keep the * stuck to alias. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 1/6] 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. The function now raises an error instead of dying when a NULL value is found. Signed-off-by: Tanay Abhra --- alias.c | 27 +++ 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/alias.c b/alias.c index 758c867..a453bd8 100644 --- a/alias.c +++ b/alias.c @@ -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) +char *alias_lookup(const char* alias) { - alias_key = alias; - alias_val = NULL; - git_config(alias_lookup_cb, NULL); - return alias_val; + const 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 (char*)v; } #define SPLIT_CMDLINE_BAD_ENDING 1 -- 1.9.0.GIT -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html