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

Function NewImageForProto

private/bufpkg/bufimage/bufimage.go:351–418  ·  view source on GitHub ↗

NewImageForProto returns a new Image for the given proto Image. The input Files are expected to be in correct DAG order! TODO FUTURE: Consider checking the above, and if not, reordering the Files. TODO FUTURE: do we want to add the ability to do external path resolution here?

(protoImage *imagev1.Image, options ...NewImageForProtoOption)

Source from the content-addressed store, hash-verified

349//
350// TODO FUTURE: do we want to add the ability to do external path resolution here?
351func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOption) (Image, error) {
352 var newImageOptions newImageForProtoOptions
353 for _, option := range options {
354 option(&newImageOptions)
355 }
356 if newImageOptions.noReparse && newImageOptions.computeUnusedImports {
357 return nil, fmt.Errorf("cannot use both WithNoReparse and WithComputeUnusedImports options; they are mutually exclusive")
358 }
359 // TODO FUTURE: right now, NewResolver sets AllowUnresolvable to true all the time
360 // we want to make this into a check, and we verify if we need this for the individual command
361 resolver := protoencoding.NewLazyResolver(protoImage.GetFile()...)
362 if !newImageOptions.noReparse {
363 if err := reparseImageProto(protoImage, resolver, newImageOptions.computeUnusedImports); err != nil {
364 return nil, err
365 }
366 }
367 if err := validateProtoImage(protoImage); err != nil {
368 return nil, err
369 }
370 imageFiles := make([]ImageFile, len(protoImage.GetFile()))
371 for i, protoImageFile := range protoImage.GetFile() {
372 var isImport bool
373 var isSyntaxUnspecified bool
374 var unusedDependencyIndexes []int32
375 var moduleFullName bufparse.FullName
376 var commitID uuid.UUID
377 var err error
378 if protoImageFileExtension := protoImageFile.GetBufExtension(); protoImageFileExtension != nil {
379 isImport = protoImageFileExtension.GetIsImport()
380 isSyntaxUnspecified = protoImageFileExtension.GetIsSyntaxUnspecified()
381 unusedDependencyIndexes = protoImageFileExtension.GetUnusedDependency()
382 if protoModuleInfo := protoImageFileExtension.GetModuleInfo(); protoModuleInfo != nil {
383 if protoModuleName := protoModuleInfo.GetName(); protoModuleName != nil {
384 moduleFullName, err = bufparse.NewFullName(
385 protoModuleName.GetRemote(),
386 protoModuleName.GetOwner(),
387 protoModuleName.GetRepository(),
388 )
389 if err != nil {
390 return nil, err
391 }
392 // we only want to set this if there is a module name
393 if protoCommitID := protoModuleInfo.GetCommit(); protoCommitID != "" {
394 commitID, err = uuidutil.FromDashless(protoCommitID)
395 if err != nil {
396 return nil, err
397 }
398 }
399 }
400 }
401 }
402 imageFile, err := NewImageFile(
403 protoImageFile,
404 moduleFullName,
405 commitID,
406 protoImageFile.GetName(),
407 "",
408 isImport,

Callers 6

runFilterImageFunction · 0.92
TestBasicFunction · 0.92
getImageForMessageRefMethod · 0.92
TestCloneImageFunction · 0.85

Calls 15

NewLazyResolverFunction · 0.92
NewFullNameFunction · 0.92
FromDashlessFunction · 0.92
optionStruct · 0.85
reparseImageProtoFunction · 0.85
validateProtoImageFunction · 0.85
newImageFunction · 0.85
GetBufExtensionMethod · 0.80
GetIsImportMethod · 0.80
GetUnusedDependencyMethod · 0.80
NewImageFileFunction · 0.70

Tested by 4

runFilterImageFunction · 0.74
TestBasicFunction · 0.74
TestCloneImageFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…