Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dev/run_benchmarks_for_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ echo "To run these benchmarks on your application, you can place this repo next

hyperfine --warmup=2 --runs=3 --export-markdown tmp/codeowners_for_file_benchmarks.md \
"../rubyatscale/codeowners-rs/target/release/codeowners for-file \"$1\"" \
"bin/codeowners for_file \"$1\"" \
"bin/codeownership for_file \"$1\""
1 change: 0 additions & 1 deletion dev/run_benchmarks_for_gv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ echo "To run these benchmarks on your application, you can place this repo next

hyperfine --warmup=2 --runs=3 --export-markdown tmp/codeowners_benchmarks_gv.md \
'../rubyatscale/codeowners-rs/target/release/codeowners gv' \
'bin/codeowners validate' \
'bin/codeownership validate'
179 changes: 0 additions & 179 deletions src/bin/compare_for_file.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use path_clean::PathClean;
use std::path::{Path, PathBuf};

#[derive(Subcommand, Debug)]
#[command(version)]
enum Command {
#[clap(about = "Finds the owner of a given file.", visible_alias = "f")]
ForFile {
Expand Down Expand Up @@ -109,7 +110,7 @@ pub fn cli() -> Result<RunResult, RunnerError> {
Command::Validate => runner::validate(&run_config, vec![]),
Command::Generate { skip_stage } => runner::generate(&run_config, !skip_stage),
Command::GenerateAndValidate { skip_stage } => runner::generate_and_validate(&run_config, vec![], !skip_stage),
Command::ForFile { name, fast } => runner::for_file(&run_config, &name, fast),
Command::ForFile { name, fast: _ } => runner::for_file(&run_config, &name),
Command::ForTeam { name } => runner::for_team(&run_config, &name),
Command::DeleteCache => runner::delete_cache(&run_config),
};
Expand Down
26 changes: 16 additions & 10 deletions src/ownership/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ impl Parser {
fn teams_by_github_team_name(team_file_glob: Vec<String>) -> HashMap<String, Team> {
let mut teams = HashMap::new();
for glob in team_file_glob {
let paths = glob::glob(&glob).expect("Failed to read glob pattern").filter_map(Result::ok);

for path in paths {
let team = match Team::from_team_file_path(path) {
Ok(team) => team,
Err(e) => {
eprintln!("Error parsing team file: {}", e);
continue;
match glob::glob(&glob) {
Ok(paths) => {
for path in paths.filter_map(Result::ok) {
let team = match Team::from_team_file_path(path) {
Ok(team) => team,
Err(e) => {
eprintln!("Error parsing team file: {}", e);
continue;
}
};
teams.insert(team.github_team.clone(), team);
}
};
teams.insert(team.github_team.clone(), team);
}
Err(e) => {
eprintln!("Failed to read glob pattern '{}': {}", glob, e);
continue;
}
}
}

Expand Down
43 changes: 31 additions & 12 deletions src/project_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,25 @@ impl<'a> ProjectBuilder<'a> {
})
});

// Process sequentially with &mut self
let collected_entries = Arc::try_unwrap(collected).unwrap().into_inner().unwrap();
// Process sequentially with &mut self without panicking on Arc/Mutex unwraps
let collected_entries = match Arc::try_unwrap(collected) {
// We are the sole owner of the Arc
Ok(mutex) => match mutex.into_inner() {
// Mutex not poisoned
Ok(entries) => entries,
// Recover entries even if the mutex was poisoned
Err(poisoned) => poisoned.into_inner(),
},
// There are still other Arc references; lock and take the contents
Err(arc) => match arc.lock() {
Ok(mut guard) => std::mem::take(&mut *guard),
// Recover guard even if poisoned, then take contents
Err(poisoned) => {
let mut guard = poisoned.into_inner();
std::mem::take(&mut *guard)
}
},
};
for entry in collected_entries {
entry_types.push(self.build_entry_type(entry)?);
}
Expand All @@ -89,11 +106,10 @@ impl<'a> ProjectBuilder<'a> {
if is_dir {
return Ok(EntryType::Directory(absolute_path.to_owned(), relative_path.to_owned()));
}
let file_name = relative_path
.file_name()
.expect("expected a file_name")
.to_string_lossy()
.to_lowercase();
let file_name = match relative_path.file_name() {
Some(name) => name.to_string_lossy().to_lowercase(),
None => return Ok(EntryType::NullEntry()),
};

match file_name.as_str() {
name if name == "package.yml"
Expand Down Expand Up @@ -142,11 +158,14 @@ impl<'a> ProjectBuilder<'a> {
}
EntryType::Directory(absolute_path, relative_path) => {
if relative_path.parent() == Some(Path::new(&self.config.vendored_gems_path)) {
let file_name = relative_path.file_name().expect("expected a file_name");
gems.push(VendoredGem {
path: absolute_path,
name: file_name.to_string_lossy().to_string(),
});
if let Some(file_name) = relative_path.file_name() {
gems.push(VendoredGem {
path: absolute_path,
name: file_name.to_string_lossy().to_string(),
});
} else {
warn!("Vendored gem path without file name: {:?}", relative_path);
}
}
}
EntryType::RubyPackage(absolute_path, relative_path) => {
Expand Down
Loading