-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
str_util: support case‐insensitive string patterns
Partially resolve a 1.5‐year‐old TODO comment. Add opt‐in syntax for case‐insensitive matching, suffixing the pattern kind with `-i`. Not every context supports case‐insensitive patterns (e.g. Git branch fetch settings). It may make sense to make this the default in at least some contexts (e.g. the commit signature and description revsets), but it would require some thought to avoid more confusing context‐sensitivity. Make `mine()` match case‐insensitively unconditionally, since email addresses are conventionally case‐insensitive and it doesn’t take a pattern anyway. This currently only handles ASCII case folding, due to the complexities of case‐insensitive Unicode comparison and the `glob` crate’s lack of support for it. This is unlikely to matter for email addresses, which very rarely contain non‐ASCII characters, but is unfortunate for names and descriptions. However, the current matching behaviour is already seriously deficient for non‐ASCII text due to the lack of any normalization, so this hopefully shouldn’t be a blocker to adding the interface. An expository comment has been left in the code for anyone who wants to try and address this (perhaps a future version of myself).
- Loading branch information
Showing
7 changed files
with
138 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -687,8 +687,11 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = Lazy: | |
}); | ||
map.insert("mine", |function, context| { | ||
function.expect_no_arguments()?; | ||
// Email address domains are inherently case‐insensitive, and the local‐parts | ||
// are generally (although not universally) treated as case‐insensitive too, so | ||
// we use a case‐insensitive match here. | ||
Ok(RevsetExpression::filter(RevsetFilterPredicate::Author( | ||
StringPattern::Exact(context.user_email.to_owned()), | ||
StringPattern::exact_i(&context.user_email), | ||
))) | ||
}); | ||
map.insert("committer", |function, _context| { | ||
|
@@ -2518,7 +2521,7 @@ mod tests { | |
assert!(parse("mine(foo)").is_err()); | ||
insta::assert_debug_snapshot!( | ||
parse("mine()").unwrap(), | ||
@r###"Filter(Author(Exact("[email protected]")))"###); | ||
@r###"Filter(Author(ExactI("[email protected]")))"###); | ||
insta::assert_debug_snapshot!( | ||
parse_with_workspace("empty()", &WorkspaceId::default()).unwrap(), | ||
@"NotIn(Filter(File(All)))"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters