Debian Codegraph @

cli/src/commands/operation/integrate.rs

raw
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 use jj_lib::op_heads_store;
16 use jj_lib::operation::Operation;
17
18 use crate::cli_util::CommandHelper;
19 use crate::cli_util::merge_operations;
20 use crate::command_error::CommandError;
21 use crate::ui::Ui;
22
23 /// Make an operation part of the operation log
24 ///
25 /// By default, operations are automatically integrated into the operation log,
26 /// but `--no-integrate-operation` or internal errors may cause that to not
27 /// happen. This command can then be used for making such operations part of the
28 /// operation log.
29 ///
30 /// Running this command on an operation that is already in the operation log
31 /// (`jj op log`) has no effect.
32 #[derive(clap::Args, Clone, Debug)]
33 pub struct OperationIntegrateArgs {
34 /// The operation to integrate
35 operation: String,
36 }
37
38 pub async fn cmd_op_integrate(
39 ui: &mut Ui,
40 command: &CommandHelper,
41 args: &OperationIntegrateArgs,
42 ) -> Result<(), CommandError> {
43 let workspace_command = command.workspace_helper_no_snapshot(ui).await?;
44 let target_op = workspace_command.resolve_single_op(&args.operation)?;
45 let repo_loader = workspace_command.repo().loader();
46 repo_loader
47 .op_heads_store()
48 .update_op_heads(target_op.parent_ids(), target_op.id())
49 .await?;
50
51 op_heads_store::resolve_op_heads(
52 repo_loader.op_heads_store().as_ref(),
53 repo_loader.op_store(),
54 async |op_heads| -> Result<Operation, CommandError> {
55 // TODO: It may be helpful to print each operation we're merging here
56 let transaction_description = "reconcile divergent operations";
57 let merged_operation = merge_operations(
58 Some(ui),
59 repo_loader,
60 op_heads,
61 Some(workspace_command.workspace_name()),
62 Some(transaction_description),
63 command.string_args(),
64 )
65 .await?;
66 writeln!(
67 ui.status(),
68 "The specified operation has been integrated with other existing operations."
69 )?;
70 Ok(merged_operation)
71 },
72 )
73 .await?;
74
75 Ok(())
76 }