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
70
71
72
73
74
75
76
77
78
79
mod access {
use crate::Kind;
impl crate::ThreadSafeRepository {
pub fn kind(&self) -> Kind {
match self.work_tree {
Some(_) => Kind::WorkTree,
None => Kind::Bare,
}
}
pub fn to_thread_local(&self) -> crate::Repository {
self.into()
}
}
}
mod from_path {
use std::convert::TryFrom;
use crate::Path;
impl TryFrom<crate::Path> for crate::ThreadSafeRepository {
type Error = crate::open::Error;
fn try_from(value: Path) -> Result<Self, Self::Error> {
let (git_dir, worktree_dir) = value.into_repository_and_work_tree_directories();
crate::ThreadSafeRepository::open_from_paths(git_dir, worktree_dir, Default::default())
}
}
}
mod location {
impl crate::ThreadSafeRepository {
pub fn path(&self) -> &std::path::Path {
self.git_dir()
}
pub fn git_dir(&self) -> &std::path::Path {
self.refs.base()
}
pub fn workdir(&self) -> Option<&std::path::Path> {
self.work_tree.as_deref()
}
pub fn objects_dir(&self) -> &std::path::Path {
self.objects.path()
}
}
}
mod impls {
impl std::fmt::Debug for crate::ThreadSafeRepository {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Repository(git = '{}', working_tree: {:?}",
self.git_dir().display(),
self.work_tree
)
}
}
impl PartialEq<crate::ThreadSafeRepository> for crate::ThreadSafeRepository {
fn eq(&self, other: &crate::ThreadSafeRepository) -> bool {
self.git_dir() == other.git_dir() && self.work_tree == other.work_tree
}
}
}