mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-03 18:24:19 +00:00
run: Fix up various things.
Adress the post-merge comments from #2486, which found a doc comment inaccurate and to not blindly ignore `-j 0` which would've worked until now. I've also reduced the default `jobs` size to one, as it's user-visible configuration which determines how many processes should run. Thanks to @necauqua the controversial `unsafe` usage was already removed. I've omitted to change `revisions` from an Vec to a RevisonArg for the moment, as I will keep working on the file anyway.
This commit is contained in:
parent
59ef3f0023
commit
c78425cf65
1 changed files with 13 additions and 15 deletions
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
//! This file contains the internal implementation of `run`.
|
//! This file contains the internal implementation of `run`.
|
||||||
|
|
||||||
use std::num::NonZeroUsize;
|
|
||||||
|
|
||||||
use crate::cli_util::{
|
use crate::cli_util::{
|
||||||
resolve_multiple_nonempty_revsets, user_error, CommandError, CommandHelper, RevisionArg,
|
resolve_multiple_nonempty_revsets, user_error, CommandError, CommandHelper, RevisionArg,
|
||||||
};
|
};
|
||||||
|
@ -39,8 +37,6 @@ pub struct RunArgs {
|
||||||
/// The command to run across all selected revisions.
|
/// The command to run across all selected revisions.
|
||||||
shell_command: String,
|
shell_command: String,
|
||||||
/// The revisions to change.
|
/// The revisions to change.
|
||||||
/// Multiple revsets are accepted and the work will be done on a
|
|
||||||
/// intersection of them.
|
|
||||||
#[arg(long, short, default_value = "@")]
|
#[arg(long, short, default_value = "@")]
|
||||||
revisions: Vec<RevisionArg>,
|
revisions: Vec<RevisionArg>,
|
||||||
/// A no-op option to match the interface of `git rebase -x`.
|
/// A no-op option to match the interface of `git rebase -x`.
|
||||||
|
@ -55,16 +51,18 @@ pub fn cmd_run(ui: &mut Ui, command: &CommandHelper, args: &RunArgs) -> Result<(
|
||||||
let workspace_command = command.workspace_helper(ui)?;
|
let workspace_command = command.workspace_helper(ui)?;
|
||||||
let _resolved_commits =
|
let _resolved_commits =
|
||||||
resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?;
|
resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?;
|
||||||
let _jobs = if let Some(_jobs) = args.jobs {
|
// Jobs are resolved in this order:
|
||||||
_jobs
|
// 1. Commandline argument iff > 0.
|
||||||
} else {
|
// 2. the amount of cores available.
|
||||||
// Use all available cores
|
// 3. a single job, if all of the above fails.
|
||||||
|
let _jobs = match args.jobs {
|
||||||
// SAFETY:
|
Some(0) => return Err(user_error("must pass at least one job")),
|
||||||
// We use a internal constant of 4 threads, if it fails
|
Some(jobs) => Some(jobs),
|
||||||
let available =
|
None => std::thread::available_parallelism()
|
||||||
std::thread::available_parallelism().unwrap_or(NonZeroUsize::new(4).unwrap());
|
.ok()
|
||||||
available.into()
|
.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"))
|
Err(user_error("This is a stub, do not use"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue