Skip to content

Commit

Permalink
cli: add ui.allow-filesets to experiment with fileset/pattern syntax
Browse files Browse the repository at this point in the history
The pattern syntax could be enabled unconditionally, but I want to fully
replace the ad-hoc pattern parsing function.
  • Loading branch information
yuja committed Apr 12, 2024
1 parent 65a525c commit a9694cb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj status` now supports filtering by paths. For example, `jj status .` will
only list changed files that are descendants of the current directory.

* File path arguments now support [file pattern
* A new config option `ui.allow-filesets` has been added to enable [file pattern
syntax](docs/filesets.md#file-patterns).

* `jj prev` and `jj next` now work when the working copy revision is a merge.
Expand Down
9 changes: 8 additions & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl WorkspaceCommandHelper {
// empty arguments.
if values.is_empty() {
Ok(FilesetExpression::all())
} else {
} else if self.settings.config().get_bool("ui.allow-filesets")? {
let ctx = self.fileset_parse_context();
let expressions = values
.iter()
Expand All @@ -665,6 +665,13 @@ impl WorkspaceCommandHelper {
.try_collect()
.map_err(user_error)?;
Ok(FilesetExpression::union_all(expressions))
} else {
let expressions = values
.iter()
.map(|v| self.parse_file_path(v))
.map_ok(FilesetExpression::prefix_path)
.try_collect()?;
Ok(FilesetExpression::union_all(expressions))
}
}

Expand Down
5 changes: 5 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"description": "Whether to allow initializing a repo with the native backend",
"default": false
},
"allow-filesets": {
"type": "boolean",
"description": "Whether to parse path arguments as fileset expressions",
"default": false
},
"always-allow-large-revsets": {
"type": "boolean",
"description": "Whether to allow large revsets to be used in all commands without the `all:` modifier",
Expand Down
1 change: 1 addition & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ unamend = ["unsquash"]
tree-level-conflicts = true

[ui]
allow-filesets = false
always-allow-large-revsets = false
diff-instructions = true
paginate = "auto"
Expand Down
12 changes: 12 additions & 0 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,18 @@ fn test_log_filtered_by_path() {
A file2
"###);

// Fileset/pattern syntax is disabled by default.
let stderr = test_env.jj_cmd_failure(
test_env.env_root(),
&["log", "-R", repo_path.to_str().unwrap(), "root:file1"],
);
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
Error: Path "root:file1" is not in the repo "repo"
Caused by: Invalid component ".." in repo-relative path "../root:file1"
"###);

test_env.add_config("ui.allow-filesets = true");

// "root:<path>" is resolved relative to the workspace root.
let stdout = test_env.jj_cmd_success(
test_env.env_root(),
Expand Down
7 changes: 7 additions & 0 deletions docs/filesets.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Expressions in this language are called "filesets" (the idea comes from
[Mercurial](https://repo.mercurial-scm.org/hg/help/filesets)). The language
consists of file patterns, operators, and functions.

**Filesets support is still experimental.** It can be enabled by
`ui.allow-filesets`.

```toml
ui.allow-filesets = true
```

## File patterns

The following patterns are supported:
Expand Down

0 comments on commit a9694cb

Please sign in to comment.