( imageFile bufimage.ImageFile, imageIndex *imageIndex, closure *transitiveClosure, options *imageFilterOptions, )
| 151 | } |
| 152 | |
| 153 | func 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(), |
no test coverage detected
searching dependent graphs…