108 lines · 3.5 KB · Rust
RawDownload
// Copyright 2020-2023 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. mod abandon;mod diff;mod log;mod restore;mod show;pub mod undo; use abandon::cmd_op_abandon;use abandon::OperationAbandonArgs;use clap::Subcommand;use diff::cmd_op_diff;use diff::OperationDiffArgs;use log::cmd_op_log;use log::OperationLogArgs;use restore::cmd_op_restore;use restore::OperationRestoreArgs;use show::cmd_op_show;use show::OperationShowArgs;use undo::cmd_op_undo;use undo::OperationUndoArgs; use crate::cli_util::CommandHelper;use crate::command_error::CommandError;use crate::ui::Ui; /// Commands for working with the operation log////// See the [operation log documentation] for more information.////// [operation log documentation]:///     https://jj-vcs.github.io/jj/latest/operation-log/#[derive(Subcommand, Clone, Debug)]pub enum OperationCommand {    Abandon(OperationAbandonArgs),    Diff(OperationDiffArgs),    Log(OperationLogArgs),    Restore(OperationRestoreArgs),    Show(OperationShowArgs),    Undo(OperationUndoArgs),} pub fn cmd_operation(    ui: &mut Ui,    command: &CommandHelper,    subcommand: &OperationCommand,) -> Result<(), CommandError> {    match subcommand {        OperationCommand::Abandon(args) => cmd_op_abandon(ui, command, args),        OperationCommand::Diff(args) => cmd_op_diff(ui, command, args),        OperationCommand::Log(args) => cmd_op_log(ui, command, args),        OperationCommand::Restore(args) => cmd_op_restore(ui, command, args),        OperationCommand::Show(args) => cmd_op_show(ui, command, args),        OperationCommand::Undo(args) => cmd_op_undo(ui, command, args),    }} #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]enum UndoWhatToRestore {    /// The jj repo state and local bookmarks    Repo,    /// The remote-tracking bookmarks. Do not restore these if you'd like to    /// push after the undo    RemoteTracking,} const DEFAULT_UNDO_WHAT: [UndoWhatToRestore; 2] =    [UndoWhatToRestore::Repo, UndoWhatToRestore::RemoteTracking]; /// Restore only the portions of the view specified by the `what` argumentfn view_with_desired_portions_restored(    view_being_restored: &jj_lib::op_store::View,    current_view: &jj_lib::op_store::View,    what: &[UndoWhatToRestore],) -> jj_lib::op_store::View {    let repo_source = if what.contains(&UndoWhatToRestore::Repo) {        view_being_restored    } else {        current_view    };    let remote_source = if what.contains(&UndoWhatToRestore::RemoteTracking) {        view_being_restored    } else {        current_view    };    jj_lib::op_store::View {        head_ids: repo_source.head_ids.clone(),        local_bookmarks: repo_source.local_bookmarks.clone(),        tags: repo_source.tags.clone(),        remote_views: remote_source.remote_views.clone(),        git_refs: current_view.git_refs.clone(),        git_head: current_view.git_head.clone(),        wc_commit_ids: repo_source.wc_commit_ids.clone(),    }}