From 7e73ebcad03a5477367763d4a5e9c22f9e9967ca Mon Sep 17 00:00:00 2001 From: Max Audron Date: Tue, 7 Jun 2022 12:28:18 +0200 Subject: process sync and update in parallel Split the repos up in x batches where x is either decided on based on number of cpu cores available or given by the --jobs argument --- src/update/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/update/mod.rs') diff --git a/src/update/mod.rs b/src/update/mod.rs index d2d6494..8f10663 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -3,20 +3,21 @@ use std::fmt::{Debug, Display}; use git2::BranchType; use tracing::debug; -use crate::repo::{Repo, RepoError, Repos}; +use crate::{ + batch::batch, + repo::{Repo, RepoError, Repos}, +}; impl crate::GTree { pub fn update(&self, repos: Repos) { - for (_name, repo) in repos { - let mut repo = repo.write().unwrap(); - + batch(repos, |mut repo| { if repo.repo.is_some() { match repo.update() { Ok(u) => println!("{}", u), Err(u) => println!("{}", u), }; } - } + }); } } -- cgit v1.2.3