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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use super::{interpolate_context, util, Error, StageOne};
use crate::{bstr::BString, config::Cache, repository};
impl Cache {
#[allow(clippy::too_many_arguments)]
pub fn from_stage_one(
StageOne {
git_dir_config,
mut buf,
lossy,
is_bare,
object_hash,
reflog: _,
}: StageOne,
git_dir: &std::path::Path,
branch_name: Option<&git_ref::FullNameRef>,
filter_config_section: fn(&git_config::file::Metadata) -> bool,
git_install_dir: Option<&std::path::Path>,
home: Option<&std::path::Path>,
repository::permissions::Environment {
git_prefix,
home: home_env,
xdg_config_home: xdg_config_home_env,
ssh_prefix: _,
}: repository::permissions::Environment,
repository::permissions::Config {
git_binary: use_installation,
system: use_system,
git: use_git,
user: use_user,
env: use_env,
includes: use_includes,
}: repository::permissions::Config,
lenient_config: bool,
config_overrides: &[BString],
) -> Result<Self, Error> {
let options = git_config::file::init::Options {
includes: if use_includes {
git_config::file::includes::Options::follow(
interpolate_context(git_install_dir, home),
git_config::file::includes::conditional::Context {
git_dir: git_dir.into(),
branch_name,
},
)
} else {
git_config::file::includes::Options::no_follow()
},
..util::base_options(lossy)
};
let config = {
let home_env = &home_env;
let xdg_config_home_env = &xdg_config_home_env;
let git_prefix = &git_prefix;
let metas = [
git_config::source::Kind::GitInstallation,
git_config::source::Kind::System,
git_config::source::Kind::Global,
]
.iter()
.flat_map(|kind| kind.sources())
.filter_map(|source| {
match source {
git_config::Source::GitInstallation if !use_installation => return None,
git_config::Source::System if !use_system => return None,
git_config::Source::Git if !use_git => return None,
git_config::Source::User if !use_user => return None,
_ => {}
}
source
.storage_location(&mut |name| {
match name {
git_ if git_.starts_with("GIT_") => Some(git_prefix),
"XDG_CONFIG_HOME" => Some(xdg_config_home_env),
"HOME" => Some(home_env),
_ => None,
}
.and_then(|perm| std::env::var_os(name).and_then(|val| perm.check_opt(val)))
})
.map(|p| (source, p.into_owned()))
})
.map(|(source, path)| git_config::file::Metadata {
path: Some(path),
source: *source,
level: 0,
trust: git_sec::Trust::Full,
});
let err_on_nonexisting_paths = false;
let mut globals = git_config::File::from_paths_metadata_buf(
metas,
&mut buf,
err_on_nonexisting_paths,
git_config::file::init::Options {
includes: git_config::file::includes::Options::no_follow(),
..options
},
)
.map_err(|err| match err {
git_config::file::init::from_paths::Error::Init(err) => Error::from(err),
git_config::file::init::from_paths::Error::Io(err) => err.into(),
})?
.unwrap_or_default();
globals.append(git_dir_config);
globals.resolve_includes(options)?;
if use_env {
globals.append(git_config::File::from_env(options)?.unwrap_or_default());
}
if !config_overrides.is_empty() {
crate::config::overrides::apply(&mut globals, config_overrides, git_config::Source::Api)?;
}
globals
};
let hex_len = util::check_lenient(util::parse_core_abbrev(&config, object_hash), lenient_config)?;
use util::config_bool;
let reflog = util::query_refupdates(&config, lenient_config)?;
let ignore_case = config_bool(&config, "core.ignoreCase", false, lenient_config)?;
let use_multi_pack_index = config_bool(&config, "core.multiPackIndex", true, lenient_config)?;
let object_kind_hint = util::disambiguate_hint(&config);
Ok(Cache {
resolved: config.into(),
use_multi_pack_index,
object_hash,
object_kind_hint,
reflog,
is_bare,
ignore_case,
hex_len,
filter_config_section,
xdg_config_home_env,
home_env,
lenient_config,
personas: Default::default(),
url_rewrite: Default::default(),
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
url_scheme: Default::default(),
diff_algorithm: Default::default(),
git_prefix,
})
}
pub fn reread_values_and_clear_caches_replacing_config(&mut self, config: crate::Config) -> Result<(), Error> {
let prev = std::mem::replace(&mut self.resolved, config);
match self.reread_values_and_clear_caches() {
Err(err) => {
drop(std::mem::replace(&mut self.resolved, prev));
Err(err)
}
Ok(()) => Ok(()),
}
}
pub fn reread_values_and_clear_caches(&mut self) -> Result<(), Error> {
let config = &self.resolved;
let hex_len = util::check_lenient(util::parse_core_abbrev(config, self.object_hash), self.lenient_config)?;
use util::config_bool;
let ignore_case = config_bool(config, "core.ignoreCase", false, self.lenient_config)?;
let object_kind_hint = util::disambiguate_hint(config);
let reflog = util::query_refupdates(config, self.lenient_config)?;
self.hex_len = hex_len;
self.ignore_case = ignore_case;
self.object_kind_hint = object_kind_hint;
self.reflog = reflog;
self.personas = Default::default();
self.url_rewrite = Default::default();
self.diff_algorithm = Default::default();
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
{
self.url_scheme = Default::default();
}
Ok(())
}
}