Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable committed Dec 3, 2024
1 parent fbdc7dc commit d2753d2
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions private/bufpkg/bufimage/bufimageutil/bufimageutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,27 @@ func ImageFilteredByTypesWithOptions(image bufimage.Image, types []string, opts
// Only handle imports and dependencies if there are any.
for indexFrom, importPath := range imageFileDescriptor.GetDependency() {
path := append(basePath, int32(indexFrom))
// If there are no required imports, we mark this as deleted.
if importsRequired == nil {
sourcePathRemapper.markDeleted(path)
// We check if the import path exists among required imports. If yes, we
// move and then delete from required imports as we go.
if importsRequired != nil && importsRequired.index(importPath) != -1 {
sourcePathRemapper.markMoved(path, int32(indexTo))
indexFromTo[int32(indexFrom)] = int32(indexTo)
imageFileDescriptor.Dependency[indexTo] = importPath
indexTo++
// delete them as we go, so we know which ones weren't in the list
importsRequired.delete(importPath)
} else {
// Otherwise, we check if the import path exists among required imports. If yes, we
// move and then delete from required imports as we go.
if i := importsRequired.index(importPath); i != -1 {
sourcePathRemapper.markMoved(path, int32(indexTo))
indexFromTo[int32(indexFrom)] = int32(indexTo)
imageFileDescriptor.Dependency[indexTo] = importPath
indexTo++
// delete them as we go, so we know which ones weren't in the list
importsRequired.delete(importPath)
} else {
// Path did not exist in required imports, we mark as deleted.
sourcePathRemapper.markDeleted(path)
}
// Path did not exist in required imports, we mark as deleted.
sourcePathRemapper.markDeleted(path)
}
}
imageFileDescriptor.Dependency = imageFileDescriptor.Dependency[:indexTo]

// Add any other imports (which may not have been in the list because
// they were picked up via a public import). The filtered files will not
// use public imports.
// The imports are added in the order they are encountered when importing
// to maintain a deterministic ordering.
if importsRequired != nil {
imageFileDescriptor.Dependency = append(imageFileDescriptor.Dependency, importsRequired.keys()...)
}
Expand Down

0 comments on commit d2753d2

Please sign in to comment.