git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] Limit refs to fetch to minimum in shallow clones

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2012, 21:25 UTC
Message-ID
<7vmxa1n8oe.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1325743516-14940-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 12 quoted lines
> The main purpose of shallow clones is to reduce download by only
> fetching objects up to a certain depth from the given refs. The number
> of objects depends on how many refs to follow. So:
>
>  - Only fetch HEAD or the ref specified by --branch
>  - Only fetch tags that point to downloaded objects
>
> More tags/branches can be fetched later using git-fetch as usual.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Only lightly tested, but seems to work.
Thanks.

Perhaps you would want to add tests so that you do not have to say "lightly tested"?

Show 9 quoted lines
> diff --git a/builtin/clone.c b/builtin/clone.c
> index efe8b6c..8de9248 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -48,6 +48,7 @@ static int option_verbosity;
>  static int option_progress;
>  static struct string_list option_config;
>  static struct string_list option_reference;
> +static char *src_ref_prefix = "refs/heads/";
Would this be const?
Show 24 quoted lines
>  static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
>  {
> @@ -427,9 +428,27 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
>  	struct ref *local_refs = head;
>  	struct ref **tail = head ? &head->next : &local_refs;
>  
> -	get_fetch_map(refs, refspec, &tail, 0);
> -	if (!option_mirror)
> -		get_fetch_map(refs, tag_refspec, &tail, 0);
> +	if (option_depth) {
> +		struct ref *remote_head = NULL;
> +
> +		if (!option_branch)
> +			remote_head = guess_remote_head(head, refs, 0);
> +		else {
> +			struct strbuf sb = STRBUF_INIT;
> +			strbuf_addstr(&sb, src_ref_prefix);
> +			strbuf_addstr(&sb, option_branch);
> +			remote_head = find_ref_by_name(refs, sb.buf);
> +			strbuf_release(&sb);
> +		}
> +
> +		if (remote_head)
> +			get_fetch_map(remote_head, refspec, &tail, 0);

What happens when we fail to find any remote_head and make no call to get_fetch_map() here? I am wondering if that should trigger an error here.

Also this breaks 5500 for rather obvious reasons, as the point of this patch is to reduce the object transferred when a shallow clone is made.

Perhaps there should be an option to give users the historical "all branches equally shallow" behaviour?

Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 12 in “Do not fetch tags on new shallow clones”
  1. Do not fetch tags on new shallow clonesNguyễn Thái Ngọc Duy, Jan 4, 2012
  2. Shawn PearceJan 4, 2012
  3. Junio C HamanoJan 4, 2012
  4. Shawn PearceJan 5, 2012
  5. Junio C HamanoJan 5, 2012
  6. Shawn PearceJan 5, 2012
  7. Limit refs to fetch to minimum in shallow clonesNguyễn Thái Ngọc Duy, Jan 5, 2012
  8. Junio C HamanoJan 5, 2012
  9. Limit refs to fetch to minimum in shallow clonesNguyễn Thái Ngọc Duy, Jan 6, 2012
  10. Junio C HamanoJan 6, 2012
  11. Nguyen Thai Ngoc DuyJan 7, 2012
  12. clone: add --single-branch to fetch only one branchNguyễn Thái Ngọc Duy, Jan 7, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.