revset: add support for explicit substring:"..." prefix

git-branchless calls it a substring, so let's do the same.

FWIW, I copied literal:_ from Mercurial, but it's exact:_ in git-branchless.
I have no idea which one is preferred. Since this feature isn't released, we
can freely change it if exact:_ makes more sense.

https://github.com/arxanas/git-branchless/wiki/Reference:-Revsets#patterns
This commit is contained in:
Yuya Nishihara 2023-08-18 15:57:50 +09:00
parent 2062abdc9d
commit ebdc22a65e
2 changed files with 9 additions and 3 deletions

View file

@ -141,7 +141,7 @@ revsets (expressions) as arguments.
Functions that perform string matching support the following pattern syntax.
* `"substring"`: Matches strings that contain `substring`.
* `"string"`, `substring:"string"`: Matches strings that contain `string`.
* `literal:"string"`: Matches strings exactly equal to `string`.
## Aliases

View file

@ -1324,7 +1324,7 @@ fn parse_function_argument_to_string_pattern(
};
match kind.as_ref() {
"literal" => StringPattern::Literal(needle.clone()),
// TODO: maybe add explicit kind for substring match?
"substring" => StringPattern::Substring(needle.clone()),
_ => {
// TODO: error span can be narrowed to the lhs node
return Err(make_error(format!(
@ -2699,6 +2699,12 @@ mod tests {
"foo".to_owned()
)))
);
assert_eq!(
parse(r#"branches(substring:"foo")"#),
Ok(RevsetExpression::branches(StringPattern::Substring(
"foo".to_owned()
)))
);
assert_eq!(
parse(r#"branches("literal:foo")"#),
Ok(RevsetExpression::branches(StringPattern::Substring(