summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-05-09 23:51:50 -0400
committerGitHub <noreply@github.com>2019-05-09 23:51:50 -0400
commit8b5055d5106da402f9a132f0ed21571ef98b8ac2 (patch)
treed5d83454742235f44b183b932355189983ba074c /src
parentc6ee5c6ac16d360ab1a44d097c91fe9f98f20f85 (diff)
Parallelize prompt modules (#46)
Diffstat (limited to 'src')
-rw-r--r--src/context.rs8
-rw-r--r--src/modules/directory.rs3
-rw-r--r--src/modules/git_branch.rs8
-rw-r--r--src/print.rs3
4 files changed, 11 insertions, 11 deletions
diff --git a/src/context.rs b/src/context.rs
index 6baa19536..035eec90a 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -8,7 +8,7 @@ pub struct Context<'a> {
pub current_dir: PathBuf,
pub dir_files: Vec<PathBuf>,
pub arguments: ArgMatches<'a>,
- pub repository: Option<Repository>,
+ pub repo_root: Option<PathBuf>,
}
impl<'a> Context<'a> {
@@ -36,13 +36,15 @@ impl<'a> Context<'a> {
.map(|entry| entry.path())
.collect::<Vec<PathBuf>>();
- let repository: Option<Repository> = Repository::discover(&current_dir).ok();
+ let repo_root: Option<PathBuf> = Repository::discover(&current_dir)
+ .ok()
+ .and_then(|repo| repo.workdir().map(|repo| repo.to_path_buf()));
Context {
arguments,
current_dir,
dir_files,
- repository,
+ repo_root,
}
}
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index a85287a67..e0f4a9e12 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -23,9 +23,8 @@ pub fn segment(context: &Context) -> Option<Module> {
let current_dir = &context.current_dir;
let dir_string;
- if let Some(repo) = &context.repository {
+ if let Some(repo_root) = &context.repo_root {
// Contract the path to the git repo root
- let repo_root = repo.workdir().unwrap();
let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap();
dir_string = contract_path(&current_dir, repo_root, repo_folder_name);
diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs
index a89e77f3e..22b934da3 100644
--- a/src/modules/git_branch.rs
+++ b/src/modules/git_branch.rs
@@ -7,12 +7,10 @@ use super::{Context, Module};
///
/// Will display the branch name if the current directory is a git repo
pub fn segment(context: &Context) -> Option<Module> {
- if context.repository.is_none() {
- return None;
- }
+ let repo_root = context.repo_root.as_ref()?;
+ let repository = Repository::open(repo_root).ok()?;
- let repository = context.repository.as_ref().unwrap();
- match get_current_branch(repository) {
+ match get_current_branch(&repository) {
Ok(branch_name) => {
const GIT_BRANCH_CHAR: &str = " ";
let segment_color = Color::Purple.bold();
diff --git a/src/print.rs b/src/print.rs
index 780d90998..3020f9de9 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -1,4 +1,5 @@
use clap::ArgMatches;
+use rayon::prelude::*;
use std::io::{self, Write};
use crate::context::Context;
@@ -29,7 +30,7 @@ pub fn prompt(args: ArgMatches) {
writeln!(handle).unwrap();
let modules = prompt_order
- .iter()
+ .par_iter()
.map(|module| modules::handle(module, &context)) // Compute modules
.flatten()
.collect::<Vec<Module>>(); // Remove segments set to `None`