Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
---
worktree.c | 16 ++++++++++++++++
worktree.h | 6 ++++++
2 files changed, 22 insertions(+)
diff --git a/worktree.c b/worktree.c
index b4e4b57..e444ad1 100644
--- a/worktree.c
+++ b/worktree.c
@@ -198,6 +198,22 @@ const char *get_worktree_git_dir(const struct worktree *wt)
return get_git_common_dir();
}
+struct worktree *find_worktree_by_path(struct worktree **list,
+ const char *path_)
+{
+ char *path = xstrdup(real_path(path_));
+ struct worktree *wt = NULL;
+
+ while (*list) {
+ wt = *list++;
+ if (!strcmp_icase(path, real_path(wt->path)))
+ break;
+ wt = NULL;
+ }
+ free(path);
+ return wt;
+}
+
char *find_shared_symref(const char *symref, const char *target)
{
char *existing = NULL;
diff --git a/worktree.h b/worktree.h
index 0ba07ab..c163b6b 100644
--- a/worktree.h
+++ b/worktree.h
@@ -28,6 +28,12 @@ extern struct worktree **get_worktrees(void);
extern const char *get_worktree_git_dir(const struct worktree *wt);
/*
+ * Search a worktree by its path. Paths are normalized internally.
+ */
+extern struct worktree *find_worktree_by_path(struct worktree **list,
+ const char *path_);
+
+/*
* Free up the memory for worktree
*/
extern void clear_worktree(struct worktree *);
--
2.8.0.rc0.210.gd302cd2
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html