diff --git a/git-odb/src/pack/index/accesss.rs b/git-odb/src/pack/index/accesss.rs index a982480ab16..b86a42d8913 100644 --- a/git-odb/src/pack/index/accesss.rs +++ b/git-odb/src/pack/index/accesss.rs @@ -1,4 +1,4 @@ -use crate::pack::index::{File, Kind, FAN_LEN}; +use crate::pack::index::{self, FAN_LEN}; use byteorder::{BigEndian, ByteOrder}; use git_object::{self as object, SHA1_SIZE}; use std::{convert::TryInto, mem::size_of}; @@ -18,10 +18,11 @@ pub struct Entry { pub crc32: Option, } -impl File { +/// Iteration and access +impl index::File { pub fn iter_v1<'a>(&'a self) -> impl Iterator + 'a { match self.kind { - Kind::V1 => self.data[V1_HEADER_SIZE..] + index::Kind::V1 => self.data[V1_HEADER_SIZE..] .chunks(N32_SIZE + SHA1_SIZE) .take(self.num_objects as usize) .map(|c| { @@ -39,7 +40,7 @@ impl File { pub fn iter_v2<'a>(&'a self) -> impl Iterator + 'a { let pack64_offset = self.offset_pack_offset64_v2(); match self.kind { - Kind::V2 => izip!( + index::Kind::V2 => izip!( self.data[V2_HEADER_SIZE..].chunks(SHA1_SIZE), self.data[self.offset_crc32_v2()..].chunks(N32_SIZE), self.data[self.offset_pack_offset_v2()..].chunks(N32_SIZE) @@ -61,8 +62,8 @@ impl File { .try_into() .expect("an architecture able to hold 32 bits of integer"); let start = match self.kind { - Kind::V2 => V2_HEADER_SIZE + index * SHA1_SIZE, - Kind::V1 => V1_HEADER_SIZE + index * (N32_SIZE + SHA1_SIZE) + N32_SIZE, + index::Kind::V2 => V2_HEADER_SIZE + index * SHA1_SIZE, + index::Kind::V1 => V1_HEADER_SIZE + index * (N32_SIZE + SHA1_SIZE) + N32_SIZE, }; &self.data[start..start + SHA1_SIZE] } @@ -72,11 +73,11 @@ impl File { .try_into() .expect("an architecture able to hold 32 bits of integer"); match self.kind { - Kind::V2 => { + index::Kind::V2 => { let start = self.offset_pack_offset_v2() + index * N32_SIZE; self.pack_offset_from_offset_v2(&self.data[start..start + N32_SIZE], self.offset_pack_offset64_v2()) } - Kind::V1 => { + index::Kind::V1 => { let start = V1_HEADER_SIZE + index * (N32_SIZE + SHA1_SIZE); BigEndian::read_u32(&self.data[start..start + N32_SIZE]) as u64 } @@ -88,11 +89,11 @@ impl File { .try_into() .expect("an architecture able to hold 32 bits of integer"); match self.kind { - Kind::V2 => { + index::Kind::V2 => { let start = self.offset_crc32_v2() + index * N32_SIZE; Some(BigEndian::read_u32(&self.data[start..start + N32_SIZE])) } - Kind::V1 => None, + index::Kind::V1 => None, } } @@ -122,8 +123,8 @@ impl File { pub fn iter<'a>(&'a self) -> Box + 'a> { match self.kind { - Kind::V2 => Box::new(self.iter_v2()), - Kind::V1 => Box::new(self.iter_v1()), + index::Kind::V2 => Box::new(self.iter_v2()), + index::Kind::V1 => Box::new(self.iter_v1()), } } @@ -140,7 +141,7 @@ impl File { } fn pack_offset_from_offset_v2(&self, offset: &[u8], pack64_offset: usize) -> u64 { - debug_assert_eq!(self.kind, Kind::V2); + debug_assert_eq!(self.kind, index::Kind::V2); let ofs32 = BigEndian::read_u32(offset); if (ofs32 & N32_HIGH_BIT) == N32_HIGH_BIT { let from = pack64_offset + (ofs32 ^ N32_HIGH_BIT) as usize * N64_SIZE; diff --git a/git-odb/src/pack/index/file.rs b/git-odb/src/pack/index/file.rs index 515887bd0c9..c4dbf2e090d 100644 --- a/git-odb/src/pack/index/file.rs +++ b/git-odb/src/pack/index/file.rs @@ -1,4 +1,4 @@ -use crate::pack::index::{Error, File, Kind, FAN_LEN}; +use crate::pack::index::{self, Error, Kind, FAN_LEN}; use byteorder::{BigEndian, ByteOrder}; use filebuffer::FileBuffer; use git_object::SHA1_SIZE; @@ -9,13 +9,13 @@ const V2_SIGNATURE: &[u8] = b"\xfftOc"; const FOOTER_SIZE: usize = SHA1_SIZE * 2; /// Instantiation -impl File { - pub fn at(path: impl AsRef) -> Result { +impl index::File { + pub fn at(path: impl AsRef) -> Result { Self::try_from(path.as_ref()) } } -impl TryFrom<&Path> for File { +impl TryFrom<&Path> for index::File { type Error = Error; fn try_from(path: &Path) -> Result { @@ -54,7 +54,7 @@ impl TryFrom<&Path> for File { (kind, version, fan, num_objects) }; - Ok(File { + Ok(index::File { data, kind, num_objects, diff --git a/git-odb/src/pack/index/verify.rs b/git-odb/src/pack/index/verify.rs index 36affa8f395..c01daeed5d1 100644 --- a/git-odb/src/pack/index/verify.rs +++ b/git-odb/src/pack/index/verify.rs @@ -1,5 +1,8 @@ -use crate::pack::{cache, decode::DecodeEntryOutcome}; -use crate::{pack, pack::index}; +use crate::{ + pack, + pack::index, + pack::{cache, decode::DecodeEntryOutcome}, +}; use git_features::progress::{self, Progress}; use git_object::SHA1_SIZE; use quick_error::quick_error; @@ -73,7 +76,7 @@ pub struct Outcome { pub pack_size: u64, } -/// Methods to verify and validate the content of the index file +/// Verify and validate the content of the index file impl index::File { pub fn checksum_of_index(&self) -> git_object::Id { git_object::Id::from_20_bytes(&self.data[self.data.len() - SHA1_SIZE..])