Skip to content
Snippets Groups Projects

catfile: Introduce request queues to allow batching reads

Merged Patrick Steinhardt requested to merge pks-catfile-queue into master
1 unresolved thread
1 file
+ 4
5
Compare changes
  • Side-by-side
  • Inline
  • 8768074a
    When retrieving tree entries via the tree entries helper, then we
    request an object, parse it and then recursively parse its children in
    case it is a tree object. When the object is not a tree, then we discard
    its contents via a deferred call and exit early. Otherwise, if it is a
    tree, we'd still try to discard the tree object _after_ we have parsed
    all of its children. This is invalid though given that objects returned
    by the catfile package cannot be read in arbitrary order, but instead
    they must always be fully read before trying to read the next object.
    Discarding contents at the end thus cannot work as expected.
    
    Fix the bug by explicitly discarding the object in case it's not a tree.
    In the other case, where it is a tree, we'll pass the reader to
    `extractEntryInfoFromTreeData()`: this function either returns an error
    in case we're unable to parse the tree, or otherwise it has fully
    consumed the tree object. Discarding it is thus not necessary in that
    case.
    
    Changelog: fixed
@@ -143,16 +143,15 @@ func treeEntries(
}
return nil, err
}
defer func() {
if _, err := io.Copy(io.Discard, treeObj); err != nil && returnedErr == nil {
returnedErr = fmt.Errorf("discarding object: %w", err)
}
}()
// The tree entry may not refer to a subtree, but instead to a blob. Historically, we have
// simply ignored such objects altogether and didn't return an error, so we keep the same
// behaviour.
if treeObj.Type != "tree" {
if _, err := io.Copy(io.Discard, treeObj); err != nil && returnedErr == nil {
return nil, fmt.Errorf("discarding object: %w", err)
}
return nil, nil
}
Loading