Browse Source

git-odb::borrowed::Object => git-odb::data::Object

pull/80/head
Sebastian Thiel 4 weeks ago
parent
commit
747a13e9a1
No known key found for this signature in database GPG Key ID: 9CB5EE7895E8268B
  1. 6
      git-odb/src/compound/locate.rs
  2. 2
      git-odb/src/data.rs
  3. 2
      git-odb/src/lib.rs
  4. 4
      git-odb/src/linked/locate.rs
  5. 9
      git-odb/src/loose/db/locate.rs
  6. 8
      git-odb/src/pack/bundle/locate.rs
  7. 6
      git-odb/tests/loose/db.rs
  8. 2
      git-odb/tests/pack/bundle.rs
  9. 2
      gitoxide-core/src/pack/explode.rs

6
git-odb/src/compound/locate.rs

@ -1,4 +1,4 @@
use crate::{compound, loose, pack};
use crate::{compound, data, loose, pack};
/// Returned by [`compound::Db::locate()`]
#[derive(thiserror::Error, Debug)]
@ -24,7 +24,7 @@ impl compound::Db {
id: impl AsRef<git_hash::oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl pack::cache::DecodeEntry,
) -> Result<Option<crate::borrowed::Object<'a>>, Error> {
) -> Result<Option<data::Object<'a>>, Error> {
let id = id.as_ref();
for pack in &self.packs {
if let Some(idx) = pack.internal_locate_index(id) {
@ -62,7 +62,7 @@ impl compound::Db {
object_index: u32,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl pack::cache::DecodeEntry,
) -> Result<crate::borrowed::Object<'a>, pack::data::decode::Error> {
) -> Result<data::Object<'a>, pack::data::decode::Error> {
self.packs[pack_index].internal_get_object_by_index(object_index, buffer, pack_cache)
}
}

git-odb/src/borrowed.rs → git-odb/src/data.rs

2
git-odb/src/lib.rs

@ -33,7 +33,7 @@ pub use sink::{sink, Sink};
pub(crate) mod hash;
mod traits;
pub mod borrowed;
pub mod data;
pub mod traverse;
pub use traits::*;

4
git-odb/src/linked/locate.rs

@ -1,4 +1,4 @@
use crate::{compound, linked, pack};
use crate::{compound, data, linked, pack};
impl linked::Db {
/// Find an object as identified by [`ObjectId`][git_hash::ObjectId] and store its data in full in the provided `buffer`.
@ -9,7 +9,7 @@ impl linked::Db {
id: impl AsRef<git_hash::oid>,
buffer: &'a mut Vec<u8>,
pack_cache: &mut impl pack::cache::DecodeEntry,
) -> Result<Option<crate::borrowed::Object<'a>>, compound::locate::Error> {
) -> Result<Option<data::Object<'a>>, compound::locate::Error> {
use compound::locate::PackInfo;
let id = id.as_ref();
for db in self.dbs.iter() {

9
git-odb/src/loose/db/locate.rs

@ -1,4 +1,5 @@
use crate::{
data,
loose::{db::sha1_path, object::header, Db, HEADER_READ_UNCOMPRESSED_BYTES},
zlib,
};
@ -38,7 +39,7 @@ impl Db {
&self,
id: impl AsRef<git_hash::oid>,
out: &'a mut Vec<u8>,
) -> Result<Option<crate::borrowed::Object<'a>>, Error> {
) -> Result<Option<data::Object<'a>>, Error> {
match self.locate_inner(id.as_ref(), out) {
Ok(obj) => Ok(Some(obj)),
Err(err) => match err {
@ -62,7 +63,7 @@ impl Db {
}
}
fn locate_inner<'a>(&self, id: &git_hash::oid, buf: &'a mut Vec<u8>) -> Result<crate::borrowed::Object<'a>, Error> {
fn locate_inner<'a>(&self, id: &git_hash::oid, buf: &'a mut Vec<u8>) -> Result<data::Object<'a>, Error> {
let path = sha1_path(id, self.path.clone());
let mut inflate = zlib::Inflate::default();
@ -111,7 +112,7 @@ impl Db {
);
buf.copy_within(decompressed_body_bytes_sans_header, 0);
buf.resize(size, 0);
Ok(crate::borrowed::Object { kind, data: buf })
Ok(crate::data::Object { kind, data: buf })
} else {
buf.resize(bytes_read + size + header_size, 0);
{
@ -134,7 +135,7 @@ impl Db {
};
buf.copy_within(decompressed_start + header_size.., 0);
buf.resize(size, 0);
Ok(crate::borrowed::Object { kind, data: buf })
Ok(crate::data::Object { kind, data: buf })
}
}
}

8
git-odb/src/pack/bundle/locate.rs

@ -1,4 +1,4 @@
use crate::pack;
use crate::{data, pack};
impl pack::Bundle {
/// Find an object with the given [`ObjectId`][git_hash::ObjectId] and place its data into `out`.
@ -12,7 +12,7 @@ impl pack::Bundle {
id: impl AsRef<git_hash::oid>,
out: &'a mut Vec<u8>,
cache: &mut impl pack::cache::DecodeEntry,
) -> Result<Option<crate::borrowed::Object<'a>>, pack::data::decode::Error> {
) -> Result<Option<data::Object<'a>>, pack::data::decode::Error> {
let idx = match self.index.lookup(id) {
Some(idx) => idx,
None => return Ok(None),
@ -35,7 +35,7 @@ impl pack::Bundle {
idx: u32,
out: &'a mut Vec<u8>,
cache: &mut impl pack::cache::DecodeEntry,
) -> Result<crate::borrowed::Object<'a>, pack::data::decode::Error> {
) -> Result<data::Object<'a>, pack::data::decode::Error> {
let ofs = self.index.pack_offset_at_index(idx);
let pack_entry = self.pack.entry(ofs);
self.pack
@ -49,7 +49,7 @@ impl pack::Bundle {
},
cache,
)
.map(move |r| crate::borrowed::Object {
.map(move |r| crate::data::Object {
kind: r.kind,
data: out.as_slice(),
})

6
git-odb/tests/loose/db.rs

@ -24,7 +24,7 @@ fn iter() {
oids.sort();
assert_eq!(oids, object_ids())
}
pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec<u8>) -> git_odb::borrowed::Object<'_> {
pub fn locate_oid(id: git_hash::ObjectId, buf: &mut Vec<u8>) -> git_odb::data::Object<'_> {
ldb().locate(id, buf).expect("read success").expect("id present")
}
@ -62,7 +62,7 @@ mod locate {
};
use git_object::{bstr::ByteSlice, immutable, immutable::tree, tree::Mode, Kind};
fn locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> git_odb::borrowed::Object<'a> {
fn locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> git_odb::data::Object<'a> {
locate_oid(hex_to_id(hex), buf)
}
@ -165,7 +165,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
Ok(())
}
fn try_locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> Option<git_odb::borrowed::Object<'a>> {
fn try_locate<'a>(hex: &str, buf: &'a mut Vec<u8>) -> Option<git_odb::data::Object<'a>> {
ldb().locate(hex_to_id(hex), buf).ok().flatten()
}

2
git-odb/tests/pack/bundle.rs

@ -4,7 +4,7 @@ mod locate {
use git_object::Kind;
use git_odb::pack;
fn locate<'a>(hex_id: &str, out: &'a mut Vec<u8>) -> git_odb::borrowed::Object<'a> {
fn locate<'a>(hex_id: &str, out: &'a mut Vec<u8>) -> git_odb::data::Object<'a> {
let bundle = pack::Bundle::at(fixture_path(SMALL_PACK_INDEX)).expect("pack and idx");
bundle
.locate(hex_to_id(hex_id), out, &mut pack::cache::Noop)

2
gitoxide-core/src/pack/explode.rs

@ -77,7 +77,7 @@ quick_error! {
display("Failed to write {} object {}", kind, id)
source(&**err)
}
Verify(err: git_odb::borrowed::verify::Error) {
Verify(err: git_odb::data::verify::Error) {
display("Object didn't verify after right after writing it")
source(err)
from()

Loading…
Cancel
Save