smarter implementation of CheckDirty()

This commit is contained in:
Jeff Carr 2025-09-04 18:32:10 -05:00
parent 89e6fd0805
commit 4cac4386f5
1 changed files with 47 additions and 5 deletions

View File

@ -11,18 +11,43 @@ import (
"go.wit.com/log" "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 { func (f *Forge) CheckDirty() *gitpb.Repos {
start := f.straightCheckDirty() start := f.straightCheckDirty()
now := time.Now() now := time.Now()
f.RillFuncError(doCheckDirty) stats := f.RillRepos(doCheckDirty)
end := f.straightCheckDirty() end := f.straightCheckDirty()
diff := end - start 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))) 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)))
// todo: actually detect if this needs to be changed? for i, s := range stats {
f.SetConfigSave(true) if s.Err == nil {
f.ConfigSave() } else {
log.Info(i, s.Err)
f.SetConfigSave(true)
}
}
return f.FindDirty() return f.FindDirty()
} }
@ -38,11 +63,28 @@ func (f *Forge) straightCheckDirty() int {
} }
func doCheckDirty(repo *gitpb.Repo) error { func doCheckDirty(repo *gitpb.Repo) error {
repo.CheckDirty()
// reset these in here for now // reset these in here for now
if repo.GetTargetVersion() != "" { if repo.GetTargetVersion() != "" {
repo.TargetVersion = "" 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 return nil
} }