summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--configDefault.go8
-rw-r--r--patch.proto33
-rw-r--r--patchset.HAMDMADE.go81
-rw-r--r--patchset.Make.go (renamed from patch.Make.go)14
-rw-r--r--patchset.Send.go (renamed from patch.Send.go)2
-rw-r--r--patchset.proto14
7 files changed, 98 insertions, 59 deletions
diff --git a/Makefile b/Makefile
index cbcbf93..79ebccd 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
# go install
-all: forgeConfig.pb.go uuid.pb.go patch.pb.go goimports vet
+all: forgeConfig.pb.go patchset.pb.go goimports vet
generate: clean
go-mod-clean
@@ -26,8 +26,5 @@ clean:
forgeConfig.pb.go: forgeConfig.proto
autogenpb --proto forgeConfig.proto
-uuid.pb.go: uuid.proto
- autogenpb --proto uuid.proto
-
patchset.pb.go: patchset.proto
autogenpb --proto patchset.proto
diff --git a/configDefault.go b/configDefault.go
index 89e8ba8..3246798 100644
--- a/configDefault.go
+++ b/configDefault.go
@@ -2,8 +2,6 @@ package forgepb
import (
"fmt"
-
- "go.wit.com/log"
)
func (all *ForgeConfigs) sampleConfig() {
@@ -11,11 +9,7 @@ func (all *ForgeConfigs) sampleConfig() {
new1.GoPath = "go.wit.com"
new1.Writable = true
new1.Directory = true
- if all.Append(new1) {
- log.Info("added", new1.GoPath, "ok")
- } else {
- log.Info("added", new1.GoPath, "failed")
- }
+ all.Append(new1)
fmt.Println("first time user. adding an example config file with", len(all.ForgeConfigs), "repos")
}
diff --git a/patch.proto b/patch.proto
deleted file mode 100644
index 5942924..0000000
--- a/patch.proto
+++ /dev/null
@@ -1,33 +0,0 @@
-syntax = "proto3";
-
-package forgepb;
-
-import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
-
-message Patch {
- string filename = 1; // `autogenpb:unique` `autogenpb:sort`
- 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 this patch
- string commitHash = 8; // the git commit hash of this patch
- string startHash = 9; // the start commit hash
- repeated string Files = 10; // the filenames this patch changes
-}
-
-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; //
- string comment = 5; //
- string gitAuthorName = 6; //
- string gitAuthorEmail = 7; //
- google.protobuf.Timestamp ctime = 8; // create time of this patchset
- string tmpDir = 9; // temp dir
- string startBranchName = 10; //
- string endBranchName = 11; //
- string startBranchHash = 12; //
- string endBranchHash = 13; //
-}
diff --git a/patchset.HAMDMADE.go b/patchset.HAMDMADE.go
new file mode 100644
index 0000000..5f3124b
--- /dev/null
+++ b/patchset.HAMDMADE.go
@@ -0,0 +1,81 @@
+// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
+// This file was autogenerated with autogenpb v0.0.40-19-gfed674d 2025.01.11_0448
+// go install go.wit.com/apps/autogenpb@latest
+//
+// define which structs (messages) you want to use in the .proto file
+// Then sort.pb.go and marshal.pb.go files are autogenerated
+//
+// autogenpb uses it and has an example .proto file with instructions
+//
+
+package forgepb
+
+import (
+ "fmt"
+ "sort"
+ "sync"
+)
+
+// DEFINE THE ITERATOR. Only one per Patch message
+
+// NewPatchsetIterator initializes a new iterator.
+func NewPatchIterator(things []*Patch) *PatchIterator {
+ return &PatchIterator{things: things}
+}
+
+// safely returns a slice of pointers to the Patchset protobufs
+func (x *Patchset) all() []*Patch {
+ x.Lock.RLock()
+ defer x.Lock.RUnlock()
+
+ // Create a new slice to hold pointers to each Patchset
+ var tmp []*Patch
+ tmp = make([]*Patch, len(x.Patches))
+ for i, p := range x.Patches {
+ tmp[i] = p // Copy pointers for safe iteration
+ }
+
+ return tmp
+}
+
+type PatchIterator struct {
+ sync.RWMutex
+
+ things []*Patch
+ index int
+}
+
+func (it *PatchIterator) Scan() bool {
+ if it.index >= len(it.things) {
+ return false
+ }
+ it.index++
+ return true
+}
+
+// Next() returns the next thing in the array
+func (it *PatchIterator) Next() *Patch {
+ if it.things[it.index-1] == nil {
+ fmt.Println("Next() error in PatchIterator", it.index)
+ }
+ return it.things[it.index-1]
+}
+
+// END DEFINE THE ITERATOR
+
+// START sort by Filename (this is all you need once the Iterator is defined)
+type PatchFilename []*Patch
+
+func (a PatchFilename) Len() int { return len(a) }
+func (a PatchFilename) Less(i, j int) bool { return a[i].Filename < a[j].Filename }
+func (a PatchFilename) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+
+func (x *Patchset) SortByFilename() *PatchIterator {
+ things := x.all()
+
+ sort.Sort(PatchFilename(things))
+
+ iterator := NewPatchIterator(things)
+ return iterator
+}
+// END sort by Filename
diff --git a/patch.Make.go b/patchset.Make.go
index f43d9be..fd68efb 100644
--- a/patch.Make.go
+++ b/patchset.Make.go
@@ -11,8 +11,8 @@ import (
"go.wit.com/log"
)
-func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
- pset := new(Patchs)
+func (f *Forge) MakeDevelPatchSet() (*Patchset, error) {
+ pset := new(Patchset)
dir, err := os.MkdirTemp("", "forge")
if err != nil {
return nil, err
@@ -42,8 +42,8 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
return pset, nil
}
-func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
- pset := new(Patchs)
+func (f *Forge) MakeMasterPatchSet() (*Patchset, error) {
+ pset := new(Patchset)
dir, err := os.MkdirTemp("", "forge")
if err != nil {
return nil, err
@@ -74,7 +74,7 @@ func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
return pset, nil
}
-func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error {
+func (pset *Patchset) makePatchSetNew(repo *gitpb.Repo) error {
startBranch := pset.StartBranchName
endBranch := pset.EndBranchName
repoDir := filepath.Join(pset.TmpDir, repo.GetGoPath())
@@ -107,7 +107,7 @@ func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error {
}
// process each file in pDir/
-func (p *Patchs) addPatchFiles(repo *gitpb.Repo) error {
+func (p *Patchset) addPatchFiles(repo *gitpb.Repo) error {
psetDir := repo.GetGoPath()
tmpDir := p.TmpDir
log.Info("ADD PATCH FILES ADDED DIR", tmpDir)
@@ -139,7 +139,7 @@ func (p *Patchs) addPatchFiles(repo *gitpb.Repo) error {
patch.Data = data
patch.parseData()
patch.StartHash = repo.DevelHash()
- p.Patchs = append(p.Patchs, patch)
+ p.Patches = append(p.Patches, patch)
log.Info("ADDED PATCH FILE", path)
return nil
})
diff --git a/patch.Send.go b/patchset.Send.go
index 42585ea..00fe37e 100644
--- a/patch.Send.go
+++ b/patchset.Send.go
@@ -10,7 +10,7 @@ import (
"go.wit.com/log"
)
-func (f *Forge) SendPatchSet(pset *Patchs) error {
+func (f *Forge) SendPatchSet(pset *Patchset) error {
var err error
data, err := pset.Marshal()
if err != nil {
diff --git a/patchset.proto b/patchset.proto
index afb725a..00b7134 100644
--- a/patchset.proto
+++ b/patchset.proto
@@ -5,7 +5,7 @@ package forgepb;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
message Patch {
- string filename = 1; // `autogenpb:unique`
+ string filename = 1; // `autogenpb:unique` `autogenpb:sort`
bytes data = 2; //
string repoPath = 3; // path to the git repo
string branchName = 4; //
@@ -17,10 +17,10 @@ message Patch {
}
message Patchset { // `autogenpb:marshal`
- repeated Patch Patches = 1;
- string name = 2; //
+ repeated Patch Patches = 1; //
+ string name = 2; // `autogenpb:sort`
string comment = 3; //
- string gitAuthorName = 4; //
+ string gitAuthorName = 4; // `autogenpb:sort`
string gitAuthorEmail = 5; //
google.protobuf.Timestamp ctime = 6; // create time of this patchset
string tmpDir = 7; // temp dir
@@ -30,8 +30,8 @@ message Patchset { // `autogenpb:marshal`
string endBranchHash = 11; //
}
-message Patchsets { // `autogenpb:marshal`
- string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079` // todo: add autogenpb support for this
- string version = 2; // could be used for protobuf schema change violations?
+message Patchsets { // `autogenpb:marshal`
+ string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079` // todo: add autogenpb support for this
+ string version = 2; // `autogenpb:version:v0.0.45` // todo: add autogenpb support for this
repeated Patchset Patchsets = 3;
}