summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--patch.Make.go146
-rw-r--r--patch.Send.go27
-rw-r--r--patch.proto24
4 files changed, 201 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 42d1a03..d65515c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
# go install
-all: goimports forgeConfig.pb.go uuid.pb.go vet
+all: goimports forgeConfig.pb.go uuid.pb.go patch.pb.go vet
vet:
@GO111MODULE=off go vet
@@ -30,3 +30,6 @@ forgeConfig.pb.go: forgeConfig.proto
uuid.pb.go: uuid.proto
autogenpb --proto uuid.proto
+
+patch.pb.go: patch.proto
+ autogenpb --proto patch.proto
diff --git a/patch.Make.go b/patch.Make.go
new file mode 100644
index 0000000..c2d1619
--- /dev/null
+++ b/patch.Make.go
@@ -0,0 +1,146 @@
+package forgepb
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "go.wit.com/log"
+)
+
+func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
+ pset := new(Patchs)
+ dir, err := os.MkdirTemp("", "forge")
+ if err != nil {
+ return nil, err
+ }
+ defer os.RemoveAll(dir) // clean up
+
+ loop := f.Repos.SortByGoPath()
+ for loop.Scan() {
+ repo := loop.Next()
+ userb := repo.GetUserBranchName()
+ develb := repo.GetDevelBranchName()
+
+ if develb == "" {
+ continue
+ }
+ if userb == "" {
+ continue
+ }
+ return f.makePatchSetNew(develb, userb)
+ }
+ return pset, nil
+}
+
+func (f *Forge) makePatchSetNew(fromBranch string, toBranch string) (*Patchs, error) {
+ return nil, nil
+}
+
+var pset *Patchs
+
+func (f *Forge) MakePatchSet() (*Patchs, error) {
+ pset = new(Patchs)
+ dir, err := os.MkdirTemp("", "forge")
+ if err != nil {
+ return nil, err
+ }
+ defer os.RemoveAll(dir) // clean up
+
+ loop := f.Repos.SortByGoPath()
+ for loop.Scan() {
+ repo := loop.Next()
+ userb := repo.GetUserBranchName()
+ develb := repo.GetDevelBranchName()
+
+ if develb == "" {
+ continue
+ }
+ if userb == "" {
+ continue
+ }
+
+ repoDir := filepath.Join(dir, repo.GoPath)
+ err := os.MkdirAll(repoDir, 0755)
+ if err != nil {
+ return nil, err
+ }
+
+ // git format-patch branch1..branch2
+ cmd := []string{"git", "format-patch", "-o", repoDir, develb + ".." + userb}
+ r := repo.Run(cmd)
+ if r.Error != nil {
+ log.Info("git format-patch", repo.FullPath)
+ log.Info("git format-patch", cmd)
+ log.Info("git format-patch error", r.Error)
+ return nil, r.Error
+ }
+ if r.Exit != 0 {
+ log.Info("git format-patch", repo.FullPath)
+ log.Info("git format-patch", cmd)
+ log.Info("git format-patch exit", r.Exit)
+ return nil, r.Error
+ }
+ if len(r.Stdout) == 0 {
+ continue
+ }
+
+ addPatchFiles(repoDir)
+ }
+ return pset, nil
+}
+
+// process each file in pDir/
+func addPatchFiles(pDir string) error {
+ // log.Info("ADD PATCH FILES ADDED DIR", pDir)
+ var baderr error
+ filepath.Walk(pDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ // Handle possible errors, like permission issues
+ fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
+ baderr = err
+ return err
+ }
+
+ if info.IsDir() {
+ return nil
+ }
+ // log.Info("TESTING FILE", path)
+ data, err := os.ReadFile(path)
+ if err != nil {
+ log.Info("addPatchFile() failed", path)
+ baderr = err
+ return err
+ }
+ patch := new(Patch)
+ patch.Filename = path
+ patch.Data = data
+ pset.Patchs = append(pset.Patchs, patch)
+ // log.Info("ADDED PATCH FILE", path)
+ return nil
+ })
+ return baderr
+}
+
+// just an example of how to walk only directories
+func onlyWalkDirs(pDir string) error {
+ log.Info("DIR", pDir)
+ // var all []string
+ var baderr error
+ filepath.WalkDir(pDir, func(path string, d os.DirEntry, err error) error {
+ if err != nil {
+ // Handle possible errors, like permission issues
+ fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
+ baderr = err
+ return err
+ }
+
+ log.Info("TESTING DIR", path)
+ if d.IsDir() {
+ return filepath.SkipDir
+ }
+ log.Info("NEVER GETS HERE? WHAT IS THIS?", path)
+ return nil
+ })
+ return baderr
+}
diff --git a/patch.Send.go b/patch.Send.go
new file mode 100644
index 0000000..42585ea
--- /dev/null
+++ b/patch.Send.go
@@ -0,0 +1,27 @@
+package forgepb
+
+// functions to import and export the protobuf
+// data to and from config files
+
+import (
+ "errors"
+ "time"
+
+ "go.wit.com/log"
+)
+
+func (f *Forge) SendPatchSet(pset *Patchs) error {
+ var err error
+ data, err := pset.Marshal()
+ if err != nil {
+ log.Info("proto.Marshal() pset(len) error", len(data), err)
+ return err
+ }
+ now := time.Now()
+ timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
+ cfgfile := "patchset/patchset." + timestamp + ".pb"
+ log.Info("proto.Marshal() pset(len)", len(data))
+ configWrite(cfgfile, data)
+
+ return errors.New("don't know how to send yet")
+}
diff --git a/patch.proto b/patch.proto
new file mode 100644
index 0000000..a35bca6
--- /dev/null
+++ b/patch.proto
@@ -0,0 +1,24 @@
+syntax = "proto3";
+
+package forgepb;
+
+import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
+
+message Patch {
+ string filename = 1; // `autogenpb:unique`
+ bytes data = 2; //
+ string repoPath = 3; // path to the git repo
+ string branchName = 4; //
+ string branchHash = 5; //
+ google.protobuf.Timestamp ctime = 7; // the git commit timestamp of the version
+}
+
+message Patchs { // `autogenpb:marshal`
+ string uuid = 1; // `autogenpb:uuid:0703df95-6a38-4422-994b-c55d3d6001f9` // todo: add file support
+ string version = 2; // could be used for protobuf schema change violations?
+ repeated Patch Patchs = 3;
+ string name = 4; // could be used for protobuf schema change violations?
+ string comment = 5; // could be used for protobuf schema change violations?
+ string gitAuthor = 6; // could be used for protobuf schema change violations?
+ google.protobuf.Timestamp ctime = 7; // the git commit timestamp of the version
+}