patch: show modes when only the mode has changed

This commit is contained in:
Edward Thomson 2015-09-23 17:48:52 -04:00 committed by Edward Thomson
parent 4ac2d8acf4
commit e2cdc145b9

View File

@ -258,6 +258,15 @@ static int diff_print_one_raw(
return pi->print_cb(delta, NULL, &pi->line, pi->payload); return pi->print_cb(delta, NULL, &pi->line, pi->payload);
} }
static int diff_print_modes(
git_buf *out, const git_diff_delta *delta)
{
git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
return git_buf_oom(out) ? -1 : 0;
}
static int diff_print_oid_range( static int diff_print_oid_range(
git_buf *out, const git_diff_delta *delta, int oid_strlen) git_buf *out, const git_diff_delta *delta, int oid_strlen)
{ {
@ -286,14 +295,13 @@ static int diff_print_oid_range(
git_buf_printf(out, "index %s..%s %o\n", git_buf_printf(out, "index %s..%s %o\n",
start_oid, end_oid, delta->old_file.mode); start_oid, end_oid, delta->old_file.mode);
} else { } else {
if (delta->old_file.mode == 0) { if (delta->old_file.mode == 0)
git_buf_printf(out, "new file mode %o\n", delta->new_file.mode); git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
} else if (delta->new_file.mode == 0) { else if (delta->new_file.mode == 0)
git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode); git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
} else { else
git_buf_printf(out, "old mode %o\n", delta->old_file.mode); diff_print_modes(out, delta);
git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
}
git_buf_printf(out, "index %s..%s\n", start_oid, end_oid); git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
} }
@ -309,7 +317,6 @@ static int diff_delta_format_path(
return git_buf_quote(out); return git_buf_quote(out);
} }
static int diff_delta_format_with_paths( static int diff_delta_format_with_paths(
git_buf *out, git_buf *out,
const git_diff_delta *delta, const git_diff_delta *delta,
@ -371,7 +378,7 @@ int git_diff_delta__format_file_header(
int oid_strlen) int oid_strlen)
{ {
git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT; git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
bool skip_index; bool unchanged;
int error = 0; int error = 0;
if (!oldpfx) if (!oldpfx)
@ -397,12 +404,10 @@ int git_diff_delta__format_file_header(
goto done; goto done;
} }
skip_index = (delta->status == GIT_DELTA_RENAMED && unchanged = (git_oid_iszero(&delta->old_file.id) &&
delta->similarity == 100 && git_oid_iszero(&delta->new_file.id));
delta->old_file.mode == 0 &&
delta->new_file.mode == 0);
if (!skip_index) { if (!unchanged) {
if ((error = diff_print_oid_range(out, delta, oid_strlen)) < 0) if ((error = diff_print_oid_range(out, delta, oid_strlen)) < 0)
goto done; goto done;
@ -411,6 +416,9 @@ int git_diff_delta__format_file_header(
"--- %s\n+++ %s\n", old_path.ptr, new_path.ptr); "--- %s\n+++ %s\n", old_path.ptr, new_path.ptr);
} }
if (unchanged && delta->old_file.mode != delta->new_file.mode)
diff_print_modes(out, delta);
if (git_buf_oom(out)) if (git_buf_oom(out))
error = -1; error = -1;