diff options
| -rw-r--r-- | doFix.deleteuser.go | 49 | ||||
| -rw-r--r-- | doStats.go | 76 |
2 files changed, 74 insertions, 51 deletions
diff --git a/doFix.deleteuser.go b/doFix.deleteuser.go index 6247be5..9d62a3c 100644 --- a/doFix.deleteuser.go +++ b/doFix.deleteuser.go @@ -334,52 +334,3 @@ func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.GitTag) (err return log.Errorf("NOT SAFE"), notes } - -// todo: these names are all horrible -// delete localRef if it's completely contained in the masterRef -func safeDelete(repo *gitpb.Repo, deleteHash string, keepHash string) error { - // compare the branches - hashok, hashbad, cmd1, cmd2, err := repo.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", repo.FullPath, err, "NOT SAFE TO DELETE. Reload()?", cmd1) - log.Printf("%-13.13s %-55.55s err='%v' %s %v\n", "CMD ERR", repo.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 - log.Printf("%-13.13s %-55.55s %v\n", "OK delete", repo.FullPath, parts) - } - - if len(hashbad) > 0 { - log.Printf("%-13.13s %-55.55s %v\n", "BAD cmd", repo.FullPath, 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 - log.Printf("%-13.13s %-55.55s %v\n", "BAD keep", repo.FullPath, parts) - } - - 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", repo.FullPath, cmd1, "") - log.Printf("%-13.13s %-55.55s %v %s\n", "CMD OK", repo.FullPath, cmd2, "") - log.Printf("%-13.13s %-55.55s %v %s\n", "SAFE TO DELETE", repo.FullPath, cmd, "add --fix") - if argv.Fix { - err := repo.RunVerbose(cmd) - if err != nil { - log.Info(deleteHash, repo.FullPath) - s := "local user branch could not be deleted" - me.sh.BadExit(s, err) - } - } - return ErrorNeedArgvFix - } - - return log.Errorf("NOT SAFE") -} @@ -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") +} |
