Manifest.Range: iterate entries (path, digest)#1966
Merged
unmultimedio merged 8 commits intomainfrom Apr 3, 2023
Merged
Conversation
pkwarren
reviewed
Mar 31, 2023
private/pkg/manifest/manifest.go
Outdated
| // IteratePaths invokes a function for all the paths in the manifest, passing | ||
| // the path and its digest. The order in which the paths are iterated is not | ||
| // guaranteed. | ||
| func (m *Manifest) IteratePaths(f func(string, Digest)) { |
Member
There was a problem hiding this comment.
The paths function doesn't look too expensive - why are we introducing this variant? Is it to return the pre-calculated digest for each path?
Member
Author
There was a problem hiding this comment.
Is not because of how expensive it is, but because we have some code paths in which we want the digests, not only the paths, so we can drop unnecessary presence checkers. I'll change a few of the code paths in this same PR as well to make it more clear.
unmultimedio
commented
Apr 3, 2023
Comment on lines
-72
to
-75
| digest, found := manifestFromCache.DigestFor(path) | ||
| if !found { | ||
| return nil, fmt.Errorf("digest not found for path: %s", path) | ||
| } |
Member
Author
There was a problem hiding this comment.
This is the check we're skipping with the new func.
| // Range invokes a function for all the paths in the manifest, passing the path | ||
| // and its digest. The order in which the paths are iterated is not guaranteed. | ||
| // This func will stop iterating if an error is returned. | ||
| func (m *Manifest) Range(f func(path string, digest Digest) error) error { |
Member
Author
There was a problem hiding this comment.
Renaming func to follow suggestion in this comment. cc @jhump
saquibmian
reviewed
Apr 3, 2023
Co-authored-by: Saquib Mian <smian@buf.build>
pkwarren
approved these changes
Apr 3, 2023
Monirul1
pushed a commit
to Monirul1/buf
that referenced
this pull request
Apr 30, 2023
Range function for the manifest entries, so we can reduce the
appearances of `.Paths()` usages like:
```go
for _, path := range m.Paths() {
digest, ok := m.DigestFor(path)
if !ok {
// this will never happen
return nil, fmt.Errorf("digest not found for path: %s", path)
}
// do something with path and digest...
}
```
into:
```go
m.Range(func(path string, digest manifest.Digest) error {
// do something with path and digest...
})
```
---------
Co-authored-by: Saquib Mian <smian@buf.build>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Range function for the manifest entries, so we can reduce the appearances of
.Paths()usages like:into: