Skip to content

Commit 7c665bf

Browse files
committed
change!: Remove Find trait (as it's now living in gix-odb)
This makes it easier to access objects via trait from other crates without having to pull in all of `gix-odb`.
1 parent b941c61 commit 7c665bf

File tree

12 files changed

+64
-245
lines changed

12 files changed

+64
-245
lines changed

gix-odb/src/cache.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,29 @@ mod impls {
150150
}
151151
}
152152

153-
impl<S> crate::Find for Cache<S>
153+
impl<S> gix_object::Find for Cache<S>
154154
where
155155
S: gix_pack::Find,
156156
{
157-
fn contains(&self, id: &oid) -> bool {
158-
self.inner.contains(id)
157+
fn try_find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, gix_object::find::Error> {
158+
gix_pack::Find::try_find(self, id, buffer).map(|t| t.map(|t| t.0))
159159
}
160+
}
160161

161-
fn try_find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, crate::find::Error> {
162-
gix_pack::Find::try_find(self, id, buffer).map(|t| t.map(|t| t.0))
162+
impl<S> gix_object::Exists for Cache<S>
163+
where
164+
S: gix_pack::Find,
165+
{
166+
fn exists(&self, id: &oid) -> bool {
167+
self.inner.contains(id)
163168
}
164169
}
165170

166171
impl<S> crate::Header for Cache<S>
167172
where
168173
S: crate::Header,
169174
{
170-
fn try_header(&self, id: &oid) -> Result<Option<Header>, crate::find::Error> {
175+
fn try_header(&self, id: &oid) -> Result<Option<Header>, gix_object::find::Error> {
171176
self.inner.try_header(id)
172177
}
173178
}
@@ -184,7 +189,7 @@ mod impls {
184189
&self,
185190
id: &oid,
186191
buffer: &'a mut Vec<u8>,
187-
) -> Result<Option<(Data<'a>, Option<Location>)>, crate::find::Error> {
192+
) -> Result<Option<(Data<'a>, Option<Location>)>, gix_object::find::Error> {
188193
match self.pack_cache.as_ref().map(RefCell::borrow_mut) {
189194
Some(mut pack_cache) => self.try_find_cached(id, buffer, pack_cache.deref_mut()),
190195
None => self.try_find_cached(id, buffer, &mut gix_pack::cache::Never),
@@ -196,7 +201,7 @@ mod impls {
196201
id: &oid,
197202
buffer: &'a mut Vec<u8>,
198203
pack_cache: &mut dyn gix_pack::cache::DecodeEntry,
199-
) -> Result<Option<(Data<'a>, Option<gix_pack::data::entry::Location>)>, crate::find::Error> {
204+
) -> Result<Option<(Data<'a>, Option<gix_pack::data::entry::Location>)>, gix_object::find::Error> {
200205
if let Some(mut obj_cache) = self.object_cache.as_ref().map(RefCell::borrow_mut) {
201206
if let Some(kind) = obj_cache.get(&id.as_ref().to_owned(), buffer) {
202207
return Ok(Some((Data::new(kind, buffer), None)));

gix-odb/src/find.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,3 @@
1-
/// The error type returned by the [`Find`](crate::Find) and [`Header`](crate::Header) traits.
2-
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
3-
///
4-
pub mod existing {
5-
use gix_hash::ObjectId;
6-
7-
/// The error returned by the [`find(…)`][crate::FindExt::find()] trait methods.
8-
#[derive(Debug, thiserror::Error)]
9-
#[allow(missing_docs)]
10-
pub enum Error {
11-
#[error(transparent)]
12-
Find(crate::find::Error),
13-
#[error("An object with id {} could not be found", .oid)]
14-
NotFound { oid: ObjectId },
15-
}
16-
}
17-
18-
///
19-
pub mod existing_object {
20-
use gix_hash::ObjectId;
21-
22-
/// The error returned by the various [`find_*()`][crate::FindExt::find_commit()] trait methods.
23-
#[derive(Debug, thiserror::Error)]
24-
#[allow(missing_docs)]
25-
pub enum Error {
26-
#[error(transparent)]
27-
Find(crate::find::Error),
28-
#[error(transparent)]
29-
Decode(gix_object::decode::Error),
30-
#[error("An object with id {oid} could not be found")]
31-
NotFound { oid: ObjectId },
32-
#[error("Expected object of kind {expected}")]
33-
ObjectKind { expected: gix_object::Kind },
34-
}
35-
}
36-
37-
///
38-
pub mod existing_iter {
39-
use gix_hash::ObjectId;
40-
41-
/// The error returned by the various [`find_*_iter()`][crate::FindExt::find_commit_iter()] trait methods.
42-
#[derive(Debug, thiserror::Error)]
43-
#[allow(missing_docs)]
44-
pub enum Error {
45-
#[error(transparent)]
46-
Find(crate::find::Error),
47-
#[error("An object with id {oid} could not be found")]
48-
NotFound { oid: ObjectId },
49-
#[error("Expected object of kind {expected}")]
50-
ObjectKind { expected: gix_object::Kind },
51-
}
52-
}
53-
541
/// An object header informing about object properties, without it being fully decoded in the process.
552
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
563
pub enum Header {

gix-odb/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub mod find;
7474
/// An object database equivalent to `/dev/null`, dropping all objects stored into it.
7575
mod traits;
7676

77-
pub use traits::{Find, FindExt, Header, HeaderExt, Write};
77+
pub use traits::{Header, HeaderExt, Write};
7878

7979
///
8080
pub mod write {

gix-odb/src/store_impls/dynamic/find.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub(crate) mod error {
7777
pub use error::Error;
7878
use gix_features::zlib;
7979

80-
use crate::{store::types::PackId, Find};
80+
use crate::store::types::PackId;
81+
use gix_object::{Exists, Find};
8182

8283
impl<S> super::Handle<S>
8384
where
@@ -503,15 +504,21 @@ where
503504
S: Deref<Target = super::Store> + Clone,
504505
Self: gix_pack::Find,
505506
{
506-
fn contains(&self, id: &gix_hash::oid) -> bool {
507-
gix_pack::Find::contains(self, id)
508-
}
509-
510507
fn try_find<'a>(
511508
&self,
512509
id: &gix_hash::oid,
513510
buffer: &'a mut Vec<u8>,
514-
) -> Result<Option<gix_object::Data<'a>>, crate::find::Error> {
511+
) -> Result<Option<gix_object::Data<'a>>, gix_object::find::Error> {
515512
gix_pack::Find::try_find(self, id, buffer).map(|t| t.map(|t| t.0))
516513
}
517514
}
515+
516+
impl<S> Exists for super::Handle<S>
517+
where
518+
S: Deref<Target = super::Store> + Clone,
519+
Self: gix_pack::Find,
520+
{
521+
fn exists(&self, id: &gix_hash::oid) -> bool {
522+
gix_pack::Find::contains(self, id)
523+
}
524+
}

gix-odb/src/store_impls/dynamic/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<S> crate::Header for super::Handle<S>
182182
where
183183
S: Deref<Target = super::Store> + Clone,
184184
{
185-
fn try_header(&self, id: &oid) -> Result<Option<Header>, crate::find::Error> {
185+
fn try_header(&self, id: &oid) -> Result<Option<Header>, gix_object::find::Error> {
186186
let mut snapshot = self.snapshot.borrow_mut();
187187
let mut inflate = self.inflate.borrow_mut();
188188
self.try_header_inner(id, &mut inflate, &mut snapshot, None)

gix-odb/src/store_impls/dynamic/prefix.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::{collections::HashSet, ops::Deref};
22

3-
use crate::{
4-
store::{load_index, Handle},
5-
Find,
6-
};
3+
use crate::store::{load_index, Handle};
4+
use gix_object::Exists;
75

86
///
97
pub mod lookup {
@@ -107,7 +105,7 @@ where
107105
) -> Result<Option<gix_hash::Prefix>, disambiguate::Error> {
108106
let max_hex_len = candidate.id().kind().len_in_hex();
109107
if candidate.hex_len() == max_hex_len {
110-
return Ok(self.contains(candidate.id()).then(|| candidate.to_prefix()));
108+
return Ok(self.exists(candidate.id()).then(|| candidate.to_prefix()));
111109
}
112110

113111
while candidate.hex_len() != max_hex_len {

0 commit comments

Comments
 (0)