MCPcopy Create free account
hub / github.com/bufbuild/buf / newImage

Function newImage

private/bufpkg/bufimage/image.go:35–88  ·  view source on GitHub ↗
(files []ImageFile, reorder bool, resolver protoencoding.Resolver)

Source from the content-addressed store, hash-verified

33}
34
35func newImage(files []ImageFile, reorder bool, resolver protoencoding.Resolver) (*image, error) {
36 if len(files) == 0 {
37 return nil, errors.New("image contains no files")
38 }
39 pathToImageFile := make(map[string]ImageFile, len(files))
40 type commitIDAndFilePath struct {
41 commitID uuid.UUID
42 filePath string
43 }
44 moduleFullNameStringToCommitIDAndFilePath := make(map[string]commitIDAndFilePath)
45 for _, file := range files {
46 path := file.Path()
47 if _, ok := pathToImageFile[path]; ok {
48 return nil, fmt.Errorf("duplicate file: %s", path)
49 }
50 pathToImageFile[path] = file
51 if moduleFullName := file.FullName(); moduleFullName != nil {
52 moduleFullNameString := moduleFullName.String()
53 existing, ok := moduleFullNameStringToCommitIDAndFilePath[moduleFullNameString]
54 if ok {
55 if existing.commitID != file.CommitID() {
56 return nil, fmt.Errorf(
57 "files with different commits for the same module %s: %s:%s and %s:%s",
58 moduleFullNameString,
59 existing.filePath,
60 uuidutil.ToDashless(existing.commitID),
61 path,
62 uuidutil.ToDashless(file.CommitID()),
63 )
64 }
65 } else {
66 moduleFullNameStringToCommitIDAndFilePath[moduleFullNameString] = commitIDAndFilePath{
67 commitID: file.CommitID(),
68 filePath: path,
69 }
70 }
71 }
72 }
73 if reorder {
74 files = orderImageFiles(files, pathToImageFile)
75 }
76 if resolver == nil {
77 fileDescriptorProtos := make([]*descriptorpb.FileDescriptorProto, len(files))
78 for i := range files {
79 fileDescriptorProtos[i] = files[i].FileDescriptorProto()
80 }
81 resolver = protoencoding.NewLazyResolver(fileDescriptorProtos...)
82 }
83 return &image{
84 files: files,
85 pathToImageFile: pathToImageFile,
86 resolver: resolver,
87 }, nil
88}
89
90func newImageNoValidate(files []ImageFile, resolver protoencoding.Resolver) *image {
91 pathToImageFile := make(map[string]ImageFile, len(files))

Callers 3

NewImageFunction · 0.85
NewImageForProtoFunction · 0.85
fileDescriptorSetToImageFunction · 0.85

Calls 8

ToDashlessFunction · 0.92
NewLazyResolverFunction · 0.92
orderImageFilesFunction · 0.85
PathMethod · 0.65
FullNameMethod · 0.65
StringMethod · 0.65
CommitIDMethod · 0.65
FileDescriptorProtoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…