diff --git a/0001-start-work-on-an-applyPatch.patch b/0001-start-work-on-an-applyPatch.patch new file mode 100644 index 0000000..263a36c --- /dev/null +++ b/0001-start-work-on-an-applyPatch.patch @@ -0,0 +1,154 @@ +From a957c22f8b63f390fc4289b93a84e921e5c3d64d Mon Sep 17 00:00:00 2001 +From: Jeff Carr +Date: Fri, 27 Dec 2024 22:27:19 -0600 +Subject: [PATCH] start work on an applyPatch() + +--- + Makefile | 5 ++++- + applyPatch.go | 35 +++++++++++++++++++++++++++++++++++ + argv.go | 9 +++++---- + main.go | 11 +++++++++++ + send.go | 13 +++++++++++++ + 5 files changed, 68 insertions(+), 5 deletions(-) + create mode 100644 applyPatch.go + +diff --git a/Makefile b/Makefile +index 409761e..3d6ef21 100644 +--- a/Makefile ++++ b/Makefile +@@ -64,7 +64,7 @@ mine: install + all: install + forge list --all + +-patches: install ++patches-make: install + forge --patchset "from makefile" + + localhost-patches: install +@@ -73,6 +73,9 @@ localhost-patches: install + patches-list: install + forge --list-patchset + ++patches-apply-213058: install ++ forge --apply /tmp/2024.12.27.213058.submitted.pb ++ + dirty: install + forge dirty --all + +diff --git a/applyPatch.go b/applyPatch.go +new file mode 100644 +index 0000000..9dccc6c +--- /dev/null ++++ b/applyPatch.go +@@ -0,0 +1,35 @@ ++// Copyright 2024 WIT.COM Inc Licensed GPL 3.0 ++ ++package main ++ ++import ( ++ "os" ++ ++ "go.wit.com/lib/protobuf/forgepb" ++ "go.wit.com/log" ++) ++ ++func applyPatches(pset *forgepb.Patchs) error { ++ all := pset.SortByFilename() ++ for all.Scan() { ++ p := all.Next() ++ log.Info("pset filename", p.Filename) ++ } ++ return nil ++} ++ ++func readPatchFile(pbfile string) (*forgepb.Patchs, error) { ++ bytes, err := os.ReadFile(pbfile) ++ if err != nil { ++ log.Info("readfile error", pbfile, err) ++ return nil, err ++ } ++ var pset *forgepb.Patchs ++ pset = new(forgepb.Patchs) ++ err = pset.Unmarshal(bytes) ++ if err != nil { ++ log.Info("Unmarshal failed", pbfile, err) ++ return nil, err ++ } ++ return pset, nil ++} +diff --git a/argv.go b/argv.go +index 7c19ed4..5b90fc4 100644 +--- a/argv.go ++++ b/argv.go +@@ -28,10 +28,11 @@ type args struct { + Delete string `arg:"--delete" help:"delete this repo"` + URL string `arg:"--connect" help:"gowebd url"` + Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` +- GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"` +- Scan bool `arg:"--scan" help:"reload protobuf from .git/"` +- Force bool `arg:"--force" help:"force redo things"` +- PatchSet string `arg:"--patchset" help:"make patch set"` ++ GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"` ++ Scan bool `arg:"--scan" help:"reload protobuf from .git/"` ++ Force bool `arg:"--force" help:"force redo things"` ++ PatchSet string `arg:"--patchset" help:"make patch set"` ++ Apply string `arg:"--apply" help:"apply a patch set"` + } + + func (args) Version() string { +diff --git a/main.go b/main.go +index 1c2db96..25e801e 100644 +--- a/main.go ++++ b/main.go +@@ -76,6 +76,17 @@ func main() { + } + } + ++ if argv.Apply != "" { ++ pset, err := readPatchFile(argv.Apply) ++ if err != nil { ++ badExit(err) ++ } ++ if err = applyPatches(pset); err == nil { ++ okExit("applied patch ok") ++ } ++ badExit(err) ++ } ++ + if argv.Delete != "" { + me.forge.DeleteByGoPath(argv.Delete) + me.forge.SetConfigSave(true) +diff --git a/send.go b/send.go +index 900b3b3..67fec90 100644 +--- a/send.go ++++ b/send.go +@@ -3,6 +3,8 @@ + package main + + import ( ++ "os" ++ "path/filepath" + "strings" + + "go.wit.com/lib/protobuf/forgepb" +@@ -77,6 +79,17 @@ func getPatch(pbfile string) error { + return err + } + log.Info("getPatch() len(body)", len(body)) ++ var pset *forgepb.Patchs ++ pset = new(forgepb.Patchs) ++ err = pset.Unmarshal(body) ++ if err != nil { ++ log.Info("Unmarshal failed", err) ++ return err ++ } ++ filename := filepath.Join("/tmp", pbfile) ++ f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) ++ f.Write(body) ++ f.Close() + return nil + } + +-- +2.45.2 + diff --git a/Makefile b/Makefile index 3d6ef21..a551286 100644 --- a/Makefile +++ b/Makefile @@ -65,16 +65,16 @@ all: install forge list --all patches-make: install - forge --patchset "from makefile" + forge --patchset "from makefile 2" localhost-patches: install forge --patchset "test-localhost" --url "http://localhost:2233/" -patches-list: install +patches-list: install patches-make forge --list-patchset -patches-apply-213058: install - forge --apply /tmp/2024.12.27.213058.submitted.pb +patches-apply-230233: install + forge --apply /tmp/2024.12.27.230233.submitted.pb dirty: install forge dirty --all diff --git a/applyPatch.go b/applyPatch.go index 9dccc6c..5c1ee12 100644 --- a/applyPatch.go +++ b/applyPatch.go @@ -4,17 +4,30 @@ package main import ( "os" + "path/filepath" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) func applyPatches(pset *forgepb.Patchs) error { + // log.Info("got to applyPatches() pset", pset) + log.Info("got to applyPatches() name", pset.Name) + log.Info("got to applyPatches() comment", pset.Comment) all := pset.SortByFilename() for all.Scan() { p := all.Next() - log.Info("pset filename", p.Filename) + // 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) + log.Info("pset filename FILENAME IS REAL? filename", filename) + fullname := filepath.Join(fullpath, filename) + raw, _ := os.OpenFile(fullname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + raw.Write(p.Data) + raw.Close() } + log.Info("THIS IS THE END MY FRIEND") return nil } @@ -24,12 +37,24 @@ func readPatchFile(pbfile string) (*forgepb.Patchs, error) { log.Info("readfile error", pbfile, err) return nil, err } + return handleBytes(bytes) +} + +func handleBytes(bytes []byte) (*forgepb.Patchs, error) { var pset *forgepb.Patchs pset = new(forgepb.Patchs) - err = pset.Unmarshal(bytes) + err := pset.Unmarshal(bytes) if err != nil { - log.Info("Unmarshal failed", pbfile, err) + log.Info("Unmarshal failed", err) return nil, err } return pset, nil } + +func doit(bytes []byte) error { + pset, err := handleBytes(bytes) + if err != nil { + return err + } + return applyPatches(pset) +} diff --git a/send.go b/send.go index 67fec90..f1f5dd4 100644 --- a/send.go +++ b/send.go @@ -90,6 +90,8 @@ func getPatch(pbfile string) error { f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) f.Write(body) f.Close() + + doit(body) return nil }