It's special as it creates its own repository.
Unified · Split
| @@ -83,7 +83,7 @@ impl<'repo> Snapshot<'repo> { · 82 unmodified lines | ||
| 83 | 83 | |
| 84 | 84 | /// |
| 85 | 85 | pub mod apply_cli_overrides { |
| 86 | − use crate::bstr::{BString, ByteSlice}; | |
| 86 | + use crate::bstr::{BStr, BString, ByteSlice}; | |
| 87 | 87 | use crate::config::SnapshotMut; |
| 88 | 88 | use std::convert::TryFrom; |
| 89 | 89 | |
| @@ -105,13 +105,13 @@ pub mod apply_cli_overrides { · 15 unmodified lines | ||
| 105 | 105 | impl SnapshotMut<'_> { |
| 106 | 106 | /// Apply configuration values of the form `core.abbrev=5` or `remote.origin.url = foo` or `core.bool-implicit-true` |
| 107 | 107 | /// to the repository configuration, marked with [source CLI][git_config::Source::Cli]. |
| 108 | − pub fn apply_cli_overrides( | |
| 108 | + pub fn apply_cli_overrides<'a>( | |
| 109 | 109 | &mut self, |
| 110 | − values: impl IntoIterator<Item = impl Into<BString>>, | |
| 110 | + values: impl IntoIterator<Item = impl AsRef<BStr>>, | |
| 111 | 111 | ) -> Result<(), Error> { |
| 112 | 112 | let mut file = git_config::File::new(git_config::file::Metadata::from(git_config::Source::Cli)); |
| 113 | 113 | for key_value in values { |
| 114 | − let key_value = key_value.into(); | |
| 114 | + let key_value = key_value.as_ref(); | |
| 115 | 115 | let mut tokens = key_value.splitn(2, |b| *b == b'=').map(|v| v.trim()); |
| 116 | 116 | let key = tokens.next().expect("always one value").as_bstr(); |
| 117 | 117 | let value = tokens.next(); |
| @@ -1,18 +1,21 @@ | ||
| 1 | 1 | use anyhow::{bail, Result}; |
| 2 | 2 | use git_repository as git; |
| 3 | +use git_repository::bstr::BString; | |
| 3 | 4 | |
| 4 | 5 | use crate::OutputFormat; |
| 5 | 6 | |
| 6 | 7 | pub fn list( |
| 7 | 8 | repo: git::Repository, |
| 8 | 9 | filters: Vec<String>, |
| 10 | + overrides: Vec<BString>, | |
| 9 | 11 | format: OutputFormat, |
| 10 | 12 | mut out: impl std::io::Write, |
| 11 | 13 | ) -> Result<()> { |
| 12 | 14 | if format != OutputFormat::Human { |
| 13 | 15 | bail!("Only human output format is supported at the moment"); |
| 14 | 16 | } |
| 15 | − let repo = git::open_opts(repo.git_dir(), repo.open_options().clone().lossy_config(false))?; | |
| 17 | + let mut repo = git::open_opts(repo.git_dir(), repo.open_options().clone().lossy_config(false))?; | |
| 18 | + repo.config_snapshot_mut().apply_cli_overrides(overrides.into_iter())?; | |
| 16 | 19 | let config = repo.config_snapshot(); |
| 17 | 20 | let config = config.plumbing(); |
| 18 | 21 | if let Some(frontmatter) = config.frontmatter() { |
| @@ -62,20 +62,24 @@ pub fn main() -> Result<()> { · 61 unmodified lines | ||
| 62 | 62 | Strict, |
| 63 | 63 | Lenient, |
| 64 | 64 | } |
| 65 | − let repository = move |mode: Mode| -> Result<git::Repository> { | |
| 66 | − let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default(); | |
| 67 | − let toggle = matches!(mode, Mode::Strict); | |
| 68 | − mapping.full = mapping.full.strict_config(toggle); | |
| 69 | − mapping.reduced = mapping.reduced.strict_config(toggle); | |
| 70 | − let mut repo = git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping) | |
| 71 | − .map(git::Repository::from) | |
| 72 | − .map(|r| r.apply_environment())?; | |
| 73 | − if !config.is_empty() { | |
| 74 | − repo.config_snapshot_mut() | |
| 75 | − .apply_cli_overrides(config) | |
| 76 | − .context("Unable to parse command-line configuration")?; | |
| 65 | + | |
| 66 | + let repository = { | |
| 67 | + let config = config.clone(); | |
| 68 | + move |mode: Mode| -> Result<git::Repository> { | |
| 69 | + let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default(); | |
| 70 | + let toggle = matches!(mode, Mode::Strict); | |
| 71 | + mapping.full = mapping.full.strict_config(toggle); | |
| 72 | + mapping.reduced = mapping.reduced.strict_config(toggle); | |
| 73 | + let mut repo = git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping) | |
| 74 | + .map(git::Repository::from) | |
| 75 | + .map(|r| r.apply_environment())?; | |
| 76 | + if !config.is_empty() { | |
| 77 | + repo.config_snapshot_mut() | |
| 78 | + .apply_cli_overrides(config.iter()) | |
| 79 | + .context("Unable to parse command-line configuration")?; | |
| 80 | + } | |
| 81 | + Ok(repo) | |
| 77 | 82 | } |
| 78 | − Ok(repo) | |
| 79 | 83 | }; |
| 80 | 84 | |
| 81 | 85 | let progress; |
| @@ -142,7 +146,9 @@ pub fn main() -> Result<()> { · 60 unmodified lines | ||
| 142 | 146 | progress, |
| 143 | 147 | progress_keep_open, |
| 144 | 148 | None, |
| 145 | − move |_progress, out, _err| core::repository::config::list(repository(Mode::Lenient)?, filter, format, out), | |
| 149 | + move |_progress, out, _err| { | |
| 150 | + core::repository::config::list(repository(Mode::Lenient)?, filter, config, format, out) | |
| 151 | + }, | |
| 146 | 152 | ) |
| 147 | 153 | .map(|_| ()), |
| 148 | 154 | Subcommands::Free(subcommands) => match subcommands { |