Skip to content

Commit fcf8fde

Browse files
committed
Adjustments to deal with changes to git-pack/git-odb (#287)
1 parent b5dd059 commit fcf8fde

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

Diff for: gitoxide-core/src/pack/explode.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub struct Context {
145145
pub sink_compress: bool,
146146
pub verify: bool,
147147
pub should_interrupt: Arc<AtomicBool>,
148+
pub object_hash: git_repository::hash::Kind,
148149
}
149150

150151
pub fn pack_or_pack_index(
@@ -158,12 +159,12 @@ pub fn pack_or_pack_index(
158159
sink_compress,
159160
verify,
160161
should_interrupt,
162+
object_hash,
161163
}: Context,
162164
) -> Result<()> {
163165
use anyhow::Context;
164166

165167
let path = pack_path.as_ref();
166-
let object_hash = git_repository::hash::Kind::Sha1; // TODO: make this configurable via CLI, maybe even different values for I/O
167168
let bundle = pack::Bundle::at(path, object_hash).with_context(|| {
168169
format!(
169170
"Could not find .idx or .pack file from given file at '{}'",
@@ -197,6 +198,7 @@ pub fn pack_or_pack_index(
197198
.traverse(
198199
&bundle.pack,
199200
progress,
201+
&should_interrupt,
200202
{
201203
let object_path = object_path.map(|p| p.as_ref().to_owned());
202204
move || {
@@ -232,12 +234,11 @@ pub fn pack_or_pack_index(
232234
}
233235
}
234236
},
235-
pack::cache::lru::StaticLinkedList::<64>::default,
236237
pack::index::traverse::Options {
237-
algorithm,
238+
traversal: algorithm,
238239
thread_limit,
239240
check: check.into(),
240-
should_interrupt: &should_interrupt,
241+
make_pack_lookup_cache: pack::cache::lru::StaticLinkedList::<64>::default,
241242
},
242243
)
243244
.with_context(|| "Failed to explode the entire pack - some loose objects may have been created nonetheless")?;

Diff for: gitoxide-core/src/pack/receive.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Context<W> {
2626
pub format: OutputFormat,
2727
pub should_interrupt: Arc<AtomicBool>,
2828
pub out: W,
29+
pub object_hash: git_repository::hash::Kind,
2930
}
3031

3132
struct CloneDelegate<W> {
@@ -330,7 +331,7 @@ fn receive_pack_blocking<W: io::Write>(
330331
thread_limit: ctx.thread_limit,
331332
index_kind: pack::index::Version::V2,
332333
iteration_mode: pack::data::input::Mode::Verify,
333-
object_hash: git_repository::hash::Kind::Sha1, // TODO: make this configurable, but respect the server response as well.
334+
object_hash: ctx.object_hash,
334335
};
335336
let outcome =
336337
pack::Bundle::write_to_directory(input, directory.take(), progress, &ctx.should_interrupt, None, options)

Diff for: gitoxide-core/src/pack/verify.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,7 @@ pub struct Context<'a, W1: io::Write, W2: io::Write> {
6363
pub mode: index::verify::Mode,
6464
pub algorithm: Algorithm,
6565
pub should_interrupt: &'a AtomicBool,
66-
}
67-
68-
impl<'a> Context<'a, Vec<u8>, Vec<u8>> {
69-
/// Create a new default context with all fields being the default.
70-
pub fn new(should_interrupt: &'a AtomicBool) -> Self {
71-
Context {
72-
output_statistics: None,
73-
thread_limit: None,
74-
mode: index::verify::Mode::HashCrc32,
75-
algorithm: Algorithm::LessMemory,
76-
out: Vec::new(),
77-
err: Vec::new(),
78-
should_interrupt,
79-
}
80-
}
66+
pub object_hash: git::hash::Kind,
8167
}
8268

8369
enum EitherCache<const SIZE: usize> {
@@ -112,6 +98,7 @@ pub fn pack_or_pack_index<W1, W2>(
11298
thread_limit,
11399
algorithm,
114100
should_interrupt,
101+
object_hash,
115102
}: Context<'_, W1, W2>,
116103
) -> Result<()>
117104
where
@@ -120,7 +107,6 @@ where
120107
{
121108
let path = path.as_ref();
122109
let ext = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
123-
let object_hash = git::hash::Kind::Sha1; // TODO: make it configurable via Context/CLI
124110
const CACHE_SIZE: usize = 64;
125111
let cache = || -> EitherCache<CACHE_SIZE> {
126112
if matches!(algorithm, Algorithm::LessMemory) {
@@ -160,11 +146,13 @@ where
160146
idx.verify_integrity(
161147
pack.as_ref().map(|p| git::odb::pack::index::verify::PackContext {
162148
data: p,
163-
verify_mode: mode,
164-
traversal_algorithm: algorithm.into(),
165-
make_cache_fn: cache,
149+
options: git::odb::pack::index::verify::integrity::Options {
150+
verify_mode: mode,
151+
traversal: algorithm.into(),
152+
make_pack_lookup_cache: cache,
153+
thread_limit
154+
}
166155
}),
167-
thread_limit,
168156
progress,
169157
should_interrupt,
170158
)

Diff for: src/plumbing/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub fn main() -> Result<()> {
144144
format,
145145
out: std::io::stdout(),
146146
should_interrupt,
147+
object_hash,
147148
},
148149
);
149150
return futures_lite::future::block_on(fut);
@@ -174,6 +175,7 @@ pub fn main() -> Result<()> {
174175
format,
175176
should_interrupt,
176177
out,
178+
object_hash,
177179
},
178180
)
179181
},
@@ -203,6 +205,7 @@ pub fn main() -> Result<()> {
203205
sink_compress,
204206
verify,
205207
should_interrupt,
208+
object_hash,
206209
},
207210
)
208211
},
@@ -237,6 +240,7 @@ pub fn main() -> Result<()> {
237240
mode,
238241
algorithm,
239242
should_interrupt: &should_interrupt,
243+
object_hash,
240244
},
241245
)
242246
},

0 commit comments

Comments
 (0)