just playing with tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

copy-tracking: implement copy-tracking for --types

+46 -22
+1 -1
CHANGELOG.md
··· 15 15 ### New features 16 16 17 17 * The following diff formats now include information about copies and moves: 18 - `--color-words`, `--stat`, `--summary` 18 + `--color-words`, `--stat`, `--summary`, `--types` 19 19 20 20 * A tilde (`~`) at the start of the path will now be expanded to the user's home 21 21 directory when configuring a `signing.key` for SSH commit signing.
+38 -18
cli/src/diff_util.rs
··· 294 294 show_diff_stat(formatter, store, tree_diff, path_converter, width)?; 295 295 } 296 296 DiffFormat::Types => { 297 - let no_copy_tracking = Default::default(); 298 - let tree_diff = from_tree.diff_stream(to_tree, matcher, &no_copy_tracking); 299 - show_types(formatter, tree_diff, path_converter)?; 297 + show_types( 298 + formatter, 299 + path_converter, 300 + from_tree, 301 + to_tree, 302 + matcher, 303 + copy_records, 304 + )?; 300 305 } 301 306 DiffFormat::NameOnly => { 302 307 let tree_diff = from_tree.diff_stream(to_tree, matcher, copy_records); ··· 366 371 width, 367 372 ) 368 373 } 374 + } 375 + 376 + fn collect_copied_sources<'a>( 377 + copy_records: &'a CopyRecords, 378 + matcher: &dyn Matcher, 379 + ) -> HashSet<&'a RepoPath> { 380 + copy_records 381 + .iter() 382 + .filter_map(|record| { 383 + if matcher.matches(&record.target) { 384 + Some(record.source.as_ref()) 385 + } else { 386 + None 387 + } 388 + }) 389 + .collect() 369 390 } 370 391 371 392 fn show_color_words_diff_hunks( ··· 1168 1189 copy_records: &CopyRecords, 1169 1190 ) -> io::Result<()> { 1170 1191 let mut tree_diff = from_tree.diff_stream(to_tree, matcher, copy_records); 1171 - 1172 - let copied_sources: HashSet<&RepoPath> = copy_records 1173 - .iter() 1174 - .filter_map(|record| { 1175 - if matcher.matches(&record.target) { 1176 - Some(record.source.as_ref()) 1177 - } else { 1178 - None 1179 - } 1180 - }) 1181 - .collect(); 1192 + let copied_sources = collect_copied_sources(copy_records, matcher); 1182 1193 1183 1194 async { 1184 1195 while let Some(TreeDiffEntry { ··· 1345 1356 1346 1357 pub fn show_types( 1347 1358 formatter: &mut dyn Formatter, 1348 - mut tree_diff: TreeDiffStream, 1349 1359 path_converter: &RepoPathUiConverter, 1360 + from_tree: &MergedTree, 1361 + to_tree: &MergedTree, 1362 + matcher: &dyn Matcher, 1363 + copy_records: &CopyRecords, 1350 1364 ) -> io::Result<()> { 1365 + let mut tree_diff = from_tree.diff_stream(to_tree, matcher, copy_records); 1366 + let copied_sources = collect_copied_sources(copy_records, matcher); 1367 + 1351 1368 async { 1352 1369 while let Some(TreeDiffEntry { 1353 - source: _, // TODO handle copy tracking 1354 - target: repo_path, 1370 + source, 1371 + target, 1355 1372 value: diff, 1356 1373 }) = tree_diff.next().await 1357 1374 { 1358 1375 let (before, after) = diff.unwrap(); 1376 + if after.is_absent() && copied_sources.contains(source.as_ref()) { 1377 + continue; 1378 + } 1359 1379 writeln!( 1360 1380 formatter.labeled("modified"), 1361 1381 "{}{} {}", 1362 1382 diff_summary_char(&before), 1363 1383 diff_summary_char(&after), 1364 - path_converter.format_file_path(&repo_path) 1384 + path_converter.format_copied_path(&source, &target) 1365 1385 )?; 1366 1386 } 1367 1387 Ok(())
+6 -1
cli/tests/test_diff_command.rs
··· 70 70 71 71 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--types"]); 72 72 insta::assert_snapshot!(stdout, @r###" 73 + FF file2 74 + FF {file1 => file3} 75 + "###); 76 + 77 + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--types", "glob:file[12]"]); 78 + insta::assert_snapshot!(stdout, @r###" 73 79 F- file1 74 80 FF file2 75 - -F file3 76 81 "###); 77 82 78 83 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]);
+1 -2
cli/tests/test_show_command.rs
··· 123 123 124 124 (no description set) 125 125 126 - F- file1 127 126 FF file2 128 - -F file3 127 + FF {file1 => file3} 129 128 "###); 130 129 131 130 let stdout = test_env.jj_cmd_success(&repo_path, &["show", "--git"]);