a fast CheckDirty() function for forge
30GB in 1200 repos in under a second on my fast laptop
This commit is contained in:
parent
3ec4b29886
commit
50351298b6
|
@ -0,0 +1,58 @@
|
||||||
|
// 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) CheckDirty() *gitpb.Repos {
|
||||||
|
start := f.straightCheckDirty()
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
f.RillFuncError(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)))
|
||||||
|
|
||||||
|
// todo: actually detect if this needs to be changed?
|
||||||
|
f.SetConfigSave(true)
|
||||||
|
f.ConfigSave()
|
||||||
|
|
||||||
|
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 {
|
||||||
|
repo.CheckDirty()
|
||||||
|
// reset these in here for now
|
||||||
|
if repo.GetTargetVersion() != "" {
|
||||||
|
repo.TargetVersion = ""
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue