Skip to content

Commit

Permalink
Info ctor marked as async
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Aug 30, 2020
1 parent e9d7d7c commit 1f0bb64
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
{AsciiArt, CommitInfo, Configuration, Error, InfoFieldOn},
},
colored::{Color, ColoredString, Colorize},
futures::executor::block_on,
git2::Repository,
image::DynamicImage,
std::{ffi::OsStr, fmt::Write, fs},
Expand Down Expand Up @@ -286,7 +287,8 @@ impl std::fmt::Display for Info {
}

impl Info {
pub fn new(
#[tokio::main]
pub async fn new(
dir: &str,
logo: Language,
colors: Vec<String>,
Expand Down Expand Up @@ -318,10 +320,23 @@ impl Info {
creation_date,
project_license,
dominant_language,
) = Info::get_info_lines(no_merges, author_nb, &repo, workdir_str, &languages_stats);
) = futures::join!(
Info::get_configuration(&repo),
Info::get_current_commit_info(&repo),
Info::get_authors(workdir_str, no_merges, author_nb),
Info::get_git_info(workdir_str),
Info::get_version(workdir_str),
Info::get_commits(workdir_str, no_merges),
Info::get_pending_pending(workdir_str),
Info::get_packed_size(workdir_str),
Info::get_last_change(workdir_str),
Info::get_creation_time(workdir_str),
Info::get_project_license(workdir_str),
Language::get_dominant_language(&languages_stats)
);

let conf = config?;
let info = Info {
Ok(Info {
git_version: git_v,
git_username: git_user,
project_name: conf.repository_name,
Expand All @@ -345,46 +360,7 @@ impl Info {
no_color_blocks: color_blocks_flag,
custom_image,
image_backend,
};

Ok(info)
}

#[tokio::main]
async fn get_info_lines(
no_merges: bool,
author_nb: usize,
repo: &git2::Repository,
workdir_str: &str,
languages_stats: &Vec<(Language, f64)>,
) -> (
Result<Configuration>,
Result<CommitInfo>,
Vec<(String, usize, usize)>,
(String, String),
Result<String>,
Result<String>,
Result<String>,
Result<String>,
Result<String>,
Result<String>,
Result<String>,
Language,
) {
futures::join!(
Info::get_configuration(&repo),
Info::get_current_commit_info(&repo),
Info::get_authors(workdir_str, no_merges, author_nb),
Info::get_git_info(workdir_str),
Info::get_version(workdir_str),
Info::get_commits(workdir_str, no_merges),
Info::get_pending_pending(workdir_str),
Info::get_packed_size(workdir_str),
Info::get_last_change(workdir_str),
Info::get_creation_time(workdir_str),
Info::get_project_license(workdir_str),
Language::get_dominant_language(&languages_stats)
)
})
}

async fn get_configuration(repo: &Repository) -> Result<Configuration> {
Expand Down

0 comments on commit 1f0bb64

Please sign in to comment.