Skip to content

Commit ef2d554

Browse files
Martin Ågrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 962dd7e commit ef2d554

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

worktree.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,10 @@ void strbuf_worktree_ref(const struct worktree *wt,
536536
strbuf_addstr(sb, refname);
537537
}
538538

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-
548539
int other_head_refs(each_ref_fn fn, void *cb_data)
549540
{
550541
struct worktree **worktrees, **p;
542+
struct strbuf refname = STRBUF_INIT;
551543
int ret = 0;
552544

553545
worktrees = get_worktrees();
@@ -559,14 +551,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
559551
if (wt->is_current)
560552
continue;
561553

554+
strbuf_reset(&refname);
555+
strbuf_worktree_ref(wt, &refname, "HEAD");
562556
if (!refs_read_ref_full(get_main_ref_store(the_repository),
563-
worktree_ref(wt, "HEAD"),
557+
refname.buf,
564558
RESOLVE_REF_READING,
565559
&oid, &flag))
566-
ret = fn(worktree_ref(wt, "HEAD"), &oid, flag, cb_data);
560+
ret = fn(refname.buf, &oid, flag, cb_data);
567561
if (ret)
568562
break;
569563
}
570564
free_worktrees(worktrees);
565+
strbuf_release(&refname);
571566
return ret;
572567
}

worktree.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,4 @@ void strbuf_worktree_ref(const struct worktree *wt,
136136
struct strbuf *sb,
137137
const char *refname);
138138

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-
146139
#endif

0 commit comments

Comments
 (0)