Bug 573390 - upload pack: can't allow fetching any sha1 in the protocol v0/v1
Summary: upload pack: can't allow fetching any sha1 in the protocol v0/v1
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 6.5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 580632 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-05-06 00:27 EDT by Kyle Zhao CLA
Modified: 2023-02-21 18:56 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle Zhao CLA 2021-05-06 00:27:59 EDT
[ git version ]
CGit/2.23.0
JGit/5.11.0.202103091610-r

I created the instance of org.eclipse.jgit.transport.UploadPack like this for all requests:

public UploadPack create(...) {
   //.....    
   uploadPack.setRequestPolicy(UploadPack.RequestPolicy.ANY);
   return uploadPack;
}

When I tried to fetch an unreachable commit:

$ GIT_TRACE_PACKET=1 GIT_CURL_VERBOSE=1 git fetch origin 8276f1c3db57ac6d1a15f0433d5bd35065a6557c

12:50:22.976115 pkt-line.c:80 packet:fetch< 8a7570a00a2a5f94dd83e13a89004e3c0d057ac0 HEAD\0 include-tag multi_ack_detailed multi_ack ofs-delta side-band side-band-64k thin-pack no-progress shallow agent=JGit/5.11.0.202103091610-r
 filter symref=HEAD:refs/heads/master
12:50:22.976633 pkt-line.c:80 packet:fetch< 8a7570a00a2a5f94dd83e13a89004e3c0d057ac0 refs/heads/master
12:50:22.976663 pkt-line.c:80 packet:fetch< b6484bdf45979938d610ae2d92027ef12a909992 refs/tags/v1.0
12:50:22.976677 pkt-line.c:80 packet:fetch< 0000
12:50:22.983349 pkt-line.c:80 packet:fetch> 0000
error: Server does not allow request for unadvertised object 8276f1c3db57ac6d1a15f0433d5bd35065a6557c

the fetch-pack process of CGit didn't send the SHA-1 it wants but reported an error.

After I read [1] in CGit, I found that Git server must send capability allow-tip-sha1-in-want or allow-reachable-sha1-in-want to allow fetching any sha1 in the protocol v0/v1. (v2 supports these by default.)

CGit sends both of these capabilities, according to [2].

Besides the reason in [2], allowing fetching any sha1 is important for the partital clone, too. We expect JGit to support this feature in any version of the protocol, refer to CGit.

[1] https://github.com/git/git/blob/master/fetch-pack.c 
[2] https://github.com/git/git/commit/f8edeaa05d8623a9f6dad408237496c51101aad8
Comment 1 Eclipse Genie CLA 2021-05-06 00:43:18 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/180276
Comment 2 Eclipse Genie CLA 2021-05-20 00:56:07 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/180794
Comment 3 Kyle Zhao CLA 2021-05-20 06:00:03 EDT
With these changes, we can simply enable Partial Clone[1] on your git server without rewriting code.


git config --global uploadpack.allowAnySHA1InWant true
git config --global uploadPack.allowFilter true

And solve Gerrit problem[2], too.

When uploadpack.allowAnySHA1InWant is true, git can fetch any sha1 (even tree/blob object).

[1] https://git-scm.com/docs/partial-clone
[2] https://groups.google.com/g/repo-discuss/c/NYr9FnbJY90
Comment 4 Longping Tang CLA 2022-08-09 04:24:48 EDT
(In reply to Kyle Zhao from comment #3)
> With these changes, we can simply enable Partial Clone[1] on your git server
> without rewriting code.
> 
> 
> git config --global uploadpack.allowAnySHA1InWant true
> git config --global uploadPack.allowFilter true
> 
> And solve Gerrit problem[2], too.
> 
> When uploadpack.allowAnySHA1InWant is true, git can fetch any sha1 (even
> tree/blob object).
> 
> [1] https://git-scm.com/docs/partial-clone
> [2] https://groups.google.com/g/repo-discuss/c/NYr9FnbJY90

I tried to enable partial clone for my gerrit server with the below configuration:
git config --global uploadpack.allowAnySHA1InWant true
git config --global uploadPack.allowFilter true

Doing partial clone with command: git clone --filter=blob:none ssh://GERRIT_SERVER/a/test.

clone works fine, but checkout gives an error:

error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: unable to read sha1 file of hello.txt (3b18e512dba79e4c8300dd08aeb37f8e728b8dad)
error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: unable to read sha1 file of src/hello.go (040ee0a2fbdbc63fc4eb04563cad44496de2f2ca)
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.

The version of my gerrit server is 3.0.1. Does the jgit used by this version of gerrit support partial clone?
Comment 5 Matthias Sohn CLA 2022-08-09 07:36:52 EDT
These changes are still in review hence no existing Gerrit release has them included.
Comment 6 Longping Tang CLA 2022-08-09 21:48:03 EDT
(In reply to Matthias Sohn from comment #5)
> These changes are still in review hence no existing Gerrit release has them
> included.

Thank you for your response.

Is there any way to make gerrit 3.0.1 support partial clone now?

Do I have to update jgit in order to support partial clone?
Comment 7 Matthias Sohn CLA 2022-08-10 06:07:22 EDT
(In reply to Longping Tang from comment #6)
> (In reply to Matthias Sohn from comment #5)
> > These changes are still in review hence no existing Gerrit release has them
> > included.
> 
> Thank you for your response.
> 
> Is there any way to make gerrit 3.0.1 support partial clone now?

You should ask this question on the gerrit mailing list [1].
Gerrit 3.0 is EOL since Dec 1, 2020 [2]. So I think your best way forward is to upgrade Gerrit to a supported release, 3.4.5, 3.5.2 or 3.6.1 [3]. Always upgrade to the latest service release to benefit from all bug fixes and improvements.

> Do I have to update jgit in order to support partial clone?

Which features of partial cloning are you looking for ?

[1] https://groups.google.com/g/repo-discuss
[2] https://www.gerritcodereview.com/support.html
[3] https://www.gerritcodereview.com/releases-readme.html
Comment 8 Longping Tang CLA 2022-08-10 22:19:36 EDT
(In reply to Matthias Sohn from comment #7)
> (In reply to Longping Tang from comment #6)
> > (In reply to Matthias Sohn from comment #5)
> > > These changes are still in review hence no existing Gerrit release has them
> > > included.
> > 
> > Thank you for your response.
> > 
> > Is there any way to make gerrit 3.0.1 support partial clone now?
> 
> You should ask this question on the gerrit mailing list [1].
> Gerrit 3.0 is EOL since Dec 1, 2020 [2]. So I think your best way forward is
> to upgrade Gerrit to a supported release, 3.4.5, 3.5.2 or 3.6.1 [3]. Always
> upgrade to the latest service release to benefit from all bug fixes and
> improvements.

I have asked the question a few days ago, but no reply.
[1] https://groups.google.com/g/repo-discuss/c/fJvdpyEGoYg 


> > Do I have to update jgit in order to support partial clone?
> 
> Which features of partial cloning are you looking for ?
> 
I want to use the --filter=blob:none option.

I tried to enable partial clone for my gerrit server with the below configuration:
git config --global uploadpack.allowAnySHA1InWant true
git config --global uploadPack.allowFilter true

Doing partial clone with command: git clone --filter=blob:none ssh://GERRIT_SERVER/a/test.

clone works fine, but checkout gives an error:

error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: Server does not allow request for unadvertised object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
error: unable to read sha1 file of hello.txt (3b18e512dba79e4c8300dd08aeb37f8e728b8dad)
error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: Server does not allow request for unadvertised object 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
error: unable to read sha1 file of src/hello.go (040ee0a2fbdbc63fc4eb04563cad44496de2f2ca)
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.

Gerrit uses jgit, I guess this error is related to jgit. Is the error caused by the lack of these two changes [1][2]?
[1]https://git.eclipse.org/r/c/jgit/jgit/+/180276
[2]https://git.eclipse.org/r/c/jgit/jgit/+/180794
Comment 9 Kyle Zhao CLA 2022-10-11 05:49:49 EDT
(In reply to Longping Tang from comment #8)
> (In reply to Matthias Sohn from comment #7)
> > (In reply to Longping Tang from comment #6)
> > > (In reply to Matthias Sohn from comment #5)
> > > > These changes are still in review hence no existing Gerrit release has them
> > > > included.
> > > 
> > > Thank you for your response.
> > > 
> > > Is there any way to make gerrit 3.0.1 support partial clone now?
> > 
> > You should ask this question on the gerrit mailing list [1].
> > Gerrit 3.0 is EOL since Dec 1, 2020 [2]. So I think your best way forward is
> > to upgrade Gerrit to a supported release, 3.4.5, 3.5.2 or 3.6.1 [3]. Always
> > upgrade to the latest service release to benefit from all bug fixes and
> > improvements.
> 
> I have asked the question a few days ago, but no reply.
> [1] https://groups.google.com/g/repo-discuss/c/fJvdpyEGoYg 
> 
> 
> > > Do I have to update jgit in order to support partial clone?
> > 
> > Which features of partial cloning are you looking for ?
> > 
> I want to use the --filter=blob:none option.
> 
> I tried to enable partial clone for my gerrit server with the below
> configuration:
> git config --global uploadpack.allowAnySHA1InWant true
> git config --global uploadPack.allowFilter true
> 
> Doing partial clone with command: git clone --filter=blob:none
> ssh://GERRIT_SERVER/a/test.
> 
> clone works fine, but checkout gives an error:
> 
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: unable to read sha1 file of hello.txt
> (3b18e512dba79e4c8300dd08aeb37f8e728b8dad)
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: unable to read sha1 file of src/hello.go
> (040ee0a2fbdbc63fc4eb04563cad44496de2f2ca)
> fatal: unable to checkout working tree
> warning: Clone succeeded, but checkout failed.
> 
> Gerrit uses jgit, I guess this error is related to jgit. Is the error caused
> by the lack of these two changes [1][2]?
> [1]https://git.eclipse.org/r/c/jgit/jgit/+/180276
> [2]https://git.eclipse.org/r/c/jgit/jgit/+/180794

You are right, To support partial clone, jgit should call uploadPack.setRequestPolicy(UploadPack.RequestPolicy.ANY);

This has been verified at my team, we use our own compiled version of jgit which is able to support partial clone.

I've searched for gerrit's code and it looks like there is no part to modify the RequestPolicy of uploadPack.


> git config --global uploadpack.allowAnySHA1InWant true
> git config --global uploadPack.allowFilter true

These didn't work because my patches were not merged into the jgit trunk yet.

It looks like my patches conflict with the master branch, I will update them.
Comment 10 Kyle Zhao CLA 2022-10-11 06:07:16 EDT
(In reply to Longping Tang from comment #8)
> (In reply to Matthias Sohn from comment #7)
> > (In reply to Longping Tang from comment #6)
> > > (In reply to Matthias Sohn from comment #5)
> > > > These changes are still in review hence no existing Gerrit release has them
> > > > included.
> > > 
> > > Thank you for your response.
> > > 
> > > Is there any way to make gerrit 3.0.1 support partial clone now?
> > 
> > You should ask this question on the gerrit mailing list [1].
> > Gerrit 3.0 is EOL since Dec 1, 2020 [2]. So I think your best way forward is
> > to upgrade Gerrit to a supported release, 3.4.5, 3.5.2 or 3.6.1 [3]. Always
> > upgrade to the latest service release to benefit from all bug fixes and
> > improvements.
> 
> I have asked the question a few days ago, but no reply.
> [1] https://groups.google.com/g/repo-discuss/c/fJvdpyEGoYg 
> 
> 
> > > Do I have to update jgit in order to support partial clone?
> > 
> > Which features of partial cloning are you looking for ?
> > 
> I want to use the --filter=blob:none option.
> 
> I tried to enable partial clone for my gerrit server with the below
> configuration:
> git config --global uploadpack.allowAnySHA1InWant true
> git config --global uploadPack.allowFilter true
> 
> Doing partial clone with command: git clone --filter=blob:none
> ssh://GERRIT_SERVER/a/test.
> 
> clone works fine, but checkout gives an error:
> 
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: Server does not allow request for unadvertised object
> 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
> error: unable to read sha1 file of hello.txt
> (3b18e512dba79e4c8300dd08aeb37f8e728b8dad)
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: Server does not allow request for unadvertised object
> 040ee0a2fbdbc63fc4eb04563cad44496de2f2ca
> error: unable to read sha1 file of src/hello.go
> (040ee0a2fbdbc63fc4eb04563cad44496de2f2ca)
> fatal: unable to checkout working tree
> warning: Clone succeeded, but checkout failed.
> 
> Gerrit uses jgit, I guess this error is related to jgit. Is the error caused
> by the lack of these two changes [1][2]?
> [1]https://git.eclipse.org/r/c/jgit/jgit/+/180276
> [2]https://git.eclipse.org/r/c/jgit/jgit/+/180794

Or you can try to implement gerrit's interface UploadPackInitializer.

Try to execute 

  uploadPack.setRequestPolicy(UploadPack.RequestPolicy.ANY);

in method com.google.gerrit.server.git.UploadPackInitializer#init(Project.NameKey project, UploadPack uploadPack);
Comment 11 Matthias Sohn CLA 2022-12-02 02:43:44 EST
*** Bug 580632 has been marked as a duplicate of this bug. ***