Re: [PATCH v6 3/6] worktree: improve message when creating a new worktree
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 8, 2018, 09:27 UTC
- Message-ID
- <CAPig+cQmEHx1N1Q9in6K8n3AyUMCk1V7JyAoeXrQVNQDQdxZ0w@mail.gmail.com>
- In-Reply-To
- <20180331151804.30380-4-t.gummerer@gmail.com>
On Sat, Mar 31, 2018 at 11:18 AM, Thomas Gummerer <t.gummerer@gmail.com> wrote:
Show 30 quoted lines
> [...]
> Fix these inconsistencies, and no longer show the identifier by making
> the 'git reset --hard' call not print the "HEAD is now at ..." line
> using the newly introduced flag from the previous commit, and printing
> the message directly from the builtin command instead.
>
> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -322,12 +320,22 @@ static int add_worktree(const char *path, const char *refname,
> argv_array_pushl(&cp.args, "reset", "--hard", NULL);
> + argv_array_push(&cp.args, "--no-show-new-head-line");
> cp.env = child_env.argv;
> ret = run_command(&cp);
> if (ret)
> goto done;
> }
>
> + fprintf(stderr, _("New worktree HEAD is now at %s"),
> + find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
> +
> + strbuf_reset(&sb);
> + pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
> + if (sb.len > 0)
> + fprintf(stderr, " %s", sb.buf);
> + fputc('\n', stderr);
> +
> is_junk = 0;
> FREE_AND_NULL(junk_work_tree);
> FREE_AND_NULL(junk_git_dir);Generally speaking, code such as this probably ought to be inserted outside of the is_junk={1,0} context in order to keep that critical section as small as possible. However, as mentioned in my response to the v6 cover letter[1], I think this chunk of new code can just go away entirely if git-reset is made to print the customized message on git-worktree's behalf.
[1]: https://public-inbox.org/git/CAPig+cQ8VzDycUMo-QOexNDBgQGEGj2BPmPa-Y0vhGCt_brbhg@mail.gmail.com/