Skip to content
Draft
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use crate::cli_util::WorkspaceCommandHelper;
use crate::cli_util::WorkspaceCommandTransaction;
use crate::command_error::CommandError;
use crate::command_error::CommandErrorKind;
use crate::commands::sparse::SparseSetArgs;
use crate::ui::Ui;

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -168,6 +169,15 @@ struct WorkspacePool {
/// When true, wipe each slot's working copy on acquisition so every commit
/// starts from a freshly checked-out tree (no artifact reuse).
clean: bool,
// TODO: (TBD) should we just define our own args? Currently, help seems
// to lack sufficient information on these options, yet using the whole
// sparse::set subcommand smells like poor UI as well.
//
// Another thing to discuss is the apparent poor performance of --remove
// option as compared to a semantically equivalent set of --clear and --add
// options, so we just might want to steer the user towards only using the
// latter two.
sparse_args: Option<SparseSetArgs>,
}

impl WorkspacePool {
Expand All @@ -176,6 +186,7 @@ impl WorkspacePool {
size: NonZeroUsize,
auto_tracking_matcher: Box<dyn Matcher>,
clean: bool,
sparse_args: Option<SparseSetArgs>,
) -> Result<Self, RunError> {
// The parent() call is needed to not write under `.jj/repo/`.
let base_path = repo_path.parent().unwrap().join("run").join("default");
Expand All @@ -185,6 +196,7 @@ impl WorkspacePool {
size,
auto_tracking_matcher,
clean,
sparse_args,
})
}

Expand Down Expand Up @@ -259,6 +271,32 @@ impl WorkspacePool {
)
};

// TODO: Sparse patterns will persist across `run` invocations, unless --clean
// is passed, which almost certainly violates the principle of least
// surprise. Persistence should probably be opt-in (and perhaps even
// required opt-in per `run` invocation?). TBD.
if let Some(sparse_args) = &self.sparse_args {
// Adopted almost verbatim from `commands::sparse::cmd_sparse_set`.
let new_patterns: Vec<_> = {
let mut new = HashSet::new();
if !sparse_args.clear {
new.extend(tree_state.sparse_patterns().iter().cloned());
for path in &sparse_args.remove {
new.remove(path);
}
}
for path in &sparse_args.add {
new.insert(path.to_owned());
}
new.into_iter().sorted_unstable().collect()
};

// TODO: define a separate error.
tree_state
.set_sparse_patterns(new_patterns)
.map_err(|_| RunError::FailedCheckout(commit.id().clone()))?;
}

tree_state
.check_out(&commit.tree())
.map_err(|_| RunError::FailedCheckout(commit.id().clone()))?;
Expand Down Expand Up @@ -660,6 +698,9 @@ pub struct RunArgs {
/// `jj run` itself.
#[arg(long)]
ignore_errors: bool,

#[clap(flatten)]
sparse_args: Option<SparseSetArgs>,
}

/// Precedence: `--jobs`, `run.jobs` config, 1.
Expand Down Expand Up @@ -769,6 +810,7 @@ pub async fn cmd_run(
jobs,
auto_tracking_matcher,
args.clean,
args.sparse_args.clone(),
)?);

let spec = Arc::new(CommandSpec {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/sparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use self::list::SparseListArgs;
use self::list::cmd_sparse_list;
use self::reset::SparseResetArgs;
use self::reset::cmd_sparse_reset;
use self::set::SparseSetArgs;
pub(crate) use self::set::SparseSetArgs;
use self::set::cmd_sparse_set;
use crate::cli_util::CommandHelper;
use crate::cli_util::WorkspaceCommandHelper;
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/sparse/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct SparseSetArgs {
value_hint = clap::ValueHint::AnyPath,
value_parser = |s: &str| RepoPathBuf::from_relative_path(s),
)]
add: Vec<RepoPathBuf>,
pub(crate) add: Vec<RepoPathBuf>,

/// Patterns to remove from the working copy
#[arg(
Expand All @@ -45,11 +45,11 @@ pub struct SparseSetArgs {
value_hint = clap::ValueHint::AnyPath,
value_parser = |s: &str| RepoPathBuf::from_relative_path(s),
)]
remove: Vec<RepoPathBuf>,
pub(crate) remove: Vec<RepoPathBuf>,

/// Include no files in the working copy (combine with --add)
#[arg(long)]
clear: bool,
pub(crate) clear: bool,
}

#[instrument(skip_all)]
Expand Down
Loading