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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#![deny(unsafe_code, rust_2018_idioms)]
#![allow(missing_docs)]
use std::path::PathBuf;
pub use git_actor as actor;
#[cfg(feature = "git-diff")]
pub use git_diff as diff;
pub use git_features::{parallel, progress, progress::Progress};
pub use git_hash as hash;
pub use git_object as object;
pub use git_odb as odb;
#[cfg(feature = "git-protocol")]
pub use git_protocol as protocol;
pub use git_ref as refs;
pub use git_tempfile as tempfile;
#[cfg(feature = "git-traverse")]
pub use git_traverse as traverse;
#[cfg(feature = "git-url")]
pub use git_url as url;
pub mod interrupt;
#[cfg(feature = "git-traverse")]
pub mod ext;
pub mod prelude {
#[cfg(all(feature = "git-traverse"))]
pub use crate::ext::*;
pub use git_features::parallel::reduce::Finalize;
pub use git_odb::{Find, FindExt, Write};
}
pub mod init;
pub mod path;
pub use path::Path;
pub mod repository;
pub struct Repository {
pub refs: git_ref::file::Store,
pub working_tree: Option<PathBuf>,
pub odb: git_odb::linked::Store,
}
impl Repository {
pub fn kind(&self) -> Kind {
match self.working_tree {
Some(_) => Kind::WorkingTree,
None => Kind::Bare,
}
}
pub fn git_dir(&self) -> &std::path::Path {
&self.refs.base
}
pub fn objects_dir(&self) -> &std::path::Path {
&self.odb.dbs[0].loose.path
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Kind {
Bare,
WorkingTree,
}
impl Kind {
pub fn is_bare(&self) -> bool {
matches!(self, Kind::Bare)
}
}
pub fn discover(directory: impl AsRef<std::path::Path>) -> Result<Repository, repository::discover::Error> {
Repository::discover(directory)
}