git_global/subcommands/
stashed.rs1use std::sync::{mpsc, Arc};
4use std::thread;
5
6use crate::config::Config;
7use crate::errors::Result;
8use crate::repo::Repo;
9use crate::report::Report;
10
11pub fn execute(mut config: Config) -> Result<Report> {
13 let repos = config.get_repos();
14 let n_repos = repos.len();
15 let mut report = Report::new(&repos);
16 report.pad_repo_output();
17 let (tx, rx) = mpsc::channel();
19 for repo in repos {
20 let tx = tx.clone();
21 let repo = Arc::new(repo);
22 thread::spawn(move || {
23 let path = repo.path();
24 let stash = repo.get_stash_list();
25 tx.send((path, stash)).unwrap();
26 });
27 }
28 for _ in 0..n_repos {
29 let (path, stash) = rx.recv().unwrap();
30 let repo = Repo::new(path.to_string());
31 for line in stash {
32 report.add_repo_message(&repo, line);
33 }
34 }
35 Ok(report)
36}