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>
Martin Ågren committed
Sep 27, 2020 at 15:15 UTC
ef2d5547fa342197befd4be599438d7a7fa41e04
2 files changed
+6
-18
worktree.c
+6
-11
@@ -536,18 +536,10 @@ void strbuf_worktree_ref(const struct worktree *wt,
536
strbuf_addstr(sb, refname);
537
}
538
539
-const char *worktree_ref(const struct worktree *wt, const char *refname)
540
-{
541
- static struct strbuf sb = STRBUF_INIT;
542
-
543
- strbuf_reset(&sb);
544
- strbuf_worktree_ref(wt, &sb, refname);
545
- return sb.buf;
546
-}
547
-
539
int other_head_refs(each_ref_fn fn, void *cb_data)
540
{
541
struct worktree **worktrees, **p;
542
+ struct strbuf refname = STRBUF_INIT;
543
int ret = 0;
544
545
worktrees = get_worktrees();
@@ -559,14 +551,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
551
if (wt->is_current)
552
continue;
553
554
+ strbuf_reset(&refname);
555
+ strbuf_worktree_ref(wt, &refname, "HEAD");
556
if (!refs_read_ref_full(get_main_ref_store(the_repository),
563
- worktree_ref(wt, "HEAD"),
557
+ refname.buf,
558
RESOLVE_REF_READING,
559
&oid, &flag))
566
- ret = fn(worktree_ref(wt, "HEAD"), &oid, flag, cb_data);
560
+ ret = fn(refname.buf, &oid, flag, cb_data);
561
if (ret)
562
break;
563
}
564
free_worktrees(worktrees);
565
+ strbuf_release(&refname);
566
return ret;
567
}
worktree.h
-7
@@ -136,11 +136,4 @@ void strbuf_worktree_ref(const struct worktree *wt,
136
struct strbuf *sb,
137
const char *refname);
138
139
-/*
140
- * Return a refname suitable for access from the current ref
141
- * store. The result will be destroyed at the next call.
142
- */
143
-const char *worktree_ref(const struct worktree *wt,
144
- const char *refname);
145
-
139
#endif