Skip to content

Commit 633f0ce

Browse files
committed
Do three things in parallel, don't wait for Repo::new()
1 parent d178a5c commit 633f0ce

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

src/info/deps/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::Result;
22
use std::collections::HashMap;
3+
use std::path::Path;
34
use std::{ffi::OsStr, fs};
45

56
pub mod package_manager;
@@ -17,7 +18,7 @@ impl DependencyDetector {
1718
DependencyDetector { package_managers }
1819
}
1920

20-
pub fn get_dependencies(&self, dir: &str) -> Result<String> {
21+
pub fn get_dependencies(&self, dir: &Path) -> Result<String> {
2122
let deps = fs::read_dir(dir)?
2223
.filter_map(std::result::Result::ok)
2324
.map(|entry| entry.path())

src/info/langs/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::{Context, Result};
22
use language::{Language, LanguageType};
33
use regex::Regex;
44
use std::collections::HashMap;
5+
use std::path::Path;
56
use strum::IntoEnumIterator;
67

78
pub mod language;
@@ -11,7 +12,7 @@ pub fn get_dominant_language(languages_stat_vec: &[(Language, f64)]) -> Language
1112
}
1213

1314
pub fn get_language_statistics(
14-
dir: &str,
15+
dir: &Path,
1516
ignored_directories: &[String],
1617
language_types: &[LanguageType],
1718
include_hidden: bool,
@@ -71,7 +72,7 @@ fn get_total_loc(languages: &tokei::Languages) -> usize {
7172
}
7273

7374
fn get_statistics(
74-
dir: &str,
75+
dir: &Path,
7576
ignored_directories: &[String],
7677
language_types: &[LanguageType],
7778
include_hidden: bool,

src/info/license.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::{bail, Result};
22
use askalono::{Store, TextData};
3+
use std::path::Path;
34
use std::{ffi::OsStr, fs};
45

56
const LICENSE_FILES: [&str; 3] = ["LICENSE", "LICENCE", "COPYING"];
@@ -24,7 +25,7 @@ impl Detector {
2425
}
2526
}
2627

27-
pub fn get_license(&self, dir: &str) -> Result<String> {
28+
pub fn get_license(&self, dir: &Path) -> Result<String> {
2829
fn is_license_file<S: AsRef<str>>(file_name: S) -> bool {
2930
LICENSE_FILES
3031
.iter()

src/info/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,7 @@ impl Info {
159159
pub fn new(config: Config) -> Result<Self> {
160160
let git_version = cli::get_git_version();
161161
let repo = Repository::discover(&config.repo_path)?;
162-
let mut internal_repo = Repo::new(
163-
&repo,
164-
config.no_merges,
165-
&config.bot_regex_pattern,
166-
config.number_of_authors,
167-
)?;
168-
let workdir = internal_repo.get_work_dir()?;
162+
let workdir = repo.workdir().expect("non-bare repo").to_owned();
169163

170164
let pending_changes = std::thread::spawn({
171165
let git_dir = repo.path().to_owned();
@@ -189,6 +183,12 @@ impl Info {
189183
}
190184
});
191185

186+
let mut internal_repo = Repo::new(
187+
&repo,
188+
config.no_merges,
189+
&config.bot_regex_pattern,
190+
config.number_of_authors,
191+
)?;
192192
let (repo_name, repo_url) = internal_repo.get_name_and_url()?;
193193
let head_refs = internal_repo.get_head_refs()?;
194194
let version = internal_repo.get_version()?;

src/info/repo.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ impl<'a> Repo<'a> {
152152
(bytes_to_human_readable(repo_size), file_count)
153153
}
154154

155-
pub fn get_work_dir(&self) -> Result<String> {
156-
let workdir = self
157-
.work_dir()?
158-
.to_str()
159-
.with_context(|| "invalid workdir")?;
160-
Ok(workdir.to_string())
161-
}
162-
163155
pub fn get_number_of_tags(&self) -> Result<usize> {
164156
Ok(self.repo.references()?.tags()?.count())
165157
}
@@ -271,12 +263,6 @@ impl<'a> Repo<'a> {
271263
.collect();
272264
Ok(HeadRefs::new(head_oid.shorten()?.to_string(), refs_info))
273265
}
274-
275-
fn work_dir(&self) -> Result<&Path> {
276-
self.repo
277-
.work_dir()
278-
.with_context(|| "unable to query workdir")
279-
}
280266
}
281267

282268
fn is_bot(author: git::actor::SignatureRef<'_>, bot_regex_pattern: &Option<Regex>) -> bool {

0 commit comments

Comments
 (0)