Skip to content

Commit

Permalink
Add GetFileNode to bufcas.Manifest (#2648)
Browse files Browse the repository at this point in the history
Adds a method to retrieve the `FileNode` by path on a `Manifest`.
Currently if trying to retrieve the `FileNode` one must call
`FileNodes()` and iterate over all to lookup by path.
  • Loading branch information
emcfarlane authored Dec 11, 2023
1 parent b06ab38 commit 3b09063
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions private/bufpkg/bufcas/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type Manifest interface {
// The paths of the given FileNodes are guaranteed to be unique.
// The iteration order will be the sorted order of the paths.
FileNodes() []FileNode
// GetFileNode gets the FileNode for the given path.
//
// Returns nil if the path does not exist.
GetFileNode(path string) FileNode
// GetDigest gets the Digest for the given path.
//
// Returns nil if the path does not exist.
Expand Down Expand Up @@ -151,9 +155,13 @@ func (m *manifest) FileNodes() []FileNode {
return m.sortedUniqueFileNodes
}

func (m *manifest) GetFileNode(path string) FileNode {
return m.pathToFileNode[path]
}

func (m *manifest) GetDigest(path string) Digest {
fileNode, ok := m.pathToFileNode[path]
if !ok {
fileNode := m.GetFileNode(path)
if fileNode == nil {
return nil
}
return fileNode.Digest()
Expand Down

0 comments on commit 3b09063

Please sign in to comment.