Re: Can I fetch an arbitrary commit by sha1?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Can I fetch an arbitrary commit by sha1?

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:02:39

Duy Nguyen [off-list ref] 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.
quoted hunk
-- 8< --
diff --git a/upload-pack.c b/upload-pack.c
index c789ec0..493f8ee 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -454,10 +454,6 @@ 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)
-		goto error;
-
 	cmd.argv = argv;
 	cmd.git_cmd = 1;
 	cmd.no_stderr = 1;
-- 8< --
If we already let smart-http do this, I don't see any harm in letting
git protocol do the same (even though it's the the original reason why
this code exists).
--
Duy

Re: Can I fetch an arbitrary commit by sha1?

From: Duy Nguyen <hidden>
Date: 2016-06-15 23:02:40

On Tue, Oct 07, 2014 at 09:52:33AM -0700, Junio C Hamano wrote:
Duy Nguyen [off-list ref] writes:
quoted
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< --
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help