Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add edges from masters #25

Merged
merged 1 commit into from
Mar 15, 2024
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
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub struct PluginData {

pub description: Option<String>,
pub version: Option<semver::Version>,
pub masters: Option<Vec<(String, u64)>>,
}

impl PluginData {
Expand All @@ -222,6 +223,7 @@ impl PluginData {
size,
description: None,
version: None,
masters: None,
}
}
}
Expand Down Expand Up @@ -309,13 +311,15 @@ where
size: f.metadata().unwrap().len(),
description: None,
version: None,
masters: None,
};

// skip if extension is omwscripts
if !file_name.to_ascii_lowercase().ends_with("omwscripts") {
match parse_header(f) {
Ok(header) => {
data.description = Some(header.description);
data.masters = header.masters;

// parse semver
let version = header.version.to_string();
Expand Down Expand Up @@ -395,10 +399,12 @@ where
size: f.metadata().unwrap().len(),
description: None,
version: None,
masters: None,
};
match parse_header(f) {
Ok(header) => {
data.description = Some(header.description);
data.masters = header.masters;

// parse semver
let version = header.version.to_string();
Expand Down Expand Up @@ -451,6 +457,7 @@ where
size: e.metadata().unwrap().len(),
description: None,
version: None,
masters: None,
};
return Some(data);
}
Expand Down Expand Up @@ -859,6 +866,7 @@ where
size: 0, // TODO fix dummy size
description: None,
version: None,
masters: None,
};
result.push(data);
}
Expand Down
27 changes: 24 additions & 3 deletions src/sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ impl Sorter {
let mut index_dict: HashMap<String, usize> = HashMap::new();
let mut index_dict_rev: HashMap<usize, String> = HashMap::default();
let mut mod_map: HashMap<usize, String> = HashMap::default();
for (i, m) in mods_cased.iter().enumerate() {
let lower_case = m.name.to_lowercase();
for (i, cased_name) in mods_cased.iter().enumerate() {
let lower_case = cased_name.name.to_lowercase();

index_dict.insert(lower_case.clone(), i);
index_dict_rev.insert(i, lower_case.clone());

mod_map.insert(i, m.name.to_owned());
mod_map.insert(i, cased_name.name.to_owned());
mods.push(lower_case.to_owned());
}

Expand Down Expand Up @@ -101,6 +101,27 @@ impl Sorter {
}
}

// add edges from masters
for mod_data in mods_cased.iter() {
// add an edge from the mod to all its masters
let idx = index_dict[&mod_data.name.to_lowercase()];
if let Some(masters) = &mod_data.masters {
for (master, _hash) in masters {
let master = master.to_lowercase();
if let Some(results) = wild_contains(&mods, &master) {
for result in results {
let idx_master = index_dict[&result];
let edge = (idx_master, idx);
if !edges.contains(&edge) {
edges.push(edge);
g.add_edge(edge.0, edge.1);
}
}
}
}
}
}

// cycle check
if self.sort_type == ESortType::Unstable {
let sort;
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_expression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ mod unit_tests {
size: 0_u64,
description: Some("description".to_string()),
version: None,
masters: None,
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -184,6 +185,7 @@ mod unit_tests {
name: e.to_string(),
size: 0_u64,
description: None,
masters: None,
version: Some(lenient_semver::parse("1.0").unwrap()),
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -254,6 +256,7 @@ mod unit_tests {
size: 0_u64,
description: None,
version: None,
masters: None,
})
.collect::<Vec<_>>();

Expand Down
Loading