Skip to content

Commit f653c6b

Browse files
committed
Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes).
Signed-off-by: Filip Navara <[email protected]>
1 parent b13d5a9 commit f653c6b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

models/repo_branch.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
5858
type Branch struct {
5959
Path string
6060
Name string
61+
62+
gitRepo *git.Repository
6163
}
6264

6365
// GetBranchesByPath returns a branch by it's path
@@ -75,8 +77,9 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
7577
branches := make([]*Branch, len(brs))
7678
for i := range brs {
7779
branches[i] = &Branch{
78-
Path: path,
79-
Name: brs[i],
80+
Path: path,
81+
Name: brs[i],
82+
gitRepo: gitRepo,
8083
}
8184
}
8285
return branches, nil
@@ -228,9 +231,13 @@ func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName
228231

229232
// GetCommit returns all the commits of a branch
230233
func (branch *Branch) GetCommit() (*git.Commit, error) {
231-
gitRepo, err := git.OpenRepository(branch.Path)
232-
if err != nil {
233-
return nil, err
234+
if branch.gitRepo != nil {
235+
return branch.gitRepo.GetBranchCommit(branch.Name)
236+
} else {
237+
gitRepo, err := git.OpenRepository(branch.Path)
238+
if err != nil {
239+
return nil, err
240+
}
241+
return gitRepo.GetBranchCommit(branch.Name)
234242
}
235-
return gitRepo.GetBranchCommit(branch.Name)
236243
}

0 commit comments

Comments
 (0)