From c2428be80c94e43609824608b8ef148be8b9da56 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 26 Jul 2022 20:00:42 +0100 Subject: [PATCH] HUGE `mlc info` speedup when pulling through ssh --- src/operations/info.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/operations/info.rs b/src/operations/info.rs index 6baa58f..4ff94e9 100644 --- a/src/operations/info.rs +++ b/src/operations/info.rs @@ -1,6 +1,7 @@ use colored::Colorize; use spinoff::{Color, Spinner, Spinners}; use std::env; +use std::fmt::Write; use std::process::Command; use tabled::Tabled; @@ -46,11 +47,6 @@ pub fn git_status(verbose: bool, repo: &str, colorblind: bool) -> String { }); log!(verbose, "Current directory: {}", repo); - Command::new("git") - .args(&["remote", "update"]) - .output() - .unwrap(); - let output = Command::new("git").arg("status").output().unwrap(); let output = String::from_utf8(output.stdout).unwrap(); log!(verbose, "Git status: {}", output); @@ -126,6 +122,26 @@ pub fn info(verbose: bool) { Color::Green, ); + // Construct bash script to run git remote upgrade on all repos asynchronously + // This helps speed up the operation when, for example, you have a lot of repositories and you store your SSH key as a subkey of your GPG key on a yubikey + // This took my `mlc info` time down from 17s to 8s (i have the above described setup) + let mut bash_script = String::new(); + bash_script.push_str("\n\ + #!/usr/bin/env bash\n\ + \n\ + # This script will run `git remote update` in all repositories\n\ + pull() { cd $1; git remote update; cd -; }\n\ + \n"); + for repo in &repos_unparsed { + writeln!(bash_script, "pull {} &", repo.name).unwrap(); + } + bash_script.push_str("wait\n"); + + log!(verbose, "Bash script: {}", bash_script); + + // Run the bash script + Command::new("bash").arg("-c").arg(bash_script).output().unwrap(); + // Iterate over all repositories for repo in repos_unparsed { // Get name with branch, '/' serving as the delimiter