commands/status: partition results of scanIndex()
This commit is contained in:
parent
babed9a0e3
commit
0fb059d709
@ -30,35 +30,11 @@ func statusCommand(cmd *cobra.Command, args []string) {
|
||||
|
||||
statusScanRefRange(ref)
|
||||
|
||||
entries, errs, err := scanIndex(scanIndexAt)
|
||||
staged, unstaged, err := scanIndex(scanIndexAt)
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
|
||||
staged := make([]*lfs.DiffIndexEntry, 0)
|
||||
unstaged := make([]*lfs.DiffIndexEntry, 0)
|
||||
|
||||
L:
|
||||
for {
|
||||
select {
|
||||
case entry, ok := <-entries:
|
||||
if !ok {
|
||||
break L
|
||||
}
|
||||
|
||||
switch entry.Status {
|
||||
case lfs.StatusModification:
|
||||
unstaged = append(unstaged, entry)
|
||||
default:
|
||||
staged = append(staged, entry)
|
||||
}
|
||||
case err := <-errs:
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Print("\nGit LFS objects to be committed:\n")
|
||||
for _, entry := range staged {
|
||||
switch entry.Status {
|
||||
@ -77,7 +53,7 @@ L:
|
||||
Print("")
|
||||
}
|
||||
|
||||
func scanIndex(ref string) (<-chan *lfs.DiffIndexEntry, <-chan error, error) {
|
||||
func scanIndex(ref string) (staged, unstaged []*lfs.DiffIndexEntry, err error) {
|
||||
uncached, err := lfs.NewDiffIndexScanner(ref, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -88,10 +64,6 @@ func scanIndex(ref string) (<-chan *lfs.DiffIndexEntry, <-chan error, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
entries := make(chan *lfs.DiffIndexEntry)
|
||||
errs := make(chan error)
|
||||
|
||||
go func() {
|
||||
seenNames := make(map[string]struct{}, 0)
|
||||
|
||||
for _, scanner := range []*lfs.DiffIndexScanner{
|
||||
@ -106,21 +78,22 @@ func scanIndex(ref string) (<-chan *lfs.DiffIndexEntry, <-chan error, error) {
|
||||
}
|
||||
|
||||
if _, seen := seenNames[name]; !seen {
|
||||
entries <- entry
|
||||
switch entry.Status {
|
||||
case lfs.StatusModification:
|
||||
unstaged = append(unstaged, entry)
|
||||
default:
|
||||
staged = append(staged, entry)
|
||||
}
|
||||
|
||||
seenNames[name] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
errs <- err
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
close(entries)
|
||||
close(errs)
|
||||
}()
|
||||
|
||||
return entries, errs, nil
|
||||
return
|
||||
}
|
||||
|
||||
func statusScanRefRange(ref *git.Ref) {
|
||||
@ -153,23 +126,13 @@ func statusScanRefRange(ref *git.Ref) {
|
||||
}
|
||||
|
||||
func porcelainStagedPointers(ref string) {
|
||||
entries, errs, err := scanIndex(ref)
|
||||
staged, unstaged, err := scanIndex(ref)
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
|
||||
L:
|
||||
for {
|
||||
select {
|
||||
case entry, ok := <-entries:
|
||||
if !ok {
|
||||
break L
|
||||
}
|
||||
|
||||
for _, entry := range append(unstaged, staged...) {
|
||||
Print(porcelainStatusLine(entry))
|
||||
case err := <-errs:
|
||||
ExitWithError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user