summaryrefslogtreecommitdiff
path: root/src/diff_print.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-09-02 02:03:45 -0500
committerEdward Thomson <ethomson@github.com>2016-09-05 12:26:47 -0500
commitadedac5aba9e4525475fd59d751cd02c6f2b3a4f (patch)
tree19fac5d44e30c3602909b9d971b26658545f2b7b /src/diff_print.c
parentf4e3dae75ff7246952f6707ad2a2fdea758e03ea (diff)
downloadlibgit2-ethomson/diff-read-empty-binary.tar.gz
diff: treat binary patches with no data specialethomson/diff-read-empty-binary
When creating and printing diffs, deal with binary deltas that have binary data specially, versus diffs that have a binary file but lack the actual binary data.
Diffstat (limited to 'src/diff_print.c')
-rw-r--r--src/diff_print.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 264bd19e9..fd1a186c1 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -500,7 +500,6 @@ static int diff_print_patch_file_binary_noshow(
&new_path, new_pfx, delta->new_file.path)) < 0)
goto done;
-
pi->line.num_lines = 1;
error = diff_delta_format_with_paths(
pi->buf, delta, "Binary files %s and %s differ\n",
@@ -524,7 +523,7 @@ static int diff_print_patch_file_binary(
if (delta->status == GIT_DELTA_UNMODIFIED)
return 0;
- if ((pi->flags & GIT_DIFF_SHOW_BINARY) == 0)
+ if ((pi->flags & GIT_DIFF_SHOW_BINARY) == 0 || !binary->contains_data)
return diff_print_patch_file_binary_noshow(
pi, delta, old_pfx, new_pfx);
@@ -563,8 +562,11 @@ static int diff_print_patch_file(
bool binary = (delta->flags & GIT_DIFF_FLAG_BINARY) ||
(pi->flags & GIT_DIFF_FORCE_BINARY);
bool show_binary = !!(pi->flags & GIT_DIFF_SHOW_BINARY);
- int id_strlen = binary && show_binary ?
- GIT_OID_HEXSZ : pi->id_strlen;
+ int id_strlen = pi->id_strlen;
+
+ if (binary && show_binary)
+ id_strlen = delta->old_file.id_abbrev ? delta->old_file.id_abbrev :
+ delta->new_file.id_abbrev;
GIT_UNUSED(progress);