Debian Codegraph @

cli/src/commands/bench/is_ancestor.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 jj_lib::repo::Repo as _;
16 use pollster::FutureExt as _;
17
18 use super::CriterionArgs;
19 use super::run_bench;
20 use crate::cli_util::CommandHelper;
21 use crate::cli_util::RevisionArg;
22 use crate::command_error::CommandError;
23 use crate::ui::Ui;
24
25 /// Checks if the first commit is an ancestor of the second commit
26 #[derive(clap::Args, Clone, Debug)]
27 pub struct BenchIsAncestorArgs {
28 ancestor: RevisionArg,
29
30 descendant: RevisionArg,
31
32 #[command(flatten)]
33 criterion: CriterionArgs,
34 }
35
36 pub async fn cmd_bench_is_ancestor(
37 ui: &mut Ui,
38 command: &CommandHelper,
39 args: &BenchIsAncestorArgs,
40 ) -> Result<(), CommandError> {
41 let workspace_command = command.workspace_helper(ui).await?;
42 let ancestor_commit = workspace_command
43 .resolve_single_rev(ui, &args.ancestor)
44 .await?;
45 let descendant_commit = workspace_command
46 .resolve_single_rev(ui, &args.descendant)
47 .await?;
48 let index = workspace_command.repo().index();
49 let routine = || {
50 index
51 .is_ancestor(ancestor_commit.id(), descendant_commit.id())
52 .block_on()
53 };
54 run_bench(
55 ui,
56 &format!("is-ancestor-{}-{}", args.ancestor, args.descendant),
57 &args.criterion,
58 routine,
59 )?;
60 Ok(())
61 }