gix_attributes/
source.rs

1use std::{borrow::Cow, ffi::OsString, path::Path};
2
3use crate::Source;
4
5impl Source {
6    /// Produce a storage location for the this source while potentially querying environment variables using `env_var(<name>)`,
7    /// or `None` if the storage location could not be obtained.
8    ///
9    /// Note that local sources are returned as relative paths to be joined with the base in a separate step.
10    pub fn storage_location(self, env_var: &mut dyn FnMut(&str) -> Option<OsString>) -> Option<Cow<'static, Path>> {
11        use Source::*;
12        Some(match self {
13            GitInstallation => gix_path::env::installation_config_prefix()?
14                .join("gitattributes")
15                .into(),
16            System => {
17                if env_var("GIT_ATTR_NOSYSTEM").is_some() {
18                    return None;
19                } else {
20                    gix_path::env::system_prefix()?.join("etc/gitattributes").into()
21                }
22            }
23            Git => return gix_path::env::xdg_config("attributes", env_var).map(Cow::Owned),
24            Local => Cow::Borrowed(Path::new("info/attributes")),
25        })
26    }
27}