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
use crate::raw;
use libc::c_int;
use std::fmt;
pub struct Version {
major: c_int,
minor: c_int,
rev: c_int,
features: c_int,
}
macro_rules! flag_test {
($features:expr, $flag:expr) => {
($features as u32 & $flag as u32) != 0
};
}
impl Version {
pub fn get() -> Version {
let mut v = Version {
major: 0,
minor: 0,
rev: 0,
features: 0,
};
unsafe {
raw::git_libgit2_version(&mut v.major, &mut v.minor, &mut v.rev);
v.features = raw::git_libgit2_features();
}
v
}
pub fn libgit2_version(&self) -> (u32, u32, u32) {
(self.major as u32, self.minor as u32, self.rev as u32)
}
pub fn crate_version(&self) -> &'static str {
env!("CARGO_PKG_VERSION")
}
pub fn vendored(&self) -> bool {
raw::vendored()
}
pub fn threads(&self) -> bool {
flag_test!(self.features, raw::GIT_FEATURE_THREADS)
}
pub fn https(&self) -> bool {
flag_test!(self.features, raw::GIT_FEATURE_HTTPS)
}
pub fn ssh(&self) -> bool {
flag_test!(self.features, raw::GIT_FEATURE_SSH)
}
pub fn nsec(&self) -> bool {
flag_test!(self.features, raw::GIT_FEATURE_NSEC)
}
}
impl fmt::Debug for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let mut f = f.debug_struct("Version");
f.field("major", &self.major)
.field("minor", &self.minor)
.field("rev", &self.rev)
.field("crate_version", &self.crate_version())
.field("vendored", &self.vendored())
.field("threads", &self.threads())
.field("https", &self.https())
.field("ssh", &self.ssh())
.field("nsec", &self.nsec());
f.finish()
}
}