Skip to content

Commit

Permalink
Do three things in parallel, don't wait for Repo::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 30, 2022
1 parent d178a5c commit 633f0ce
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/info/deps/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use std::collections::HashMap;
use std::path::Path;
use std::{ffi::OsStr, fs};

pub mod package_manager;
Expand All @@ -17,7 +18,7 @@ impl DependencyDetector {
DependencyDetector { package_managers }
}

pub fn get_dependencies(&self, dir: &str) -> Result<String> {
pub fn get_dependencies(&self, dir: &Path) -> Result<String> {
let deps = fs::read_dir(dir)?
.filter_map(std::result::Result::ok)
.map(|entry| entry.path())
Expand Down
5 changes: 3 additions & 2 deletions src/info/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/info/license.rs
Original file line number Diff line number Diff line change
@@ -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"];
Expand All @@ -24,7 +25,7 @@ impl Detector {
}
}

pub fn get_license(&self, dir: &str) -> Result<String> {
pub fn get_license(&self, dir: &Path) -> Result<String> {
fn is_license_file<S: AsRef<str>>(file_name: S) -> bool {
LICENSE_FILES
.iter()
Expand Down
14 changes: 7 additions & 7 deletions src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ impl Info {
pub fn new(config: Config) -> Result<Self> {
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();
Expand All @@ -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()?;
Expand Down
14 changes: 0 additions & 14 deletions src/info/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ impl<'a> Repo<'a> {
(bytes_to_human_readable(repo_size), file_count)
}

pub fn get_work_dir(&self) -> Result<String> {
let workdir = self
.work_dir()?
.to_str()
.with_context(|| "invalid workdir")?;
Ok(workdir.to_string())
}

pub fn get_number_of_tags(&self) -> Result<usize> {
Ok(self.repo.references()?.tags()?.count())
}
Expand Down Expand Up @@ -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<Regex>) -> bool {
Expand Down

0 comments on commit 633f0ce

Please sign in to comment.