summaryrefslogtreecommitdiff
path: root/src/patch_generate.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/patch_generate.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/patch_generate.c')
-rw-r--r--src/patch_generate.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/patch_generate.c b/src/patch_generate.c
index 67a13b706..a13f2ff5d 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -342,7 +342,7 @@ done:
static int diff_binary(git_patch_generated_output *output, git_patch_generated *patch)
{
- git_diff_binary binary = {{0}};
+ git_diff_binary binary = {0};
const char *old_data = patch->ofile.map.data;
const char *new_data = patch->nfile.map.data;
size_t old_len = patch->ofile.map.len,
@@ -352,6 +352,8 @@ static int diff_binary(git_patch_generated_output *output, git_patch_generated *
/* Only load contents if the user actually wants to diff
* binary files. */
if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) {
+ binary.contains_data = 1;
+
/* Create the old->new delta (as the "new" side of the patch),
* and the new->old delta (as the "old" side)
*/
@@ -492,8 +494,17 @@ static int diff_single_generate(patch_generated_with_delta *pd, git_xdiff_output
patch_generated_init_common(patch);
if (pd->delta.status == GIT_DELTA_UNMODIFIED &&
- !(patch->ofile.opts_flags & GIT_DIFF_INCLUDE_UNMODIFIED))
+ !(patch->ofile.opts_flags & GIT_DIFF_INCLUDE_UNMODIFIED)) {
+
+ /* Even empty patches are flagged as binary, and even though
+ * there's no difference, we flag this as "containing data"
+ * (the data is known to be empty, as opposed to wholly unknown).
+ */
+ if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY)
+ patch->base.binary.contains_data = 1;
+
return error;
+ }
error = patch_generated_invoke_file_callback(patch, (git_patch_generated_output *)xo);