Skip to content

Commit 6f9a332

Browse files
committed
branch: add read_branch_desc() helper function
This will be used by various callers that make use of the branch description throughout the system, so that if we need to update the implementation the callers do not have to be modified. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3bcad5a commit 6f9a332

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

branch.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,37 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
135135
return 0;
136136
}
137137

138+
struct branch_desc_cb {
139+
const char *config_name;
140+
const char *value;
141+
};
142+
143+
static int read_branch_desc_cb(const char *var, const char *value, void *cb)
144+
{
145+
struct branch_desc_cb *desc = cb;
146+
if (strcmp(desc->config_name, var))
147+
return 0;
148+
free((char *)desc->value);
149+
return git_config_string(&desc->value, var, value);
150+
}
151+
152+
int read_branch_desc(struct strbuf *buf, const char *branch_name)
153+
{
154+
struct branch_desc_cb cb;
155+
struct strbuf name = STRBUF_INIT;
156+
strbuf_addf(&name, "branch.%s.description", branch_name);
157+
cb.config_name = name.buf;
158+
cb.value = NULL;
159+
if (git_config(read_branch_desc_cb, &cb) < 0) {
160+
strbuf_release(&name);
161+
return -1;
162+
}
163+
if (cb.value)
164+
strbuf_addstr(buf, cb.value);
165+
strbuf_release(&name);
166+
return 0;
167+
}
168+
138169
int validate_new_branchname(const char *name, struct strbuf *ref,
139170
int force, int attr_only)
140171
{

branch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ void remove_branch_state(void);
4646
#define BRANCH_CONFIG_VERBOSE 01
4747
extern void install_branch_config(int flag, const char *local, const char *origin, const char *remote);
4848

49+
/*
50+
* Read branch description
51+
*/
52+
extern int read_branch_desc(struct strbuf *, const char *branch_name);
53+
4954
#endif

0 commit comments

Comments
 (0)