Skip to content

Commit

Permalink
cleanup path classificaiton after fixes in gix-pathspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 19, 2024
1 parent 5b47567 commit 44a2e00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
18 changes: 4 additions & 14 deletions gix-dir/src/walk/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ pub fn root(
let mut path_buf = worktree_root.to_owned();
// These initial values kick in if worktree_relative_root.is_empty();
let file_kind = path_buf.symlink_metadata().map(|m| m.file_type().into()).ok();
let pathspec_orig = std::mem::replace(
ctx.pathspec,
gix_pathspec::Search::from_specs(None, None, "".as_ref()).expect("empty is valid"),
);
let res = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx);
*ctx.pathspec = pathspec_orig;
let mut out = res?;
let mut out = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx)?;
let worktree_root_is_repository = out
.disk_kind
.map_or(false, |kind| matches!(kind, entry::Kind::Repository));
Expand Down Expand Up @@ -59,9 +53,6 @@ pub fn root(
}
last_length = Some(buf.len());
}
if out.pathspec_match.is_none() {
out.pathspec_match = Some(PathspecMatch::Always);
}
Ok((out, worktree_root_is_repository))
}
/// The product of [`path()`] calls.
Expand Down Expand Up @@ -181,10 +172,9 @@ pub fn path(
out.property = entry::Property::DotGit.into();
return Ok(out);
}
let pathspec_could_match = rela_path.is_empty()
|| ctx
.pathspec
.can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
let pathspec_could_match = ctx
.pathspec
.can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
if !pathspec_could_match {
return Ok(out.with_status(entry::Status::Pruned));
}
Expand Down
22 changes: 13 additions & 9 deletions gix-dir/tests/walk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ fn worktree_root_can_be_symlink() -> crate::Result {
#[test]
fn root_may_not_go_through_dot_git() -> crate::Result {
let root = fixture("with-nested-dot-git");
for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
let troot = root.join("dir").join(".git").join(dir);
let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
walk(&root, ctx, options_emit_all(), keep)
Expand All @@ -2747,9 +2747,11 @@ fn root_may_not_go_through_dot_git() -> crate::Result {
);
assert_eq!(
entries,
[entry("dir/.git", Pruned, Directory)
.with_property(DotGit)
.with_match(expected_pathspec)],
[{
let mut e = entry("dir/.git", Pruned, Directory).with_property(DotGit);
e.0.pathspec_match = expected_pathspec;
e
}],
"{dir}: no traversal happened as root passes though .git"
);
}
Expand Down Expand Up @@ -3165,7 +3167,7 @@ fn root_can_be_pruned_early_with_pathspec() -> crate::Result {

assert_eq!(
entries,
[entry("dir", Pruned, Directory)],
[entry_nomatch("dir", Pruned, Directory)],
"the pathspec didn't match the root, early abort"
);
Ok(())
Expand Down Expand Up @@ -3927,7 +3929,7 @@ fn untracked_and_ignored_collapse_mix() {
#[test]
fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -> crate::Result {
let root = fixture("with-nested-capitalized-dot-git");
for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
let troot = root.join("dir").join(".GIT").join(dir);
let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
walk(
Expand All @@ -3950,9 +3952,11 @@ fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -
);
assert_eq!(
entries,
[entry("dir/.GIT", Pruned, Directory)
.with_property(DotGit)
.with_match(expected_pathspec)],
[{
let mut e = entry("dir/.GIT", Pruned, Directory).with_property(DotGit);
e.0.pathspec_match = expected_pathspec;
e
}],
"{dir}: no traversal happened as root passes though .git, it compares in a case-insensitive fashion"
);
}
Expand Down

0 comments on commit 44a2e00

Please sign in to comment.