Skip to content

Commit b921964

Browse files
committed
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 parent accd784 commit b921964

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/git2/diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ typedef enum {
10931093
GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */
10941094
GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */
10951095
GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */
1096+
GIT_DIFF_FORMAT_PATCH_ID = 6u, /**< git diff as used by git patch-id */
10961097
} git_diff_format_t;
10971098

10981099
/**

src/diff_print.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ static int diff_print_patch_file(
571571
(pi->flags & GIT_DIFF_FORCE_BINARY);
572572
bool show_binary = !!(pi->flags & GIT_DIFF_SHOW_BINARY);
573573
int id_strlen = pi->id_strlen;
574-
bool print_index = true;
574+
bool print_index = (pi->format != GIT_DIFF_FORMAT_PATCH_ID);
575575

576576
if (binary && show_binary)
577577
id_strlen = delta->old_file.id_abbrev ? delta->old_file.id_abbrev :
@@ -677,6 +677,11 @@ int git_diff_print(
677677
print_hunk = diff_print_patch_hunk;
678678
print_line = diff_print_patch_line;
679679
break;
680+
case GIT_DIFF_FORMAT_PATCH_ID:
681+
print_file = diff_print_patch_file;
682+
print_binary = diff_print_patch_binary;
683+
print_line = diff_print_patch_line;
684+
break;
680685
case GIT_DIFF_FORMAT_PATCH_HEADER:
681686
print_file = diff_print_patch_file;
682687
break;

0 commit comments

Comments
 (0)