diff --git a/src/info/deps/mod.rs b/src/info/deps/mod.rs index 9adc2dc4b..fff6ad1db 100644 --- a/src/info/deps/mod.rs +++ b/src/info/deps/mod.rs @@ -1,5 +1,6 @@ use anyhow::Result; use std::collections::HashMap; +use std::path::Path; use std::{ffi::OsStr, fs}; pub mod package_manager; @@ -17,7 +18,7 @@ impl DependencyDetector { DependencyDetector { package_managers } } - pub fn get_dependencies(&self, dir: &str) -> Result { + pub fn get_dependencies(&self, dir: &Path) -> Result { let deps = fs::read_dir(dir)? .filter_map(std::result::Result::ok) .map(|entry| entry.path()) diff --git a/src/info/langs/mod.rs b/src/info/langs/mod.rs index 04aa67e8b..f77f5f810 100644 --- a/src/info/langs/mod.rs +++ b/src/info/langs/mod.rs @@ -2,6 +2,7 @@ use anyhow::{Context, Result}; use language::{Language, LanguageType}; use regex::Regex; use std::collections::HashMap; +use std::path::Path; use strum::IntoEnumIterator; pub mod language; @@ -11,7 +12,7 @@ pub fn get_dominant_language(languages_stat_vec: &[(Language, f64)]) -> Language } pub fn get_language_statistics( - dir: &str, + dir: &Path, ignored_directories: &[String], language_types: &[LanguageType], include_hidden: bool, @@ -71,7 +72,7 @@ fn get_total_loc(languages: &tokei::Languages) -> usize { } fn get_statistics( - dir: &str, + dir: &Path, ignored_directories: &[String], language_types: &[LanguageType], include_hidden: bool, diff --git a/src/info/license.rs b/src/info/license.rs index ba93aa34e..7e1b90c03 100644 --- a/src/info/license.rs +++ b/src/info/license.rs @@ -1,5 +1,6 @@ use anyhow::{bail, Result}; use askalono::{Store, TextData}; +use std::path::Path; use std::{ffi::OsStr, fs}; const LICENSE_FILES: [&str; 3] = ["LICENSE", "LICENCE", "COPYING"]; @@ -24,7 +25,7 @@ impl Detector { } } - pub fn get_license(&self, dir: &str) -> Result { + pub fn get_license(&self, dir: &Path) -> Result { fn is_license_file>(file_name: S) -> bool { LICENSE_FILES .iter() diff --git a/src/info/mod.rs b/src/info/mod.rs index d35012a51..4412dfd5d 100644 --- a/src/info/mod.rs +++ b/src/info/mod.rs @@ -159,13 +159,7 @@ impl Info { pub fn new(config: Config) -> Result { let git_version = cli::get_git_version(); let repo = Repository::discover(&config.repo_path)?; - let mut internal_repo = Repo::new( - &repo, - config.no_merges, - &config.bot_regex_pattern, - config.number_of_authors, - )?; - let workdir = internal_repo.get_work_dir()?; + let workdir = repo.workdir().expect("non-bare repo").to_owned(); let pending_changes = std::thread::spawn({ let git_dir = repo.path().to_owned(); @@ -189,6 +183,12 @@ impl Info { } }); + let mut internal_repo = Repo::new( + &repo, + config.no_merges, + &config.bot_regex_pattern, + config.number_of_authors, + )?; let (repo_name, repo_url) = internal_repo.get_name_and_url()?; let head_refs = internal_repo.get_head_refs()?; let version = internal_repo.get_version()?; diff --git a/src/info/repo.rs b/src/info/repo.rs index 74d01b85e..a5c76bd64 100644 --- a/src/info/repo.rs +++ b/src/info/repo.rs @@ -152,14 +152,6 @@ impl<'a> Repo<'a> { (bytes_to_human_readable(repo_size), file_count) } - pub fn get_work_dir(&self) -> Result { - let workdir = self - .work_dir()? - .to_str() - .with_context(|| "invalid workdir")?; - Ok(workdir.to_string()) - } - pub fn get_number_of_tags(&self) -> Result { Ok(self.repo.references()?.tags()?.count()) } @@ -271,12 +263,6 @@ impl<'a> Repo<'a> { .collect(); Ok(HeadRefs::new(head_oid.shorten()?.to_string(), refs_info)) } - - fn work_dir(&self) -> Result<&Path> { - self.repo - .work_dir() - .with_context(|| "unable to query workdir") - } } fn is_bot(author: git::actor::SignatureRef<'_>, bot_regex_pattern: &Option) -> bool {