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
21 let mut path_buf = worktree_root.to_owned();21 let mut path_buf = worktree_root.to_owned();
22 // These initial values kick in if worktree_relative_root.is_empty();22 // These initial values kick in if worktree_relative_root.is_empty();
23 let file_kind = path_buf.symlink_metadata().map(|m| m.file_type().into()).ok();23 let file_kind = path_buf.symlink_metadata().map(|m| m.file_type().into()).ok();
24 let pathspec_orig = std::mem::replace(24 let mut out = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx)?;
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?;
31 let worktree_root_is_repository = out25 let worktree_root_is_repository = out
32 .disk_kind26 .disk_kind
33 .map_or(false, |kind| matches!(kind, entry::Kind::Repository));27 .map_or(false, |kind| matches!(kind, entry::Kind::Repository));
@@ -59,9 +53,6 @@ pub fn root( · 25 unmodified lines
59 }53 }
60 last_length = Some(buf.len());54 last_length = Some(buf.len());
61 }55 }
62 if out.pathspec_match.is_none() {
63 out.pathspec_match = Some(PathspecMatch::Always);
64 }
65 Ok((out, worktree_root_is_repository))56 Ok((out, worktree_root_is_repository))
66}57}
67/// The product of [`path()`] calls.58/// The product of [`path()`] calls.
@@ -181,10 +172,9 @@ pub fn path( · 113 unmodified lines
181 out.property = entry::Property::DotGit.into();172 out.property = entry::Property::DotGit.into();
182 return Ok(out);173 return Ok(out);
183 }174 }
184 let pathspec_could_match = rela_path.is_empty()175 let pathspec_could_match = ctx
185 || ctx176 .pathspec
186 .pathspec177 .can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
187 .can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
188 if !pathspec_could_match {178 if !pathspec_could_match {
189 return Ok(out.with_status(entry::Status::Pruned));179 return Ok(out.with_status(entry::Status::Pruned));
190 }180 }
gix-dir/tests/walk/mod.rs+13−9
@@ -2732,7 +2732,7 @@ fn worktree_root_can_be_symlink() -> crate::Result { · 2731 unmodified lines
2732#[test]2732#[test]
2733fn root_may_not_go_through_dot_git() -> crate::Result {2733fn root_may_not_go_through_dot_git() -> crate::Result {
2734 let root = fixture("with-nested-dot-git");2734 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)] {
2736 let troot = root.join("dir").join(".git").join(dir);2736 let troot = root.join("dir").join(".git").join(dir);
2737 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {2737 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
2738 walk(&root, ctx, options_emit_all(), keep)2738 walk(&root, ctx, options_emit_all(), keep)
@@ -2747,9 +2747,11 @@ fn root_may_not_go_through_dot_git() -> crate::Result { · 8 unmodified lines
2747 );2747 );
2748 assert_eq!(2748 assert_eq!(
2749 entries,2749 entries,
2750 [entry("dir/.git", Pruned, Directory)2750 [{
2751 .with_property(DotGit)2751 let mut e = entry("dir/.git", Pruned, Directory).with_property(DotGit);
2752 .with_match(expected_pathspec)],2752 e.0.pathspec_match = expected_pathspec;
2753 e
2754 }],
2753 "{dir}: no traversal happened as root passes though .git"2755 "{dir}: no traversal happened as root passes though .git"
2754 );2756 );
2755 }2757 }
@@ -3165,7 +3167,7 @@ fn root_can_be_pruned_early_with_pathspec() -> crate::Result { · 409 unmodified lines
3165 3167
3166 assert_eq!(3168 assert_eq!(
3167 entries,3169 entries,
3168 [entry("dir", Pruned, Directory)],3170 [entry_nomatch("dir", Pruned, Directory)],
3169 "the pathspec didn't match the root, early abort"3171 "the pathspec didn't match the root, early abort"
3170 );3172 );
3171 Ok(())3173 Ok(())
@@ -3927,7 +3929,7 @@ fn untracked_and_ignored_collapse_mix() { · 755 unmodified lines
3927#[test]3929#[test]
3928fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -> crate::Result {3930fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -> crate::Result {
3929 let root = fixture("with-nested-capitalized-dot-git");3931 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)] {
3931 let troot = root.join("dir").join(".GIT").join(dir);3933 let troot = root.join("dir").join(".GIT").join(dir);
3932 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {3934 let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
3933 walk(3935 walk(
@@ -3950,9 +3952,11 @@ fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() - · 16 unmodified lines
3950 );3952 );
3951 assert_eq!(3953 assert_eq!(
3952 entries,3954 entries,
3953 [entry("dir/.GIT", Pruned, Directory)3955 [{
3954 .with_property(DotGit)3956 let mut e = entry("dir/.GIT", Pruned, Directory).with_property(DotGit);
3955 .with_match(expected_pathspec)],3957 e.0.pathspec_match = expected_pathspec;
3958 e
3959 }],
3956 "{dir}: no traversal happened as root passes though .git, it compares in a case-insensitive fashion"3960 "{dir}: no traversal happened as root passes though .git, it compares in a case-insensitive fashion"
3957 );3961 );
3958 }3962 }