matchers: simplify DifferenceMatcher slightly

The new `Visit::Nothing` variant lets us more easily restructure
`DifferenceMatcher::visit()` to make it handle the case of not
removing anything. I think this makes the code a little clearer.
This commit is contained in:
Martin von Zweigbergk 2022-05-21 22:59:43 -07:00 committed by Martin von Zweigbergk
parent 169261ca21
commit 4fda0f8b6a

View file

@ -187,17 +187,12 @@ impl Matcher for DifferenceMatcher<'_> {
fn visit(&self, dir: &RepoPath) -> Visit { fn visit(&self, dir: &RepoPath) -> Visit {
match self.unwanted.visit(dir) { match self.unwanted.visit(dir) {
Visit::AllRecursively => Visit::Nothing, Visit::AllRecursively => Visit::Nothing,
unwanted_visit => match self.wanted.visit(dir) { Visit::Nothing => self.wanted.visit(dir),
Visit::AllRecursively => { Visit::Specific { .. } => match self.wanted.visit(dir) {
if unwanted_visit == Visit::Nothing { Visit::AllRecursively => Visit::Specific {
Visit::AllRecursively
} else {
Visit::Specific {
dirs: VisitDirs::All, dirs: VisitDirs::All,
files: VisitFiles::All, files: VisitFiles::All,
} },
}
}
wanted_visit => wanted_visit, wanted_visit => wanted_visit,
}, },
} }