patch: show modes when only the mode has changed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/src/diff_print.c b/src/diff_print.c
index 93c887b..32283d5 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -258,6 +258,15 @@ static int diff_print_one_raw(
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(
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",
start_oid, end_oid, delta->old_file.mode);
} 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);
- } 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);
- } else {
- git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
- git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
- }
+ else
+ diff_print_modes(out, delta);
+
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);
}
-
static int diff_delta_format_with_paths(
git_buf *out,
const git_diff_delta *delta,
@@ -371,7 +378,7 @@ int git_diff_delta__format_file_header(
int oid_strlen)
{
git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_INIT;
- bool skip_index;
+ bool unchanged;
int error = 0;
if (!oldpfx)
@@ -397,12 +404,10 @@ int git_diff_delta__format_file_header(
goto done;
}
- skip_index = (delta->status == GIT_DELTA_RENAMED &&
- delta->similarity == 100 &&
- delta->old_file.mode == 0 &&
- delta->new_file.mode == 0);
+ unchanged = (git_oid_iszero(&delta->old_file.id) &&
+ git_oid_iszero(&delta->new_file.id));
- if (!skip_index) {
+ if (!unchanged) {
if ((error = diff_print_oid_range(out, delta, oid_strlen)) < 0)
goto done;
@@ -411,6 +416,9 @@ int git_diff_delta__format_file_header(
"--- %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))
error = -1;