Skip to content

Commit

Permalink
Merge branch 'improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 22, 2024
2 parents 6990afd + ba72ee0 commit 9ed2b24
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
17 changes: 12 additions & 5 deletions gix/src/reference/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Platform<'r> {
/// An iterator over references, with or without filter.
pub struct Iter<'r> {
inner: gix_ref::file::iter::LooseThenPacked<'r, 'r>,
peel_with_packed: Option<gix_ref::file::packed::SharedBufferSnapshot>,
peel: bool,
repo: &'r crate::Repository,
}
Expand All @@ -22,6 +23,7 @@ impl<'r> Iter<'r> {
fn new(repo: &'r crate::Repository, platform: gix_ref::file::iter::LooseThenPacked<'r, 'r>) -> Self {
Iter {
inner: platform,
peel_with_packed: None,
peel: false,
repo,
}
Expand Down Expand Up @@ -80,9 +82,10 @@ impl<'r> Iter<'r> {
///
/// Doing this is necessary as the packed-refs buffer is already held by the iterator, disallowing the consumer of the iterator
/// to peel the returned references themselves.
pub fn peeled(mut self) -> Self {
pub fn peeled(mut self) -> Result<Self, gix_ref::packed::buffer::open::Error> {
self.peel_with_packed = self.repo.refs.cached_packed_buffer()?;
self.peel = true;
self
Ok(self)
}
}

Expand All @@ -95,9 +98,13 @@ impl<'r> Iterator for Iter<'r> {
.and_then(|mut r| {
if self.peel {
let repo = &self.repo;
r.peel_to_id_in_place(&repo.refs, &repo.objects)
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)
.map(|_| r)
r.peel_to_id_in_place_packed(
&repo.refs,
&repo.objects,
self.peel_with_packed.as_ref().map(|p| &***p),
)
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)
.map(|_| r)
} else {
Ok(r)
}
Expand Down
2 changes: 1 addition & 1 deletion gix/src/remote/connection/fetch/negotiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn mark_all_refs_in_repo(
mark: Flags,
) -> Result<(), Error> {
let _span = gix_trace::detail!("mark_all_refs");
for local_ref in repo.references()?.all()?.peeled() {
for local_ref in repo.references()?.all()?.peeled()? {
let local_ref = local_ref?;
let id = local_ref.id().detach();
let mut is_complete = false;
Expand Down
1 change: 1 addition & 0 deletions gix/src/revision/spec/parse/delegate/navigate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl<'repo> delegate::Navigate for Delegate<'repo> {
.rev_walk(
references
.peeled()
.ok()?
.filter_map(Result::ok)
.filter(|r| r.id().header().ok().map_or(false, |obj| obj.kind().is_commit()))
.filter_map(|r| r.detach().peeled),
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/repository/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod iter_references {
assert_eq!(
repo.references()?
.prefixed("refs/heads/")?
.peeled()
.peeled()?
.filter_map(Result::ok)
.map(|r| (
r.name().as_bstr().to_string(),
Expand Down

0 comments on commit 9ed2b24

Please sign in to comment.