diff --git a/.dockerignore b/.dockerignore index 87b1547c5e..cc25fc0030 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,6 +14,8 @@ private/buf/cmd/buf/command/alpha/protoc/internal/protoc-gen-insertion-point-rec private/buf/cmd/buf/command/alpha/protoc/internal/protoc-gen-insertion-point-writer/protoc-gen-insertion-point-writer private/buf/cmd/buf/command/alpha/protoc/test.txt private/buf/cmd/buf/workspacetests/other/proto/workspacetest/cache/ +private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/buf-commit-id-from-dashless +private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/buf-commit-id-to-dashless private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/buf-digest private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/buf-new-commit-id private/bufpkg/bufstyle/cmd/bufstyle/bufstyle diff --git a/.gitignore b/.gitignore index 09d10c07ce..7e4df7ba87 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ /private/buf/cmd/buf/command/alpha/protoc/internal/protoc-gen-insertion-point-writer/protoc-gen-insertion-point-writer /private/buf/cmd/buf/command/alpha/protoc/test.txt /private/buf/cmd/buf/workspacetests/other/proto/workspacetest/cache/ +/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/buf-commit-id-from-dashless +/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/buf-commit-id-to-dashless /private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/buf-digest /private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/buf-new-commit-id /private/bufpkg/bufstyle/cmd/bufstyle/bufstyle diff --git a/go.sum b/go.sum index d45ded4994..0628659af3 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,7 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= -buf.build/gen/go/bufbuild/registry/connectrpc/go v1.14.0-20240103033507-2860fe703a60.1 h1:tyOczeIHltbjCt0R1FqOUW6GYOFGtxfWmVROxZtGfNo= -buf.build/gen/go/bufbuild/registry/connectrpc/go v1.14.0-20240103033507-2860fe703a60.1/go.mod h1:In1Pi5BipMwL3oumRdchqsf/xKZ8BM8+g2/8+qUIFAM= buf.build/gen/go/bufbuild/registry/connectrpc/go v1.14.0-20240124193556-c1b9aad65c81.1 h1:pFs/DMJMhNd+tlwkXbzx2bzWXiJPLHDyZjFZyNYICoE= buf.build/gen/go/bufbuild/registry/connectrpc/go v1.14.0-20240124193556-c1b9aad65c81.1/go.mod h1:czrtSW9UGDwm5munsVYBBIpRaL29UBCOE6qi7em+4qE= -buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.32.0-20240103033507-2860fe703a60.1 h1:slGktetnGQEVfeAaDjpy/uv1XTJXrbW0sElbiMj4fEc= -buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.32.0-20240103033507-2860fe703a60.1/go.mod h1:L+pboYag9Pd0vt+ErAHa7QSdqP0Dzd7S+4OLKlrXNXQ= buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.32.0-20240124193556-c1b9aad65c81.1 h1:ZiA3hFK2dF93c8uOLOB78dQ4xWas8KM04NDKguPWIUE= buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.32.0-20240124193556-c1b9aad65c81.1/go.mod h1:L+pboYag9Pd0vt+ErAHa7QSdqP0Dzd7S+4OLKlrXNXQ= connectrpc.com/connect v1.14.0 h1:PDS+J7uoz5Oui2VEOMcfz6Qft7opQM9hPiKvtGC01pA= diff --git a/make/buf/all.mk b/make/buf/all.mk index 5d5f16c3f8..4167a12f2e 100644 --- a/make/buf/all.mk +++ b/make/buf/all.mk @@ -5,6 +5,8 @@ GO_BINS := $(GO_BINS) \ cmd/protoc-gen-buf-breaking \ cmd/protoc-gen-buf-lint \ private/buf/bufwkt/cmd/wkt-go-data \ + private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless \ + private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless \ private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest \ private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id \ private/bufpkg/bufstyle/cmd/bufstyle \ diff --git a/private/buf/bufctl/controller.go b/private/buf/bufctl/controller.go index 90f00718c2..0c994373d1 100644 --- a/private/buf/bufctl/controller.go +++ b/private/buf/bufctl/controller.go @@ -45,6 +45,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/tracing" + "github.com/gofrs/uuid/v5" "go.uber.org/multierr" "go.uber.org/zap" "google.golang.org/protobuf/proto" @@ -67,7 +68,7 @@ type ProtoFileInfo interface { storage.ObjectInfo ModuleFullName() bufmodule.ModuleFullName - CommitID() string + CommitID() uuid.UUID isProtoFileInfo() } @@ -508,7 +509,10 @@ func (c *controller) PutImage( if functionOptions.imageAsFileDescriptorSet { putMessage = bufimage.ImageToFileDescriptorSet(putImage) } else { - putMessage = bufimage.ImageToProtoImage(putImage) + putMessage, err = bufimage.ImageToProtoImage(putImage) + if err != nil { + return err + } } data, err := marshaler.Marshal(putMessage) if err != nil { diff --git a/private/buf/bufctl/module_proto_file_info.go b/private/buf/bufctl/module_proto_file_info.go index 0d04440b45..fffb17d08e 100644 --- a/private/buf/bufctl/module_proto_file_info.go +++ b/private/buf/bufctl/module_proto_file_info.go @@ -16,6 +16,7 @@ package bufctl import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/gofrs/uuid/v5" ) type moduleProtoFileInfo struct { @@ -32,7 +33,7 @@ func (p *moduleProtoFileInfo) ModuleFullName() bufmodule.ModuleFullName { return p.FileInfo.Module().ModuleFullName() } -func (p *moduleProtoFileInfo) CommitID() string { +func (p *moduleProtoFileInfo) CommitID() uuid.UUID { return p.FileInfo.Module().CommitID() } diff --git a/private/buf/bufgen/generator.go b/private/buf/bufgen/generator.go index 7bb88d615e..ca8f1e3cf6 100644 --- a/private/buf/bufgen/generator.go +++ b/private/buf/bufgen/generator.go @@ -362,11 +362,15 @@ func (g *generator) execRemotePluginsV2( requests[i] = request } codeGenerationService := connectclient.Make(g.clientConfig, remote, registryv1alpha1connect.NewCodeGenerationServiceClient) + protoImage, err := bufimage.ImageToProtoImage(image) + if err != nil { + return nil, err + } response, err := codeGenerationService.GenerateCode( ctx, connect.NewRequest( ®istryv1alpha1.GenerateCodeRequest{ - Image: bufimage.ImageToProtoImage(image), + Image: protoImage, Requests: requests, }, ), diff --git a/private/buf/bufmigrate/migrator.go b/private/buf/bufmigrate/migrator.go index f304134c1e..51684d1a65 100644 --- a/private/buf/bufmigrate/migrator.go +++ b/private/buf/bufmigrate/migrator.go @@ -38,6 +38,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/stringutil" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/multierr" ) @@ -344,7 +345,7 @@ func (m *migrator) addModuleDirectory( m.rootBucket, moduleDir, bufconfig.BufLockFileWithDigestResolver( - func(ctx context.Context, remote, commitID string) (bufmodule.Digest, error) { + func(ctx context.Context, remote string, commitID uuid.UUID) (bufmodule.Digest, error) { return bufmoduleapi.DigestForCommitID(ctx, m.clientProvider, remote, commitID, bufmodule.DigestTypeB4) }, ), @@ -521,7 +522,7 @@ func (m *migrator) buildBufYAMLAndBufLock( for depModule, lockEntries := range depModuleToLockEntries { commitIDToKey, err := slicesext.ToUniqueValuesMapError( lockEntries, - func(moduleKey bufmodule.ModuleKey) (string, error) { + func(moduleKey bufmodule.ModuleKey) (uuid.UUID, error) { return moduleKey.CommitID(), nil }, ) @@ -660,7 +661,7 @@ func (m *migrator) warnf(format string, args ...any) { func resolvedDeclaredAndLockedDependencies( moduleToRefToCommit map[string]map[string]*modulev1beta1.Commit, - commitIDToCommit map[string]*modulev1beta1.Commit, + commitIDToCommit map[uuid.UUID]*modulev1beta1.Commit, moduleFullNameToDeclaredRefs map[string][]bufmodule.ModuleRef, moduleFullNameToLockKeys map[string][]bufmodule.ModuleKey, ) ([]bufmodule.ModuleRef, []bufmodule.ModuleKey, error) { @@ -682,9 +683,13 @@ func resolvedDeclaredAndLockedDependencies( // If we have already picked a pinned dependency ref for this dependency, // we use that as the lock entry as well. resolvedCommit := moduleToRefToCommit[moduleFullName][resolvedRef.Ref()] + commitID, err := uuid.FromString(resolvedCommit.GetId()) + if err != nil { + return nil, nil, err + } key, err := bufmodule.NewModuleKey( resolvedRef.ModuleFullName(), - resolvedCommit.GetId(), + commitID, func() (bufmodule.Digest, error) { return bufmoduleapi.ProtoToDigest(resolvedCommit.GetDigest()) }, @@ -766,8 +771,8 @@ func getCommitIDToCommit( ctx context.Context, clientProvider bufapi.ClientProvider, moduleKeys []bufmodule.ModuleKey, -) (map[string]*modulev1beta1.Commit, error) { - commitIDToCommit := make(map[string]*modulev1beta1.Commit) +) (map[uuid.UUID]*modulev1beta1.Commit, error) { + commitIDToCommit := make(map[uuid.UUID]*modulev1beta1.Commit) for _, moduleKey := range moduleKeys { moduleFullName := moduleKey.ModuleFullName() response, err := clientProvider.CommitServiceClient(moduleFullName.Registry()).GetCommits( @@ -777,8 +782,7 @@ func getCommitIDToCommit( ResourceRefs: []*modulev1beta1.ResourceRef{ { Value: &modulev1beta1.ResourceRef_Id{ - // TODO: is this in the correct dashless/dashful form? Answer: no - Id: moduleKey.CommitID(), + Id: moduleKey.CommitID().String(), }, }, }, @@ -787,7 +791,7 @@ func getCommitIDToCommit( ) if err != nil { if connect.CodeOf(err) == connect.CodeNotFound { - return nil, &fs.PathError{Op: "read", Path: moduleKey.CommitID(), Err: fs.ErrNotExist} + return nil, &fs.PathError{Op: "read", Path: moduleKey.CommitID().String(), Err: fs.ErrNotExist} } return nil, err } diff --git a/private/buf/bufworkspace/testdata/basic/scripts/fakebuflock.bash b/private/buf/bufworkspace/testdata/basic/scripts/fakebuflock.bash index 15066a9a4a..7e34912966 100755 --- a/private/buf/bufworkspace/testdata/basic/scripts/fakebuflock.bash +++ b/private/buf/bufworkspace/testdata/basic/scripts/fakebuflock.bash @@ -7,8 +7,8 @@ cd "${DIR}" DATE_DIGEST="$(buf-digest bsr/buf.testing/acme/date bsr/buf.testing/acme/extension | grep date | cut -f 2 -d ' ')" EXTENSION_DIGEST="$(buf-digest bsr/buf.testing/acme/date bsr/buf.testing/acme/extension | grep extension | cut -f 2 -d ' ')" -DATE_COMMIT_ID="ffded0b4cf6b47cab74da08d291a3c2f" -EXTENSION_COMMIT_ID="b8488077ea6d4f6d9562a337b98259c8" +DATE_COMMIT_ID="ffded0b4-cf6b-47ca-b74d-a08d291a3c2f" +EXTENSION_COMMIT_ID="b8488077-ea6d-4f6d-9562-a337b98259c8" rm -f workspacev1/finance/bond/proto/buf.lock cat < workspacev1/finance/bond/proto/buf.lock diff --git a/private/buf/bufworkspace/testdata/basic/workspace_undeclared_dep/buf.lock b/private/buf/bufworkspace/testdata/basic/workspace_undeclared_dep/buf.lock index e25f7a509f..e645681c69 100644 --- a/private/buf/bufworkspace/testdata/basic/workspace_undeclared_dep/buf.lock +++ b/private/buf/bufworkspace/testdata/basic/workspace_undeclared_dep/buf.lock @@ -1,8 +1,8 @@ version: v2 deps: - name: buf.testing/acme/date - commit: ffded0b4cf6b47cab74da08d291a3c2f + commit: ffded0b4-cf6b-47ca-b74d-a08d291a3c2f digest: b5:24ed4f13925cf89ea0ae0127fa28540704c7ae14750af027270221b737a1ce658f8014ca2555f6f7fcd95ea84e071d33f37f86cc36d07fe0d0963329a5ec2462 - name: buf.testing/acme/extension - commit: b8488077ea6d4f6d9562a337b98259c8 + commit: b8488077-ea6d-4f6d-9562-a337b98259c8 digest: b5:d2c1da8f8331c5c75b50549c79fc360394dedfb6a11f5381c4523592018964119f561088fc8aaddfc9f5773ba02692e6fd9661853450f76a3355dec62c1f57b4 diff --git a/private/buf/bufworkspace/testdata/basic/workspace_unused_dep/buf.lock b/private/buf/bufworkspace/testdata/basic/workspace_unused_dep/buf.lock index e25f7a509f..e645681c69 100644 --- a/private/buf/bufworkspace/testdata/basic/workspace_unused_dep/buf.lock +++ b/private/buf/bufworkspace/testdata/basic/workspace_unused_dep/buf.lock @@ -1,8 +1,8 @@ version: v2 deps: - name: buf.testing/acme/date - commit: ffded0b4cf6b47cab74da08d291a3c2f + commit: ffded0b4-cf6b-47ca-b74d-a08d291a3c2f digest: b5:24ed4f13925cf89ea0ae0127fa28540704c7ae14750af027270221b737a1ce658f8014ca2555f6f7fcd95ea84e071d33f37f86cc36d07fe0d0963329a5ec2462 - name: buf.testing/acme/extension - commit: b8488077ea6d4f6d9562a337b98259c8 + commit: b8488077-ea6d-4f6d-9562-a337b98259c8 digest: b5:d2c1da8f8331c5c75b50549c79fc360394dedfb6a11f5381c4523592018964119f561088fc8aaddfc9f5773ba02692e6fd9661853450f76a3355dec62c1f57b4 diff --git a/private/buf/bufworkspace/testdata/basic/workspacev1/finance/bond/proto/buf.lock b/private/buf/bufworkspace/testdata/basic/workspacev1/finance/bond/proto/buf.lock index e25f7a509f..e645681c69 100644 --- a/private/buf/bufworkspace/testdata/basic/workspacev1/finance/bond/proto/buf.lock +++ b/private/buf/bufworkspace/testdata/basic/workspacev1/finance/bond/proto/buf.lock @@ -1,8 +1,8 @@ version: v2 deps: - name: buf.testing/acme/date - commit: ffded0b4cf6b47cab74da08d291a3c2f + commit: ffded0b4-cf6b-47ca-b74d-a08d291a3c2f digest: b5:24ed4f13925cf89ea0ae0127fa28540704c7ae14750af027270221b737a1ce658f8014ca2555f6f7fcd95ea84e071d33f37f86cc36d07fe0d0963329a5ec2462 - name: buf.testing/acme/extension - commit: b8488077ea6d4f6d9562a337b98259c8 + commit: b8488077-ea6d-4f6d-9562-a337b98259c8 digest: b5:d2c1da8f8331c5c75b50549c79fc360394dedfb6a11f5381c4523592018964119f561088fc8aaddfc9f5773ba02692e6fd9661853450f76a3355dec62c1f57b4 diff --git a/private/buf/bufworkspace/testdata/basic/workspacev1/finance/portfolio/proto/buf.lock b/private/buf/bufworkspace/testdata/basic/workspacev1/finance/portfolio/proto/buf.lock index e25f7a509f..e645681c69 100644 --- a/private/buf/bufworkspace/testdata/basic/workspacev1/finance/portfolio/proto/buf.lock +++ b/private/buf/bufworkspace/testdata/basic/workspacev1/finance/portfolio/proto/buf.lock @@ -1,8 +1,8 @@ version: v2 deps: - name: buf.testing/acme/date - commit: ffded0b4cf6b47cab74da08d291a3c2f + commit: ffded0b4-cf6b-47ca-b74d-a08d291a3c2f digest: b5:24ed4f13925cf89ea0ae0127fa28540704c7ae14750af027270221b737a1ce658f8014ca2555f6f7fcd95ea84e071d33f37f86cc36d07fe0d0963329a5ec2462 - name: buf.testing/acme/extension - commit: b8488077ea6d4f6d9562a337b98259c8 + commit: b8488077-ea6d-4f6d-9562-a337b98259c8 digest: b5:d2c1da8f8331c5c75b50549c79fc360394dedfb6a11f5381c4523592018964119f561088fc8aaddfc9f5773ba02692e6fd9661853450f76a3355dec62c1f57b4 diff --git a/private/buf/bufworkspace/testdata/basic/workspacev2/buf.lock b/private/buf/bufworkspace/testdata/basic/workspacev2/buf.lock index e25f7a509f..e645681c69 100644 --- a/private/buf/bufworkspace/testdata/basic/workspacev2/buf.lock +++ b/private/buf/bufworkspace/testdata/basic/workspacev2/buf.lock @@ -1,8 +1,8 @@ version: v2 deps: - name: buf.testing/acme/date - commit: ffded0b4cf6b47cab74da08d291a3c2f + commit: ffded0b4-cf6b-47ca-b74d-a08d291a3c2f digest: b5:24ed4f13925cf89ea0ae0127fa28540704c7ae14750af027270221b737a1ce658f8014ca2555f6f7fcd95ea84e071d33f37f86cc36d07fe0d0963329a5ec2462 - name: buf.testing/acme/extension - commit: b8488077ea6d4f6d9562a337b98259c8 + commit: b8488077-ea6d-4f6d-9562-a337b98259c8 digest: b5:d2c1da8f8331c5c75b50549c79fc360394dedfb6a11f5381c4523592018964119f561088fc8aaddfc9f5773ba02692e6fd9661853450f76a3355dec62c1f57b4 diff --git a/private/buf/bufworkspace/workspace.go b/private/buf/bufworkspace/workspace.go index d06959ab3b..89b32e599d 100644 --- a/private/buf/bufworkspace/workspace.go +++ b/private/buf/bufworkspace/workspace.go @@ -30,6 +30,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/tracing" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -584,7 +585,7 @@ func newWorkspaceForBucketAndModuleDirPathsV1Beta1OrV1( // buf.lock files live at the module root moduleDirPath, bufconfig.BufLockFileWithDigestResolver( - func(ctx context.Context, remote string, commitID string) (bufmodule.Digest, error) { + func(ctx context.Context, remote string, commitID uuid.UUID) (bufmodule.Digest, error) { return bufmoduleapi.DigestForCommitID(ctx, clientProvider, remote, commitID, bufmodule.DigestTypeB4) }, ), diff --git a/private/buf/cmd/buf/command/graph/graph.go b/private/buf/cmd/buf/command/graph/graph.go index dac202aa32..3359261d1f 100644 --- a/private/buf/cmd/buf/command/graph/graph.go +++ b/private/buf/cmd/buf/command/graph/graph.go @@ -137,8 +137,8 @@ func run( func moduleToString(module bufmodule.Module) string { if moduleFullName := module.ModuleFullName(); moduleFullName != nil { - if commitID := module.CommitID(); commitID != "" { - return moduleFullName.String() + ":" + commitID + if commitID := module.CommitID(); !commitID.IsNil() { + return moduleFullName.String() + ":" + commitID.String() } return moduleFullName.String() } diff --git a/private/buf/cmd/buf/command/push/push.go b/private/buf/cmd/buf/command/push/push.go index 5ba32350ab..829e7653d6 100644 --- a/private/buf/cmd/buf/command/push/push.go +++ b/private/buf/cmd/buf/command/push/push.go @@ -32,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/pkg/app/appext" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/stringutil" + "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/spf13/pflag" ) @@ -190,13 +191,20 @@ func run( if err != nil { return err } + commitIDs, err := slicesext.MapError( + commits, + // TODO: Printing dashless for historical reasons, can we only print dashless in certain situations? + func(commit bufmodule.Commit) (string, error) { + return uuidutil.ToDashless(commit.ModuleKey().CommitID()) + }, + ) + if err != nil { + return err + } if _, err := container.Stdout().Write( []byte( strings.Join( - slicesext.Map( - commits, - func(commit bufmodule.Commit) string { return commit.ModuleKey().CommitID() }, - ), + commitIDs, "\n", ) + "\n", ), diff --git a/private/buf/cmd/buf/imports_test.go b/private/buf/cmd/buf/imports_test.go index 9788428a89..1b1664e00c 100644 --- a/private/buf/cmd/buf/imports_test.go +++ b/private/buf/cmd/buf/imports_test.go @@ -49,7 +49,7 @@ func TestValidImportFromCorruptedCacheFile(t *testing.T) { t, func(use string) *appcmd.Command { return NewRootCommand(use) }, 1, - `Failure: ***Digest verification failed for module bufbuild.test/bufbot/people:fc7d540124fd42db92511c19a60a1d98*** + `Failure: ***Digest verification failed for module bufbuild.test/bufbot/people:fc7d5401-24fd-42db-9251-1c19a60a1d98*** Expected digest: "b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465" Downloaded data digest: "b5:87403abcc5ec8403180536840a46bef8751df78caa8ad4b46939f4673d8bd58663d0f593668651bb2cd23049fedac4989e8b28c7e0e36b9b524f58ab09bf1053"`, func(use string) map[string]string { @@ -70,7 +70,7 @@ func TestValidImportFromCorruptedCacheDep(t *testing.T) { t, func(use string) *appcmd.Command { return NewRootCommand(use) }, 1, - `Failure: ***Digest verification failed for module bufbuild.test/bufbot/students:6c776ed5bee54462b06d31fb7f7c16b8*** + `Failure: ***Digest verification failed for module bufbuild.test/bufbot/students:6c776ed5-bee5-4462-b06d-31fb7f7c16b8*** Expected digest: "b5:01764dd31d0e1b8355eb3b262bba4539657af44872df6e4dfec76f57fbd9f1ae645c7c9c607db5c8352fb7041ca97111e3b0f142dafc1028832acbbc14ba1d70" Downloaded data digest: "b5:975dad3641303843fb6a06eedf038b0e6ff41da82b8a483920afb36011e0b0a24f720a2407f5e0783389530486ff410b7e132f219add69a5c7324d54f6f89a6c"`, func(use string) map[string]string { diff --git a/private/buf/cmd/buf/testdata/imports/cache/README.md b/private/buf/cmd/buf/testdata/imports/cache/README.md index 98578504eb..540969d235 100644 --- a/private/buf/cmd/buf/testdata/imports/cache/README.md +++ b/private/buf/cmd/buf/testdata/imports/cache/README.md @@ -17,5 +17,5 @@ buf-digest \ To make new commit IDs: ``` -buf-new-commit-id +buf-new-commit-id --type v1 ``` diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/files/school/v1/school1.proto b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/files/school/v1/school1.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/files/school/v1/school1.proto rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/files/school/v1/school1.proto diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/files/school/v1/school2.proto b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/files/school/v1/school2.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/files/school/v1/school2.proto rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/files/school/v1/school2.proto diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/module.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/module.yaml similarity index 83% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/module.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/module.yaml index 174d4baff9..5901c553be 100644 --- a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/module.yaml +++ b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/module.yaml @@ -1,10 +1,10 @@ version: v1 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 - name: bufbuild.test/bufbot/students - commit: 6c776ed5bee54462b06d31fb7f7c16b8 + commit: 6c776ed5-bee5-4462-b06d-31fb7f7c16b8 digest: b5:01764dd31d0e1b8355eb3b262bba4539657af44872df6e4dfec76f57fbd9f1ae645c7c9c607db5c8352fb7041ca97111e3b0f142dafc1028832acbbc14ba1d70 files_dir: files v1_buf_yaml_file: v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95720e46da93b5b4011a42ae7b/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/school/f4329b95-720e-46da-93b5-b4011a42ae7b/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/files/students/v1/students.proto b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/files/students/v1/students.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/files/students/v1/students.proto rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/files/students/v1/students.proto diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml similarity index 85% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml index be5a021680..76f6f2dfa9 100644 --- a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml +++ b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml @@ -1,7 +1,7 @@ version: v1 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 files_dir: files v1_buf_yaml_file: v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/cache/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/files/students/v1/students.proto b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/files/students/v1/students.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/files/students/v1/students.proto rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/files/students/v1/students.proto diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml similarity index 87% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml index 1a9cf82b51..b36f95b4a0 100644 --- a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/module.yaml +++ b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/module.yaml @@ -1,7 +1,7 @@ version: v1 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 # Last character changed from 5 to 4 to corrupt digest. digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631464 files_dir: files diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5bee54462b06d31fb7f7c16b8/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_dep/v3/modules/bufbuild.test/bufbot/students/6c776ed5-bee5-4462-b06d-31fb7f7c16b8/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto b/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people1.proto rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people1.proto diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto b/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/files/people/v1/people2.proto rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/files/people/v1/people2.proto diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/module.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/module.yaml diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock b/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_lock/buf.lock rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_lock/buf.lock diff --git a/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml b/private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml similarity index 100% rename from private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d540124fd42db92511c19a60a1d98/v1_buf_yaml/buf.yaml rename to private/buf/cmd/buf/testdata/imports/corrupted_cache_file/v3/modules/bufbuild.test/bufbot/people/fc7d5401-24fd-42db-9251-1c19a60a1d98/v1_buf_yaml/buf.yaml diff --git a/private/buf/cmd/buf/testdata/imports/failure/school/buf.lock b/private/buf/cmd/buf/testdata/imports/failure/school/buf.lock index 8c818af1ec..ee27815394 100644 --- a/private/buf/cmd/buf/testdata/imports/failure/school/buf.lock +++ b/private/buf/cmd/buf/testdata/imports/failure/school/buf.lock @@ -2,8 +2,8 @@ version: v2 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 - name: bufbuild.test/bufbot/students - commit: 6c776ed5bee54462b06d31fb7f7c16b8 + commit: 6c776ed5-bee5-4462-b06d-31fb7f7c16b8 digest: b5:01764dd31d0e1b8355eb3b262bba4539657af44872df6e4dfec76f57fbd9f1ae645c7c9c607db5c8352fb7041ca97111e3b0f142dafc1028832acbbc14ba1d70 diff --git a/private/buf/cmd/buf/testdata/imports/failure/students/buf.lock b/private/buf/cmd/buf/testdata/imports/failure/students/buf.lock index b3ed25b4de..cde064da06 100644 --- a/private/buf/cmd/buf/testdata/imports/failure/students/buf.lock +++ b/private/buf/cmd/buf/testdata/imports/failure/students/buf.lock @@ -2,5 +2,5 @@ version: v2 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 diff --git a/private/buf/cmd/buf/testdata/imports/success/school/buf.lock b/private/buf/cmd/buf/testdata/imports/success/school/buf.lock index 8c818af1ec..ee27815394 100644 --- a/private/buf/cmd/buf/testdata/imports/success/school/buf.lock +++ b/private/buf/cmd/buf/testdata/imports/success/school/buf.lock @@ -2,8 +2,8 @@ version: v2 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 - name: bufbuild.test/bufbot/students - commit: 6c776ed5bee54462b06d31fb7f7c16b8 + commit: 6c776ed5-bee5-4462-b06d-31fb7f7c16b8 digest: b5:01764dd31d0e1b8355eb3b262bba4539657af44872df6e4dfec76f57fbd9f1ae645c7c9c607db5c8352fb7041ca97111e3b0f142dafc1028832acbbc14ba1d70 diff --git a/private/buf/cmd/buf/testdata/imports/success/students/buf.lock b/private/buf/cmd/buf/testdata/imports/success/students/buf.lock index b3ed25b4de..cde064da06 100644 --- a/private/buf/cmd/buf/testdata/imports/success/students/buf.lock +++ b/private/buf/cmd/buf/testdata/imports/success/students/buf.lock @@ -2,5 +2,5 @@ version: v2 deps: - name: bufbuild.test/bufbot/people - commit: fc7d540124fd42db92511c19a60a1d98 + commit: fc7d5401-24fd-42db-9251-1c19a60a1d98 digest: b5:b22338d6faf2a727613841d760c9cbfd21af6950621a589df329e1fe6611125904c39e22a73e0aa8834006a514dbd084e6c33b6bef29c8e4835b4b9dec631465 diff --git a/private/buf/cmd/buf/testdata/workspace/success/lock/a/buf.lock b/private/buf/cmd/buf/testdata/workspace/success/lock/a/buf.lock index d600a12a62..e2003b06cd 100644 --- a/private/buf/cmd/buf/testdata/workspace/success/lock/a/buf.lock +++ b/private/buf/cmd/buf/testdata/workspace/success/lock/a/buf.lock @@ -2,5 +2,5 @@ version: v2 deps: - name: bufbuild.test/workspace/second - commit: 69f147a9d686496dbbfcdd30ffda9d20 + commit: 69f147a9-d686-496d-bbfc-dd30ffda9d20 digest: b5:a2db383c1a54738e12966b87af5a65d054cfe0da14da3aba40447e65f884d6667cfcc1078fd321d1b36e9436f58846d97de5a8e2481c1b4fae5cea179de29ac7 diff --git a/private/buf/cmd/protoc-gen-buf-lint/lint_test.go b/private/buf/cmd/protoc-gen-buf-lint/lint_test.go index 40277602ea..ea784750f2 100644 --- a/private/buf/cmd/protoc-gen-buf-lint/lint_test.go +++ b/private/buf/cmd/protoc-gen-buf-lint/lint_test.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/pkg/protoplugin" "github.com/bufbuild/buf/private/pkg/prototesting" "github.com/bufbuild/buf/private/pkg/stringutil" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/pluginpb" ) @@ -331,7 +332,7 @@ func testBuildCodeGeneratorRequest( imageFile, err := bufimage.NewImageFile( fileDescriptorProto, nil, - "", + uuid.Nil, "", !isNotImport, false, diff --git a/private/bufpkg/bufconfig/buf_lock_file.go b/private/bufpkg/bufconfig/buf_lock_file.go index 3c8b476cc5..4658d1e045 100644 --- a/private/bufpkg/bufconfig/buf_lock_file.go +++ b/private/bufpkg/bufconfig/buf_lock_file.go @@ -28,6 +28,8 @@ import ( "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/gofrs/uuid/v5" ) // DefaultBufLockFileName is default buf.lock file name. @@ -156,7 +158,7 @@ type BufLockFileOption func(*bufLockFileOptions) // TODO: use this for all reads of buf.locks, including migrate, prune, update, etc. This really almost should not // be an option. func BufLockFileWithDigestResolver( - digestResolver func(ctx context.Context, remote string, commitID string) (bufmodule.Digest, error), + digestResolver func(ctx context.Context, remote string, commitID uuid.UUID) (bufmodule.Digest, error), ) BufLockFileOption { return func(bufLockFileOptions *bufLockFileOptions) { bufLockFileOptions.digestResolver = digestResolver @@ -270,6 +272,11 @@ func readBufLockFile( if dep.Commit == "" { return nil, fmt.Errorf("no commit specified for module %s", moduleFullName.String()) } + // v1beta1 and v1 buf.locks used dashless commit IDs + commitID, err := uuidutil.FromDashless(dep.Commit) + if err != nil { + return nil, err + } getDigest := func() (bufmodule.Digest, error) { return bufmodule.ParseDigest(dep.Digest) } @@ -278,7 +285,7 @@ func readBufLockFile( return nil, fmt.Errorf("no digest specified for module %s", moduleFullName.String()) } getDigest = func() (bufmodule.Digest, error) { - return bufLockFileOptions.digestResolver(ctx, dep.Remote, dep.Commit) + return bufLockFileOptions.digestResolver(ctx, dep.Remote, commitID) } } for digestType, prefix := range deprecatedDigestTypeToPrefix { @@ -289,7 +296,7 @@ func readBufLockFile( } depModuleKey, err := bufmodule.NewModuleKey( moduleFullName, - dep.Commit, + commitID, getDigest, ) if err != nil { @@ -325,9 +332,13 @@ func readBufLockFile( return nil, fmt.Errorf(`%s digests are no longer supported, run "buf mod update" to update your buf.lock`, digestType) } } + commitID, err := uuid.FromString(dep.Commit) + if err != nil { + return nil, err + } depModuleKey, err := bufmodule.NewModuleKey( moduleFullName, - dep.Commit, + commitID, func() (bufmodule.Digest, error) { return bufmodule.ParseDigest(dep.Digest) }, @@ -363,11 +374,15 @@ func writeBufLockFile( if err != nil { return err } + externalCommitID, err := uuidutil.ToDashless(depModuleKey.CommitID()) + if err != nil { + return err + } externalBufLockFile.Deps[i] = externalBufLockFileDepV1Beta1V1{ Remote: depModuleKey.ModuleFullName().Registry(), Owner: depModuleKey.ModuleFullName().Owner(), Repository: depModuleKey.ModuleFullName().Name(), - Commit: depModuleKey.CommitID(), + Commit: externalCommitID, Digest: digest.String(), } } @@ -391,7 +406,7 @@ func writeBufLockFile( } externalBufLockFile.Deps[i] = externalBufLockFileDepV2{ Name: depModuleKey.ModuleFullName().String(), - Commit: depModuleKey.CommitID(), + Commit: depModuleKey.CommitID().String(), Digest: digest.String(), } } @@ -424,7 +439,7 @@ func validateV1AndV1Beta1DepsHaveCommits(bufLockFile BufLockFile) error { switch fileVersion := bufLockFile.FileVersion(); fileVersion { case FileVersionV1Beta1, FileVersionV1: for _, depModuleKey := range bufLockFile.DepModuleKeys() { - if depModuleKey.CommitID() == "" { + if depModuleKey.CommitID().IsNil() { // This is a system error. return syserror.Newf( "%s lock files require commits, however we did not have a commit for module %q", @@ -502,7 +517,7 @@ type bufLockFileOptions struct { digestResolver func( ctx context.Context, remote string, - commitID string, + commitID uuid.UUID, ) (bufmodule.Digest, error) } diff --git a/private/bufpkg/bufimage/bufimage.go b/private/bufpkg/bufimage/bufimage.go index 09c1a2f96c..f86437248e 100644 --- a/private/bufpkg/bufimage/bufimage.go +++ b/private/bufpkg/bufimage/bufimage.go @@ -26,6 +26,8 @@ import ( "github.com/bufbuild/buf/private/pkg/protoencoding" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/tracing" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/gofrs/uuid/v5" "google.golang.org/protobuf/types/descriptorpb" "google.golang.org/protobuf/types/pluginpb" ) @@ -44,9 +46,9 @@ type ImageFile interface { // if the ImageFile came from a Module (as opposed to a serialized Protobuf message), and // if the CommitID was known.. // - // May be empty. Callers should not rely on this value being present. If - // ModuleFullName is nil, this will always be empty. - CommitID() string + // May be empty, that is CommitID().IsNil() may be true. Callers should not rely on this + // value being present. If ModuleFullName is nil, this will always be empty. + CommitID() uuid.UUID // FileDescriptorProto is the backing *descriptorpb.FileDescriptorProto for this File. // @@ -75,7 +77,7 @@ type ImageFile interface { func NewImageFile( fileDescriptor protodescriptor.FileDescriptor, moduleFullName bufmodule.ModuleFullName, - commitID string, + commitID uuid.UUID, externalPath string, isImport bool, isSyntaxUnspecified bool, @@ -263,7 +265,7 @@ func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOpti var isSyntaxUnspecified bool var unusedDependencyIndexes []int32 var moduleFullName bufmodule.ModuleFullName - var commitID string + var commitID uuid.UUID var err error if protoImageFileExtension := protoImageFile.GetBufExtension(); protoImageFileExtension != nil { isImport = protoImageFileExtension.GetIsImport() @@ -280,7 +282,13 @@ func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOpti return nil, err } // we only want to set this if there is a module name - commitID = protoModuleInfo.GetCommit() + if protoCommitID := protoModuleInfo.GetCommit(); protoCommitID != "" { + // Need to use dashless for historical reasons. + commitID, err = uuidutil.FromDashless(protoCommitID) + if err != nil { + return nil, err + } + } } } } @@ -438,15 +446,19 @@ func ImageByDir(image Image) ([]Image, error) { } // ImageToProtoImage returns a new ProtoImage for the Image. -func ImageToProtoImage(image Image) *imagev1.Image { +func ImageToProtoImage(image Image) (*imagev1.Image, error) { imageFiles := image.Files() protoImage := &imagev1.Image{ File: make([]*imagev1.ImageFile, len(imageFiles)), } for i, imageFile := range imageFiles { - protoImage.File[i] = imageFileToProtoImageFile(imageFile) + protoImageFile, err := imageFileToProtoImageFile(imageFile) + if err != nil { + return nil, err + } + protoImage.File[i] = protoImageFile } - return protoImage + return protoImage, nil } // ImageToFileDescriptorSet returns a new FileDescriptorSet for the Image. diff --git a/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go b/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go index 972d19235a..2c08a21e30 100644 --- a/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go +++ b/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" "github.com/bufbuild/buf/private/pkg/tracing" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -787,7 +788,7 @@ func testGetImageFile( Syntax: proto.String("proto3"), }, parsedModuleFullName, - "", + uuid.Nil, path, false, false, diff --git a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go index 2723f067dc..af8a1424e3 100644 --- a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go +++ b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go @@ -21,6 +21,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/protodescriptor" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -33,7 +34,7 @@ func NewImageFile( t testing.TB, fileDescriptor protodescriptor.FileDescriptor, moduleFullName bufmodule.ModuleFullName, - commit string, + commit uuid.UUID, externalPath string, isImport bool, isSyntaxUnspecified bool, diff --git a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting_test.go b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting_test.go index b4e02999d0..79d5aed9d0 100644 --- a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting_test.go +++ b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting_test.go @@ -20,6 +20,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufimage" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -40,7 +41,7 @@ func BenchmarkNewImageWithOnlyPathsAllowNotExistFileOnly(b *testing.B) { fmt.Sprintf("a%d.proto/a%d.proto", i, i), ), nil, - "", + uuid.Nil, fmt.Sprintf("foo/two/a%d.proto/a%d.proto", i, i), false, false, @@ -72,7 +73,7 @@ func BenchmarkNewImageWithOnlyPathsAllowNotExistDirOnly(b *testing.B) { fmt.Sprintf("a%d.proto/a%d.proto", i, i), ), nil, - "", + uuid.Nil, fmt.Sprintf("foo/two/a%d.proto/a%d.proto", i, i), false, false, @@ -134,7 +135,7 @@ func TestBasic(t *testing.T) { t, protoImageFileImport, nil, - "", + uuid.Nil, "some/import/import.proto", true, false, @@ -144,7 +145,7 @@ func TestBasic(t *testing.T) { t, protoImageFileWellKnownTypeImport, nil, - "", + uuid.Nil, "google/protobuf/timestamp.proto", true, false, @@ -154,7 +155,7 @@ func TestBasic(t *testing.T) { t, protoImageFileAA, nil, - "", + uuid.Nil, "foo/one/a/a.proto", false, false, @@ -164,7 +165,7 @@ func TestBasic(t *testing.T) { t, protoImageFileAB, nil, - "", + uuid.Nil, "foo/one/a/b.proto", false, false, @@ -174,7 +175,7 @@ func TestBasic(t *testing.T) { t, protoImageFileBA, nil, - "", + uuid.Nil, "foo/two/b/a.proto", false, false, @@ -184,7 +185,7 @@ func TestBasic(t *testing.T) { t, protoImageFileBB, nil, - "", + uuid.Nil, "foo/two/b/b.proto", false, false, @@ -194,7 +195,7 @@ func TestBasic(t *testing.T) { t, protoImageFileOutlandishDirectoryName, nil, - "", + uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, @@ -216,13 +217,13 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "foo/two/b/b.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "foo/three/d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "foo/two/b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, nil), }, image.Files(), ) @@ -231,11 +232,11 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "foo/two/b/b.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "foo/three/d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "foo/two/b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, nil), }, bufimage.ImageWithoutImports(image).Files(), ) @@ -252,11 +253,11 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", true, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", true, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), }, newImage.Files(), ) @@ -285,11 +286,11 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", true, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", true, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), }, newImage.Files(), ) @@ -304,10 +305,10 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), }, newImage.Files(), ) @@ -322,12 +323,12 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", true, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", true, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "foo/two/b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", true, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", true, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "foo/two/b/b.proto", false, false, nil), }, newImage.Files(), ) @@ -343,11 +344,11 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), }, newImage.Files(), ) @@ -374,11 +375,11 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), }, newImage.Files(), ) @@ -395,12 +396,12 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "foo/three/d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, nil), }, newImage.Files(), ) @@ -417,12 +418,12 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "foo/three/d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, nil), }, newImage.Files(), ) @@ -443,17 +444,19 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "b/b.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "d/d.proto/d.proto", false, false, nil), }, newImage.Files(), ) - diff := cmp.Diff(protoImage, bufimage.ImageToProtoImage(newImage), protocmp.Transform()) + newProtoImage, err := bufimage.ImageToProtoImage(newImage) + require.NoError(t, err) + diff := cmp.Diff(protoImage, newProtoImage, protocmp.Transform()) require.Equal(t, "", diff) fileDescriptorSet := &descriptorpb.FileDescriptorSet{ File: []*descriptorpb.FileDescriptorProto{ @@ -534,13 +537,13 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "a/b.proto", false, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "b/b.proto", false, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "d/d.proto/d.proto", false, false, nil), }, newImage.Files(), ) @@ -578,30 +581,30 @@ func TestBasic(t *testing.T) { AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", false, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", false, false, nil), }, imagesByDir[0].Files(), ) AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileAA, nil, "", "foo/one/a/a.proto", true, false, nil), - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileWellKnownTypeImport, nil, "", "google/protobuf/timestamp.proto", true, false, nil), - NewImageFile(t, protoImageFileAB, nil, "", "foo/one/a/b.proto", true, false, nil), - NewImageFile(t, protoImageFileBA, nil, "", "foo/two/b/a.proto", false, false, nil), - NewImageFile(t, protoImageFileBB, nil, "", "foo/two/b/b.proto", false, false, nil), + NewImageFile(t, protoImageFileAA, nil, uuid.Nil, "foo/one/a/a.proto", true, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileWellKnownTypeImport, nil, uuid.Nil, "google/protobuf/timestamp.proto", true, false, nil), + NewImageFile(t, protoImageFileAB, nil, uuid.Nil, "foo/one/a/b.proto", true, false, nil), + NewImageFile(t, protoImageFileBA, nil, uuid.Nil, "foo/two/b/a.proto", false, false, nil), + NewImageFile(t, protoImageFileBB, nil, uuid.Nil, "foo/two/b/b.proto", false, false, nil), }, imagesByDir[1].Files(), ) AssertImageFilesEqual( t, []bufimage.ImageFile{ - NewImageFile(t, protoImageFileImport, nil, "", "some/import/import.proto", true, false, nil), - NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, "", "foo/three/d/d.proto/d.proto", false, false, nil), + NewImageFile(t, protoImageFileImport, nil, uuid.Nil, "some/import/import.proto", true, false, nil), + NewImageFile(t, protoImageFileOutlandishDirectoryName, nil, uuid.Nil, "foo/three/d/d.proto/d.proto", false, false, nil), }, imagesByDir[2].Files(), ) diff --git a/private/bufpkg/bufimage/bufimageutil/bufimageutil_test.go b/private/bufpkg/bufimage/bufimageutil/bufimageutil_test.go index 7982f43b9c..e06dc78128 100644 --- a/private/bufpkg/bufimage/bufimageutil/bufimageutil_test.go +++ b/private/bufpkg/bufimage/bufimageutil/bufimageutil_test.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/tracing" + "github.com/gofrs/uuid/v5" "github.com/jhump/protoreflect/desc" "github.com/jhump/protoreflect/desc/protoprint" "github.com/stretchr/testify/assert" @@ -468,7 +469,7 @@ func benchmarkFilterImage(b *testing.B, opts ...bufimage.BuildImageOption) { clone, ok := proto.Clone(imageFile.FileDescriptorProto()).(*descriptorpb.FileDescriptorProto) require.True(b, ok) var err error - imageFiles[j], err = bufimage.NewImageFile(clone, nil, "", "", false, false, nil) + imageFiles[j], err = bufimage.NewImageFile(clone, nil, uuid.Nil, "", false, false, nil) require.NoError(b, err) } image, err := bufimage.NewImage(imageFiles) diff --git a/private/bufpkg/bufimage/image.go b/private/bufpkg/bufimage/image.go index 60bd3e3402..769ee2f998 100644 --- a/private/bufpkg/bufimage/image.go +++ b/private/bufpkg/bufimage/image.go @@ -17,6 +17,8 @@ package bufimage import ( "errors" "fmt" + + "github.com/gofrs/uuid/v5" ) var _ Image = &image{} @@ -32,7 +34,7 @@ func newImage(files []ImageFile, reorder bool) (*image, error) { } pathToImageFile := make(map[string]ImageFile, len(files)) type commitIDAndFilePath struct { - commitID string + commitID uuid.UUID filePath string } moduleFullNameStringToCommitIDAndFilePath := make(map[string]commitIDAndFilePath) diff --git a/private/bufpkg/bufimage/image_file.go b/private/bufpkg/bufimage/image_file.go index 74ff85c45d..dfce110b18 100644 --- a/private/bufpkg/bufimage/image_file.go +++ b/private/bufpkg/bufimage/image_file.go @@ -17,6 +17,7 @@ package bufimage import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/protodescriptor" + "github.com/gofrs/uuid/v5" "google.golang.org/protobuf/types/descriptorpb" ) @@ -25,7 +26,7 @@ var _ ImageFile = &imageFile{} type imageFile struct { fileDescriptorProto *descriptorpb.FileDescriptorProto moduleFullName bufmodule.ModuleFullName - commitID string + commitID uuid.UUID externalPath string isImport bool isSyntaxUnspecified bool @@ -35,7 +36,7 @@ type imageFile struct { func newImageFile( fileDescriptor protodescriptor.FileDescriptor, moduleFullName bufmodule.ModuleFullName, - commitID string, + commitID uuid.UUID, externalPath string, isImport bool, isSyntaxUnspecified bool, @@ -58,7 +59,7 @@ func newImageFile( func newImageFileNoValidate( fileDescriptor protodescriptor.FileDescriptor, moduleFullName bufmodule.ModuleFullName, - commitID string, + commitID uuid.UUID, externalPath string, isImport bool, isSyntaxUnspecified bool, @@ -96,7 +97,7 @@ func (f *imageFile) ModuleFullName() bufmodule.ModuleFullName { return f.moduleFullName } -func (f *imageFile) CommitID() string { +func (f *imageFile) CommitID() uuid.UUID { return f.commitID } diff --git a/private/bufpkg/bufimage/parser_accessor_handler.go b/private/bufpkg/bufimage/parser_accessor_handler.go index 99fdf43ecf..6dc39a578f 100644 --- a/private/bufpkg/bufimage/parser_accessor_handler.go +++ b/private/bufpkg/bufimage/parser_accessor_handler.go @@ -24,6 +24,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/gen/data/datawkt" + "github.com/gofrs/uuid/v5" "go.uber.org/multierr" ) @@ -33,7 +34,7 @@ type parserAccessorHandler struct { pathToExternalPath map[string]string nonImportPaths map[string]struct{} pathToModuleFullName map[string]bufmodule.ModuleFullName - pathToCommitID map[string]string + pathToCommitID map[string]uuid.UUID lock sync.RWMutex } @@ -47,7 +48,7 @@ func newParserAccessorHandler( pathToExternalPath: make(map[string]string), nonImportPaths: make(map[string]struct{}), pathToModuleFullName: make(map[string]bufmodule.ModuleFullName), - pathToCommitID: make(map[string]string), + pathToCommitID: make(map[string]uuid.UUID), } } @@ -65,7 +66,7 @@ func (p *parserAccessorHandler) Open(path string) (_ io.ReadCloser, retErr error // this should never happen, but just in case return nil, fmt.Errorf("parser accessor requested path %q but got %q", path, wktModuleFile.Path()) } - if err := p.addPath(path, path, nil, ""); err != nil { + if err := p.addPath(path, path, nil, uuid.Nil); err != nil { return nil, err } return wktModuleFile, nil @@ -112,7 +113,7 @@ func (p *parserAccessorHandler) ModuleFullName(path string) bufmodule.ModuleFull } // CommitID returns empty if not available. -func (p *parserAccessorHandler) CommitID(path string) string { +func (p *parserAccessorHandler) CommitID(path string) uuid.UUID { p.lock.RLock() defer p.lock.RUnlock() return p.pathToCommitID[path] // empty is a valid value. @@ -122,7 +123,7 @@ func (p *parserAccessorHandler) addPath( path string, externalPath string, moduleFullName bufmodule.ModuleFullName, - commitID string, + commitID uuid.UUID, ) error { p.lock.Lock() defer p.lock.Unlock() @@ -137,7 +138,7 @@ func (p *parserAccessorHandler) addPath( if moduleFullName != nil { p.pathToModuleFullName[path] = moduleFullName } - if commitID != "" { + if !commitID.IsNil() { p.pathToCommitID[path] = commitID } return nil diff --git a/private/bufpkg/bufimage/util.go b/private/bufpkg/bufimage/util.go index 022b289e19..8c0a619c36 100644 --- a/private/bufpkg/bufimage/util.go +++ b/private/bufpkg/bufimage/util.go @@ -23,6 +23,7 @@ import ( imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" + "github.com/bufbuild/buf/private/pkg/uuidutil" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" @@ -298,15 +299,20 @@ func imageFilesToFileDescriptorProtos(imageFiles []ImageFile) []*descriptorpb.Fi return fileDescriptorProtos } -func imageFileToProtoImageFile(imageFile ImageFile) *imagev1.ImageFile { +func imageFileToProtoImageFile(imageFile ImageFile) (*imagev1.ImageFile, error) { + // Need to use dashless for historical reasons. + protoCommitID, err := uuidutil.ToDashless(imageFile.CommitID()) + if err != nil { + return nil, err + } return fileDescriptorProtoToProtoImageFile( imageFile.FileDescriptorProto(), imageFile.IsImport(), imageFile.IsSyntaxUnspecified(), imageFile.UnusedDependencyIndexes(), imageFile.ModuleFullName(), - imageFile.CommitID(), - ) + protoCommitID, + ), nil } func fileDescriptorProtoToProtoImageFile( diff --git a/private/bufpkg/bufimage/util_test.go b/private/bufpkg/bufimage/util_test.go index 154599ca1d..d0ea2d610c 100644 --- a/private/bufpkg/bufimage/util_test.go +++ b/private/bufpkg/bufimage/util_test.go @@ -20,6 +20,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" + "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/encoding/protowire" @@ -143,10 +144,12 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { moduleFullName, err := bufmodule.ParseModuleFullName("buf.build/foo/bar") require.NoError(t, err) + commitID, err := uuidutil.New() + require.NoError(t, err) imageFile, err := NewImageFile( fileDescriptor, moduleFullName, - "1234123451235", + commitID, "foo/bar/baz.proto", false, false, @@ -154,7 +157,8 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { ) require.NoError(t, err) - protoImageFile := imageFileToProtoImageFile(imageFile) + protoImageFile, err := imageFileToProtoImageFile(imageFile) + require.NoError(t, err) // make sure unrecognized bytes survived require.Equal(t, otherData, []byte(protoImageFile.ProtoReflect().GetUnknown())) @@ -173,10 +177,12 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { moduleFullName, err = bufmodule.ParseModuleFullName("buf.build/abc/def") require.NoError(t, err) // NB: intentionally different metadata + commitID2, err := uuidutil.New() + require.NoError(t, err) imageFile, err = NewImageFile( fileDescriptor, moduleFullName, - "987654321", + commitID2, "abc/def/xyz.proto", false, true, @@ -184,7 +190,8 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { ) require.NoError(t, err) - protoImageFile = imageFileToProtoImageFile(imageFile) + protoImageFile, err = imageFileToProtoImageFile(imageFile) + require.NoError(t, err) // make sure unrecognized bytes survived and extraneous buf extension is not present require.Equal(t, otherData, []byte(protoImageFile.ProtoReflect().GetUnknown())) diff --git a/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go index 4fea6537f4..9ec87e17c6 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go @@ -23,6 +23,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -114,30 +115,22 @@ func (a *commitProvider) getIndexedCommitsForRegistryAndIndexedModuleKeys( ) ([]slicesext.Indexed[bufmodule.Commit], error) { commitIDToIndexedModuleKey, err := slicesext.ToUniqueValuesMapError( indexedModuleKeys, - func(indexedModuleKey slicesext.Indexed[bufmodule.ModuleKey]) (string, error) { + func(indexedModuleKey slicesext.Indexed[bufmodule.ModuleKey]) (uuid.UUID, error) { return indexedModuleKey.Value.CommitID(), nil }, ) if err != nil { return nil, err } - protoCommitIDs, err := slicesext.MapError( - slicesext.MapKeysToSortedSlice(commitIDToIndexedModuleKey), - func(commitID string) (string, error) { - return CommitIDToProto(commitID) - }, - ) - if err != nil { - return nil, err - } - protoCommits, err := getProtoCommitsForRegistryAndCommitIDs(ctx, a.clientProvider, registry, protoCommitIDs, digestType) + commitIDs := slicesext.MapKeysToSlice(commitIDToIndexedModuleKey) + protoCommits, err := getProtoCommitsForRegistryAndCommitIDs(ctx, a.clientProvider, registry, commitIDs, digestType) if err != nil { return nil, err } return slicesext.MapError( protoCommits, func(protoCommit *modulev1beta1.Commit) (slicesext.Indexed[bufmodule.Commit], error) { - commitID, err := ProtoToCommitID(protoCommit.Id) + commitID, err := uuid.FromString(protoCommit.Id) if err != nil { return slicesext.Indexed[bufmodule.Commit]{}, err } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/convert.go b/private/bufpkg/bufmodule/bufmoduleapi/convert.go index a92b12c264..4ac944c080 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/convert.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/convert.go @@ -25,7 +25,6 @@ import ( "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/storage/storagemem" - "github.com/bufbuild/buf/private/pkg/uuidutil" ) var ( @@ -51,28 +50,6 @@ func ParseModuleVisibility(s string) (modulev1beta1.ModuleVisibility, error) { } } -// CommitIDToProto converts the CommitID to a BSR Commit ID. -// -// This just takes a dashless UUID and converts it to a dashful UUID. -func CommitIDToProto(commitID string) (string, error) { - protoCommitID, err := uuidutil.FromDashless(commitID) - if err != nil { - return "", fmt.Errorf("invalid commit ID %s: %w", commitID, err) - } - return protoCommitID.String(), nil -} - -// ProtoToCommitID converts the BSR Commit ID to a CommitID. -// -// This just takes a dashless UUID and converts it to a dashful UUID. -func ProtoToCommitID(protoCommitID string) (string, error) { - id, err := uuidutil.FromString(protoCommitID) - if err != nil { - return "", fmt.Errorf("invalid BSR commit ID %s: %w", protoCommitID, err) - } - return uuidutil.ToDashless(id) -} - // DigestToProto converts the given Digest to a proto Digest. func DigestToProto(digest bufmodule.Digest) (*modulev1beta1.Digest, error) { protoDigestType, err := digestTypeToProto(digest.Type()) diff --git a/private/bufpkg/bufmodule/bufmoduleapi/digest_for_commit_id.go b/private/bufpkg/bufmodule/bufmoduleapi/digest_for_commit_id.go index 9fb3f7eb7a..54f45ef4a5 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/digest_for_commit_id.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/digest_for_commit_id.go @@ -19,6 +19,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufapi" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/gofrs/uuid/v5" ) // DigestForCommitID resolves the commit ID by calling the CommitService to get @@ -27,7 +28,7 @@ func DigestForCommitID( ctx context.Context, clientProvider bufapi.CommitServiceClientProvider, registry string, - commitID string, + commitID uuid.UUID, digestType bufmodule.DigestType, ) (bufmodule.Digest, error) { protoCommit, err := getProtoCommitForRegistryAndCommitID(ctx, clientProvider, registry, commitID, digestType) diff --git a/private/bufpkg/bufmodule/bufmoduleapi/graph_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/graph_provider.go index 47b7e9d567..b7a7ad2b25 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/graph_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/graph_provider.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/pkg/dag" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -70,8 +71,8 @@ func newGraphProvider( func (a *graphProvider) GetGraphForModuleKeys( ctx context.Context, moduleKeys []bufmodule.ModuleKey, -) (*dag.Graph[string, bufmodule.ModuleKey], error) { - graph := dag.NewGraph[string, bufmodule.ModuleKey](bufmodule.ModuleKey.CommitID) +) (*dag.Graph[uuid.UUID, bufmodule.ModuleKey], error) { + graph := dag.NewGraph[uuid.UUID, bufmodule.ModuleKey](bufmodule.ModuleKey.CommitID) if len(moduleKeys) == 0 { return graph, nil } @@ -102,7 +103,7 @@ func (a *graphProvider) GetGraphForModuleKeys( } commitIDToModuleKey, err := slicesext.ToUniqueValuesMapError( moduleKeys, - func(moduleKey bufmodule.ModuleKey) (string, error) { + func(moduleKey bufmodule.ModuleKey) (uuid.UUID, error) { return moduleKey.CommitID(), nil }, ) @@ -110,7 +111,7 @@ func (a *graphProvider) GetGraphForModuleKeys( return nil, err } for _, protoCommit := range protoGraph.Commits { - commitID, err := ProtoToCommitID(protoCommit.Id) + commitID, err := uuid.FromString(protoCommit.Id) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (a *graphProvider) GetGraphForModuleKeys( graph.AddNode(moduleKey) } for _, protoEdge := range protoGraph.Edges { - fromCommitID, err := ProtoToCommitID(protoEdge.FromCommitId) + fromCommitID, err := uuid.FromString(protoEdge.FromCommitId) if err != nil { return nil, err } @@ -143,7 +144,7 @@ func (a *graphProvider) GetGraphForModuleKeys( // This could be an API error, but regardless we consider it a system error here. return nil, syserror.Newf("did not have commit id %q in commitIDToModuleKey", fromCommitID) } - toCommitID, err := ProtoToCommitID(protoEdge.ToCommitId) + toCommitID, err := uuid.FromString(protoEdge.ToCommitId) if err != nil { return nil, err } @@ -164,15 +165,7 @@ func (a *graphProvider) getProtoGraphForRegistryAndModuleKeys( moduleKeys []bufmodule.ModuleKey, digestType bufmodule.DigestType, ) (*modulev1beta1.Graph, error) { - protoCommitIDs, err := slicesext.MapError( - moduleKeys, - func(moduleKey bufmodule.ModuleKey) (string, error) { - return CommitIDToProto(moduleKey.CommitID()) - }, - ) - if err != nil { - return nil, err - } + commitIDs := slicesext.Map(moduleKeys, bufmodule.ModuleKey.CommitID) protoDigestType, err := digestTypeToProto(digestType) if err != nil { return nil, err @@ -183,11 +176,11 @@ func (a *graphProvider) getProtoGraphForRegistryAndModuleKeys( &modulev1beta1.GetGraphRequest{ // TODO: chunking ResourceRefs: slicesext.Map( - protoCommitIDs, - func(protoCommitID string) *modulev1beta1.ResourceRef { + commitIDs, + func(commitID uuid.UUID) *modulev1beta1.ResourceRef { return &modulev1beta1.ResourceRef{ Value: &modulev1beta1.ResourceRef_Id{ - Id: protoCommitID, + Id: commitID.String(), }, } }, diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go index 8eba5876ac..61d582f2bd 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -131,7 +132,7 @@ func (a *moduleDataProvider) getIndexedModuleDatasForRegistryAndIndexedModuleKey } commitIDToIndexedModuleKey, err := slicesext.ToUniqueValuesMapError( indexedModuleKeys, - func(indexedModuleKey slicesext.Indexed[bufmodule.ModuleKey]) (string, error) { + func(indexedModuleKey slicesext.Indexed[bufmodule.ModuleKey]) (uuid.UUID, error) { return indexedModuleKey.Value.CommitID(), nil }, ) @@ -195,18 +196,10 @@ func (a *moduleDataProvider) getCommitIDToProtoContentForRegistryAndIndexedModul ctx context.Context, protoModuleProvider *protoModuleProvider, registry string, - commitIDToIndexedModuleKey map[string]slicesext.Indexed[bufmodule.ModuleKey], + commitIDToIndexedModuleKey map[uuid.UUID]slicesext.Indexed[bufmodule.ModuleKey], digestType bufmodule.DigestType, -) (map[string]*modulev1beta1.DownloadResponse_Content, error) { - protoCommitIDs, err := slicesext.MapError( - slicesext.MapKeysToSortedSlice(commitIDToIndexedModuleKey), - func(commitID string) (string, error) { - return CommitIDToProto(commitID) - }, - ) - if err != nil { - return nil, err - } +) (map[uuid.UUID]*modulev1beta1.DownloadResponse_Content, error) { + commitIDs := slicesext.MapKeysToSlice(commitIDToIndexedModuleKey) protoDigestType, err := digestTypeToProto(digestType) if err != nil { return nil, err @@ -217,12 +210,12 @@ func (a *moduleDataProvider) getCommitIDToProtoContentForRegistryAndIndexedModul &modulev1beta1.DownloadRequest{ // TODO: chunking Values: slicesext.Map( - protoCommitIDs, - func(protoCommitID string) *modulev1beta1.DownloadRequest_Value { + commitIDs, + func(commitID uuid.UUID) *modulev1beta1.DownloadRequest_Value { return &modulev1beta1.DownloadRequest_Value{ ResourceRef: &modulev1beta1.ResourceRef{ Value: &modulev1beta1.ResourceRef_Id{ - Id: protoCommitID, + Id: commitID.String(), }, }, DigestType: protoDigestType, @@ -244,8 +237,8 @@ func (a *moduleDataProvider) getCommitIDToProtoContentForRegistryAndIndexedModul } commitIDToProtoContent, err := slicesext.ToUniqueValuesMapError( response.Msg.Contents, - func(protoContent *modulev1beta1.DownloadResponse_Content) (string, error) { - return CommitIDToProto(protoContent.Commit.Id) + func(protoContent *modulev1beta1.DownloadResponse_Content) (uuid.UUID, error) { + return uuid.FromString(protoContent.Commit.Id) }, ) if err != nil { diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_proto_commit.go b/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_proto_commit.go index 19aabef858..d3f740ef66 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_proto_commit.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_proto_commit.go @@ -20,6 +20,7 @@ import ( modulev1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1beta1" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/gofrs/uuid/v5" ) func getModuleKeyForProtoCommit( @@ -62,7 +63,7 @@ func getModuleKeyForProtoCommit( if err != nil { return nil, err } - commitID, err := ProtoToCommitID(protoCommit.Id) + commitID, err := uuid.FromString(protoCommit.Id) if err != nil { return nil, err } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go index eacbd717a5..7f3a3468f0 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go @@ -24,6 +24,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufapi" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/slicesext" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -101,7 +102,7 @@ func (a *moduleKeyProvider) getIndexedModuleKeysForRegistryAndIndexedModuleRefs( } indexedModuleKeys := make([]slicesext.Indexed[bufmodule.ModuleKey], len(indexedModuleRefs)) for i, protoCommit := range protoCommits { - commitID, err := ProtoToCommitID(protoCommit.Id) + commitID, err := uuid.FromString(protoCommit.Id) if err != nil { return nil, err } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/proto_commits_for_registry_and_proto_commit_ids.go b/private/bufpkg/bufmodule/bufmoduleapi/proto_commits_for_registry_and_proto_commit_ids.go index 4f4281fc02..b0a32bb643 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/proto_commits_for_registry_and_proto_commit_ids.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/proto_commits_for_registry_and_proto_commit_ids.go @@ -24,16 +24,17 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufapi" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/slicesext" + "github.com/gofrs/uuid/v5" ) func getProtoCommitForRegistryAndCommitID( ctx context.Context, clientProvider bufapi.CommitServiceClientProvider, registry string, - commitID string, + commitID uuid.UUID, digestType bufmodule.DigestType, ) (*modulev1beta1.Commit, error) { - protoCommits, err := getProtoCommitsForRegistryAndCommitIDs(ctx, clientProvider, registry, []string{commitID}, digestType) + protoCommits, err := getProtoCommitsForRegistryAndCommitIDs(ctx, clientProvider, registry, []uuid.UUID{commitID}, digestType) if err != nil { return nil, err } @@ -45,18 +46,9 @@ func getProtoCommitsForRegistryAndCommitIDs( ctx context.Context, clientProvider bufapi.CommitServiceClientProvider, registry string, - commitIDs []string, + commitIDs []uuid.UUID, digestType bufmodule.DigestType, ) ([]*modulev1beta1.Commit, error) { - protoCommitIDs, err := slicesext.MapError( - commitIDs, - func(commitID string) (string, error) { - return CommitIDToProto(commitID) - }, - ) - if err != nil { - return nil, err - } protoDigestType, err := digestTypeToProto(digestType) if err != nil { return nil, err @@ -67,11 +59,11 @@ func getProtoCommitsForRegistryAndCommitIDs( &modulev1beta1.GetCommitsRequest{ // TODO: chunking ResourceRefs: slicesext.Map( - protoCommitIDs, - func(protoCommitID string) *modulev1beta1.ResourceRef { + commitIDs, + func(commitID uuid.UUID) *modulev1beta1.ResourceRef { return &modulev1beta1.ResourceRef{ Value: &modulev1beta1.ResourceRef_Id{ - Id: protoCommitID, + Id: commitID.String(), }, } }, diff --git a/private/bufpkg/bufmodule/bufmoduleapi/upload.go b/private/bufpkg/bufmodule/bufmoduleapi/upload.go index 25c166dcee..4233cb4cd5 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/upload.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/upload.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" ) // Upload uploads the given ModuleSet. @@ -106,25 +107,21 @@ func Upload( if !ok { return nil, syserror.Newf("no Module found for OpaqueID %q", moduleDep.OpaqueID()) } - var depProtoCommitID string + var depCommitID uuid.UUID // TODO: This should probably just become !moduleDep.IsLocal()!!!! if !moduleDep.IsTarget() { - depCommitID := moduleDep.CommitID() - if depCommitID == "" { + depCommitID = moduleDep.CommitID() + if depCommitID.IsNil() { // TODO: THIS IS A MAJOR TODO. We might NOT have commit IDs for other modules // in the workspace. In this case, we need to add their data to the upload. return nil, fmt.Errorf("did not have a commit ID for a non-target module dependency %q", moduleDep.OpaqueID()) } - depProtoCommitID, err = CommitIDToProto(depCommitID) - if err != nil { - return nil, err - } } protoDepRefs = append( protoDepRefs, &modulev1beta1.UploadRequest_DepRef{ ModuleRef: depProtoModuleRef, - CommitId: depProtoCommitID, + CommitId: depCommitID.String(), }, ) } @@ -166,7 +163,7 @@ func Upload( commits := make([]bufmodule.Commit, len(response.Msg.Commits)) for i, protoCommit := range response.Msg.Commits { targetModule := targetModules[i] - commitID, err := ProtoToCommitID(protoCommit.Id) + commitID, err := uuid.FromString(protoCommit.Id) if err != nil { return nil, err } diff --git a/private/bufpkg/bufmodule/bufmodulecache/base_provider.go b/private/bufpkg/bufmodule/bufmodulecache/base_provider.go index cec7da2fb8..c393b60b65 100644 --- a/private/bufpkg/bufmodule/bufmodulecache/base_provider.go +++ b/private/bufpkg/bufmodule/bufmodulecache/base_provider.go @@ -21,6 +21,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -58,7 +59,7 @@ func (p *baseProvider[T]) getValuesForModuleKeys( ) ([]T, error) { commitIDToIndexedModuleKey, err := slicesext.ToUniqueIndexedValuesMap( moduleKeys, - func(moduleKey bufmodule.ModuleKey) string { + func(moduleKey bufmodule.ModuleKey) uuid.UUID { return moduleKey.CommitID() }, ) diff --git a/private/bufpkg/bufmodule/bufmodulestore/commit_store.go b/private/bufpkg/bufmodule/bufmodulestore/commit_store.go index ddaf5a9fc8..c5103a5e07 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/commit_store.go +++ b/private/bufpkg/bufmodule/bufmodulestore/commit_store.go @@ -242,7 +242,7 @@ func getCommitStoreDirPath(moduleKey bufmodule.ModuleKey) string { // // This is "commitID.json", e.g. the commit "12345" will return "12345.json". func getCommitStoreFilePath(moduleKey bufmodule.ModuleKey) string { - return moduleKey.CommitID() + ".json" + return moduleKey.CommitID().String() + ".json" } // externalCommit is the store representation of a Commit. diff --git a/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go b/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go index 73f5d71646..5f3b9b7d1b 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go +++ b/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/storage/storagearchive" "github.com/bufbuild/buf/private/pkg/storage/storagemem" + "github.com/gofrs/uuid/v5" "go.uber.org/multierr" "go.uber.org/zap" ) @@ -324,7 +325,7 @@ func (p *moduleDataStore) putModuleData( } externalModuleData.Deps[i] = externalModuleDataDep{ Name: depModuleKey.ModuleFullName().String(), - Commit: depModuleKey.CommitID(), + Commit: depModuleKey.CommitID().String(), Digest: digest.String(), } } @@ -472,7 +473,7 @@ func getModuleDataStoreDirPath(moduleKey bufmodule.ModuleKey) string { moduleKey.ModuleFullName().Registry(), moduleKey.ModuleFullName().Owner(), moduleKey.ModuleFullName().Name(), - moduleKey.CommitID(), + moduleKey.CommitID().String(), ) } @@ -486,7 +487,7 @@ func getModuleDataStoreTarPath(moduleKey bufmodule.ModuleKey) string { moduleKey.ModuleFullName().Registry(), moduleKey.ModuleFullName().Owner(), moduleKey.ModuleFullName().Name(), - moduleKey.CommitID()+".tar", + moduleKey.CommitID().String()+".tar", ) } @@ -508,9 +509,13 @@ func getDeclaredDepModuleKeyForExternalModuleDataDep(dep externalModuleDataDep) if err != nil { return nil, err } + commitID, err := uuid.FromString(dep.Commit) + if err != nil { + return nil, err + } return bufmodule.NewModuleKey( moduleFullName, - dep.Commit, + commitID, func() (bufmodule.Digest, error) { return digest, nil }, diff --git a/private/bufpkg/bufmodule/bufmodulestore/util.go b/private/bufpkg/bufmodule/bufmodulestore/util.go index b13b67de7c..1284bd46a1 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/util.go +++ b/private/bufpkg/bufmodule/bufmodulestore/util.go @@ -25,7 +25,7 @@ func logDebugModuleKey(logger *zap.Logger, moduleKey bufmodule.ModuleKey, messag append( []zap.Field{ zap.String("moduleFullName", moduleKey.ModuleFullName().String()), - zap.String("commitID", moduleKey.CommitID()), + zap.String("commitID", moduleKey.CommitID().String()), }, fields..., )..., diff --git a/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go b/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go index 8c0983fffd..8efd30704e 100644 --- a/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go +++ b/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go @@ -29,6 +29,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage/storagemem" "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -54,7 +55,7 @@ var ( // used. It is an error to both set ReadObjectDataFromBucket and set Buf.*ObjectData. type ModuleData struct { Name string - CommitID string + CommitID uuid.UUID CreateTime time.Time DirPath string PathToData map[string][]byte @@ -143,28 +144,17 @@ func NewModuleSetForBucket( ) } -// NewCommitID returns a new CommitID. -// -// This is a dashless UUID. -func NewCommitID() (string, error) { - id, err := uuidutil.New() - if err != nil { - return "", err - } - return uuidutil.ToDashless(id) -} - // *** PRIVATE *** type omniProvider struct { bufmodule.ModuleSet - commitIDToCreateTime map[string]time.Time + commitIDToCreateTime map[uuid.UUID]time.Time } func newOmniProvider( moduleDatas []ModuleData, ) (*omniProvider, error) { - commitIDToCreateTime := make(map[string]time.Time) + commitIDToCreateTime := make(map[uuid.UUID]time.Time) moduleSet, err := newModuleSet(moduleDatas, true, commitIDToCreateTime) if err != nil { return nil, err @@ -246,8 +236,8 @@ func (o *omniProvider) GetCommitsForModuleKeys( func (o *omniProvider) GetGraphForModuleKeys( ctx context.Context, moduleKeys []bufmodule.ModuleKey, -) (*dag.Graph[string, bufmodule.ModuleKey], error) { - graph := dag.NewGraph[string, bufmodule.ModuleKey](bufmodule.ModuleKey.CommitID) +) (*dag.Graph[uuid.UUID, bufmodule.ModuleKey], error) { + graph := dag.NewGraph[uuid.UUID, bufmodule.ModuleKey](bufmodule.ModuleKey.CommitID) if len(moduleKeys) == 0 { return graph, nil } @@ -322,7 +312,7 @@ func newModuleSet( moduleDatas []ModuleData, requireName bool, // may be nil - commitIDToCreateTime map[string]time.Time, + commitIDToCreateTime map[uuid.UUID]time.Time, ) (bufmodule.ModuleSet, error) { moduleSetBuilder := bufmodule.NewModuleSetBuilder(context.Background(), zap.NewNop(), bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) for i, moduleData := range moduleDatas { @@ -344,7 +334,7 @@ func addModuleDataToModuleSetBuilder( moduleData ModuleData, requireName bool, // may be nil - commitIDToCreateTime map[string]time.Time, + commitIDToCreateTime map[uuid.UUID]time.Time, index int, ) error { if boolCount( @@ -398,8 +388,8 @@ func addModuleDataToModuleSetBuilder( return err } commitID := moduleData.CommitID - if commitID == "" { - commitID, err = NewCommitID() + if commitID.IsNil() { + commitID, err = uuidutil.New() if err != nil { return err } @@ -457,7 +447,7 @@ func addModuleDataToModuleSetBuilder( func addModuleToGraphRec( module bufmodule.Module, - graph *dag.Graph[string, bufmodule.ModuleKey], + graph *dag.Graph[uuid.UUID, bufmodule.ModuleKey], digestType bufmodule.DigestType, ) error { moduleKey, err := bufmodule.ModuleToModuleKey(module, digestType) diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/commitidfromdashless.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/commitidfromdashless.go new file mode 100644 index 0000000000..bc9b44c380 --- /dev/null +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/commitidfromdashless.go @@ -0,0 +1,75 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "time" + + "github.com/bufbuild/buf/private/pkg/app/appcmd" + "github.com/bufbuild/buf/private/pkg/app/appext" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/pflag" +) + +const ( + name = "buf-commit-id-from-dashless" +) + +func main() { + appcmd.Main(context.Background(), newCommand()) +} + +func newCommand() *appcmd.Command { + builder := appext.NewBuilder( + name, + appext.BuilderWithTimeout(120*time.Second), + appext.BuilderWithTracing(), + ) + flags := newFlags() + return &appcmd.Command{ + Use: name + "dashless-commit_id", + Short: "Convert a commit ID from dashless.", + Args: appcmd.ExactArgs(1), + Run: builder.NewRunFunc( + func(ctx context.Context, container appext.Container) error { + return run(ctx, container, flags) + }, + ), + BindFlags: flags.Bind, + BindPersistentFlags: builder.BindRoot, + } +} + +type flags struct{} + +func newFlags() *flags { + return &flags{} +} + +func (f *flags) Bind(flagSet *pflag.FlagSet) {} + +func run( + ctx context.Context, + container appext.Container, + flags *flags, +) error { + commitID, err := uuidutil.FromDashless(container.Arg(0)) + if err != nil { + return err + } + _, err = container.Stdout().Write([]byte(commitID.String() + "\n")) + return err +} diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/usage.gen.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/usage.gen.go new file mode 100644 index 0000000000..dfb23e3564 --- /dev/null +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-from-dashless/usage.gen.go @@ -0,0 +1,19 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated. DO NOT EDIT. + +package main + +import _ "github.com/bufbuild/buf/private/usage" diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/commitidtodashless.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/commitidtodashless.go new file mode 100644 index 0000000000..3722411df3 --- /dev/null +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/commitidtodashless.go @@ -0,0 +1,80 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "time" + + "github.com/bufbuild/buf/private/pkg/app/appcmd" + "github.com/bufbuild/buf/private/pkg/app/appext" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/gofrs/uuid/v5" + "github.com/spf13/pflag" +) + +const ( + name = "buf-commit-id-to-dashless" +) + +func main() { + appcmd.Main(context.Background(), newCommand()) +} + +func newCommand() *appcmd.Command { + builder := appext.NewBuilder( + name, + appext.BuilderWithTimeout(120*time.Second), + appext.BuilderWithTracing(), + ) + flags := newFlags() + return &appcmd.Command{ + Use: name + "commit_id", + Short: "Convert a commit ID to dashless.", + Args: appcmd.ExactArgs(1), + Run: builder.NewRunFunc( + func(ctx context.Context, container appext.Container) error { + return run(ctx, container, flags) + }, + ), + BindFlags: flags.Bind, + BindPersistentFlags: builder.BindRoot, + } +} + +type flags struct{} + +func newFlags() *flags { + return &flags{} +} + +func (f *flags) Bind(flagSet *pflag.FlagSet) {} + +func run( + ctx context.Context, + container appext.Container, + flags *flags, +) error { + commitID, err := uuid.FromString(container.Arg(0)) + if err != nil { + return err + } + commitIDString, err := uuidutil.ToDashless(commitID) + if err != nil { + return err + } + _, err = container.Stdout().Write([]byte(commitIDString + "\n")) + return err +} diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/usage.gen.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/usage.gen.go new file mode 100644 index 0000000000..dfb23e3564 --- /dev/null +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-commit-id-to-dashless/usage.gen.go @@ -0,0 +1,19 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated. DO NOT EDIT. + +package main + +import _ "github.com/bufbuild/buf/private/usage" diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/newcommitid.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/newcommitid.go index 15477b72a9..a097bfe965 100644 --- a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/newcommitid.go +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-new-commit-id/newcommitid.go @@ -16,20 +16,84 @@ package main import ( "context" + "fmt" + "time" - "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" - "github.com/bufbuild/buf/private/pkg/app" + "github.com/bufbuild/buf/private/pkg/app/appcmd" + "github.com/bufbuild/buf/private/pkg/app/appext" + "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/pflag" +) + +const ( + name = "buf-new-commit-id" + typeFlagName = "type" ) func main() { - app.Main(context.Background(), run) + appcmd.Main(context.Background(), newCommand()) +} + +func newCommand() *appcmd.Command { + builder := appext.NewBuilder( + name, + appext.BuilderWithTimeout(120*time.Second), + appext.BuilderWithTracing(), + ) + flags := newFlags() + return &appcmd.Command{ + Use: name, + Short: "Produce a new commit ID for testing.", + Long: fmt.Sprintf(`If --%s v1 is specified, a dashless commit ID is produced. +If --%s v2 is specified, a dashful commit ID is produced.`, typeFlagName, typeFlagName), + Run: builder.NewRunFunc( + func(ctx context.Context, container appext.Container) error { + return run(ctx, container, flags) + }, + ), + BindFlags: flags.Bind, + BindPersistentFlags: builder.BindRoot, + } +} + +type flags struct { + Type string +} + +func newFlags() *flags { + return &flags{} } -func run(ctx context.Context, container app.Container) error { - commitID, err := bufmoduletesting.NewCommitID() +func (f *flags) Bind(flagSet *pflag.FlagSet) { + flagSet.StringVar( + &f.Type, + typeFlagName, + "v2", + "The commit ID type, either v1 or v2.", + ) +} + +func run( + ctx context.Context, + container appext.Container, + flags *flags, +) error { + commitID, err := uuidutil.New() if err != nil { return err } - _, err = container.Stdout().Write([]byte(commitID + "\n")) + var commitIDString string + switch flags.Type { + case "v1": + commitIDString, err = uuidutil.ToDashless(commitID) + if err != nil { + return err + } + case "v2": + commitIDString = commitID.String() + default: + return appcmd.NewInvalidArgumentErrorf("invalid value for --%s: %q", typeFlagName, flags.Type) + } + _, err = container.Stdout().Write([]byte(commitIDString + "\n")) return err } diff --git a/private/bufpkg/bufmodule/commit.go b/private/bufpkg/bufmodule/commit.go index 990567edc5..4ba252758e 100644 --- a/private/bufpkg/bufmodule/commit.go +++ b/private/bufpkg/bufmodule/commit.go @@ -19,7 +19,6 @@ import ( "time" "github.com/bufbuild/buf/private/pkg/syncext" - "github.com/bufbuild/buf/private/pkg/uuidutil" ) // Commit represents a Commit on the BSR. @@ -110,10 +109,3 @@ func (c *commit) Digest() (Digest, error) { } func (*commit) isCommit() {} - -func validateCommitID(commitID string) error { - if err := uuidutil.ValidateDashless(commitID); err != nil { - return fmt.Errorf("invalid commit ID %s: %w", commitID, err) - } - return nil -} diff --git a/private/bufpkg/bufmodule/graph_provider.go b/private/bufpkg/bufmodule/graph_provider.go index 2ea386834d..8c9177f67a 100644 --- a/private/bufpkg/bufmodule/graph_provider.go +++ b/private/bufpkg/bufmodule/graph_provider.go @@ -18,6 +18,7 @@ import ( "context" "github.com/bufbuild/buf/private/pkg/dag" + "github.com/gofrs/uuid/v5" ) // GraphProvider provides directed acyclic graphs for ModuleKeys. @@ -35,5 +36,5 @@ type GraphProvider interface { // The input ModuleKeys must all have the same registry. An error will be returned otherwise. // // If any ModuleKey is not found, an error with fs.ErrNotExist will be returned. - GetGraphForModuleKeys(context.Context, []ModuleKey) (*dag.Graph[string, ModuleKey], error) + GetGraphForModuleKeys(context.Context, []ModuleKey) (*dag.Graph[uuid.UUID, ModuleKey], error) } diff --git a/private/bufpkg/bufmodule/module.go b/private/bufpkg/bufmodule/module.go index 496dd8e10f..2a8215e240 100644 --- a/private/bufpkg/bufmodule/module.go +++ b/private/bufpkg/bufmodule/module.go @@ -22,6 +22,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/syncext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" ) @@ -77,12 +78,13 @@ type Module interface { ModuleFullName() ModuleFullName // CommitID returns the BSR ID of the Commit. // - // A CommitID is always a dashless UUID. - // The CommitID converted to using dashes is the ID of the Commit on the BSR. - // May be empty. Callers should not rely on this value being present. + // A CommitID is always a dashful UUID, i.e. this is a proper UUID. + // In situations where a dashless UUID is needed, it is up to the caller to do so (i.e. with v1 buf.locks). + // May be empty, that is CommitID().IsNil() may be true. + // Callers should not rely on this value being present. // // If ModuleFullName is nil, this will always be empty. - CommitID() string + CommitID() uuid.UUID // Digest returns the Module digest for the given DigestType. // @@ -260,7 +262,7 @@ type module struct { getBucket func() (storage.ReadBucket, error) bucketID string moduleFullName ModuleFullName - commitID string + commitID uuid.UUID isTarget bool isLocal bool v1BufYAMLObjectData ObjectData @@ -280,7 +282,7 @@ func newModule( syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error), bucketID string, moduleFullName ModuleFullName, - commitID string, + commitID uuid.UUID, isTarget bool, isLocal bool, v1BufYAMLObjectData ObjectData, @@ -303,14 +305,9 @@ func newModule( if !isLocal && moduleFullName == nil { return nil, syserror.New("moduleFullName not present when constructing a remote Module") } - if moduleFullName == nil && commitID != "" { + if moduleFullName == nil && !commitID.IsNil() { return nil, syserror.New("moduleFullName not present and commitID present when constructing a remote Module") } - if commitID != "" { - if err := validateCommitID(commitID); err != nil { - return nil, err - } - } module := &module{ ctx: ctx, logger: logger, @@ -360,7 +357,7 @@ func (m *module) ModuleFullName() ModuleFullName { return m.moduleFullName } -func (m *module) CommitID() string { +func (m *module) CommitID() uuid.UUID { return m.commitID } diff --git a/private/bufpkg/bufmodule/module_key.go b/private/bufpkg/bufmodule/module_key.go index 7da31d54ac..0b0488bb97 100644 --- a/private/bufpkg/bufmodule/module_key.go +++ b/private/bufpkg/bufmodule/module_key.go @@ -22,6 +22,7 @@ import ( "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syncext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" ) // ModuleKey provides identifying information for a Module. @@ -39,11 +40,10 @@ type ModuleKey interface { ModuleFullName() ModuleFullName // CommitID returns the ID of the Commit. // - // A CommitID is always a dashless UUID. - // The CommitID converted to using dashes is the ID of the Commit on the BSR. + // In situations where a dashless UUID is needed, it is up to the caller to do so (i.e. with v1 buf.locks). // - // Always present. - CommitID() string + // Always present, that is CommitID().IsNil() will always be false. + CommitID() uuid.UUID // Digest returns the Module digest. // // Note this is *not* a bufcas.Digest - this is a Digest. bufcas.Digests are a lower-level @@ -61,7 +61,7 @@ type ModuleKey interface { // the returned error. func NewModuleKey( moduleFullName ModuleFullName, - commitID string, + commitID uuid.UUID, getDigest func() (Digest, error), ) (ModuleKey, error) { return newModuleKey( @@ -101,25 +101,22 @@ func UniqueDigestTypeForModuleKeys(moduleKeys []ModuleKey) (DigestType, error) { type moduleKey struct { moduleFullName ModuleFullName - commitID string + commitID uuid.UUID getDigest func() (Digest, error) } func newModuleKey( moduleFullName ModuleFullName, - commitID string, + commitID uuid.UUID, getDigest func() (Digest, error), ) (*moduleKey, error) { if moduleFullName == nil { return nil, errors.New("nil ModuleFullName when constructing ModuleKey") } - if commitID == "" { + if commitID.IsNil() { return nil, errors.New("empty commitID when constructing ModuleKey") } - if err := validateCommitID(commitID); err != nil { - return nil, err - } return &moduleKey{ moduleFullName: moduleFullName, commitID: commitID, @@ -131,7 +128,7 @@ func (m *moduleKey) ModuleFullName() ModuleFullName { return m.moduleFullName } -func (m *moduleKey) CommitID() string { +func (m *moduleKey) CommitID() uuid.UUID { return m.commitID } @@ -140,7 +137,7 @@ func (m *moduleKey) Digest() (Digest, error) { } func (m *moduleKey) String() string { - return m.moduleFullName.String() + ":" + m.commitID + return m.moduleFullName.String() + ":" + m.commitID.String() } func (*moduleKey) isModuleKey() {} diff --git a/private/bufpkg/bufmodule/module_set.go b/private/bufpkg/bufmodule/module_set.go index 44fbc8f625..f1907e3177 100644 --- a/private/bufpkg/bufmodule/module_set.go +++ b/private/bufpkg/bufmodule/module_set.go @@ -25,6 +25,7 @@ import ( "github.com/bufbuild/buf/private/pkg/dag" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" ) // errIsWKT is the error returned by getFastscanResultForPath or getModuleForFilePath if the @@ -63,7 +64,7 @@ type ModuleSet interface { // GetModuleForCommitID gets the Module for the CommitID, if it exists. // // Returns nil if there is no Module with the given CommitID. - GetModuleForCommitID(commitID string) Module + GetModuleForCommitID(commitID uuid.UUID) Module // WithTargetOpaqueIDs returns a new ModuleSet that changes the targeted Modules to // the Modules with the specified OpaqueIDs. @@ -196,7 +197,7 @@ type moduleSet struct { moduleFullNameStringToModule map[string]Module opaqueIDToModule map[string]Module bucketIDToModule map[string]Module - commitIDToModule map[string]Module + commitIDToModule map[uuid.UUID]Module // filePathToModule is a cache of filePath -> module. // @@ -211,7 +212,7 @@ func newModuleSet( moduleFullNameStringToModule := make(map[string]Module, len(modules)) opaqueIDToModule := make(map[string]Module, len(modules)) bucketIDToModule := make(map[string]Module, len(modules)) - commitIDToModule := make(map[string]Module, len(modules)) + commitIDToModule := make(map[uuid.UUID]Module, len(modules)) for _, module := range modules { if moduleFullName := module.ModuleFullName(); moduleFullName != nil { moduleFullNameString := moduleFullName.String() @@ -236,10 +237,10 @@ func newModuleSet( bucketIDToModule[bucketID] = module } commitID := module.CommitID() - if commitID != "" { + if !commitID.IsNil() { if _, ok := commitIDToModule[commitID]; ok { // This should never happen. - return nil, syserror.Newf("duplicate CommitID %q when constructing ModuleSet", commitID) + return nil, syserror.Newf("duplicate CommitID %v when constructing ModuleSet", commitID) } commitIDToModule[commitID] = module } @@ -275,7 +276,7 @@ func (m *moduleSet) GetModuleForBucketID(bucketID string) Module { return m.bucketIDToModule[bucketID] } -func (m *moduleSet) GetModuleForCommitID(commitID string) Module { +func (m *moduleSet) GetModuleForCommitID(commitID uuid.UUID) Module { return m.commitIDToModule[commitID] } diff --git a/private/bufpkg/bufmodule/module_set_builder.go b/private/bufpkg/bufmodule/module_set_builder.go index 553d87124a..58110f8a0d 100644 --- a/private/bufpkg/bufmodule/module_set_builder.go +++ b/private/bufpkg/bufmodule/module_set_builder.go @@ -23,6 +23,7 @@ import ( "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/gofrs/uuid/v5" "go.uber.org/multierr" "go.uber.org/zap" ) @@ -133,7 +134,7 @@ func LocalModuleWithModuleFullName(moduleFullName ModuleFullName) LocalModuleOpt // LocalModuleWithModuleFullName returns a new LocalModuleOption that adds the given ModuleFullName and CommitID // to the result Module. -func LocalModuleWithModuleFullNameAndCommitID(moduleFullName ModuleFullName, commitID string) LocalModuleOption { +func LocalModuleWithModuleFullNameAndCommitID(moduleFullName ModuleFullName, commitID uuid.UUID) LocalModuleOption { return func(localModuleOptions *localModuleOptions) { localModuleOptions.moduleFullName = moduleFullName localModuleOptions.commitID = commitID @@ -265,7 +266,7 @@ func (b *moduleSetBuilder) AddLocalModule( for _, option := range options { option(localModuleOptions) } - if localModuleOptions.moduleFullName == nil && localModuleOptions.commitID != "" { + if localModuleOptions.moduleFullName == nil && !localModuleOptions.commitID.IsNil() { return b.addError(syserror.New("cannot set commitID without ModuleFullName when calling AddLocalModule")) } if !isTarget && (len(localModuleOptions.targetPaths) > 0 || len(localModuleOptions.targetExcludePaths) > 0) { @@ -534,7 +535,7 @@ func getUniqueSortedAddedModulesByOpaqueID(ctx context.Context, addedModules []* type localModuleOptions struct { moduleFullName ModuleFullName - commitID string + commitID uuid.UUID targetPaths []string targetExcludePaths []string protoFileTargetPath string diff --git a/private/pkg/protosource/protosource.go b/private/pkg/protosource/protosource.go index 409305b02a..e5195b4729 100644 --- a/private/pkg/protosource/protosource.go +++ b/private/pkg/protosource/protosource.go @@ -32,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/protodescriptor" + "github.com/gofrs/uuid/v5" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/descriptorpb" ) @@ -205,7 +206,7 @@ type FileInfo interface { // This will only be set if ModuleFullName is set, but may not be set // even if ModuleFullName is set, that is commit is optional information // even if we know what module this file came from. - CommitID() string + CommitID() uuid.UUID // IsImport returns true if this file is an import. IsImport() bool }