pub struct Tree<'repo> { /* private fields */ }
Expand description
A structure to represent a git tree
Implementations§
source§impl<'repo> Tree<'repo>
impl<'repo> Tree<'repo>
sourcepub fn walk<C, T>(&self, mode: TreeWalkMode, callback: C) -> Result<(), Error>
pub fn walk<C, T>(&self, mode: TreeWalkMode, callback: C) -> Result<(), Error>
Traverse the entries in a tree and its subtrees in post or pre-order. The callback function will be run on each node of the tree that’s walked. The return code of this function will determine how the walk continues.
libgit2 requires that the callback be an integer, where 0 indicates a
successful visit, 1 skips the node, and -1 aborts the traversal completely.
You may opt to use the enum TreeWalkResult
instead.
let mut ct = 0;
tree.walk(TreeWalkMode::PreOrder, |_, entry| {
assert_eq!(entry.name(), Some("foo"));
ct += 1;
TreeWalkResult::Ok
}).unwrap();
assert_eq!(ct, 1);
See libgit2 documentation for more information.
sourcepub fn get(&self, n: usize) -> Option<TreeEntry<'_>>
pub fn get(&self, n: usize) -> Option<TreeEntry<'_>>
Lookup a tree entry by its position in the tree
sourcepub fn get_name(&self, filename: &str) -> Option<TreeEntry<'_>>
pub fn get_name(&self, filename: &str) -> Option<TreeEntry<'_>>
Lookup a tree entry by its filename
sourcepub fn get_name_bytes(&self, filename: &[u8]) -> Option<TreeEntry<'_>>
pub fn get_name_bytes(&self, filename: &[u8]) -> Option<TreeEntry<'_>>
Lookup a tree entry by its filename, specified as bytes.
This allows for non-UTF-8 filenames.
sourcepub fn get_path(&self, path: &Path) -> Result<TreeEntry<'static>, Error>
pub fn get_path(&self, path: &Path) -> Result<TreeEntry<'static>, Error>
Retrieve a tree entry contained in a tree or in any of its subtrees, given its relative path.
sourcepub fn into_object(self) -> Object<'repo>
pub fn into_object(self) -> Object<'repo>
Consumes this Tree to be returned as an Object