Skip to content

Commit

Permalink
Move resolve_destination_revs into mod.rs
Browse files Browse the repository at this point in the history
It's not very general.
  • Loading branch information
ilyagr committed Feb 6, 2023
1 parent 4183c69 commit db148af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
20 changes: 0 additions & 20 deletions src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,26 +1431,6 @@ pub fn resolve_mutliple_nonempty_revsets_flag_guarded(
}
}

/// Resolves revsets into revisions to rebase onto. These revisions don't have
/// to be rewriteable.
pub fn resolve_destination_revs(
workspace_command: &WorkspaceCommandHelper,
revisions: &[RevisionArg],
allow_plural_revsets: bool,
) -> Result<IndexSet<Commit>, CommandError> {
let commits = resolve_mutliple_nonempty_revsets_flag_guarded(
workspace_command,
revisions,
allow_plural_revsets,
)?;
let root_commit_id = workspace_command.repo().store().root_commit_id();
if commits.len() >= 2 && commits.iter().any(|c| c.id() == root_commit_id) {
Err(user_error("Cannot merge with root revision"))
} else {
Ok(commits)
}
}

pub fn update_working_copy(
ui: &mut Ui,
repo: &Arc<ReadonlyRepo>,
Expand Down
28 changes: 24 additions & 4 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ use maplit::{hashmap, hashset};
use pest::Parser;

use crate::cli_util::{
self, check_stale_working_copy, print_checkout_stats, resolve_destination_revs,
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,
self, check_stale_working_copy, print_checkout_stats, resolve_multiple_nonempty_revsets,
resolve_mutliple_nonempty_revsets_flag_guarded, run_ui_editor, serialize_config_value,
short_commit_hash, user_error, user_error_with_hint, Args, CommandError, CommandHelper,
DescriptionArg, RevisionArg, WorkspaceCommandHelper, DESCRIPTION_PLACEHOLDER_TEMPLATE,
};
use crate::config::{config_path, AnnotatedValue, ConfigSource};
use crate::diff_util::{self, DiffFormat, DiffFormatArgs};
Expand Down Expand Up @@ -1997,6 +1997,26 @@ fn cmd_edit(ui: &mut Ui, command: &CommandHelper, args: &EditArgs) -> Result<(),
Ok(())
}

/// Resolves revsets into revisions to rebase onto. These revisions don't have
/// to be rewriteable.
fn resolve_destination_revs(
workspace_command: &WorkspaceCommandHelper,
revisions: &[RevisionArg],
allow_plural_revsets: bool,
) -> Result<IndexSet<Commit>, CommandError> {
let commits = resolve_mutliple_nonempty_revsets_flag_guarded(
workspace_command,
revisions,
allow_plural_revsets,
)?;
let root_commit_id = workspace_command.repo().store().root_commit_id();
if commits.len() >= 2 && commits.iter().any(|c| c.id() == root_commit_id) {
Err(user_error("Cannot merge with root revision"))
} else {
Ok(commits)
}
}

fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
assert!(
Expand Down

0 comments on commit db148af

Please sign in to comment.