aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs
diff options
context:
space:
mode:
authorAlexander Egorenkov <Alexander.Egorenkov@ibm.com>2020-11-20 14:09:02 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-20 14:57:09 +0100
commit740ff4615a9ced4a8a016365aa44674b9b0e807d (patch)
treeb729c92a0a53386d6bcc6e3ac3de67aa17721a23 /pkg/vcs
parent0767f13fbd87c99aea7893eb64199b76be42cd61 (diff)
pkg/vcs/git: optimize CheckoutBranch
Fetching a remote branch w/o the corresponding remote with git disables delta optimization on the server's side and the git client is forced to download the complete branch even if it already has got an older version. This leads to several problems as: * Long fetch time * Limitless growth of local git repo due to git fetch creating a new pack file every time Create a remote before fetching to fix the above issues. With a remote, only the first fetch will take some time and all the following ones shall be very fast. Furthermore, git fetch will avoid creating many pack files in .git/objects/pack. Signed-off-by: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
Diffstat (limited to 'pkg/vcs')
-rw-r--r--pkg/vcs/git.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go
index 5b1efa33a..2f1f0f301 100644
--- a/pkg/vcs/git.go
+++ b/pkg/vcs/git.go
@@ -99,7 +99,10 @@ func (git *git) CheckoutBranch(repo, branch string) (*Commit, error) {
if err := git.repair(); err != nil {
return nil, err
}
- _, err := git.git("fetch", repo, branch)
+ repoHash := hash.String([]byte(repo))
+ // Ignore error as we can double add the same remote and that will fail.
+ git.git("remote", "add", repoHash, repo)
+ _, err := git.git("fetch", repoHash, branch)
if err != nil {
return nil, err
}