summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-09-23 17:48:52 -0400
committerEdward Thomson <ethomson@github.com>2016-05-26 13:01:06 -0500
commite2cdc145b9633ed0f7fcfdeed5eb4a7fc65653ae (patch)
tree3d578d945f0caa97ae41e70851afaafbf6dc9444
parent4ac2d8acf4e76384ffaa84d4152333a71051f3c3 (diff)
downloadlibgit2-e2cdc145b9633ed0f7fcfdeed5eb4a7fc65653ae.tar.gz
patch: show modes when only the mode has changed
-rw-r--r--src/diff_print.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 93c887bf5..32283d52b 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;