public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks•im>
To: Toon Claes <toon@iotcl•com>
Cc: git@vger•kernel.org,
	"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail•com>,
	"Michal Suchánek" <msuchanek@suse•de>,
	"Jeff King" <peff@peff•net>
Subject: Re: [PATCH v4 5/6] clone: introduce struct clone_opts in builtin/clone.c
Date: Mon, 3 Feb 2025 08:51:31 +0100	[thread overview]
Message-ID: <Z6B1g1bkUpU78NUw@pks.im> (raw)
In-Reply-To: <20250131-toon-clone-refs-v4-5-2a4ff851498f@iotcl.com>

On Fri, Jan 31, 2025 at 04:30:33PM +0100, Toon Claes wrote:
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 7ab156ac00240de89baca6533ed2541839286fc4..f92017c751dd31cb25a3ba31667b015d5766ce84 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -429,23 +436,27 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch
>  	return ref;
>  }
>  
> -static struct ref *wanted_peer_refs(const struct ref *refs,
> -		struct refspec *refspec)
> +static struct ref *wanted_peer_refs(struct clone_opts *opts,
> +				    const struct ref *refs,
> +				    struct refspec *refspec)
>  {
> -	struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
> -	struct ref *local_refs = head;
> -	struct ref **tail = local_refs ? &local_refs->next : &local_refs;
> +	struct ref *local_refs = NULL;
> +	struct ref **tail = &local_refs;
>  	struct ref *to_free = NULL;
>  
> -	if (option_single_branch) {
> -		if (!option_branch)
> +	if (opts->wants_head) {
> +		struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
> +		if (head)
> +			tail_link_ref(head, &tail);
> +
> +		if (option_single_branch)
>  			refs = to_free = guess_remote_head(head, refs, 0);
> -		else {
> -			free_one_ref(head);
> -			local_refs = head = NULL;
> -			tail = &local_refs;
> -			refs = to_free = copy_ref(find_remote_branch(refs, option_branch));
> -		}
> +	}
> +
> +	else if (option_single_branch) {

Formatting: the `else if` should be on the same line as the closing
brace.

> +		local_refs = NULL;
> +		tail = &local_refs;
> +		refs = to_free = copy_ref(find_remote_branch(refs, option_branch));
>  	}
>  
>  	for (int i = 0; i < refspec->nr; i++)
> @@ -893,6 +904,8 @@ int cmd_clone(int argc,
>  	struct string_list server_options = STRING_LIST_INIT_NODUP;
>  	const char *bundle_uri = NULL;
>  
> +	struct clone_opts opts = CLONE_OPTS_INIT;
> +

Nit: There's a bit too many empty lines to my taste, without a clear
reason why.

>  	struct transport_ls_refs_options transport_ls_refs_options =
>  		TRANSPORT_LS_REFS_OPTIONS_INIT;
>  
> @@ -1343,9 +1356,13 @@ int cmd_clone(int argc,
>  	if (option_not.nr)
>  		transport_set_option(transport, TRANS_OPT_DEEPEN_NOT,
>  				     (const char *)&option_not);
> -	if (option_single_branch)
> +	if (option_single_branch) {
>  		transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
>  
> +		if (option_branch)
> +			opts.wants_head = 0;

Makes sense. If we only want to clone a single branch, and we specify
which branch that is, then there is no need to fetch the remote HEAD.

> +	}
> +
>  	if (option_upload_pack)
>  		transport_set_option(transport, TRANS_OPT_UPLOADPACK,
>  				     option_upload_pack);
> @@ -1450,7 +1467,7 @@ int cmd_clone(int argc,
>  	}
>  
>  	if (refs)
> -		mapped_refs = wanted_peer_refs(refs, &remote->fetch);
> +		mapped_refs = wanted_peer_refs(&opts, refs, &remote->fetch);
>  
>  	if (mapped_refs) {
>  		/*
> index bda10dd5c85ffd8988a6c3d39583e7b9701278b8..65d2de2c2051cf28def8b43fcca3fd5e1c86a0d8 100644
> --- a/remote.h
> +++ b/remote.h
> @@ -219,6 +219,7 @@ struct ref *alloc_ref(const char *name);
>  struct ref *copy_ref(const struct ref *ref);
>  struct ref *copy_ref_list(const struct ref *ref);
>  int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
> +void tail_link_ref(struct ref *ref, struct ref ***tail);

Can we maybe add a comment explaining what this function does?

Patrick

  reply	other threads:[~2025-02-03  7:51 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 12:00 [PATCH v2] builtin/clone: teach git-clone(1) the --revision= option Toon Claes
2024-12-02 14:08 ` Patrick Steinhardt
2024-12-02 21:17   ` Jeff King
2024-12-03 15:34   ` Michal Suchánek
2024-12-19 11:23   ` Toon Claes
2024-12-19 11:58 ` [PATCH v3] " Toon Claes
2024-12-19 18:30   ` Junio C Hamano
2025-01-31 15:30   ` [PATCH v4 0/6] Enable doing a shallow clone of a specific git revision Toon Claes
2025-01-31 15:30     ` [PATCH v4 1/6] clone: cut down on global variables in clone.c Toon Claes
2025-01-31 15:30     ` [PATCH v4 2/6] clone: make it possible to specify --tags Toon Claes
2025-02-01 16:47       ` Jean-Noël AVILA
2025-01-31 15:30     ` [PATCH v4 3/6] clone: refactor wanted_peer_refs() Toon Claes
2025-02-03  7:51       ` Patrick Steinhardt
2025-01-31 15:30     ` [PATCH v4 4/6] clone: add tags refspec earlier to fetch refspec Toon Claes
2025-02-03  7:51       ` Patrick Steinhardt
2025-01-31 15:30     ` [PATCH v4 5/6] clone: introduce struct clone_opts in builtin/clone.c Toon Claes
2025-02-03  7:51       ` Patrick Steinhardt [this message]
2025-01-31 15:30     ` [PATCH v4 6/6] builtin/clone: teach git-clone(1) the --revision= option Toon Claes
2025-01-31 21:05       ` Junio C Hamano
2025-02-01 16:50       ` Jean-Noël AVILA
2025-02-03  7:51       ` Patrick Steinhardt
2025-02-04 21:33     ` [PATCH v5 0/7] Enable doing a shallow clone of a specific git revision Toon Claes
2025-02-04 21:34       ` [PATCH v5 1/7] clone: cut down on global variables in clone.c Toon Claes
2025-02-04 21:34       ` [PATCH v5 2/7] clone: make it possible to specify --tags Toon Claes
2025-02-05  8:03         ` Patrick Steinhardt
2025-02-05 16:29           ` Toon Claes
2025-02-05 21:15           ` Jean-Noël AVILA
2025-02-04 21:34       ` [PATCH v5 3/7] clone: refactor wanted_peer_refs() Toon Claes
2025-02-04 21:34       ` [PATCH v5 4/7] clone: add tags refspec earlier to fetch refspec Toon Claes
2025-02-05  8:03         ` Patrick Steinhardt
2025-02-04 21:34       ` [PATCH v5 5/7] clone: introduce struct clone_opts in builtin/clone.c Toon Claes
2025-02-04 21:34       ` [PATCH v5 6/7] parse-options: introduce die_for_incompatible_opt2() Toon Claes
2025-02-05  8:03         ` Patrick Steinhardt
2025-02-04 21:34       ` [PATCH v5 7/7] builtin/clone: teach git-clone(1) the --revision= option Toon Claes
2025-02-05  8:03         ` Patrick Steinhardt
2025-02-05 16:43           ` Toon Claes
2025-02-05  8:03       ` [PATCH v5 0/7] Enable doing a shallow clone of a specific git revision Patrick Steinhardt
2025-02-05 14:09       ` Junio C Hamano
2025-02-05 16:47       ` [PATCH v6 " Toon Claes
2025-02-05 16:47         ` [PATCH v6 1/7] clone: cut down on global variables in clone.c Toon Claes
2025-02-05 16:47         ` [PATCH v6 2/7] clone: make it possible to specify --tags Toon Claes
2025-02-05 16:47         ` [PATCH v6 3/7] clone: refactor wanted_peer_refs() Toon Claes
2025-02-05 16:47         ` [PATCH v6 4/7] clone: add tags refspec earlier to fetch refspec Toon Claes
2025-02-05 16:47         ` [PATCH v6 5/7] clone: introduce struct clone_opts in builtin/clone.c Toon Claes
2025-02-05 16:47         ` [PATCH v6 6/7] parse-options: introduce die_for_incompatible_opt2() Toon Claes
2025-02-05 16:47         ` [PATCH v6 7/7] builtin/clone: teach git-clone(1) the --revision= option Toon Claes
2025-02-05 17:24           ` Junio C Hamano
2025-02-06  6:33         ` [PATCH v7 0/7] Enable doing a shallow clone of a specific git revision Toon Claes
2025-02-06  6:33           ` [PATCH v7 1/7] clone: cut down on global variables in clone.c Toon Claes
2025-02-06  6:33           ` [PATCH v7 2/7] clone: make it possible to specify --tags Toon Claes
2025-02-06  6:33           ` [PATCH v7 3/7] clone: refactor wanted_peer_refs() Toon Claes
2025-02-06  6:33           ` [PATCH v7 4/7] clone: add tags refspec earlier to fetch refspec Toon Claes
2025-02-06  6:33           ` [PATCH v7 5/7] clone: introduce struct clone_opts in builtin/clone.c Toon Claes
2025-02-06  6:33           ` [PATCH v7 6/7] parse-options: introduce die_for_incompatible_opt2() Toon Claes
2025-02-06  6:33           ` [PATCH v7 7/7] builtin/clone: teach git-clone(1) the --revision= option Toon Claes
2025-02-06  8:13             ` Patrick Steinhardt
2025-02-06 20:26               ` 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

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

  git send-email \
    --in-reply-to=Z6B1g1bkUpU78NUw@pks.im \
    --to=ps@pks$(echo .)im \
    --cc=git@vger$(echo .)kernel.org \
    --cc=kristofferhaugsbakk@fastmail$(echo .)com \
    --cc=msuchanek@suse$(echo .)de \
    --cc=peff@peff$(echo .)net \
    --cc=toon@iotcl$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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