@@ -39,26 +39,64 @@ impl FromStr for OutputFormat {
39
39
}
40
40
}
41
41
42
+ /// A general purpose context for many operations provided here
42
43
pub struct Context < W1 : io:: Write , W2 : io:: Write > {
43
44
/// If set, provide statistics to `out` in the given format
44
45
pub output_statistics : Option < OutputFormat > ,
45
46
/// A stream to which to output operation results
46
47
pub out : W1 ,
47
48
/// A stream to which to errors
48
49
pub err : W2 ,
50
+ /// If set, don't use more than this amount of threads.
51
+ /// Otherwise, usually use as many threads as there are logical cores.
52
+ /// A value of 0 is interpreted as no-limit
53
+ pub thread_limit : Option < usize > ,
54
+ }
55
+
56
+ impl Default for Context < Vec < u8 > , Vec < u8 > > {
57
+ fn default ( ) -> Self {
58
+ Context {
59
+ output_statistics : None ,
60
+ thread_limit : None ,
61
+ out : Vec :: new ( ) ,
62
+ err : Vec :: new ( ) ,
63
+ }
64
+ }
49
65
}
50
66
51
67
pub fn init ( ) -> Result < ( ) > {
52
68
git_repository:: init:: repository ( ) . with_context ( || "Repository initialization failed" )
53
69
}
54
70
71
+ enum EitherCache {
72
+ Left ( pack:: cache:: DecodeEntryNoop ) ,
73
+ Right ( pack:: cache:: DecodeEntryLRU ) ,
74
+ }
75
+
76
+ impl pack:: cache:: DecodeEntry for EitherCache {
77
+ fn put ( & mut self , offset : u64 , data : & [ u8 ] , kind : Kind , compressed_size : usize ) {
78
+ match self {
79
+ EitherCache :: Left ( v) => v. put ( offset, data, kind, compressed_size) ,
80
+ EitherCache :: Right ( v) => v. put ( offset, data, kind, compressed_size) ,
81
+ }
82
+ }
83
+
84
+ fn get ( & mut self , offset : u64 , out : & mut Vec < u8 > ) -> Option < ( Kind , usize ) > {
85
+ match self {
86
+ EitherCache :: Left ( v) => v. get ( offset, out) ,
87
+ EitherCache :: Right ( v) => v. get ( offset, out) ,
88
+ }
89
+ }
90
+ }
91
+
55
92
pub fn verify_pack_or_pack_index < P , W1 , W2 > (
56
93
path : impl AsRef < Path > ,
57
94
progress : Option < P > ,
58
95
Context {
59
96
mut out,
60
97
mut err,
61
98
output_statistics,
99
+ thread_limit,
62
100
} : Context < W1 , W2 > ,
63
101
) -> Result < ( git_object:: Id , Option < index:: PackFileChecksumResult > ) >
64
102
where
@@ -94,25 +132,6 @@ where
94
132
Err ( e)
95
133
} )
96
134
. ok ( ) ;
97
- enum EitherCache {
98
- Left ( pack:: cache:: DecodeEntryNoop ) ,
99
- Right ( pack:: cache:: DecodeEntryLRU ) ,
100
- } ;
101
- impl pack:: cache:: DecodeEntry for EitherCache {
102
- fn put ( & mut self , offset : u64 , data : & [ u8 ] , kind : Kind , compressed_size : usize ) {
103
- match self {
104
- EitherCache :: Left ( v) => v. put ( offset, data, kind, compressed_size) ,
105
- EitherCache :: Right ( v) => v. put ( offset, data, kind, compressed_size) ,
106
- }
107
- }
108
-
109
- fn get ( & mut self , offset : u64 , out : & mut Vec < u8 > ) -> Option < ( Kind , usize ) > {
110
- match self {
111
- EitherCache :: Left ( v) => v. get ( offset, out) ,
112
- EitherCache :: Right ( v) => v. get ( offset, out) ,
113
- }
114
- }
115
- }
116
135
idx. verify_checksum_of_index ( pack. as_ref ( ) , progress, || -> EitherCache {
117
136
if output_statistics. is_some ( ) {
118
137
// turn off acceleration as we need to see entire chains all the time
0 commit comments