Debian Codegraph @

cli/src/commands/bench/resolve_prefix.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::object_id::HexPrefix;
16 use jj_lib::repo::Repo as _;
17 use pollster::FutureExt as _;
18
19 use super::CriterionArgs;
20 use super::run_bench;
21 use crate::cli_util::CommandHelper;
22 use crate::command_error::CommandError;
23 use crate::ui::Ui;
24
25 /// Resolve a commit ID prefix
26 #[derive(clap::Args, Clone, Debug)]
27 pub struct BenchResolvePrefixArgs {
28 prefix: String,
29
30 #[command(flatten)]
31 criterion: CriterionArgs,
32 }
33
34 pub async fn cmd_bench_resolve_prefix(
35 ui: &mut Ui,
36 command: &CommandHelper,
37 args: &BenchResolvePrefixArgs,
38 ) -> Result<(), CommandError> {
39 let workspace_command = command.workspace_helper(ui).await?;
40 let prefix = HexPrefix::try_from_hex(&args.prefix).unwrap();
41 let index = workspace_command.repo().index();
42 let routine = || index.resolve_commit_id_prefix(&prefix).block_on();
43 run_bench(
44 ui,
45 &format!("resolve-prefix-{}", prefix.hex()),
46 &args.criterion,
47 routine,
48 )?;
49 Ok(())
50 }