Git concurrency limit (#420)

This commit is contained in:
Roey Darwish Dror
2020-06-06 17:34:27 +03:00
committed by GitHub
parent 3f9ab8ccd7
commit 612d74840e
3 changed files with 39 additions and 16 deletions

View File

@@ -59,3 +59,6 @@
#yay_arguments = "--nodevel" #yay_arguments = "--nodevel"
#trizen_arguments = "--devel" #trizen_arguments = "--devel"
#enable_tlmgr = true #enable_tlmgr = true
#[git]
#max_concurrency = 5

View File

@@ -50,6 +50,11 @@ pub enum Step {
Tmux, Tmux,
} }
#[derive(Deserialize, Default, Debug)]
pub struct Git {
max_concurrency: Option<usize>,
}
#[derive(Deserialize, Default, Debug)] #[derive(Deserialize, Default, Debug)]
pub struct Brew { pub struct Brew {
greedy_cask: Option<bool>, greedy_cask: Option<bool>,
@@ -93,6 +98,7 @@ pub struct ConfigFile {
composer: Option<Composer>, composer: Option<Composer>,
brew: Option<Brew>, brew: Option<Brew>,
linux: Option<Linux>, linux: Option<Linux>,
git: Option<Git>,
} }
impl ConfigFile { impl ConfigFile {
@@ -440,6 +446,11 @@ impl Config {
.and_then(|linux| linux.dnf_arguments.as_deref()) .and_then(|linux| linux.dnf_arguments.as_deref())
} }
/// Concurrency limit for git
pub fn git_concurrency_limit(&self) -> Option<usize> {
self.config_file.git.as_ref().and_then(|git| git.max_concurrency)
}
/// Extra yay arguments /// Extra yay arguments
#[allow(dead_code)] #[allow(dead_code)]
pub fn enable_tlmgr_linux(&self) -> bool { pub fn enable_tlmgr_linux(&self) -> bool {

View File

@@ -1,19 +1,22 @@
use std::collections::HashSet;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use anyhow::Result;
use console::style;
use futures::stream::{iter, FuturesUnordered};
use futures::StreamExt;
use glob::{glob_with, MatchOptions};
use log::{debug, error};
use tokio::process::Command as AsyncCommand;
use tokio::runtime;
use crate::error::SkipStep; use crate::error::SkipStep;
use crate::execution_context::ExecutionContext; use crate::execution_context::ExecutionContext;
use crate::executor::{CommandExt, RunType}; use crate::executor::{CommandExt, RunType};
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::{which, PathExt}; use crate::utils::{which, PathExt};
use anyhow::Result;
use console::style;
use futures::future::try_join_all;
use glob::{glob_with, MatchOptions};
use log::{debug, error};
use std::collections::HashSet;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use tokio::process::Command as AsyncCommand;
use tokio::runtime;
#[cfg(windows)] #[cfg(windows)]
static PATH_PREFIX: &str = "\\\\?\\"; static PATH_PREFIX: &str = "\\\\?\\";
@@ -189,7 +192,7 @@ impl Git {
return Ok(()); return Ok(());
} }
let futures: Vec<_> = repositories let futures_iterator = repositories
.repositories .repositories
.iter() .iter()
.filter(|repo| match has_remotes(git, repo) { .filter(|repo| match has_remotes(git, repo) {
@@ -203,13 +206,19 @@ impl Git {
} }
_ => true, // repo has remotes or command to check for remotes has failed. proceed to pull anyway. _ => true, // repo has remotes or command to check for remotes has failed. proceed to pull anyway.
}) })
.map(|repo| pull_repository(repo.clone(), &git, ctx)) .map(|repo| pull_repository(repo.clone(), &git, ctx));
.collect();
let stream_of_futures = if let Some(limit) = ctx.config().git_concurrency_limit() {
iter(futures_iterator).buffer_unordered(limit).boxed()
} else {
futures_iterator.collect::<FuturesUnordered<_>>().boxed()
};
let mut basic_rt = runtime::Runtime::new()?; let mut basic_rt = runtime::Runtime::new()?;
basic_rt.block_on(async { try_join_all(futures).await })?; let results = basic_rt.block_on(async { stream_of_futures.collect::<Vec<Result<()>>>().await });
Ok(()) let error = results.into_iter().find(|r| r.is_err());
error.unwrap_or(Ok(()))
} }
} }