git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Tan <jonathantanmy@google.com>
Cc: git@vger.kernel.org, jrnieder@gmail.com
Subject: Re: [PATCH v2 1/2] sha1-name: replace unsigned int with option struct
Date: Sat, 29 Aug 2020 11:44:22 -0700	[thread overview]
Message-ID: <xmqqsgc5i96h.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <1ce44900a08857332ee70b916c3d9e7e76751221.1598662525.git.jonathantanmy@google.com> (Jonathan Tan's message of "Fri, 28 Aug 2020 18:02:26 -0700")

Jonathan Tan <jonathantanmy@google.com> writes:

> In preparation for a future patch adding a boolean parameter to
> repo_interpret_branch_name(), which might be easily confused with an
> existing unsigned int parameter, refactor repo_interpret_branch_name()
> to take an option struct instead of the unsigned int parameter.

Makes sense.

>  #define INTERPRET_BRANCH_LOCAL (1<<0)
>  #define INTERPRET_BRANCH_REMOTE (1<<1)
>  #define INTERPRET_BRANCH_HEAD (1<<2)
> +struct interpret_branch_name_options {
> +	/*
> +	 * If "allowed" is non-zero, it is a treated as a bitfield of allowable
> +	 * expansions: local branches ("refs/heads/"), remote branches
> +	 * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
> +	 * allowed, even ones to refs outside of those namespaces.
> +	 */
> +	unsigned allowed;
> +};
>  int repo_interpret_branch_name(struct repository *r,
>  			       const char *str, int len,
>  			       struct strbuf *buf,
> -			       unsigned allowed);
> -#define interpret_branch_name(str, len, buf, allowed) \
> -	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
> +			       const struct interpret_branch_name_options *options);
> +#define interpret_branch_name(str, len, buf, options) \
> +	repo_interpret_branch_name(the_repository, str, len, buf, options)

I was debating myself if we want to have 

    #define IBN_OPTIONS_INIT { 0 }

or something similar (perhaps "#define IOI(abit) { .allowed = (abit) }"),
but it probably is not worth it given that we have only 3 local
sites that define it, 1 always initializes the field to 0, and the
other just relay the value passed by its caller.

> ...
> diff --git a/sha1-name.c b/sha1-name.c
> index 0b8cb5247a..a7a9de66c4 100644
> --- a/sha1-name.c
> +++ b/sha1-name.c
> @@ -1427,9 +1427,12 @@ static int reinterpret(struct repository *r,
>  	struct strbuf tmp = STRBUF_INIT;
>  	int used = buf->len;
>  	int ret;
> +	struct interpret_branch_name_options options = {
> +		.allowed = allowed
> +	};
>  
>  	strbuf_add(buf, name + len, namelen - len);
> -	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
> +	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, &options);

> @@ -1557,7 +1561,10 @@ int repo_interpret_branch_name(struct repository *r,
>  void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
>  {
>  	int len = strlen(name);
> -	int used = interpret_branch_name(name, len, sb, allowed);
> +	struct interpret_branch_name_options options = {
> +		.allowed = allowed
> +	};
> +	int used = interpret_branch_name(name, len, sb, &options);

These are quite straight-forward rewrites.  Looking good.

Thanks.

  reply	other threads:[~2020-08-29 18:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13  0:40 [PATCH] wt-status: expand, not dwim, a "detached from" ref Jonathan Tan
2020-05-13  5:33 ` Junio C Hamano
2020-05-13 14:59   ` Junio C Hamano
2020-05-18 22:24     ` Jonathan Tan
2020-08-27  1:47 ` Jonathan Nieder
2020-08-27  2:10   ` Junio C Hamano
2020-08-29  1:02 ` [PATCH v2 0/2] Fix for git checkout @{u} (non-local) then git status Jonathan Tan
2020-08-29  1:02   ` [PATCH v2 1/2] sha1-name: replace unsigned int with option struct Jonathan Tan
2020-08-29 18:44     ` Junio C Hamano [this message]
2020-08-29  1:02   ` [PATCH v2 2/2] wt-status: tolerate dangling marks Jonathan Tan
2020-08-29 18:55     ` Junio C Hamano
2020-08-31 17:17       ` Jonathan Tan
2020-08-31 17:37         ` Junio C Hamano
2020-09-01 22:28 ` [PATCH v3 0/3] Fix for git checkout @{u} (non-local) then git status Jonathan Tan
2020-09-01 22:28   ` [PATCH v3 1/3] sha1-name: replace unsigned int with option struct Jonathan Tan
2020-09-01 22:28   ` [PATCH v3 2/3] refs: move dwim_ref() to header file Jonathan Tan
2020-09-01 22:28   ` [PATCH v3 3/3] wt-status: tolerate dangling marks Jonathan Tan

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=xmqqsgc5i96h.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=jrnieder@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).