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