From: Nguyễn Thái Ngọc Duy Date: Wed, 13 Apr 2016 13:15:35 GMT Subject: [PATCH 14/25] worktree.c: add find_worktree_by_path() Message-ID: <1460553346-12985-15-git-send-email-pclouds@gmail.com> In-Reply-To: <1460553346-12985-1-git-send-email-pclouds@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy --- 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