@@ -2,10 +2,10 @@ use std::{io, path::Path, str::FromStr, sync::atomic::AtomicBool};
2
2
3
3
use anyhow:: { anyhow, Context as AnyhowContext , Result } ;
4
4
use bytesize:: ByteSize ;
5
+ use git_pack_for_configuration_only:: index:: traverse:: Outcome ;
5
6
use git_repository as git;
6
7
use git_repository:: {
7
8
easy:: object,
8
- hash:: ObjectId ,
9
9
odb,
10
10
odb:: { pack, pack:: index} ,
11
11
Progress ,
@@ -113,19 +113,27 @@ pub fn pack_or_pack_index<W1, W2>(
113
113
algorithm,
114
114
should_interrupt,
115
115
} : Context < ' _ , W1 , W2 > ,
116
- ) -> Result < ( ObjectId , Option < index :: traverse :: Outcome > ) >
116
+ ) -> Result < ( ) >
117
117
where
118
118
W1 : io:: Write ,
119
119
W2 : io:: Write ,
120
120
{
121
121
let path = path. as_ref ( ) ;
122
- let ext = path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) . ok_or_else ( || {
123
- anyhow ! (
124
- "Cannot determine data type on path without extension '{}', expecting default extensions 'idx' and 'pack'" ,
125
- path. display( )
126
- )
127
- } ) ?;
122
+ let ext = path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) . unwrap_or ( "" ) ;
128
123
let object_hash = git:: hash:: Kind :: Sha1 ; // TODO: make it configurable via Context/CLI
124
+ const CACHE_SIZE : usize = 64 ;
125
+ let cache = || -> EitherCache < CACHE_SIZE > {
126
+ if matches ! ( algorithm, Algorithm :: LessMemory ) {
127
+ if output_statistics. is_some ( ) {
128
+ // turn off acceleration as we need to see entire chains all the time
129
+ EitherCache :: Left ( pack:: cache:: Never )
130
+ } else {
131
+ EitherCache :: Right ( pack:: cache:: lru:: StaticLinkedList :: < CACHE_SIZE > :: default ( ) )
132
+ }
133
+ } else {
134
+ EitherCache :: Left ( pack:: cache:: Never )
135
+ }
136
+ } ;
129
137
let res = match ext {
130
138
"pack" => {
131
139
let pack = odb:: pack:: data:: File :: at ( path, object_hash) . with_context ( || "Could not open pack file" ) ?;
@@ -148,19 +156,6 @@ where
148
156
e
149
157
} )
150
158
. ok ( ) ;
151
- const CACHE_SIZE : usize = 64 ;
152
- let cache = || -> EitherCache < CACHE_SIZE > {
153
- if matches ! ( algorithm, Algorithm :: LessMemory ) {
154
- if output_statistics. is_some ( ) {
155
- // turn off acceleration as we need to see entire chains all the time
156
- EitherCache :: Left ( pack:: cache:: Never )
157
- } else {
158
- EitherCache :: Right ( pack:: cache:: lru:: StaticLinkedList :: < CACHE_SIZE > :: default ( ) )
159
- }
160
- } else {
161
- EitherCache :: Left ( pack:: cache:: Never )
162
- }
163
- } ;
164
159
165
160
idx. verify_integrity (
166
161
pack. as_ref ( ) . map ( |p| git:: odb:: pack:: index:: verify:: PackContext {
@@ -176,18 +171,42 @@ where
176
171
. map ( |o| ( o. actual_index_checksum , o. pack_traverse_outcome ) )
177
172
. with_context ( || "Verification failure" ) ?
178
173
}
174
+ "" => {
175
+ match path. file_name ( ) {
176
+ Some ( file_name) if file_name == "multi-pack-index" => {
177
+ let multi_index = git:: odb:: pack:: multi_index:: File :: at ( path) ?;
178
+ let res = multi_index. verify_integrity ( mode, algorithm. into ( ) , cache, thread_limit, progress, should_interrupt) ?;
179
+ for stats in res. pack_traverse_outcomes {
180
+ output_outcome ( & mut out, output_statistics, & stats) ?;
181
+ }
182
+ return Ok ( ( ) )
183
+ } ,
184
+ _ => return Err ( anyhow ! (
185
+ "Cannot determine data type on path without extension '{}', expecting default extensions 'idx' and 'pack'" ,
186
+ path. display( )
187
+ ) )
188
+ }
189
+ }
179
190
ext => return Err ( anyhow ! ( "Unknown extension {:?}, expecting 'idx' or 'pack'" , ext) ) ,
180
191
} ;
181
192
if let Some ( stats) = res. 1 . as_ref ( ) {
182
- #[ cfg_attr( not( feature = "serde1" ) , allow( clippy:: single_match) ) ]
183
- match output_statistics {
184
- Some ( OutputFormat :: Human ) => drop ( print_statistics ( & mut out, stats) ) ,
185
- #[ cfg( feature = "serde1" ) ]
186
- Some ( OutputFormat :: Json ) => serde_json:: to_writer_pretty ( out, stats) ?,
187
- _ => { }
188
- } ;
193
+ output_outcome ( & mut out, output_statistics, stats) ?;
189
194
}
190
- Ok ( res)
195
+ Ok ( ( ) )
196
+ }
197
+
198
+ fn output_outcome < W1 > ( mut out : & mut W1 , output_statistics : Option < OutputFormat > , stats : & Outcome ) -> anyhow:: Result < ( ) >
199
+ where
200
+ W1 : io:: Write ,
201
+ {
202
+ #[ cfg_attr( not( feature = "serde1" ) , allow( clippy:: single_match) ) ]
203
+ match output_statistics {
204
+ Some ( OutputFormat :: Human ) => drop ( print_statistics ( & mut out, stats) ) ,
205
+ #[ cfg( feature = "serde1" ) ]
206
+ Some ( OutputFormat :: Json ) => serde_json:: to_writer_pretty ( out, stats) ?,
207
+ _ => { }
208
+ } ;
209
+ Ok ( ( ) )
191
210
}
192
211
193
212
fn print_statistics ( out : & mut impl io:: Write , stats : & index:: traverse:: Outcome ) -> io:: Result < ( ) > {
0 commit comments