git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Stefan Beller <stefanbeller@googlemail.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	schlotter@users.sourceforge.net, Ralf.Wildenhues@gmx.de
Subject: Re: [PATCH 2/2] upload-pack: fix off-by-one depth calculation in shallow clone
Date: Thu, 10 Jan 2013 20:26:27 -0800	[thread overview]
Message-ID: <7vpq1ccpl8.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1357875005-21956-2-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Fri, 11 Jan 2013 10:30:05 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> 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.

> 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.

  reply	other threads:[~2013-01-11  4:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08  8:07 [PATCH] add warning for depth=0 in git clone Stefan Beller
2013-01-08  8:09 ` Stefan Beller
2013-01-08  8:14   ` Jonathan Nieder
2013-01-08  8:12 ` Jonathan Nieder
2013-01-09  0:57 ` Duy Nguyen
2013-01-09  2:53   ` On --depth=funny value Junio C Hamano
2013-01-09  4:18     ` Duy Nguyen
2013-01-09  5:19       ` Junio C Hamano
2013-01-09 14:12         ` Duy Nguyen
2013-01-09 14:59     ` Duy Nguyen
2013-01-09 21:38     ` Stefan Beller
2013-01-11  3:30     ` [PATCH 1/2] fetch, upload-pack: add --no-shallow for infinite depth Nguyễn Thái Ngọc Duy
2013-01-11  3:30       ` [PATCH 2/2] upload-pack: fix off-by-one depth calculation in shallow clone Nguyễn Thái Ngọc Duy
2013-01-11  4:26         ` Junio C Hamano [this message]
2013-01-11  3:55       ` [PATCH 1/2] fetch, upload-pack: add --no-shallow for infinite depth Junio C Hamano
2013-01-11  9:05       ` [PATCH v2 1/3] fetch: add --unshallow for turning shallow repo into complete one Nguyễn Thái Ngọc Duy
2013-01-11  9:05         ` [PATCH v2 2/3] upload-pack: fix off-by-one depth calculation in shallow clone Nguyễn Thái Ngọc Duy
2013-01-11  9:05         ` [PATCH v2 3/3] fetch: elaborate --depth action Nguyễn Thái Ngọc Duy

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=7vpq1ccpl8.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Ralf.Wildenhues@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=schlotter@users.sourceforge.net \
    --cc=stefanbeller@googlemail.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).