gix_odb/alternate/
parse.rs1use std::{borrow::Cow, path::PathBuf};
2
3use gix_object::bstr::ByteSlice;
4
5#[derive(thiserror::Error, Debug)]
7#[allow(missing_docs)]
8pub enum Error {
9 #[error("Could not obtain an object path for the alternate directory '{}'", String::from_utf8_lossy(.0))]
10 PathConversion(Vec<u8>),
11 #[error("Could not unquote alternate path")]
12 Unquote(#[from] gix_quote::ansi_c::undo::Error),
13}
14
15pub(crate) fn content(input: &[u8]) -> Result<Vec<PathBuf>, Error> {
16 let mut out = Vec::new();
17 for line in input.split(|b| *b == b'\n') {
18 let line = line.as_bstr();
19 if line.is_empty() || line.starts_with(b"#") {
20 continue;
21 }
22 out.push(
23 gix_path::try_from_bstr(if line.starts_with(b"\"") {
24 gix_quote::ansi_c::undo(line)?.0
25 } else {
26 Cow::Borrowed(line)
27 })
28 .map_err(|_| Error::PathConversion(line.to_vec()))?
29 .into_owned(),
30 );
31 }
32 Ok(out)
33}