| 1 |
// Copyright 2025 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::default_index::DefaultIndexStore; |
| 16 |
use jj_lib::repo::Repo as _; |
| 17 |
|
| 18 |
use crate::cli_util::CommandHelper; |
| 19 |
use crate::command_error::CommandError; |
| 20 |
use crate::command_error::internal_error; |
| 21 |
use crate::command_error::user_error; |
| 22 |
use crate::progress::ProgressWriter; |
| 23 |
use crate::ui::Ui; |
| 24 |
|
| 25 |
/// Build changed-path index |
| 26 |
#[derive(clap::Args, Clone, Debug)] |
| 27 |
pub struct DebugIndexChangedPathsArgs { |
| 28 |
/// Limit number of revisions to index |
| 29 |
#[arg(long, short = 'n', default_value_t = u32::MAX)] |
| 30 |
limit: u32, |
| 31 |
} |
| 32 |
|
| 33 |
pub async fn cmd_debug_index_changed_paths( |
| 34 |
ui: &mut Ui, |
| 35 |
command: &CommandHelper, |
| 36 |
args: &DebugIndexChangedPathsArgs, |
| 37 |
) -> Result<(), CommandError> { |
| 38 |
let workspace_command = command.workspace_helper(ui).await?; |
| 39 |
let repo = workspace_command.repo(); |
| 40 |
let repo_loader = workspace_command.workspace().repo_loader(); |
| 41 |
let index_store = repo_loader.index_store(); |
| 42 |
let Some(default_index_store) = index_store.downcast_ref::<DefaultIndexStore>() else { |
| 43 |
return Err(user_error(format!( |
| 44 |
"Unsupported index type '{}'", |
| 45 |
index_store.name() |
| 46 |
))); |
| 47 |
}; |
| 48 |
let index = { |
| 49 |
let mut progress_writer = ProgressWriter::new(ui, "Indexing commits"); |
| 50 |
default_index_store |
| 51 |
.build_changed_path_index_at_operation(repo.op_id(), repo.store(), args.limit, |p| { |
| 52 |
if let Some(writer) = &mut progress_writer { |
| 53 |
writer.display(&format!("{}/{}", p.current, p.total)).ok(); |
| 54 |
} |
| 55 |
}) |
| 56 |
.await |
| 57 |
.map_err(internal_error)? |
| 58 |
}; |
| 59 |
let stats = index.stats(); |
| 60 |
writeln!( |
| 61 |
ui.status(), |
| 62 |
"Finished indexing {:?} commits.", |
| 63 |
stats.changed_path_commits_range.unwrap() |
| 64 |
)?; |
| 65 |
Ok(()) |
| 66 |
} |