| 1 |
// Copyright 2020-2023 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
mod abandon; |
| 16 |
mod diff; |
| 17 |
mod integrate; |
| 18 |
mod log; |
| 19 |
mod restore; |
| 20 |
mod revert; |
| 21 |
mod show; |
| 22 |
|
| 23 |
use abandon::OperationAbandonArgs; |
| 24 |
use abandon::cmd_op_abandon; |
| 25 |
use clap::Subcommand; |
| 26 |
use diff::OperationDiffArgs; |
| 27 |
use diff::cmd_op_diff; |
| 28 |
use integrate::OperationIntegrateArgs; |
| 29 |
use integrate::cmd_op_integrate; |
| 30 |
use log::OperationLogArgs; |
| 31 |
use log::cmd_op_log; |
| 32 |
use restore::OperationRestoreArgs; |
| 33 |
use restore::cmd_op_restore; |
| 34 |
use revert::OperationRevertArgs; |
| 35 |
use revert::cmd_op_revert; |
| 36 |
use show::OperationShowArgs; |
| 37 |
use show::cmd_op_show; |
| 38 |
|
| 39 |
use crate::cli_util::CommandHelper; |
| 40 |
use crate::command_error::CommandError; |
| 41 |
use crate::ui::Ui; |
| 42 |
|
| 43 |
/// Commands for working with the operation log |
| 44 |
/// |
| 45 |
/// See the [operation log documentation] for more information. |
| 46 |
/// |
| 47 |
/// [operation log documentation]: |
| 48 |
/// https://docs.jj-vcs.dev/latest/operation-log/ |
| 49 |
#[derive(Subcommand, Clone, Debug)] |
| 50 |
pub enum OperationCommand { |
| 51 |
Abandon(OperationAbandonArgs), |
| 52 |
Diff(OperationDiffArgs), |
| 53 |
Integrate(OperationIntegrateArgs), |
| 54 |
Log(OperationLogArgs), |
| 55 |
Restore(OperationRestoreArgs), |
| 56 |
Revert(OperationRevertArgs), |
| 57 |
Show(OperationShowArgs), |
| 58 |
} |
| 59 |
|
| 60 |
pub async fn cmd_operation( |
| 61 |
ui: &mut Ui, |
| 62 |
command: &CommandHelper, |
| 63 |
subcommand: &OperationCommand, |
| 64 |
) -> Result<(), CommandError> { |
| 65 |
match subcommand { |
| 66 |
OperationCommand::Abandon(args) => cmd_op_abandon(ui, command, args).await, |
| 67 |
OperationCommand::Diff(args) => cmd_op_diff(ui, command, args).await, |
| 68 |
OperationCommand::Integrate(args) => cmd_op_integrate(ui, command, args).await, |
| 69 |
OperationCommand::Log(args) => cmd_op_log(ui, command, args).await, |
| 70 |
OperationCommand::Restore(args) => cmd_op_restore(ui, command, args).await, |
| 71 |
OperationCommand::Revert(args) => cmd_op_revert(ui, command, args).await, |
| 72 |
OperationCommand::Show(args) => cmd_op_show(ui, command, args).await, |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
// pub for `jj undo` |
| 77 |
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] |
| 78 |
pub(crate) enum RevertWhatToRestore { |
| 79 |
/// The jj repo state and local bookmarks |
| 80 |
Repo, |
| 81 |
/// The remote-tracking bookmarks. Do not restore these if you'd like to |
| 82 |
/// push after the undo |
| 83 |
RemoteTracking, |
| 84 |
} |
| 85 |
|
| 86 |
// pub for `jj undo` |
| 87 |
pub(crate) const DEFAULT_REVERT_WHAT: [RevertWhatToRestore; 2] = [ |
| 88 |
RevertWhatToRestore::Repo, |
| 89 |
RevertWhatToRestore::RemoteTracking, |
| 90 |
]; |
| 91 |
|
| 92 |
/// Restore only the portions of the view specified by the `what` argument |
| 93 |
pub(crate) fn view_with_desired_portions_restored( |
| 94 |
view_being_restored: &jj_lib::op_store::View, |
| 95 |
current_view: &jj_lib::op_store::View, |
| 96 |
what: &[RevertWhatToRestore], |
| 97 |
) -> jj_lib::op_store::View { |
| 98 |
let repo_source = if what.contains(&RevertWhatToRestore::Repo) { |
| 99 |
view_being_restored |
| 100 |
} else { |
| 101 |
current_view |
| 102 |
}; |
| 103 |
let remote_source = if what.contains(&RevertWhatToRestore::RemoteTracking) { |
| 104 |
view_being_restored |
| 105 |
} else { |
| 106 |
current_view |
| 107 |
}; |
| 108 |
jj_lib::op_store::View { |
| 109 |
head_ids: repo_source.head_ids.clone(), |
| 110 |
local_bookmarks: repo_source.local_bookmarks.clone(), |
| 111 |
local_tags: repo_source.local_tags.clone(), |
| 112 |
remote_views: remote_source.remote_views.clone(), |
| 113 |
git_refs: current_view.git_refs.clone(), |
| 114 |
git_heads: current_view.git_heads.clone(), |
| 115 |
wc_commit_ids: repo_source.wc_commit_ids.clone(), |
| 116 |
} |
| 117 |
} |