shortcut to get the age of a repo
This commit is contained in:
parent
1e4b0c0d37
commit
5341a70557
Notes:
Jeff Carr
2024-12-14 15:22:14 -06:00
// `autogen:go.mod` module go.wit.com/lib/protobuf/gitpb go 1.20 require ( github.com/destel/rill v0.6.0 github.com/go-cmd/cmd v1.4.3 go.wit.com/lib/gui/shell v0.22.16 go.wit.com/log v0.22.9 google.golang.org/protobuf v1.35.2 ) // `autogen:go.sum` github.com/destel/rill v0.6.0 h1:8MQRzS6k0akKmwNZFahKIhG1dkBeNxMoWKSfOxkaJNw= github.com/destel/rill v0.6.0/go.mod h1:srKuXzvGqINUEGYR5b/iwvW+L9/S35RxVHWGYbXNoO4= github.com/go-cmd/cmd v1.4.3 h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y= github.com/go-cmd/cmd v1.4.3/go.mod h1:u3hxg/ry+D5kwh8WvUkHLAMe2zQCaXd00t35WfQaOFk= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= go.wit.com/lib/gui/shell v0.22.16 h1:MLCaJnxEjKWW275VeavKGvUo5G4AqkPOPG1mMt2SJps= go.wit.com/lib/gui/shell v0.22.16/go.mod h1:nypmR50Bov++Ajjf2aC/RJ+4DWh2Xtm2ciaRm7pGY54= go.wit.com/log v0.22.9 h1:aBM6SI2kxlJcBfS/osFTomJqNhO0hfEo1gk+LCqLk7Y= go.wit.com/log v0.22.9/go.mod h1:4uNPFBqhsAh8zNF+zxVEmC3c/9AZ8JeTfUUvRpddvLQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= // `autogen:gitTag.marshal.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" ) // human readable JSON func (v *GitTag) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *GitTag) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *GitTag) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *GitTag) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *GitTag) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *GitTag) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *GitTag) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // human readable JSON func (v *GitTags) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *GitTags) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *GitTags) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *GitTags) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *GitTags) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *GitTags) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *GitTags) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:gitTag.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: gitTag.proto package gitpb import ( reflect "reflect" sync "sync" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) type GitTag struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Refname string `protobuf:"bytes,1,opt,name=refname,proto3" json:"refname,omitempty"` // `autogenpb:unique` // tag name. treated as unique Creatordate *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=creatordate,proto3" json:"creatordate,omitempty"` // git creatordate Authordate *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=authordate,proto3" json:"authordate,omitempty"` // git author date Hash string `protobuf:"bytes,4,opt,name=hash,proto3" json:"hash,omitempty"` // `autogenpb:unique` // git hash Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` // git tag subject } func (x *GitTag) Reset() { *x = GitTag{} mi := &file_gitTag_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *GitTag) String() string { return protoimpl.X.MessageStringOf(x) } func (*GitTag) ProtoMessage() {} func (x *GitTag) ProtoReflect() protoreflect.Message { mi := &file_gitTag_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use GitTag.ProtoReflect.Descriptor instead. func (*GitTag) Descriptor() ([]byte, []int) { return file_gitTag_proto_rawDescGZIP(), []int{0} } func (x *GitTag) GetRefname() string { if x != nil { return x.Refname } return "" } func (x *GitTag) GetCreatordate() *timestamppb.Timestamp { if x != nil { return x.Creatordate } return nil } func (x *GitTag) GetAuthordate() *timestamppb.Timestamp { if x != nil { return x.Authordate } return nil } func (x *GitTag) GetHash() string { if x != nil { return x.Hash } return "" } func (x *GitTag) GetSubject() string { if x != nil { return x.Subject } return "" } type GitTags struct { Lock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // I guess why not just have this on each file Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // maybe can be used for protobuf schema change violations GitTags []*GitTag `protobuf:"bytes,3,rep,name=gitTags,proto3" json:"gitTags,omitempty"` } func (x *GitTags) Reset() { *x = GitTags{} mi := &file_gitTag_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *GitTags) String() string { return protoimpl.X.MessageStringOf(x) } func (*GitTags) ProtoMessage() {} func (x *GitTags) ProtoReflect() protoreflect.Message { mi := &file_gitTag_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use GitTags.ProtoReflect.Descriptor instead. func (*GitTags) Descriptor() ([]byte, []int) { return file_gitTag_proto_rawDescGZIP(), []int{1} } func (x *GitTags) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *GitTags) GetVersion() string { if x != nil { return x.Version } return "" } func (x *GitTags) GetGitTags() []*GitTag { if x != nil { return x.GitTags } return nil } var File_gitTag_proto protoreflect.FileDescriptor var file_gitTag_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x67, 0x69, 0x74, 0x54, 0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xca, 0x01, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x54, 0x61, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x66, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x12, 0x3a, 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x60, 0x0a, 0x07, 0x47, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x27, 0x0a, 0x07, 0x67, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x69, 0x74, 0x54, 0x61, 0x67, 0x52, 0x07, 0x67, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_gitTag_proto_rawDescOnce sync.Once file_gitTag_proto_rawDescData = file_gitTag_proto_rawDesc ) func file_gitTag_proto_rawDescGZIP() []byte { file_gitTag_proto_rawDescOnce.Do(func() { file_gitTag_proto_rawDescData = protoimpl.X.CompressGZIP(file_gitTag_proto_rawDescData) }) return file_gitTag_proto_rawDescData } var file_gitTag_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_gitTag_proto_goTypes = []any{ (*GitTag)(nil), // 0: gitpb.GitTag (*GitTags)(nil), // 1: gitpb.GitTags (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp } var file_gitTag_proto_depIdxs = []int32{ 2, // 0: gitpb.GitTag.creatordate:type_name -> google.protobuf.Timestamp 2, // 1: gitpb.GitTag.authordate:type_name -> google.protobuf.Timestamp 0, // 2: gitpb.GitTags.gitTags:type_name -> gitpb.GitTag 3, // [3:3] is the sub-list for method output_type 3, // [3:3] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name } func init() { file_gitTag_proto_init() } func file_gitTag_proto_init() { if File_gitTag_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_gitTag_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_gitTag_proto_goTypes, DependencyIndexes: file_gitTag_proto_depIdxs, MessageInfos: file_gitTag_proto_msgTypes, }.Build() File_gitTag_proto = out.File file_gitTag_proto_rawDesc = nil file_gitTag_proto_goTypes = nil file_gitTag_proto_depIdxs = nil } // `autogen:gitTag.sort.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "fmt" "os" "sort" "sync" ) type GitTagIterator struct { sync.RWMutex packs []*GitTag index int } // NewGitTagIterator initializes a new iterator. func NewGitTagIterator(packs []*GitTag) *GitTagIterator { return &GitTagIterator{packs: packs} } // Scan moves to the next element and returns false if there are no more packs. // Use Scan() in a loop, similar to a while loop // // for iterator.Scan() // d := iterator.Next( // fmt.Println("found UUID:", d.Uuid // } func (it *GitTagIterator) Scan() bool { if it.index >= len(it.packs) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *GitTagIterator) Next() *GitTag { if it.packs[it.index-1] == nil { for i, d := range it.packs { fmt.Println("i =", i, d) } fmt.Println("protobuf autogenpb sort error len =", len(it.packs)) fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1) os.Exit(-1) } return it.packs[it.index-1] } // does not enforce any unique fields func (all *GitTags) Append(newP *GitTag) bool { all.Lock.RLock() defer all.Lock.RUnlock() all.GitTags = append(all.GitTags, newP) return true } func (all *GitTags) All() *GitTagIterator { gitTagPointers := all.selectAllGitTag() iterator := NewGitTagIterator(gitTagPointers) return iterator } func (all *GitTags) Len() int { all.Lock.RLock() defer all.Lock.RUnlock() return len(all.GitTags) } func (all *GitTags) SortByRefname() *GitTagIterator { packs := all.selectAllGitTag() sort.Sort(GitTagRefname(packs)) iterator := NewGitTagIterator(packs) return iterator } type GitTagRefname []*GitTag func (a GitTagRefname) Len() int { return len(a) } func (a GitTagRefname) Less(i, j int) bool { return a[i].Refname < a[j].Refname } func (a GitTagRefname) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces Refname is unique func (all *GitTags) AppendUniqueRefname(newP *GitTag) bool { all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GitTags { if p.Refname == newP.Refname { return false } } all.GitTags = append(all.GitTags, newP) return true } func (all *GitTags) DeleteByRefname(s string) bool { all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GitTags { if all.GitTags[i].Refname == s { all.GitTags[i] = all.GitTags[len(all.GitTags)-1] all.GitTags = all.GitTags[:len(all.GitTags)-1] return true } } return false } // enforces Refname is unique func (all *GitTags) ReplaceRefname(newP *GitTag) bool { // todo: make unique name here all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GitTags { if p.Refname == newP.Refname { return false } } all.GitTags = append(all.GitTags, newP) return true } // find a dependancy by the go path func (all *GitTags) FindByRefname(s string) *GitTag { if all == nil { return nil } all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GitTags { if all.GitTags[i].Refname == s { return all.GitTags[i] } } return nil } func (all *GitTags) SortByHash() *GitTagIterator { packs := all.selectAllGitTag() sort.Sort(GitTagHash(packs)) iterator := NewGitTagIterator(packs) return iterator } type GitTagHash []*GitTag func (a GitTagHash) Len() int { return len(a) } func (a GitTagHash) Less(i, j int) bool { return a[i].Hash < a[j].Hash } func (a GitTagHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces Hash is unique func (all *GitTags) AppendUniqueHash(newP *GitTag) bool { all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GitTags { if p.Hash == newP.Hash { return false } } all.GitTags = append(all.GitTags, newP) return true } func (all *GitTags) DeleteByHash(s string) bool { all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GitTags { if all.GitTags[i].Hash == s { all.GitTags[i] = all.GitTags[len(all.GitTags)-1] all.GitTags = all.GitTags[:len(all.GitTags)-1] return true } } return false } // enforces Hash is unique func (all *GitTags) ReplaceHash(newP *GitTag) bool { // todo: make unique name here all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GitTags { if p.Hash == newP.Hash { return false } } all.GitTags = append(all.GitTags, newP) return true } // find a dependancy by the go path func (all *GitTags) FindByHash(s string) *GitTag { if all == nil { return nil } all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GitTags { if all.GitTags[i].Hash == s { return all.GitTags[i] } } return nil } // safely returns a slice of pointers to the GitTag protobufs func (all *GitTags) selectAllGitTag() []*GitTag { all.Lock.RLock() defer all.Lock.RUnlock() // Create a new slice to hold pointers to each GitTag var aStuff []*GitTag aStuff = make([]*GitTag, len(all.GitTags)) for i, p := range all.GitTags { aStuff[i] = p // Copy pointers for safe iteration } return aStuff } // `autogen:goDep.marshal.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" ) // human readable JSON func (v *GoDep) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *GoDep) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *GoDep) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *GoDep) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *GoDep) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *GoDep) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *GoDep) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // human readable JSON func (v *GoDeps) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *GoDeps) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *GoDeps) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *GoDeps) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *GoDeps) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *GoDeps) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *GoDeps) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:goDep.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: goDep.proto // store go dependancies package gitpb import ( reflect "reflect" sync "sync" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) type GoDep struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` // `autogenpb:unique` // md5sum/hash value from the go.sum file Ctime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=ctime,proto3" json:"ctime,omitempty"` // get the go date from 'go list' ? Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` // v1.2.2 GoPath string `protobuf:"bytes,4,opt,name=goPath,proto3" json:"goPath,omitempty"` // `autogenpb:unique` // "go.wit.com/lib/foo" GoVersion string `protobuf:"bytes,5,opt,name=goVersion,proto3" json:"goVersion,omitempty"` // version of golang the developer used to make this package version } func (x *GoDep) Reset() { *x = GoDep{} mi := &file_goDep_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *GoDep) String() string { return protoimpl.X.MessageStringOf(x) } func (*GoDep) ProtoMessage() {} func (x *GoDep) ProtoReflect() protoreflect.Message { mi := &file_goDep_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use GoDep.ProtoReflect.Descriptor instead. func (*GoDep) Descriptor() ([]byte, []int) { return file_goDep_proto_rawDescGZIP(), []int{0} } func (x *GoDep) GetHash() string { if x != nil { return x.Hash } return "" } func (x *GoDep) GetCtime() *timestamppb.Timestamp { if x != nil { return x.Ctime } return nil } func (x *GoDep) GetVersion() string { if x != nil { return x.Version } return "" } func (x *GoDep) GetGoPath() string { if x != nil { return x.GoPath } return "" } func (x *GoDep) GetGoVersion() string { if x != nil { return x.GoVersion } return "" } type GoDeps struct { Lock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // I guess why not just have this on each file Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // maybe can be used for protobuf schema change violations GoDeps []*GoDep `protobuf:"bytes,3,rep,name=goDeps,proto3" json:"goDeps,omitempty"` } func (x *GoDeps) Reset() { *x = GoDeps{} mi := &file_goDep_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *GoDeps) String() string { return protoimpl.X.MessageStringOf(x) } func (*GoDeps) ProtoMessage() {} func (x *GoDeps) ProtoReflect() protoreflect.Message { mi := &file_goDep_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use GoDeps.ProtoReflect.Descriptor instead. func (*GoDeps) Descriptor() ([]byte, []int) { return file_goDep_proto_rawDescGZIP(), []int{1} } func (x *GoDeps) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *GoDeps) GetVersion() string { if x != nil { return x.Version } return "" } func (x *GoDeps) GetGoDeps() []*GoDep { if x != nil { return x.GoDeps } return nil } var File_goDep_proto protoreflect.FileDescriptor var file_goDep_proto_rawDesc = []byte{ 0x0a, 0x0b, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9d, 0x01, 0x0a, 0x05, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x30, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x67, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x5c, 0x0a, 0x06, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x0a, 0x06, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x52, 0x06, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_goDep_proto_rawDescOnce sync.Once file_goDep_proto_rawDescData = file_goDep_proto_rawDesc ) func file_goDep_proto_rawDescGZIP() []byte { file_goDep_proto_rawDescOnce.Do(func() { file_goDep_proto_rawDescData = protoimpl.X.CompressGZIP(file_goDep_proto_rawDescData) }) return file_goDep_proto_rawDescData } var file_goDep_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_goDep_proto_goTypes = []any{ (*GoDep)(nil), // 0: gitpb.GoDep (*GoDeps)(nil), // 1: gitpb.GoDeps (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp } var file_goDep_proto_depIdxs = []int32{ 2, // 0: gitpb.GoDep.ctime:type_name -> google.protobuf.Timestamp 0, // 1: gitpb.GoDeps.goDeps:type_name -> gitpb.GoDep 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name } func init() { file_goDep_proto_init() } func file_goDep_proto_init() { if File_goDep_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_goDep_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_goDep_proto_goTypes, DependencyIndexes: file_goDep_proto_depIdxs, MessageInfos: file_goDep_proto_msgTypes, }.Build() File_goDep_proto = out.File file_goDep_proto_rawDesc = nil file_goDep_proto_goTypes = nil file_goDep_proto_depIdxs = nil } // `autogen:goDep.sort.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "fmt" "os" "sort" "sync" ) type GoDepIterator struct { sync.RWMutex packs []*GoDep index int } // NewGoDepIterator initializes a new iterator. func NewGoDepIterator(packs []*GoDep) *GoDepIterator { return &GoDepIterator{packs: packs} } // Scan moves to the next element and returns false if there are no more packs. // Use Scan() in a loop, similar to a while loop // // for iterator.Scan() // d := iterator.Next( // fmt.Println("found UUID:", d.Uuid // } func (it *GoDepIterator) Scan() bool { if it.index >= len(it.packs) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *GoDepIterator) Next() *GoDep { if it.packs[it.index-1] == nil { for i, d := range it.packs { fmt.Println("i =", i, d) } fmt.Println("protobuf autogenpb sort error len =", len(it.packs)) fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1) os.Exit(-1) } return it.packs[it.index-1] } // does not enforce any unique fields func (all *GoDeps) Append(newP *GoDep) bool { all.Lock.RLock() defer all.Lock.RUnlock() all.GoDeps = append(all.GoDeps, newP) return true } func (all *GoDeps) All() *GoDepIterator { goDepPointers := all.selectAllGoDep() iterator := NewGoDepIterator(goDepPointers) return iterator } func (all *GoDeps) Len() int { all.Lock.RLock() defer all.Lock.RUnlock() return len(all.GoDeps) } func (all *GoDeps) SortByHash() *GoDepIterator { packs := all.selectAllGoDep() sort.Sort(GoDepHash(packs)) iterator := NewGoDepIterator(packs) return iterator } type GoDepHash []*GoDep func (a GoDepHash) Len() int { return len(a) } func (a GoDepHash) Less(i, j int) bool { return a[i].Hash < a[j].Hash } func (a GoDepHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces Hash is unique func (all *GoDeps) AppendUniqueHash(newP *GoDep) bool { all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GoDeps { if p.Hash == newP.Hash { return false } } all.GoDeps = append(all.GoDeps, newP) return true } func (all *GoDeps) DeleteByHash(s string) bool { all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GoDeps { if all.GoDeps[i].Hash == s { all.GoDeps[i] = all.GoDeps[len(all.GoDeps)-1] all.GoDeps = all.GoDeps[:len(all.GoDeps)-1] return true } } return false } // enforces Hash is unique func (all *GoDeps) ReplaceHash(newP *GoDep) bool { // todo: make unique name here all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GoDeps { if p.Hash == newP.Hash { return false } } all.GoDeps = append(all.GoDeps, newP) return true } // find a dependancy by the go path func (all *GoDeps) FindByHash(s string) *GoDep { if all == nil { return nil } all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GoDeps { if all.GoDeps[i].Hash == s { return all.GoDeps[i] } } return nil } func (all *GoDeps) SortByGoPath() *GoDepIterator { packs := all.selectAllGoDep() sort.Sort(GoDepGoPath(packs)) iterator := NewGoDepIterator(packs) return iterator } type GoDepGoPath []*GoDep func (a GoDepGoPath) Len() int { return len(a) } func (a GoDepGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } func (a GoDepGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces GoPath is unique func (all *GoDeps) AppendUniqueGoPath(newP *GoDep) bool { all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GoDeps { if p.GoPath == newP.GoPath { return false } } all.GoDeps = append(all.GoDeps, newP) return true } func (all *GoDeps) DeleteByGoPath(s string) bool { all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GoDeps { if all.GoDeps[i].GoPath == s { all.GoDeps[i] = all.GoDeps[len(all.GoDeps)-1] all.GoDeps = all.GoDeps[:len(all.GoDeps)-1] return true } } return false } // enforces GoPath is unique func (all *GoDeps) ReplaceGoPath(newP *GoDep) bool { // todo: make unique name here all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.GoDeps { if p.GoPath == newP.GoPath { return false } } all.GoDeps = append(all.GoDeps, newP) return true } // find a dependancy by the go path func (all *GoDeps) FindByGoPath(s string) *GoDep { if all == nil { return nil } all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.GoDeps { if all.GoDeps[i].GoPath == s { return all.GoDeps[i] } } return nil } // safely returns a slice of pointers to the GoDep protobufs func (all *GoDeps) selectAllGoDep() []*GoDep { all.Lock.RLock() defer all.Lock.RUnlock() // Create a new slice to hold pointers to each GoDep var aStuff []*GoDep aStuff = make([]*GoDep, len(all.GoDeps)) for i, p := range all.GoDeps { aStuff[i] = p // Copy pointers for safe iteration } return aStuff } // `autogen:repo.marshal.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" ) // human readable JSON func (v *Repo) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *Repo) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *Repo) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *Repo) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *Repo) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *Repo) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *Repo) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // human readable JSON func (v *Repos) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *Repos) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *Repos) UnmarshalJSON(data []byte) error { return protojson.Unmarshal(data, v) } // apparently this isn't stable, but it's awesomely better // https://protobuf.dev/reference/go/faq/#unstable-text // it's so great for config files, I'm using it by default to try to fix the problems with it func (v *Repos) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *Repos) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *Repos) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *Repos) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:repo.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: repo.proto package gitpb import ( reflect "reflect" sync "sync" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) type Repo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields FullPath string `protobuf:"bytes,1,opt,name=fullPath,proto3" json:"fullPath,omitempty"` // the actual path to the .git directory: '/home/devel/golang.org/x/tools' LastPull *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=lastPull,proto3" json:"lastPull,omitempty"` // last time a git pull was done MasterBranchName string `protobuf:"bytes,3,opt,name=masterBranchName,proto3" json:"masterBranchName,omitempty"` // git 'main' or 'master' branch name DevelBranchName string `protobuf:"bytes,4,opt,name=develBranchName,proto3" json:"develBranchName,omitempty"` // whatever the git 'devel' branch name is UserBranchName string `protobuf:"bytes,5,opt,name=userBranchName,proto3" json:"userBranchName,omitempty"` // whatever your username branch is Tags *GitTags `protobuf:"bytes,6,opt,name=tags,proto3" json:"tags,omitempty"` // known tags GoPath string `protobuf:"bytes,7,opt,name=goPath,proto3" json:"goPath,omitempty"` // `autogenpb:unique` // the logical path as used by golang: 'go.wit.com/apps/helloworld' GoLibrary bool `protobuf:"varint,8,opt,name=goLibrary,proto3" json:"goLibrary,omitempty"` // is this a golang library? GoBinary bool `protobuf:"varint,9,opt,name=goBinary,proto3" json:"goBinary,omitempty"` // is this a golang binary? GoPrimitive bool `protobuf:"varint,10,opt,name=goPrimitive,proto3" json:"goPrimitive,omitempty"` // if this is a golang primitive (only has go.mod) GoPlugin bool `protobuf:"varint,11,opt,name=goPlugin,proto3" json:"goPlugin,omitempty"` // is this a golang plugin? GoDeps *GoDeps `protobuf:"bytes,12,opt,name=goDeps,proto3" json:"goDeps,omitempty"` // what is in the go.sum file LastGoDep *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=lastGoDep,proto3" json:"lastGoDep,omitempty"` // last time go.sum was processed Dirty bool `protobuf:"varint,14,opt,name=dirty,proto3" json:"dirty,omitempty"` // if git says things have been changed Published *GoDeps `protobuf:"bytes,15,opt,name=published,proto3" json:"published,omitempty"` // the last published go.mod/go.sum TargetVersion string `protobuf:"bytes,16,opt,name=targetVersion,proto3" json:"targetVersion,omitempty"` // useful during the package release process ReadOnly bool `protobuf:"varint,17,opt,name=readOnly,proto3" json:"readOnly,omitempty"` // tracks access to 'git push' URL string `protobuf:"bytes,18,opt,name=URL,proto3" json:"URL,omitempty"` // the URL. amazingly I didn't add this earlier. duh. GoProtobuf bool `protobuf:"varint,19,opt,name=goProtobuf,proto3" json:"goProtobuf,omitempty"` // autogen go files from .proto Desc string `protobuf:"bytes,20,opt,name=desc,proto3" json:"desc,omitempty"` // what is this repo? GoMod []byte `protobuf:"bytes,21,opt,name=goMod,proto3" json:"goMod,omitempty"` // the last go.mod file GoSum []byte `protobuf:"bytes,22,opt,name=goSum,proto3" json:"goSum,omitempty"` // the last go.sum file } func (x *Repo) Reset() { *x = Repo{} mi := &file_repo_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *Repo) String() string { return protoimpl.X.MessageStringOf(x) } func (*Repo) ProtoMessage() {} func (x *Repo) ProtoReflect() protoreflect.Message { mi := &file_repo_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Repo.ProtoReflect.Descriptor instead. func (*Repo) Descriptor() ([]byte, []int) { return file_repo_proto_rawDescGZIP(), []int{0} } func (x *Repo) GetFullPath() string { if x != nil { return x.FullPath } return "" } func (x *Repo) GetLastPull() *timestamppb.Timestamp { if x != nil { return x.LastPull } return nil } func (x *Repo) GetMasterBranchName() string { if x != nil { return x.MasterBranchName } return "" } func (x *Repo) GetDevelBranchName() string { if x != nil { return x.DevelBranchName } return "" } func (x *Repo) GetUserBranchName() string { if x != nil { return x.UserBranchName } return "" } func (x *Repo) GetTags() *GitTags { if x != nil { return x.Tags } return nil } func (x *Repo) GetGoPath() string { if x != nil { return x.GoPath } return "" } func (x *Repo) GetGoLibrary() bool { if x != nil { return x.GoLibrary } return false } func (x *Repo) GetGoBinary() bool { if x != nil { return x.GoBinary } return false } func (x *Repo) GetGoPrimitive() bool { if x != nil { return x.GoPrimitive } return false } func (x *Repo) GetGoPlugin() bool { if x != nil { return x.GoPlugin } return false } func (x *Repo) GetGoDeps() *GoDeps { if x != nil { return x.GoDeps } return nil } func (x *Repo) GetLastGoDep() *timestamppb.Timestamp { if x != nil { return x.LastGoDep } return nil } func (x *Repo) GetDirty() bool { if x != nil { return x.Dirty } return false } func (x *Repo) GetPublished() *GoDeps { if x != nil { return x.Published } return nil } func (x *Repo) GetTargetVersion() string { if x != nil { return x.TargetVersion } return "" } func (x *Repo) GetReadOnly() bool { if x != nil { return x.ReadOnly } return false } func (x *Repo) GetURL() string { if x != nil { return x.URL } return "" } func (x *Repo) GetGoProtobuf() bool { if x != nil { return x.GoProtobuf } return false } func (x *Repo) GetDesc() string { if x != nil { return x.Desc } return "" } func (x *Repo) GetGoMod() []byte { if x != nil { return x.GoMod } return nil } func (x *Repo) GetGoSum() []byte { if x != nil { return x.GoSum } return nil } type Repos struct { Lock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:8daaeba1-fb1f-4762-ae6e-95a55d352673` Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // maybe can be used for protobuf schema change violations Repos []*Repo `protobuf:"bytes,3,rep,name=repos,proto3" json:"repos,omitempty"` } func (x *Repos) Reset() { *x = Repos{} mi := &file_repo_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *Repos) String() string { return protoimpl.X.MessageStringOf(x) } func (*Repos) ProtoMessage() {} func (x *Repos) ProtoReflect() protoreflect.Message { mi := &file_repo_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Repos.ProtoReflect.Descriptor instead. func (*Repos) Descriptor() ([]byte, []int) { return file_repo_proto_rawDescGZIP(), []int{1} } func (x *Repos) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *Repos) GetVersion() string { if x != nil { return x.Version } return "" } func (x *Repos) GetRepos() []*Repo { if x != nil { return x.Repos } return nil } var File_repo_proto protoreflect.FileDescriptor var file_repo_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x0c, 0x67, 0x69, 0x74, 0x54, 0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0b, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe4, 0x05, 0x0a, 0x04, 0x52, 0x65, 0x70, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x75, 0x6c, 0x6c, 0x50, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x6c, 0x6c, 0x50, 0x61, 0x74, 0x68, 0x12, 0x36, 0x0a, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x50, 0x75, 0x6c, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x50, 0x75, 0x6c, 0x6c, 0x12, 0x2a, 0x0a, 0x10, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x75, 0x73, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x75, 0x73, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x67, 0x6f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x67, 0x6f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x6f, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x67, 0x6f, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x67, 0x6f, 0x50, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x67, 0x6f, 0x50, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x6f, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x67, 0x6f, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x25, 0x0a, 0x06, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x52, 0x06, 0x67, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x12, 0x38, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x69, 0x72, 0x74, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x64, 0x69, 0x72, 0x74, 0x79, 0x12, 0x2b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x44, 0x65, 0x70, 0x73, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x18, 0x11, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x52, 0x4c, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x55, 0x52, 0x4c, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x6f, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x18, 0x13, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x6f, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x65, 0x73, 0x63, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x65, 0x73, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x6f, 0x4d, 0x6f, 0x64, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x67, 0x6f, 0x4d, 0x6f, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x6f, 0x53, 0x75, 0x6d, 0x18, 0x16, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x67, 0x6f, 0x53, 0x75, 0x6d, 0x22, 0x58, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x05, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x52, 0x05, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_repo_proto_rawDescOnce sync.Once file_repo_proto_rawDescData = file_repo_proto_rawDesc ) func file_repo_proto_rawDescGZIP() []byte { file_repo_proto_rawDescOnce.Do(func() { file_repo_proto_rawDescData = protoimpl.X.CompressGZIP(file_repo_proto_rawDescData) }) return file_repo_proto_rawDescData } var file_repo_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_repo_proto_goTypes = []any{ (*Repo)(nil), // 0: gitpb.Repo (*Repos)(nil), // 1: gitpb.Repos (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp (*GitTags)(nil), // 3: gitpb.GitTags (*GoDeps)(nil), // 4: gitpb.GoDeps } var file_repo_proto_depIdxs = []int32{ 2, // 0: gitpb.Repo.lastPull:type_name -> google.protobuf.Timestamp 3, // 1: gitpb.Repo.tags:type_name -> gitpb.GitTags 4, // 2: gitpb.Repo.goDeps:type_name -> gitpb.GoDeps 2, // 3: gitpb.Repo.lastGoDep:type_name -> google.protobuf.Timestamp 4, // 4: gitpb.Repo.published:type_name -> gitpb.GoDeps 0, // 5: gitpb.Repos.repos:type_name -> gitpb.Repo 6, // [6:6] is the sub-list for method output_type 6, // [6:6] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension extendee 0, // [0:6] is the sub-list for field type_name } func init() { file_repo_proto_init() } func file_repo_proto_init() { if File_repo_proto != nil { return } file_gitTag_proto_init() file_goDep_proto_init() type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_repo_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_repo_proto_goTypes, DependencyIndexes: file_repo_proto_depIdxs, MessageInfos: file_repo_proto_msgTypes, }.Build() File_repo_proto = out.File file_repo_proto_rawDesc = nil file_repo_proto_goTypes = nil file_repo_proto_depIdxs = nil } // `autogen:repo.sort.pb.go` package gitpb // This file was autogenerated with autogenpb. // go install go.wit.com/apps/autogenpb@latest // // You can use it on simple protobuf files // The .proto file must have a singular and plural form of a message // (for those of you that know ruby on rails, it's like that) // // You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for // // For an example, // go-clone go.wit.com/lib/protobuf/gitpb // import ( "fmt" "os" "sort" "sync" ) type RepoIterator struct { sync.RWMutex packs []*Repo index int } // NewRepoIterator initializes a new iterator. func NewRepoIterator(packs []*Repo) *RepoIterator { return &RepoIterator{packs: packs} } // Scan moves to the next element and returns false if there are no more packs. // Use Scan() in a loop, similar to a while loop // // for iterator.Scan() // d := iterator.Next( // fmt.Println("found UUID:", d.Uuid // } func (it *RepoIterator) Scan() bool { if it.index >= len(it.packs) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *RepoIterator) Next() *Repo { if it.packs[it.index-1] == nil { for i, d := range it.packs { fmt.Println("i =", i, d) } fmt.Println("protobuf autogenpb sort error len =", len(it.packs)) fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1) os.Exit(-1) } return it.packs[it.index-1] } // does not enforce any unique fields func (all *Repos) Append(newP *Repo) bool { all.Lock.RLock() defer all.Lock.RUnlock() all.Repos = append(all.Repos, newP) return true } func (all *Repos) All() *RepoIterator { repoPointers := all.selectAllRepo() iterator := NewRepoIterator(repoPointers) return iterator } func (all *Repos) Len() int { all.Lock.RLock() defer all.Lock.RUnlock() return len(all.Repos) } func (all *Repos) SortByGoPath() *RepoIterator { packs := all.selectAllRepo() sort.Sort(RepoGoPath(packs)) iterator := NewRepoIterator(packs) return iterator } type RepoGoPath []*Repo func (a RepoGoPath) Len() int { return len(a) } func (a RepoGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } func (a RepoGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces GoPath is unique func (all *Repos) AppendUniqueGoPath(newP *Repo) bool { all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.Repos { if p.GoPath == newP.GoPath { return false } } all.Repos = append(all.Repos, newP) return true } func (all *Repos) DeleteByGoPath(s string) bool { all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.Repos { if all.Repos[i].GoPath == s { all.Repos[i] = all.Repos[len(all.Repos)-1] all.Repos = all.Repos[:len(all.Repos)-1] return true } } return false } // enforces GoPath is unique func (all *Repos) ReplaceGoPath(newP *Repo) bool { // todo: make unique name here all.Lock.RLock() defer all.Lock.RUnlock() for _, p := range all.Repos { if p.GoPath == newP.GoPath { return false } } all.Repos = append(all.Repos, newP) return true } // find a dependancy by the go path func (all *Repos) FindByGoPath(s string) *Repo { if all == nil { return nil } all.Lock.RLock() defer all.Lock.RUnlock() for i, _ := range all.Repos { if all.Repos[i].GoPath == s { return all.Repos[i] } } return nil } // safely returns a slice of pointers to the Repo protobufs func (all *Repos) selectAllRepo() []*Repo { all.Lock.RLock() defer all.Lock.RUnlock() // Create a new slice to hold pointers to each Repo var aStuff []*Repo aStuff = make([]*Repo, len(all.Repos)) for i, p := range all.Repos { aStuff[i] = p // Copy pointers for safe iteration } return aStuff } // `autogen:`
|
@ -29,3 +29,12 @@ func (a GitTagAge) Less(i, j int) bool {
|
|||
return false
|
||||
}
|
||||
func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func (repo *Repo) NewestAge() time.Duration {
|
||||
all := repo.Tags.SortByAge()
|
||||
for all.Scan() {
|
||||
r := all.Next()
|
||||
return time.Since(r.GetAuthordate().AsTime())
|
||||
}
|
||||
return time.Since(time.Now())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue