Skip to content

Commit 91ce698

Browse files
committed
re-use git history in get_last_change()
1 parent f3d7335 commit 91ce698

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

Diff for: src/info.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ impl Info {
314314
version,
315315
pending,
316316
repo_size,
317-
last_change,
318317
project_license,
319318
dominant_language,
320319
) = futures::join!(
@@ -325,14 +324,14 @@ impl Info {
325324
Info::get_version(workdir_str),
326325
Info::get_pending_changes(workdir_str),
327326
Info::get_packed_size(workdir_str),
328-
Info::get_last_change(workdir_str),
329327
Info::get_project_license(workdir_str),
330328
Language::get_dominant_language(&languages_stats)
331329
);
332330

333331
let creation_date = Info::get_creation_date(&git_history);
334332
let number_of_commits = Info::get_number_of_commits(&git_history);
335333
let authors = Info::get_authors(&git_history, author_nb);
334+
let last_change = Info::get_date_of_last_commit(&git_history);
336335

337336
let conf = config?;
338337
Ok(Info {
@@ -614,24 +613,15 @@ impl Info {
614613
}
615614
}
616615

617-
async fn get_last_change(dir: &str) -> Result<String> {
618-
let output = Command::new("git")
619-
.arg("-C")
620-
.arg(dir)
621-
.arg("log")
622-
.arg("-1")
623-
.arg("--format=%cr")
624-
.output()
625-
.await
626-
.expect("Failed to execute git.");
616+
fn get_date_of_last_commit(git_history: &[String]) -> Result<String> {
617+
let last_commit = git_history.first();
627618

628-
let output = String::from_utf8_lossy(&output.stdout);
619+
let output = match last_commit {
620+
Some(date) => date.split('\u{09}').collect::<Vec<_>>()[0].to_string(),
621+
None => "??".into(),
622+
};
629623

630-
if output == "" {
631-
Ok("??".into())
632-
} else {
633-
Ok(output.to_string().replace('\n', ""))
634-
}
624+
Ok(output)
635625
}
636626

637627
fn get_creation_date(git_history: &[String]) -> Result<String> {

0 commit comments

Comments
 (0)