ok/jj
1
0
Fork 0
forked from mirrors/jj

Refactor & rename resolve_base_revs to extract the more general function

This extracts the more general `resolve_mutliple_nonempty_revsets_flag_guarded`
out of `resolve_base_revs`. This function should be useful for `rebase -s`,
etc.

`resolve_base_revs` is renamed to `resolve_destination_revs`; that's simply a
better name for it. It is also quite specific to the `new` and `rebase -d`
commands.  It will be moved out of general utilities in the next commit
This commit is contained in:
Ilya Grigoriev 2023-02-04 16:10:42 -08:00
parent 1c6c6dbccc
commit 4183c69238
2 changed files with 20 additions and 6 deletions

View file

@ -1409,15 +1409,15 @@ pub fn resolve_multiple_nonempty_revsets(
Ok(acc)
}
pub fn resolve_base_revs(
pub fn resolve_mutliple_nonempty_revsets_flag_guarded(
workspace_command: &WorkspaceCommandHelper,
revisions: &[RevisionArg],
allow_plural_revsets: bool,
) -> Result<IndexSet<Commit>, CommandError> {
let mut commits = IndexSet::new();
if allow_plural_revsets {
commits = resolve_multiple_nonempty_revsets(revisions, workspace_command)?;
resolve_multiple_nonempty_revsets(revisions, workspace_command)
} else {
let mut commits = IndexSet::new();
for revision_str in revisions {
let commit = workspace_command.resolve_single_rev(revision_str)?;
let commit_hash = short_commit_hash(commit.id());
@ -1427,8 +1427,22 @@ pub fn resolve_base_revs(
)));
}
}
Ok(commits)
}
}
/// 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"))

View file

@ -45,7 +45,7 @@ use maplit::{hashmap, hashset};
use pest::Parser;
use crate::cli_util::{
self, check_stale_working_copy, print_checkout_stats, resolve_base_revs,
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,
@ -2003,7 +2003,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
!args.revisions.is_empty(),
"expected a non-empty list from clap"
);
let commits = resolve_base_revs(
let commits = resolve_destination_revs(
&workspace_command,
&args.revisions,
args.allow_large_revsets,
@ -2698,7 +2698,7 @@ fn cmd_merge(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(),
fn cmd_rebase(ui: &mut Ui, command: &CommandHelper, args: &RebaseArgs) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let new_parents = resolve_base_revs(
let new_parents = resolve_destination_revs(
&workspace_command,
&args.destination,
args.allow_large_revsets,