(hex: &str)
| 3209 | } |
| 3210 | |
| 3211 | fn hex_decode_bytes(hex: &str) -> Result<Vec<u8>, RepositoryError> { |
| 3212 | if !hex.len().is_multiple_of(2) || !hex.bytes().all(|byte| byte.is_ascii_hexdigit()) { |
| 3213 | return Err(RepositoryError::InvalidRepository { |
| 3214 | reason: format!("'{hex}' is not a hex Git object id"), |
| 3215 | }); |
| 3216 | } |
| 3217 | let mut bytes = Vec::with_capacity(hex.len() / 2); |
| 3218 | let byte_values = hex.as_bytes(); |
| 3219 | for pair in byte_values.chunks(2) { |
| 3220 | let high = |
| 3221 | (pair[0] as char) |
| 3222 | .to_digit(16) |
| 3223 | .ok_or_else(|| RepositoryError::InvalidRepository { |
| 3224 | reason: format!("'{hex}' is not a hex Git object id"), |
| 3225 | })?; |
| 3226 | let low = |
| 3227 | (pair[1] as char) |
| 3228 | .to_digit(16) |
| 3229 | .ok_or_else(|| RepositoryError::InvalidRepository { |
| 3230 | reason: format!("'{hex}' is not a hex Git object id"), |
| 3231 | })?; |
| 3232 | bytes.push(((high << 4) | low) as u8); |
| 3233 | } |
| 3234 | Ok(bytes) |
| 3235 | } |
| 3236 | |
| 3237 | fn walk_unexplained_worktree( |
| 3238 | root: &std::path::Path, |
no test coverage detected