summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 03:02:14 -0500
committerJeff Carr <[email protected]>2025-10-07 03:02:14 -0500
commit75ad3a3085eaff6083724e10edb4f72bd47abc83 (patch)
tree38013fcf5c0a050c3454a708563271ce5209ec63
parent4ae05c8f12c4a2f6e8be3bf69072d1ca6459854c (diff)
remove old code
-rw-r--r--argv.go2
-rw-r--r--doPatch.go195
2 files changed, 8 insertions, 189 deletions
diff --git a/argv.go b/argv.go
index eb986a8..2e967cb 100644
--- a/argv.go
+++ b/argv.go
@@ -202,7 +202,7 @@ func (args) Appname() string {
func (a args) DoAutoComplete(pb *prep.Auto) {
if pb.Cmd == "" {
- pb.Autocomplete3([]string{"checkout", "reset", "commit", "config", "gui", "merge", "mode", "patch", "pull", "show", "add", "--version", "--force", "dev"})
+ pb.Autocomplete3([]string{"checkout", "clean", "commit", "config", "gui", "merge", "mode", "patch", "pull", "show", "add", "--version", "--force", "dev"})
} else {
pb.SubCommand(pb.Goargs...)
}
diff --git a/doPatch.go b/doPatch.go
index 2b8e031..e0d492f 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -4,6 +4,7 @@
package main
import (
+ "errors"
"os"
"path/filepath"
@@ -77,18 +78,6 @@ func doPatch() error {
}
if argv.Patch.Check != nil {
- /*
- old := findExpired()
- // old.PrintTable()
- for p := range old.IterAll() {
- log.Info("patch", p.Filename, p.Namespace)
- }
- newpb, err := old.HttpPostVerbose(myServer(), "check")
- if err != nil {
- return err
- }
- newpb.PrintTable()
- */
log.Info("do something here to find patches merged to devel")
// doMergeReport()
return nil
@@ -109,7 +98,9 @@ func doPatch() error {
continue
}
newId, newHash, err := isPatchIdApplied(repo, patch)
- if err != nil {
+ if errors.Is(err, ErrorGitPullOnDirty) {
+ log.Info("a patch with that comment couldn't be found in the repo")
+ } else if err != nil {
log.Info("err", patch.PatchId, patch.Namespace, patch.Comment, err)
return patch.Error(err)
}
@@ -130,12 +121,9 @@ func doPatch() error {
log.Info("apply results:", newhash, err)
}
}
- // return doPatchList()
return nil
}
- // list patches by default
- // return doPatchList()
log.Info("todo: fix this")
return nil
}
@@ -217,13 +205,15 @@ func doPatchGet(newpb *forgepb.Sets) {
// me.forge.Patchsets.Save()
}
+var ErrorGitPullOnDirty error = errors.New("git comment is not there")
+
func isPatchIdApplied(repo *gitpb.Repo, patch *forgepb.Patch) (string, string, error) {
comment := cleanSubject(patch.Comment)
os.Chdir(repo.GetFullPath())
newhash, err := findCommitBySubject(comment)
if err != nil {
- return "", "", log.Errorf("comment not found")
+ return "", "", ErrorGitPullOnDirty
}
patchId, err := repo.FindPatchIdByHash(newhash)
@@ -235,122 +225,6 @@ func isPatchIdApplied(repo *gitpb.Repo, patch *forgepb.Patch) (string, string, e
return patchId, newhash, nil
}
-/*
-func doPatchList() error {
- // if nothing selected, list the patches
- var changed bool
- newpatches := new(forgepb.Set)
- newpatches.Patches = forgepb.NewPatches()
- for pset := range me.forge.Patchsets.IterAll() {
- // pset.PrintTable()
- if pset.Patches.Len() == 0 {
- log.Info("pset is empty")
- me.forge.Patchsets.Delete(pset)
- changed = true
- continue
- }
- for patch := range pset.Patches.IterAll() {
- if len(patch.Data) == 0 {
- continue
- }
- patchid, hash, err := gitpb.FindPatchIdFromGitAm(patch.Data)
- if err != nil {
- log.Info("git patchid exec err", err)
- continue
- }
- // gitpb.FindPatchIdFromGitAmBroken(patch.Data) // doesn't os.Exec()
- log.Info("patch", patchid, hash, patch.CommitHash, patch.PatchId, patch.Filename, err)
- if patchid != patch.PatchId {
- log.Info("ERROR: patchid's didn't match", patchid, patch.PatchId)
- continue
- }
-
- changed = true
- if err := isPatchIdApplied(patch); err == nil {
- log.Infof("%s patchId already applied %s\n", patch.PatchId, patch.Filename)
- pset.Patches.Delete(patch)
- changed = true
- continue
- }
-
- if patch.NewHash == "" || patch.NewHash == "na" {
- if newpatches.Patches.AppendByPatchId(patch) {
- log.Infof("%s patchId added here\n", patch.PatchId)
- } else {
- log.Infof("%s patchId already here\n", patch.PatchId)
- pset.Patches.Delete(patch)
- changed = true
- }
- } else {
- if err := setNewCommitHash(patch); err != nil {
- log.Infof("%s bad check on patch failure %v\n", patch.Filename, err)
- return err
- }
- log.Infof("%s %s newhash set already here\n", patch.PatchId, patch.NewHash)
- }
- }
- }
-*/
-/*
- log.Info("NEW PATCHES TABLE")
- newpatches.PrintTable()
- for patch := range newpatches.Patches.IterAll() {
- if err := setNewCommitHash(patch); err == nil {
- log.Info("newhash set already here", patch.PatchId, patch.NewHash)
- changed = true
- continue
- }
- log.Infof("%s is new\n", patch.Filename)
- repo := me.forge.FindByGoPath(patch.Namespace)
- if repo == nil {
- log.Info("\tCould not find namespace:", patch.Namespace)
- continue
- }
- if fhelp.QuestionUser("apply this patch?") {
- newhash, err := applyAndTrackPatch(repo, patch)
- log.Info("apply results:", newhash, err)
- }
- }
-*/
-/*
- if changed {
- if err := me.forge.SavePatchsets(); err != nil {
- log.Warn("savePatchsets() failed", err)
- }
- }
- return nil
-*/
-/*
- if newpatches.Len() != 0 {
- for patch := range newpatches.IterAll() {
- log.Info("new patch:", patch.CommitHash, patch.NewHash, patch.Filename)
- repo := me.forge.FindByGoPath(patch.Namespace)
- if repo == nil {
- log.Info("\tCould not find namespace:", patch.Namespace)
- continue
- }
- }
- return log.Errorf("patches need to be applied")
- }
-
- // return doPatchList()
- applied := findApplied()
- if applied == nil || applied.Len() == 0 {
- log.Info("no patches have been appled to the devel branch yet")
- return nil
- }
- // for patch := range applied.IterAll() {
- // log.Info("SEND APPLIED: newhash:", patch.NewHash, "commithash:", patch.CommitHash, "patch", patch.Namespace)
- // }
- newpb, _, err := applied.HttpPostVerbose(myServer(), "applied")
- if err != nil {
- return err
- }
- newpb.PrintTable()
- return nil
-*/
-// }
-
// Shows repos that are:
// - git dirty repos
// - repos with 'user' branch patches not in 'devel' branch
@@ -372,58 +246,3 @@ func showWorkRepos() bool {
}
return true
}
-
-// returns bad if patches can not be applied
-// logic is not great here but it was a first pass
-func showPatchset(pset *forgepb.Set) bool {
- // don't even bother to continue if we already know it's broken
- if pset.State == "BROKEN" {
- log.Printf("Patchset Name: %-24s Author: %s <%s> IS BAD\n", pset.Name, pset.GetGitAuthorName(), pset.GetGitAuthorEmail())
- return false
- } else {
- log.Printf("Patchset Name: %-24s Author: %s <%s> IS GOOD\n", pset.Name, pset.GetGitAuthorName(), pset.GetGitAuthorEmail())
- }
-
- var count int
- var bad int
- all := pset.Patches.SortByFilename()
- for all.Scan() {
- p := all.Next()
- if IsValidPatch(p) {
- // ok
- } else {
- pset.State = "BROKEN"
- bad += 1
- }
- count += 1
- }
- log.Info("pset has", count, "total patches, ", bad, "bad patches")
- if bad == 0 {
- return true
- }
- return false
-}
-
-func IsValidPatch(p *forgepb.Patch) bool {
- basepath, filename := filepath.Split(p.Filename)
- repo := me.forge.FindByGoPath(basepath)
- if argv.Verbose {
- log.Info("start:", p.StartHash, "end:", p.CommitHash, "file:", basepath, filename, "devel version", repo.GetDevelVersion())
- }
- if repo == nil {
- log.Info("can not apply patch! repo not found", basepath, filename)
- return false
- }
- if repo.ActualDevelHash() != p.StartHash {
- log.Info("can not apply patch! devel hash mismatch", basepath, filename)
- return false
- }
- if repo.ActualDevelHash() == p.StartHash {
- log.Info("local devel hash:", repo.ActualDevelHash(), "matches patch hash", p.StartHash, "and can be applied")
- }
- log.Info("start:", p.StartHash, "end:", p.CommitHash, "file:", basepath, filename, "devel version", repo.GetDevelVersion())
- for _, line := range p.Files {
- log.Info("\t", line)
- }
- return true
-}