Skip to content

Commit 5331452

Browse files
committed
specify processing type in args
1 parent 0ce687b commit 5331452

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

src/common_test.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ pub mod tests {
1010

1111
use tempfile::tempdir;
1212

13-
use crate::{ownership::Ownership, project_builder::ProjectBuilder};
13+
use crate::{
14+
ownership::Ownership,
15+
project_builder::{EntryProcessorType, ProjectBuilder, WalkType},
16+
};
1417

1518
macro_rules! ownership {
1619
($($test_files:expr),+) => {{
@@ -110,14 +113,30 @@ pub mod tests {
110113
let config = serde_yaml::from_reader(config_file)?;
111114

112115
let codeowners_file_path = &test_config.temp_dir_path.join(".github/CODEOWNERS");
113-
let mut builder = ProjectBuilder::new(&config, test_config.temp_dir_path.clone(), codeowners_file_path.clone());
116+
let walk_type = WalkType::JWalk;
117+
let entry_processor_type = EntryProcessorType::Parallel;
118+
let mut builder = ProjectBuilder::new(
119+
&config,
120+
test_config.temp_dir_path.clone(),
121+
codeowners_file_path.clone(),
122+
walk_type,
123+
entry_processor_type,
124+
);
114125
let project = builder.build()?;
115126
let ownership = Ownership::build(project);
116127
if test_config.generate_codeowners {
117128
std::fs::write(codeowners_file_path, ownership.generate_file())?;
118129
}
119130
// rebuild project to ensure new codeowners file is read
120-
let mut builder = ProjectBuilder::new(&config, test_config.temp_dir_path.clone(), codeowners_file_path.clone());
131+
let walk_type = WalkType::JWalk;
132+
let entry_processor_type = EntryProcessorType::Parallel;
133+
let mut builder = ProjectBuilder::new(
134+
&config,
135+
test_config.temp_dir_path.clone(),
136+
codeowners_file_path.clone(),
137+
walk_type,
138+
entry_processor_type,
139+
);
121140
let project = builder.build()?;
122141
Ok(Ownership::build(project))
123142
}

src/main.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ownership::{FileOwner, Ownership};
2+
use project_builder::{EntryProcessorType, WalkType};
23

34
use crate::project_builder::ProjectBuilder;
45
use clap::{Parser, Subcommand};
@@ -58,6 +59,14 @@ struct Args {
5859
/// Path for the root of the project
5960
#[arg(long, default_value = ".")]
6061
project_root: PathBuf,
62+
63+
/// Walk type
64+
#[arg(long, default_value = "jwalk")]
65+
walk_type: String,
66+
67+
/// Entry processor type
68+
#[arg(long, default_value = "parallel")]
69+
entry_processor_type: String,
6170
}
6271

6372
impl Args {
@@ -114,8 +123,18 @@ fn cli() -> Result<(), Error> {
114123
.attach_printable(format!("Can't open config file: {}", config_path.to_string_lossy()))?;
115124

116125
let config = serde_yaml::from_reader(config_file).change_context(Error::Io)?;
117-
118-
let mut builder = ProjectBuilder::new(&config, project_root, codeowners_file_path.clone());
126+
let walk_type = match args.walk_type.as_str() {
127+
"jwalk" => WalkType::JWalk,
128+
_ => WalkType::Ignore,
129+
};
130+
let entry_processor_type = match args.entry_processor_type.as_str() {
131+
"parallel" => EntryProcessorType::Parallel,
132+
_ => EntryProcessorType::Serial,
133+
};
134+
135+
dbg!(&walk_type, &entry_processor_type);
136+
137+
let mut builder = ProjectBuilder::new(&config, project_root, codeowners_file_path.clone(), walk_type, entry_processor_type);
119138
let project = builder.build().change_context(Error::Io)?;
120139
let ownership = Ownership::build(project);
121140

src/project_builder.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ enum EntryType {
2828
PossiblyOwnedFile(AbsolutePath, RelativePath),
2929
}
3030

31+
#[derive(Debug)]
32+
pub enum WalkType {
33+
JWalk,
34+
Ignore,
35+
}
36+
37+
#[derive(Debug)]
38+
pub enum EntryProcessorType {
39+
Serial,
40+
Parallel,
41+
}
42+
3143
#[derive(Debug)]
3244
pub struct ProjectBuilder<'a> {
3345
pub config: &'a Config,
@@ -37,10 +49,18 @@ pub struct ProjectBuilder<'a> {
3749
pub teams: Vec<Team>,
3850
pub codeowners_file_path: PathBuf,
3951
pub directory_codeowner_files: Vec<DirectoryCodeownersFile>,
52+
pub walk_type: WalkType,
53+
pub entry_processor_type: EntryProcessorType,
4054
}
4155

4256
impl<'a> ProjectBuilder<'a> {
43-
pub fn new(config: &'a Config, base_path: PathBuf, codeowners_file_path: PathBuf) -> Self {
57+
pub fn new(
58+
config: &'a Config,
59+
base_path: PathBuf,
60+
codeowners_file_path: PathBuf,
61+
walk_type: WalkType,
62+
entry_processor_type: EntryProcessorType,
63+
) -> Self {
4464
Self {
4565
config,
4666
base_path,
@@ -49,13 +69,17 @@ impl<'a> ProjectBuilder<'a> {
4969
teams: Vec::new(),
5070
codeowners_file_path,
5171
directory_codeowner_files: Vec::new(),
72+
walk_type,
73+
entry_processor_type,
5274
}
5375
}
5476

5577
#[instrument(level = "debug", skip_all)]
5678
pub fn build(&mut self) -> Result<Project, Error> {
57-
self.build_ignore()
58-
//self.build_jwalk()
79+
match self.walk_type {
80+
WalkType::Ignore => self.build_ignore(),
81+
WalkType::JWalk => self.build_jwalk(),
82+
}
5983
}
6084

6185
#[instrument(level = "debug", skip_all)]
@@ -71,7 +95,6 @@ impl<'a> ProjectBuilder<'a> {
7195
entry_types.push(self.build_entry_type_ignore(entry)?);
7296
}
7397
self.build_project_from_entry_types(entry_types)
74-
//self.build_project_from_entry_types_rayon(entry_types)
7598
}
7699

77100
fn build_entry_type_ignore(&mut self, entry: ignore::DirEntry) -> Result<EntryType, Error> {
@@ -131,6 +154,13 @@ impl<'a> ProjectBuilder<'a> {
131154
}
132155

133156
fn build_project_from_entry_types(&mut self, entry_types: Vec<EntryType>) -> Result<Project, Error> {
157+
match self.entry_processor_type {
158+
EntryProcessorType::Serial => self.build_project_from_entry_types_serial(entry_types),
159+
EntryProcessorType::Parallel => self.build_project_from_entry_types_rayon(entry_types),
160+
}
161+
}
162+
163+
fn build_project_from_entry_types_serial(&mut self, entry_types: Vec<EntryType>) -> Result<Project, Error> {
134164
let mut owned_files_vec = Vec::new();
135165
for entry_type in entry_types {
136166
match entry_type {

0 commit comments

Comments
 (0)