Skip to content

Commit 1f34844

Browse files
committed
adjust to changes in gix-pack
1 parent 0a65eaa commit 1f34844

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

gitoxide-core/src/pack/explode.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::sync::Mutex;
12
use std::{
23
fs,
34
io::Read,
@@ -137,7 +138,7 @@ pub fn pack_or_pack_index(
137138
pack_path: impl AsRef<Path>,
138139
object_path: Option<impl AsRef<Path>>,
139140
check: SafetyCheck,
140-
progress: impl Progress,
141+
mut progress: impl Progress,
141142
Context {
142143
thread_limit,
143144
delete_pack,
@@ -178,7 +179,8 @@ pub fn pack_or_pack_index(
178179
}
179180
});
180181

181-
let pack::index::traverse::Outcome{mut progress, ..} = bundle
182+
let sub_progress = Arc::new(Mutex::new(progress.add_child("validate object")));
183+
let pack::index::traverse::Outcome { mut progress, .. } = bundle
182184
.index
183185
.traverse(
184186
&bundle.pack,
@@ -187,30 +189,40 @@ pub fn pack_or_pack_index(
187189
{
188190
let object_path = object_path.map(|p| p.as_ref().to_owned());
189191
let out = OutputWriter::new(object_path.clone(), sink_compress, object_hash);
190-
let loose_odb = verify.then(|| object_path.as_ref().map(|path| loose::Store::at(path, object_hash))).flatten();
192+
let loose_odb = verify
193+
.then(|| object_path.as_ref().map(|path| loose::Store::at(path, object_hash)))
194+
.flatten();
191195
let mut read_buf = Vec::new();
192-
move |object_kind, buf, index_entry, progress| {
193-
let written_id = out.write_buf(object_kind, buf).map_err(|err| {
194-
Error::Write{source: Box::new(err) as Box<dyn std::error::Error + Send + Sync>,
195-
kind: object_kind,
196-
id: index_entry.oid,
197-
}
196+
move |object_kind, buf, index_entry| {
197+
let written_id = out.write_buf(object_kind, buf).map_err(|err| Error::Write {
198+
source: Box::new(err) as Box<dyn std::error::Error + Send + Sync>,
199+
kind: object_kind,
200+
id: index_entry.oid,
198201
})?;
199202
if written_id != index_entry.oid {
200203
if let object::Kind::Tree = object_kind {
201-
progress.info(format!(
202-
"The tree in pack named {} was written as {} due to modes 100664 and 100640 rewritten as 100644.",
203-
index_entry.oid, written_id
204-
));
204+
if let Ok(mut progress) = sub_progress.lock() {
205+
progress.info(format!(
206+
"The tree in pack named {} was written as {} due to modes 100664 and 100640 rewritten as 100644.",
207+
index_entry.oid, written_id
208+
));
209+
};
205210
} else {
206-
return Err(Error::ObjectEncodeMismatch{kind: object_kind, actual: index_entry.oid, expected:written_id});
211+
return Err(Error::ObjectEncodeMismatch {
212+
kind: object_kind,
213+
actual: index_entry.oid,
214+
expected: written_id,
215+
});
207216
}
208217
}
209218
if let Some(verifier) = loose_odb.as_ref() {
210219
let obj = verifier
211220
.try_find(written_id, &mut read_buf)
212-
.map_err(|err| Error::WrittenFileCorrupt{source:err, id:written_id})?
213-
.ok_or(Error::WrittenFileMissing{id:written_id})?;
221+
.map_err(|err| Error::WrittenFileCorrupt {
222+
source: err,
223+
id: written_id,
224+
})?
225+
.ok_or(Error::WrittenFileMissing { id: written_id })?;
214226
obj.verify_checksum(written_id)?;
215227
}
216228
Ok(())
@@ -220,7 +232,7 @@ pub fn pack_or_pack_index(
220232
traversal: algorithm,
221233
thread_limit,
222234
check: check.into(),
223-
make_pack_lookup_cache: pack::cache::lru::StaticLinkedList::<64>::default,
235+
make_pack_lookup_cache: pack::cache::lru::StaticLinkedList::<64>::default,
224236
},
225237
)
226238
.with_context(|| "Failed to explode the entire pack - some loose objects may have been created nonetheless")?;

0 commit comments

Comments
 (0)