Re: [PATCH v5 4/6] worktree: factor out dwim_branch function
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 27, 2018, 09:01 UTC
- Message-ID
- <CAPig+cSYxGrhz2RDmHFXaEWC687BSiGb12cq8pZN_XYPGi7ejQ@mail.gmail.com>
- In-Reply-To
- <20180325134947.25828-5-t.gummerer@gmail.com>
On Sun, Mar 25, 2018 at 9:49 AM, Thomas Gummerer <t.gummerer@gmail.com> wrote:
Show 23 quoted lines
> 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 <t.gummerer@gmail.com>
> ---
> 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.