diff options
author | Thomas Gummerer <t.gummerer@gmail.com> | 2018-03-25 14:49:45 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-27 15:38:26 -0700 |
commit | d9532c666209af436410cabcc128152571613ba7 (patch) | |
tree | 3da14a39941352590aa554ae2aca3b387417ac34 | |
parent | f24f163e8f915662e4208232f1f12a6537aeeea6 (diff) | |
download | git-d9532c666209af436410cabcc128152571613ba7.tar.gz |
worktree: factor out dwim_branch function
Factor out a dwim_branch function, which takes care of the dwim'ery in
'git worktree add <path>'. It's not too much code currently, but we're
adding a new kind of dwim in a subsequent patch, at which point it makes
more sense to have it as a separate function.
Factor it out now to reduce the patch noise in the next patch.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/worktree.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index 1e4a919a00..c296c3eacb 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -366,6 +366,20 @@ done: return ret; } +static const char *dwim_branch(const char *path, struct add_opts *opts) +{ + int n; + const char *s = worktree_basename(path, &n); + opts->new_branch = xstrndup(s, n); + if (guess_remote) { + struct object_id oid; + const char *remote = + unique_tracking_name(opts->new_branch, &oid); + return remote; + } + return NULL; +} + static int add(int ac, const char **av, const char *prefix) { struct add_opts opts; @@ -417,16 +431,9 @@ static int add(int ac, const char **av, const char *prefix) } if (ac < 2 && !opts.new_branch && !opts.detach) { - int n; - const char *s = worktree_basename(path, &n); - opts.new_branch = xstrndup(s, n); - if (guess_remote) { - struct object_id oid; - const char *remote = - unique_tracking_name(opts.new_branch, &oid); - if (remote) - branch = remote; - } + const char *dwim_branchname = dwim_branch(path, &opts); + if (dwim_branchname) + branch = dwim_branchname; } if (ac == 2 && !opts.new_branch && !opts.detach) { |