@@ -7,78 +7,6 @@ pub fn init(directory: Option<PathBuf>) -> Result<git_repository::Path> {
77 . with_context ( || "Repository initialization failed" )
88}
99
10- pub mod verify {
11- use std:: { path:: PathBuf , sync:: atomic:: AtomicBool } ;
10+ pub mod tree;
1211
13- use git_repository as git;
14- use git_repository:: Progress ;
15-
16- use crate :: { pack, OutputFormat } ;
17-
18- /// A general purpose context for many operations provided here
19- pub struct Context {
20- /// If set, provide statistics to `out` in the given format
21- pub output_statistics : Option < OutputFormat > ,
22- /// If set, don't use more than this amount of threads.
23- /// Otherwise, usually use as many threads as there are logical cores.
24- /// A value of 0 is interpreted as no-limit
25- pub thread_limit : Option < usize > ,
26- pub verify_mode : pack:: verify:: Mode ,
27- pub algorithm : pack:: verify:: Algorithm ,
28- }
29-
30- pub const PROGRESS_RANGE : std:: ops:: RangeInclusive < u8 > = 1 ..=3 ;
31-
32- pub fn integrity (
33- repo : PathBuf ,
34- mut out : impl std:: io:: Write ,
35- progress : impl Progress ,
36- should_interrupt : & AtomicBool ,
37- Context {
38- output_statistics,
39- thread_limit,
40- verify_mode,
41- algorithm,
42- } : Context ,
43- ) -> anyhow:: Result < ( ) > {
44- let repo = git_repository:: open ( repo) ?;
45- #[ cfg_attr( not( feature = "serde1" ) , allow( unused) ) ]
46- let mut outcome = repo. objects . store_ref ( ) . verify_integrity (
47- progress,
48- should_interrupt,
49- git_repository:: odb:: pack:: index:: verify:: integrity:: Options {
50- verify_mode,
51- traversal : algorithm. into ( ) ,
52- thread_limit,
53- // TODO: a way to get the pack cache from a handle
54- make_pack_lookup_cache : || git_repository:: odb:: pack:: cache:: Never ,
55- } ,
56- ) ?;
57- // TODO: make this work for indices in multiple workspaces, once we have workspace support
58- if let Some ( index) = repo. load_index ( ) . transpose ( ) ? {
59- index. verify_integrity ( ) ?;
60- index. verify_entries ( ) ?;
61- index. verify_extensions ( true , {
62- use git:: odb:: FindExt ;
63- let objects = repo. objects ;
64- move |oid, buf : & mut Vec < u8 > | objects. find_tree_iter ( oid, buf) . ok ( )
65- } ) ?;
66- outcome. progress . info ( format ! ( "Index at '{}' OK" , index. path. display( ) ) ) ;
67- }
68- match output_statistics {
69- Some ( OutputFormat :: Human ) => writeln ! ( out, "Human output is currently unsupported, use JSON instead" ) ?,
70- #[ cfg( feature = "serde1" ) ]
71- Some ( OutputFormat :: Json ) => {
72- serde_json:: to_writer_pretty (
73- out,
74- & serde_json:: json!( {
75- "index_statistics" : outcome. index_statistics,
76- "loose_object-stores" : outcome. loose_object_stores
77- } ) ,
78- ) ?;
79- }
80- None => { }
81- }
82- Ok ( ( ) )
83- }
84- }
12+ pub mod verify;
0 commit comments