diff options
| author | Jeff Carr <[email protected]> | 2025-08-28 14:05:01 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-08-28 19:30:59 -0500 |
| commit | c193af11e7f2d32b336127e123e496c5c16915e3 (patch) | |
| tree | 85242b84379882a3e8b0aa03250a8c88046b1517 /doMerge.go | |
| parent | 6b6b31eef6f6a636db0750fcd0d59e3e0758013e (diff) | |
try merging patches together
Diffstat (limited to 'doMerge.go')
| -rw-r--r-- | doMerge.go | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/doMerge.go b/doMerge.go new file mode 100644 index 0000000..f049c5c --- /dev/null +++ b/doMerge.go @@ -0,0 +1,95 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/log" + "google.golang.org/protobuf/proto" +) + +func doMerge() error { + if err := loadConfigfile(); err != nil { + badExit(err) + } + + mergePatchsets() + for pset := range me.all.IterAll() { + showPatchsets(pset) + } + // savePatchsets() + return nil +} + +// adds submitted patches not specifically assigned to a patchset +// to the generic patchset called "forge auto commit" +func addRandomPatch(patch *forgepb.Patch) { + for pset := range me.all.IterAll() { + if pset.Name == "forge auto commit" { + newpb := proto.Clone(patch).(*forgepb.Patch) + if newpb != nil { + pset.Patches.Append(newpb) + } + } + } + log.Warn("patchset.Name == 'forge auto commit' could not be found so the patch in", patch.Namespace, "could not be added") +} + +func addPatchset(filename string, pb *forgepb.Patchset) { + if pb.Name == "forge auto commit" { + author := "Author: " + pb.GitAuthorName + author += " <" + pb.GitAuthorEmail + ">" + + // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME") + // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">" + fmt.Println(filename, pb.Name, pb.Comment, author) + for _, patch := range pb.Patches.Patches { + // log.Info("\tnew patch:", i, patch.CommitHash, patch.Namespace) + if findPatch(patch) { + // log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace) + } else { + log.Info("\tnew patch:", filename, pb.Name, pb.Comment, author) + } + } + // add each of the patches to the general pool + } else { + // Clone() this protobuf into me.all + var newpb *forgepb.Patchset + newpb = proto.Clone(pb).(*forgepb.Patchset) + if newpb != nil { + me.all.Append(newpb) + } + } +} + +func mergePatchsets() { + dirname := filepath.Join(LIBDIR, "patchset/") + // Open the directory + entries, err := os.ReadDir(dirname) + if err != nil { + fmt.Printf("Error reading directory: %v\n", err) + return + } + + // Iterate through the directory entries + for _, entry := range entries { + // Check if the entry is a file and matches the *.pb pattern + if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" { + bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name())) + if err != nil { + fmt.Println(entry.Name(), err) + continue + } + var p *forgepb.Patchset + p = new(forgepb.Patchset) + err = p.Unmarshal(bytes) + if err != nil { + fmt.Println(entry.Name(), err) + continue + } + addPatchset(entry.Name(), p) + } + } +} |
