Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--worktree.c15
-rw-r--r--worktree.h8
2 files changed, 23 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)
{
diff --git a/worktree.h b/worktree.h
index 13949093cc..7ad15da0dc 100644
--- a/worktree.h
+++ b/worktree.h
@@ -30,6 +30,14 @@ extern struct worktree **get_worktrees(void);
extern const char *get_worktree_git_dir(const struct worktree *wt);
/*
+ * Search a worktree that can be unambiguously identified by
+ * "arg". "prefix" must not be NULL.
+ */
+extern struct worktree *find_worktree(struct worktree **list,
+ const char *prefix,
+ const char *arg);
+
+/*
* Free up the memory for worktree(s)
*/
extern void free_worktrees(struct worktree **);