All of lore.kernel.org
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Patrick Donnelly <batrick@batbytes.com>,
	Jeff King <peff@peff.net>, Dan Johnson <computerdruid@gmail.com>,
	Christian Halstrick <christian.halstrick@gmail.com>,
	Git <git@vger.kernel.org>
Subject: Re: Can I fetch an arbitrary commit by sha1?
Date: Wed, 8 Oct 2014 20:30:29 +0700	[thread overview]
Message-ID: <20141008133029.GA23010@lanh> (raw)
In-Reply-To: <xmqqwq8bizzi.fsf@gitster.dls.corp.google.com>

On Tue, Oct 07, 2014 at 09:52:33AM -0700, Junio C Hamano wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
> 
> > Hmm.. Junio already did most of the work in 051e400 (helping
> > smart-http/stateless-rpc fetch race - 2011-08-05), so all we need to
> > do is enable uploadpack.allowtipsha1inwant and apply this patch
> 
> Not that patch, I would think.
> 
> I would understand "if !stateless_rpc and !allowtipsha1 then it is
> an error", though.

Fair enough. It seems to work, technically, using the patch below. But
I think people would rather have support from "git clone" and "git
clone --branch" can't deal with SHA-1 this way yet. And --branch might
be a bad place to enable this..

So it needs more work. Any help is appreciated, as I still need to
finish my untracked cache series first and re-evaluate watchman series
before git 3.0 is released.

-- 8< --
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 67e0ab3..bdc121e 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1277,4 +1277,22 @@ EOF
 	git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
 '
 
+test_expect_success 'shallow fetch reachable SHA1 (but not a ref)' '
+	mk_empty testrepo &&
+	(
+		cd testrepo &&
+		test_commit foo &&
+		test_commit bar
+	) &&
+	SHA1=`git --git-dir=testrepo/.git rev-parse HEAD^` &&
+	git init shallow &&
+	(
+		cd shallow &&
+		test_must_fail git fetch --depth=1 ../testrepo/.git $SHA1 &&
+		git --git-dir=../testrepo/.git config uploadpack.allowtipsha1inwant true &&
+		git fetch --depth=1 ../testrepo/.git $SHA1 &&
+		git cat-file commit $SHA1 >/dev/null
+	)
+'
+
 test_done
diff --git a/upload-pack.c b/upload-pack.c
index c789ec0..4a9a656 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -454,8 +454,12 @@ static void check_non_tip(void)
 	char namebuf[42]; /* ^ + SHA-1 + LF */
 	int i;
 
-	/* In the normal in-process case non-tip request can never happen */
-	if (!stateless_rpc)
+	/*
+	 * In the normal in-process case without
+	 * uploadpack.allowtipsha1inwant, non-tip requests can never
+	 * happen
+	 */
+	if (!stateless_rpc && !allow_tip_sha1_in_want)
 		goto error;
 
 	cmd.argv = argv;
-- 8< --

  reply	other threads:[~2014-10-08 13:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02 13:57 Can I fetch an arbitrary commit by sha1? Christian Halstrick
2014-10-02 14:22 ` Dan Johnson
2014-10-02 16:10   ` Jeff King
2014-10-02 17:35     ` Jonathan Nieder
2014-10-05 20:49       ` Christian Halstrick
2014-10-06 18:25     ` Patrick Donnelly
2014-10-06 18:28       ` David Lang
2014-10-07 12:34       ` Duy Nguyen
2014-10-07 13:12         ` Duy Nguyen
2014-10-07 16:52           ` Junio C Hamano
2014-10-08 13:30             ` Duy Nguyen [this message]
2014-10-09 18:08               ` 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=20141008133029.GA23010@lanh \
    --to=pclouds@gmail.com \
    --cc=batrick@batbytes.com \
    --cc=christian.halstrick@gmail.com \
    --cc=computerdruid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.