Skip to content

Commit

Permalink
Refactor and rename rewrite_multiple_rewriteable_revsets to be more…
Browse files Browse the repository at this point in the history
… general

We'll soon need that functionality without the checking for rewriteable
part.
  • Loading branch information
ilyagr committed Feb 5, 2023
1 parent 10a5c29 commit 2c53946
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,17 +1396,14 @@ fn load_revset_aliases(
Ok(aliases_map)
}

pub fn resolve_multiple_rewritable_revsets(
pub fn resolve_multiple_nonempty_revsets(
revision_args: &[RevisionArg],
workspace_command: &WorkspaceCommandHelper,
) -> Result<IndexSet<Commit>, CommandError> {
let mut acc = IndexSet::new();
for revset in revision_args {
let revisions = workspace_command.resolve_revset(revset)?;
workspace_command.check_non_empty(&revisions)?;
for commit in &revisions {
workspace_command.check_rewritable(commit)?;
}
acc.extend(revisions);
}
Ok(acc)
Expand Down
14 changes: 11 additions & 3 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use pest::Parser;

use crate::cli_util::{
self, check_stale_working_copy, print_checkout_stats, resolve_base_revs,
resolve_multiple_rewritable_revsets, run_ui_editor, serialize_config_value, short_commit_hash,
resolve_multiple_nonempty_revsets, run_ui_editor, serialize_config_value, short_commit_hash,
user_error, user_error_with_hint, Args, CommandError, CommandHelper, DescriptionArg,
RevisionArg, WorkspaceCommandHelper, DESCRIPTION_PLACEHOLDER_TEMPLATE,
};
Expand Down Expand Up @@ -1869,7 +1869,11 @@ fn cmd_duplicate(
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let to_duplicate: IndexSet<Commit> =
resolve_multiple_rewritable_revsets(&args.revisions, &workspace_command)?;
resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command)?;
to_duplicate
.iter()
.map(|commit| workspace_command.check_rewritable(commit))
.try_collect()?;
let mut duplicated_old_to_new: IndexMap<Commit, Commit> = IndexMap::new();

let mut tx = workspace_command
Expand Down Expand Up @@ -1922,7 +1926,11 @@ fn cmd_abandon(
args: &AbandonArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let to_abandon = resolve_multiple_rewritable_revsets(&args.revisions, &workspace_command)?;
let to_abandon = resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command)?;
to_abandon
.iter()
.map(|commit| workspace_command.check_rewritable(commit))
.try_collect()?;
let transaction_description = if to_abandon.len() == 1 {
format!("abandon commit {}", to_abandon[0].id().hex())
} else {
Expand Down

0 comments on commit 2c53946

Please sign in to comment.