From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 2/3] branch: split validate_new_branchname() into two
Date: Sat, 21 Oct 2017 10:28:30 +0530 [thread overview]
Message-ID: <1508561910.2516.22.camel@gmail.com> (raw)
In-Reply-To: <20171013051132.3973-3-gitster@pobox.com>
On Fri, 2017-10-13 at 14:11 +0900, Junio C Hamano wrote:
>
> diff --git a/branch.c b/branch.c
> index 7404597678..2c3a364a0b 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -178,19 +178,31 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
> return 0;
> }
>
> -int validate_new_branchname(const char *name, struct strbuf *ref,
> - int force, int attr_only)
> +/*
> + * Check if 'name' can be a valid name for a branch; die otherwise.
> + * Return 1 if the named branch already exists; return 0 otherwise.
> + * Fill ref with the full refname for the branch.
> + */
> +int validate_branchname(const char *name, struct strbuf *ref)
> {
> - const char *head;
> -
> if (strbuf_check_branch_ref(ref, name))
> die(_("'%s' is not a valid branch name."), name);
>
> - if (!ref_exists(ref->buf))
> - return 0;
> + return ref_exists(ref->buf);
> +}
>
> - if (attr_only)
> - return 1;
> +/*
> + * Check if a branch 'name' can be created as a new branch; die otherwise.
> + * 'force' can be used when it is OK for the named branch already exists.
> + * Return 1 if the named branch already exists; return 0 otherwise.
> + * Fill ref with the full refname for the branch.
> + */
I guess it's better to avoid repeating the comments in both the .h and
.c file as they might quite easily become stale. I would prefer keeping
it in the header file alone.
> +int validate_new_branchname(const char *name, struct strbuf *ref, int force)
> +{
> + const char *head;
> +
> + if (!validate_branchname(name, ref))
> + return 0;
>
> if (!force)
> die(_("A branch named '%s' already exists."),
> @@ -246,9 +258,9 @@ void create_branch(const char *name, const char *start_name,
> if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE)
> explicit_tracking = 1;
>
> - if (validate_new_branchname(name, &ref, force,
> - track == BRANCH_TRACK_OVERRIDE ||
> - clobber_head)) {
> + if ((track == BRANCH_TRACK_OVERRIDE || clobber_head)
> + ? validate_branchname(name, &ref)
> + : validate_new_branchname(name, &ref, force)) {
> if (!force)
> dont_change_ref = 1;
>
The change was simple by splitting the function into two and calling
the right function as required at every call site! As far as I could
see this doesn't seem to be reducing the confusion that the 'attr_only'
parameter caused. That's because the new validate_branchname function
seems to be called in some cases when the 'force' parameter is true and
in other cases the 'force' parameter is sent to the
'validate_new_branchname' function. So, I think consistency is lacking
in this change. That's just my opinion, of course.
--
Kaartic
next prev parent reply other threads:[~2017-10-21 5:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-13 5:11 [PATCH 0/3] a small branch API clean-up Junio C Hamano
2017-10-13 5:11 ` [PATCH 1/3] branch: streamline "attr_only" handling in validate_new_branchname() Junio C Hamano
2017-10-13 7:05 ` Eric Sunshine
2017-10-13 5:11 ` [PATCH 2/3] branch: split validate_new_branchname() into two Junio C Hamano
2017-10-21 4:58 ` Kaartic Sivaraam [this message]
2017-10-21 9:01 ` Junio C Hamano
2017-10-13 5:11 ` [PATCH 3/3] branch: forbid refs/heads/HEAD Junio C Hamano
2017-10-13 13:15 ` Jeff King
2017-10-14 2:11 ` Junio C Hamano
2017-10-14 2:20 ` Junio C Hamano
2017-10-16 21:38 ` Jeff King
2017-10-21 4:50 ` Kaartic Sivaraam
2017-10-21 8:57 ` Junio C Hamano
2017-10-22 5:00 ` Kaartic Sivaraam
2017-10-21 3:07 ` [PATCH 0/3] a small branch API clean-up Kaartic Sivaraam
2017-10-21 8:52 ` Junio C Hamano
2017-10-22 4:36 ` Kaartic Sivaraam
2017-11-14 11:42 ` [PATCH v2 1/2] branch: forbid refs/heads/HEAD Kaartic Sivaraam
2017-11-14 11:42 ` [PATCH v2 2/2] builtin/branch: remove redundant check for HEAD Kaartic Sivaraam
2017-11-14 12:00 ` [PATCH v2 1/2] branch: forbid refs/heads/HEAD Kaartic Sivaraam
2017-11-14 15:08 ` Junio C Hamano
2017-11-15 16:59 ` Kaartic Sivaraam
2017-11-15 22:14 ` [PATCH 3/4] branch: correctly reject refs/heads/{-dash,HEAD} Junio C Hamano
2017-11-16 13:11 ` Kaartic Sivaraam
2017-11-16 14:57 ` Junio C Hamano
2017-11-16 17:02 ` Kaartic Sivaraam
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=1508561910.2516.22.camel@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).