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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use std::borrow::Cow;
use git_features::threading::OwnShared;
use crate::{
bstr::BStr,
config::{CommitAutoRollback, Snapshot, SnapshotMut},
};
impl<'repo> Snapshot<'repo> {
pub fn boolean(&self, key: &str) -> Option<bool> {
self.try_boolean(key).and_then(Result::ok)
}
pub fn try_boolean(&self, key: &str) -> Option<Result<bool, git_config::value::Error>> {
let key = git_config::parse::key(key)?;
self.repo
.config
.resolved
.boolean(key.section_name, key.subsection_name, key.value_name)
}
pub fn integer(&self, key: &str) -> Option<i64> {
self.try_integer(key).and_then(Result::ok)
}
pub fn try_integer(&self, key: &str) -> Option<Result<i64, git_config::value::Error>> {
let key = git_config::parse::key(key)?;
self.repo
.config
.resolved
.integer(key.section_name, key.subsection_name, key.value_name)
}
pub fn string(&self, key: &str) -> Option<Cow<'_, BStr>> {
let key = git_config::parse::key(key)?;
self.repo
.config
.resolved
.string(key.section_name, key.subsection_name, key.value_name)
}
pub fn trusted_path(
&self,
key: &str,
) -> Option<Result<Cow<'_, std::path::Path>, git_config::path::interpolate::Error>> {
let key = git_config::parse::key(key)?;
self.repo
.config
.trusted_file_path(key.section_name, key.subsection_name, key.value_name)
}
}
impl<'repo> Snapshot<'repo> {
pub fn plumbing(&self) -> &git_config::File<'static> {
&self.repo.config.resolved
}
}
impl<'repo> SnapshotMut<'repo> {
pub fn apply_cli_overrides(
&mut self,
values: impl IntoIterator<Item = impl AsRef<BStr>>,
) -> Result<&mut Self, crate::config::overrides::Error> {
crate::config::overrides::apply(&mut self.config, values, git_config::Source::Cli)?;
Ok(self)
}
pub fn commit(mut self) -> Result<&'repo mut crate::Repository, crate::config::Error> {
let repo = self.repo.take().expect("always present here");
self.commit_inner(repo)
}
pub(crate) fn commit_inner(
&mut self,
repo: &'repo mut crate::Repository,
) -> Result<&'repo mut crate::Repository, crate::config::Error> {
repo.reread_values_and_clear_caches_replacing_config(std::mem::take(&mut self.config).into())?;
Ok(repo)
}
pub fn commit_auto_rollback(mut self) -> Result<CommitAutoRollback<'repo>, crate::config::Error> {
let repo = self.repo.take().expect("this only runs once on consumption");
let prev_config = OwnShared::clone(&repo.config.resolved);
Ok(CommitAutoRollback {
repo: self.commit_inner(repo)?.into(),
prev_config,
})
}
pub fn forget(mut self) -> git_config::File<'static> {
self.repo.take();
std::mem::take(&mut self.config)
}
}
impl<'repo> CommitAutoRollback<'repo> {
pub fn rollback(mut self) -> Result<&'repo mut crate::Repository, crate::config::Error> {
let repo = self.repo.take().expect("still present, consumed only once");
self.rollback_inner(repo)
}
pub(crate) fn rollback_inner(
&mut self,
repo: &'repo mut crate::Repository,
) -> Result<&'repo mut crate::Repository, crate::config::Error> {
repo.reread_values_and_clear_caches_replacing_config(OwnShared::clone(&self.prev_config))?;
Ok(repo)
}
}