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

Function filterImageFile

private/bufpkg/bufimage/bufimageutil/image_filter.go:153–214  ·  view source on GitHub ↗
(
	imageFile bufimage.ImageFile,
	imageIndex *imageIndex,
	closure *transitiveClosure,
	options *imageFilterOptions,
)

Source from the content-addressed store, hash-verified

151}
152
153func filterImageFile(
154 imageFile bufimage.ImageFile,
155 imageIndex *imageIndex,
156 closure *transitiveClosure,
157 options *imageFilterOptions,
158) (bufimage.ImageFile, error) {
159 fileDescriptor := imageFile.FileDescriptorProto()
160 var sourcePathsRemap sourcePathsRemapTrie
161 builder := sourcePathsBuilder{
162 imageIndex: imageIndex,
163 closure: closure,
164 options: options,
165 }
166 newFileDescriptor, changed, err := builder.remapFileDescriptor(&sourcePathsRemap, fileDescriptor)
167 if err != nil {
168 return nil, err
169 }
170 if newFileDescriptor == nil {
171 return nil, nil // Filtered out.
172 }
173 if !changed {
174 if len(sourcePathsRemap) > 0 {
175 return nil, syserror.Newf("unexpected %d sourcePathsRemaps", len(sourcePathsRemap))
176 }
177 return imageFile, nil // No changes required.
178 }
179
180 // Remap the source code info.
181 if locations := fileDescriptor.SourceCodeInfo.GetLocation(); len(locations) > 0 {
182 newLocations := make([]*descriptorpb.SourceCodeInfo_Location, 0, len(locations))
183 for _, location := range locations {
184 oldPath := location.Path
185 newPath, noComment := sourcePathsRemap.newPath(oldPath)
186 if newPath == nil {
187 continue
188 }
189 if noComment || !slices.Equal(oldPath, newPath) {
190 location = maybeClone(location, options)
191 location.Path = newPath
192 }
193 if noComment {
194 location.LeadingDetachedComments = nil
195 location.LeadingComments = nil
196 location.TrailingComments = nil
197 }
198 newLocations = append(newLocations, location)
199 }
200 newFileDescriptor.SourceCodeInfo = &descriptorpb.SourceCodeInfo{
201 Location: newLocations,
202 }
203 }
204 return bufimage.NewImageFile(
205 newFileDescriptor,
206 imageFile.FullName(),
207 imageFile.CommitID(),
208 imageFile.ExternalPath(),
209 imageFile.LocalPath(),
210 imageFile.IsImport(),

Callers 1

filterImageFunction · 0.85

Calls 13

remapFileDescriptorMethod · 0.95
newPathMethod · 0.95
NewfFunction · 0.92
NewImageFileFunction · 0.92
maybeCloneFunction · 0.85
FileDescriptorProtoMethod · 0.65
FullNameMethod · 0.65
CommitIDMethod · 0.65
ExternalPathMethod · 0.65
LocalPathMethod · 0.65
IsImportMethod · 0.65
IsSyntaxUnspecifiedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…