Skip to content

Commit

Permalink
Fix: Disallow revset function names starting with a number.
Browse files Browse the repository at this point in the history
  • Loading branch information
matts1 committed Oct 4, 2024
1 parent 3d26af8 commit 498bb7f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 33 deletions.
70 changes: 39 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]

### Breaking changes

* Revset and Fileset function names can no longer start with a number.

### Deprecations

### New features

### Fixed bugs


## [0.22.0] - 2024-10-02

### Breaking changes
Expand Down Expand Up @@ -57,7 +57,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* The `git.push-branch-prefix` config has been deprecated in favor of
`git.push-bookmark-prefix`.

* `conflict()` and `file()` revsets have been renamed to `conflicts()` and `files()`
* `conflict()` and `file()` revsets have been renamed to `conflicts()`
and `files()`
respectively. The old names are still around and will be removed in a future
release.

Expand All @@ -70,7 +71,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
as a workaround.
[#323](https://github.com/martinvonz/jj/issues/323)

* `jj fix` now allows fixing unchanged files with the `--include-unchanged-files` flag. This
* `jj fix` now allows fixing unchanged files with
the `--include-unchanged-files` flag. This
can be used to more easily introduce automatic formatting changes in a new
commit separate from other changes.

Expand All @@ -93,25 +95,30 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

* CommitId / ChangeId template types now support `.normal_hex()`.

* `jj commit` and `jj describe` now accept `--author` option allowing to quickly change
* `jj commit` and `jj describe` now accept `--author` option allowing to quickly
change
author of given commit.

* `jj diffedit`, `jj abandon`, and `jj restore` now accept a `--restore-descendants`
flag. When used, descendants of the edited or deleted commits will keep their original
* `jj diffedit`, `jj abandon`, and `jj restore` now accept
a `--restore-descendants`
flag. When used, descendants of the edited or deleted commits will keep their
original
content.

* `jj git fetch -b <remote-git-branch-name>` will now warn if the branch(es)
can not be found in any of the specified/configured remotes.
can not be found in any of the specified/configured remotes.

* `jj split` now lets the user select all changes in interactive mode. This may be used
* `jj split` now lets the user select all changes in interactive mode. This may
be used
to keeping all changes into the first commit while keeping the current commit
description for the second commit (the newly created empty one).

* Author and committer names are now yellow by default.

### Fixed bugs

* Update working copy before reporting changes. This prevents errors during reporting
* Update working copy before reporting changes. This prevents errors during
reporting
from leaving the working copy in a stale state.

* Fixed panic when parsing invalid conflict markers of a particular form.
Expand Down Expand Up @@ -246,7 +253,8 @@ Thanks to the people who made this release happen!

### New features

* Define `immutable_heads()` revset alias in terms of a new `builtin_immutable_heads()`.
* Define `immutable_heads()` revset alias in terms of a
new `builtin_immutable_heads()`.
This enables users to redefine `immutable_heads()` as they wish, but still
have `builtin_immutable_heads()` which should not be redefined.

Expand Down Expand Up @@ -274,7 +282,7 @@ Thanks to the people who made this release happen!
* `jj backout` can now back out multiple commits at once.

* `jj git clone some/nested/path` now creates the full directory tree for
nested destination paths if they don't exist.
nested destination paths if they don't exist.

* String patterns now support case‐insensitive matching by suffixing any
pattern kind with `-i`. `mine()` uses case‐insensitive matching on your email
Expand Down Expand Up @@ -384,9 +392,9 @@ Thanks to the people who made this release happen!

* A new `jj file` subcommand now replaces several existing uncategorized
commands, which are deprecated.
- `jj file show` replaces `jj cat`.
- `jj file chmod` replaces `jj chmod`.
- `jj file list` replaces `jj files`.
- `jj file show` replaces `jj cat`.
- `jj file chmod` replaces `jj chmod`.
- `jj file list` replaces `jj files`.

### New features

Expand All @@ -407,9 +415,9 @@ Thanks to the people who made this release happen!
* Conflicted files are individually simplified before being materialized.

* The `jj file` subcommand now contains several existing file utilities.
- `jj file show`, replacing `jj cat`.
- `jj file chmod` replacing `jj chmod`.
- `jj file list` replacing `jj files`.
- `jj file show`, replacing `jj cat`.
- `jj file chmod` replacing `jj chmod`.
- `jj file list` replacing `jj files`.

* New command `jj branch move` let you update branches by name pattern or source
revision.
Expand Down Expand Up @@ -609,12 +617,12 @@ Thanks to the people who made this release happen!
### Breaking changes

* The default template aliases were replaced as follows:
* `builtin_op_log_root(op_id: OperationId)` ->
`format_root_operation(root: Operation)`
* `builtin_log_root(change_id: ChangeId, commit_id: CommitId)` ->
`format_root_commit(root: Commit)`
* `builtin_change_id_with_hidden_and_divergent_info` ->
`format_short_change_id_with_hidden_and_divergent_info(commit: Commit)`
* `builtin_op_log_root(op_id: OperationId)` ->
`format_root_operation(root: Operation)`
* `builtin_log_root(change_id: ChangeId, commit_id: CommitId)` ->
`format_root_commit(root: Commit)`
* `builtin_change_id_with_hidden_and_divergent_info` ->
`format_short_change_id_with_hidden_and_divergent_info(commit: Commit)`

* The `--revision` option of `jj rebase` is renamed to `--revisions`. The short
alias `-r` is still supported.
Expand Down Expand Up @@ -738,8 +746,8 @@ Thanks to the people who made this release happen!
default `jj` commands.

* Graph node symbols are now configurable via templates
* `templates.log_node`
* `templates.op_log_node`
* `templates.log_node`
* `templates.op_log_node`

* `jj log` now includes synthetic nodes in the graph where some revisions were
elided.
Expand Down Expand Up @@ -841,8 +849,8 @@ No code changes (fixing Rust `Cargo.toml` stuff).
commits when they are created.

This comes with out-of-the-box support for the following backends:
* GnuPG
* SSH
* GnuPG
* SSH

Signature verification and an explicit sign command will hopefully come soon.

Expand Down Expand Up @@ -1188,9 +1196,9 @@ Thanks to the people who made this release happen!
`git.auto-local-branch` setting is applied only to newly fetched remote
branches. Existing remote branches are migrated as follows:

* If local branch exists, the corresponding remote branches are considered
tracking branches.
* Otherwise, the remote branches are non-tracking branches.
* If local branch exists, the corresponding remote branches are considered
tracking branches.
* Otherwise, the remote branches are non-tracking branches.

If the deduced tracking flags are wrong, use `jj branch track`/`untrack`
commands to fix them up.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fileset.pest
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ prefix_ops = _{ negate_op }
infix_ops = _{ union_op | intersection_op | difference_op }

function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
function_arguments = {
expression ~ (whitespace* ~ "," ~ whitespace* ~ expression)* ~ (whitespace* ~ ",")?
| ""
Expand Down
8 changes: 8 additions & 0 deletions lib/src/fileset_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ mod tests {
assert_ne!(parse_normalized(r#" foo "#), parse_normalized(r#" "foo" "#));
}

#[test]
fn test_parse_invalid_function_name() {
assert_eq!(
parse_into_kind("5foo(x)"),
Err(FilesetParseErrorKind::SyntaxError)
);
}

#[test]
fn test_parse_whitespace() {
let ascii_whitespaces: String = ('\x00'..='\x7f')
Expand Down
2 changes: 1 addition & 1 deletion lib/src/revset.pest
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ compat_sub_op = { "-" }
infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op }

function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
keyword_argument = { identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }
argument = _{ keyword_argument | expression }
function_arguments = {
Expand Down
1 change: 1 addition & 0 deletions lib/src/revset_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ mod tests {
#[test]
fn test_parse_revset_alias_func_decl() {
let mut aliases_map = RevsetAliasesMap::new();
assert!(aliases_map.insert("5func()", r#""is function 0""#).is_err());
aliases_map.insert("func()", r#""is function 0""#).unwrap();
aliases_map
.insert("func(a, b)", r#""is function 2""#)
Expand Down

0 comments on commit 498bb7f

Please sign in to comment.