Open
Description
When I cloned a repo about 1G in size, it consumed my 1G of memory and generated a lot of stacks
// 拉取代码
func (p *Puller) Pull() (string, error) {
p.logger.Printf("Pulling %s\n", p.repo)
options := git.CloneOptions{
URL: p.repo,
Progress: p.writer,
SingleBranch: true,
ReferenceName: plumbing.ReferenceName("refs/heads/dev"),
Depth: 1,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
}
if p.auth != nil {
options.Auth = *p.auth
}
tempDir := os.TempDir()
rootPath := filepath.Join(tempDir, p.taskID)
p.logger.Printf("拉取项目到目录 %s\n", rootPath)
// clone project
fs := osfs.New(rootPath)
gitDir := filepath.Join(rootPath, ".git")
storage := filesystem.NewStorage(osfs.New(gitDir), cache.NewObjectLRU(cache.MiByte*50))
_, err := git.CloneContext(p.ctx, storage, fs, &options)
if err != nil {
return "", errors.WithStack(err)
}
return rootPath, nil
}