From 3b09063e4f2cc123be38b0ea79c3b84390f4f865 Mon Sep 17 00:00:00 2001 From: Edward McFarlane <3036610+emcfarlane@users.noreply.github.com> Date: Mon, 11 Dec 2023 10:09:26 -0500 Subject: [PATCH] Add GetFileNode to bufcas.Manifest (#2648) 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. --- private/bufpkg/bufcas/manifest.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/private/bufpkg/bufcas/manifest.go b/private/bufpkg/bufcas/manifest.go index 647c23a78d..a8146e6296 100644 --- a/private/bufpkg/bufcas/manifest.go +++ b/private/bufpkg/bufcas/manifest.go @@ -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. @@ -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()