summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--worktree.c16
-rw-r--r--worktree.h6
2 files changed, 16 insertions, 6 deletions
diff --git a/worktree.c b/worktree.c
index 5b4793c..43c6685 100644
--- a/worktree.c
+++ b/worktree.c
@@ -215,7 +215,6 @@ struct worktree *find_worktree(struct worktree **list,
const char *arg)
{
struct worktree *wt;
- char *path;
char *to_free = NULL;
if ((wt = find_worktree_by_suffix(list, arg)))
@@ -223,11 +222,17 @@ struct worktree *find_worktree(struct worktree **list,
if (prefix)
arg = to_free = prefix_filename(prefix, arg);
- path = real_pathdup(arg, 0);
- if (!path) {
- free(to_free);
+ wt = find_worktree_by_path(list, arg);
+ free(to_free);
+ return wt;
+}
+
+struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
+{
+ char *path = real_pathdup(p, 0);
+
+ if (!path)
return NULL;
- }
for (; *list; list++) {
const char *wt_path = real_path_if_valid((*list)->path);
@@ -235,7 +240,6 @@ struct worktree *find_worktree(struct worktree **list,
break;
}
free(path);
- free(to_free);
return *list;
}
diff --git a/worktree.h b/worktree.h
index b8a851b..d242a6e 100644
--- a/worktree.h
+++ b/worktree.h
@@ -62,6 +62,12 @@ struct worktree *find_worktree(struct worktree **list,
const char *arg);
/*
+ * Return the worktree corresponding to `path`, or NULL if no such worktree
+ * exists.
+ */
+struct worktree *find_worktree_by_path(struct worktree **, const char *path);
+
+/*
* Return true if the given worktree is the main one.
*/
int is_main_worktree(const struct worktree *wt);