From c8dd491fa5b57ecfd9ef33ae5291eb2a9402cd59 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 1 Dec 2021 14:15:43 -0800 Subject: worktree: simplify find_shared_symref() memory ownership model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Storing the worktrees list in a static variable meant that find_shared_symref() had to rebuild the list on each call (which is inefficient when the call site is in a loop), and also that each call invalidated the pointer returned by the previous call (which is confusing). Instead, make it the caller’s responsibility to pass in the worktrees list and manage its lifetime. Signed-off-by: Anders Kaseorg Signed-off-by: Junio C Hamano --- worktree.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'worktree.c') diff --git a/worktree.c b/worktree.c index 2c155b1015..6f598dcfcd 100644 --- a/worktree.c +++ b/worktree.c @@ -404,17 +404,13 @@ int is_worktree_being_bisected(const struct worktree *wt, * bisect). New commands that do similar things should update this * function as well. */ -const struct worktree *find_shared_symref(const char *symref, +const struct worktree *find_shared_symref(struct worktree **worktrees, + const char *symref, const char *target) { const struct worktree *existing = NULL; - static struct worktree **worktrees; int i = 0; - if (worktrees) - free_worktrees(worktrees); - worktrees = get_worktrees(); - for (i = 0; worktrees[i]; i++) { struct worktree *wt = worktrees[i]; const char *symref_target; -- cgit v1.2.1