summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2024-06-24 19:26:28 +0200
committerGitHub <noreply@github.com>2024-06-24 13:26:28 -0400
commitf5b37173fe88a62e37208a9587a0ab4fec0ef107 (patch)
tree6742d4289eb1bf154d034a3b675fd94929eaba80
parent0f8a2f0786d56e9395b7e7f244f356bfdab562e8 (diff)
Don't read git files when --no-gitconfig is given + unused variables (#1728)
* Fix unused variables * Don't read git files when --no-gitconfig is given Despite starting delta with `--no-gitconfig`, strace still shows that `.git/config` etc. files are accessed. By no longer doing that it is very clear that no config options are read from there.
-rw-r--r--src/cli.rs21
-rw-r--r--src/config.rs2
-rw-r--r--src/env.rs2
-rw-r--r--src/features/mod.rs2
-rw-r--r--src/main.rs6
-rw-r--r--src/subcommands/show_colors.rs7
-rw-r--r--src/subcommands/show_themes.rs9
-rw-r--r--src/tests/integration_test_utils.rs2
8 files changed, 20 insertions, 31 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 723ea42c..a18f11e4 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1159,18 +1159,19 @@ pub enum DetectDarkLight {
}
impl Opt {
- pub fn from_args_and_git_config(
- env: DeltaEnv,
- git_config: Option<GitConfig>,
- assets: HighlightingAssets,
- ) -> Self {
- let mut final_config = git_config;
+ pub fn from_args_and_git_config(env: &DeltaEnv, assets: HighlightingAssets) -> Self {
let matches = Self::command().get_matches();
+ let mut final_config = if *matches.get_one::<bool>("no_gitconfig").unwrap_or(&false) {
+ None
+ } else {
+ GitConfig::try_create(env)
+ };
+
if let Some(path) = matches.get_one::<String>("config") {
if !path.is_empty() {
let path = Path::new(path);
- final_config = Some(GitConfig::from_path(&env, path, true));
+ final_config = Some(GitConfig::from_path(env, path, true));
}
}
@@ -1178,7 +1179,7 @@ impl Opt {
}
pub fn from_iter_and_git_config<I>(
- env: DeltaEnv,
+ env: &DeltaEnv,
iter: I,
git_config: Option<GitConfig>,
) -> Self
@@ -1196,14 +1197,14 @@ impl Opt {
}
fn from_clap_and_git_config(
- env: DeltaEnv,
+ env: &DeltaEnv,
arg_matches: clap::ArgMatches,
mut git_config: Option<GitConfig>,
assets: HighlightingAssets,
) -> Self {
let mut opt = Opt::from_arg_matches(&arg_matches)
.unwrap_or_else(|_| delta_unreachable("Opt::from_arg_matches failed"));
- opt.env = env;
+ opt.env = env.clone();
options::set::set_options(&mut opt, &mut git_config, &arg_matches, assets);
opt.git_config = git_config;
opt
diff --git a/src/config.rs b/src/config.rs
index 76789289..5247cdf8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -125,7 +125,6 @@ pub struct Config {
pub show_themes: bool,
pub side_by_side_data: side_by_side::SideBySideData,
pub side_by_side: bool,
- pub syntax_dummy_theme: SyntaxTheme,
pub syntax_set: SyntaxSet,
pub syntax_theme: Option<SyntaxTheme>,
pub tab_cfg: utils::tabs::TabCfg,
@@ -417,7 +416,6 @@ impl From<cli::Opt> for Config {
side_by_side: opt.side_by_side && !handlers::hunk::is_word_diff(),
side_by_side_data,
styles_map,
- syntax_dummy_theme: SyntaxTheme::default(),
syntax_set: opt.computed.syntax_set,
syntax_theme: opt.computed.syntax_theme,
tab_cfg: utils::tabs::TabCfg::new(opt.tab_width),
diff --git a/src/env.rs b/src/env.rs
index 8c169bcc..49c7b212 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -77,6 +77,8 @@ pub mod tests {
env::set_var("DELTA_FEATURES", feature);
let env = DeltaEnv::init();
assert_eq!(env.features, Some(feature.into()));
+ // otherwise `current_dir` is not used in the test cfg:
+ assert_eq!(env.current_dir, env::current_dir().ok());
}
#[test]
diff --git a/src/features/mod.rs b/src/features/mod.rs
index dfc3582d..133cea42 100644
--- a/src/features/mod.rs
+++ b/src/features/mod.rs
@@ -103,7 +103,7 @@ pub mod tests {
let builtin_features = make_builtin_features();
let mut args = vec!["delta".to_string()];
args.extend(builtin_features.keys().map(|s| format!("--{s}")));
- let opt = cli::Opt::from_iter_and_git_config(DeltaEnv::default(), args, None);
+ let opt = cli::Opt::from_iter_and_git_config(&DeltaEnv::default(), args, None);
let features: HashSet<&str> = opt
.features
.as_deref()
diff --git a/src/main.rs b/src/main.rs
index 67ea0ca3..925e7dc4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -76,11 +76,7 @@ fn main() -> std::io::Result<()> {
fn run_app() -> std::io::Result<i32> {
let assets = utils::bat::assets::load_highlighting_assets();
let env = env::DeltaEnv::init();
- let opt = cli::Opt::from_args_and_git_config(
- env.clone(),
- git_config::GitConfig::try_create(&env),
- assets,
- );
+ let opt = cli::Opt::from_args_and_git_config(&env, assets);
let subcommand_result = if let Some(shell) = opt.generate_completion {
Some(subcommands::generate_completion::generate_completion_file(
diff --git a/src/subcommands/show_colors.rs b/src/subcommands/show_colors.rs
index 2898dd97..9d0428c7 100644
--- a/src/subcommands/show_colors.rs
+++ b/src/subcommands/show_colors.rs
@@ -4,7 +4,6 @@ use crate::colors;
use crate::config;
use crate::delta;
use crate::env::DeltaEnv;
-use crate::git_config;
use crate::paint;
use crate::paint::BgShouldFill;
use crate::style;
@@ -16,11 +15,7 @@ pub fn show_colors() -> std::io::Result<()> {
let assets = utils::bat::assets::load_highlighting_assets();
let env = DeltaEnv::default();
- let opt = cli::Opt::from_args_and_git_config(
- env.clone(),
- git_config::GitConfig::try_create(&env),
- assets,
- );
+ let opt = cli::Opt::from_args_and_git_config(&env, assets);
let config = config::Config::from(opt);
let mut output_type =
diff --git a/src/subcommands/show_themes.rs b/src/subcommands/show_themes.rs
index 52c92386..86cae34d 100644
--- a/src/subcommands/show_themes.rs
+++ b/src/subcommands/show_themes.rs
@@ -36,7 +36,7 @@ pub fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> st
let git_config = git_config::GitConfig::try_create(&env);
let opt = cli::Opt::from_iter_and_git_config(
- env.clone(),
+ &env,
&["delta", "--navigate", "--show-themes"],
git_config,
);
@@ -47,11 +47,8 @@ pub fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> st
for theme in &themes {
let git_config = git_config::GitConfig::try_create(&env);
- let opt = cli::Opt::from_iter_and_git_config(
- env.clone(),
- &["delta", "--features", theme],
- git_config,
- );
+ let opt =
+ cli::Opt::from_iter_and_git_config(&env, &["delta", "--features", theme], git_config);
let is_dark_theme = opt.dark;
let is_light_theme = opt.light;
let config = config::Config::from(opt);
diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs
index 764be5d2..09e445e9 100644
--- a/src/tests/integration_test_utils.rs
+++ b/src/tests/integration_test_utils.rs
@@ -66,7 +66,7 @@ fn _make_options_from_args_and_git_config(
None
}
};
- cli::Opt::from_iter_and_git_config(env, args, git_config)
+ cli::Opt::from_iter_and_git_config(&env, args, git_config)
}
pub fn make_options_from_args(args: &[&str]) -> cli::Opt {