D6489: rust-regex: fix shortcut for exact matches
Alphare (Raphaël Gomès)
phabricator at mercurial-scm.org
Mon Jun 10 10:57:12 EDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG48f1f864d928: rust-regex: fix shortcut for exact matches (authored by Alphare, committed by ).
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D6489?vs=15361&id=15418
REVISION DETAIL
https://phab.mercurial-scm.org/D6489
AFFECTED FILES
rust/hg-core/src/filepatterns.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs
--- a/rust/hg-core/src/filepatterns.rs
+++ b/rust/hg-core/src/filepatterns.rs
@@ -200,9 +200,11 @@
) -> Result<Vec<u8>, PatternError> {
let enum_kind = parse_pattern_syntax(kind)?;
if enum_kind == PatternSyntax::RootGlob
- && pat.iter().all(|b| GLOB_SPECIAL_CHARACTERS.contains(b))
+ && !pat.iter().any(|b| GLOB_SPECIAL_CHARACTERS.contains(b))
{
- Ok(pat.to_vec())
+ let mut escaped = escape_pattern(pat);
+ escaped.extend(b"(?:/|$)");
+ Ok(escaped)
} else {
Ok(_build_single_regex(enum_kind, pat, globsuffix))
}
@@ -351,4 +353,20 @@
vec![(b"relglob:**.o".to_vec(), 1, b"**.o".to_vec())]
);
}
+
+ #[test]
+ fn test_build_single_regex_shortcut() {
+ assert_eq!(
+ br"(?:/|$)".to_vec(),
+ build_single_regex(b"rootglob", b"", b"").unwrap()
+ );
+ assert_eq!(
+ br"whatever(?:/|$)".to_vec(),
+ build_single_regex(b"rootglob", b"whatever", b"").unwrap()
+ );
+ assert_eq!(
+ br"[^/]*\.o".to_vec(),
+ build_single_regex(b"rootglob", b"*.o", b"").unwrap()
+ );
+ }
}
To: Alphare, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel
More information about the Mercurial-devel
mailing list