From b8a846b2e03610e6f550d364c75e514532ef7adf Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 8 Jan 2024 11:05:43 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- worktree.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'worktree.h') diff --git a/worktree.h b/worktree.h index ce45b66de9..f14784a2ff 100644 --- a/worktree.h +++ b/worktree.h @@ -57,6 +57,13 @@ struct worktree *find_worktree(struct worktree **list, const char *prefix, const char *arg); +/* + * Look up the worktree corresponding to `id`, or NULL of no such worktree + * exists. + */ +struct worktree *get_linked_worktree(const char *id, + int skip_reading_head); + /* * Return the worktree corresponding to `path`, or NULL if no such worktree * exists. @@ -134,6 +141,11 @@ void repair_worktrees(worktree_repair_fn, void *cb_data); */ void repair_worktree_at_path(const char *, worktree_repair_fn, void *cb_data); +/* + * Free up the memory for a worktree. + */ +void free_worktree(struct worktree *); + /* * Free up the memory for worktree(s) */ -- cgit v1.3