diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-01-08 11:05:43 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-08 22:17:30 +0100 |
commit | b8a846b2e03610e6f550d364c75e514532ef7adf (patch) | |
tree | efa9a3a57dd26a54323bd036a16ac2c103d4e129 /worktree.c | |
parent | builtin/worktree: move setup of commondir file earlier (diff) | |
download | git-b8a846b2e03610e6f550d364c75e514532ef7adf.tar.xz git-b8a846b2e03610e6f550d364c75e514532ef7adf.zip |
worktree: expose interface to look up worktree by name
Our worktree interfaces do not provide a way to look up a worktree by
its name. Expose `get_linked_worktree()` to allow for this usecase. As
callers are responsible for freeing this worktree, introduce a new
function `free_worktree()` that does so.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'worktree.c')
-rw-r--r-- | worktree.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/worktree.c b/worktree.c index cc34a3419b..5d5dd46609 100644 --- a/worktree.c +++ b/worktree.c @@ -12,18 +12,23 @@ #include "wt-status.h" #include "config.h" +void free_worktree(struct worktree *worktree) +{ + if (!worktree) + return; + free(worktree->path); + free(worktree->id); + free(worktree->head_ref); + free(worktree->lock_reason); + free(worktree->prune_reason); + free(worktree); +} + void free_worktrees(struct worktree **worktrees) { int i = 0; - - for (i = 0; worktrees[i]; i++) { - free(worktrees[i]->path); - free(worktrees[i]->id); - free(worktrees[i]->head_ref); - free(worktrees[i]->lock_reason); - free(worktrees[i]->prune_reason); - free(worktrees[i]); - } + for (i = 0; worktrees[i]; i++) + free_worktree(worktrees[i]); free (worktrees); } @@ -75,8 +80,8 @@ static struct worktree *get_main_worktree(int skip_reading_head) return worktree; } -static struct worktree *get_linked_worktree(const char *id, - int skip_reading_head) +struct worktree *get_linked_worktree(const char *id, + int skip_reading_head) { struct worktree *worktree = NULL; struct strbuf path = STRBUF_INIT; |