Debian Codegraph @

cli/src/commands/bench/common_ancestors.rs

raw
1 // Copyright 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 std::slice;
16
17 use jj_lib::repo::Repo as _;
18 use pollster::FutureExt as _;
19
20 use super::CriterionArgs;
21 use super::run_bench;
22 use crate::cli_util::CommandHelper;
23 use crate::cli_util::RevisionArg;
24 use crate::command_error::CommandError;
25 use crate::ui::Ui;
26
27 /// Find the common ancestor(s) of a set of commits
28 #[derive(clap::Args, Clone, Debug)]
29 pub struct BenchCommonAncestorsArgs {
30 revision1: RevisionArg,
31
32 revision2: RevisionArg,
33
34 #[command(flatten)]
35 criterion: CriterionArgs,
36 }
37
38 pub async fn cmd_bench_common_ancestors(
39 ui: &mut Ui,
40 command: &CommandHelper,
41 args: &BenchCommonAncestorsArgs,
42 ) -> Result<(), CommandError> {
43 let workspace_command = command.workspace_helper(ui).await?;
44 let commit1 = workspace_command
45 .resolve_single_rev(ui, &args.revision1)
46 .await?;
47 let commit2 = workspace_command
48 .resolve_single_rev(ui, &args.revision2)
49 .await?;
50 let index = workspace_command.repo().index();
51 let routine = || {
52 index
53 .common_ancestors(slice::from_ref(commit1.id()), slice::from_ref(commit2.id()))
54 .block_on()
55 };
56 run_bench(
57 ui,
58 &format!("common-ancestors-{}-{}", args.revision1, args.revision2),
59 &args.criterion,
60 routine,
61 )?;
62 Ok(())
63 }