From a9694cba274d1dd3f36eb8b669c98bbd8e4daf5c Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 11 Apr 2024 18:04:38 +0900 Subject: [PATCH] cli: add ui.allow-filesets to experiment with fileset/pattern syntax The pattern syntax could be enabled unconditionally, but I want to fully replace the ad-hoc pattern parsing function. --- CHANGELOG.md | 2 +- cli/src/cli_util.rs | 9 ++++++++- cli/src/config-schema.json | 5 +++++ cli/src/config/misc.toml | 1 + cli/tests/test_log_command.rs | 12 ++++++++++++ docs/filesets.md | 7 +++++++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c8917cb5..a57c048e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 924413d189..ba34861ca1 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -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() @@ -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)) } } diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index 340eaa222a..6c69b4c8e7 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -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", diff --git a/cli/src/config/misc.toml b/cli/src/config/misc.toml index dde689ad1c..dc279216ac 100644 --- a/cli/src/config/misc.toml +++ b/cli/src/config/misc.toml @@ -9,6 +9,7 @@ unamend = ["unsquash"] tree-level-conflicts = true [ui] +allow-filesets = false always-allow-large-revsets = false diff-instructions = true paginate = "auto" diff --git a/cli/tests/test_log_command.rs b/cli/tests/test_log_command.rs index 14dd87ee30..b2c1b55e61 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -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:" is resolved relative to the workspace root. let stdout = test_env.jj_cmd_success( test_env.env_root(), diff --git a/docs/filesets.md b/docs/filesets.md index b9bccaf079..768c706607 100644 --- a/docs/filesets.md +++ b/docs/filesets.md @@ -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: