Debian Codegraph @

cli/src/commands/debug/copy_detection.rs

raw
1 // Copyright 2024 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::fmt::Debug;
16 use std::io::Write as _;
17
18 use futures::StreamExt as _;
19 use jj_lib::backend::CopyRecord;
20 use jj_lib::repo::Repo as _;
21
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 /// Show information about file copies detected
28 #[derive(clap::Args, Clone, Debug)]
29 pub struct CopyDetectionArgs {
30 /// Show file copies detected in changed files in this revision, compared to
31 /// its parent(s)
32 #[arg(default_value = "@", value_name = "REVSET")]
33 revision: RevisionArg,
34 }
35
36 pub async fn cmd_debug_copy_detection(
37 ui: &mut Ui,
38 command: &CommandHelper,
39 args: &CopyDetectionArgs,
40 ) -> Result<(), CommandError> {
41 let ws = command.workspace_helper(ui).await?;
42 let store = ws.repo().store();
43
44 let commit = ws.resolve_single_rev(ui, &args.revision).await?;
45 for parent_id in commit.parent_ids() {
46 let mut records = store.get_copy_records(None, parent_id, commit.id())?;
47 while let Some(result) = records.next().await {
48 if let Ok(CopyRecord { target, source, .. }) = result {
49 writeln!(
50 ui.stdout(),
51 "{} -> {}",
52 source.as_internal_file_string(),
53 target.as_internal_file_string()
54 )?;
55 }
56 }
57 }
58 Ok(())
59 }