History

only a select few early config attributes must be repo-local (#331)

Sebastian Thiel committed 4 years ago

Commit be0971c1 parent de8572f2 files · +22 −20Browse files

Unified · Split

2 files
  1. git-repository/src/config/cache.rs +18 −16
  2. git-repository/src/open.rs +4 −4
git-repository/src/config/cache.rs+18−16
@@ -14,7 +14,6 @@ pub(crate) struct StageOne { · 13 unmodified lines
14 14
15 is_bare: bool,15 is_bare: bool,
16 pub object_hash: git_hash::Kind,16 pub object_hash: git_hash::Kind,
17 use_multi_pack_index: bool,
18 pub reflog: Option<git_ref::store::WriteReflog>,17 pub reflog: Option<git_ref::store::WriteReflog>,
19}18}
20 19
@@ -38,7 +37,6 @@ impl StageOne { · 17 unmodified lines
38 };37 };
39 38
40 let is_bare = config_bool(&config, "core.bare", false)?;39 let is_bare = config_bool(&config, "core.bare", false)?;
41 let use_multi_pack_index = config_bool(&config, "core.multiPackIndex", true)?;
42 let repo_format_version = config40 let repo_format_version = config
43 .value::<Integer>("core", None, "repositoryFormatVersion")41 .value::<Integer>("core", None, "repositoryFormatVersion")
44 .map_or(0, |v| v.to_decimal().unwrap_or_default());42 .map_or(0, |v| v.to_decimal().unwrap_or_default());
@@ -57,23 +55,13 @@ impl StageOne { · 12 unmodified lines
57 })55 })
58 .transpose()?56 .transpose()?
59 .unwrap_or(git_hash::Kind::Sha1);57 .unwrap_or(git_hash::Kind::Sha1);
60 let reflog = config.string("core", None, "logallrefupdates").map(|val| {
61 (val.eq_ignore_ascii_case(b"always"))
62 .then(|| git_ref::store::WriteReflog::Always)
63 .or_else(|| {
64 git_config::Boolean::try_from(val)
65 .ok()
66 .and_then(|b| b.is_true().then(|| git_ref::store::WriteReflog::Normal))
67 })
68 .unwrap_or(git_ref::store::WriteReflog::Disable)
69 });
70 58
59 let reflog = query_refupdates(&config);
71 Ok(StageOne {60 Ok(StageOne {
72 git_dir_config: config,61 git_dir_config: config,
73 buf,62 buf,
74 is_bare,63 is_bare,
75 object_hash,64 object_hash,
76 use_multi_pack_index,
77 reflog,65 reflog,
78 })66 })
79 }67 }
@@ -86,8 +74,7 @@ impl Cache { · 6 unmodified lines
86 buf: _,74 buf: _,
87 is_bare,75 is_bare,
88 object_hash,76 object_hash,
89 use_multi_pack_index,77 reflog: _,
90 reflog,
91 }: StageOne,78 }: StageOne,
92 git_dir: &std::path::Path,79 git_dir: &std::path::Path,
93 branch_name: Option<&git_ref::FullNameRef>,80 branch_name: Option<&git_ref::FullNameRef>,
@@ -117,7 +104,6 @@ impl Cache { · 23 unmodified lines
117 .path_filter("core", None, "excludesFile", &mut filter_config_section)104 .path_filter("core", None, "excludesFile", &mut filter_config_section)
118 .map(|p| p.interpolate(options.includes.interpolate).map(|p| p.into_owned()))105 .map(|p| p.interpolate(options.includes.interpolate).map(|p| p.into_owned()))
119 .transpose()?;106 .transpose()?;
120 let ignore_case = config_bool(&config, "core.ignoreCase", false)?;
121 107
122 let mut hex_len = None;108 let mut hex_len = None;
123 if let Some(hex_len_str) = config.string("core", None, "abbrev") {109 if let Some(hex_len_str) = config.string("core", None, "abbrev") {
@@ -150,6 +136,9 @@ impl Cache { · 26 unmodified lines
150 }136 }
151 }137 }
152 138
139 let reflog = query_refupdates(&config);
140 let ignore_case = config_bool(&config, "core.ignoreCase", false)?;
141 let use_multi_pack_index = config_bool(&config, "core.multiPackIndex", true)?;
153 Ok(Cache {142 Ok(Cache {
154 resolved: config.into(),143 resolved: config.into(),
155 use_multi_pack_index,144 use_multi_pack_index,
@@ -212,3 +201,16 @@ fn config_bool(config: &git_config::File<'_>, key: &str, default: bool) -> Resul · 56 unmodified lines
212 key: key.into(),201 key: key.into(),
213 })202 })
214}203}
204
205fn query_refupdates(config: &git_config::File<'static>) -> Option<git_ref::store::WriteReflog> {
206 config.string("core", None, "logallrefupdates").map(|val| {
207 (val.eq_ignore_ascii_case(b"always"))
208 .then(|| git_ref::store::WriteReflog::Always)
209 .or_else(|| {
210 git_config::Boolean::try_from(val)
211 .ok()
212 .and_then(|b| b.is_true().then(|| git_ref::store::WriteReflog::Normal))
213 })
214 .unwrap_or(git_ref::store::WriteReflog::Disable)
215 })
216}
git-repository/src/open.rs+4−4
@@ -270,10 +270,10 @@ impl ThreadSafeRepository { · 269 unmodified lines
270 .map(|cd| git_dir.join(cd));270 .map(|cd| git_dir.join(cd));
271 let common_dir_ref = common_dir.as_deref().unwrap_or(&git_dir);271 let common_dir_ref = common_dir.as_deref().unwrap_or(&git_dir);
272 272
273 let cache = crate::config::cache::StageOne::new(common_dir_ref, git_dir_trust)?;273 let repo_config = crate::config::cache::StageOne::new(common_dir_ref, git_dir_trust)?;
274 let mut refs = {274 let mut refs = {
275 let reflog = cache.reflog.unwrap_or(git_ref::store::WriteReflog::Disable);275 let reflog = repo_config.reflog.unwrap_or(git_ref::store::WriteReflog::Disable);
276 let object_hash = cache.object_hash;276 let object_hash = repo_config.object_hash;
277 match &common_dir {277 match &common_dir {
278 Some(common_dir) => crate::RefStore::for_linked_worktree(&git_dir, common_dir, reflog, object_hash),278 Some(common_dir) => crate::RefStore::for_linked_worktree(&git_dir, common_dir, reflog, object_hash),
279 None => crate::RefStore::at(&git_dir, reflog, object_hash),279 None => crate::RefStore::at(&git_dir, reflog, object_hash),
@@ -281,7 +281,7 @@ impl ThreadSafeRepository { · 1 unmodified line
281 };281 };
282 let head = refs.find("HEAD").ok();282 let head = refs.find("HEAD").ok();
283 let config = crate::config::Cache::from_stage_one(283 let config = crate::config::Cache::from_stage_one(
284 cache,284 repo_config,
285 common_dir_ref,285 common_dir_ref,
286 head.as_ref().and_then(|head| head.target.try_name()),286 head.as_ref().and_then(|head| head.target.try_name()),
287 filter_config_section.unwrap_or(crate::config::section::is_trusted),287 filter_config_section.unwrap_or(crate::config::section::is_trusted),