Skip to content

Commit

Permalink
remove rayon. tidy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDavison committed Mar 18, 2024
1 parent c9443ca commit 5dd29c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 91 deletions.
52 changes: 0 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "repoutil"
version = "0.28.0"
version = "0.29.0"
authors = ["Chris Davison <c.jr.davison@gmail.com>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,4 +13,3 @@ description = "Wrapper around my common git commands"
shellexpand = "3.1.0"
anyhow = "1.0"
structopt = "0.3.26"
rayon = "1.8.1"
64 changes: 27 additions & 37 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::{anyhow, Result};
use rayon::prelude::*;
use std::fs::read_dir;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
Expand Down Expand Up @@ -45,17 +44,17 @@ enum OptCommand {

fn common_substring<T: ToString>(ss: &[T]) -> String {
let mut idx = 0;
let charlists = ss.iter().map(|x| x.to_string().chars().collect()).collect::<Vec<Vec<char>>>();
let charlists = ss
.iter()
.map(|x| x.to_string().chars().collect())
.collect::<Vec<Vec<char>>>();
if charlists.is_empty() {
return "".to_string();
}
let first_charlist = &charlists[0];
loop {
let first = first_charlist.iter().nth(idx);
if !charlists
.iter()
.all(|w| w.iter().nth(idx) == first)
{
let first = first_charlist.get(idx);
if !charlists.iter().all(|w| w.get(idx) == first) {
break;
}
idx += 1;
Expand Down Expand Up @@ -101,38 +100,29 @@ fn main() {

let all_repos = get_repos_from_config().expect("Couldn't get repos");

let n = all_repos.len();
println!("Running `{:?}` on {n} repos\n", opts.command);
let mut messages: Vec<_> = all_repos
.par_iter()
.map(|repo| match cmd(repo, json) {
Ok(Some(out)) => out,
Err(e) => format!("ERR Repo {}: {}", repo.display(), e),
_ => String::new(),
})
.collect();

messages.sort();
let messages = messages.iter().filter(|msg| !msg.is_empty());
if json {
println!(
"{{\"items\": [{}]}}",
messages
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(",")
);
} else {
let messages = messages.map(|x| x.to_string()).collect::<Vec<String>>();
let common = if messages.is_empty() {
String::new()
} else {
common_substring(&messages)
};
for msg in messages {
println!("{}", msg.replace(&common, ""))
let common = common_substring(
&all_repos
.iter()
.map(|x| x.display().to_string())
.collect::<Vec<String>>(),
);
let mut outs = Vec::new();
for repo in all_repos {
match cmd(&repo, json) {
Ok(Some(out)) => {
if json {
outs.push(out.replace(&common, ""));
} else {
println!("{}", out.replace(&common, ""))
}
}
Ok(_) => (),
Err(e) => eprintln!("ERR Repo {}: {}", repo.display(), e),
}
}
if json {
println!("{{\"items\": [{}]}}", outs.join(","));
}
}

fn get_dirs_from_config() -> Result<(Vec<PathBuf>, Vec<PathBuf>)> {
Expand Down

0 comments on commit 5dd29c2

Please sign in to comment.