101 lines
2.0 KiB
Go
101 lines
2.0 KiB
Go
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
package forgepb
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.wit.com/lib/gui/shell"
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func (f *Forge) CheckDirtyQuiet() {
|
|
start := f.straightCheckDirty()
|
|
now := time.Now()
|
|
stats := f.RillRepos(doCheckDirty)
|
|
end := f.straightCheckDirty()
|
|
diff := end - start
|
|
|
|
var changed bool
|
|
for _, s := range stats {
|
|
if s.Err == nil {
|
|
} else {
|
|
// log.Info(i, s.Err)
|
|
f.SetConfigSave(true)
|
|
changed = true
|
|
}
|
|
}
|
|
if changed {
|
|
log.Printf("dirty check (%d dirty repos) (%d total repos) (%d changed) took:%s\n", end, f.Repos.Len(), diff, shell.FormatDuration(time.Since(now)))
|
|
}
|
|
}
|
|
|
|
func (f *Forge) CheckDirty() *gitpb.Repos {
|
|
start := f.straightCheckDirty()
|
|
|
|
now := time.Now()
|
|
stats := f.RillRepos(doCheckDirty)
|
|
end := f.straightCheckDirty()
|
|
diff := end - start
|
|
log.Printf("dirty check (%d dirty repos) (%d total repos) (%d changed) took:%s\n", end, f.Repos.Len(), diff, shell.FormatDuration(time.Since(now)))
|
|
|
|
for i, s := range stats {
|
|
if s.Err == nil {
|
|
} else {
|
|
log.Info(i, s.Err)
|
|
f.SetConfigSave(true)
|
|
}
|
|
}
|
|
|
|
return f.FindDirty()
|
|
}
|
|
|
|
func (f *Forge) straightCheckDirty() int {
|
|
var count int
|
|
for repo := range f.Repos.IterAll() {
|
|
if repo.IsDirty() {
|
|
count += 1
|
|
}
|
|
}
|
|
return count
|
|
}
|
|
|
|
func doCheckDirty(repo *gitpb.Repo) error {
|
|
// reset these in here for now
|
|
if repo.GetTargetVersion() != "" {
|
|
repo.TargetVersion = ""
|
|
}
|
|
|
|
if repo.IsDirty() {
|
|
if repo.CheckDirty() {
|
|
// nothing changed
|
|
} else {
|
|
log.Info("Repo changed to clean", repo.FullPath)
|
|
// f.SetConfigSave(true)
|
|
}
|
|
} else {
|
|
if repo.CheckDirty() {
|
|
log.Info("Repo changed to dirty", repo.FullPath)
|
|
return log.Errorf("%s repo changed to dirty", repo.FullPath)
|
|
// f.SetConfigSave(true)
|
|
} else {
|
|
// nothing changed
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (f *Forge) FindDirty() *gitpb.Repos {
|
|
found := gitpb.NewRepos()
|
|
|
|
for repo := range f.Repos.IterByFullPath() {
|
|
if repo.IsDirty() {
|
|
found.AppendByFullPath(repo)
|
|
}
|
|
}
|
|
return found
|
|
}
|