summaryrefslogtreecommitdiffstats
path: root/vendor/gix-traverse/src/tree
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/gix-traverse/src/tree
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-traverse/src/tree')
-rw-r--r--vendor/gix-traverse/src/tree/breadthfirst.rs53
1 files changed, 23 insertions, 30 deletions
diff --git a/vendor/gix-traverse/src/tree/breadthfirst.rs b/vendor/gix-traverse/src/tree/breadthfirst.rs
index 115b9a396..bb5b3f7d2 100644
--- a/vendor/gix-traverse/src/tree/breadthfirst.rs
+++ b/vendor/gix-traverse/src/tree/breadthfirst.rs
@@ -6,8 +6,8 @@ use gix_hash::ObjectId;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
- #[error("The tree {oid} could not be found")]
- NotFound { oid: ObjectId },
+ #[error(transparent)]
+ Find(#[from] gix_object::find::existing_iter::Error),
#[error("The delegate cancelled the operation")]
Cancelled,
#[error(transparent)]
@@ -31,8 +31,7 @@ impl State {
pub(crate) mod impl_ {
use std::borrow::BorrowMut;
- use gix_hash::oid;
- use gix_object::{tree::EntryMode, TreeRefIter};
+ use gix_object::{FindExt, TreeRefIter};
use super::{Error, State};
use crate::tree::Visit;
@@ -46,17 +45,17 @@ pub(crate) mod impl_ {
/// * `find` - a way to lookup new object data during traversal by their `ObjectId`, writing their data into buffer and returning
/// an iterator over entries if the object is present and is a tree. Caching should be implemented within this function
/// as needed. The return value is `Option<TreeIter>` which degenerates all error information. Not finding a commit should also
- /// be considered an errors as all objects in the tree DAG should be present in the database. Hence [`Error::NotFound`] should
+ /// be considered an errors as all objects in the tree DAG should be present in the database. Hence [`Error::Find`] should
/// be escalated into a more specific error if its encountered by the caller.
/// * `delegate` - A way to observe entries and control the iteration while allowing the optimizer to let you pay only for what you use.
pub fn traverse<StateMut, Find, V>(
root: TreeRefIter<'_>,
mut state: StateMut,
- mut find: Find,
+ objects: Find,
delegate: &mut V,
) -> Result<(), Error>
where
- Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<TreeRefIter<'a>>,
+ Find: gix_object::Find,
StateMut: BorrowMut<State>,
V: Visit,
{
@@ -66,39 +65,33 @@ pub(crate) mod impl_ {
loop {
for entry in tree {
let entry = entry?;
- match entry.mode {
- EntryMode::Tree => {
- use crate::tree::visit::Action::*;
- delegate.push_path_component(entry.filename);
- let action = delegate.visit_tree(&entry);
- match action {
- Skip => {}
- Continue => {
- delegate.pop_path_component();
- delegate.push_back_tracked_path_component(entry.filename);
- state.next.push_back(entry.oid.to_owned())
- }
- Cancel => {
- return Err(Error::Cancelled);
- }
+ if entry.mode.is_tree() {
+ use crate::tree::visit::Action::*;
+ delegate.push_path_component(entry.filename);
+ let action = delegate.visit_tree(&entry);
+ match action {
+ Skip => {}
+ Continue => {
+ delegate.pop_path_component();
+ delegate.push_back_tracked_path_component(entry.filename);
+ state.next.push_back(entry.oid.to_owned())
}
- }
- _non_tree => {
- delegate.push_path_component(entry.filename);
- if delegate.visit_nontree(&entry).cancelled() {
+ Cancel => {
return Err(Error::Cancelled);
}
}
+ } else {
+ delegate.push_path_component(entry.filename);
+ if delegate.visit_nontree(&entry).cancelled() {
+ return Err(Error::Cancelled);
+ }
}
delegate.pop_path_component();
}
match state.next.pop_front() {
Some(oid) => {
delegate.pop_front_tracked_path_and_set_current();
- match find(&oid, &mut state.buf) {
- Some(tree_iter) => tree = tree_iter,
- None => return Err(Error::NotFound { oid: oid.to_owned() }),
- }
+ tree = objects.find_tree_iter(&oid, &mut state.buf)?;
}
None => break Ok(()),
}