branch.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. While we are at it, return -1 if we find no value for the queried variable. Original code returned 0 for all cases, which was checked by `add_branch_desc()` in fmt-merge-msg.c resulting in addition of a spurious newline to the `out` strbuf. Now, the newline addition is skipped as -1 is returned to the caller if no value is found. 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>
This commit is contained in:
parent
111791559e
commit
540b0f4977
27
branch.c
27
branch.c
@ -140,30 +140,17 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct branch_desc_cb {
|
|
||||||
const char *config_name;
|
|
||||||
const char *value;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int read_branch_desc_cb(const char *var, const char *value, void *cb)
|
|
||||||
{
|
|
||||||
struct branch_desc_cb *desc = cb;
|
|
||||||
if (strcmp(desc->config_name, var))
|
|
||||||
return 0;
|
|
||||||
free((char *)desc->value);
|
|
||||||
return git_config_string(&desc->value, var, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_branch_desc(struct strbuf *buf, const char *branch_name)
|
int read_branch_desc(struct strbuf *buf, const char *branch_name)
|
||||||
{
|
{
|
||||||
struct branch_desc_cb cb;
|
char *v = NULL;
|
||||||
struct strbuf name = STRBUF_INIT;
|
struct strbuf name = STRBUF_INIT;
|
||||||
strbuf_addf(&name, "branch.%s.description", branch_name);
|
strbuf_addf(&name, "branch.%s.description", branch_name);
|
||||||
cb.config_name = name.buf;
|
if (git_config_get_string(name.buf, &v)) {
|
||||||
cb.value = NULL;
|
strbuf_release(&name);
|
||||||
git_config(read_branch_desc_cb, &cb);
|
return -1;
|
||||||
if (cb.value)
|
}
|
||||||
strbuf_addstr(buf, cb.value);
|
strbuf_addstr(buf, v);
|
||||||
|
free(v);
|
||||||
strbuf_release(&name);
|
strbuf_release(&name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user