mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Fix clippy::trivially_copy_pass_by_ref
This commit is contained in:
parent
bfe73779e2
commit
77e12bf3b7
@ -51,14 +51,14 @@ impl<BE: DecryptWriteBackend, I: IndexedBackend> Archiver<BE, I> {
|
||||
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<BE: DecryptWriteBackend, I: IndexedBackend> Archiver<BE, I> {
|
||||
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)| {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -29,13 +29,13 @@ pub struct ChunkIter<R: Read + Send> {
|
||||
}
|
||||
|
||||
impl<R: Read + Send> ChunkIter<R> {
|
||||
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());
|
||||
|
||||
@ -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(())
|
||||
|
||||
@ -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...");
|
||||
|
||||
@ -107,7 +107,7 @@ pub(super) fn execute(repo: OpenRepository, opts: Opts, ignore_snaps: Vec<Id>) -
|
||||
|
||||
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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -205,8 +205,8 @@ impl IntoIterator for Index {
|
||||
}
|
||||
|
||||
impl ReadIndex for Index {
|
||||
fn get_id(&self, blob_type: &BlobType, id: &Id) -> Option<IndexEntry> {
|
||||
let vec = match &self.0[*blob_type].entries {
|
||||
fn get_id(&self, blob_type: BlobType, id: &Id) -> Option<IndexEntry> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,24 +60,24 @@ impl IndexEntry {
|
||||
}
|
||||
|
||||
pub trait ReadIndex {
|
||||
fn get_id(&self, tpe: &BlobType, id: &Id) -> Option<IndexEntry>;
|
||||
fn total_size(&self, tpe: &BlobType) -> u64;
|
||||
fn has(&self, tpe: &BlobType, id: &Id) -> bool;
|
||||
fn get_id(&self, tpe: BlobType, id: &Id) -> Option<IndexEntry>;
|
||||
fn total_size(&self, tpe: BlobType) -> u64;
|
||||
fn has(&self, tpe: BlobType, id: &Id) -> bool;
|
||||
|
||||
fn get_tree(&self, id: &Id) -> Option<IndexEntry> {
|
||||
self.get_id(&BlobType::Tree, id)
|
||||
self.get_id(BlobType::Tree, id)
|
||||
}
|
||||
|
||||
fn get_data(&self, id: &Id) -> Option<IndexEntry> {
|
||||
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<Bytes> {
|
||||
fn blob_from_backend(&self, tpe: BlobType, id: &Id) -> Result<Bytes> {
|
||||
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<BE: DecryptReadBackend> {
|
||||
}
|
||||
|
||||
impl<BE: DecryptReadBackend> ReadIndex for IndexBackend<BE> {
|
||||
fn get_id(&self, tpe: &BlobType, id: &Id) -> Option<IndexEntry> {
|
||||
fn get_id(&self, tpe: BlobType, id: &Id) -> Option<IndexEntry> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user