summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 02:36:53 -0500
committerJeff Carr <[email protected]>2025-10-07 02:36:53 -0500
commit4ae05c8f12c4a2f6e8be3bf69072d1ca6459854c (patch)
treeaf3bc72e22c0037c0796b4b433b3beb402af2f48
parent957f860213c582970d458544cb6b3956da468cd7 (diff)
ready to purge old codev0.25.62
-rw-r--r--doPatch.go172
-rw-r--r--windowPatches.go52
2 files changed, 114 insertions, 110 deletions
diff --git a/doPatch.go b/doPatch.go
index 1d87121..2b8e031 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
+ "go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@@ -95,6 +96,40 @@ func doPatch() error {
if argv.Patch.List != nil {
log.Info("todo: fix this")
+ curpatches := forgepb.NewPatches()
+ curpatches.Filename = "/tmp/curpatches.pb"
+ if err := curpatches.Load(); err != nil {
+ return err
+ }
+ curpatches.PrintTable()
+ for patch := range curpatches.IterAll() {
+ repo := me.forge.Repos.FindByNamespace(patch.Namespace)
+ if repo == nil {
+ log.Info("no namespace", patch.PatchId, patch.Namespace, patch.Comment)
+ continue
+ }
+ newId, newHash, err := isPatchIdApplied(repo, patch)
+ if err != nil {
+ log.Info("err", patch.PatchId, patch.Namespace, patch.Comment, err)
+ return patch.Error(err)
+ }
+ if (newId == patch.PatchId) && (newHash == patch.CommitHash) {
+ log.Info(patch.PatchId, "patch made here", patch.Comment)
+ continue
+ }
+ if newId == patch.PatchId {
+ log.Info(patch.PatchId, "patch already applied", patch.Comment)
+ continue
+ }
+ if newId != patch.PatchId {
+ log.Info(patch.PatchId, "probably duplicate subject", patch.Comment)
+ }
+ log.Info("new patch", patch.PatchId, patch.Comment)
+ if fhelp.QuestionUser("apply this patch?") {
+ newhash, err := applyPatch(repo, patch)
+ log.Info("apply results:", newhash, err)
+ }
+ }
// return doPatchList()
return nil
}
@@ -105,6 +140,29 @@ func doPatch() error {
return nil
}
+func applyPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) {
+ _, filen := filepath.Split(p.Filename)
+ tmpname := filepath.Join("/tmp", filen)
+ log.Info("saving as", tmpname, p.Filename)
+ raw, err := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+ if err != nil {
+ return "", err
+ }
+ raw.Write(p.Data)
+ raw.Close()
+
+ cmd := []string{"git", "am", tmpname}
+ err = repo.RunVerbose(cmd)
+ if err != nil {
+ log.Info("git am failed. run 'git am --abort' here")
+ return "", log.Errorf("git am failed")
+ }
+
+ log.Info("Try to find hash value now")
+
+ return p.NewHash, log.Errorf("did not lookup new hash")
+}
+
func doPatchGet(newpb *forgepb.Sets) {
// var changed bool
curpatches := forgepb.NewPatches()
@@ -159,32 +217,25 @@ func doPatchGet(newpb *forgepb.Sets) {
// me.forge.Patchsets.Save()
}
-func isPatchIdApplied(patch *forgepb.Patch) error {
- repo := me.forge.FindByGoPath(patch.Namespace)
- if repo == nil {
- return log.Errorf("could not find repo %s", patch.Namespace)
- }
-
+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("patch: not found hash: %s %s %s %s %v", patch.CommitHash, patch.Namespace, comment, newhash, err)
+ return "", "", log.Errorf("comment not found")
}
patchId, err := repo.FindPatchIdByHash(newhash)
if err != nil {
- return err
+ return "", "", err
}
- patch.PatchId = patchId
- patch.NewHash = newhash
-
- log.Infof("%s %s patch: found hash: %s %s\n", patch.CommitHash, newhash, patch.Namespace, comment)
- return nil
+ // log.Infof("%s %s found hash by comment %s \n", patchId, newhash, patch.Comment)
+ return patchId, newhash, nil
}
+/*
func doPatchList() error {
// if nothing selected, list the patches
var changed bool
@@ -239,63 +290,66 @@ func doPatchList() error {
}
}
}
- /*
- 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)
- }
+*/
+/*
+ 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
- }
+*/
+/*
+ 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 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 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
diff --git a/windowPatches.go b/windowPatches.go
index fa1d299..65f54b7 100644
--- a/windowPatches.go
+++ b/windowPatches.go
@@ -12,7 +12,6 @@ import (
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb"
- "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -90,7 +89,7 @@ func applyPatchNew(p *forgepb.Patch) error {
log.Info("Could not figure out repo path", rn)
return log.Errorf("%s namespace?\n", rn)
}
- if _, err := applyAndTrackPatch(repo, p); err != nil {
+ if _, err := applyPatch(repo, p); err != nil {
cmd := []string{"git", "am", "--abort"}
err := repo.RunVerbose(cmd)
log.Info("warn user of git am error", err)
@@ -158,12 +157,6 @@ func AddPatchesPB(tbox *gui.Node, pb *forgepb.Patches) *forgepb.PatchesTable {
return t
}
-func applyPatch(repo *gitpb.Repo, filename string) error {
- cmd := []string{"git", "am", filename}
- err := repo.RunVerbose(cmd)
- return err
-}
-
func savePatch(p *forgepb.Patch) (string, error) {
_, filen := filepath.Split(p.Filename)
tmpname := filepath.Join("/tmp", filen)
@@ -177,46 +170,3 @@ func savePatch(p *forgepb.Patch) (string, error) {
return tmpname, nil
}
-
-func applyAndTrackPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) {
- _, filen := filepath.Split(p.Filename)
- tmpname := filepath.Join("/tmp", filen)
- log.Info("saving as", tmpname, p.Filename)
- raw, err := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
- if err != nil {
- return "", err
- }
- raw.Write(p.Data)
- raw.Close()
-
- cmd := []string{"git", "am", tmpname}
- err = repo.RunVerbose(cmd)
- if err != nil {
- log.Info("git am failed. run 'git am --abort' here")
- return "", log.Errorf("git am failed")
- }
-
- log.Info("Try to find hash value now")
-
- p.NewHash = "fixme applyAndTrack"
- if setNewHash(p, p.NewHash) {
- log.Info("setting NewHash worked", p.NewHash)
- }
- me.forge.SavePatchsets()
-
- return p.NewHash, log.Errorf("did not lookup new hash")
-}
-
-func setNewHash(p *forgepb.Patch, hash string) bool {
- for pset := range me.forge.Patchsets.IterAll() {
- for patch := range pset.Patches.IterAll() {
- if patch.CommitHash == hash {
- patch.NewHash = hash
- log.Info("found patch in repo")
- me.forge.SavePatchsets()
- return true
- }
- }
- }
- return false
-}