Skip to content

Commit

Permalink
run: Fix up various things.
Browse files Browse the repository at this point in the history
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 two, as most cheap consumer laptops
don't have four cores.

Thanks to @necaqua 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.
  • Loading branch information
PhilipMetzger committed Nov 8, 2023
1 parent 084b99e commit 78c5dd5
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,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<RevisionArg>,
/// A no-op option to match the interface of `git rebase -x`.
Expand All @@ -55,16 +53,16 @@ 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()
};
let _jobs = args
.jobs
.filter(|j| j > 0)
.or_else(|| {
// Use all available cores
std::thread::available_parallelism()
.ok()
.and_then(|t| t.try_into().ok())
})
// Fallback to two cores as we don't know on which system we're running on.
.unwrap_or(2usize);
Err(user_error("This is a stub, do not use"))
}

0 comments on commit 78c5dd5

Please sign in to comment.