summaryrefslogtreecommitdiff
path: root/patch.Make.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-11 22:48:33 -0600
committerJeff Carr <[email protected]>2024-12-11 22:48:33 -0600
commitb7e36449dec8c2939210f55d98dd6dc2c0453e04 (patch)
tree0043a17500161a6718a29a42a658a3bddf02df6f /patch.Make.go
parentdae2653975b6db822633430a97adbb21b52a99ff (diff)
make patchset
Diffstat (limited to 'patch.Make.go')
-rw-r--r--patch.Make.go84
1 files changed, 76 insertions, 8 deletions
diff --git a/patch.Make.go b/patch.Make.go
index a71dff2..5341cb8 100644
--- a/patch.Make.go
+++ b/patch.Make.go
@@ -1,10 +1,12 @@
package forgepb
import (
+ "errors"
"fmt"
"os"
"path/filepath"
+ "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -15,6 +17,7 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
return nil, err
}
defer os.RemoveAll(dir) // clean up
+ pset.TmpDir = dir
all := f.Repos.SortByGoPath()
for all.Scan() {
@@ -28,19 +31,84 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
if userb == "" {
continue
}
- return f.makePatchSetNew(develb, userb)
+ pset.StartBranchName = develb
+ pset.EndBranchName = userb
+ err := pset.makePatchSetNew(repo)
+ if err != nil {
+ return nil, err
+ }
+ }
+ return pset, nil
+}
+
+func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
+ pset := new(Patchs)
+ dir, err := os.MkdirTemp("", "forge")
+ if err != nil {
+ return nil, err
+ }
+ defer os.RemoveAll(dir) // clean up
+ pset.TmpDir = dir
+
+ all := f.Repos.SortByGoPath()
+ for all.Scan() {
+ repo := all.Next()
+ startb := repo.GetMasterBranchName()
+ endb := repo.GetUserBranchName()
+
+ if startb == "" {
+ continue
+ }
+ if endb == "" {
+ continue
+ }
+ // log.Info("repo", repo.GoPath, startb, "..", endb)
+ pset.StartBranchName = startb
+ pset.EndBranchName = endb
+ err := pset.makePatchSetNew(repo)
+ if err != nil {
+ return nil, err
+ }
}
return pset, nil
}
-func (f *Forge) makePatchSetNew(fromBranch string, toBranch string) (*Patchs, error) {
- return nil, nil
+func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error {
+ startBranch := pset.StartBranchName
+ endBranch := pset.EndBranchName
+ repoDir := filepath.Join(pset.TmpDir, repo.GoPath)
+ err := os.MkdirAll(repoDir, 0755)
+ if err != nil {
+ return err
+ }
+
+ // git format-patch branch1..branch2
+ cmd := []string{"git", "format-patch", "-o", repoDir, startBranch + ".." + endBranch}
+ 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 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 errors.New(fmt.Sprintf("git returned %d", r.Exit))
+ }
+ if len(r.Stdout) == 0 {
+ // git created no files to add
+ return nil
+ }
+
+ return pset.addPatchFiles(repoDir)
}
-var pset *Patchs
+// var pset *Patchs
func (f *Forge) MakePatchSet() (*Patchs, error) {
- pset = new(Patchs)
+ pset := new(Patchs)
dir, err := os.MkdirTemp("", "forge")
if err != nil {
return nil, err
@@ -85,13 +153,13 @@ func (f *Forge) MakePatchSet() (*Patchs, error) {
continue
}
- addPatchFiles(repoDir)
+ pset.addPatchFiles(repoDir)
}
return pset, nil
}
// process each file in pDir/
-func addPatchFiles(pDir string) error {
+func (p *Patchs) 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 {
@@ -115,7 +183,7 @@ func addPatchFiles(pDir string) error {
patch := new(Patch)
patch.Filename = path
patch.Data = data
- pset.Patchs = append(pset.Patchs, patch)
+ p.Patchs = append(p.Patchs, patch)
// log.Info("ADDED PATCH FILE", path)
return nil
})