just playing with tangled
at diffedit3 72 lines 2.6 kB view raw
1// Copyright 2020 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 clap::ArgGroup; 16use jj_lib::rewrite::rebase_to_dest_parent; 17use tracing::instrument; 18 19use crate::cli_util::{CommandHelper, RevisionArg}; 20use crate::command_error::CommandError; 21use crate::diff_util::{self, DiffFormatArgs}; 22use crate::ui::Ui; 23 24/// Compare the changes of two commits 25/// 26/// This excludes changes from other commits by temporarily rebasing `--from` 27/// onto `--to`'s parents. If you wish to compare the same change across 28/// versions, consider `jj obslog -p` instead. 29#[derive(clap::Args, Clone, Debug)] 30#[command(group(ArgGroup::new("to_diff").args(&["from", "to"]).multiple(true).required(true)))] 31pub(crate) struct InterdiffArgs { 32 /// Show changes from this revision 33 #[arg(long)] 34 from: Option<RevisionArg>, 35 /// Show changes to this revision 36 #[arg(long)] 37 to: Option<RevisionArg>, 38 /// Restrict the diff to these paths 39 #[arg(value_hint = clap::ValueHint::AnyPath)] 40 paths: Vec<String>, 41 #[command(flatten)] 42 format: DiffFormatArgs, 43} 44 45#[instrument(skip_all)] 46pub(crate) fn cmd_interdiff( 47 ui: &mut Ui, 48 command: &CommandHelper, 49 args: &InterdiffArgs, 50) -> Result<(), CommandError> { 51 let workspace_command = command.workspace_helper(ui)?; 52 let from = 53 workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?; 54 let to = workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?; 55 56 let from_tree = rebase_to_dest_parent(workspace_command.repo().as_ref(), &from, &to)?; 57 let to_tree = to.tree()?; 58 let matcher = workspace_command 59 .parse_file_patterns(&args.paths)? 60 .to_matcher(); 61 let diff_formats = diff_util::diff_formats_for(command.settings(), &args.format)?; 62 ui.request_pager(); 63 diff_util::show_diff( 64 ui, 65 ui.stdout_formatter().as_mut(), 66 &workspace_command, 67 &from_tree, 68 &to_tree, 69 matcher.as_ref(), 70 &diff_formats, 71 ) 72}