Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't read git files when --no-gitconfig is given + unused variables #1728

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,26 +1159,27 @@ 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));
}
}

Self::from_clap_and_git_config(env, matches, final_config, assets)
}

pub fn from_iter_and_git_config<I>(
env: DeltaEnv,
env: &DeltaEnv,
iter: I,
git_config: Option<GitConfig>,
) -> Self
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 1 addition & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 1 addition & 6 deletions src/subcommands/show_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand Down
9 changes: 3 additions & 6 deletions src/subcommands/show_themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/integration_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading