summaryrefslogtreecommitdiff
path: root/doStats.go
diff options
context:
space:
mode:
Diffstat (limited to 'doStats.go')
-rw-r--r--doStats.go76
1 files changed, 74 insertions, 2 deletions
diff --git a/doStats.go b/doStats.go
index 38ceb15..a7317b1 100644
--- a/doStats.go
+++ b/doStats.go
@@ -41,7 +41,9 @@ func doVerify() (string, error) {
HEAD, err := refHash(repo, "remotes/origin/HEAD")
allerr = errors.Join(allerr, err)
log.Printf("user=%10.10s master=%10.10s HEAD=%10.10s\n", user, master, HEAD)
- safeDelete(repo, user, HEAD) // delete user if safely contained in HEAD
+
+ safeDelete(repo, user, HEAD) // delete user if safely contained in HEAD
+ safeDelete(repo, "refs/heads/jcarr", "refs/remotes/origin/HEAD") // delete user if safely contained in HEAD
return s, allerr
}
@@ -74,10 +76,12 @@ func doStats(r *gitpb.Repo) (string, error) {
}
}
+ // set the repo to have the stats
+ r.Stats = pb
+
if counter > 0 {
pb.SaveVerbose()
}
- // build()
return s, nil
}
@@ -153,3 +157,71 @@ func last100(r *gitpb.Repo, pb *gitpb.Stats) (int, error) {
}
return counter, allerr
}
+
+func findPatchIdInStats(pb *gitpb.Stats, patchId string) *gitpb.Stat {
+ for stat := range pb.IterAll() {
+ if stat.PatchId == patchId {
+ return stat
+ }
+ }
+ // log.Info("findPatchId searched in", pb.Len(), "stats")
+ return nil
+}
+
+// delete localRef if it's completely contained in the masterRef
+func safeDelete(r *gitpb.Repo, deleteHash string, keepHash string) error {
+ // compare the branches
+ hashok, hashbad, cmd1, cmd2, err := r.CompareHashes(keepHash, deleteHash)
+
+ if err != nil {
+ // things are really really messed up. might be 'branchless' at this point (?)
+ log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", r.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1)
+ log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", r.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd2)
+ return err
+ }
+
+ // things only in the master branch (safe to ignore)
+ for _, line := range hashok {
+ parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL
+ patchId, err := r.FindPatchIdByHash(parts[0])
+ _ = err
+ log.Printf("%-13.13s %-55.55s hId %10.10s pId %10.10s %v\n", "OK delete", r.FullPath, parts[0], patchId, parts[2:])
+ }
+
+ if len(hashbad) > 0 {
+ log.Printf("%-13.13s %v\n", "BAD cmd", cmd1)
+ }
+ // things still only in the local branch (bad to delete)
+ for _, line := range hashbad {
+ parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL
+ patchId, err := r.FindPatchIdByHash(parts[0])
+ _ = err
+ searchResult := log.Sprintf("NOPE(%d)", r.Stats.Len())
+ stat := findPatchIdInStats(r.Stats, patchId)
+ if stat != nil {
+ searchResult = log.Sprintf("YES %10.10s %s", stat.PatchId, stat.Name)
+ }
+
+ log.Printf("%-13.13s %-55.55s hId %10.10s pId %10.10s %s %v\n", "BAD keep", r.FullPath, parts[0], patchId, searchResult, parts[2:])
+ }
+
+ if len(hashbad) == 0 {
+ // todo: force checkout to local master branch
+ // before doing this
+ cmd := []string{"git", "update-ref", "-d", deleteHash}
+ log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", r.FullPath, cmd1, "")
+ log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", r.FullPath, cmd2, "")
+ log.Printf("%-13.13s %-55.55s %v %s\n", "SAFE TO DELETE", r.FullPath, cmd, "add --fix")
+ if argv.Fix {
+ err := r.RunVerbose(cmd)
+ if err != nil {
+ log.Info(deleteHash, r.FullPath)
+ s := "local user branch could not be deleted"
+ me.sh.BadExit(s, err)
+ }
+ }
+ return ErrorNeedArgvFix
+ }
+
+ return log.Errorf("NOT SAFE")
+}