just playing with tangled
at ig/vimdiffwarn 69 lines 2.7 kB view 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 15use std::fmt::Debug; 16use std::io::Write as _; 17 18use jj_lib::default_index::AsCompositeIndex as _; 19use jj_lib::default_index::DefaultReadonlyIndex; 20 21use crate::cli_util::CommandHelper; 22use crate::command_error::internal_error; 23use crate::command_error::user_error; 24use crate::command_error::CommandError; 25use crate::ui::Ui; 26 27/// Show commit index stats 28#[derive(clap::Args, Clone, Debug)] 29pub struct DebugIndexArgs {} 30 31pub fn cmd_debug_index( 32 ui: &mut Ui, 33 command: &CommandHelper, 34 _args: &DebugIndexArgs, 35) -> Result<(), CommandError> { 36 // Resolve the operation without loading the repo, so this command won't 37 // update the index. 38 let workspace = command.load_workspace()?; 39 let repo_loader = workspace.repo_loader(); 40 let op = command.resolve_operation(ui, repo_loader)?; 41 let index_store = repo_loader.index_store(); 42 let index = index_store 43 .get_index_at_op(&op, repo_loader.store()) 44 .map_err(internal_error)?; 45 if let Some(default_index) = index.as_any().downcast_ref::<DefaultReadonlyIndex>() { 46 let stats = default_index.as_composite().stats(); 47 writeln!(ui.stdout(), "Number of commits: {}", stats.num_commits)?; 48 writeln!(ui.stdout(), "Number of merges: {}", stats.num_merges)?; 49 writeln!( 50 ui.stdout(), 51 "Max generation number: {}", 52 stats.max_generation_number 53 )?; 54 writeln!(ui.stdout(), "Number of heads: {}", stats.num_heads)?; 55 writeln!(ui.stdout(), "Number of changes: {}", stats.num_changes)?; 56 writeln!(ui.stdout(), "Stats per level:")?; 57 for (i, level) in stats.levels.iter().enumerate() { 58 writeln!(ui.stdout(), " Level {i}:")?; 59 writeln!(ui.stdout(), " Number of commits: {}", level.num_commits)?; 60 writeln!(ui.stdout(), " Name: {}", level.name.as_ref().unwrap())?; 61 } 62 } else { 63 return Err(user_error(format!( 64 "Cannot get stats for indexes of type '{}'", 65 index_store.name() 66 ))); 67 } 68 Ok(()) 69}