finally re-organize and rename Clone to GoClone()
This commit is contained in:
parent
24c96ccaa7
commit
4582a76081
Notes:
Jeff Carr
2024-12-18 18:20:09 -06:00
// `autogen:go.mod` module go.wit.com/lib/protobuf/forgepb go 1.21 toolchain go1.23.4 require ( github.com/destel/rill v0.6.0 go.wit.com/lib/gui/shell v0.22.19 go.wit.com/lib/protobuf/gitpb v0.0.37 go.wit.com/lib/protobuf/zoopb v0.0.20 go.wit.com/log v0.22.9 google.golang.org/protobuf v1.36.0 ) require github.com/go-cmd/cmd v1.4.3 // indirect // `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.19 h1:c2xUbSPulUp8MKDk/zSPcHyPCPSkzuIvG+OqWadxU5I= go.wit.com/lib/gui/shell v0.22.19/go.mod h1:zduuMSWq+EE7w0xbXn+vkoGZ4HJhURVJpvXw8oK9WAU= go.wit.com/lib/protobuf/gitpb v0.0.37 h1:fmg7t638GgDpi87/KL84Ytv5+Xv+A3NPGD36E3zRuKo= go.wit.com/lib/protobuf/gitpb v0.0.37/go.mod h1:cBqXEzIbEuyJIgsjzBCy0SecE7tofnu0qLPvYgyx+ls= go.wit.com/lib/protobuf/zoopb v0.0.20 h1:Ki/MhVuHibwA615hAnXF99My35GYPkGOh3qkTW91Wao= go.wit.com/lib/protobuf/zoopb v0.0.20/go.mod h1:Sw47KomE+5nzioBTC/Gf8iV3p8gidB7uVoeyAtPvWi4= 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.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= // `autogen:forgeConfig.marshal.pb.go` package forgepb // This file was autogenerated with autogenpb v0.0.30-1-g84c25d7 DO NOT EDIT // 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 *ForgeConfigs) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *ForgeConfigs) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *ForgeConfigs) 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 *ForgeConfigs) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *ForgeConfigs) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *ForgeConfigs) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *ForgeConfigs) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:forgeConfig.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: forgeConfig.proto package forgepb 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) ) // define 3 branches. that is all that is supported // the term 'master' is used in the code because 'main' is a reserved word in golang already // allow 'read only' and 'private' flags // package names sometimes must be different than the binary name // for example 'zookeeper' is packaged as 'zookeeper-go' // // due to the prior apache foundation project. This happens and is ok! type ForgeConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields GoPath string `protobuf:"bytes,1,opt,name=goPath,proto3" json:"goPath,omitempty"` // `autogenpb:unique` // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo" Writable bool `protobuf:"varint,2,opt,name=writable,proto3" json:"writable,omitempty"` // if you have write access to the repo ReadOnly bool `protobuf:"varint,3,opt,name=readOnly,proto3" json:"readOnly,omitempty"` // the opposite, but needed for now because I don't know what I'm doing Private bool `protobuf:"varint,4,opt,name=private,proto3" json:"private,omitempty"` // if the repo can be published Directory bool `protobuf:"varint,5,opt,name=directory,proto3" json:"directory,omitempty"` // everything in this directory should use these writable & private values Favorite bool `protobuf:"varint,6,opt,name=favorite,proto3" json:"favorite,omitempty"` // you like this. always git clone/go clone this repo Interesting bool `protobuf:"varint,7,opt,name=interesting,proto3" json:"interesting,omitempty"` // this is something interesting you found and want to remember it MasterBranchName string `protobuf:"bytes,8,opt,name=masterBranchName,proto3" json:"masterBranchName,omitempty"` // git 'main' or 'master' branch name DevelBranchName string `protobuf:"bytes,9,opt,name=develBranchName,proto3" json:"develBranchName,omitempty"` // whatever the git 'devel' branch name is UserBranchName string `protobuf:"bytes,10,opt,name=userBranchName,proto3" json:"userBranchName,omitempty"` // whatever your username branch is DebName string `protobuf:"bytes,11,opt,name=debName,proto3" json:"debName,omitempty"` // the actual name used with 'apt install' (or distro apt equivalent. Verstamp *timestamppb.Timestamp `protobuf:"bytes,12,opt,name=verstamp,proto3" json:"verstamp,omitempty"` // the git commit timestamp of the version GoSrc string `protobuf:"bytes,13,opt,name=goSrc,proto3" json:"goSrc,omitempty"` // is ~/go/src unless a go.work file is found } func (x *ForgeConfig) Reset() { *x = ForgeConfig{} mi := &file_forgeConfig_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *ForgeConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*ForgeConfig) ProtoMessage() {} func (x *ForgeConfig) ProtoReflect() protoreflect.Message { mi := &file_forgeConfig_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 ForgeConfig.ProtoReflect.Descriptor instead. func (*ForgeConfig) Descriptor() ([]byte, []int) { return file_forgeConfig_proto_rawDescGZIP(), []int{0} } func (x *ForgeConfig) GetGoPath() string { if x != nil { return x.GoPath } return "" } func (x *ForgeConfig) GetWritable() bool { if x != nil { return x.Writable } return false } func (x *ForgeConfig) GetReadOnly() bool { if x != nil { return x.ReadOnly } return false } func (x *ForgeConfig) GetPrivate() bool { if x != nil { return x.Private } return false } func (x *ForgeConfig) GetDirectory() bool { if x != nil { return x.Directory } return false } func (x *ForgeConfig) GetFavorite() bool { if x != nil { return x.Favorite } return false } func (x *ForgeConfig) GetInteresting() bool { if x != nil { return x.Interesting } return false } func (x *ForgeConfig) GetMasterBranchName() string { if x != nil { return x.MasterBranchName } return "" } func (x *ForgeConfig) GetDevelBranchName() string { if x != nil { return x.DevelBranchName } return "" } func (x *ForgeConfig) GetUserBranchName() string { if x != nil { return x.UserBranchName } return "" } func (x *ForgeConfig) GetDebName() string { if x != nil { return x.DebName } return "" } func (x *ForgeConfig) GetVerstamp() *timestamppb.Timestamp { if x != nil { return x.Verstamp } return nil } func (x *ForgeConfig) GetGoSrc() string { if x != nil { return x.GoSrc } return "" } type ForgeConfigs struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // could be useful for /usr/share/file/magic someday? Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // could be used for protobuf schema change violations? ForgeConfigs []*ForgeConfig `protobuf:"bytes,3,rep,name=ForgeConfigs,proto3" json:"ForgeConfigs,omitempty"` } func (x *ForgeConfigs) Reset() { *x = ForgeConfigs{} mi := &file_forgeConfig_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *ForgeConfigs) String() string { return protoimpl.X.MessageStringOf(x) } func (*ForgeConfigs) ProtoMessage() {} func (x *ForgeConfigs) ProtoReflect() protoreflect.Message { mi := &file_forgeConfig_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 ForgeConfigs.ProtoReflect.Descriptor instead. func (*ForgeConfigs) Descriptor() ([]byte, []int) { return file_forgeConfig_proto_rawDescGZIP(), []int{1} } func (x *ForgeConfigs) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *ForgeConfigs) GetVersion() string { if x != nil { return x.Version } return "" } func (x *ForgeConfigs) GetForgeConfigs() []*ForgeConfig { if x != nil { return x.ForgeConfigs } return nil } var File_forgeConfig_proto protoreflect.FileDescriptor var file_forgeConfig_proto_rawDesc = []byte{ 0x0a, 0x11, 0x66, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x66, 0x6f, 0x72, 0x67, 0x65, 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, 0xb9, 0x03, 0x0a, 0x0b, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x77, 0x72, 0x69, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x77, 0x72, 0x69, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x2a, 0x0a, 0x10, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x08, 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, 0x09, 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, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x75, 0x73, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x62, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x62, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x76, 0x65, 0x72, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x0c, 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, 0x76, 0x65, 0x72, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x6f, 0x53, 0x72, 0x63, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x67, 0x6f, 0x53, 0x72, 0x63, 0x22, 0x76, 0x0a, 0x0c, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 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, 0x38, 0x0a, 0x0c, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x66, 0x6f, 0x72, 0x67, 0x65, 0x70, 0x62, 0x2e, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0c, 0x46, 0x6f, 0x72, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_forgeConfig_proto_rawDescOnce sync.Once file_forgeConfig_proto_rawDescData = file_forgeConfig_proto_rawDesc ) func file_forgeConfig_proto_rawDescGZIP() []byte { file_forgeConfig_proto_rawDescOnce.Do(func() { file_forgeConfig_proto_rawDescData = protoimpl.X.CompressGZIP(file_forgeConfig_proto_rawDescData) }) return file_forgeConfig_proto_rawDescData } var file_forgeConfig_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_forgeConfig_proto_goTypes = []any{ (*ForgeConfig)(nil), // 0: forgepb.ForgeConfig (*ForgeConfigs)(nil), // 1: forgepb.ForgeConfigs (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp } var file_forgeConfig_proto_depIdxs = []int32{ 2, // 0: forgepb.ForgeConfig.verstamp:type_name -> google.protobuf.Timestamp 0, // 1: forgepb.ForgeConfigs.ForgeConfigs:type_name -> forgepb.ForgeConfig 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_forgeConfig_proto_init() } func file_forgeConfig_proto_init() { if File_forgeConfig_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_forgeConfig_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_forgeConfig_proto_goTypes, DependencyIndexes: file_forgeConfig_proto_depIdxs, MessageInfos: file_forgeConfig_proto_msgTypes, }.Build() File_forgeConfig_proto = out.File file_forgeConfig_proto_rawDesc = nil file_forgeConfig_proto_goTypes = nil file_forgeConfig_proto_depIdxs = nil } // `autogen:forgeConfig.sort.pb.go` package forgepb // This file was autogenerated with autogenpb v0.0.30-1-g84c25d7 DO NOT EDIT // 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" "sort" "sync" ) // bad global lock until I figure out some other plan // redo/fix protoc-gen-go 1.35 and do it there? // sync.RWMutex or sync.Mutex? var forgeConfigsMu sync.RWMutex type ForgeConfigIterator struct { sync.RWMutex packs []*ForgeConfig index int } // NewForgeConfigIterator initializes a new iterator. func NewForgeConfigIterator(packs []*ForgeConfig) *ForgeConfigIterator { return &ForgeConfigIterator{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 *ForgeConfigIterator) Scan() bool { if it.index >= len(it.packs) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *ForgeConfigIterator) Next() *ForgeConfig { 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) } return it.packs[it.index-1] } // does not enforce any unique fields func (all *ForgeConfigs) Append(newP *ForgeConfig) bool { forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() all.ForgeConfigs = append(all.ForgeConfigs, newP) return true } func (all *ForgeConfigs) All() *ForgeConfigIterator { forgeConfigPointers := all.selectAllForgeConfig() iterator := NewForgeConfigIterator(forgeConfigPointers) return iterator } func (all *ForgeConfigs) Len() int { forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() return len(all.ForgeConfigs) } func (all *ForgeConfigs) SortByGoPath() *ForgeConfigIterator { packs := all.selectAllForgeConfig() sort.Sort(ForgeConfigGoPath(packs)) iterator := NewForgeConfigIterator(packs) return iterator } type ForgeConfigGoPath []*ForgeConfig func (a ForgeConfigGoPath) Len() int { return len(a) } func (a ForgeConfigGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } func (a ForgeConfigGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // enforces GoPath is unique func (all *ForgeConfigs) AppendUniqueGoPath(newP *ForgeConfig) bool { forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() for _, p := range all.ForgeConfigs { if p.GoPath == newP.GoPath { return false } } all.ForgeConfigs = append(all.ForgeConfigs, newP) return true } func (all *ForgeConfigs) DeleteByGoPath(s string) bool { forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() for i, _ := range all.ForgeConfigs { if all.ForgeConfigs[i].GoPath == s { all.ForgeConfigs[i] = all.ForgeConfigs[len(all.ForgeConfigs)-1] all.ForgeConfigs = all.ForgeConfigs[:len(all.ForgeConfigs)-1] return true } } return false } // enforces GoPath is unique func (all *ForgeConfigs) ReplaceGoPath(newP *ForgeConfig) bool { // todo: make unique name here forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() for _, p := range all.ForgeConfigs { if p.GoPath == newP.GoPath { return false } } all.ForgeConfigs = append(all.ForgeConfigs, newP) return true } // find a dependancy by the go path func (all *ForgeConfigs) FindByGoPath(s string) *ForgeConfig { if all == nil { return nil } forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() for i, _ := range all.ForgeConfigs { if all.ForgeConfigs[i].GoPath == s { return all.ForgeConfigs[i] } } return nil } // safely returns a slice of pointers to the ForgeConfig protobufs func (all *ForgeConfigs) selectAllForgeConfig() []*ForgeConfig { forgeConfigsMu.RLock() defer forgeConfigsMu.RUnlock() // Create a new slice to hold pointers to each ForgeConfig var aStuff []*ForgeConfig aStuff = make([]*ForgeConfig, len(all.ForgeConfigs)) for i, p := range all.ForgeConfigs { aStuff[i] = p // Copy pointers for safe iteration } return aStuff } // `autogen:patch.marshal.pb.go` package forgepb // This file was autogenerated with autogenpb v0.0.30-1-g84c25d7 DO NOT EDIT // 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 *Patchs) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *Patchs) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *Patchs) 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 *Patchs) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *Patchs) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *Patchs) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *Patchs) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:patch.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: patch.proto package forgepb 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 Patch struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` // `autogenpb:unique` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // RepoPath string `protobuf:"bytes,3,opt,name=repoPath,proto3" json:"repoPath,omitempty"` // path to the git repo BranchName string `protobuf:"bytes,4,opt,name=branchName,proto3" json:"branchName,omitempty"` // BranchHash string `protobuf:"bytes,5,opt,name=branchHash,proto3" json:"branchHash,omitempty"` // Ctime *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=ctime,proto3" json:"ctime,omitempty"` // the git commit timestamp of the version } func (x *Patch) Reset() { *x = Patch{} mi := &file_patch_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *Patch) String() string { return protoimpl.X.MessageStringOf(x) } func (*Patch) ProtoMessage() {} func (x *Patch) ProtoReflect() protoreflect.Message { mi := &file_patch_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 Patch.ProtoReflect.Descriptor instead. func (*Patch) Descriptor() ([]byte, []int) { return file_patch_proto_rawDescGZIP(), []int{0} } func (x *Patch) GetFilename() string { if x != nil { return x.Filename } return "" } func (x *Patch) GetData() []byte { if x != nil { return x.Data } return nil } func (x *Patch) GetRepoPath() string { if x != nil { return x.RepoPath } return "" } func (x *Patch) GetBranchName() string { if x != nil { return x.BranchName } return "" } func (x *Patch) GetBranchHash() string { if x != nil { return x.BranchHash } return "" } func (x *Patch) GetCtime() *timestamppb.Timestamp { if x != nil { return x.Ctime } return nil } type Patchs struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:0703df95-6a38-4422-994b-c55d3d6001f9` // todo: add file support Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // could be used for protobuf schema change violations? Patchs []*Patch `protobuf:"bytes,3,rep,name=Patchs,proto3" json:"Patchs,omitempty"` Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` // Comment string `protobuf:"bytes,5,opt,name=comment,proto3" json:"comment,omitempty"` // GitAuthorName string `protobuf:"bytes,6,opt,name=gitAuthorName,proto3" json:"gitAuthorName,omitempty"` // GitAuthorEmail string `protobuf:"bytes,7,opt,name=gitAuthorEmail,proto3" json:"gitAuthorEmail,omitempty"` // Ctime *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=ctime,proto3" json:"ctime,omitempty"` // create time of this patchset TmpDir string `protobuf:"bytes,9,opt,name=tmpDir,proto3" json:"tmpDir,omitempty"` // temp dir StartBranchName string `protobuf:"bytes,10,opt,name=startBranchName,proto3" json:"startBranchName,omitempty"` // EndBranchName string `protobuf:"bytes,11,opt,name=endBranchName,proto3" json:"endBranchName,omitempty"` // StartBranchHash string `protobuf:"bytes,12,opt,name=startBranchHash,proto3" json:"startBranchHash,omitempty"` // EndBranchHash string `protobuf:"bytes,13,opt,name=endBranchHash,proto3" json:"endBranchHash,omitempty"` // } func (x *Patchs) Reset() { *x = Patchs{} mi := &file_patch_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *Patchs) String() string { return protoimpl.X.MessageStringOf(x) } func (*Patchs) ProtoMessage() {} func (x *Patchs) ProtoReflect() protoreflect.Message { mi := &file_patch_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 Patchs.ProtoReflect.Descriptor instead. func (*Patchs) Descriptor() ([]byte, []int) { return file_patch_proto_rawDescGZIP(), []int{1} } func (x *Patchs) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *Patchs) GetVersion() string { if x != nil { return x.Version } return "" } func (x *Patchs) GetPatchs() []*Patch { if x != nil { return x.Patchs } return nil } func (x *Patchs) GetName() string { if x != nil { return x.Name } return "" } func (x *Patchs) GetComment() string { if x != nil { return x.Comment } return "" } func (x *Patchs) GetGitAuthorName() string { if x != nil { return x.GitAuthorName } return "" } func (x *Patchs) GetGitAuthorEmail() string { if x != nil { return x.GitAuthorEmail } return "" } func (x *Patchs) GetCtime() *timestamppb.Timestamp { if x != nil { return x.Ctime } return nil } func (x *Patchs) GetTmpDir() string { if x != nil { return x.TmpDir } return "" } func (x *Patchs) GetStartBranchName() string { if x != nil { return x.StartBranchName } return "" } func (x *Patchs) GetEndBranchName() string { if x != nil { return x.EndBranchName } return "" } func (x *Patchs) GetStartBranchHash() string { if x != nil { return x.StartBranchHash } return "" } func (x *Patchs) GetEndBranchHash() string { if x != nil { return x.EndBranchHash } return "" } var File_patch_proto protoreflect.FileDescriptor var file_patch_proto_rawDesc = []byte{ 0x0a, 0x0b, 0x70, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x66, 0x6f, 0x72, 0x67, 0x65, 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, 0xc5, 0x01, 0x0a, 0x05, 0x50, 0x61, 0x74, 0x63, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x70, 0x6f, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x12, 0x30, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, 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, 0x22, 0xc4, 0x03, 0x0a, 0x06, 0x50, 0x61, 0x74, 0x63, 0x68, 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, 0x26, 0x0a, 0x06, 0x50, 0x61, 0x74, 0x63, 0x68, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x66, 0x6f, 0x72, 0x67, 0x65, 0x70, 0x62, 0x2e, 0x50, 0x61, 0x74, 0x63, 0x68, 0x52, 0x06, 0x50, 0x61, 0x74, 0x63, 0x68, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x67, 0x69, 0x74, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x67, 0x69, 0x74, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x67, 0x69, 0x74, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x67, 0x69, 0x74, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x30, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 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, 0x16, 0x0a, 0x06, 0x74, 0x6d, 0x70, 0x44, 0x69, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x6d, 0x70, 0x44, 0x69, 0x72, 0x12, 0x28, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x65, 0x6e, 0x64, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x12, 0x24, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x65, 0x6e, 0x64, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x61, 0x73, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_patch_proto_rawDescOnce sync.Once file_patch_proto_rawDescData = file_patch_proto_rawDesc ) func file_patch_proto_rawDescGZIP() []byte { file_patch_proto_rawDescOnce.Do(func() { file_patch_proto_rawDescData = protoimpl.X.CompressGZIP(file_patch_proto_rawDescData) }) return file_patch_proto_rawDescData } var file_patch_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_patch_proto_goTypes = []any{ (*Patch)(nil), // 0: forgepb.Patch (*Patchs)(nil), // 1: forgepb.Patchs (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp } var file_patch_proto_depIdxs = []int32{ 2, // 0: forgepb.Patch.ctime:type_name -> google.protobuf.Timestamp 0, // 1: forgepb.Patchs.Patchs:type_name -> forgepb.Patch 2, // 2: forgepb.Patchs.ctime:type_name -> google.protobuf.Timestamp 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_patch_proto_init() } func file_patch_proto_init() { if File_patch_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_patch_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_patch_proto_goTypes, DependencyIndexes: file_patch_proto_depIdxs, MessageInfos: file_patch_proto_msgTypes, }.Build() File_patch_proto = out.File file_patch_proto_rawDesc = nil file_patch_proto_goTypes = nil file_patch_proto_depIdxs = nil } // `autogen:patch.sort.pb.go` package forgepb // This file was autogenerated with autogenpb v0.0.30-1-g84c25d7 DO NOT EDIT // 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" "sort" "sync" ) // bad global lock until I figure out some other plan // redo/fix protoc-gen-go 1.35 and do it there? // sync.RWMutex or sync.Mutex? var patchsMu sync.RWMutex type PatchIterator struct { sync.RWMutex packs []*Patch index int } // NewPatchIterator initializes a new iterator. func NewPatchIterator(packs []*Patch) *PatchIterator { return &PatchIterator{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 *PatchIterator) Scan() bool { if it.index >= len(it.packs) { return false } it.index++ return true } // Next() returns the next thing in the array func (it *PatchIterator) Next() *Patch { 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) } return it.packs[it.index-1] } // does not enforce any unique fields func (all *Patchs) Append(newP *Patch) bool { patchsMu.RLock() defer patchsMu.RUnlock() all.Patchs = append(all.Patchs, newP) return true } func (all *Patchs) All() *PatchIterator { patchPointers := all.selectAllPatch() iterator := NewPatchIterator(patchPointers) return iterator } func (all *Patchs) Len() int { patchsMu.RLock() defer patchsMu.RUnlock() return len(all.Patchs) } func (all *Patchs) SortByFilename() *PatchIterator { packs := all.selectAllPatch() sort.Sort(PatchFilename(packs)) iterator := NewPatchIterator(packs) return iterator } 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] } // enforces Filename is unique func (all *Patchs) AppendUniqueFilename(newP *Patch) bool { patchsMu.RLock() defer patchsMu.RUnlock() for _, p := range all.Patchs { if p.Filename == newP.Filename { return false } } all.Patchs = append(all.Patchs, newP) return true } func (all *Patchs) DeleteByFilename(s string) bool { patchsMu.RLock() defer patchsMu.RUnlock() for i, _ := range all.Patchs { if all.Patchs[i].Filename == s { all.Patchs[i] = all.Patchs[len(all.Patchs)-1] all.Patchs = all.Patchs[:len(all.Patchs)-1] return true } } return false } // enforces Filename is unique func (all *Patchs) ReplaceFilename(newP *Patch) bool { // todo: make unique name here patchsMu.RLock() defer patchsMu.RUnlock() for _, p := range all.Patchs { if p.Filename == newP.Filename { return false } } all.Patchs = append(all.Patchs, newP) return true } // find a dependancy by the go path func (all *Patchs) FindByFilename(s string) *Patch { if all == nil { return nil } patchsMu.RLock() defer patchsMu.RUnlock() for i, _ := range all.Patchs { if all.Patchs[i].Filename == s { return all.Patchs[i] } } return nil } // safely returns a slice of pointers to the Patch protobufs func (all *Patchs) selectAllPatch() []*Patch { patchsMu.RLock() defer patchsMu.RUnlock() // Create a new slice to hold pointers to each Patch var aStuff []*Patch aStuff = make([]*Patch, len(all.Patchs)) for i, p := range all.Patchs { aStuff[i] = p // Copy pointers for safe iteration } return aStuff } // `autogen:uuid.marshal.pb.go` package forgepb // This file was autogenerated with autogenpb v0.0.30-1-g84c25d7 DO NOT EDIT // 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 *UuidConfigs) FormatJSON() string { return protojson.Format(v) } // marshal json func (v *UuidConfigs) MarshalJSON() ([]byte, error) { return protojson.Marshal(v) } // unmarshal json func (v *UuidConfigs) 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 *UuidConfigs) FormatTEXT() string { return prototext.Format(v) } // unmarshalTEXT. This reads the .text config file back in after the user edits it func (v *UuidConfigs) UnmarshalTEXT(data []byte) error { return prototext.Unmarshal(data, v) } // marshal to wire. This is called winning. func (v *UuidConfigs) Marshal() ([]byte, error) { return proto.Marshal(v) } // unmarshal from wire. You have won. func (v *UuidConfigs) Unmarshal(data []byte) error { return proto.Unmarshal(data, v) } // `autogen:uuid.pb.go` // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.2-devel // protoc v3.21.12 // source: uuid.proto // experiment to identify .pb files incase things go sideways package forgepb import ( reflect "reflect" sync "sync" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) 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) ) // autogenpb:no-sort type UuidConfigs struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // could be useful for /usr/share/file/magic someday? Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // could be used for protobuf schema change violations? } func (x *UuidConfigs) Reset() { *x = UuidConfigs{} mi := &file_uuid_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } func (x *UuidConfigs) String() string { return protoimpl.X.MessageStringOf(x) } func (*UuidConfigs) ProtoMessage() {} func (x *UuidConfigs) ProtoReflect() protoreflect.Message { mi := &file_uuid_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 UuidConfigs.ProtoReflect.Descriptor instead. func (*UuidConfigs) Descriptor() ([]byte, []int) { return file_uuid_proto_rawDescGZIP(), []int{0} } func (x *UuidConfigs) GetUuid() string { if x != nil { return x.Uuid } return "" } func (x *UuidConfigs) GetVersion() string { if x != nil { return x.Version } return "" } var File_uuid_proto protoreflect.FileDescriptor var file_uuid_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x75, 0x75, 0x69, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x66, 0x6f, 0x72, 0x67, 0x65, 0x70, 0x62, 0x22, 0x3b, 0x0a, 0x0b, 0x55, 0x75, 0x69, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_uuid_proto_rawDescOnce sync.Once file_uuid_proto_rawDescData = file_uuid_proto_rawDesc ) func file_uuid_proto_rawDescGZIP() []byte { file_uuid_proto_rawDescOnce.Do(func() { file_uuid_proto_rawDescData = protoimpl.X.CompressGZIP(file_uuid_proto_rawDescData) }) return file_uuid_proto_rawDescData } var file_uuid_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_uuid_proto_goTypes = []any{ (*UuidConfigs)(nil), // 0: forgepb.UuidConfigs } var file_uuid_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_uuid_proto_init() } func file_uuid_proto_init() { if File_uuid_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_uuid_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_uuid_proto_goTypes, DependencyIndexes: file_uuid_proto_depIdxs, MessageInfos: file_uuid_proto_msgTypes, }.Build() File_uuid_proto = out.File file_uuid_proto_rawDesc = nil file_uuid_proto_goTypes = nil file_uuid_proto_depIdxs = nil } // `autogen:`
272
clone.go
272
clone.go
|
@ -2,193 +2,171 @@ package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: make some config file for things like this
|
// will not violate filesystem namespace
|
||||||
// can be used to work around temporary problems
|
// always returns the path or a parent path
|
||||||
func clonePathHack(dirname string, basedir string, gopath string) (string, error) {
|
//
|
||||||
// newdir = helloworld
|
// attemps to exec git clone based off of a golang path
|
||||||
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
// will transferse parent directories in case the path
|
||||||
// giturl = https://gitea.wit.com/gui/helloworld
|
// is a child of a git repo
|
||||||
// func cloneActual(newdir, basedir, giturl string) error {
|
//
|
||||||
|
// returns *gitpb.Repo if already cloned
|
||||||
|
//
|
||||||
|
// example gopath = go.wit.com/apps/go-clone
|
||||||
|
// or "go.googlesource.com/go/src/cmd/internal/pkgpath/" returns repo for "go.googlesource.com/go"
|
||||||
|
func (f *Forge) GoClone(gopath string) (*gitpb.Repo, error) {
|
||||||
|
|
||||||
switch gopath {
|
// will match /root/go/src/go.wit.com/apps/go-clone/something/inside
|
||||||
case "golang.org/x/crypto":
|
// and return the *gitpb.Repo for "go.wit.com/apps/go-clone"
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/crypto")
|
|
||||||
case "golang.org/x/mod":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/mod")
|
|
||||||
case "golang.org/x/net":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/net")
|
|
||||||
case "golang.org/x/sys":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/sys")
|
|
||||||
case "golang.org/x/sync":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/sync")
|
|
||||||
case "golang.org/x/term":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/term")
|
|
||||||
case "golang.org/x/text":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/text")
|
|
||||||
case "golang.org/x/tools":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/tools")
|
|
||||||
case "golang.org/x/xerrors":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/xerrors")
|
|
||||||
case "google.golang.org/protobuf":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/protobuf")
|
|
||||||
case "google.golang.org/genproto":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/genproto")
|
|
||||||
case "google.golang.org/api":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/api")
|
|
||||||
case "google.golang.org/grpc":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/grpc")
|
|
||||||
case "google.golang.org/appengine":
|
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/appengine")
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(gopath, "github.com/go-gl/glfw") {
|
|
||||||
return cloneActual(dirname, basedir, "https://github.com/go-gl/glfw")
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("no gopath override here")
|
|
||||||
}
|
|
||||||
|
|
||||||
// attempt to git clone if the go path doesn't exist
|
|
||||||
// does a git clone, if it works, returns true
|
|
||||||
// gopath = go.wit.com/apps/helloworld
|
|
||||||
func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
|
||||||
var err error
|
|
||||||
fullpath := filepath.Join(f.goSrc, gopath)
|
fullpath := filepath.Join(f.goSrc, gopath)
|
||||||
|
if pb := f.FindAnyPath(fullpath); pb != nil {
|
||||||
if pb := f.Repos.FindByFullPath(fullpath); pb != nil {
|
|
||||||
// repo already exists
|
// repo already exists
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dirname := filepath.Base(fullpath)
|
|
||||||
basedir := strings.TrimSuffix(fullpath, dirname)
|
|
||||||
|
|
||||||
url := "https://" + gopath
|
|
||||||
log.Info("trying git clone")
|
|
||||||
log.Info("gopath =", gopath)
|
|
||||||
|
|
||||||
// try a direct git clone against the gopath
|
// try a direct git clone against the gopath
|
||||||
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "https://go.wit.com/apps/helloworld")
|
// if this doesn't work, probably the package is abandoned and you
|
||||||
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
// are probably using something old, broken, or wrong
|
||||||
return f.finishClone(gopath, finalurl)
|
if repo, err := f.urlClone(gopath, "https://"+gopath); repo != nil {
|
||||||
|
return repo, err
|
||||||
}
|
}
|
||||||
log.Info("direct attempt at git clone failed", url)
|
|
||||||
|
|
||||||
// if direct git clone doesn't work, look for a redirect
|
// check for parent git repos
|
||||||
// go directly to the URL as that is autoritive. If that failes
|
if repo, err := f.goClonePop(gopath); repo != nil {
|
||||||
// try the go package system as maybe the git site no longer exists
|
return repo, err
|
||||||
if url, err = findGoImport(url); err != nil {
|
|
||||||
log.Info("findGoImport() DID NOT WORK", url)
|
|
||||||
log.Info("findGoImport() DID NOT WORK", err)
|
|
||||||
} else {
|
|
||||||
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
|
||||||
return f.finishClone(gopath, finalurl)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log.Info("git clone from 'go-import' info failed", url)
|
|
||||||
|
|
||||||
// query the golang package system for the last known location
|
// query the golang package system for the last known location
|
||||||
// NOTE: take time to thank the go developers and google for designing this wonderful system
|
// NOTE: take time to thank the go developers and google for designing this wonderful system
|
||||||
if url, err = runGoList(gopath); err != nil {
|
if pkgurl, err := runGoList(gopath); err == nil {
|
||||||
log.Info("go list failed", err)
|
if repo, err := f.urlClone(gopath, pkgurl); repo != nil {
|
||||||
} else {
|
return repo, err
|
||||||
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
|
||||||
return f.finishClone(gopath, finalurl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("git clone from 'git list' info failed", url)
|
|
||||||
|
|
||||||
// try to parse a redirect
|
// todo: emit some sort of warning?
|
||||||
|
|
||||||
if finalurl, err := clonePathHack(dirname, basedir, gopath); err == nil {
|
// hacks
|
||||||
return f.finishClone(gopath, finalurl)
|
if repo, err := f.clonePathHack(gopath); repo != nil {
|
||||||
|
return repo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("can not find git sources for gopath " + gopath)
|
return nil, errors.New("can not find git sources for gopath " + gopath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// actually does something smart
|
// this is obvious a experiemental hack
|
||||||
func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
|
// todo: make a config file for this?
|
||||||
var err error
|
func overridePath(gopath string) string {
|
||||||
newr := f.FindByGoPath(gopath)
|
switch gopath {
|
||||||
if newr == nil {
|
case "golang.org/x/crypto":
|
||||||
newr, err = f.NewGoRepo(gopath, giturl)
|
return "https://" + "go.googlesource.com/crypto"
|
||||||
|
case "golang.org/x/mod":
|
||||||
|
return "https://" + "go.googlesource.com/mod"
|
||||||
|
case "golang.org/x/net":
|
||||||
|
return "https://" + "go.googlesource.com/net"
|
||||||
|
case "golang.org/x/sys":
|
||||||
|
return "https://" + "go.googlesource.com/sys"
|
||||||
|
case "golang.org/x/sync":
|
||||||
|
return "https://" + "go.googlesource.com/sync"
|
||||||
|
case "golang.org/x/term":
|
||||||
|
return "https://" + "go.googlesource.com/term"
|
||||||
|
case "golang.org/x/text":
|
||||||
|
return "https://" + "go.googlesource.com/text"
|
||||||
|
case "golang.org/x/tools":
|
||||||
|
return "https://" + "go.googlesource.com/tools"
|
||||||
|
case "golang.org/x/xerrors":
|
||||||
|
return "https://" + "go.googlesource.com/xerrors"
|
||||||
|
case "google.golang.org/protobuf":
|
||||||
|
return "https://" + "go.googlesource.com/protobuf"
|
||||||
|
case "google.golang.org/genproto":
|
||||||
|
return "https://" + "go.googlesource.com/genproto"
|
||||||
|
case "google.golang.org/api":
|
||||||
|
return "https://" + "go.googlesource.com/api"
|
||||||
|
case "google.golang.org/grpc":
|
||||||
|
return "https://" + "go.googlesource.com/grpc"
|
||||||
|
case "google.golang.org/appengine":
|
||||||
|
return "https://" + "go.googlesource.com/appengine"
|
||||||
}
|
}
|
||||||
if newr == nil {
|
if strings.HasPrefix(gopath, "github.com/go-gl/glfw") {
|
||||||
log.Warn("forge.Clone() new repo can not be found or created for gopath", gopath)
|
return "https://github.com/go-gl/glfw"
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if newr.URL != giturl {
|
return ""
|
||||||
log.Warn("forge.Clone() url changed", newr.URL, "to", giturl)
|
|
||||||
newr.URL = giturl
|
|
||||||
}
|
|
||||||
if err := newr.RepoIgnoresGoMod(); err != nil {
|
|
||||||
log.Info("never modify go.mod or go.sum for this repo", newr.GetGoPath())
|
|
||||||
log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata")
|
|
||||||
newr.ParseGoSum()
|
|
||||||
return newr, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if newr.Exists("go.mod") {
|
|
||||||
return newr, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("todo: something went wrong probably. didn't finish. run go-mod-clean? (can't here. loop of circles)")
|
|
||||||
log.Info("todo: do go mod init here directly")
|
|
||||||
log.Info("todo: try to run go mod init here", newr.GetGoPath())
|
|
||||||
return newr, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make some config file for things like this
|
||||||
|
// can be used to work around temporary problems
|
||||||
|
func (f *Forge) clonePathHack(gopath string) (*gitpb.Repo, error) {
|
||||||
// newdir = helloworld
|
// newdir = helloworld
|
||||||
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
// giturl = https://gitea.wit.com/gui/helloworld
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
func cloneActual(newdir, basedir, giturl string) (string, error) {
|
|
||||||
log.Info("cloneActual() newdir =", newdir)
|
url := overridePath(gopath)
|
||||||
log.Info("cloneActual() basedir =", basedir)
|
if url == "" {
|
||||||
log.Info("cloneActual() giturl =", giturl)
|
return nil, errors.New("no gopath override here")
|
||||||
if !IsDirectory(basedir) {
|
|
||||||
os.MkdirAll(basedir, 0750)
|
|
||||||
}
|
|
||||||
err := os.Chdir(basedir)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("chdir failed", basedir, err)
|
|
||||||
return giturl, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := []string{"git", "clone", "--verbose", "--progress", giturl, newdir}
|
return f.urlClone(gopath, url)
|
||||||
log.Info("Running:", basedir, cmd)
|
|
||||||
r := shell.PathRunRealtime(basedir, cmd)
|
|
||||||
if r.Error != nil {
|
|
||||||
log.Warn("git clone error", r.Error)
|
|
||||||
return giturl, r.Error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fullpath := filepath.Join(basedir, newdir)
|
// for: github.com/gdamore/tcell/v2
|
||||||
if !IsDirectory(fullpath) {
|
// tries git clone github.com/gdamore/tcell/v2
|
||||||
log.Info("git clone failed", giturl)
|
// then git clone github.com/gdamore/tcell
|
||||||
return giturl, errors.New("git clone failed " + giturl)
|
// then git clone github.com/gdamore , etc
|
||||||
|
func (f *Forge) goClonePop(gopath string) (*gitpb.Repo, error) {
|
||||||
|
log.Info("forge.goClonePop() trying", gopath)
|
||||||
|
if gopath == "" {
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
gitdir := filepath.Join(fullpath, ".git")
|
fullpath := filepath.Join(f.GetGoSrc(), gopath)
|
||||||
if IsDirectory(gitdir) {
|
if pb := f.FindAnyPath(fullpath); pb != nil {
|
||||||
log.Info("git cloned worked to", fullpath)
|
// repo already exists
|
||||||
// also clone notes -- this can store the go.mod and go.sum files
|
return pb, nil
|
||||||
cmd := []string{"git", "fetch", "origin", "refs/notes/*:refs/notes/*"}
|
|
||||||
shell.PathRunRealtime(fullpath, cmd)
|
|
||||||
return giturl, nil
|
|
||||||
}
|
}
|
||||||
// git clone didn't really work but did make a directory
|
|
||||||
log.Info("fullpath is probably empty", fullpath)
|
newpath, _ := filepath.Split(gopath)
|
||||||
return giturl, errors.New("crapnuts. rmdir fullpath here? " + fullpath)
|
if repo, _ := f.urlClone(newpath, "https://"+newpath); repo != nil {
|
||||||
|
return repo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo, err := f.goClonePop(newpath); repo != nil {
|
||||||
|
return repo, err
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("forge.goClonePop() failed %s", gopath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// clone a URL directly, also try cloning if 'go-import' is sent
|
||||||
|
// newdir = helloworld
|
||||||
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
|
func (f *Forge) urlClone(gopath, giturl string) (*gitpb.Repo, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
fullpath := filepath.Join(f.goSrc, gopath)
|
||||||
|
basedir, newdir := filepath.Split(fullpath)
|
||||||
|
|
||||||
|
// clone the URL directly
|
||||||
|
if err = RunGitClone(newdir, basedir, giturl); err == nil {
|
||||||
|
return f.NewGoRepo(gopath, giturl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// see if the URL has go-import for a new URL
|
||||||
|
if giturl, err = findGoImport(giturl); err == nil {
|
||||||
|
if err = RunGitClone(newdir, basedir, giturl); err == nil {
|
||||||
|
return f.NewGoRepo(gopath, giturl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// log.Info("git clone from 'go-import' info failed", url)
|
||||||
|
// yes, this misses the first error
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the server for the current go path to git url mapping
|
// check the server for the current go path to git url mapping
|
||||||
|
@ -236,11 +214,3 @@ func findGoImport(url string) (string, error) {
|
||||||
|
|
||||||
return newurl, nil
|
return newurl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsDirectory(path string) bool {
|
|
||||||
info, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return info.IsDir()
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,9 +47,8 @@ func useGoSrc() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
pwd := filepath.Join(homeDir, "go/src")
|
pwd := filepath.Join(homeDir, "go/src")
|
||||||
shell.Mkdir(pwd)
|
err = os.MkdirAll(pwd, os.ModePerm)
|
||||||
// os.Chdir(pwd)
|
return pwd, err
|
||||||
return pwd, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forge) goWorkExists() bool {
|
func (f *Forge) goWorkExists() bool {
|
||||||
|
|
22
repoNew.go
22
repoNew.go
|
@ -143,6 +143,28 @@ func (f *Forge) FindByGoPath(gopath string) *gitpb.Repo {
|
||||||
return f.Repos.FindByFullPath(fullpath)
|
return f.Repos.FindByFullPath(fullpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tries any parent
|
||||||
|
func (f *Forge) FindAnyPath(dir string) *gitpb.Repo {
|
||||||
|
dir = filepath.Clean(dir)
|
||||||
|
repo := f.Repos.FindByFullPath(dir)
|
||||||
|
if repo != nil {
|
||||||
|
log.Info("FindAnyPath() worked = ", dir)
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
if dir == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if dir == "/" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
basedir, newdir := filepath.Split(dir)
|
||||||
|
if newdir == "" {
|
||||||
|
// is this correct? not sure what stupid windows does
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return f.FindAnyPath(basedir)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Forge) DeleteByGoPath(gopath string) bool {
|
func (f *Forge) DeleteByGoPath(gopath string) bool {
|
||||||
fullpath := filepath.Join(f.GetGoSrc(), gopath)
|
fullpath := filepath.Join(f.GetGoSrc(), gopath)
|
||||||
return f.Repos.DeleteByFullPath(fullpath)
|
return f.Repos.DeleteByFullPath(fullpath)
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package forgepb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// git clone (also downloads git notes)
|
||||||
|
// newdir = helloworld
|
||||||
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
|
func RunGitClone(newdir, basedir, giturl string) error {
|
||||||
|
log.Info("runGitClone() newdir =", newdir)
|
||||||
|
log.Info("runGitClone() basedir =", basedir)
|
||||||
|
log.Info("runGitClone() giturl =", giturl)
|
||||||
|
if !shell.IsDir(basedir) {
|
||||||
|
os.MkdirAll(basedir, os.ModePerm)
|
||||||
|
}
|
||||||
|
err := os.Chdir(basedir)
|
||||||
|
if err != nil {
|
||||||
|
// log.Warn("chdir failed", basedir, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := []string{"git", "clone", "--verbose", "--progress", giturl, newdir}
|
||||||
|
log.Info("Running:", basedir, cmd)
|
||||||
|
r := shell.PathRunRealtime(basedir, cmd)
|
||||||
|
if r.Error != nil {
|
||||||
|
// log.Warn("git clone error", r.Error)
|
||||||
|
return r.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
fullpath := filepath.Join(basedir, newdir)
|
||||||
|
if !shell.IsDir(fullpath) {
|
||||||
|
// log.Info("git clone failed", giturl)
|
||||||
|
return fmt.Errorf("git clone %s failed to create a directory", giturl)
|
||||||
|
}
|
||||||
|
gitdir := filepath.Join(fullpath, ".git")
|
||||||
|
if shell.IsDir(gitdir) {
|
||||||
|
// log.Info("git cloned worked to", fullpath)
|
||||||
|
// also clone notes -- this can store the go.mod and go.sum files
|
||||||
|
cmd := []string{"git", "fetch", "origin", "refs/notes/*:refs/notes/*"}
|
||||||
|
shell.PathRunRealtime(fullpath, cmd)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// git clone didn't really work but did make a directory
|
||||||
|
log.Info("fullpath is probably empty", fullpath)
|
||||||
|
return errors.New("crapnuts. rmdir fullpath here? " + fullpath)
|
||||||
|
}
|
Loading…
Reference in New Issue