Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff correctness #1106

Merged
merged 20 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1838cbd
feat: support for querying only the header of an object with the `Fin…
Byron Nov 18, 2023
336d161
adapt to changes in `gix-object` (Find::try_header())
Byron Nov 18, 2023
ee47fba
fix: specify minimum required `url` version of v2.2.0 (#1119).
Byron Nov 17, 2023
86cdb42
feat: Add `Buffers` type.
Byron Nov 17, 2023
1ed74f7
use `Buffers` implementation from `gix-utils`
Byron Nov 17, 2023
c752f67
fix: Use `gix-objet::Find` error type.
Byron Nov 13, 2023
c74c7fe
feat!: simplify `Pipeline::new()` by reomving the metadata collection.
Byron Nov 15, 2023
7d754cc
more correct initialization order for new attribute search outcomes.
Byron Nov 15, 2023
1763862
adapt to changes in `gix-filter`
Byron Nov 15, 2023
0f03a08
feat: Allow obtaining mutable pipeline buffers.
Byron Nov 17, 2023
552bed2
feat!: Use `&dyn gix_object::Find` where possible.
Byron Nov 18, 2023
a0e4dec
adapt to changes in `gix-worktree`
Byron Nov 18, 2023
20e56b3
feat: add `Oid::is_null()` - previously it was only available on `Obj…
Byron Nov 27, 2023
ebe66db
feat: add `blob::Platform` and `blob::Pipeline` for diff-content conv…
Byron Nov 13, 2023
feca5d0
feat!: rewrite-tracker now uses blob diff-platform for correct and op…
Byron Nov 28, 2023
4aea9b0
feat: add the`diff::resource_cache()` low-level utility for rapid in-…
Byron Nov 28, 2023
6f4bbc3
feat: add key for `diff.external`.
Byron Dec 2, 2023
406acef
Allow empty paths to be passed to Stack in debug mode
Byron Dec 2, 2023
4743212
feat!: `object::blob::diff::Platform` now performs all necessary conv…
Byron Dec 2, 2023
1706e23
adapt to changes in `gix-diff`
Byron Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: support for querying only the header of an object with the `Fin…
…dHeader` trait.

That way one can know its decompressed size and its kind.

We also add a `FindObjectOrHeader` trait for use as `dyn` trait object that
can find objects and access their headers.
Byron committed Nov 26, 2023
commit 1838cbd36f4c19e07080529ec05ecf6c81218686
6 changes: 6 additions & 0 deletions gix-object/src/find.rs
Original file line number Diff line number Diff line change
@@ -66,6 +66,12 @@ pub mod existing_iter {
#[derive(Debug, Copy, Clone)]
pub struct Never;

impl super::FindHeader for Never {
fn try_header(&self, _id: &gix_hash::oid) -> Result<Option<crate::Header>, Error> {
Ok(None)
}
}

impl super::Find for Never {
fn try_find<'a>(&self, _id: &gix_hash::oid, _buffer: &'a mut Vec<u8>) -> Result<Option<crate::Data<'a>>, Error> {
Ok(None)
11 changes: 10 additions & 1 deletion gix-object/src/lib.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ pub mod data;
pub mod find;

mod traits;
pub use traits::{Exists, Find, FindExt, WriteTo};
pub use traits::{Exists, Find, FindExt, FindObjectOrHeader, Header as FindHeader, HeaderExt, WriteTo};

pub mod encode;
pub(crate) mod parse;
@@ -257,6 +257,15 @@ pub struct Data<'a> {
pub data: &'a [u8],
}

/// Information about an object, which includes its kind and the amount of bytes it would have when obtained.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
pub struct Header {
/// The kind of object.
pub kind: Kind,
/// The object's size in bytes, or the size of the buffer when it's retrieved in full.
pub size: u64,
}

///
pub mod decode {
#[cfg(feature = "verbose-object-parsing-errors")]
63 changes: 61 additions & 2 deletions gix-object/src/traits.rs
Original file line number Diff line number Diff line change
@@ -71,6 +71,17 @@ mod find {
) -> Result<Option<crate::Data<'a>>, find::Error>;
}

/// Find the header of an object in the object store.
pub trait Header {
/// Find the header of the object matching `id` in the database.
///
/// Returns `Some` header if it was present, or the error that occurred during lookup.
fn try_header(&self, id: &gix_hash::oid) -> Result<Option<crate::Header>, find::Error>;
}

/// A combination of [`Find`] and [`Header`] traits to help with `dyn` trait objects.
pub trait FindObjectOrHeader: Find + Header {}

mod _impls {
use std::{ops::Deref, rc::Rc, sync::Arc};

@@ -86,6 +97,8 @@ mod find {
}
}

impl<T> crate::FindObjectOrHeader for T where T: crate::Find + crate::FindHeader {}

impl<T> crate::Find for &T
where
T: crate::Find,
@@ -95,6 +108,15 @@ mod find {
}
}

impl<T> crate::FindHeader for &T
where
T: crate::FindHeader,
{
fn try_header(&self, id: &gix_hash::oid) -> Result<Option<crate::Header>, crate::find::Error> {
(*self).try_header(id)
}
}

impl<T> crate::Exists for Box<T>
where
T: crate::Exists,
@@ -122,6 +144,15 @@ mod find {
}
}

impl<T> crate::FindHeader for Rc<T>
where
T: crate::FindHeader,
{
fn try_header(&self, id: &gix_hash::oid) -> Result<Option<crate::Header>, crate::find::Error> {
self.deref().try_header(id)
}
}

impl<T> crate::Find for Box<T>
where
T: crate::Find,
@@ -131,6 +162,15 @@ mod find {
}
}

impl<T> crate::FindHeader for Box<T>
where
T: crate::FindHeader,
{
fn try_header(&self, id: &gix_hash::oid) -> Result<Option<crate::Header>, crate::find::Error> {
self.deref().try_header(id)
}
}

impl<T> crate::Exists for Arc<T>
where
T: crate::Exists,
@@ -148,6 +188,15 @@ mod find {
self.deref().try_find(id, buffer)
}
}

impl<T> crate::FindHeader for Arc<T>
where
T: crate::FindHeader,
{
fn try_header(&self, id: &gix_hash::oid) -> Result<Option<crate::Header>, crate::find::Error> {
self.deref().try_header(id)
}
}
}

mod ext {
@@ -214,9 +263,19 @@ mod find {
};
}

/// An extension trait with convenience functions.
pub trait HeaderExt: super::Header {
/// Like [`try_header(…)`](super::Header::try_header()), but flattens the `Result<Option<_>>` into a single `Result` making a non-existing header an error.
fn header(&self, id: &gix_hash::oid) -> Result<crate::Header, find::existing::Error> {
self.try_header(id)
.map_err(find::existing::Error::Find)?
.ok_or_else(|| find::existing::Error::NotFound { oid: id.to_owned() })
}
}

/// An extension trait with convenience functions.
pub trait FindExt: super::Find {
/// Like [`try_find(…)`][super::Find::try_find()], but flattens the `Result<Option<_>>` into a single `Result` making a non-existing object an error.
/// Like [`try_find(…)`](super::Find::try_find()), but flattens the `Result<Option<_>>` into a single `Result` making a non-existing object an error.
fn find<'a>(
&self,
id: &gix_hash::oid,
@@ -238,6 +297,6 @@ mod find {

impl<T: super::Find + ?Sized> FindExt for T {}
}
pub use ext::FindExt;
pub use ext::{FindExt, HeaderExt};
}
pub use find::*;