Re: [PATCH v5 4/6] worktree: factor out dwim_branch function
From: Eric Sunshine <hidden>
Date: 2018-03-27 09:01:36
On Sun, Mar 25, 2018 at 9:49 AM, Thomas Gummerer [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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. [...] Signed-off-by: Thomas Gummerer <redacted> ---diff --git a/builtin/worktree.c b/builtin/worktree.c@@ -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;
I don't care strongly but the name 'dwim_branchname' is awfully long in a context where it's assigned the result of a call to dwim_branch(). In this tiny code block, a short and sweet name 's' would be easy to grok; there'd be no confusion. Anyhow, it's subjective and not at all worth a re-roll.