summaryrefslogtreecommitdiff
path: root/worktree.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2016-06-03 19:19:39 +0700
committerJunio C Hamano <gitster@pobox.com>2016-06-03 21:58:18 -0700
commit6835314459794831a1b88bed56549653710e910c (patch)
treec387fabf54b670a19fcec4a02320ca5eb1197930 /worktree.c
parent0409e0b6dc169b07c05d02e8b62389b1cc975a45 (diff)
downloadgit-6835314459794831a1b88bed56549653710e910c.tar.gz
worktree.c: add find_worktree()
So far we haven't needed to identify an existing worktree from command line. Future commands such as lock or move will need it. The current implementation identifies worktrees by path (*). In future, the function could learn to identify by $(basename $path) or tags... (*) We could probably go cheaper with comparing inode number (and probably more reliable than paths when unicode enters the game). But not all systems have good inode that so let's stick to something simple for now. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'worktree.c')
-rw-r--r--worktree.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/worktree.c b/worktree.c
index f4a4f38092..0782e00983 100644
--- a/worktree.c
+++ b/worktree.c
@@ -214,6 +214,21 @@ const char *get_worktree_git_dir(const struct worktree *wt)
return git_common_path("worktrees/%s", wt->id);
}
+struct worktree *find_worktree(struct worktree **list,
+ const char *prefix,
+ const char *arg)
+{
+ char *path;
+
+ arg = prefix_filename(prefix, strlen(prefix), arg);
+ path = xstrdup(real_path(arg));
+ for (; *list; list++)
+ if (!fspathcmp(path, real_path((*list)->path)))
+ break;
+ free(path);
+ return *list;
+}
+
int is_worktree_being_rebased(const struct worktree *wt,
const char *target)
{