Commit 853e585fb13475073c7000d74934f6c96c1e1a47

Edward Thomson 2016-04-25T16:32:30

patch: zero id and abbrev length for empty files

diff --git a/src/patch_parse.c b/src/patch_parse.c
index c5cf9fc..cdf4850 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -933,20 +933,32 @@ static int check_filenames(git_patch_parsed *patch)
 
 static int check_patch(git_patch_parsed *patch)
 {
+	git_diff_delta *delta = patch->base.delta;
+
 	if (check_filenames(patch) < 0)
 		return -1;
 
-	if (patch->base.delta->old_file.path &&
-			patch->base.delta->status != GIT_DELTA_DELETED &&
-			!patch->base.delta->new_file.mode)
-		patch->base.delta->new_file.mode = patch->base.delta->old_file.mode;
+	if (delta->old_file.path &&
+			delta->status != GIT_DELTA_DELETED &&
+			!delta->new_file.mode)
+		delta->new_file.mode = delta->old_file.mode;
 
-	if (patch->base.delta->status == GIT_DELTA_MODIFIED &&
-		!(patch->base.delta->flags & GIT_DIFF_FLAG_BINARY) &&
-		patch->base.delta->new_file.mode == patch->base.delta->old_file.mode &&
-		git_array_size(patch->base.hunks) == 0)
+	if (delta->status == GIT_DELTA_MODIFIED &&
+			!(delta->flags & GIT_DIFF_FLAG_BINARY) &&
+			delta->new_file.mode == delta->old_file.mode &&
+			git_array_size(patch->base.hunks) == 0)
 		return parse_err("patch with no hunks");
 
+	if (delta->status == GIT_DELTA_ADDED) {
+		memset(&delta->old_file.id, 0x0, sizeof(git_oid));
+		delta->old_file.id_abbrev = 0;
+	}
+
+	if (delta->status == GIT_DELTA_DELETED) {
+		memset(&delta->new_file.id, 0x0, sizeof(git_oid));
+		delta->new_file.id_abbrev = 0;
+	}
+
 	return 0;
 }