Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: simplify-parents: add default revsets.simplify-parents config #4879

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
"diff3" conflict style, meaning it is more likely to work with external tools,
but it doesn't support conflicts with more than 2 sides.

* `jj simplify-parents` now supports configuring the default revset when no
`--source` or `--revisions` arguments are provided with the
`revsets.simplify-parents` config.

### Fixed bugs

* `jj config unset <TABLE-NAME>` no longer removes a table (such as `[ui]`.)
Expand Down
43 changes: 23 additions & 20 deletions cli/src/commands/simplify_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ use crate::ui::Ui;
/// ancestor of B, A will be rewritten to have only B as a parent instead of
/// B+C.
#[derive(clap::Args, Clone, Debug)]
#[command(group = clap::ArgGroup::new("revision-args").multiple(true).required(true))]
pub(crate) struct SimplifyParentsArgs {
/// Simplify specified revision(s) together with their trees of descendants
/// (can be repeated)
#[arg(
long, short,
group = "revision-args",
add = ArgValueCandidates::new(complete::mutable_revisions),
)]
#[arg(long, short, add = ArgValueCandidates::new(complete::mutable_revisions))]
source: Vec<RevisionArg>,
/// Simplify specified revision(s) (can be repeated)
#[arg(
long, short,
group = "revision-args",
add = ArgValueCandidates::new(complete::mutable_revisions),
)]
///
/// If both `--source` and `--revisions` are not provided, this defaults to
/// the `revsets.simplify-parents` setting, or `reachable(@, mutable())`
/// if it is not set.
#[arg(long, short, add = ArgValueCandidates::new(complete::mutable_revisions))]
revisions: Vec<RevisionArg>,
}

Expand All @@ -45,16 +40,24 @@ pub(crate) fn cmd_simplify_parents(
args: &SimplifyParentsArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let revs = RevsetExpression::descendants(
let revs = if args.source.is_empty() && args.revisions.is_empty() {
let revs = command.settings().get_string("revsets.simplify-parents")?;
workspace_command
.parse_union_revsets(ui, &args.source)?
.expression(),
)
.union(
workspace_command
.parse_union_revsets(ui, &args.revisions)?
.expression(),
);
.parse_revset(ui, &RevisionArg::from(revs))?
.expression()
.clone()
} else {
RevsetExpression::descendants(
workspace_command
.parse_union_revsets(ui, &args.source)?
.expression(),
)
.union(
workspace_command
.parse_union_revsets(ui, &args.revisions)?
.expression(),
)
};
let commit_ids: Vec<_> = workspace_command
.attach_revset_evaluator(revs)
.evaluate_to_commit_ids()?
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 @@ -421,6 +421,11 @@
"type": "string",
"description": "Revisions to give shorter change and commit IDs to",
"default": "<revsets.log>"
},
"simplify-parents": {
"type": "string",
"description": "Default set of revisions to simplify when no explicit revset is given for jj simplify-parents",
"default": "reachable(@, mutable())"
}
},
"additionalProperties": {
Expand Down
5 changes: 3 additions & 2 deletions cli/src/config/revsets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[revsets]
fix = "reachable(@, mutable())"
simplify-parents = "reachable(@, mutable())"
# log revset is also used as the default short-prefixes. If it failed to
# evaluate, lengthy warning messages would be printed. Use present(expr) to
# suppress symbol resolution error.
Expand All @@ -13,8 +14,8 @@ log = "present(@) | ancestors(immutable_heads().., 2) | present(trunk())"
# symbol resolution error should be suppressed.
'trunk()' = '''
latest(
remote_bookmarks(exact:"main", exact:"origin") |
remote_bookmarks(exact:"master", exact:"origin") |
remote_bookmarks(exact:"main", exact:"origin") |
remote_bookmarks(exact:"master", exact:"origin") |
remote_bookmarks(exact:"trunk", exact:"origin") |
remote_bookmarks(exact:"main", exact:"upstream") |
remote_bookmarks(exact:"master", exact:"upstream") |
Expand Down
4 changes: 3 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1975,13 +1975,15 @@ Removes all parents of each of the specified revisions that are also indirect an

In other words, for all (A, B, C) where A has (B, C) as parents and C is an ancestor of B, A will be rewritten to have only B as a parent instead of B+C.

**Usage:** `jj simplify-parents <--source <SOURCE>|--revisions <REVISIONS>>`
**Usage:** `jj simplify-parents [OPTIONS]`

###### **Options:**

* `-s`, `--source <SOURCE>` — Simplify specified revision(s) together with their trees of descendants (can be repeated)
* `-r`, `--revisions <REVISIONS>` — Simplify specified revision(s) (can be repeated)

If both `--source` and `--revisions` are not provided, this defaults to the `revsets.simplify-parents` setting, or `reachable(@, mutable())` if it is not set.



## `jj sparse`
Expand Down
86 changes: 71 additions & 15 deletions cli/tests/test_simplify_parents_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, paren
test_env.jj_cmd_ok(repo_path, &["bookmark", "create", name]);
}

#[test]
fn test_simplify_parents_no_args() {
let (test_env, repo_path) = create_repo();

let stderr = test_env.jj_cmd_cli_error(&repo_path, &["simplify-parents"]);
insta::assert_snapshot!(stderr, @r###"
error: the following required arguments were not provided:
<--source <SOURCE>|--revisions <REVISIONS>>

Usage: jj simplify-parents <--source <SOURCE>|--revisions <REVISIONS>>

For more information, try '--help'.
"###);
}

#[test]
fn test_simplify_parents_no_commits() {
let (test_env, repo_path) = create_repo();
Expand Down Expand Up @@ -248,3 +233,74 @@ fn test_simplify_parents_multiple_redundant_parents() {
"#);
}

#[test]
fn test_simplify_parents_no_args() {
let (test_env, repo_path) = create_repo();

create_commit(&test_env, &repo_path, "a", &["root()"]);
create_commit(&test_env, &repo_path, "b", &["a"]);
create_commit(&test_env, &repo_path, "c", &["a", "b"]);
create_commit(&test_env, &repo_path, "d", &["c"]);
create_commit(&test_env, &repo_path, "e", &["d"]);
create_commit(&test_env, &repo_path, "f", &["d", "e"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]);
insta::assert_snapshot!(stdout, @r#"
@ f
├─╮
│ ○ e
├─╯
○ d
○ c
├─╮
│ ○ b
├─╯
○ a
"#);
let setup_opid = test_env.current_operation_id(&repo_path);

let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["simplify-parents"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Removed 2 edges from 2 out of 6 commits.
Rebased 2 descendant commits
Working copy now at: kmkuslsw 8cc01e1b f | f
Parent commit : znkkpsqq 040ae3a6 e | e
"#);

let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]);
insta::assert_snapshot!(stdout, @r#"
@ f
○ e
○ d
○ c
○ b
○ a
"#);

// Test with custom `revsets.simplify-parents`.
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]);
test_env.add_config(r#"revsets.simplify-parents = "d::""#);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["simplify-parents"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Removed 1 edges from 1 out of 3 commits.
Working copy now at: kmkuslsw 0c6b4c43 f | f
Parent commit : znkkpsqq 6a679611 e | e
"#);

let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]);
insta::assert_snapshot!(stdout, @r#"
@ f
○ e
○ d
○ c
├─╮
│ ○ b
├─╯
○ a
"#);
}