Skip to content

Commit

Permalink
feat: add tree::Editor|editor::Cursor::get() to see if an entry is …
Browse files Browse the repository at this point in the history
…loaded at path.

This can be useful to get a feeling for how far the tree was already made available,
even though it won't reveal if an entry was edited.
  • Loading branch information
Byron committed Jan 4, 2025
1 parent c6340c7 commit 562bd78
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gix/src/object/tree/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ impl<'repo> Cursor<'_, 'repo> {
pub fn write(&mut self) -> Result<Id<'repo>, write::Error> {
write_cursor(self)
}

/// Obtain the entry at `rela_path` or return `None` if none was found, or the tree wasn't yet written
/// to that point.
/// The root tree is always available.
/// Note that after [writing](Self::write) only the root path remains, all other intermediate trees are removed.
/// The entry can be anything that can be stored in a tree, but may have a null-id if it's a newly
/// inserted tree. Also, ids of trees might not be accurate as they may have been changed in memory.
pub fn get(&self, rela_path: impl ToComponents) -> Option<crate::object::tree::EntryRef<'repo, '_>> {
self.inner
.get(rela_path.to_components())
.map(|entry| crate::object::tree::EntryRef {
inner: entry.into(),
repo: self.repo,
})
}
}

/// Operations
Expand Down Expand Up @@ -242,6 +257,21 @@ impl<'repo> super::Editor<'repo> {
pub fn write(&mut self) -> Result<Id<'repo>, write::Error> {
write_cursor(&mut self.to_cursor())
}

/// Obtain the entry at `rela_path` or return `None` if none was found, or the tree wasn't yet written
/// to that point.
/// The root tree is always available.
/// Note that after [writing](Self::write) only the root path remains, all other intermediate trees are removed.
/// The entry can be anything that can be stored in a tree, but may have a null-id if it's a newly
/// inserted tree. Also, ids of trees might not be accurate as they may have been changed in memory.
pub fn get(&self, rela_path: impl ToComponents) -> Option<crate::object::tree::EntryRef<'repo, '_>> {
self.inner
.get(rela_path.to_components())
.map(|entry| crate::object::tree::EntryRef {
inner: entry.into(),
repo: self.repo,
})
}
}

fn write_cursor<'repo>(cursor: &mut Cursor<'_, 'repo>) -> Result<Id<'repo>, write::Error> {
Expand Down

0 comments on commit 562bd78

Please sign in to comment.