History

cleanup path classificaiton after fixes in `gix-pathspec`

Sebastian Thiel committed 2 years ago

Commit 44a2e001 parent 5b475672 files · +17 −23Browse files

Unified · Split

2 files
  1. gix-dir/src/walk/classify.rs +4 −14
  2. gix-dir/tests/walk/mod.rs +13 −9
gix-dir/src/walk/classify.rs+4−14
@@ -21,13 +21,7 @@ pub fn root( · 20 unmodified lines
2121 let mut path_buf = worktree_root.to_owned();
2222 // These initial values kick in if worktree_relative_root.is_empty();
2323 let file_kind = path_buf.symlink_metadata().map(|m| m.file_type().into()).ok();
24− let pathspec_orig = std::mem::replace(
25− ctx.pathspec,
26− gix_pathspec::Search::from_specs(None, None, "".as_ref()).expect("empty is valid"),
27− );
28− let res = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx);
29− *ctx.pathspec = pathspec_orig;
30− let mut out = res?;
24+ let mut out = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx)?;
3125 let worktree_root_is_repository = out
3226 .disk_kind
3327 .map_or(false, |kind| matches!(kind, entry::Kind::Repository));
@@ -59,9 +53,6 @@ pub fn root( · 25 unmodified lines
5953 }
6054 last_length = Some(buf.len());
6155 }
62− if out.pathspec_match.is_none() {
63− out.pathspec_match = Some(PathspecMatch::Always);
64− }
6556 Ok((out, worktree_root_is_repository))
6657 }
6758 /// The product of [`path()`] calls.
@@ -181,10 +172,9 @@ pub fn path( · 113 unmodified lines
181172 out.property = entry::Property::DotGit.into();
182173 return Ok(out);
183174 }
184− let pathspec_could_match = rela_path.is_empty()
185− || ctx
186− .pathspec
187− .can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
175+ let pathspec_could_match = ctx
176+ .pathspec
177+ .can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
188178 if !pathspec_could_match {
189179 return Ok(out.with_status(entry::Status::Pruned));
190180 }
gix-dir/tests/walk/mod.rs+13−9
@@ -2732,7 +2732,7 @@ fn worktree_root_can_be_symlink() -> crate::Result { · 2731 unmodified lines
27322732 #[test]
27332733 fn root_may_not_go_through_dot_git() -> crate::Result {
27342734 let root = fixture("with-nested-dot-git");
2735− for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
2735+ for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
27362736 let troot = root.join("dir").join(".git").join(dir);
27372737 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
27382738 walk(&root, ctx, options_emit_all(), keep)
@@ -2747,9 +2747,11 @@ fn root_may_not_go_through_dot_git() -> crate::Result { · 8 unmodified lines
27472747 );
27482748 assert_eq!(
27492749 entries,
2750− [entry("dir/.git", Pruned, Directory)
2751− .with_property(DotGit)
2752− .with_match(expected_pathspec)],
2750+ [{
2751+ let mut e = entry("dir/.git", Pruned, Directory).with_property(DotGit);
2752+ e.0.pathspec_match = expected_pathspec;
2753+ e
2754+ }],
27532755 "{dir}: no traversal happened as root passes though .git"
27542756 );
27552757 }
@@ -3165,7 +3167,7 @@ fn root_can_be_pruned_early_with_pathspec() -> crate::Result { · 409 unmodified lines
31653167
31663168 assert_eq!(
31673169 entries,
3168− [entry("dir", Pruned, Directory)],
3170+ [entry_nomatch("dir", Pruned, Directory)],
31693171 "the pathspec didn't match the root, early abort"
31703172 );
31713173 Ok(())
@@ -3927,7 +3929,7 @@ fn untracked_and_ignored_collapse_mix() { · 755 unmodified lines
39273929 #[test]
39283930 fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -> crate::Result {
39293931 let root = fixture("with-nested-capitalized-dot-git");
3930− for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
3932+ for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
39313933 let troot = root.join("dir").join(".GIT").join(dir);
39323934 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
39333935 walk(
@@ -3950,9 +3952,11 @@ fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() - · 16 unmodified lines
39503952 );
39513953 assert_eq!(
39523954 entries,
3953− [entry("dir/.GIT", Pruned, Directory)
3954− .with_property(DotGit)
3955− .with_match(expected_pathspec)],
3955+ [{
3956+ let mut e = entry("dir/.GIT", Pruned, Directory).with_property(DotGit);
3957+ e.0.pathspec_match = expected_pathspec;
3958+ e
3959+ }],
39563960 "{dir}: no traversal happened as root passes though .git, it compares in a case-insensitive fashion"
39573961 );
39583962 }