Skip to content

git-odb refactoring #180

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

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions git-odb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### 0.21.0 (2021-08-??)

- **renames**
- `compound::Store::find()` -> `compound::Store::try_find()`
- `loose::Store::find()` -> `loose::Store::try_find()`
4 changes: 2 additions & 2 deletions git-odb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "git-odb"
version = "0.20.2"
version = "0.21.0"
repository = "https://github.com/Byron/gitoxide"
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
license = "MIT/Apache-2.0"
description = "Implements various git object databases"
edition = "2018"
include = ["src/**/*"]
include = ["src/**/*", "CHANGELOG.md"]

[lib]
doctest = false
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use git_pack as pack;
pub use pack::{data, Find, FindExt};

mod store;
pub use store::*;
pub use store::{compound, linked, loose, sink, Sink};

pub mod alternate;

Expand Down
6 changes: 3 additions & 3 deletions git-odb/src/store/compound/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
store::{compound, loose},
};

/// Returned by [`compound::Store::find()`]
/// Returned by [`compound::Store::try_find()`]
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum Error {
Expand All @@ -25,7 +25,7 @@ impl compound::Store {
/// Find an object as identified by [`ObjectId`][git_hash::ObjectId] and store its data in full in the provided `buffer`.
/// This will search the object in all contained object databases.
/// Use a `pack_cache` to accelerate pack access by reducing the amount of work duplication, or [`pack::cache::Never`] to disable any caching.
pub fn find<'a>(
pub fn try_find<'a>(
&self,
id: impl AsRef<git_hash::oid>,
buffer: &'a mut Vec<u8>,
Expand All @@ -39,7 +39,7 @@ impl compound::Store {
}
}
if self.loose.contains(id) {
return self.loose.find(id, buffer).map_err(Into::into);
return self.loose.try_find(id, buffer).map_err(Into::into);
}
Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/store/linked/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl crate::Find for linked::Store {
}
None => {
if db.loose.contains(id) {
return db.loose.find(id, buffer).map_err(Into::into);
return db.loose.try_find(id, buffer).map_err(Into::into);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/store/loose/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use git_pack::{data, loose::object::header};

use crate::store::loose::{sha1_path, Store, HEADER_READ_UNCOMPRESSED_BYTES};

/// Returned by [`Store::find()`]
/// Returned by [`Store::try_find()`]
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum Error {
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Store {
///
/// Returns `Err` if there was an error locating or reading the object. Returns `Ok<None>` if
/// there was no such object.
pub fn find<'a>(
pub fn try_find<'a>(
&self,
id: impl AsRef<git_hash::oid>,
out: &'a mut Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/store/loose/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Store {

/// Return an iterator over all objects contained in the database.
///
/// The [`Id`][git_hash::ObjectId]s returned by the iterator can typically be used in the [`locate(…)`][Store::find()] method.
/// The [`Id`][git_hash::ObjectId]s returned by the iterator can typically be used in the [`locate(…)`][Store::try_find()] method.
/// _Note_ that the result is not sorted or stable, thus ordering can change between runs.
///
/// # Notes
Expand Down
2 changes: 1 addition & 1 deletion git-odb/tests/odb/store/compound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod locate {
fn can_locate(db: &Store, hex_id: &str) {
let mut buf = vec![];
assert!(db
.find(hex_to_id(hex_id), &mut buf, &mut git_pack::cache::Never)
.try_find(hex_to_id(hex_id), &mut buf, &mut git_pack::cache::Never)
.expect("no read error")
.is_some());
}
Expand Down
14 changes: 10 additions & 4 deletions git-odb/tests/odb/store/loose/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn iter() {
assert_eq!(oids, object_ids())
}
pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec<u8>) -> git_pack::data::Object<'_> {
ldb().find(id, buf).expect("read success").expect("id present")
ldb().try_find(id, buf).expect("read success").expect("id present")
}

mod write {
Expand All @@ -45,10 +45,16 @@ mod write {
let obj = locate_oid(oid, &mut buf);
let actual = db.write(&obj.decode()?.into(), git_hash::Kind::Sha1)?;
assert_eq!(actual, oid);
assert_eq!(db.find(oid, &mut buf2)?.expect("id present").decode()?, obj.decode()?);
assert_eq!(
db.try_find(oid, &mut buf2)?.expect("id present").decode()?,
obj.decode()?
);
let actual = db.write_buf(obj.kind, obj.data, git_hash::Kind::Sha1)?;
assert_eq!(actual, oid);
assert_eq!(db.find(oid, &mut buf2)?.expect("id present").decode()?, obj.decode()?);
assert_eq!(
db.try_find(oid, &mut buf2)?.expect("id present").decode()?,
obj.decode()?
);
}
Ok(())
}
Expand Down Expand Up @@ -168,7 +174,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
}

fn try_locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> Option<git_pack::data::Object<'a>> {
ldb().find(hex_to_id(hex), buf).ok().flatten()
ldb().try_find(hex_to_id(hex), buf).ok().flatten()
}

pub fn as_id(id: &[u8; 20]) -> &git_hash::oid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ fn packed_refs_creation_with_packed_refs_mode_prune_removes_original_loose_refs(
.transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(
Box::new(move |oid, buf| {
odb.find(oid, buf, &mut git_odb::pack::cache::Never)
odb.try_find(oid, buf, &mut git_odb::pack::cache::Never)
.map(|obj| obj.map(|obj| obj.kind))
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync>)
}),
Expand Down
2 changes: 1 addition & 1 deletion git-repository/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ git-tempfile = { version ="^1.0.0", path = "../git-tempfile" }
git-lock = { version ="^1.0.0", path = "../git-lock" }
git-validate = { version = "^0.5.0", path = "../git-validate" }

git-odb = { version ="0.20.0", path = "../git-odb" }
git-odb = { version ="^0.21.0", path = "../git-odb" }
git-hash = { version = "^0.5.0", path = "../git-hash" }
git-object = { version ="^0.13.0", path = "../git-object" }
git-actor = { version ="^0.5.0", path = "../git-actor" }
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub fn pack_or_pack_index(
}
}
if let Some(verifier) = object_verifier.as_ref() {
let obj = verifier.find(written_id, &mut read_buf)
let obj = verifier.try_find(written_id, &mut read_buf)
.map_err(|err| Error::WrittenFileCorrupt(err, written_id))?
.ok_or(Error::WrittenFileMissing(written_id))?;
obj.verify_checksum(written_id)?;
Expand Down