diff --git a/src/archiver/archiver_impl.rs b/src/archiver/archiver_impl.rs index be8de89..4737b1e 100644 --- a/src/archiver/archiver_impl.rs +++ b/src/archiver/archiver_impl.rs @@ -51,14 +51,14 @@ impl Archiver { BlobType::Data, indexer.clone(), config, - index.total_size(&BlobType::Data), + index.total_size(BlobType::Data), )?; let tree_packer = Packer::new( be.clone(), BlobType::Tree, indexer.clone(), config, - index.total_size(&BlobType::Tree), + index.total_size(BlobType::Tree), )?; Ok(Self { path: PathBuf::default(), @@ -231,7 +231,7 @@ impl Archiver { node: Node, p: ProgressBar, ) -> Result<()> { - let mut chunks: Vec<_> = ChunkIter::new(r, *node.meta().size() as usize, &self.poly) + let mut chunks: Vec<_> = ChunkIter::new(r, *node.meta().size() as usize, self.poly) .enumerate() // see below .par_bridge() .map(|(num, chunk)| { diff --git a/src/backend/mod.rs b/src/backend/mod.rs index f91a296..6bfc252 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -47,8 +47,8 @@ pub enum FileType { } impl FileType { - pub fn name(&self) -> &str { - match &self { + pub fn name(self) -> &'static str { + match self { FileType::Config => "config", FileType::Snapshot => "snapshots", FileType::Index => "index", @@ -57,7 +57,7 @@ impl FileType { } } - pub fn is_cacheable(&self) -> bool { + pub fn is_cacheable(self) -> bool { match self { FileType::Config | FileType::Key | FileType::Pack => false, FileType::Snapshot | FileType::Index => true, diff --git a/src/blob/mod.rs b/src/blob/mod.rs index 6f7f87b..ecdac4c 100644 --- a/src/blob/mod.rs +++ b/src/blob/mod.rs @@ -23,7 +23,7 @@ pub enum BlobType { } impl BlobType { - pub fn is_cacheable(&self) -> bool { + pub fn is_cacheable(self) -> bool { match self { BlobType::Tree => true, BlobType::Data => false, diff --git a/src/chunker.rs b/src/chunker.rs index b89c3d1..94588e8 100644 --- a/src/chunker.rs +++ b/src/chunker.rs @@ -29,13 +29,13 @@ pub struct ChunkIter { } impl ChunkIter { - pub fn new(reader: R, size_hint: usize, poly: &Polynom64) -> Self { + pub fn new(reader: R, size_hint: usize, poly: Polynom64) -> Self { Self { buf: Vec::with_capacity(4 * KB), pos: 0, reader, predicate: default_predicate, - rabin: Rabin64::new_with_polynom(6, poly), + rabin: Rabin64::new_with_polynom(6, &poly), size_hint, // size hint is used to optimize memory allocation; this should be an upper bound on the size min_size: MIN_SIZE, max_size: MAX_SIZE, @@ -165,7 +165,7 @@ impl PolynomExtend for Polynom64 { // Finite Fields". fn irreducible(&self) -> bool { for i in 1..=self.degree() / 2 { - if self.gcd(&qp(i, self)) != 1 { + if self.gcd(&qp(i, *self)) != 1 { return false; } } @@ -219,17 +219,17 @@ impl PolynomExtend for Polynom64 { // qp computes the polynomial (x^(2^p)-x) mod g. This is needed for the // reducibility test. -fn qp(p: i32, g: &Polynom64) -> Polynom64 { +fn qp(p: i32, g: Polynom64) -> Polynom64 { // start with x let mut res: Polynom64 = 2; for _ in 0..p { // repeatedly square res - res = res.mulmod(&res, g); + res = res.mulmod(&res, &g); } // add x - res.add(&2).modulo(g) + res.add(&2).modulo(&g) } #[cfg(test)] @@ -243,7 +243,7 @@ mod tests { let mut reader = Cursor::new(empty); let poly = random_poly().unwrap(); - let chunker = ChunkIter::new(&mut reader, 0, &poly); + let chunker = ChunkIter::new(&mut reader, 0, poly); let chunks: Vec<_> = chunker.into_iter().collect(); assert_eq!(0, chunks.len()); @@ -255,7 +255,7 @@ mod tests { let mut reader = Cursor::new(empty); let poly = random_poly().unwrap(); - let chunker = ChunkIter::new(&mut reader, 100, &poly); + let chunker = ChunkIter::new(&mut reader, 100, poly); let chunks: Vec<_> = chunker.into_iter().collect(); assert_eq!(0, chunks.len()); @@ -266,7 +266,7 @@ mod tests { let mut reader = repeat(0u8); let poly = random_poly().unwrap(); - let mut chunker = ChunkIter::new(&mut reader, usize::MAX, &poly); + let mut chunker = ChunkIter::new(&mut reader, usize::MAX, poly); let chunk = chunker.next().unwrap().unwrap(); assert_eq!(MIN_SIZE, chunk.len()); diff --git a/src/commands/cat.rs b/src/commands/cat.rs index 2ffe516..cc44947 100644 --- a/src/commands/cat.rs +++ b/src/commands/cat.rs @@ -75,7 +75,7 @@ fn cat_file(be: &impl DecryptReadBackend, tpe: FileType, opt: IdOpt) -> Result<( fn cat_blob(be: &impl DecryptReadBackend, tpe: BlobType, opt: IdOpt) -> Result<()> { let id = Id::from_hex(&opt.id)?; - let data = IndexBackend::new(be, ProgressBar::hidden())?.blob_from_backend(&tpe, &id)?; + let data = IndexBackend::new(be, ProgressBar::hidden())?.blob_from_backend(tpe, &id)?; print!("{}", String::from_utf8(data.to_vec())?); Ok(()) @@ -93,7 +93,7 @@ fn cat_tree( let index = IndexBackend::new(be, progress_counter(""))?; let node = Tree::node_from_path(&index, snap.tree, Path::new(path))?; let id = node.subtree.ok_or_else(|| anyhow!("{path} is no dir"))?; - let data = index.blob_from_backend(&BlobType::Tree, &id)?; + let data = index.blob_from_backend(BlobType::Tree, &id)?; println!("{}", String::from_utf8(data.to_vec())?); Ok(()) diff --git a/src/commands/copy.rs b/src/commands/copy.rs index 8c1bdb4..bf5f714 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -98,14 +98,14 @@ fn copy( BlobType::Data, indexer.clone(), &repo_dest.config, - index.total_size(&BlobType::Data), + index.total_size(BlobType::Data), )?; let tree_packer = Packer::new( be_dest.clone(), BlobType::Tree, indexer.clone(), &repo_dest.config, - index.total_size(&BlobType::Tree), + index.total_size(BlobType::Tree), )?; let p = progress_counter("copying blobs in snapshots..."); diff --git a/src/commands/prune.rs b/src/commands/prune.rs index e0e810d..a9443a2 100644 --- a/src/commands/prune.rs +++ b/src/commands/prune.rs @@ -107,7 +107,7 @@ pub(super) fn execute(repo: OpenRepository, opts: Opts, ignore_snaps: Vec) - let (used_ids, total_size) = { let index = index_collector.into_index(); - let total_size = BlobTypeMap::init(|blob_type| index.total_size(&blob_type)); + let total_size = BlobTypeMap::init(|blob_type| index.total_size(blob_type)); let indexed_be = IndexBackend::new_from_index(&be.clone(), index); let used_ids = find_used_blobs(&indexed_be, ignore_snaps)?; (used_ids, total_size) diff --git a/src/commands/repair.rs b/src/commands/repair.rs index 582e550..2e22d9b 100644 --- a/src/commands/repair.rs +++ b/src/commands/repair.rs @@ -230,7 +230,7 @@ fn repair_snaps( BlobType::Tree, indexer.clone(), config, - index.total_size(&BlobType::Tree), + index.total_size(BlobType::Tree), )?; for mut snap in snapshots { diff --git a/src/index/binarysorted.rs b/src/index/binarysorted.rs index aa5cc45..0404d7c 100644 --- a/src/index/binarysorted.rs +++ b/src/index/binarysorted.rs @@ -205,8 +205,8 @@ impl IntoIterator for Index { } impl ReadIndex for Index { - fn get_id(&self, blob_type: &BlobType, id: &Id) -> Option { - let vec = match &self.0[*blob_type].entries { + fn get_id(&self, blob_type: BlobType, id: &Id) -> Option { + let vec = match &self.0[blob_type].entries { EntriesVariants::FullEntries(entries) => entries, _ => { // get_id() only gives results if index contains full entries @@ -217,8 +217,8 @@ impl ReadIndex for Index { vec.binary_search_by_key(id, |e| e.id).ok().map(|index| { let be = &vec[index]; IndexEntry::new( - *blob_type, - self.0[*blob_type].packs[be.pack_idx], + blob_type, + self.0[blob_type].packs[be.pack_idx], be.offset, be.length, be.uncompressed_length, @@ -226,12 +226,12 @@ impl ReadIndex for Index { }) } - fn total_size(&self, blob_type: &BlobType) -> u64 { - self.0[*blob_type].total_size + fn total_size(&self, blob_type: BlobType) -> u64 { + self.0[blob_type].total_size } - fn has(&self, blob_type: &BlobType, id: &Id) -> bool { - match &self.0[*blob_type].entries { + fn has(&self, blob_type: BlobType, id: &Id) -> bool { + match &self.0[blob_type].entries { EntriesVariants::FullEntries(entries) => { entries.binary_search_by_key(id, |e| e.id).is_ok() } @@ -318,23 +318,23 @@ mod tests { let index = index(it); let id = parse("0000000000000000000000000000000000000000000000000000000000000000"); - assert!(!index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); let id = parse("aac5e908151e5652b7570108127b96e6bae22bcdda1d3d867f63ed1555fc8aef"); - assert!(!index.has(&BlobType::Data, &id,)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Data, &id,)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); let id = parse("2ef8decbd2a17d9bfb1b35cfbdcd368175ea86d05dd93a4751fdacbe5213e611"); - assert!(!index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(index.has(&BlobType::Tree, &id)); + assert!(!index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(index.has(BlobType::Tree, &id)); assert_eq!( - index.get_id(&BlobType::Tree, &id), + index.get_id(BlobType::Tree, &id), Some(IndexEntry { blob_type: BlobType::Tree, pack: parse("8431a27d38dd7d192dc37abd43a85d6dc4298de72fc8f583c5d7cdd09fa47274"), @@ -351,16 +351,16 @@ mod tests { let index = index(IndexType::OnlyTrees); let id = parse("fac5e908151e565267570108127b96e6bae22bcdda1d3d867f63ed1555fc8aef"); - assert!(!index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); let id = parse("620b2cef43d4c7aab3d7c911a3c0e872d2e0e70f170201002b8af8fb98c59da5"); - assert!(!index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); } #[test] @@ -368,16 +368,16 @@ mod tests { let index = index(IndexType::FullTrees); let id = parse("fac5e908151e565267570108127b96e6bae22bcdda1d3d867f63ed1555fc8aef"); - assert!(index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); let id = parse("620b2cef43d4c7aab3d7c911a3c0e872d2e0e70f170201002b8af8fb98c59da5"); - assert!(index.has(&BlobType::Data, &id)); - assert!(index.get_id(&BlobType::Data, &id).is_none()); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(index.has(BlobType::Data, &id)); + assert!(index.get_id(BlobType::Data, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); } #[test] @@ -385,9 +385,9 @@ mod tests { let index = index(IndexType::Full); let id = parse("fac5e908151e565267570108127b96e6bae22bcdda1d3d867f63ed1555fc8aef"); - assert!(index.has(&BlobType::Data, &id)); + assert!(index.has(BlobType::Data, &id)); assert_eq!( - index.get_id(&BlobType::Data, &id), + index.get_id(BlobType::Data, &id), Some(IndexEntry { blob_type: BlobType::Data, pack: parse("217f145b63fbc10267f5a686186689ea3389bed0d6a54b50ffc84d71f99eb7fa"), @@ -396,13 +396,13 @@ mod tests { uncompressed_length: Some(NonZeroU32::new(6411).unwrap()), }), ); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); let id = parse("620b2cef43d4c7aab3d7c911a3c0e872d2e0e70f170201002b8af8fb98c59da5"); - assert!(index.has(&BlobType::Data, &id)); + assert!(index.has(BlobType::Data, &id)); assert_eq!( - index.get_id(&BlobType::Data, &id), + index.get_id(BlobType::Data, &id), Some(IndexEntry { blob_type: BlobType::Data, pack: parse("3b25ec6d16401c31099c259311562160b1b5efbcf70bd69d0463104d3b8148fc"), @@ -411,7 +411,7 @@ mod tests { uncompressed_length: Some(NonZeroU32::new(3752).unwrap()), }), ); - assert!(!index.has(&BlobType::Tree, &id)); - assert!(index.get_id(&BlobType::Tree, &id).is_none()); + assert!(!index.has(BlobType::Tree, &id)); + assert!(index.get_id(BlobType::Tree, &id).is_none()); } } diff --git a/src/index/mod.rs b/src/index/mod.rs index 2d48ffd..6506a10 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -60,24 +60,24 @@ impl IndexEntry { } pub trait ReadIndex { - fn get_id(&self, tpe: &BlobType, id: &Id) -> Option; - fn total_size(&self, tpe: &BlobType) -> u64; - fn has(&self, tpe: &BlobType, id: &Id) -> bool; + fn get_id(&self, tpe: BlobType, id: &Id) -> Option; + fn total_size(&self, tpe: BlobType) -> u64; + fn has(&self, tpe: BlobType, id: &Id) -> bool; fn get_tree(&self, id: &Id) -> Option { - self.get_id(&BlobType::Tree, id) + self.get_id(BlobType::Tree, id) } fn get_data(&self, id: &Id) -> Option { - self.get_id(&BlobType::Data, id) + self.get_id(BlobType::Data, id) } fn has_tree(&self, id: &Id) -> bool { - self.has(&BlobType::Tree, id) + self.has(BlobType::Tree, id) } fn has_data(&self, id: &Id) -> bool { - self.has(&BlobType::Data, id) + self.has(BlobType::Data, id) } } @@ -86,7 +86,7 @@ pub trait IndexedBackend: ReadIndex + Clone + Sync + Send + 'static { fn be(&self) -> &Self::Backend; - fn blob_from_backend(&self, tpe: &BlobType, id: &Id) -> Result { + fn blob_from_backend(&self, tpe: BlobType, id: &Id) -> Result { match self.get_id(tpe, id) { None => Err(anyhow!("blob not found in index")), Some(ie) => ie.read_data(self.be()), @@ -101,14 +101,14 @@ pub struct IndexBackend { } impl ReadIndex for IndexBackend { - fn get_id(&self, tpe: &BlobType, id: &Id) -> Option { + fn get_id(&self, tpe: BlobType, id: &Id) -> Option { self.index.get_id(tpe, id) } - fn total_size(&self, tpe: &BlobType) -> u64 { + fn total_size(&self, tpe: BlobType) -> u64 { self.index.total_size(tpe) } - fn has(&self, tpe: &BlobType, id: &Id) -> bool { + fn has(&self, tpe: BlobType, id: &Id) -> bool { self.index.has(tpe, id) } }