From 805d3cdcc3f1cb71c80fa32d42755f2d839f22f5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 9 Jan 2025 20:40:00 -0600 Subject: [PATCH] final commit before rolling a new release. (maybe) Signed-off-by: Jeff Carr --- Makefile | 11 ++++++----- example/patch.proto | 33 +++++++++++++++++++++++++++++++++ newsort.go | 33 --------------------------------- sort.go | 32 ++++++++++++++++++-------------- 4 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 example/patch.proto diff --git a/Makefile b/Makefile index 3d7a726..26dfb7a 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d_%H%M) -test: goimports build test +full: clean auto goimports vet build test + @echo everything worked and the example ran -full: clean goimports auto vet build +test: goimports build test vet: @GO111MODULE=off go vet @@ -29,9 +30,9 @@ install: -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" auto: - rm -f auto.pb.go - ./autogenpb --proto file.proto --package main - rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go + # rm -f auto.pb.go + autogenpb --proto file.proto --package main + # rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go test: make -C example rawproto diff --git a/example/patch.proto b/example/patch.proto new file mode 100644 index 0000000..0c5fd62 --- /dev/null +++ b/example/patch.proto @@ -0,0 +1,33 @@ +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 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/newsort.go b/newsort.go index b931977..c226e64 100644 --- a/newsort.go +++ b/newsort.go @@ -21,38 +21,5 @@ func (pb *Files) makeNewSortfile(pf *File) error { pf.appendUnique(f) // Append() enforce no unique keys pf.iterSortBy(f) pf.iterAll(f) - // pf.iterSortAll(f, sortmap) - - return nil - - /* - for _, s := range uniqueKeys { - // log.Info("found unique key in .proto", s) - sortmap["sortBy"] = s - sortmap["sortKey"] = s - - sortmap["append"] = sortmap["sortKey"] - iterAppend(f, sortmap) // Append() enforce unique key argv.Append - - iterDelete(f, sortmap) - iterReplace(f, sortmap) - iterFind(f, sortmap) - } - - for _, s := range argv.Sort { - sortparts := strings.Split(s, ",") - sortmap["sortBy"] = sortparts[0] - sortmap["sortKey"] = sortparts[1] - - iterSortBy(f, sortmap) - - sortmap["append"] = sortmap["sortKey"] - iterAppend(f, sortmap) // Append() enforce unique key argv.Append - - iterDelete(f, sortmap) - iterReplace(f, sortmap) - iterFind(f, sortmap) - } - */ return nil } diff --git a/sort.go b/sort.go index 29d795a..6eb5d34 100644 --- a/sort.go +++ b/sort.go @@ -142,20 +142,12 @@ func (pf *File) appendUnique(w io.Writer) { LOCK = pf.Bases.Lockname } - // append check for every key - fmt.Fprintln(w, "// enforces "+BASE+" is unique") - fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique(newP *"+BASE+") bool {") + // append -- no check at all + fmt.Fprintln(w, "// just a simple Append() with no checking (but still uses the mutex lock)") + fmt.Fprintln(w, "func (all *"+MSG+") Append(newP *"+BASE+") bool {") fmt.Fprintln(w, " "+LOCK+".RLock()") fmt.Fprintln(w, " defer "+LOCK+".RUnlock()") fmt.Fprintln(w, "") - fmt.Fprintln(w, " for _, p := range all."+MSG+" {") - for _, KEY := range pf.Base.Unique { - fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {") - fmt.Fprintln(w, " return false") - fmt.Fprintln(w, " }") - } - fmt.Fprintln(w, " }") - fmt.Fprintln(w, "") fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)") fmt.Fprintln(w, " return true") fmt.Fprintln(w, "}") @@ -180,12 +172,24 @@ func (pf *File) appendUnique(w io.Writer) { fmt.Fprintln(w, "") } - // append -- no check at all - fmt.Fprintln(w, "// just a simple Append() with no checking (but still uses the mutex lock)") - fmt.Fprintln(w, "func (all *"+MSG+") Append(newP *"+BASE+") bool {") + // append check for every key + if len(pf.Base.Unique) == 0 { + // there are no keys defined + return + } + fmt.Fprintln(w, "// enforces "+BASE+" is unique") + fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique(newP *"+BASE+") bool {") fmt.Fprintln(w, " "+LOCK+".RLock()") fmt.Fprintln(w, " defer "+LOCK+".RUnlock()") fmt.Fprintln(w, "") + fmt.Fprintln(w, " for _, p := range all."+MSG+" {") + for _, KEY := range pf.Base.Unique { + fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {") + fmt.Fprintln(w, " return false") + fmt.Fprintln(w, " }") + } + fmt.Fprintln(w, " }") + fmt.Fprintln(w, "") fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)") fmt.Fprintln(w, " return true") fmt.Fprintln(w, "}")