mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Use one worker per branch to speed things up
This commit is contained in:
parent
eded3ccf54
commit
de7ee9af21
1 changed files with 22 additions and 6 deletions
|
@ -1,12 +1,14 @@
|
||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/generics/set"
|
"github.com/jesseduffield/generics/set"
|
||||||
"github.com/jesseduffield/go-git/v5/config"
|
"github.com/jesseduffield/go-git/v5/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
|
@ -131,14 +133,23 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, existingMainBranc
|
||||||
|
|
||||||
onWorker(func() error {
|
onWorker(func() error {
|
||||||
mainBranches := existingMainBranches.Get()
|
mainBranches := existingMainBranches.Get()
|
||||||
if len(mainBranches) > 0 {
|
if len(mainBranches) == 0 {
|
||||||
for _, branch := range branches {
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
t := time.Now()
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
for _, branch := range branches {
|
||||||
|
branch := branch
|
||||||
|
wg.Add(1)
|
||||||
|
onWorker(func() error {
|
||||||
|
defer wg.Done()
|
||||||
baseBranch, err := self.GetBaseBranch(branch, existingMainBranches)
|
baseBranch, err := self.GetBaseBranch(branch, existingMainBranches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if baseBranch == "" {
|
if baseBranch == "" {
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
output, err := self.cmd.New(
|
output, err := self.cmd.New(
|
||||||
NewGitCmd("rev-list").
|
NewGitCmd("rev-list").
|
||||||
|
@ -156,13 +167,18 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, existingMainBranc
|
||||||
}
|
}
|
||||||
if ahead, err := strconv.Atoi(aheadBehindStr[0]); err == nil {
|
if ahead, err := strconv.Atoi(aheadBehindStr[0]); err == nil {
|
||||||
if behind, err := strconv.Atoi(aheadBehindStr[1]); err == nil {
|
if behind, err := strconv.Atoi(aheadBehindStr[1]); err == nil {
|
||||||
|
|
||||||
branch.AheadOfBaseBranch.Store(int32(ahead))
|
branch.AheadOfBaseBranch.Store(int32(ahead))
|
||||||
branch.BehindBaseBranch.Store(int32(behind))
|
branch.BehindBaseBranch.Store(int32(behind))
|
||||||
renderFunc()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
self.Log.Infof("time to get ahead/behind base branch for all branches: %s", time.Since(t))
|
||||||
|
renderFunc()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue