just playing with tangled
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
15use std::fmt::Debug;
16use std::io::Write as _;
17
18use futures::executor::block_on_stream;
19use jj_lib::backend::CopyRecord;
20use jj_lib::repo::Repo as _;
21
22use crate::cli_util::CommandHelper;
23use crate::cli_util::RevisionArg;
24use crate::command_error::CommandError;
25use crate::ui::Ui;
26
27/// Show information about file copies detected
28#[derive(clap::Args, Clone, Debug)]
29pub 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
36pub 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)?;
42 let store = ws.repo().store();
43
44 let commit = ws.resolve_single_rev(ui, &args.revision)?;
45 for parent_id in commit.parent_ids() {
46 for CopyRecord { target, source, .. } in
47 block_on_stream(store.get_copy_records(None, parent_id, commit.id())?)
48 .filter_map(|r| r.ok())
49 {
50 writeln!(
51 ui.stdout(),
52 "{} -> {}",
53 source.as_internal_file_string(),
54 target.as_internal_file_string()
55 )?;
56 }
57 }
58 Ok(())
59}