summaryrefslogtreecommitdiff
path: root/doDirty.go
blob: b1d162407e00fde9756d438ec29622d87daf4c29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"time"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func doDirty() {
	findAll() // select all the repos
	doCheckDirtyAndConfigSave()
	me.found = new(gitpb.Repos)
	findDirty()
	me.forge.PrintHumanTableDirty(me.found)
}

func straightCheckDirty() int {
	var count int
	var total int
	now := time.Now()
	all := me.found.All()
	for all.Scan() {
		repo := all.Next()
		total += 1
		if repo.IsDirty() {
			count += 1
		}
	}
	log.Printf("rill dirty check (%d dirty repos) (%d total repos) took:%s\n", count, total, shell.FormatDuration(time.Since(now)))
	return count
}

func doCheckDirtyAndConfigSave() {
	start := straightCheckDirty()
	now := time.Now()
	// log.Info("before findAll()")
	all := me.found.All()
	for all.Scan() {
		repo := all.Next()
		repo.CheckDirty()
	}
	end := straightCheckDirty()
	log.Printf("dirty check (%d dirty repos) (%d total repos) took:%s\n", end, me.found.Len(), shell.FormatDuration(time.Since(now)))
	if start != end {
		// todo: use internal forgepb configsave flag. should work?
		me.forge.ConfigSave()
	}
}