Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
worktree: extract basename computation to new function
author
Eric Sunshine
<sunshine@sunshineco.com>
Mon, 6 Jul 2015 17:30:57 +0000
(13:30 -0400)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 6 Jul 2015 18:07:48 +0000
(11:07 -0700)
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>
builtin/worktree.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
0ca560c
)
diff --git
a/builtin/worktree.c
b/builtin/worktree.c
index 04e6d0f92798f32dd10c1e677f3d85760f7dcdc6..25fe25b45f7771bb3b000ae92aa5f24875adc51e 100644
(file)
--- a/
builtin/worktree.c
+++ b/
builtin/worktree.c
@@
-152,6
+152,25
@@
static void remove_junk_on_signal(int signo)
raise(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;
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);
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;
strbuf_addstr(&sb_repo,
git_path("worktrees/%.*s", (int)(path + len - name), name));
len = sb_repo.len;