Showing the changes to git-pack/src/data (6 of 20 files). Show all
Unified · Split
| @@ -44,7 +44,7 @@ impl Header { · 43 unmodified lines | |||
| 44 | pack_offset.checked_sub(distance) | 44 | pack_offset.checked_sub(distance) |
| 45 | } | 45 | } |
| 46 | /// Convert the header's object kind into [`git_object::Kind`] if possible | 46 | /// Convert the header's object kind into [`git_object::Kind`] if possible |
| 47 | pub fn to_kind(&self) -> Option<git_object::Kind> { | 47 | pub fn as_kind(&self) -> Option<git_object::Kind> { |
| 48 | use git_object::Kind::*; | 48 | use git_object::Kind::*; |
| 49 | Some(match self { | 49 | Some(match self { |
| 50 | Header::Tree => Tree, | 50 | Header::Tree => Tree, |
| @@ -55,7 +55,7 @@ impl Header { · 4 unmodified lines | |||
| 55 | }) | 55 | }) |
| 56 | } | 56 | } |
| 57 | /// Convert this header's object kind into the packs internal representation | 57 | /// Convert this header's object kind into the packs internal representation |
| 58 | pub fn to_type_id(&self) -> u8 { | 58 | pub fn as_type_id(&self) -> u8 { |
| 59 | use Header::*; | 59 | use Header::*; |
| 60 | match self { | 60 | match self { |
| 61 | Blob => BLOB, | 61 | Blob => BLOB, |
| @@ -81,10 +81,10 @@ impl Header { · 19 unmodified lines | |||
| 81 | /// | 81 | /// |
| 82 | /// Returns the amount of bytes written to `out`. | 82 | /// Returns the amount of bytes written to `out`. |
| 83 | /// `decompressed_size_in_bytes` is the full size in bytes of the object that this header represents | 83 | /// `decompressed_size_in_bytes` is the full size in bytes of the object that this header represents |
| 84 | pub fn to_write(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> { | 84 | pub fn write_to(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> { |
| 85 | let mut size = decompressed_size_in_bytes; | 85 | let mut size = decompressed_size_in_bytes; |
| 86 | let mut written = 1; | 86 | let mut written = 1; |
| 87 | let mut c: u8 = (self.to_type_id() << 4) | (size as u8 & 0b0000_1111); | 87 | let mut c: u8 = (self.as_type_id() << 4) | (size as u8 & 0b0000_1111); |
| 88 | size >>= 4; | 88 | size >>= 4; |
| 89 | while size != 0 { | 89 | while size != 0 { |
| 90 | out.write_all(&[c | 0b1000_0000])?; | 90 | out.write_all(&[c | 0b1000_0000])?; |
| @@ -36,7 +36,7 @@ impl Entry { · 35 unmodified lines | |||
| 36 | /// The amount of bytes used to describe this entry in the pack. The header starts at [`Self::pack_offset()`] | 36 | /// The amount of bytes used to describe this entry in the pack. The header starts at [`Self::pack_offset()`] |
| 37 | pub fn header_size(&self) -> usize { | 37 | pub fn header_size(&self) -> usize { |
| 38 | self.header | 38 | self.header |
| 39 | .to_write(self.decompressed_size, io::sink()) | 39 | .write_to(self.decompressed_size, io::sink()) |
| 40 | .expect("io::sink() to never fail") | 40 | .expect("io::sink() to never fail") |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| @@ -153,7 +153,7 @@ impl File { · 152 unmodified lines | |||
| 153 | ); | 153 | ); |
| 154 | self.decompress_entry(&entry, out.as_mut_slice()).map(|consumed_input| { | 154 | self.decompress_entry(&entry, out.as_mut_slice()).map(|consumed_input| { |
| 155 | Outcome::from_object_entry( | 155 | Outcome::from_object_entry( |
| 156 | entry.header.to_kind().expect("a non-delta entry"), | 156 | entry.header.as_kind().expect("a non-delta entry"), |
| 157 | &entry, | 157 | &entry, |
| 158 | consumed_input, | 158 | consumed_input, |
| 159 | ) | 159 | ) |
| @@ -314,7 +314,7 @@ impl File { · 154 unmodified lines | |||
| 314 | if base_buffer_size.is_none() { | 314 | if base_buffer_size.is_none() { |
| 315 | let base_entry = cursor; | 315 | let base_entry = cursor; |
| 316 | debug_assert!(!base_entry.header.is_delta()); | 316 | debug_assert!(!base_entry.header.is_delta()); |
| 317 | object_kind = base_entry.header.to_kind(); | 317 | object_kind = base_entry.header.as_kind(); |
| 318 | let packed_size = self.decompress_entry_from_data_offset(base_entry.data_offset, out)?; | 318 | let packed_size = self.decompress_entry_from_data_offset(base_entry.data_offset, out)?; |
| 319 | cache.put( | 319 | cache.put( |
| 320 | self.id, | 320 | self.id, |
| @@ -138,7 +138,7 @@ where · 137 unmodified lines | |||
| 138 | 138 | ||
| 139 | let crc32 = if self.compressed.crc32() { | 139 | let crc32 = if self.compressed.crc32() { |
| 140 | let mut header_buf = [0u8; 32]; | 140 | let mut header_buf = [0u8; 32]; |
| 141 | let header_len = entry.header.to_write(bytes_copied, header_buf.as_mut())?; | 141 | let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?; |
| 142 | let state = git_features::hash::crc32_update(0, &header_buf[..header_len]); | 142 | let state = git_features::hash::crc32_update(0, &header_buf[..header_len]); |
| 143 | Some(git_features::hash::crc32_update(state, &compressed)) | 143 | Some(git_features::hash::crc32_update(state, &compressed)) |
| 144 | } else { | 144 | } else { |
| @@ -100,7 +100,7 @@ where · 99 unmodified lines | |||
| 100 | let header = entry.to_entry_header(self.entry_version, |_index_offset| { | 100 | let header = entry.to_entry_header(self.entry_version, |_index_offset| { |
| 101 | unimplemented!("a way to calculate pack offsets from object index offsets") | 101 | unimplemented!("a way to calculate pack offsets from object index offsets") |
| 102 | }); | 102 | }); |
| 103 | written += header.to_write(entry.decompressed_size as u64, &mut self.output)? as u64; | 103 | written += header.write_to(entry.decompressed_size as u64, &mut self.output)? as u64; |
| 104 | written += std::io::copy(&mut &*entry.compressed_data, &mut self.output)? as u64; | 104 | written += std::io::copy(&mut &*entry.compressed_data, &mut self.output)? as u64; |
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| @@ -80,7 +80,7 @@ impl output::Entry { · 79 unmodified lines | |||
| 80 | if pack_entry.header.is_base() { | 80 | if pack_entry.header.is_base() { |
| 81 | Some(Ok(output::Entry { | 81 | Some(Ok(output::Entry { |
| 82 | id: count.id.to_owned(), | 82 | id: count.id.to_owned(), |
| 83 | object_kind: pack_entry.header.to_kind().expect("valid object only"), | 83 | object_kind: pack_entry.header.as_kind().expect("valid object only"), |
| 84 | kind: output::entry::Kind::Base, | 84 | kind: output::entry::Kind::Base, |
| 85 | decompressed_size: pack_entry.decompressed_size as usize, | 85 | decompressed_size: pack_entry.decompressed_size as usize, |
| 86 | compressed_data: entry.data[pack_entry.data_offset as usize..].to_owned(), | 86 | compressed_data: entry.data[pack_entry.data_offset as usize..].to_owned(), |