From: Jeff King <peff@peff.net>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: What's cooking in git.git (Apr 2017, #04; Wed, 19)
Date: Thu, 20 Apr 2017 11:35:13 -0400 [thread overview]
Message-ID: <20170420153512.kc57z7cyxdzq74sg@sigill.intra.peff.net> (raw)
In-Reply-To: <20170420095921.GA23873@ash>
On Thu, Apr 20, 2017 at 04:59:21PM +0700, Duy Nguyen wrote:
> On Wed, Apr 19, 2017 at 10:37:21PM -0700, Junio C Hamano wrote:
> > * nd/worktree-add-lock (2017-04-16) 2 commits
> > - SQUASH???
> > - worktree add: add --lock option
> >
> > Allow to lock a worktree immediately after it's created. This helps
> > prevent a race between "git worktree add; git worktree lock" and
> > "git worktree prune".
> >
> > Waiting for a response to SQUASH???
>
> Looking good. I would add some comment, lest ';' feel lonely. But it's
> really personal taste.
>
> -- 8< --
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 5ebdcce793..bc75676bf3 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -310,7 +310,7 @@ static int add_worktree(const char *path, const char *refname,
> strbuf_reset(&sb);
> strbuf_addf(&sb, "%s/locked", sb_repo.buf);
> if (!ret && opts->keep_locked)
> - ;
> + ; /* --lock wants to keep "locked" file */
> else
> unlink_or_warn(sb.buf);
I know this is just a drive-by comment, but given that the "else" is the
only thing that does anything, would it be simpler to flip the
conditional? The strbuf manipulation above also could go inside it.
E.g.:
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 5ebdcce79..05ade547c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -307,12 +307,11 @@ static int add_worktree(const char *path, const char *refname,
junk_git_dir = NULL;
done:
- strbuf_reset(&sb);
- strbuf_addf(&sb, "%s/locked", sb_repo.buf);
- if (!ret && opts->keep_locked)
- ;
- else
+ if (ret || !opts->keep_locked) {
+ strbuf_reset(&sb);
+ strbuf_addf(&sb, "%s/locked", sb_repo.buf);
unlink_or_warn(sb.buf);
+ }
argv_array_clear(&child_env);
strbuf_release(&sb);
strbuf_release(&symref);
(Since it's in its own block I'd also consider just introducing a new
variable for the path, but I guess reusing "sb" for each path is already
a pattern in the function).
-Peff
next prev parent reply other threads:[~2017-04-20 15:35 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 5:37 What's cooking in git.git (Apr 2017, #04; Wed, 19) Junio C Hamano
2017-04-20 9:59 ` Duy Nguyen
2017-04-20 15:35 ` Jeff King [this message]
2017-04-20 22:51 ` Junio C Hamano
2017-04-20 22:46 ` Junio C Hamano
[not found] ` <D61D47BD-9750-4FB6-892E-013504E03738@gmail.com>
2017-04-20 13:24 ` Johannes Schindelin
2017-04-20 16:56 ` Brandon Williams
2017-04-20 23:18 ` Brandon Williams
2017-04-21 0:56 ` Junio C Hamano
2017-04-20 22:58 ` Junio C Hamano
2017-04-21 9:50 ` Johannes Schindelin
2017-04-21 12:29 ` Christian Couder
2017-04-22 11:48 ` Johannes Schindelin
2017-04-22 17:32 ` Christian Couder
2017-04-24 14:08 ` Johannes Schindelin
2017-04-22 13:37 ` Johannes Sixt
2017-04-24 14:24 ` Johannes Schindelin
2017-04-24 16:34 ` Philip Oakley
2017-04-25 2:17 ` Christian Couder
2017-04-25 2:00 ` Christian Couder
2017-04-25 5:51 ` Johannes Sixt
2017-04-25 6:52 ` Junio C Hamano
2017-04-25 18:26 ` Johannes Sixt
2017-04-24 0:25 ` Junio C Hamano
2017-04-24 14:19 ` Johannes Schindelin
2017-04-24 15:18 ` Ævar Arnfjörð Bjarmason
2017-04-25 0:56 ` Junio C Hamano
2017-04-20 15:32 ` Lars Schneider
2017-04-20 22:52 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170420153512.kc57z7cyxdzq74sg@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).