Skip to content

Commit ba2301f

Browse files
committed
refactor
1 parent d6835f2 commit ba2301f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

gix-refspec/src/match_group/util.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ impl<'a> Needle<'a> {
105105
Match::GlobRange(*asterisk_pos..end)
106106
}
107107
Needle::Pattern(pattern) => {
108-
if gix_glob::wildmatch(pattern, item.full_ref_name, gix_glob::wildmatch::Mode::empty()) {
108+
if gix_glob::wildmatch(
109+
pattern,
110+
item.full_ref_name,
111+
gix_glob::wildmatch::Mode::NO_MATCH_SLASH_LITERAL,
112+
) {
109113
Match::Normal
110114
} else {
111115
Match::None
@@ -187,9 +191,7 @@ impl<'a> From<RefSpecRef<'a>> for Matcher<'a> {
187191
};
188192
if m.rhs.is_none() {
189193
if let Some(src) = v.src {
190-
// Only use Pattern for complex globs (multiple asterisks or other glob features)
191-
// Simple single-asterisk globs can use the more efficient Needle::Glob
192-
if is_complex_pattern(src) {
194+
if must_use_pattern_matching(src) {
193195
m.lhs = Some(Needle::Pattern(src));
194196
}
195197
}
@@ -199,11 +201,12 @@ impl<'a> From<RefSpecRef<'a>> for Matcher<'a> {
199201
}
200202

201203
/// Check if a pattern is complex enough to require wildmatch instead of simple glob matching
202-
fn is_complex_pattern(pattern: &BStr) -> bool {
204+
fn must_use_pattern_matching(pattern: &BStr) -> bool {
203205
let asterisk_count = pattern.iter().filter(|&&b| b == b'*').count();
204206
if asterisk_count > 1 {
205207
return true;
206208
}
207-
// Check for other glob features: ?, [, ], \
208-
pattern.iter().any(|&b| b == b'?' || b == b'[' || b == b']' || b == b'\\')
209+
pattern
210+
.iter()
211+
.any(|&b| b == b'?' || b == b'[' || b == b']' || b == b'\\')
209212
}

gix-refspec/tests/refspec/match_group.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ mod complex_globs {
214214
#[test]
215215
fn one_sided_simple_glob_patterns_match() {
216216
// Test that simple glob patterns (one asterisk) work correctly with matching
217-
let refs = vec![
217+
let refs = [
218218
new_ref("refs/heads/feature/foo", "1111111111111111111111111111111111111111"),
219219
new_ref("refs/heads/bugfix/bar", "2222222222222222222222222222222222222222"),
220220
new_ref("refs/tags/v1.0", "3333333333333333333333333333333333333333"),
@@ -277,7 +277,7 @@ mod complex_globs {
277277
#[test]
278278
fn one_sided_glob_with_suffix_matches() {
279279
// Test that glob patterns with suffix work correctly
280-
let refs = vec![
280+
let refs = [
281281
new_ref("refs/heads/feature", "1111111111111111111111111111111111111111"),
282282
new_ref("refs/heads/feat", "2222222222222222222222222222222222222222"),
283283
new_ref("refs/heads/main", "3333333333333333333333333333333333333333"),

gix/tests/gix/config/tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,17 +1125,17 @@ mod remote {
11251125

11261126
assert_eq!(
11271127
Remote::FETCH
1128-
.try_into_refspec(bcow("*/*/*"), gix_refspec::parse::Operation::Fetch)
1128+
.try_into_refspec(bcow("*/*/*:refs/heads/*"), gix_refspec::parse::Operation::Fetch)
11291129
.unwrap_err()
11301130
.to_string(),
1131-
"The refspec at \"remote.<name>.fetch=*/*/*\" could not be parsed"
1131+
"The refspec at \"remote.<name>.fetch=*/*/*:refs/heads/*\" could not be parsed"
11321132
);
11331133
assert_eq!(
11341134
Remote::PUSH
1135-
.try_into_refspec(bcow("*/*/*"), gix_refspec::parse::Operation::Push)
1135+
.try_into_refspec(bcow("*/*/*:refs/heads/*"), gix_refspec::parse::Operation::Push)
11361136
.unwrap_err()
11371137
.to_string(),
1138-
"The refspec at \"remote.<name>.push=*/*/*\" could not be parsed"
1138+
"The refspec at \"remote.<name>.push=*/*/*:refs/heads/*\" could not be parsed"
11391139
);
11401140
}
11411141
}

0 commit comments

Comments
 (0)