From ebdc22a65e14a4741693ab35c17ea5a85122945f Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 18 Aug 2023 15:57:50 +0900 Subject: [PATCH] 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 --- docs/revsets.md | 4 ++-- lib/src/revset.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/revsets.md b/docs/revsets.md index b32e97651..cbba30ed3 100644 --- a/docs/revsets.md +++ b/docs/revsets.md @@ -141,8 +141,8 @@ revsets (expressions) as arguments. Functions that perform string matching support the following pattern syntax. -* `"substring"`: Matches strings that contain `substring`. -* `literal:"string"`: Matches strings exactly equal to `string`. +* `"string"`, `substring:"string"`: Matches strings that contain `string`. +* `literal:"string"`: Matches strings exactly equal to `string`. ## Aliases diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 5097578f4..efc3e95a3 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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(