git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Piotr Szlazak via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Christian Couder <chriscool@tuxfamily.org>,
	David Turner <dturner@twosigma.com>,
	Piotr Szlazak <piotr.szlazak@gmail.com>
Subject: Re: [PATCH] upload-pack: fix how ALLOW_ANY_SHA1 flag is disabled
Date: Wed, 16 Oct 2024 17:18:44 -0400	[thread overview]
Message-ID: <ZxAttC1dQUllR76m@nand.local> (raw)
In-Reply-To: <pull.1814.git.git.1729112794671.gitgitgadget@gmail.com>

On Wed, Oct 16, 2024 at 09:06:34PM +0000, Piotr Szlazak via GitGitGadget wrote:
> From: Piotr Szlazak <piotr.szlazak@gmail.com>
>
> ALLOW_ANY_SHA1 implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1.
> Yet ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1 flags can be enabled
> independently.
> If uploadpack.allowAnySHA1InWant is not enabled in config file,
> other flags should not be disabled together with ALLOW_ANY_SHA1.
> They should be kept enabled if they were separately enabled in
> config file with they respective options.
>
> Signed-off-by: Piotr Szlazak <piotr.szlazak@gmail.com>
> ---
>     upload-pack: fix how ALLOW_ANY_SHA1 flag is disabled
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1814%2Fpszlazak%2Fupload-pack-allow-flags-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1814/pszlazak/upload-pack-allow-flags-v1
> Pull-Request: https://github.com/git/git/pull/1814
>
>  upload-pack.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/upload-pack.c b/upload-pack.c
> index 6d6e0f9f980..cf99b228719 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -53,6 +53,7 @@ enum allow_uor {
>  	/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
>  	ALLOW_REACHABLE_SHA1 = 0x02,
>  	/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
> +	/* As this flag implies other two flags, be careful when it must be disabled. */
>  	ALLOW_ANY_SHA1 = 0x07
>  };
>
> @@ -1368,7 +1369,7 @@ static int upload_pack_config(const char *var, const char *value,
>  		if (git_config_bool(var, value))
>  			data->allow_uor |= ALLOW_ANY_SHA1;
>  		else
> -			data->allow_uor &= ~ALLOW_ANY_SHA1;
> +			data->allow_uor &= ~(ALLOW_ANY_SHA1 -(ALLOW_TIP_SHA1|ALLOW_REACHABLE_SHA1));

Subtracting the result of a bitwise-OR feels a little odd to me.

Since ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1 are defined as 0x1 and
0x2, respectively, I think the end result is as you described it, but
the route to get there feels a little odd to me.

I think it would probably make more sense to write this as:

    data->allow_uor &= ~(ALLOW_ANY_SHA1 ^ (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));

Stepping back a moment, I suppose this is handling the case where a user
writes:

    [uploadpack]
        allowTipSHA1InWant = true
        allowReachableSHA1InWant = true
        allowAnySHA1InWant = false

and is surprised when the final "uploadPack.allowAnySHA1InWant" unsets
the previous two options.

I'm not sure that the current behavior is actually wrong. The final line
in the example above seems to indicate "do not allow any SHA-1 in the
'wants'", which would indeed imply that the other two options should be
set to false as well.

And that is what the current code is doing, which I think is correct.

I do see that our upload-pack section of "git-config(1)" is lacking in
this area, though, as it does not indicate that
uploadPack.allowAnySHA1InWant implies the other two options. It may be
worth saying something like:

    NOTE: this option implies both uploadPack.allowTipSHA1InWant and
    uploadPack.allowReachableSHA1InWant. Setting this option to "false"
    will do the same for the implied ones.

Thanks,
Taylor

  reply	other threads:[~2024-10-16 21:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 21:06 [PATCH] upload-pack: fix how ALLOW_ANY_SHA1 flag is disabled Piotr Szlazak via GitGitGadget
2024-10-16 21:18 ` Taylor Blau [this message]
2024-10-17  2:37   ` Jeff King
2024-10-17 15:23     ` Taylor Blau
2024-10-17 15:59       ` Piotr Szlazak
2024-10-17 18:46         ` Taylor Blau
2024-10-18  4:33           ` Jeff King
2024-10-18 21:46             ` Taylor Blau
2024-10-19 16:39 ` [PATCH v2] doc: document how uploadpack.allowAnySHA1InWant impact other allow options Piotr Szlazak via GitGitGadget
2024-10-19 16:46   ` Piotr Szlazak
2024-10-21  5:55     ` Piotr Szlazak
2024-10-21 19:03       ` Jeff King
2024-10-21 19:47         ` Taylor Blau
2024-10-21 19:48   ` Taylor Blau

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZxAttC1dQUllR76m@nand.local \
    --to=me@ttaylorr.com \
    --cc=chriscool@tuxfamily.org \
    --cc=dturner@twosigma.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=piotr.szlazak@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.
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 NNTP newsgroup(s).