| 144 | } |
| 145 | |
| 146 | fn decode_legacy(bytes: &[u8]) -> PristineResult<Vec<Hash>> { |
| 147 | let count_bytes = bytes |
| 148 | .get(..4) |
| 149 | .ok_or_else(|| invalid("Git commit closure is truncated"))?; |
| 150 | let count = u32::from_le_bytes(count_bytes.try_into().unwrap()) as u64; |
| 151 | if bytes.len() as u64 != 4 + count * 32 { |
| 152 | return Err(invalid(format!( |
| 153 | "Git commit closure claims {count} hashes but holds {} bytes", |
| 154 | bytes.len() |
| 155 | ))); |
| 156 | } |
| 157 | Ok(bytes[4..] |
| 158 | .as_chunks::<32>() |
| 159 | .0 |
| 160 | .iter() |
| 161 | .map(|hash| Hash::from_bytes(*hash)) |
| 162 | .collect()) |
| 163 | } |
| 164 | |
| 165 | #[cfg(test)] |
| 166 | mod tests { |