Skip to content

Commit

Permalink
adapt to changes in gix-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 13, 2024
1 parent b32a847 commit bad5b48
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gix-config/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::alloc;
use std::time::Instant;

#[global_allocator]
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::max_value());
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::MAX);

#[test]
fn usage() {
Expand Down
2 changes: 1 addition & 1 deletion gix-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include = ["src/**/*", "LICENSE-*"]
rust-version = "1.65"

[lib]
proc_macro = true
proc-macro = true

[dependencies]
syn = { version = "2.0", features = ["full", "fold"] }
Expand Down
28 changes: 16 additions & 12 deletions gix-odb/src/store_impls/dynamic/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(crate) mod error {
LoadIndex(#[from] crate::store::load_index::Error),
#[error(transparent)]
LoadPack(#[from] std::io::Error),
#[error(transparent)]
EntryType(#[from] gix_pack::data::entry::decode::Error),
#[error("Reached recursion limit of {} while resolving ref delta bases for {}", .max_depth, .id)]
DeltaBaseRecursionLimit {
/// the maximum recursion depth we encountered.
Expand Down Expand Up @@ -144,19 +146,21 @@ where
}
},
};
let entry = pack.entry(pack_offset);
let entry = pack.entry(pack_offset)?;
let header_size = entry.header_size();
let res = match pack.decode_entry(
let res = pack.decode_entry(
entry,
buffer,
inflate,
&|id, _out| {
index_file.pack_offset_by_id(id).map(|pack_offset| {
gix_pack::data::decode::entry::ResolvedBase::InPack(pack.entry(pack_offset))
})
let pack_offset = index_file.pack_offset_by_id(id)?;
pack.entry(pack_offset)
.ok()
.map(gix_pack::data::decode::entry::ResolvedBase::InPack)
},
pack_cache,
) {
);
let res = match res {
Ok(r) => Ok((
gix_object::Data {
kind: r.kind,
Expand Down Expand Up @@ -230,7 +234,7 @@ where
let pack = possibly_pack
.as_ref()
.expect("pack to still be available like just now");
let entry = pack.entry(pack_offset);
let entry = pack.entry(pack_offset)?;
let header_size = entry.header_size();
pack.decode_entry(
entry,
Expand All @@ -239,10 +243,10 @@ where
&|id, out| {
index_file
.pack_offset_by_id(id)
.map(|pack_offset| {
gix_pack::data::decode::entry::ResolvedBase::InPack(
pack.entry(pack_offset),
)
.and_then(|pack_offset| {
pack.entry(pack_offset)
.ok()
.map(gix_pack::data::decode::entry::ResolvedBase::InPack)
})
.or_else(|| {
(id == base_id).then(|| {
Expand Down Expand Up @@ -398,7 +402,7 @@ where
}
},
};
let entry = pack.entry(pack_offset);
let entry = pack.entry(pack_offset).ok()?;

buf.resize(entry.decompressed_size.try_into().expect("representable size"), 0);
assert_eq!(pack.id, pack_id.to_intrinsic_pack_id(), "both ids must always match");
Expand Down
18 changes: 10 additions & 8 deletions gix-odb/src/store_impls/dynamic/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ where
}
},
};
let entry = pack.entry(pack_offset);
let entry = pack.entry(pack_offset)?;
let res = match pack.decode_header(entry, inflate, &|id| {
index_file.pack_offset_by_id(id).map(|pack_offset| {
gix_pack::data::decode::header::ResolvedBase::InPack(pack.entry(pack_offset))
index_file.pack_offset_by_id(id).and_then(|pack_offset| {
pack.entry(pack_offset)
.ok()
.map(gix_pack::data::decode::header::ResolvedBase::InPack)
})
}) {
Ok(header) => Ok(header.into()),
Expand Down Expand Up @@ -129,14 +131,14 @@ where
let pack = possibly_pack
.as_ref()
.expect("pack to still be available like just now");
let entry = pack.entry(pack_offset);
let entry = pack.entry(pack_offset)?;
pack.decode_header(entry, inflate, &|id| {
index_file
.pack_offset_by_id(id)
.map(|pack_offset| {
gix_pack::data::decode::header::ResolvedBase::InPack(
pack.entry(pack_offset),
)
.and_then(|pack_offset| {
pack.entry(pack_offset)
.ok()
.map(gix_pack::data::decode::header::ResolvedBase::InPack)
})
.or_else(|| {
(id == base_id).then(|| {
Expand Down
6 changes: 3 additions & 3 deletions gix-pack/tests/pack/data/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod decode_entry {
}

let p = pack_at(SMALL_PACK);
let entry = p.entry(offset);
let entry = p.entry(offset).expect("valid object type");
let mut buf = Vec::new();
p.decode_entry(
entry,
Expand Down Expand Up @@ -159,7 +159,7 @@ mod resolve_header {
}

let p = pack_at(SMALL_PACK);
let entry = p.entry(offset);
let entry = p.entry(offset).expect("valid object type");
p.decode_header(entry, &mut Default::default(), &resolve_with_panic)
.expect("valid offset provides valid entry")
}
Expand Down Expand Up @@ -208,7 +208,7 @@ mod decompress_entry {

fn decompress_entry_at_offset(offset: u64) -> Vec<u8> {
let p = pack_at(SMALL_PACK);
let entry = p.entry(offset);
let entry = p.entry(offset).expect("valid object type");

let size = entry.decompressed_size as usize;
let mut buf = vec![0; size];
Expand Down
4 changes: 2 additions & 2 deletions gix-pack/tests/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn pack_lookup() -> Result<(), Box<dyn std::error::Error>> {
let sorted_offsets = idx.sorted_offsets();
assert_eq!(num_objects, sorted_offsets.len());
for idx_entry in idx.iter() {
let pack_entry = pack.entry(idx_entry.pack_offset);
let pack_entry = pack.entry(idx_entry.pack_offset)?;
assert_ne!(pack_entry.data_offset, idx_entry.pack_offset);
assert!(sorted_offsets.binary_search(&idx_entry.pack_offset).is_ok());
}
Expand All @@ -410,7 +410,7 @@ fn pack_lookup() -> Result<(), Box<dyn std::error::Error>> {
);

let mut buf = vec![0u8; entry.decompressed_size as usize];
let pack_entry = pack.entry(offset_from_index);
let pack_entry = pack.entry(offset_from_index)?;
assert_eq!(
pack_entry.pack_offset(),
entry.pack_offset,
Expand Down
2 changes: 1 addition & 1 deletion gix-pack/tests/pack/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod new_from_header {
let mut buf = Vec::<u8>::new();
entry.header.write_to(entry.decompressed_size, &mut buf)?;
let new_entry =
pack::data::Entry::from_bytes(&buf, entry.pack_offset, gix_hash::Kind::Sha1.len_in_bytes());
pack::data::Entry::from_bytes(&buf, entry.pack_offset, gix_hash::Kind::Sha1.len_in_bytes())?;

assert_eq!(
new_entry.header_size(),
Expand Down

0 comments on commit bad5b48

Please sign in to comment.