mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-26 14:00:51 +00:00
cli: preserve RevisionArg type as much as possible
Just for a bit of type safety.
This commit is contained in:
parent
426ee1c154
commit
ae91adbaf4
9 changed files with 38 additions and 29 deletions
|
@ -240,7 +240,7 @@ fn cmd_branch_create(
|
|||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let target_commit =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
workspace_command.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let view = workspace_command.repo().view();
|
||||
let branch_names = &args.names;
|
||||
if let Some(branch_name) = branch_names
|
||||
|
@ -341,7 +341,7 @@ fn cmd_branch_set(
|
|||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let target_commit =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
workspace_command.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let repo = workspace_command.repo().as_ref();
|
||||
let is_fast_forward = |old_target: &RefTarget| {
|
||||
// Strictly speaking, "all" old targets should be ancestors, but we allow
|
||||
|
|
|
@ -313,8 +313,8 @@ fn cmd_debug_tree(
|
|||
let tree = store.get_tree(&dir, &tree_id)?;
|
||||
MergedTree::resolved(tree)
|
||||
} else {
|
||||
let commit =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
let commit = workspace_command
|
||||
.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
commit.tree()?
|
||||
};
|
||||
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
||||
|
|
|
@ -63,13 +63,15 @@ pub(crate) fn cmd_diff(
|
|||
let from_tree;
|
||||
let to_tree;
|
||||
if args.from.is_some() || args.to.is_some() {
|
||||
let from = workspace_command.resolve_single_rev(args.from.as_deref().unwrap_or("@"))?;
|
||||
let from =
|
||||
workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
from_tree = from.tree()?;
|
||||
let to = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"))?;
|
||||
let to =
|
||||
workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
to_tree = to.tree()?;
|
||||
} else {
|
||||
let commit =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
let commit = workspace_command
|
||||
.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let parents = commit.parents();
|
||||
from_tree = merge_commit_trees(workspace_command.repo().as_ref(), &parents)?;
|
||||
to_tree = commit.tree()?
|
||||
|
|
|
@ -66,16 +66,18 @@ pub(crate) fn cmd_diffedit(
|
|||
|
||||
let (target_commit, base_commits, diff_description);
|
||||
if args.from.is_some() || args.to.is_some() {
|
||||
target_commit = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"))?;
|
||||
target_commit =
|
||||
workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
base_commits =
|
||||
vec![workspace_command.resolve_single_rev(args.from.as_deref().unwrap_or("@"))?];
|
||||
vec![workspace_command
|
||||
.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?];
|
||||
diff_description = format!(
|
||||
"The diff initially shows the commit's changes relative to:\n{}",
|
||||
workspace_command.format_commit_summary(&base_commits[0])
|
||||
);
|
||||
} else {
|
||||
target_commit =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
target_commit = workspace_command
|
||||
.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
base_commits = target_commit.parents();
|
||||
diff_description = "The diff initially shows the commit's changes.".to_string();
|
||||
};
|
||||
|
|
|
@ -49,8 +49,9 @@ pub(crate) fn cmd_interdiff(
|
|||
args: &InterdiffArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let from = workspace_command.resolve_single_rev(args.from.as_deref().unwrap_or("@"))?;
|
||||
let to = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"))?;
|
||||
let from =
|
||||
workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let to = workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
|
||||
let from_tree = rebase_to_dest_parent(workspace_command.repo().as_ref(), &from, &to)?;
|
||||
let to_tree = to.tree()?;
|
||||
|
|
|
@ -71,8 +71,10 @@ pub(crate) fn cmd_move(
|
|||
"`jj move` will be removed in a future version, and this will be a hard error"
|
||||
)?;
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let source = workspace_command.resolve_single_rev(args.from.as_deref().unwrap_or("@"))?;
|
||||
let destination = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"))?;
|
||||
let source =
|
||||
workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let destination =
|
||||
workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
if source.id() == destination.id() {
|
||||
return Err(user_error("Source and destination cannot be the same."));
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ Please use `jj rebase -d 'all:x|y'` instead of `jj rebase --allow-large-revsets
|
|||
.resolve_some_revsets_default_single(&args.destination)?
|
||||
.into_iter()
|
||||
.collect_vec();
|
||||
if let Some(rev_str) = &args.revision {
|
||||
if let Some(rev_arg) = &args.revision {
|
||||
assert_eq!(
|
||||
// In principle, `-r --skip-empty` could mean to abandon the `-r`
|
||||
// commit if it becomes empty. This seems internally consistent with
|
||||
|
@ -218,7 +218,7 @@ Please use `jj rebase -d 'all:x|y'` instead of `jj rebase --allow-large-revsets
|
|||
command.settings(),
|
||||
&mut workspace_command,
|
||||
&new_parents,
|
||||
rev_str,
|
||||
rev_arg,
|
||||
)?;
|
||||
} else if !args.source.is_empty() {
|
||||
let source_commits = workspace_command.resolve_some_revsets_default_single(&args.source)?;
|
||||
|
@ -232,7 +232,7 @@ Please use `jj rebase -d 'all:x|y'` instead of `jj rebase --allow-large-revsets
|
|||
)?;
|
||||
} else {
|
||||
let branch_commits = if args.branch.is_empty() {
|
||||
IndexSet::from([workspace_command.resolve_single_rev("@")?])
|
||||
IndexSet::from([workspace_command.resolve_single_rev(&RevisionArg::AT)?])
|
||||
} else {
|
||||
workspace_command.resolve_some_revsets_default_single(&args.branch)?
|
||||
};
|
||||
|
@ -350,9 +350,9 @@ fn rebase_revision(
|
|||
settings: &UserSettings,
|
||||
workspace_command: &mut WorkspaceCommandHelper,
|
||||
new_parents: &[Commit],
|
||||
rev_str: &str,
|
||||
rev_arg: &RevisionArg,
|
||||
) -> Result<(), CommandError> {
|
||||
let old_commit = workspace_command.resolve_single_rev(rev_str)?;
|
||||
let old_commit = workspace_command.resolve_single_rev(rev_arg)?;
|
||||
workspace_command.check_rewritable([&old_commit])?;
|
||||
if new_parents.contains(&old_commit) {
|
||||
return Err(user_error(format!(
|
||||
|
|
|
@ -86,13 +86,14 @@ pub(crate) fn cmd_restore(
|
|||
));
|
||||
}
|
||||
if args.from.is_some() || args.to.is_some() {
|
||||
to_commit = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"))?;
|
||||
to_commit =
|
||||
workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
from_tree = workspace_command
|
||||
.resolve_single_rev(args.from.as_deref().unwrap_or("@"))?
|
||||
.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?
|
||||
.tree()?;
|
||||
} else {
|
||||
to_commit =
|
||||
workspace_command.resolve_single_rev(args.changes_in.as_deref().unwrap_or("@"))?;
|
||||
to_commit = workspace_command
|
||||
.resolve_single_rev(args.changes_in.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
from_tree = merge_commit_trees(workspace_command.repo().as_ref(), &to_commit.parents())?;
|
||||
}
|
||||
workspace_command.check_rewritable([&to_commit])?;
|
||||
|
|
|
@ -85,10 +85,11 @@ pub(crate) fn cmd_squash(
|
|||
let destination;
|
||||
if args.from.is_some() || args.into.is_some() {
|
||||
sources = workspace_command
|
||||
.parse_revset(args.from.as_deref().unwrap_or("@"))?
|
||||
.parse_revset(args.from.as_ref().unwrap_or(&RevisionArg::AT))?
|
||||
.evaluate_to_commits()?
|
||||
.try_collect()?;
|
||||
destination = workspace_command.resolve_single_rev(args.into.as_deref().unwrap_or("@"))?;
|
||||
destination =
|
||||
workspace_command.resolve_single_rev(args.into.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
if sources.iter().any(|source| source.id() == destination.id()) {
|
||||
return Err(user_error("Source and destination cannot be the same"));
|
||||
}
|
||||
|
@ -97,8 +98,8 @@ pub(crate) fn cmd_squash(
|
|||
// a little faster.
|
||||
sources.reverse();
|
||||
} else {
|
||||
let source =
|
||||
workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?;
|
||||
let source = workspace_command
|
||||
.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||
let mut parents = source.parents();
|
||||
if parents.len() != 1 {
|
||||
return Err(user_error("Cannot squash merge commits"));
|
||||
|
|
Loading…
Reference in a new issue