Enum git_pack::data::input::EntryDataMode
source · pub enum EntryDataMode {
Ignore,
Crc32,
Keep,
KeepAndCrc32,
}
Expand description
Define what to do with the compressed bytes portion of a pack Entry
Variants§
Ignore
Do nothing with the compressed bytes we read
Crc32
Only create a CRC32 of the entry, otherwise similar to Ignore
Keep
Keep them and pass them along in a newly allocated buffer
KeepAndCrc32
As above, but also compute a CRC32
Implementations§
source§impl EntryDataMode
impl EntryDataMode
sourcepub fn crc32(&self) -> bool
pub fn crc32(&self) -> bool
Returns true if a crc32 should be computed
Examples found in repository?
src/data/input/bytes_to_entries.rs (line 150)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
fn next_inner(&mut self) -> Result<input::Entry, input::Error> {
self.objects_left -= 1; // even an error counts as objects
// Read header
let entry = match self.hash.take() {
Some(hash) => {
let mut read = read_and_pass_to(
&mut self.read,
hash::Write {
inner: io::sink(),
hash,
},
);
let res = crate::data::Entry::from_read(&mut read, self.offset, self.hash_len);
self.hash = Some(read.write.hash);
res
}
None => crate::data::Entry::from_read(&mut self.read, self.offset, self.hash_len),
}
.map_err(input::Error::from)?;
// Decompress object to learn its compressed bytes
let mut decompressor = self
.decompressor
.take()
.unwrap_or_else(|| Box::new(Decompress::new(true)));
let compressed_buf = self.compressed_buf.take().unwrap_or_else(|| Vec::with_capacity(4096));
decompressor.reset(true);
let mut decompressed_reader = ReadBoxed {
inner: read_and_pass_to(
&mut self.read,
if self.compressed.keep() {
Vec::with_capacity(entry.decompressed_size as usize)
} else {
compressed_buf
},
),
decompressor,
};
let bytes_copied = io::copy(&mut decompressed_reader, &mut io::sink())?;
if bytes_copied != entry.decompressed_size {
return Err(input::Error::IncompletePack {
actual: bytes_copied,
expected: entry.decompressed_size,
});
}
let pack_offset = self.offset;
let compressed_size = decompressed_reader.decompressor.total_in();
self.offset += entry.header_size() as u64 + compressed_size;
self.decompressor = Some(decompressed_reader.decompressor);
let mut compressed = decompressed_reader.inner.write;
debug_assert_eq!(
compressed_size,
compressed.len() as u64,
"we must track exactly the same amount of bytes as read by the decompressor"
);
if let Some(hash) = self.hash.as_mut() {
hash.update(&compressed);
}
let crc32 = if self.compressed.crc32() {
let mut header_buf = [0u8; 12 + git_hash::Kind::longest().len_in_bytes()];
let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?;
let state = git_features::hash::crc32_update(0, &header_buf[..header_len]);
Some(git_features::hash::crc32_update(state, &compressed))
} else {
None
};
let compressed = if self.compressed.keep() {
Some(compressed)
} else {
compressed.clear();
self.compressed_buf = Some(compressed);
None
};
// Last objects gets trailer (which is potentially verified)
let trailer = self.try_read_trailer()?;
Ok(input::Entry {
header: entry.header,
header_size: entry.header_size() as u16,
compressed,
compressed_size,
crc32,
pack_offset,
decompressed_size: bytes_copied,
trailer,
})
}
sourcepub fn keep(&self) -> bool
pub fn keep(&self) -> bool
Returns true if compressed bytes should be kept
Examples found in repository?
src/data/input/bytes_to_entries.rs (line 118)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
fn next_inner(&mut self) -> Result<input::Entry, input::Error> {
self.objects_left -= 1; // even an error counts as objects
// Read header
let entry = match self.hash.take() {
Some(hash) => {
let mut read = read_and_pass_to(
&mut self.read,
hash::Write {
inner: io::sink(),
hash,
},
);
let res = crate::data::Entry::from_read(&mut read, self.offset, self.hash_len);
self.hash = Some(read.write.hash);
res
}
None => crate::data::Entry::from_read(&mut self.read, self.offset, self.hash_len),
}
.map_err(input::Error::from)?;
// Decompress object to learn its compressed bytes
let mut decompressor = self
.decompressor
.take()
.unwrap_or_else(|| Box::new(Decompress::new(true)));
let compressed_buf = self.compressed_buf.take().unwrap_or_else(|| Vec::with_capacity(4096));
decompressor.reset(true);
let mut decompressed_reader = ReadBoxed {
inner: read_and_pass_to(
&mut self.read,
if self.compressed.keep() {
Vec::with_capacity(entry.decompressed_size as usize)
} else {
compressed_buf
},
),
decompressor,
};
let bytes_copied = io::copy(&mut decompressed_reader, &mut io::sink())?;
if bytes_copied != entry.decompressed_size {
return Err(input::Error::IncompletePack {
actual: bytes_copied,
expected: entry.decompressed_size,
});
}
let pack_offset = self.offset;
let compressed_size = decompressed_reader.decompressor.total_in();
self.offset += entry.header_size() as u64 + compressed_size;
self.decompressor = Some(decompressed_reader.decompressor);
let mut compressed = decompressed_reader.inner.write;
debug_assert_eq!(
compressed_size,
compressed.len() as u64,
"we must track exactly the same amount of bytes as read by the decompressor"
);
if let Some(hash) = self.hash.as_mut() {
hash.update(&compressed);
}
let crc32 = if self.compressed.crc32() {
let mut header_buf = [0u8; 12 + git_hash::Kind::longest().len_in_bytes()];
let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?;
let state = git_features::hash::crc32_update(0, &header_buf[..header_len]);
Some(git_features::hash::crc32_update(state, &compressed))
} else {
None
};
let compressed = if self.compressed.keep() {
Some(compressed)
} else {
compressed.clear();
self.compressed_buf = Some(compressed);
None
};
// Last objects gets trailer (which is potentially verified)
let trailer = self.try_read_trailer()?;
Ok(input::Entry {
header: entry.header,
header_size: entry.header_size() as u16,
compressed,
compressed_size,
crc32,
pack_offset,
decompressed_size: bytes_copied,
trailer,
})
}
Trait Implementations§
source§impl Clone for EntryDataMode
impl Clone for EntryDataMode
source§fn clone(&self) -> EntryDataMode
fn clone(&self) -> EntryDataMode
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for EntryDataMode
impl Debug for EntryDataMode
source§impl<'de> Deserialize<'de> for EntryDataMode
impl<'de> Deserialize<'de> for EntryDataMode
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Hash for EntryDataMode
impl Hash for EntryDataMode
source§impl Ord for EntryDataMode
impl Ord for EntryDataMode
source§fn cmp(&self, other: &EntryDataMode) -> Ordering
fn cmp(&self, other: &EntryDataMode) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<EntryDataMode> for EntryDataMode
impl PartialEq<EntryDataMode> for EntryDataMode
source§fn eq(&self, other: &EntryDataMode) -> bool
fn eq(&self, other: &EntryDataMode) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<EntryDataMode> for EntryDataMode
impl PartialOrd<EntryDataMode> for EntryDataMode
source§fn partial_cmp(&self, other: &EntryDataMode) -> Option<Ordering>
fn partial_cmp(&self, other: &EntryDataMode) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for EntryDataMode
impl Serialize for EntryDataMode
impl Copy for EntryDataMode
impl Eq for EntryDataMode
impl StructuralEq for EntryDataMode
impl StructuralPartialEq for EntryDataMode
Auto Trait Implementations§
impl RefUnwindSafe for EntryDataMode
impl Send for EntryDataMode
impl Sync for EntryDataMode
impl Unpin for EntryDataMode
impl UnwindSafe for EntryDataMode
Blanket Implementations§
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more