| @@ -1,29 +1,25 @@ |
| 1 | | −use bstr::{BString, ByteSlice}; |
| 1 | +use bstr::{BStr, BString, ByteSlice}; |
| 2 | 2 | use git_attributes::State; |
| 3 | 3 | use git_pathspec::{MagicSignature, Pattern, SearchMode}; |
| 4 | 4 | use once_cell::sync::Lazy; |
| 5 | 5 | use std::collections::HashMap; |
| 6 | 6 | |
| 7 | | −static BASELINE: Lazy<HashMap<BString, BString>> = Lazy::new(|| { |
| 8 | | − let mut baseline_map = HashMap::new(); |
| 7 | +pub use git_testtools::Result; |
| 9 | 8 | |
| 9 | +static BASELINE: Lazy<HashMap<BString, usize>> = Lazy::new(|| { |
| 10 | 10 | let base = git_testtools::scripted_fixture_repo_read_only("generate_pathspec_baseline.sh").unwrap(); |
| 11 | 11 | |
| 12 | | − let dirwalk = walkdir::WalkDir::new(base) |
| 13 | | − .max_depth(1) |
| 14 | | − .follow_links(false) |
| 15 | | − .into_iter() |
| 16 | | − .filter_map(|e| e.ok().and_then(|e| (e.file_name() == "baseline.git").then(|| e))); |
| 17 | | − |
| 18 | | − for baseline_entry in dirwalk { |
| 19 | | − let baseline = std::fs::read(baseline_entry.path()).unwrap(); |
| 12 | + (|| -> Result<_> { |
| 13 | + let mut map = HashMap::new(); |
| 14 | + let baseline = std::fs::read(base.join("baseline.git"))?; |
| 20 | 15 | let mut lines = baseline.lines(); |
| 21 | 16 | while let Some(spec) = lines.next() { |
| 22 | | − let exit_code = lines.next().unwrap().into(); |
| 23 | | − baseline_map.insert(spec.into(), exit_code); |
| 17 | + let exit_code = lines.next().expect("two lines per baseline").to_str()?.parse()?; |
| 18 | + map.insert(spec.into(), exit_code); |
| 24 | 19 | } |
| 25 | | − } |
| 26 | | − baseline_map |
| 20 | + Ok(map) |
| 21 | + })() |
| 22 | + .unwrap() |
| 27 | 23 | }); |
| 28 | 24 | |
| 29 | 25 | mod succeed { |
| @@ -393,8 +389,9 @@ fn pat(path: &str, signature: MagicSignature, search_mode: SearchMode, attribute · 363 unmodified lines |
| 393 | 389 | } |
| 394 | 390 | |
| 395 | 391 | fn check_against_baseline(pathspec: &str) -> bool { |
| 392 | + let key: &BStr = pathspec.into(); |
| 396 | 393 | let base = BASELINE |
| 397 | | − .get(&BString::from(pathspec)) |
| 394 | + .get(key) |
| 398 | 395 | .expect(&format!("missing baseline for pathspec: {:?}", pathspec)); |
| 399 | | − *base == BString::from("0") |
| 396 | + *base == 0 |
| 400 | 397 | } |