Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Exact equivalent to "git clone -b <branch> <repository>" in jgit
Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1847014] Tue, 12 October 2021 09:12 Go to next message
Esteban Aliverti is currently offline Esteban AlivertiFriend
Messages: 3
Registered: October 2021
Junior Member
I have a local mirror of a quite big repository.

If I do:
git clone -b branch-name /home/where/my/local/mirror/is clone-dir


I end up with a clone of my local mirror in the "clone-dir" repository in 4 seconds.

While trying to do the same thing using jgit I can't make it faster than 220 seconds:
Git.cloneRepository()
        .setBranch("branch-name")
        .setURI("file:///home/where/my/local/mirror/is")
        .setDirectory(new File("/tmp/clone-dir"))
        .call();


I would like to understand what are the differences between the 2 approaches and if there is a way in jgit to do exactly what the "git clone" command is doing.

Thanks,
Re: Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1847034 is a reply to message #1847014] Tue, 12 October 2021 18:15 Go to previous messageGo to next message
Aaron Hawley is currently offline Aaron HawleyFriend
Messages: 3
Registered: June 2019
Junior Member
Does using setCloneAllBranches(false) make it run faster?
Re: Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1847046 is a reply to message #1847034] Wed, 13 October 2021 06:42 Go to previous messageGo to next message
Esteban Aliverti is currently offline Esteban AlivertiFriend
Messages: 3
Registered: October 2021
Junior Member
I tried it, yes, and it didn't make any difference.

I should probably mention that the local mirror I'm using contains a reference to a Bitbucket repository in its `config` file:

[remote "origin"]
    url = ssh://some-body@some.remote.bitbucket.repo.git
    fetch = +refs/*:refs/*
    mirror = true


If I add a `TextProgressMonitor` to the clone operation, then I see this:

remote: Counting objects: 74573
remote: Finding sources: 100% (1173572/1173572)
remote: Getting sizes:  100% (513288/513288)
remote: Compressing objects: 100% (1321579/1321579)
Receiving objects:      100% (1173572/1173572)
Resolving deltas:       100% (618623/618623)
Checking out files:     100% (19060/19060)


The "Receiving objects" and 'Resolving deltas" steps are taking most of the time.

So, it seems like if `jgit` is actually contacting the remote server even if it shouldn't.
Re: Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1847049 is a reply to message #1847046] Wed, 13 October 2021 06:59 Go to previous messageGo to next message
Esteban Aliverti is currently offline Esteban AlivertiFriend
Messages: 3
Registered: October 2021
Junior Member
I executed `jgit` again but this time being offline and the amount of time it takes doesn't change. So I guess that the issue is not related to `jgit` contacting a slow remote repository after all.

[Updated on: Wed, 13 October 2021 06:59]

Report message to a moderator

Re: Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1848414 is a reply to message #1847049] Wed, 01 December 2021 14:50 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1214
Registered: July 2009
Senior Member
if you clone using a local path without specifying the file protocol c git will by default use the -l option which
hard-links all objects under .git/objects to your local mirror instead of cloning them, see [1]

try

git clone -b branch-name file:///home/where/my/local/mirror/is clone-dir

[1] https://git-scm.com/docs/git-clone#Documentation/git-clone.txt--l
Re: Exact equivalent to "git clone -b <branch> <repository>" in jgit [message #1848416 is a reply to message #1848414] Wed, 01 December 2021 14:58 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1214
Registered: July 2009
Senior Member
The jgit CloneCommand has no implementation of the -l/--local option
Previous Topic:Git-upload-pack not permitted on Github
Next Topic:EGit 5.12 SSH clone failing due to Signature encoding error
Goto Forum:
  


Current Time: Wed Dec 07 08:17:52 GMT 2022

Powered by FUDForum. Page generated in 0.03195 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top