ok/jj
1
0
Fork 0
forked from mirrors/jj

templater: integrate copy tracking in commit.diff() template

This commit is contained in:
Yuya Nishihara 2024-08-24 11:09:01 +09:00
parent b78c83e9fe
commit 8d166c7642
2 changed files with 40 additions and 10 deletions

View file

@ -1311,11 +1311,17 @@ impl TreeDiff {
commit: &Commit, commit: &Commit,
matcher: Rc<dyn Matcher>, matcher: Rc<dyn Matcher>,
) -> BackendResult<Self> { ) -> BackendResult<Self> {
let mut copy_records = CopyRecords::default();
for parent in commit.parent_ids() {
let records =
diff_util::get_copy_records(repo.store(), parent, commit.id(), &*matcher)?;
copy_records.add_records(records)?;
}
Ok(TreeDiff { Ok(TreeDiff {
from_tree: commit.parent_tree(repo)?, from_tree: commit.parent_tree(repo)?,
to_tree: commit.tree()?, to_tree: commit.tree()?,
matcher, matcher,
copy_records: Default::default(), // TODO: real copy tracking copy_records,
}) })
} }

View file

@ -951,9 +951,15 @@ fn test_log_diff_predefined_formats() {
std::fs::write(repo_path.join("file1"), "a\nb\n").unwrap(); std::fs::write(repo_path.join("file1"), "a\nb\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap(); std::fs::write(repo_path.join("file2"), "a\n").unwrap();
std::fs::write(repo_path.join("rename-source"), "rename").unwrap();
test_env.jj_cmd_ok(&repo_path, &["new"]); test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "a\nb\nc\n").unwrap(); std::fs::write(repo_path.join("file1"), "a\nb\nc\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\nc\n").unwrap(); std::fs::write(repo_path.join("file2"), "b\nc\n").unwrap();
std::fs::rename(
repo_path.join("rename-source"),
repo_path.join("rename-target"),
)
.unwrap();
let template = r#" let template = r#"
concat( concat(
@ -982,6 +988,7 @@ fn test_log_diff_predefined_formats() {
Modified regular file file2: Modified regular file file2:
 1  1: ab  1  1: ab
 2: c  2: c
Modified regular file rename-target (rename-source => rename-target):
=== git === === git ===
diff --git a/file1 b/file1 diff --git a/file1 b/file1
index 422c2b7ab3..de980441c3 100644 index 422c2b7ab3..de980441c3 100644
@ -999,13 +1006,18 @@ fn test_log_diff_predefined_formats() {
-a -a
+b +b
+c +c
diff --git a/rename-source b/rename-target
rename from rename-source
rename to rename-target
=== stat === === stat ===
file1 | 1 + file1 | 1 +
file2 | 3 ++- file2 | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-) {rename-source => rename-target} | 0
3 files changed, 3 insertions(+), 1 deletion(-)
=== summary === === summary ===
M file1 M file1
M file2 M file2
R {rename-source => rename-target}
"###); "###);
// color labels // color labels
@ -1022,6 +1034,7 @@ fn test_log_diff_predefined_formats() {
<<log diff color_words header::Modified regular file file2:>> <<log diff color_words header::Modified regular file file2:>>
<<log diff color_words removed line_number:: 1>><<log diff color_words:: >><<log diff color_words added line_number:: 1>><<log diff color_words::: >><<log diff color_words removed token::a>><<log diff color_words added token::b>><<log diff color_words::>> <<log diff color_words removed line_number:: 1>><<log diff color_words:: >><<log diff color_words added line_number:: 1>><<log diff color_words::: >><<log diff color_words removed token::a>><<log diff color_words added token::b>><<log diff color_words::>>
<<log diff color_words:: >><<log diff color_words added line_number:: 2>><<log diff color_words::: >><<log diff color_words added token::c>> <<log diff color_words:: >><<log diff color_words added line_number:: 2>><<log diff color_words::: >><<log diff color_words added token::c>>
<<log diff color_words header::Modified regular file rename-target (rename-source => rename-target):>>
<<log::=== git ===>> <<log::=== git ===>>
<<log diff git file_header::diff --git a/file1 b/file1>> <<log diff git file_header::diff --git a/file1 b/file1>>
<<log diff git file_header::index 422c2b7ab3..de980441c3 100644>> <<log diff git file_header::index 422c2b7ab3..de980441c3 100644>>
@ -1039,13 +1052,18 @@ fn test_log_diff_predefined_formats() {
<<log diff git removed::->><<log diff git removed token::a>><<log diff git removed::>> <<log diff git removed::->><<log diff git removed token::a>><<log diff git removed::>>
<<log diff git added::+>><<log diff git added token::b>><<log diff git added::>> <<log diff git added::+>><<log diff git added token::b>><<log diff git added::>>
<<log diff git added::+>><<log diff git added token::c>> <<log diff git added::+>><<log diff git added token::c>>
<<log diff git file_header::diff --git a/rename-source b/rename-target>>
<<log diff git file_header::rename from rename-source>>
<<log diff git file_header::rename to rename-target>>
<<log::=== stat ===>> <<log::=== stat ===>>
<<log diff stat::file1 | 1 >><<log diff stat added::+>><<log diff stat removed::>> <<log diff stat::file1 | 1 >><<log diff stat added::+>><<log diff stat removed::>>
<<log diff stat::file2 | 3 >><<log diff stat added::++>><<log diff stat removed::->> <<log diff stat::file2 | 3 >><<log diff stat added::++>><<log diff stat removed::->>
<<log diff stat stat-summary::2 files changed, 3 insertions(+), 1 deletion(-)>> <<log diff stat::{rename-source => rename-target} | 0>><<log diff stat removed::>>
<<log diff stat stat-summary::3 files changed, 3 insertions(+), 1 deletion(-)>>
<<log::=== summary ===>> <<log::=== summary ===>>
<<log diff summary modified::M file1>> <<log diff summary modified::M file1>>
<<log diff summary modified::M file2>> <<log diff summary modified::M file2>>
<<log diff summary renamed::R {rename-source => rename-target}>>
"###); "###);
// cwd != workspace root // cwd != workspace root
@ -1062,6 +1080,7 @@ fn test_log_diff_predefined_formats() {
Modified regular file repo/file2: Modified regular file repo/file2:
1 1: ab 1 1: ab
2: c 2: c
Modified regular file repo/rename-target (repo/rename-source => repo/rename-target):
=== git === === git ===
diff --git a/file1 b/file1 diff --git a/file1 b/file1
index 422c2b7ab3..de980441c3 100644 index 422c2b7ab3..de980441c3 100644
@ -1079,13 +1098,18 @@ fn test_log_diff_predefined_formats() {
-a -a
+b +b
+c +c
diff --git a/rename-source b/rename-target
rename from rename-source
rename to rename-target
=== stat === === stat ===
repo/file1 | 1 + repo/file1 | 1 +
repo/file2 | 3 ++- repo/file2 | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-) repo/{rename-source => rename-target} | 0
3 files changed, 3 insertions(+), 1 deletion(-)
=== summary === === summary ===
M repo/file1 M repo/file1
M repo/file2 M repo/file2
R repo/{rename-source => rename-target}
"###); "###);
// color_words() with parameters // color_words() with parameters