-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commands: move backout code to backout.rs
- Loading branch information
1 parent
2d23a71
commit 9814aa8
Showing
2 changed files
with
65 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2020 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use jj_lib::backend::ObjectId; | ||
use jj_lib::rewrite::back_out_commit; | ||
use tracing::instrument; | ||
|
||
use crate::cli_util::{CommandError, CommandHelper, RevisionArg}; | ||
use crate::ui::Ui; | ||
|
||
/// Apply the reverse of a revision on top of another revision | ||
#[derive(clap::Args, Clone, Debug)] | ||
pub(crate) struct BackoutArgs { | ||
/// The revision to apply the reverse of | ||
#[arg(long, short, default_value = "@")] | ||
revision: RevisionArg, | ||
/// The revision to apply the reverse changes on top of | ||
// TODO: It seems better to default this to `@-`. Maybe the working | ||
// copy should be rebased on top? | ||
#[arg(long, short, default_value = "@")] | ||
destination: Vec<RevisionArg>, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub(crate) fn cmd_backout( | ||
ui: &mut Ui, | ||
command: &CommandHelper, | ||
args: &BackoutArgs, | ||
) -> Result<(), CommandError> { | ||
let mut workspace_command = command.workspace_helper(ui)?; | ||
let commit_to_back_out = workspace_command.resolve_single_rev(&args.revision, ui)?; | ||
let mut parents = vec![]; | ||
for revision_str in &args.destination { | ||
let destination = workspace_command.resolve_single_rev(revision_str, ui)?; | ||
parents.push(destination); | ||
} | ||
let mut tx = workspace_command.start_transaction(&format!( | ||
"back out commit {}", | ||
commit_to_back_out.id().hex() | ||
)); | ||
back_out_commit( | ||
command.settings(), | ||
tx.mut_repo(), | ||
&commit_to_back_out, | ||
&parents, | ||
)?; | ||
tx.finish(ui)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters