start work on an applyPatch()
This commit is contained in:
parent
8b3be0ab42
commit
a957c22f8b
5
Makefile
5
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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
1
argv.go
1
argv.go
|
@ -32,6 +32,7 @@ type args struct {
|
|||
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 {
|
||||
|
|
11
main.go
11
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)
|
||||
|
|
13
send.go
13
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue