summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-07-06 17:30:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-06 18:07:48 (GMT)
commitf5682b2a861cbde6e9aca324caa5e2d36c49569a (patch)
treed24d90cd3abce149190b8a3e56eba3c9837e8462 /builtin
parent0ca560cb975aa081971d0fb1586e0206156fa22f (diff)
downloadgit-f5682b2a861cbde6e9aca324caa5e2d36c49569a.zip
git-f5682b2a861cbde6e9aca324caa5e2d36c49569a.tar.gz
git-f5682b2a861cbde6e9aca324caa5e2d36c49569a.tar.bz2
worktree: extract basename computation to new function
A subsequent patch will also need to compute the basename of the new worktree, so factor out this logic into a new function. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/worktree.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 04e6d0f..25fe25b 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -152,6 +152,25 @@ static void remove_junk_on_signal(int signo)
raise(signo);
}
+static const char *worktree_basename(const char *path, int *olen)
+{
+ const char *name;
+ int len;
+
+ len = strlen(path);
+ while (len && is_dir_sep(path[len - 1]))
+ len--;
+
+ for (name = path + len - 1; name > path; name--)
+ if (is_dir_sep(*name)) {
+ name++;
+ break;
+ }
+
+ *olen = len;
+ return name;
+}
+
static int add_worktree(const char *path, const char **child_argv)
{
struct strbuf sb_git = STRBUF_INIT, sb_repo = STRBUF_INIT;
@@ -165,15 +184,7 @@ static int add_worktree(const char *path, const char **child_argv)
if (file_exists(path) && !is_empty_dir(path))
die(_("'%s' already exists"), path);
- len = strlen(path);
- while (len && is_dir_sep(path[len - 1]))
- len--;
-
- for (name = path + len - 1; name > path; name--)
- if (is_dir_sep(*name)) {
- name++;
- break;
- }
+ name = worktree_basename(path, &len);
strbuf_addstr(&sb_repo,
git_path("worktrees/%.*s", (int)(path + len - name), name));
len = sb_repo.len;