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

cli: make diff stat determine path length in chars, not bytes

This commit is contained in:
Martin von Zweigbergk 2023-08-30 21:17:50 -07:00 committed by Martin von Zweigbergk
parent 0493e2b50e
commit 5ecc95a245
2 changed files with 12 additions and 12 deletions

View file

@ -785,7 +785,7 @@ pub fn show_diff_stat(
let path = workspace_command.format_file_path(&repo_path);
let left_content = diff_content(workspace_command.repo(), &repo_path, &left)?;
let right_content = diff_content(workspace_command.repo(), &repo_path, &right)?;
max_path_length = max(max_path_length, path.len());
max_path_length = max(max_path_length, path.chars().count());
let stat = get_diff_stat(path, &left_content, &right_content);
max_diffs = max(max_diffs, stat.added + stat.removed);
stats.push(stat);

View file

@ -805,51 +805,51 @@ fn test_diff_stat_long_name_or_stat() {
};
insta::assert_snapshot!(get_stat(&test_env, 1, 1), @r###"
| 1 +
| 1 +
1 file changed, 1 insertion(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 1, 10), @r###"
| 10 ++++++++++
| 10 ++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 1, 100), @r###"
| 100 +++++++++++++++++
| 100 +++++++++++++++++++
1 file changed, 100 insertions(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 10, 1), @r###"
| 1
| 1 +
1 file changed, 1 insertion(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
| 10
| 10 ++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 10, 100), @r###"
| 100
| 100 ++++++++++
1 file changed, 100 insertions(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 50, 1), @r###"
| 1
| 1
1 file changed, 1 insertion(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 50, 10), @r###"
| 10
| 10
1 file changed, 10 insertions(+), 0 deletions(-)
"###);
insta::assert_snapshot!(get_stat(&test_env, 50, 100), @r###"
| 100
| 100
1 file changed, 100 insertions(+), 0 deletions(-)
"###);
// Very narrow terminal (doesn't have to fit, just don't crash)
test_env.add_env_var("COLUMNS", "10");
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
| 10
| 10
1 file changed, 10 insertions(+), 0 deletions(-)
"###);
test_env.add_env_var("COLUMNS", "3");
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
| 10
| 10
1 file changed, 10 insertions(+), 0 deletions(-)
"###);
}