From acf1193e6b72433d4b74ec9fd39de148529224c5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Aug 2021 16:26:50 +0800 Subject: [PATCH 1/4] [odb #180] add changelog --- git-odb/CHANGELOG.md | 3 +++ git-odb/Cargo.toml | 2 +- git-odb/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 git-odb/CHANGELOG.md diff --git a/git-odb/CHANGELOG.md b/git-odb/CHANGELOG.md new file mode 100644 index 00000000000..a458597e947 --- /dev/null +++ b/git-odb/CHANGELOG.md @@ -0,0 +1,3 @@ +### 0.21.0 (2021-08-??) + +- TBD diff --git a/git-odb/Cargo.toml b/git-odb/Cargo.toml index c1d6b112d51..5cb746cf2d8 100644 --- a/git-odb/Cargo.toml +++ b/git-odb/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Sebastian Thiel "] license = "MIT/Apache-2.0" description = "Implements various git object databases" edition = "2018" -include = ["src/**/*"] +include = ["src/**/*", "CHANGELOG.md"] [lib] doctest = false diff --git a/git-odb/src/lib.rs b/git-odb/src/lib.rs index 713a2b0e521..161bde4db4a 100644 --- a/git-odb/src/lib.rs +++ b/git-odb/src/lib.rs @@ -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; From 7b9854fb35e86958a5ca827ec9a55b1168f38395 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Aug 2021 16:27:13 +0800 Subject: [PATCH 2/4] Bump git-odb v0.21.0 --- Cargo.lock | 2 +- git-odb/Cargo.toml | 2 +- git-repository/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 460246ce6fa..27d5eab4d14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1096,7 +1096,7 @@ dependencies = [ [[package]] name = "git-odb" -version = "0.20.2" +version = "0.21.0" dependencies = [ "btoi", "git-actor", diff --git a/git-odb/Cargo.toml b/git-odb/Cargo.toml index 5cb746cf2d8..27655ffa838 100644 --- a/git-odb/Cargo.toml +++ b/git-odb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git-odb" -version = "0.20.2" +version = "0.21.0" repository = "https://github.com/Byron/gitoxide" authors = ["Sebastian Thiel "] license = "MIT/Apache-2.0" diff --git a/git-repository/Cargo.toml b/git-repository/Cargo.toml index f8b08a03849..3b915b83114 100644 --- a/git-repository/Cargo.toml +++ b/git-repository/Cargo.toml @@ -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" } From eff21dae1083042412f45cd2f7a0faaf7d6400e6 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Aug 2021 16:30:49 +0800 Subject: [PATCH 3/4] [odb #180] refactor --- git-odb/CHANGELOG.md | 4 +++- git-odb/src/store/compound/find.rs | 4 ++-- git-odb/src/store/linked/find.rs | 2 +- git-odb/src/store/loose/find.rs | 2 +- git-odb/tests/odb/store/compound/mod.rs | 2 +- git-odb/tests/odb/store/loose/backend.rs | 14 ++++++++++---- .../prepare_and_commit/create_or_update.rs | 2 +- gitoxide-core/src/pack/explode.rs | 2 +- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/git-odb/CHANGELOG.md b/git-odb/CHANGELOG.md index a458597e947..845ee42134d 100644 --- a/git-odb/CHANGELOG.md +++ b/git-odb/CHANGELOG.md @@ -1,3 +1,5 @@ ### 0.21.0 (2021-08-??) -- TBD +- **renames** + - `compound::Store::find()` -> `compound::Store::try_find()` + - `loose::Store::find()` -> `loose::Store::try_find()` diff --git a/git-odb/src/store/compound/find.rs b/git-odb/src/store/compound/find.rs index c0e85fd6679..4131e3e12d3 100644 --- a/git-odb/src/store/compound/find.rs +++ b/git-odb/src/store/compound/find.rs @@ -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, buffer: &'a mut Vec, @@ -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) } diff --git a/git-odb/src/store/linked/find.rs b/git-odb/src/store/linked/find.rs index c8900e5595f..77e95365300 100644 --- a/git-odb/src/store/linked/find.rs +++ b/git-odb/src/store/linked/find.rs @@ -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); } } } diff --git a/git-odb/src/store/loose/find.rs b/git-odb/src/store/loose/find.rs index 2eb5ef85a19..0e14733105a 100644 --- a/git-odb/src/store/loose/find.rs +++ b/git-odb/src/store/loose/find.rs @@ -38,7 +38,7 @@ impl Store { /// /// Returns `Err` if there was an error locating or reading the object. Returns `Ok` if /// there was no such object. - pub fn find<'a>( + pub fn try_find<'a>( &self, id: impl AsRef, out: &'a mut Vec, diff --git a/git-odb/tests/odb/store/compound/mod.rs b/git-odb/tests/odb/store/compound/mod.rs index 7bf4f7fb009..5b3bb0f4b88 100644 --- a/git-odb/tests/odb/store/compound/mod.rs +++ b/git-odb/tests/odb/store/compound/mod.rs @@ -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()); } diff --git a/git-odb/tests/odb/store/loose/backend.rs b/git-odb/tests/odb/store/loose/backend.rs index 649392c7cb6..14a70e021c6 100644 --- a/git-odb/tests/odb/store/loose/backend.rs +++ b/git-odb/tests/odb/store/loose/backend.rs @@ -26,7 +26,7 @@ fn iter() { assert_eq!(oids, object_ids()) } pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec) -> 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 { @@ -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(()) } @@ -168,7 +174,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB } fn try_locate<'a>(hex: &str, buf: &'a mut Vec) -> Option> { - 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 { diff --git a/git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs b/git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs index cd7a76c989c..43b0a15cc00 100644 --- a/git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs +++ b/git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs @@ -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) }), diff --git a/gitoxide-core/src/pack/explode.rs b/gitoxide-core/src/pack/explode.rs index 4217ce8b86c..1e8a52bcf24 100644 --- a/gitoxide-core/src/pack/explode.rs +++ b/gitoxide-core/src/pack/explode.rs @@ -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)?; From bd50752dd9188acd92b8503db53cc2ce8112c61f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Aug 2021 16:33:28 +0800 Subject: [PATCH 4/4] [odb #180] fix docs --- git-odb/src/store/compound/find.rs | 2 +- git-odb/src/store/loose/find.rs | 2 +- git-odb/src/store/loose/iter.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/git-odb/src/store/compound/find.rs b/git-odb/src/store/compound/find.rs index 4131e3e12d3..56e852c2ca0 100644 --- a/git-odb/src/store/compound/find.rs +++ b/git-odb/src/store/compound/find.rs @@ -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 { diff --git a/git-odb/src/store/loose/find.rs b/git-odb/src/store/loose/find.rs index 0e14733105a..c32c409ffab 100644 --- a/git-odb/src/store/loose/find.rs +++ b/git-odb/src/store/loose/find.rs @@ -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 { diff --git a/git-odb/src/store/loose/iter.rs b/git-odb/src/store/loose/iter.rs index 7da98d80dac..91e93b6c59e 100644 --- a/git-odb/src/store/loose/iter.rs +++ b/git-odb/src/store/loose/iter.rs @@ -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