1
1
use crate :: pack;
2
+ use crate :: store:: verify:: integrity:: { IndexStatistics , SingleOrMultiStatistics } ;
2
3
use crate :: types:: IndexAndPacks ;
3
4
use git_features:: progress:: Progress ;
4
5
use std:: ops:: Deref ;
5
6
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
6
7
7
- #[ allow( missing_docs, unused) ]
8
-
9
8
///
10
9
pub mod integrity {
11
10
use crate :: pack;
11
+ use std:: path:: PathBuf ;
12
12
13
13
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
14
14
#[ derive( Debug , thiserror:: Error ) ]
@@ -21,6 +21,8 @@ pub mod integrity {
21
21
#[ error( transparent) ]
22
22
IndexOpen ( #[ from] pack:: index:: init:: Error ) ,
23
23
#[ error( transparent) ]
24
+ LooseObjectStoreIntegrity ( #[ from] crate :: loose:: verify:: integrity:: Error ) ,
25
+ #[ error( transparent) ]
24
26
MultiIndexOpen ( #[ from] pack:: multi_index:: init:: Error ) ,
25
27
#[ error( transparent) ]
26
28
PackOpen ( #[ from] pack:: data:: init:: Error ) ,
@@ -30,10 +32,41 @@ pub mod integrity {
30
32
NeedsRetryDueToChangeOnDisk ,
31
33
}
32
34
35
+ #[ derive( Debug , PartialEq , Eq , Hash , Ord , PartialOrd , Clone ) ]
36
+ #[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
37
+ /// Integrity information about loose object databases
38
+ pub struct LooseObjectStatistics {
39
+ /// The path to the root directory of the loose objects database
40
+ pub path : PathBuf ,
41
+ /// The statistics created after verifying the loose object database.
42
+ pub statistics : crate :: loose:: verify:: integrity:: Statistics ,
43
+ }
44
+
45
+ #[ derive( Debug , PartialEq , Eq , Hash , Ord , PartialOrd , Clone ) ]
46
+ #[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
47
+ /// Traversal statistics of packs governed by single indices or multi-pack indices.
48
+ #[ allow( missing_docs) ]
49
+ pub enum SingleOrMultiStatistics {
50
+ Single ( pack:: index:: traverse:: Statistics ) ,
51
+ Multi ( Vec < ( PathBuf , pack:: index:: traverse:: Statistics ) > ) ,
52
+ }
53
+
54
+ /// Statistics gathered when traversing packs of various kinds of indices.
55
+ #[ derive( Debug , PartialEq , Eq , Hash , Ord , PartialOrd , Clone ) ]
56
+ #[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
57
+ pub struct IndexStatistics {
58
+ /// The path to the index or multi-pack index for which statics were gathered.
59
+ pub path : PathBuf ,
60
+ /// The actual statistics for the index at `path`.
61
+ pub statistics : SingleOrMultiStatistics ,
62
+ }
63
+
33
64
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
34
65
pub struct Outcome < P > {
35
- /// Pack traversal statistics for each pack whose objects were checked.
36
- pub pack_traverse_statistics : Vec < pack:: index:: traverse:: Statistics > ,
66
+ /// Statistics for validated loose object stores.
67
+ pub loose_object_stores : Vec < LooseObjectStatistics > ,
68
+ /// Pack traversal statistics for each index and their pack(s)
69
+ pub index_statistics : Vec < IndexStatistics > ,
37
70
/// The provided progress instance.
38
71
pub progress : P ,
39
72
}
@@ -104,11 +137,14 @@ impl super::Store {
104
137
progress. add_child ( "Checking integrity" ) ,
105
138
should_interrupt,
106
139
) ?;
107
- statistics. push (
108
- outcome
109
- . pack_traverse_statistics
110
- . expect ( "pack provided so there are stats" ) ,
111
- ) ;
140
+ statistics. push ( IndexStatistics {
141
+ path : bundle. index . path ( ) . to_owned ( ) ,
142
+ statistics : SingleOrMultiStatistics :: Single (
143
+ outcome
144
+ . pack_traverse_statistics
145
+ . expect ( "pack provided so there are stats" ) ,
146
+ ) ,
147
+ } ) ;
112
148
}
113
149
IndexAndPacks :: MultiIndex ( bundle) => {
114
150
let index;
@@ -124,18 +160,45 @@ impl super::Store {
124
160
should_interrupt,
125
161
options. clone ( ) ,
126
162
) ?;
127
- statistics. extend ( outcome. pack_traverse_statistics ) ;
163
+
164
+ let index_dir = bundle. multi_index . path ( ) . parent ( ) . expect ( "file in a directory" ) ;
165
+ statistics. push ( IndexStatistics {
166
+ path : Default :: default ( ) ,
167
+ statistics : SingleOrMultiStatistics :: Multi (
168
+ outcome
169
+ . pack_traverse_statistics
170
+ . into_iter ( )
171
+ . zip ( index. index_names ( ) )
172
+ . map ( |( statistics, index_name) | ( index_dir. join ( index_name) , statistics) )
173
+ . collect ( ) ,
174
+ ) ,
175
+ } ) ;
128
176
}
129
177
}
130
178
progress. inc ( ) ;
131
179
}
132
180
133
- for _loose_db in & * index. loose_dbs {
134
- // TODO: impl verify integrity for loose object databases
181
+ progress. init (
182
+ Some ( index. loose_dbs . len ( ) ) ,
183
+ git_features:: progress:: count ( "loose object stores" ) ,
184
+ ) ;
185
+ let mut loose_object_stores = Vec :: new ( ) ;
186
+ for loose_db in & * index. loose_dbs {
187
+ let out = loose_db
188
+ . verify_integrity (
189
+ progress. add_child ( loose_db. path ( ) . display ( ) . to_string ( ) ) ,
190
+ should_interrupt,
191
+ )
192
+ . map ( |statistics| integrity:: LooseObjectStatistics {
193
+ path : loose_db. path ( ) . to_owned ( ) ,
194
+ statistics,
195
+ } ) ?;
196
+ loose_object_stores. push ( out) ;
135
197
}
136
198
137
199
Ok ( integrity:: Outcome {
138
- pack_traverse_statistics : statistics,
200
+ loose_object_stores,
201
+ index_statistics : statistics,
139
202
progress,
140
203
} )
141
204
}
0 commit comments