Skip to content

Commit

Permalink
Adjustments to deal with changes to git-pack/git-odb (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 2, 2022
1 parent b5dd059 commit fcf8fde
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
9 changes: 5 additions & 4 deletions gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub struct Context {
pub sink_compress: bool,
pub verify: bool,
pub should_interrupt: Arc<AtomicBool>,
pub object_hash: git_repository::hash::Kind,
}

pub fn pack_or_pack_index(
Expand All @@ -158,12 +159,12 @@ pub fn pack_or_pack_index(
sink_compress,
verify,
should_interrupt,
object_hash,
}: Context,
) -> Result<()> {
use anyhow::Context;

let path = pack_path.as_ref();
let object_hash = git_repository::hash::Kind::Sha1; // TODO: make this configurable via CLI, maybe even different values for I/O
let bundle = pack::Bundle::at(path, object_hash).with_context(|| {
format!(
"Could not find .idx or .pack file from given file at '{}'",
Expand Down Expand Up @@ -197,6 +198,7 @@ pub fn pack_or_pack_index(
.traverse(
&bundle.pack,
progress,
&should_interrupt,
{
let object_path = object_path.map(|p| p.as_ref().to_owned());
move || {
Expand Down Expand Up @@ -232,12 +234,11 @@ pub fn pack_or_pack_index(
}
}
},
pack::cache::lru::StaticLinkedList::<64>::default,
pack::index::traverse::Options {
algorithm,
traversal: algorithm,
thread_limit,
check: check.into(),
should_interrupt: &should_interrupt,
make_pack_lookup_cache: pack::cache::lru::StaticLinkedList::<64>::default,
},
)
.with_context(|| "Failed to explode the entire pack - some loose objects may have been created nonetheless")?;
Expand Down
3 changes: 2 additions & 1 deletion gitoxide-core/src/pack/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Context<W> {
pub format: OutputFormat,
pub should_interrupt: Arc<AtomicBool>,
pub out: W,
pub object_hash: git_repository::hash::Kind,
}

struct CloneDelegate<W> {
Expand Down Expand Up @@ -330,7 +331,7 @@ fn receive_pack_blocking<W: io::Write>(
thread_limit: ctx.thread_limit,
index_kind: pack::index::Version::V2,
iteration_mode: pack::data::input::Mode::Verify,
object_hash: git_repository::hash::Kind::Sha1, // TODO: make this configurable, but respect the server response as well.
object_hash: ctx.object_hash,
};
let outcome =
pack::Bundle::write_to_directory(input, directory.take(), progress, &ctx.should_interrupt, None, options)
Expand Down
28 changes: 8 additions & 20 deletions gitoxide-core/src/pack/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,7 @@ pub struct Context<'a, W1: io::Write, W2: io::Write> {
pub mode: index::verify::Mode,
pub algorithm: Algorithm,
pub should_interrupt: &'a AtomicBool,
}

impl<'a> Context<'a, Vec<u8>, Vec<u8>> {
/// Create a new default context with all fields being the default.
pub fn new(should_interrupt: &'a AtomicBool) -> Self {
Context {
output_statistics: None,
thread_limit: None,
mode: index::verify::Mode::HashCrc32,
algorithm: Algorithm::LessMemory,
out: Vec::new(),
err: Vec::new(),
should_interrupt,
}
}
pub object_hash: git::hash::Kind,
}

enum EitherCache<const SIZE: usize> {
Expand Down Expand Up @@ -112,6 +98,7 @@ pub fn pack_or_pack_index<W1, W2>(
thread_limit,
algorithm,
should_interrupt,
object_hash,
}: Context<'_, W1, W2>,
) -> Result<()>
where
Expand All @@ -120,7 +107,6 @@ where
{
let path = path.as_ref();
let ext = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
let object_hash = git::hash::Kind::Sha1; // TODO: make it configurable via Context/CLI
const CACHE_SIZE: usize = 64;
let cache = || -> EitherCache<CACHE_SIZE> {
if matches!(algorithm, Algorithm::LessMemory) {
Expand Down Expand Up @@ -160,11 +146,13 @@ where
idx.verify_integrity(
pack.as_ref().map(|p| git::odb::pack::index::verify::PackContext {
data: p,
verify_mode: mode,
traversal_algorithm: algorithm.into(),
make_cache_fn: cache,
options: git::odb::pack::index::verify::integrity::Options {
verify_mode: mode,
traversal: algorithm.into(),
make_pack_lookup_cache: cache,
thread_limit
}
}),
thread_limit,
progress,
should_interrupt,
)
Expand Down
4 changes: 4 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub fn main() -> Result<()> {
format,
out: std::io::stdout(),
should_interrupt,
object_hash,
},
);
return futures_lite::future::block_on(fut);
Expand Down Expand Up @@ -174,6 +175,7 @@ pub fn main() -> Result<()> {
format,
should_interrupt,
out,
object_hash,
},
)
},
Expand Down Expand Up @@ -203,6 +205,7 @@ pub fn main() -> Result<()> {
sink_compress,
verify,
should_interrupt,
object_hash,
},
)
},
Expand Down Expand Up @@ -237,6 +240,7 @@ pub fn main() -> Result<()> {
mode,
algorithm,
should_interrupt: &should_interrupt,
object_hash,
},
)
},
Expand Down

0 comments on commit fcf8fde

Please sign in to comment.