6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 18:34:51 +00:00

Move status loader into the git package

- Loading status belongs to git domain so it makes more sense for it to
  be in git package.
- It also makes the `list` file simpler.
- Because status loader is now part of the RepoFinder, the ugly Repo interface is no longer necessary.
This commit is contained in:
Grzegorz Dlugoszewski
2020-07-26 17:19:45 +02:00
parent 942af7df6d
commit 3aef50a4d0
5 changed files with 141 additions and 144 deletions

View File

@@ -5,7 +5,6 @@ import (
"git-get/pkg/cfg"
"git-get/pkg/git"
"git-get/pkg/print"
"sort"
"strings"
)
@@ -18,16 +17,15 @@ type ListCfg struct {
// List executes the "git list" command.
func List(c *ListCfg) error {
paths, err := git.NewRepoFinder(c.Root).Find()
if err != nil {
finder := git.NewRepoFinder(c.Root)
if err := finder.Find(); err != nil {
return err
}
loaded := loadAll(paths, c.Fetch)
printables := make([]print.Printable, len(loaded))
for i := range loaded {
printables[i] = loaded[i]
statuses := finder.LoadAll(c.Fetch)
printables := make([]print.Printable, len(statuses))
for i := range statuses {
printables[i] = statuses[i]
}
switch c.Output {
@@ -43,33 +41,3 @@ func List(c *ListCfg) error {
return nil
}
// loadAll runs a separate goroutine to open, fetch (if asked to) and load status of git repo
func loadAll(paths []string, fetch bool) []*Loaded {
var ll []*Loaded
loadedChan := make(chan *Loaded)
for _, path := range paths {
go func(path string) {
loadedChan <- Load(path, fetch)
}(path)
}
for l := range loadedChan {
ll = append(ll, l)
// Close the channell when loaded all paths
if len(ll) == len(paths) {
close(loadedChan)
}
}
// sort the loaded slice by path
sort.Slice(ll, func(i, j int) bool {
return strings.Compare(ll[i].path, ll[j].path) < 0
})
return ll
}