Update/clone all git repositories in parallel with rayon. A progress bar is added for progress indication.
(&self, repos: &[String], download_dir: &Path)
| 134 | /// |
| 135 | /// A progress bar is added for progress indication. |
| 136 | fn parallel_update_or_clone(&self, repos: &[String], download_dir: &Path) -> Result<(), Error> { |
| 137 | let progress_bar = get_progress_bar(repos.len() as u64); |
| 138 | |
| 139 | // Prepare a ssh session for better performance. |
| 140 | warmup_ssh_session()?; |
| 141 | |
| 142 | // Clone/update all repositories in parallel |
| 143 | let results: Vec<Result<(), Error>> = repos |
| 144 | .par_iter() |
| 145 | .map(|repo| { |
| 146 | let target_dir = download_dir.join(repo); |
| 147 | |
| 148 | // If the repo already exists, only pull it. |
| 149 | // Otherwise do a clone. |
| 150 | let result = if target_dir.exists() { |
| 151 | update_repo(repo, &target_dir) |
| 152 | } else { |
| 153 | clone_repo(repo.to_string(), &target_dir) |
| 154 | }; |
| 155 | |
| 156 | // Increment the counter |
| 157 | progress_bar.inc(1); |
| 158 | result |
| 159 | }) |
| 160 | .collect(); |
| 161 | |
| 162 | // Finish the spinner |
| 163 | progress_bar.finish_with_message("All repositories cloned or updated."); |
| 164 | |
| 165 | // Display any errors during cloning/updating to the user. |
| 166 | let mut error_iter = results.into_iter().filter_map(Result::err).peekable(); |
| 167 | if error_iter.peek().is_some() { |
| 168 | error!("The command failed for the following repositories:"); |
| 169 | for error in error_iter { |
| 170 | error!("{error}"); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | Ok(()) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /// Create a new ssh connection that doesn't get bound to a given session. |
no test coverage detected