git_next_core/config/
git_dir.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
use std::path::PathBuf;

use derive_more::Deref;
use pike::pike;

/// The path to the directory containing the git repository.
#[derive(
    Clone,
    Debug,
    derive_more::From,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    derive_more::AsRef,
    derive_more::Constructor,
)]
pub struct GitDir {
    pathbuf: PathBuf,
    /// Whether the directory is under the control of git-next (Internal) or not (External).
    storage_path_type: StoragePathType,
}
impl GitDir {
    pub(crate) const fn pathbuf(&self) -> &PathBuf {
        &self.pathbuf
    }

    pub(crate) const fn storage_path_type(&self) -> StoragePathType {
        self.storage_path_type
    }

    pub(crate) fn as_fs(&self) -> kxio::fs::FileSystem {
        pike! {
            self
            |> Self::pathbuf
            |> PathBuf::clone
            |> kxio::fs::new
        }
    }
}
impl std::fmt::Display for GitDir {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", &self.pathbuf.display())
    }
}
impl Deref for GitDir {
    type Target = PathBuf;

    fn deref(&self) -> &Self::Target {
        &self.pathbuf
    }
}
impl From<&GitDir> for PathBuf {
    fn from(value: &GitDir) -> Self {
        value.to_path_buf()
    }
}
impl From<&GitDir> for kxio::fs::FileSystem {
    fn from(gitdir: &GitDir) -> Self {
        gitdir.as_fs()
    }
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum StoragePathType {
    Internal,
    External,
}