Skip to content

Commit 8fd9f24

Browse files
committed
change!: invert meaning of wildcard::Mode::SLASH_IS_LITERAL (#301)
This is done by renaming it to `wildcard::MODE::NO_MATCH_SLASH_LITERAL` and actually fits what it does.
1 parent 0ad2d8c commit 8fd9f24

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

git-glob/src/pattern.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bitflags! {
2828
/// Describes whether to match a path case sensitively or not.
2929
///
3030
/// Used in [Pattern::matches_repo_relative_path()].
31+
#[derive(Debug, PartialOrd, PartialEq, Copy, Clone, Hash, Ord, Eq)]
3132
pub enum Case {
3233
/// The case affects the match
3334
Sensitive,
@@ -84,7 +85,7 @@ impl Pattern {
8485
return false;
8586
}
8687

87-
let flags = wildmatch::Mode::SLASH_IS_LITERAL
88+
let flags = wildmatch::Mode::NO_MATCH_SLASH_LITERAL
8889
| match case {
8990
Case::Fold => wildmatch::Mode::IGNORE_CASE,
9091
Case::Sensitive => wildmatch::Mode::empty(),

git-glob/src/wildmatch.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ bitflags! {
33
/// The match mode employed in [`Pattern::matches()`][crate::Pattern::matches()].
44
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
55
pub struct Mode: u8 {
6-
/// Let globs not match the slash `/` literal.
7-
const SLASH_IS_LITERAL = 1 << 0;
6+
/// Let globs like `*` and `?` not match the slash `/` literal, which is useful when matching paths.
7+
const NO_MATCH_SLASH_LITERAL = 1 << 0;
88
/// Match case insensitively for ascii characters only.
99
const IGNORE_CASE = 1 << 1;
1010
}
@@ -65,22 +65,25 @@ pub(crate) mod function {
6565
}
6666
match p_ch {
6767
b'?' => {
68-
if mode.contains(Mode::SLASH_IS_LITERAL) && t_ch == SLASH {
68+
if mode.contains(Mode::NO_MATCH_SLASH_LITERAL) && t_ch == SLASH {
6969
return NoMatch;
7070
} else {
7171
continue;
7272
}
7373
}
7474
STAR => {
75-
let mut match_slash = mode.contains(Mode::SLASH_IS_LITERAL).then(|| false).unwrap_or(true);
75+
let mut match_slash = mode
76+
.contains(Mode::NO_MATCH_SLASH_LITERAL)
77+
.then(|| false)
78+
.unwrap_or(true);
7679
match p.next() {
7780
Some((next_p_idx, next_p_ch)) => {
7881
let next;
7982
if next_p_ch == STAR {
8083
let leading_slash_idx = p_idx.checked_sub(1);
8184
while p.next_if(|(_, c)| *c == STAR).is_some() {}
8285
next = p.next();
83-
if !mode.contains(Mode::SLASH_IS_LITERAL) {
86+
if !mode.contains(Mode::NO_MATCH_SLASH_LITERAL) {
8487
match_slash = true;
8588
} else if leading_slash_idx.map_or(true, |idx| pattern[idx] == SLASH)
8689
&& next.map_or(true, |(_, c)| {
@@ -318,7 +321,7 @@ pub(crate) mod function {
318321
break;
319322
}
320323
}
321-
if matched == negated || mode.contains(Mode::SLASH_IS_LITERAL) && t_ch == SLASH {
324+
if matched == negated || mode.contains(Mode::NO_MATCH_SLASH_LITERAL) && t_ch == SLASH {
322325
return NoMatch;
323326
}
324327
continue;

0 commit comments

Comments
 (0)