summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-11-18 23:11:17 -0500
committerGitHub <noreply@github.com>2016-11-18 23:11:17 -0500
commit1e6c2ac8e374c9f45204ecce1ddd96842ed26d15 (patch)
treece10c84961fd004e55c6e04140ae0fdcd43f34e0
parent0302d58eb8b064da91e67de00aa25f542d1ff666 (diff)
parentf63c168563743ddc402335893a9cacfcb780ccc9 (diff)
Merge pull request #238 from jacwah/refactor
`Ignore` refactorings
-rw-r--r--ignore/src/dir.rs19
-rw-r--r--ignore/src/lib.rs9
2 files changed, 13 insertions, 15 deletions
diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs
index 496664f3..95c71848 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
}
}
@@ -285,7 +285,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;
@@ -365,19 +365,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 d489712d..626588d2 100644
--- a/ignore/src/lib.rs
+++ b/ignore/src/lib.rs
@@ -357,4 +357,13 @@ impl<T> Match<T> {
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
+ }
+ }
}