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

Re: [PATCH 2/2] upload-pack: fix off-by-one depth calculation in shallow clone

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 11, 2013, 04:26 UTC
Message-ID
<7vpq1ccpl8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1357875005-21956-2-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 33 quoted lines
> get_shallow_commits() is used to determine the cut points at a given
> depth (i.e. the number of commits in a chain that the user likes to
> get). However we count current depth up to the commit "commit" but we
> do the cutting at its parents (i.e. current depth + 1). This makes
> upload-pack always return one commit more than requested. This patch
> fixes it.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  shallow.c             |  8 +++++++-
>  t/t5500-fetch-pack.sh | 25 +++++++++++++++++++------
>  2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/shallow.c b/shallow.c
> index a0363de..6be915f 100644
> --- a/shallow.c
> +++ b/shallow.c
> @@ -72,8 +72,14 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
>  		}
>  		if (parse_commit(commit))
>  			die("invalid commit");
> -		commit->object.flags |= not_shallow_flag;
>  		cur_depth++;
> +		if (cur_depth >= depth) {
> +			commit_list_insert(commit, &result);
> +			commit->object.flags |= shallow_flag;
> +			commit = NULL;
> +			continue;
> +		}
> +		commit->object.flags |= not_shallow_flag;
>  		for (p = commit->parents, commit = NULL; p; p = p->next) {
>  			if (!p->item->util) {
>  				int *pointer = xmalloc(sizeof(int));

Nice. No protocol extensions, you update the server side, and an old client starts getting the right number of generations.

Show 12 quoted lines
> diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
> index 6a6e672..58d3bdf 100755
> --- a/t/t5500-fetch-pack.sh
> +++ b/t/t5500-fetch-pack.sh
> @@ -130,16 +130,25 @@ test_expect_success 'single given branch clone' '
>  	test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
>  '
>  
> +test_expect_success 'clone shallow depth 1' '
> +	git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0
> +	test "`git --git-dir=shallow0/.git rev-list --count HEAD`" = 1
> +'
No &&-chaining?
Thanks.
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 14 of 18 in “add warning for depth=0 in git clone.”
  1. add warning for depth=0 in git clone.Stefan Beller, Jan 8, 2013
  2. Stefan BellerJan 8, 2013
  3. Jonathan NiederJan 8, 2013
  4. Jonathan NiederJan 8, 2013
  5. Duy NguyenJan 9, 2013
  6. On --depth=funny valueJunio C Hamano, Jan 9, 2013
  7. Duy NguyenJan 9, 2013
  8. Junio C HamanoJan 9, 2013
  9. Duy NguyenJan 9, 2013
  10. Duy NguyenJan 9, 2013
  11. Stefan BellerJan 9, 2013
  12. 1/2 fetch, upload-pack: add --no-shallow for infinite depthNguyễn Thái Ngọc Duy, Jan 11, 2013
  13. 2/2 upload-pack: fix off-by-one depth calculation in shallow cloneNguyễn Thái Ngọc Duy, Jan 11, 2013
  14. Junio C HamanoJan 11, 2013
  15. Junio C HamanoJan 11, 2013
  16. 1/3 fetch: add --unshallow for turning shallow repo into complete oneNguyễn Thái Ngọc Duy, Jan 11, 2013
  17. 2/3 upload-pack: fix off-by-one depth calculation in shallow cloneNguyễn Thái Ngọc Duy, Jan 11, 2013
  18. 3/3 fetch: elaborate --depth actionNguyễn Thái Ngọc Duy, Jan 11, 2013

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.