worktree: inline `worktree_ref()` into its only caller
We have `strbuf_worktree_ref()`, which works on a strbuf, and a wrapper for it, `worktree_ref()` which returns a string. We even make this wrapper available through worktree.h. But it only has a single caller, sitting right next to it in worktree.c. Just inline the wrapper into its only caller. This means the caller can quite naturally reuse a single strbuf. We currently achieve something similar by having a static strbuf in the wrapper. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
962dd7ebc3
commit
ef2d5547fa
17
worktree.c
17
worktree.c
|
@ -536,18 +536,10 @@ void strbuf_worktree_ref(const struct worktree *wt,
|
||||||
strbuf_addstr(sb, refname);
|
strbuf_addstr(sb, refname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *worktree_ref(const struct worktree *wt, const char *refname)
|
|
||||||
{
|
|
||||||
static struct strbuf sb = STRBUF_INIT;
|
|
||||||
|
|
||||||
strbuf_reset(&sb);
|
|
||||||
strbuf_worktree_ref(wt, &sb, refname);
|
|
||||||
return sb.buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int other_head_refs(each_ref_fn fn, void *cb_data)
|
int other_head_refs(each_ref_fn fn, void *cb_data)
|
||||||
{
|
{
|
||||||
struct worktree **worktrees, **p;
|
struct worktree **worktrees, **p;
|
||||||
|
struct strbuf refname = STRBUF_INIT;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
worktrees = get_worktrees();
|
worktrees = get_worktrees();
|
||||||
|
@ -559,14 +551,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
|
||||||
if (wt->is_current)
|
if (wt->is_current)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
strbuf_reset(&refname);
|
||||||
|
strbuf_worktree_ref(wt, &refname, "HEAD");
|
||||||
if (!refs_read_ref_full(get_main_ref_store(the_repository),
|
if (!refs_read_ref_full(get_main_ref_store(the_repository),
|
||||||
worktree_ref(wt, "HEAD"),
|
refname.buf,
|
||||||
RESOLVE_REF_READING,
|
RESOLVE_REF_READING,
|
||||||
&oid, &flag))
|
&oid, &flag))
|
||||||
ret = fn(worktree_ref(wt, "HEAD"), &oid, flag, cb_data);
|
ret = fn(refname.buf, &oid, flag, cb_data);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free_worktrees(worktrees);
|
free_worktrees(worktrees);
|
||||||
|
strbuf_release(&refname);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,11 +136,4 @@ void strbuf_worktree_ref(const struct worktree *wt,
|
||||||
struct strbuf *sb,
|
struct strbuf *sb,
|
||||||
const char *refname);
|
const char *refname);
|
||||||
|
|
||||||
/*
|
|
||||||
* Return a refname suitable for access from the current ref
|
|
||||||
* store. The result will be destroyed at the next call.
|
|
||||||
*/
|
|
||||||
const char *worktree_ref(const struct worktree *wt,
|
|
||||||
const char *refname);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue