Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ linters:
# makes this test flaky.
path: private/buf/bufstudioagent/bufstudioagent_test.go
text: missing the call to method parallel
- linters:
- gochecknoinits
# we actually want to use this init to create a protovalidate.Validator
path: private/bufpkg/bufcas/proto.go
- linters:
- gochecknoinits
# we actually want to use init here
Expand Down
10 changes: 5 additions & 5 deletions private/bufpkg/bufmodule/bufmoduleapi/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1"
modulev1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1beta1"
"buf.build/go/standard/xslices"
"github.com/bufbuild/buf/private/bufpkg/bufcas"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/pkg/cas"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/uuidutil"
"github.com/google/uuid"
Expand Down Expand Up @@ -71,11 +71,11 @@ func V1ProtoToDigest(protoDigest *modulev1.Digest) (bufmodule.Digest, error) {
if err != nil {
return nil, err
}
bufcasDigest, err := bufcas.NewDigest(protoDigest.Value)
casDigest, err := cas.NewDigest(protoDigest.Value)
if err != nil {
return nil, err
}
return bufmodule.NewDigest(digestType, bufcasDigest)
return bufmodule.NewDigest(digestType, casDigest)
}

// DigestToV1Beta1Proto converts the given Digest to a proto Digest.
Expand All @@ -99,11 +99,11 @@ func V1Beta1ProtoToDigest(protoDigest *modulev1beta1.Digest) (bufmodule.Digest,
if err != nil {
return nil, err
}
bufcasDigest, err := bufcas.NewDigest(protoDigest.Value)
casDigest, err := cas.NewDigest(protoDigest.Value)
if err != nil {
return nil, err
}
return bufmodule.NewDigest(digestType, bufcasDigest)
return bufmodule.NewDigest(digestType, casDigest)
}

// *** PRIVATE ***
Expand Down
2 changes: 1 addition & 1 deletion private/bufpkg/bufmodule/commit_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type CommitKey interface {
CommitID() uuid.UUID
// DigestType returns the DigestType of the Commit.
//
// Note this is *not* a bufcas.Digest - this is a Digest. bufcas.Digests are a lower-level
// Note this is *not* a cas.Digest - this is a Digest. cas.Digests are a lower-level
// type that just deal in terms of files and content. A ModuleDigest is a specific algorithm
// applied to a set of files and dependencies.
DigestType() DigestType
Expand Down
66 changes: 33 additions & 33 deletions private/bufpkg/bufmodule/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"

"buf.build/go/standard/xslices"
"github.com/bufbuild/buf/private/bufpkg/bufcas"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/pkg/cas"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/syserror"
)
Expand Down Expand Up @@ -109,17 +109,17 @@ type Digest interface {
}

// NewDigest creates a new Digest.
func NewDigest(digestType DigestType, bufcasDigest bufcas.Digest) (Digest, error) {
func NewDigest(digestType DigestType, casDigest cas.Digest) (Digest, error) {
switch digestType {
case DigestTypeB4, DigestTypeB5:
if bufcasDigest.Type() != bufcas.DigestTypeShake256 {
if casDigest.Type() != cas.DigestTypeShake256 {
return nil, syserror.Newf(
"trying to create a %v Digest for a cas Digest of type %v",
digestType,
bufcasDigest.Type(),
casDigest.Type(),
)
}
return newDigest(digestType, bufcasDigest), nil
return newDigest(digestType, casDigest), nil
default:
// This is a system error.
return nil, syserror.Newf("unknown DigestType: %v", digestType)
Expand Down Expand Up @@ -165,11 +165,11 @@ func ParseDigest(s string) (Digest, error) {
}
switch digestType {
case DigestTypeB4, DigestTypeB5:
bufcasDigest, err := bufcas.NewDigest(value)
casDigest, err := cas.NewDigest(value)
if err != nil {
return nil, err
}
return NewDigest(digestType, bufcasDigest)
return NewDigest(digestType, casDigest)
default:
return nil, syserror.Newf("unknown DigestType: %v", digestType)
}
Expand All @@ -196,19 +196,19 @@ func DigestEqual(a Digest, b Digest) bool {
/// *** PRIVATE ***

type digest struct {
digestType DigestType
bufcasDigest bufcas.Digest
digestType DigestType
casDigest cas.Digest
// Cache as we call String pretty often.
// We could do this lazily but not worth it.
stringValue string
}

// validation should occur outside of this function.
func newDigest(digestType DigestType, bufcasDigest bufcas.Digest) *digest {
func newDigest(digestType DigestType, casDigest cas.Digest) *digest {
return &digest{
digestType: digestType,
bufcasDigest: bufcasDigest,
stringValue: digestType.String() + ":" + hex.EncodeToString(bufcasDigest.Value()),
digestType: digestType,
casDigest: casDigest,
stringValue: digestType.String() + ":" + hex.EncodeToString(casDigest.Value()),
}
}

Expand All @@ -217,7 +217,7 @@ func (d *digest) Type() DigestType {
}

func (d *digest) Value() []byte {
return d.bufcasDigest.Value()
return d.casDigest.Value()
}

func (d *digest) String() string {
Expand All @@ -232,19 +232,19 @@ func getB4Digest(
v1BufYAMLObjectData ObjectData,
v1BufLockObjectData ObjectData,
) (Digest, error) {
var fileNodes []bufcas.FileNode
var fileNodes []cas.FileNode
if err := storage.WalkReadObjects(
ctx,
// This is extreme defensive programming. We've gone out of our way to make sure
// that the bucket is already filtered, but it's just too important to mess up here.
storage.FilterReadBucket(bucketWithStorageMatcherApplied, getStorageMatcher(ctx, bucketWithStorageMatcherApplied)),
"",
func(readObject storage.ReadObject) error {
digest, err := bufcas.NewDigestForContent(readObject)
digest, err := cas.NewDigestForContent(readObject)
if err != nil {
return err
}
fileNode, err := bufcas.NewFileNode(readObject.Path(), digest)
fileNode, err := cas.NewFileNode(readObject.Path(), digest)
if err != nil {
return err
}
Expand All @@ -262,25 +262,25 @@ func getB4Digest(
// We may not have object data for one of these files, this is valid.
continue
}
digest, err := bufcas.NewDigestForContent(bytes.NewReader(objectData.Data()))
digest, err := cas.NewDigestForContent(bytes.NewReader(objectData.Data()))
if err != nil {
return nil, err
}
fileNode, err := bufcas.NewFileNode(objectData.Name(), digest)
fileNode, err := cas.NewFileNode(objectData.Name(), digest)
if err != nil {
return nil, err
}
fileNodes = append(fileNodes, fileNode)
}
manifest, err := bufcas.NewManifest(fileNodes)
manifest, err := cas.NewManifest(fileNodes)
if err != nil {
return nil, err
}
bufcasDigest, err := bufcas.ManifestToDigest(manifest)
casDigest, err := cas.ManifestToDigest(manifest)
if err != nil {
return nil, err
}
return NewDigest(DigestTypeB4, bufcasDigest)
return NewDigest(DigestTypeB4, casDigest)
}

func getB5DigestForBucketAndModuleDeps(
Expand Down Expand Up @@ -321,8 +321,8 @@ func getB5DigestForBucketAndDepModuleKeys(
//
// A Digest is a composite digest of all Module Files, and all Module dependencies.
//
// All Files are added to a bufcas.Manifest, which is then turned into a bufcas.Digest.
// The file bufcas.Digest, along with all Digests of the dependencies, are then sorted,
// All Files are added to a cas.Manifest, which is then turned into a cas.Digest.
// The file cas.Digest, along with all Digests of the dependencies, are then sorted,
// and then digested themselves as content.
//
// Note that the name of the Module and any of its dependencies has no effect on the Digest.
Expand All @@ -331,13 +331,13 @@ func getB5DigestForBucketAndDepDigests(
bucketWithStorageMatcherApplied storage.ReadBucket,
depDigests []Digest,
) (Digest, error) {
// First, compute the shake256 bufcas.Digest of the files. This will include a
// First, compute the shake256 cas.Digest of the files. This will include a
// sorted list of file names and their digests.
filesDigest, err := getFilesDigestForB5Digest(ctx, bucketWithStorageMatcherApplied)
if err != nil {
return nil, err
}
if filesDigest.Type() != bufcas.DigestTypeShake256 {
if filesDigest.Type() != cas.DigestTypeShake256 {
return nil, syserror.Newf("trying to compute b5 Digest with files digest of type %v", filesDigest.Type())
}
// Next, we get the b5 digests of all the dependencies and sort their string representations.
Expand All @@ -359,7 +359,7 @@ func getB5DigestForBucketAndDepDigests(
// Now, place the file digest first, then the sorted dependency digests afterwards.
digestStrings := append([]string{filesDigest.String()}, depDigestStrings...)
// Join these strings together with newlines, and make a new shake256 digest.
digestOfDigests, err := bufcas.NewDigestForContent(strings.NewReader(strings.Join(digestStrings, "\n")))
digestOfDigests, err := cas.NewDigestForContent(strings.NewReader(strings.Join(digestStrings, "\n")))
if err != nil {
return nil, err
}
Expand All @@ -371,20 +371,20 @@ func getB5DigestForBucketAndDepDigests(
func getFilesDigestForB5Digest(
ctx context.Context,
bucketWithStorageMatcherApplied storage.ReadBucket,
) (bufcas.Digest, error) {
var fileNodes []bufcas.FileNode
) (cas.Digest, error) {
var fileNodes []cas.FileNode
if err := storage.WalkReadObjects(
ctx,
// This is extreme defensive programming. We've gone out of our way to make sure
// that the bucket is already filtered, but it's just too important to mess up here.
storage.FilterReadBucket(bucketWithStorageMatcherApplied, getStorageMatcher(ctx, bucketWithStorageMatcherApplied)),
"",
func(readObject storage.ReadObject) error {
digest, err := bufcas.NewDigestForContent(readObject)
digest, err := cas.NewDigestForContent(readObject)
if err != nil {
return err
}
fileNode, err := bufcas.NewFileNode(readObject.Path(), digest)
fileNode, err := cas.NewFileNode(readObject.Path(), digest)
if err != nil {
return err
}
Expand All @@ -394,9 +394,9 @@ func getFilesDigestForB5Digest(
); err != nil {
return nil, err
}
manifest, err := bufcas.NewManifest(fileNodes)
manifest, err := cas.NewManifest(fileNodes)
if err != nil {
return nil, err
}
return bufcas.ManifestToDigest(manifest)
return cas.ManifestToDigest(manifest)
}
2 changes: 1 addition & 1 deletion private/bufpkg/bufmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Module interface {

// Digest returns the Module digest for the given DigestType.
//
// Note this is *not* a bufcas.Digest - this is a Digest. bufcas.Digests are a lower-level
// Note this is *not* a cas.Digest - this is a Digest. cas.Digests are a lower-level
// type that just deal in terms of files and content. A Digest is a specific algorithm
// applied to a set of files and dependencies.
Digest(DigestType) (Digest, error)
Expand Down
2 changes: 1 addition & 1 deletion private/bufpkg/bufmodule/module_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ModuleKey interface {
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
// Note this is *not* a cas.Digest - this is a Digest. cas.Digests are a lower-level
// type that just deal in terms of files and content. A ModuleDigest is a specific algorithm
// applied to a set of files and dependencies.
Digest() (Digest, error)
Expand Down
6 changes: 3 additions & 3 deletions private/bufpkg/bufplugin/bufpluginapi/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"fmt"

pluginv1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/plugin/v1beta1"
"github.com/bufbuild/buf/private/bufpkg/bufcas"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/cas"
)

var (
Expand All @@ -37,11 +37,11 @@ func V1Beta1ProtoToDigest(protoDigest *pluginv1beta1.Digest) (bufplugin.Digest,
if err != nil {
return nil, err
}
bufcasDigest, err := bufcas.NewDigest(protoDigest.Value)
casDigest, err := cas.NewDigest(protoDigest.Value)
if err != nil {
return nil, err
}
return bufplugin.NewDigest(digestType, bufcasDigest)
return bufplugin.NewDigest(digestType, casDigest)
}

// *** PRIVATE ***
Expand Down
28 changes: 14 additions & 14 deletions private/bufpkg/bufplugin/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"strconv"
"strings"

"github.com/bufbuild/buf/private/bufpkg/bufcas"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/pkg/cas"
"github.com/bufbuild/buf/private/pkg/syserror"
)

Expand Down Expand Up @@ -96,17 +96,17 @@ type Digest interface {
}

// NewDigest creates a new Digest.
func NewDigest(digestType DigestType, bufcasDigest bufcas.Digest) (Digest, error) {
func NewDigest(digestType DigestType, casDigest cas.Digest) (Digest, error) {
switch digestType {
case DigestTypeP1:
if bufcasDigest.Type() != bufcas.DigestTypeShake256 {
if casDigest.Type() != cas.DigestTypeShake256 {
return nil, syserror.Newf(
"trying to create a %v Digest for a cas Digest of type %v",
digestType,
bufcasDigest.Type(),
casDigest.Type(),
)
}
return newDigest(digestType, bufcasDigest), nil
return newDigest(digestType, casDigest), nil
default:
// This is a system error.
return nil, syserror.Newf("unknown DigestType: %v", digestType)
Expand Down Expand Up @@ -152,11 +152,11 @@ func ParseDigest(s string) (Digest, error) {
}
switch digestType {
case DigestTypeP1:
bufcasDigest, err := bufcas.NewDigest(value)
casDigest, err := cas.NewDigest(value)
if err != nil {
return nil, err
}
return NewDigest(digestType, bufcasDigest)
return NewDigest(digestType, casDigest)
default:
return nil, syserror.Newf("unknown DigestType: %v", digestType)
}
Expand All @@ -183,19 +183,19 @@ func DigestEqual(a Digest, b Digest) bool {
/// *** PRIVATE ***

type digest struct {
digestType DigestType
bufcasDigest bufcas.Digest
digestType DigestType
casDigest cas.Digest
// Cache as we call String pretty often.
// We could do this lazily but not worth it.
stringValue string
}

// validation should occur outside of this function.
func newDigest(digestType DigestType, bufcasDigest bufcas.Digest) *digest {
func newDigest(digestType DigestType, casDigest cas.Digest) *digest {
return &digest{
digestType: digestType,
bufcasDigest: bufcasDigest,
stringValue: digestType.String() + ":" + hex.EncodeToString(bufcasDigest.Value()),
digestType: digestType,
casDigest: casDigest,
stringValue: digestType.String() + ":" + hex.EncodeToString(casDigest.Value()),
}
}

Expand All @@ -204,7 +204,7 @@ func (d *digest) Type() DigestType {
}

func (d *digest) Value() []byte {
return d.bufcasDigest.Value()
return d.casDigest.Value()
}

func (d *digest) String() string {
Expand Down
Loading