Merge pull request #3922 from pks-t/pks/diff-only-load-binaries-when-requested patch_generate: only calculate binary diffs if requested
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
diff --git a/src/patch_generate.c b/src/patch_generate.c
index 927786a..67a13b7 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -349,20 +349,24 @@ static int diff_binary(git_patch_generated_output *output, git_patch_generated *
new_len = patch->nfile.map.len;
int error;
- /* Create the old->new delta (as the "new" side of the patch),
- * and the new->old delta (as the "old" side)
- */
- if ((error = create_binary(&binary.old_file.type,
- (char **)&binary.old_file.data,
- &binary.old_file.datalen,
- &binary.old_file.inflatedlen,
- new_data, new_len, old_data, old_len)) < 0 ||
- (error = create_binary(&binary.new_file.type,
- (char **)&binary.new_file.data,
- &binary.new_file.datalen,
- &binary.new_file.inflatedlen,
- old_data, old_len, new_data, new_len)) < 0)
- return error;
+ /* Only load contents if the user actually wants to diff
+ * binary files. */
+ if (patch->base.diff_opts.flags & GIT_DIFF_SHOW_BINARY) {
+ /* Create the old->new delta (as the "new" side of the patch),
+ * and the new->old delta (as the "old" side)
+ */
+ if ((error = create_binary(&binary.old_file.type,
+ (char **)&binary.old_file.data,
+ &binary.old_file.datalen,
+ &binary.old_file.inflatedlen,
+ new_data, new_len, old_data, old_len)) < 0 ||
+ (error = create_binary(&binary.new_file.type,
+ (char **)&binary.new_file.data,
+ &binary.new_file.datalen,
+ &binary.new_file.inflatedlen,
+ old_data, old_len, new_data, new_len)) < 0)
+ return error;
+ }
error = giterr_set_after_callback_function(
output->binary_cb(patch->base.delta, &binary, output->payload),