diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c1fb277..0cf0a8ec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/revsets.md b/docs/revsets.md index a17f84972..23edfc001 100644 --- a/docs/revsets.md +++ b/docs/revsets.md @@ -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 diff --git a/lib/src/revset.pest b/lib/src/revset.pest index 85b8f79b2..17c208fe6 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -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 diff --git a/lib/src/revset.rs b/lib/src/revset.rs index bd2922ea4..783554e17 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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