Skip to content

Commit

Permalink
diff_util: add copy records tracking to DiffRenderer::show_patch
Browse files Browse the repository at this point in the history
This allow `jj show --summary` and other commands to include copy
tracking information.
  • Loading branch information
bnjmnt4n committed Aug 14, 2024
1 parent f983021 commit 41e99cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 9 additions & 1 deletion cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,21 @@ impl<'a> DiffRenderer<'a> {
) -> Result<(), DiffRenderError> {
let from_tree = commit.parent_tree(self.repo)?;
let to_tree = commit.tree()?;
let mut copy_records = CopyRecords::default();
for parent_id in commit.parent_ids() {
copy_records.add_records(self.repo.store().get_copy_records(
None,
parent_id,
commit.id(),
)?)?;
}
self.show_diff(
ui,
formatter,
&from_tree,
&to_tree,
matcher,
&Default::default(),
&copy_records,
width,
)
}
Expand Down
22 changes: 8 additions & 14 deletions cli/tests/test_show_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ fn test_show_basic() {
1 1: foo
2: bar
2 3: baz quxquux
Added regular file file3:
1: foo
Modified regular file file3 (file1 => file3):
"###);

let stdout = test_env.jj_cmd_success(&repo_path, &["show", "--context=0"]);
Expand All @@ -81,8 +80,7 @@ fn test_show_basic() {
1 1: foo
2: bar
2 3: baz quxquux
Added regular file file3:
1: foo
Modified regular file file3 (file1 => file3):
"###);

let stdout = test_env.jj_cmd_success(&repo_path, &["show", "--color=debug"]);
Expand All @@ -100,8 +98,7 @@ fn test_show_basic() {
<<diff removed line_number:: 1>><<diff:: >><<diff added line_number:: 1>><<diff::: foo>>
<<diff:: >><<diff added line_number:: 2>><<diff::: >><<diff added token::bar>>
<<diff removed line_number:: 2>><<diff:: >><<diff added line_number:: 3>><<diff::: baz >><<diff removed token::qux>><<diff added token::quux>><<diff::>>
<<diff header::Added regular file file3:>>
<<diff:: >><<diff added line_number:: 1>><<diff::: >><<diff added token::foo>>
<<diff header::Modified regular file file3 (file1 => file3):>>
"###);

let stdout = test_env.jj_cmd_success(&repo_path, &["show", "-s"]);
Expand All @@ -113,9 +110,8 @@ fn test_show_basic() {
(no description set)
D file1
M file2
A file3
R {file1 => file3}
"###);

let stdout = test_env.jj_cmd_success(&repo_path, &["show", "--types"]);
Expand Down Expand Up @@ -242,9 +238,8 @@ fn test_show_basic() {
(no description set)
D file1
M file2
A file3
R {file1 => file3}
diff --git a/file1 b/file1
deleted file mode 100644
index 257cc5642c..0000000000
Expand Down Expand Up @@ -279,10 +274,9 @@ fn test_show_basic() {
(no description set)
file1 | 1 -
file2 | 3 ++-
file3 | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
file2 | 3 ++-
{file1 => file3} | 0
2 files changed, 2 insertions(+), 1 deletion(-)
"###);
}

Expand Down

0 comments on commit 41e99cc

Please sign in to comment.