From a05671c8d72659c1189eefea15f798c20407282a Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 6 Nov 2016 01:01:14 +0100 Subject: [PATCH 1/2] Use new Match::or to simplify return --- ignore/src/dir.rs | 15 ++------------- ignore/src/lib.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs index 6ac00627..ebc2c699 100644 --- a/ignore/src/dir.rs +++ b/ignore/src/dir.rs @@ -360,19 +360,8 @@ impl Ignore { } let m_global = self.0.git_global_matcher.matched(&path, is_dir) .map(IgnoreMatch::gitignore); - if !m_ignore.is_none() { - m_ignore - } else if !m_gi.is_none() { - m_gi - } else if !m_gi_exclude.is_none() { - m_gi_exclude - } else if !m_global.is_none() { - m_global - } else if !m_explicit.is_none() { - m_explicit - } else { - Match::None - } + + m_ignore.or(m_gi).or(m_gi_exclude).or(m_global).or(m_explicit) } /// Returns an iterator over parent ignore matchers, including this one. diff --git a/ignore/src/lib.rs b/ignore/src/lib.rs index a3aa0c8f..9d979275 100644 --- a/ignore/src/lib.rs +++ b/ignore/src/lib.rs @@ -297,4 +297,13 @@ impl Match { Match::Whitelist(t) => Match::Whitelist(f(t)), } } + + /// Return the match if it is not none. Otherwise, return other. + pub fn or(self, other: Self) -> Self { + if self.is_none() { + other + } else { + self + } + } } From f63c168563743ddc402335893a9cacfcb780ccc9 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 6 Nov 2016 01:17:41 +0100 Subject: [PATCH 2/2] Rename IgnoreOptions::has_ignores The name has_ignores is not descriptive in my opinion. I think has_any_ignore_options more clearly states this method's purpose. I also considered simply IgnoreOptions::any though I went with the more verbose option. --- ignore/src/dir.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs index ebc2c699..370fd92d 100644 --- a/ignore/src/dir.rs +++ b/ignore/src/dir.rs @@ -75,7 +75,7 @@ struct IgnoreOptions { impl IgnoreOptions { /// Returns true if at least one type of ignore rules should be matched. - fn should_ignores(&self) -> bool { + fn has_any_ignore_options(&self) -> bool { self.ignore || self.git_global || self.git_ignore || self.git_exclude } } @@ -280,7 +280,7 @@ impl Ignore { } } let mut whitelisted = Match::None; - if self.0.opts.should_ignores() { + if self.0.opts.has_any_ignore_options() { let mat = self.matched_ignore(path, is_dir); if mat.is_ignore() { return mat;