1
+ use std:: sync:: Mutex ;
1
2
use std:: {
2
3
fs,
3
4
io:: Read ,
@@ -137,7 +138,7 @@ pub fn pack_or_pack_index(
137
138
pack_path : impl AsRef < Path > ,
138
139
object_path : Option < impl AsRef < Path > > ,
139
140
check : SafetyCheck ,
140
- progress : impl Progress ,
141
+ mut progress : impl Progress ,
141
142
Context {
142
143
thread_limit,
143
144
delete_pack,
@@ -178,7 +179,8 @@ pub fn pack_or_pack_index(
178
179
}
179
180
} ) ;
180
181
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
182
184
. index
183
185
. traverse (
184
186
& bundle. pack ,
@@ -187,30 +189,40 @@ pub fn pack_or_pack_index(
187
189
{
188
190
let object_path = object_path. map ( |p| p. as_ref ( ) . to_owned ( ) ) ;
189
191
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 ( ) ;
191
195
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 ,
198
201
} ) ?;
199
202
if written_id != index_entry. oid {
200
203
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
+ } ;
205
210
} 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
+ } ) ;
207
216
}
208
217
}
209
218
if let Some ( verifier) = loose_odb. as_ref ( ) {
210
219
let obj = verifier
211
220
. 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 } ) ?;
214
226
obj. verify_checksum ( written_id) ?;
215
227
}
216
228
Ok ( ( ) )
@@ -220,7 +232,7 @@ pub fn pack_or_pack_index(
220
232
traversal : algorithm,
221
233
thread_limit,
222
234
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,
224
236
} ,
225
237
)
226
238
. with_context ( || "Failed to explode the entire pack - some loose objects may have been created nonetheless" ) ?;
0 commit comments