From 6e1977e4f3c525b476ea4bc87ecc8f4276f67f08 Mon Sep 17 00:00:00 2001 From: Philip Metzger Date: Tue, 2 May 2023 16:30:25 +0200 Subject: [PATCH] commands: move `cmd_run` into run.rs. This also does two cosmetic changes, changing `jobs` from a plain usize to a Option and making execute a no-op boolean, like `-r` in describe. It also contains a minor documentation update to match newer `jj` features and a fix to the `pre-submit` invocation. While we're at it, teach it to resolve the passed Revsets. --- cli/src/commands/mod.rs | 49 ++++++++++++++++++++++------------------- cli/src/commands/run.rs | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 cli/src/commands/run.rs diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index a94e680bcb..1253cc304b 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -42,6 +42,7 @@ mod operation; mod prev; mod rebase; mod resolve; +mod run; use std::collections::HashSet; use std::fmt::Debug; @@ -129,7 +130,7 @@ enum Commands { Restore(RestoreArgs), #[command(hide = true)] // TODO: Flesh out. - Run(RunArgs), + Run(run::RunArgs), Show(ShowArgs), #[command(subcommand)] Sparse(SparseArgs), @@ -280,27 +281,34 @@ struct RestoreArgs { revision: Option, } -/// Run a command across a set of revisions. +/// Touch up the content changes in a revision with a diff editor /// +/// With the `-r` option, which is the default, starts a diff editor (`meld` by +/// default) on the changes in the revision. /// -/// All recorded state will be persisted in the `.jj` directory, so occasionally -/// a `jj run --clean` is needed to clean up disk space. +/// With the `--from` and/or `--to` options, starts a diff editor comparing the +/// "from" revision to the "to" revision. /// -/// # Example +/// Edit the right side of the diff until it looks the way you want. Once you +/// close the editor, the revision specified with `-r` or `--to` will be +/// updated. Descendants will be rebased on top as usual, which may result in +/// conflicts. /// -/// # Run pre-commit on your local work -/// $ jj run 'pre-commit.py .github/pre-commit.yaml' -r (main..@) -j 4 -/// -/// This allows pre-commit integration and other funny stuff. +/// See `jj restore` if you want to move entire files from one revision to +/// another. See `jj squash -i` or `jj unsquash -i` if you instead want to move +/// changes into or out of the parent revision. #[derive(clap::Args, Clone, Debug)] -#[command(verbatim_doc_comment)] -struct RunArgs { - /// The command to run across all selected revisions. - #[arg(long, short, alias = "x")] - command: String, - /// The revisions to change. - #[arg(long, short, default_value = "@")] - revisions: Vec, +struct DiffeditArgs { + /// The revision to touch up. Defaults to @ if neither --to nor --from are + /// specified. + #[arg(long, short)] + revision: Option, + /// Show changes from this revision. Defaults to @ if --to is specified. + #[arg(long, conflicts_with = "revision")] + from: Option, + /// Edit changes in this revision. Defaults to @ if --from is specified. + #[arg(long, conflicts_with = "revision")] + to: Option, } /// Split a revision in two @@ -1259,11 +1267,6 @@ don't make any changes, then the operation will be aborted. Ok(()) } -// TODO: Move to run.rs -fn cmd_run(_ui: &mut Ui, _command: &CommandHelper, _args: &RunArgs) -> Result<(), CommandError> { - Err(user_error("This is a stub, do not use")) -} - fn make_branch_term(branch_names: &[impl fmt::Display]) -> String { match branch_names { [branch_name] => format!("branch {}", branch_name), @@ -1668,7 +1671,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Commands::Squash(sub_args) => cmd_squash(ui, command_helper, sub_args), Commands::Unsquash(sub_args) => cmd_unsquash(ui, command_helper, sub_args), Commands::Restore(sub_args) => cmd_restore(ui, command_helper, sub_args), - Commands::Run(sub_args) => cmd_run(ui, command_helper, sub_args), + Commands::Run(sub_args) => run::cmd_run(ui, command_helper, sub_args), Commands::Diffedit(sub_args) => diffedit::cmd_diffedit(ui, command_helper, sub_args), Commands::Split(sub_args) => cmd_split(ui, command_helper, sub_args), Commands::Merge(sub_args) => merge::cmd_merge(ui, command_helper, sub_args), diff --git a/cli/src/commands/run.rs b/cli/src/commands/run.rs new file mode 100644 index 0000000000..d6cd3dd334 --- /dev/null +++ b/cli/src/commands/run.rs @@ -0,0 +1,42 @@ +//! This file contains the internals of the `run` command. +use crate::cli_util::{ + resolve_multiple_nonempty_revsets, user_error, CommandError, CommandHelper, RevisionArg, +}; +use crate::ui::Ui; + +/// Run a command across a set of revisions. +/// +/// +/// All recorded state will be persisted in the `.jj` directory, so occasionally +/// a `jj run --clean` is needed to clean up disk space. +/// +/// # Example +/// +/// # Run pre-commit on your local work +/// $ jj run 'pre-commit run .github/pre-commit.yaml' -r (trunk()..@) -j 4 +/// +/// This allows pre-commit integration and other funny stuff. +#[derive(clap::Args, Clone, Debug)] +#[command(verbatim_doc_comment)] +pub struct RunArgs { + /// The command to run across all selected revisions. + shell_command: String, + /// A no-op option to match the interface of `git bisect -x`. + #[arg(long, short, alias = "x")] + command: bool, + /// The revisions to change. + /// Multiple revsets are accepted and the work will be done on a + /// intersection of them. + #[arg(long, short, default_value = "@")] + revisions: Vec, + /// How many processes should run in parallel, uses by default all cores. + #[arg(long, short)] + jobs: Option, +} + +pub fn cmd_run(ui: &mut Ui, command: &CommandHelper, args: &RunArgs) -> Result<(), CommandError> { + let workspace_command = command.workspace_helper(ui)?; + let _resolved_commits = + resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?; + Err(user_error("This is a stub, do not use")) +}