Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7add82c

Browse files
committed
refactor
1 parent 3b927e5 commit 7add82c

4 files changed

Lines changed: 48 additions & 37 deletions

File tree

git-features/src/parallel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub trait Reducer {
33
type Output;
44
type Error;
55
fn feed(&mut self, input: Self::Input) -> Result<(), Self::Error>;
6-
fn finalize(&mut self) -> Result<Self::Output, Self::Error>;
6+
fn finalize(self) -> Result<Self::Output, Self::Error>;
77
}
88

99
mod serial {

git-odb/src/pack/file/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ struct Delta {
1717
data_offset: u64,
1818
}
1919

20-
#[derive(Debug)]
20+
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
2121
pub enum ResolvedBase {
2222
InPack(Entry),
2323
OutOfPack { kind: object::Kind, end: usize },
2424
}
2525

26-
#[derive(Debug, Clone, Copy)]
26+
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
2727
pub struct DecodeEntryResult {
2828
pub kind: object::Kind,
2929
pub num_deltas: u32,

git-odb/src/pack/index/verify.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{pack, pack::index};
33
use git_features::progress::{self, Progress};
44
use git_object::SHA1_SIZE;
55
use quick_error::quick_error;
6+
use smallvec::alloc::collections::BTreeMap;
67
use std::time::Instant;
78

89
quick_error! {
@@ -59,6 +60,14 @@ impl Into<String> for TimeThroughput {
5960
}
6061
}
6162

63+
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
64+
pub struct FileChecksumResult {
65+
/// The sha1 over the whole index file
66+
id: git_object::Id,
67+
average: DecodeEntryResult,
68+
objects_per_chain_length: BTreeMap<u32, u32>,
69+
}
70+
6271
/// Methods to verify and validate the content of the index file
6372
impl index::File {
6473
pub fn checksum_of_index(&self) -> git_object::Id {
@@ -133,40 +142,34 @@ impl index::File {
133142

134143
fn add_decode_result(
135144
DecodeEntryResult {
136-
kind,
137-
num_deltas,
138-
decompressed_size,
139-
compressed_size,
140-
object_size,
141-
}: DecodeEntryResult,
145+
kind: _,
146+
mut num_deltas,
147+
mut decompressed_size,
148+
mut compressed_size,
149+
mut object_size,
150+
}: &mut DecodeEntryResult,
142151
rhs: DecodeEntryResult,
143-
) -> DecodeEntryResult {
144-
DecodeEntryResult {
145-
kind,
146-
num_deltas: num_deltas + rhs.num_deltas,
147-
decompressed_size: decompressed_size + rhs.decompressed_size,
148-
compressed_size: compressed_size + rhs.compressed_size,
149-
object_size: object_size + rhs.object_size,
150-
}
152+
) {
153+
num_deltas += rhs.num_deltas;
154+
decompressed_size += rhs.decompressed_size;
155+
compressed_size += rhs.compressed_size;
156+
object_size += rhs.object_size;
151157
}
152158

153159
fn div_decode_result(
154160
DecodeEntryResult {
155-
kind,
156-
num_deltas,
157-
decompressed_size,
158-
compressed_size,
159-
object_size,
160-
}: DecodeEntryResult,
161+
kind: _,
162+
mut num_deltas,
163+
mut decompressed_size,
164+
mut compressed_size,
165+
mut object_size,
166+
}: &mut DecodeEntryResult,
161167
div: usize,
162-
) -> DecodeEntryResult {
163-
DecodeEntryResult {
164-
kind,
165-
num_deltas: num_deltas / div as u32,
166-
decompressed_size: decompressed_size / div as u64,
167-
compressed_size: compressed_size / div,
168-
object_size: object_size / div as u64,
169-
}
168+
) {
169+
num_deltas /= div as u32;
170+
decompressed_size /= div as u64;
171+
compressed_size /= div;
172+
object_size /= div as u64;
170173
}
171174

172175
struct Reducer<'a, P> {
@@ -189,14 +192,15 @@ impl index::File {
189192
self.entries_seen += num_entries as u32;
190193
self.chunks_seen += 1;
191194

192-
self.stats = add_decode_result(self.stats, chunk_stats);
195+
add_decode_result(&mut self.stats, chunk_stats);
193196
self.progress.lock().unwrap().set(self.entries_seen);
194197
Ok(())
195198
}
196199

197-
fn finalize(&mut self) -> Result<Self::Output, Self::Error> {
200+
fn finalize(mut self) -> Result<Self::Output, Self::Error> {
198201
self.progress.lock().unwrap().done("finished");
199-
Ok(div_decode_result(self.stats, self.chunks_seen))
202+
div_decode_result(&mut self.stats, self.chunks_seen);
203+
Ok(self.stats)
200204
}
201205
}
202206

@@ -256,7 +260,7 @@ impl index::File {
256260
})?;
257261
let object_kind = entry_stats.kind;
258262
let consumed_input = entry_stats.compressed_size;
259-
stats = add_decode_result(stats, entry_stats);
263+
add_decode_result(&mut stats, entry_stats);
260264

261265
let mut header_buf = [0u8; 64];
262266
let header_size = crate::loose::db::serde::write_header(
@@ -294,7 +298,7 @@ impl index::File {
294298
}
295299
progress.set(idx as u32);
296300
}
297-
stats = div_decode_result(stats, entries.len());
301+
div_decode_result(&mut stats, entries.len());
298302
Ok((entries.len(), stats))
299303
},
300304
Reducer {

src/plumbing/lean.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ mod options {
1919
#[derive(FromArgs, PartialEq, Debug)]
2020
#[argh(subcommand, name = "verify-pack")]
2121
pub struct VerifyPack {
22+
/// if set, output statistical information about the pack
23+
#[argh(switch, short = 's')]
24+
pub statistics: bool,
2225
/// if set, verbose progress messages are printed line by line
2326
#[argh(switch, short = 'v')]
2427
pub verbose: bool,
@@ -37,7 +40,11 @@ pub fn main() -> Result<()> {
3740
pub use options::*;
3841
let cli: Args = argh::from_env();
3942
match cli.subcommand {
40-
SubCommands::VerifyPack(VerifyPack { path, verbose }) => {
43+
SubCommands::VerifyPack(VerifyPack {
44+
path,
45+
verbose,
46+
statistics,
47+
}) => {
4148
super::init_env_logger(verbose);
4249
core::verify_pack_or_pack_index(
4350
path,

0 commit comments

Comments
 (0)