Unverified Commit 0cd976c8 by Edward Thomson Committed by GitHub

Merge pull request #4830 from pks-t/pks/diff-stats-rename-common

diff_stats: use git's formatting of renames with common directories
parents 0c973356 e5090ee3
......@@ -61,15 +61,29 @@ int git_diff_file_stats__full_to_buf(
old_size = delta->old_file.size;
new_size = delta->new_file.size;
if (git_buf_printf(out, " %s", old_path) < 0)
goto on_error;
if (strcmp(old_path, new_path) != 0) {
size_t common_dirlen;
int error;
padding = stats->max_name - strlen(old_path) - strlen(new_path);
if (git_buf_printf(out, DIFF_RENAME_FILE_SEPARATOR "%s", new_path) < 0)
if ((common_dirlen = git_path_common_dirlen(old_path, new_path)) &&
common_dirlen <= INT_MAX) {
error = git_buf_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}",
(int) common_dirlen, old_path,
old_path + common_dirlen,
new_path + common_dirlen);
} else {
error = git_buf_printf(out, " %s" DIFF_RENAME_FILE_SEPARATOR "%s",
old_path, new_path);
}
if (error < 0)
goto on_error;
} else {
if (git_buf_printf(out, " %s", old_path) < 0)
goto on_error;
padding = stats->max_name - strlen(old_path);
if (stats->renames > 0)
......
......@@ -210,6 +210,25 @@ void test_diff_stats__rename_and_modifiy(void)
git_buf_dispose(&buf);
}
void test_diff_stats__rename_in_subdirectory(void)
{
git_buf buf = GIT_BUF_INIT;
const char *stat =
" dir/{orig.txt => renamed.txt} | 0\n"
" 1 file changed, 0 insertions(+), 0 deletions(-)\n";
diff_stats_from_commit_oid(
&_stats, "0db2a262bc8c5c3cba55254730045a8258da7a37", true);
cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
cl_assert_equal_s(stat, git_buf_cstr(&buf));
git_buf_dispose(&buf);
}
void test_diff_stats__rename_no_find(void)
{
git_buf buf = GIT_BUF_INIT;
......
5219b9784f9a92d7bd7cb567a6d6a21bfb86697e
0db2a262bc8c5c3cba55254730045a8258da7a37
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment