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
1414
1515 is_bare: bool,
1616 pub object_hash: git_hash::Kind,
17− use_multi_pack_index: bool,
1817 pub reflog: Option<git_ref::store::WriteReflog>,
1918 }
2019
@@ -38,7 +37,6 @@ impl StageOne { · 17 unmodified lines
3837 };
3938
4039 let is_bare = config_bool(&config, "core.bare", false)?;
41− let use_multi_pack_index = config_bool(&config, "core.multiPackIndex", true)?;
4240 let repo_format_version = config
4341 .value::<Integer>("core", None, "repositoryFormatVersion")
4442 .map_or(0, |v| v.to_decimal().unwrap_or_default());
@@ -57,23 +55,13 @@ impl StageOne { · 12 unmodified lines
5755 })
5856 .transpose()?
5957 .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− });
7058
59+ let reflog = query_refupdates(&config);
7160 Ok(StageOne {
7261 git_dir_config: config,
7362 buf,
7463 is_bare,
7564 object_hash,
76− use_multi_pack_index,
7765 reflog,
7866 })
7967 }
@@ -86,8 +74,7 @@ impl Cache { · 6 unmodified lines
8674 buf: _,
8775 is_bare,
8876 object_hash,
89− use_multi_pack_index,
90− reflog,
77+ reflog: _,
9178 }: StageOne,
9279 git_dir: &std::path::Path,
9380 branch_name: Option<&git_ref::FullNameRef>,
@@ -117,7 +104,6 @@ impl Cache { · 23 unmodified lines
117104 .path_filter("core", None, "excludesFile", &mut filter_config_section)
118105 .map(|p| p.interpolate(options.includes.interpolate).map(|p| p.into_owned()))
119106 .transpose()?;
120− let ignore_case = config_bool(&config, "core.ignoreCase", false)?;
121107
122108 let mut hex_len = None;
123109 if let Some(hex_len_str) = config.string("core", None, "abbrev") {
@@ -150,6 +136,9 @@ impl Cache { · 26 unmodified lines
150136 }
151137 }
152138
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)?;
153142 Ok(Cache {
154143 resolved: config.into(),
155144 use_multi_pack_index,
@@ -212,3 +201,16 @@ fn config_bool(config: &git_config::File<'_>, key: &str, default: bool) -> Resul · 56 unmodified lines
212201 key: key.into(),
213202 })
214203 }
204+
205+fn 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
270270 .map(|cd| git_dir.join(cd));
271271 let common_dir_ref = common_dir.as_deref().unwrap_or(&git_dir);
272272
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)?;
274274 let mut refs = {
275− let reflog = cache.reflog.unwrap_or(git_ref::store::WriteReflog::Disable);
276− let object_hash = cache.object_hash;
275+ let reflog = repo_config.reflog.unwrap_or(git_ref::store::WriteReflog::Disable);
276+ let object_hash = repo_config.object_hash;
277277 match &common_dir {
278278 Some(common_dir) => crate::RefStore::for_linked_worktree(&git_dir, common_dir, reflog, object_hash),
279279 None => crate::RefStore::at(&git_dir, reflog, object_hash),
@@ -281,7 +281,7 @@ impl ThreadSafeRepository { · 1 unmodified line
281281 };
282282 let head = refs.find("HEAD").ok();
283283 let config = crate::config::Cache::from_stage_one(
284− cache,
284+ repo_config,
285285 common_dir_ref,
286286 head.as_ref().and_then(|head| head.target.try_name()),
287287 filter_config_section.unwrap_or(crate::config::section::is_trusted),