revsets: allow single internal - and + characters in symbols (#46)

This commit is contained in:
Martin von Zweigbergk 2022-04-27 09:42:18 -07:00 committed by Martin von Zweigbergk
parent 78da5596b7
commit 0789a8a4c0
4 changed files with 21 additions and 5 deletions

View file

@ -41,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`ui.editor` config. There is also a new `$JJ_EDITOR` environment variable,
which has even higher priority than the config.
* You can now use `-` and `+` in revset symbols. You used to have to quote
branch names like `my-feature` in nested quotes (outer layer for your shell)
like `jj co '"my-feature"'`. The quoting is no longer needed.
* The new revset function `connected(x)` is the same as `x:x`.
* The new revset function `roots(x)` finds commits in the set that are not

View file

@ -34,9 +34,9 @@ typically only one visible commit with a given change ID). A unique prefix of
the full change ID can also be used. It is an error to use a non-unique prefix.
Use double quotes to prevent a symbol from being interpreted as an expression.
For example, `"x-1"` is the symbol `x-1`, not the parents of symbol `x`.
For example, `"x-"` is the symbol `x-`, not the parents of symbol `x`.
Taking shell quoting into account, you may need to use something like
`jj log -r '"x-1"'`.
`jj log -r '"x-"'`.
### Priority

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
non_period_identifier = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
identifier = @{
(non_period_identifier+ ~ ".")+ ~ non_period_identifier+
| non_period_identifier+
(identifier_part+ ~ ("." | "-" | "+" ))+ ~ identifier_part+
| identifier_part+
}
symbol = {
identifier

View file

@ -1481,6 +1481,18 @@ mod tests {
assert_eq!(parse("@"), Ok(checkout_symbol.clone()));
// Parse a single symbol
assert_eq!(parse("foo"), Ok(foo_symbol.clone()));
// Internal '.', '-', and '+' are allowed
assert_eq!(
parse("foo.bar-v1+7"),
Ok(RevsetExpression::symbol("foo.bar-v1+7".to_string()))
);
// '.' is not allowed at the beginning or end
assert_matches!(parse(".foo"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo."), Err(RevsetParseError::SyntaxError(_)));
// Multiple '.', '-', '+' are not allowed
assert_matches!(parse("foo.+bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo--bar"), Err(RevsetParseError::SyntaxError(_)));
assert_matches!(parse("foo+-bar"), Err(RevsetParseError::SyntaxError(_)));
// Parse a parenthesized symbol
assert_eq!(parse("(foo)"), Ok(foo_symbol.clone()));
// Parse a quoted symbol