diff --git a/cli/src/commands/run.rs b/cli/src/commands/run.rs index cd343d490a8..d1d57c5c89b 100644 --- a/cli/src/commands/run.rs +++ b/cli/src/commands/run.rs @@ -14,8 +14,6 @@ //! This file contains the internal implementation of `run`. -use std::num::NonZeroUsize; - use crate::cli_util::{ resolve_multiple_nonempty_revsets, user_error, CommandError, CommandHelper, RevisionArg, }; @@ -39,8 +37,6 @@ pub struct RunArgs { /// The command to run across all selected revisions. shell_command: String, /// 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, /// A no-op option to match the interface of `git rebase -x`. @@ -55,16 +51,21 @@ pub fn cmd_run(ui: &mut Ui, command: &CommandHelper, args: &RunArgs) -> Result<( let workspace_command = command.workspace_helper(ui)?; let _resolved_commits = resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?; - let _jobs = if let Some(_jobs) = args.jobs { - _jobs - } else { - // Use all available cores - - // SAFETY: - // We use a internal constant of 4 threads, if it fails - let available = - std::thread::available_parallelism().unwrap_or(NonZeroUsize::new(4).unwrap()); - available.into() - }; + // Jobs are resolved in this order: + // 1. Commandline argument iff > 0. + // 2. the amount of cores available. + // 3. a single job, if all above fails. + let _jobs = args + .jobs + // We need to fixup a `jj run -j0` input, as 0 jobs is a invalid state. + .filter(|j| *j > 0) + .or_else(|| { + // Use all available cores + std::thread::available_parallelism() + .ok() + .and_then(|t| t.try_into().ok()) + }) + // Fallback to a single user-visible job. + .unwrap_or(1usize); Err(user_error("This is a stub, do not use")) }