diff options
| author | Jeff Carr <[email protected]> | 2025-01-30 18:31:10 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-30 18:31:10 -0600 |
| commit | a491579a6dca359308259177977e0c36e69bf0f9 (patch) | |
| tree | a1c8f557e1c888b9beb452a9b95b33b626596536 /doPatch.go | |
| parent | 3db2e7ff6c70a06fc24a49b074dbaf33444c3757 (diff) | |
open and save patchsets to a file
Diffstat (limited to 'doPatch.go')
| -rw-r--r-- | doPatch.go | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -1,6 +1,7 @@ package main import ( + "os" "path/filepath" "go.wit.com/lib/protobuf/forgepb" @@ -16,6 +17,10 @@ func doPatch() error { return nil } + if argv.Patch.Get != nil { + return doPatchGet() + } + if argv.Patch.List != nil { return doPatchList() } @@ -45,10 +50,49 @@ func doPatchList() error { dumpPatchset(pset) } + if err := savePatchsets(psets); err != nil { + return err + } + return nil +} + +func savePatchsets(psets *forgepb.Patchsets) error { + data, err := psets.Marshal() + if err != nil { + log.Info("protobuf.Marshal() failed:", err) + return err + } + fullpath := filepath.Join(me.forge.GetGoSrc(), "patchsets.pb") + var pfile *os.File + pfile, err = os.OpenFile(fullpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + log.Info("Patchsets save failed:", err, fullpath) + return err + } + pfile.Write(data) + pfile.Close() return nil } +func openPatchsets() (*forgepb.Patchsets, error) { + fullpath := filepath.Join(me.forge.GetGoSrc(), "patchsets.pb") + data, err := os.ReadFile(fullpath) + if err != nil { + log.Info("Patchsets open failed:", err, fullpath) + return nil, err + } + + psets := new(forgepb.Patchsets) + err = psets.Unmarshal(data) + if err != nil { + log.Info("Unmarshal patchsets failed", err) + return nil, err + } + return psets, nil +} + // returns bad if patches can not be applied +// logic is not great here but it was a first pass func dumpPatchset(pset *forgepb.Patchset) bool { log.Info("applyPatches() NAME", pset.Name) log.Info("applyPatches() COMMENT", pset.Comment) @@ -100,3 +144,13 @@ func IsValidPatch(p *forgepb.Patch) bool { } return true } + +func doPatchGet() error { + psets, err := me.forge.GetPatchesets() + if err != nil { + log.Info("Get Patchsets failed", err) + return err + } + log.Info("Got Patchsets ok", psets.Uuid) + return nil +} |
