diff_print: add support for GIT_DIFF_FORMAT_PATCH_ID. Git is generating patch-id using a stripped down version of a patch where hunk header and index information are not present. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
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
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 73c5e55..89733a7 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -1093,6 +1093,7 @@ typedef enum {
GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */
GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */
GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */
+ GIT_DIFF_FORMAT_PATCH_ID = 6u, /**< git diff as used by git patch-id */
} git_diff_format_t;
/**
diff --git a/src/diff_print.c b/src/diff_print.c
index 4124bcb..369e5c1 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -571,7 +571,7 @@ static int diff_print_patch_file(
(pi->flags & GIT_DIFF_FORCE_BINARY);
bool show_binary = !!(pi->flags & GIT_DIFF_SHOW_BINARY);
int id_strlen = pi->id_strlen;
- bool print_index = true;
+ bool print_index = (pi->format != GIT_DIFF_FORMAT_PATCH_ID);
if (binary && show_binary)
id_strlen = delta->old_file.id_abbrev ? delta->old_file.id_abbrev :
@@ -677,6 +677,11 @@ int git_diff_print(
print_hunk = diff_print_patch_hunk;
print_line = diff_print_patch_line;
break;
+ case GIT_DIFF_FORMAT_PATCH_ID:
+ print_file = diff_print_patch_file;
+ print_binary = diff_print_patch_binary;
+ print_line = diff_print_patch_line;
+ break;
case GIT_DIFF_FORMAT_PATCH_HEADER:
print_file = diff_print_patch_file;
break;