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

run: Teach run to resolve revsets and about jobs. #2486

Merged
merged 1 commit into from
Nov 4, 2023
Merged
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
43 changes: 33 additions & 10 deletions cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::cli_util::{user_error, CommandError, CommandHelper, RevisionArg};
//! 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,
};
use crate::ui::Ui;

/// Run a command across a set of revisions.
Expand All @@ -24,24 +30,41 @@ use crate::ui::Ui;
/// # Example
///
/// # Run pre-commit on your local work
/// $ jj run 'pre-commit.py .github/pre-commit.yaml' -r (main..@) -j 4
/// $ 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(crate) struct RunArgs {
pub struct RunArgs {
/// The command to run across all selected revisions.
#[arg(long, short, alias = "x")]
command: String,
shell_command: String,
/// The revisions to change.
/// Multiple revsets are accepted and the work will be done on a
/// intersection of them.
PhilipMetzger marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long, short, default_value = "@")]
revisions: Vec<RevisionArg>,
/// A no-op option to match the interface of `git rebase -x`.
#[arg(short = 'x', hide = true)]
unused_command: bool,
/// How many processes should run in parallel, uses by default all cores.
#[arg(long, short)]
jobs: Option<usize>,
}

pub(crate) fn cmd_run(
_ui: &mut Ui,
_command: &CommandHelper,
_args: &RunArgs,
) -> Result<(), CommandError> {
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)?;
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(unsafe { NonZeroUsize::new_unchecked(4) });
PhilipMetzger marked this conversation as resolved.
Show resolved Hide resolved
available.into()
PhilipMetzger marked this conversation as resolved.
Show resolved Hide resolved
};
Err(user_error("This is a stub, do not use"))
}