- add docs - naming
Unified · Split
| @@ -9,11 +9,11 @@ use crate::{ · 8 unmodified lines | |||
| 9 | pub mod editor; | 9 | pub mod editor; |
| 10 | 10 | ||
| 11 | mod ref_iter; | 11 | mod ref_iter; |
| 12 | pub use ref_iter::next_entry; | ||
| 13 | |||
| 12 | /// | 14 | /// |
| 13 | pub mod write; | 15 | pub mod write; |
| 14 | 16 | ||
| 15 | pub use ref_iter::iter_next; | ||
| 16 | |||
| 17 | /// The state needed to apply edits instantly to in-memory trees. | 17 | /// The state needed to apply edits instantly to in-memory trees. |
| 18 | /// | 18 | /// |
| 19 | /// It's made so that each tree is looked at in the object database at most once, and held in memory for | 19 | /// It's made so that each tree is looked at in the object database at most once, and held in memory for |
| @@ -5,8 +5,25 @@ use winnow::{error::ParserError, prelude::*}; · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | use crate::{tree, tree::EntryRef, TreeRef, TreeRefIter}; | 6 | use crate::{tree, tree::EntryRef, TreeRef, TreeRefIter}; |
| 7 | 7 | ||
| 8 | /// Yes | 8 | /// Advance a path lookup by matching the next path component against `tree`. |
| 9 | pub fn iter_next<'a, I, P>( | 9 | /// |
| 10 | /// `components` must yield the remaining path components to resolve, and `tree` must be the | ||
| 11 | /// current object to search in. | ||
| 12 | /// | ||
| 13 | /// The return value indicates how the caller should proceed: | ||
| 14 | /// | ||
| 15 | /// - [`ControlFlow::Continue`] contains the object id of the matched entry when there are more | ||
| 16 | /// components left to resolve. Callers should load that object and pass it back into a subsequent | ||
| 17 | /// invocation. | ||
| 18 | /// - [`ControlFlow::Break`]`(Some(entry))` contains the matched entry for the final component, and | ||
| 19 | /// signals that lookup completed successfully. | ||
| 20 | /// - [`ControlFlow::Break`]`(None)` signals that lookup cannot continue and should stop without a | ||
| 21 | /// match. This happens if `tree` is not a tree object, if `components` is already exhausted, or if | ||
| 22 | /// the next component is not present in `tree`. | ||
| 23 | /// | ||
| 24 | /// Note that this behaviour is tuned to prefer to exhaust the entire chain of `components`, only the | ||
| 25 | /// last component can yield a [`ControlFlow::Break`]. | ||
| 26 | pub fn next_entry<'a, I, P>( | ||
| 10 | components: &mut core::iter::Peekable<I>, | 27 | components: &mut core::iter::Peekable<I>, |
| 11 | tree: crate::Data<'a>, | 28 | tree: crate::Data<'a>, |
| 12 | ) -> core::ops::ControlFlow<Option<EntryRef<'a>>, gix_hash::ObjectId> | 29 | ) -> core::ops::ControlFlow<Option<EntryRef<'a>>, gix_hash::ObjectId> |
| @@ -67,7 +84,7 @@ impl<'a> TreeRefIter<'a> { · 54 unmodified lines | |||
| 67 | let mut data = crate::Data::new(crate::Kind::Tree, buffer); | 84 | let mut data = crate::Data::new(crate::Kind::Tree, buffer); |
| 68 | 85 | ||
| 69 | loop { | 86 | loop { |
| 70 | data = match iter_next(&mut iter, data) { | 87 | data = match next_entry(&mut iter, data) { |
| 71 | ControlFlow::Continue(oid) => { | 88 | ControlFlow::Continue(oid) => { |
| 72 | let Some(next_tree) = odb.try_find(&oid, buffer)? else { | 89 | let Some(next_tree) = odb.try_find(&oid, buffer)? else { |
| 73 | break Ok(None); | 90 | break Ok(None); |
| @@ -2,7 +2,7 @@ use std::ops::ControlFlow; · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | use gix_hash::ObjectId; | 3 | use gix_hash::ObjectId; |
| 4 | pub use gix_object::tree::{EntryKind, EntryMode}; | 4 | pub use gix_object::tree::{EntryKind, EntryMode}; |
| 5 | use gix_object::{bstr::BStr, tree::iter_next, FindExt, TreeRefIter}; | 5 | use gix_object::{bstr::BStr, tree::next_entry, FindExt, TreeRefIter}; |
| 6 | 6 | ||
| 7 | use crate::{object::find, Id, ObjectDetached, Repository, Tree}; | 7 | use crate::{object::find, Id, ObjectDetached, Repository, Tree}; |
| 8 | 8 | ||
| @@ -72,7 +72,7 @@ impl<'repo> Tree<'repo> { · 63 unmodified lines | |||
| 72 | let mut data = gix_object::Data::new(gix_object::Kind::Tree, buf); | 72 | let mut data = gix_object::Data::new(gix_object::Kind::Tree, buf); |
| 73 | 73 | ||
| 74 | loop { | 74 | loop { |
| 75 | data = match iter_next(&mut iter, data) { | 75 | data = match next_entry(&mut iter, data) { |
| 76 | ControlFlow::Continue(oid) => self.repo.find(&oid, buf)?, | 76 | ControlFlow::Continue(oid) => self.repo.find(&oid, buf)?, |
| 77 | ControlFlow::Break(entry) => { | 77 | ControlFlow::Break(entry) => { |
| 78 | let mapped = entry.map(|e| Entry { | 78 | let mapped = entry.map(|e| Entry { |
| @@ -106,10 +106,11 @@ impl<'repo> Tree<'repo> { · 27 unmodified lines | |||
| 106 | let mut data = gix_object::Data::new(gix_object::Kind::Tree, &self.data); | 106 | let mut data = gix_object::Data::new(gix_object::Kind::Tree, &self.data); |
| 107 | 107 | ||
| 108 | loop { | 108 | loop { |
| 109 | data = match iter_next(&mut iter, data) { | 109 | data = match next_entry(&mut iter, data) { |
| 110 | ControlFlow::Continue(oid) => { | 110 | ControlFlow::Continue(oid) => { |
| 111 | let res = self.repo.find(&oid, &mut self.data)?; | ||
| 111 | self.id = oid; | 112 | self.id = oid; |
| 112 | self.repo.find(&oid, &mut self.data)? | 113 | res |
| 113 | } | 114 | } |
| 114 | ControlFlow::Break(entry) => { | 115 | ControlFlow::Break(entry) => { |
| 115 | let repo = self.repo; | 116 | let repo = self.repo; |