diff options
| author | Jeff Carr <[email protected]> | 2025-01-28 13:20:10 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-28 13:20:10 -0600 |
| commit | 91c28de514b1a41e2355714f5352f5438dbe34a2 (patch) | |
| tree | fbf0c71cecc509195501be13a26dd07c0d026706 /applyPatch.go | |
| parent | 3b6e84abdfdff7181c1eb9553a6c6589d6ba027a (diff) | |
make a patchset grid widget
Diffstat (limited to 'applyPatch.go')
| -rw-r--r-- | applyPatch.go | 103 |
1 files changed, 81 insertions, 22 deletions
diff --git a/applyPatch.go b/applyPatch.go index 83d4be2..f1beba9 100644 --- a/applyPatch.go +++ b/applyPatch.go @@ -6,12 +6,42 @@ import ( "os" "path/filepath" - "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) +// saves the patches in ~/.config/forge/currentpatches/ +func savePatchset(pset *forgepb.Patchset) bool { + log.Info("applyPatches() NAME", pset.Name) + log.Info("applyPatches() COMMENT", pset.Comment) + log.Info("applyPatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName()) + log.Info("applyPatches() GIT_AUTHOR_EMAIL", pset.GetGitAuthorEmail()) + log.Info("applyPatches() Branch Name", pset.GetStartBranchName()) + log.Info("applyPatches() Start Hash", pset.GetStartBranchHash()) + + var count int + var bad int + all := pset.Patches.SortByFilename() + for all.Scan() { + p := all.Next() + // basedir := me.forge.GetGoSrc() + basedir := filepath.Join(os.Getenv("FORGE_CONFIG"), "currentpatches") + if fullname, err := savePatchFile(p, basedir); err != nil { + log.Info(fullname, "save failed", err) + continue + } else { + bad += 1 + } + count += 1 + } + log.Info("pset has", count, "total patches, ", bad, "bad save patches") + if bad == 0 { + return true + } + return false +} + // returns bad if patches can not be applied func dumpPatchset(pset *forgepb.Patchset) bool { log.Info("applyPatches() NAME", pset.Name) @@ -99,28 +129,40 @@ func applyPatchset(pset *forgepb.Patchset) error { all := pset.Patches.SortByFilename() for all.Scan() { p := all.Next() - // log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment) - basepath, filename := filepath.Split(p.Filename) - fullpath := filepath.Join(me.forge.GetGoSrc(), basepath) - log.Info("pset filename FILENAME IS REAL? fullpath", fullpath) - fullTmpdir := filepath.Join(tmpdir, basepath) - err := os.MkdirAll(fullTmpdir, os.ModePerm) - if err != nil { - log.Info("applyPathces() MkdirAll failed for", fullTmpdir) - log.Info("applyPathces() MkdirAll failed err", err) - everythingworked = false + + basedir := me.forge.GetGoSrc() + if fullname, err := savePatchFile(p, basedir); err != nil { + log.Info(fullname, "save failed", err) continue - } - log.Info("pset filename FILENAME IS REAL? tmp fullTmpdir", fullTmpdir) - tmpname := filepath.Join(fullTmpdir, filename) - raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - raw.Write(p.Data) - raw.Close() - cmd := []string{"git", "am", tmpname} - result := shell.PathRun(fullpath, cmd) - if result.Exit != 0 { - log.Info("cmd failed", cmd, result.Exit) - everythingworked = false + } else { + /* + // log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment) + basepath, filename := filepath.Split(p.Filename) + fullpath := filepath.Join(me.forge.GetGoSrc(), basepath) + log.Info("pset filename FILENAME IS REAL? fullpath", fullpath) + fullTmpdir := filepath.Join(tmpdir, basepath) + err := os.MkdirAll(fullTmpdir, os.ModePerm) + if err != nil { + log.Info("applyPathces() MkdirAll failed for", fullTmpdir) + log.Info("applyPathces() MkdirAll failed err", err) + everythingworked = false + continue + } + log.Info("pset filename FILENAME IS REAL? tmp fullTmpdir", fullTmpdir) + tmpname := filepath.Join(fullTmpdir, filename) + raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + raw.Write(p.Data) + raw.Close() + */ + /* + FIX THIS + cmd := []string{"git", "am", fullname} + result := shell.PathRun(fullpath, cmd) + if result.Exit != 0 { + log.Info("cmd failed", cmd, result.Exit) + everythingworked = false + } + */ } // until 'git am' works everythingworked = false @@ -132,6 +174,23 @@ func applyPatchset(pset *forgepb.Patchset) error { return nil } +func savePatchFile(p *forgepb.Patch, basedir string) (string, error) { + basepath, filename := filepath.Split(p.Filename) + fulldir := filepath.Join(basedir, basepath) + err := os.MkdirAll(fulldir, os.ModePerm) + if err != nil { + log.Info("applyPathces() MkdirAll failed for", fulldir) + log.Info("applyPathces() MkdirAll failed err", err) + return "", err + } + tmpname := filepath.Join(fulldir, filename) + log.Info("pset filename FILENAME IS REAL?", tmpname) + raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + raw.Write(p.Data) + raw.Close() + return tmpname, nil +} + func readPatchFile(pbfile string) (*forgepb.Patchset, error) { bytes, err := os.ReadFile(pbfile) if err != nil { |
