mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	On open repository open common cat file batch and batch-check (#15667)
Use common git cat-file --batch and git cat-file --batch-check to
significantly reduce calls to git.
    
Signed-off-by: Andrew Thornton <art27@cantab.net>
			
			
This commit is contained in:
		@@ -13,12 +13,30 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// IsReferenceExist returns true if given reference exists in the repository.
 | 
			
		||||
func (repo *Repository) IsReferenceExist(name string) bool {
 | 
			
		||||
	if name == "" {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wr, rd, cancel := repo.CatFileBatchCheck()
 | 
			
		||||
	defer cancel()
 | 
			
		||||
	_, err := wr.Write([]byte(name + "\n"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log("Error writing to CatFileBatchCheck %v", err)
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	_, _, _, err = ReadBatchLine(rd)
 | 
			
		||||
	return err == nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsBranchExist returns true if given branch exists in current repository.
 | 
			
		||||
func (repo *Repository) IsBranchExist(name string) bool {
 | 
			
		||||
	if name == "" {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return IsReferenceExist(repo.Path, BranchPrefix+name)
 | 
			
		||||
 | 
			
		||||
	return repo.IsReferenceExist(BranchPrefix + name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetBranches returns branches from the repository, skipping skip initial branches and
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user