2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
10 #include "patch_generate.h"
15 #include "git2/sys/diff.h"
18 git_diff_format_t format
;
19 git_diff_line_cb print_cb
;
25 const char *old_prefix
;
26 const char *new_prefix
;
30 int (*strcomp
)(const char *, const char *);
33 static int diff_print_info_init__common(
37 git_diff_format_t format
,
43 pi
->payload
= payload
;
48 pi
->id_strlen
= GIT_ABBREV_DEFAULT
;
49 else if (git_repository__cvar(&pi
->id_strlen
, repo
, GIT_CVAR_ABBREV
) < 0)
53 if (pi
->id_strlen
> GIT_OID_HEXSZ
)
54 pi
->id_strlen
= GIT_OID_HEXSZ
;
56 memset(&pi
->line
, 0, sizeof(pi
->line
));
57 pi
->line
.old_lineno
= -1;
58 pi
->line
.new_lineno
= -1;
59 pi
->line
.num_lines
= 1;
64 static int diff_print_info_init_fromdiff(
68 git_diff_format_t format
,
72 git_repository
*repo
= diff
? diff
->repo
: NULL
;
74 memset(pi
, 0, sizeof(diff_print_info
));
77 pi
->flags
= diff
->opts
.flags
;
78 pi
->id_strlen
= diff
->opts
.id_abbrev
;
79 pi
->old_prefix
= diff
->opts
.old_prefix
;
80 pi
->new_prefix
= diff
->opts
.new_prefix
;
82 pi
->strcomp
= diff
->strcomp
;
85 return diff_print_info_init__common(pi
, out
, repo
, format
, cb
, payload
);
88 static int diff_print_info_init_frompatch(
92 git_diff_format_t format
,
98 memset(pi
, 0, sizeof(diff_print_info
));
100 pi
->flags
= patch
->diff_opts
.flags
;
101 pi
->id_strlen
= patch
->diff_opts
.id_abbrev
;
102 pi
->old_prefix
= patch
->diff_opts
.old_prefix
;
103 pi
->new_prefix
= patch
->diff_opts
.new_prefix
;
105 return diff_print_info_init__common(pi
, out
, patch
->repo
, format
, cb
, payload
);
108 static char diff_pick_suffix(int mode
)
112 else if (GIT_PERMS_IS_EXEC(mode
)) /* -V536 */
113 /* in git, modes are very regular, so we must have 0100755 mode */
119 char git_diff_status_char(git_delta_t status
)
124 case GIT_DELTA_ADDED
: code
= 'A'; break;
125 case GIT_DELTA_DELETED
: code
= 'D'; break;
126 case GIT_DELTA_MODIFIED
: code
= 'M'; break;
127 case GIT_DELTA_RENAMED
: code
= 'R'; break;
128 case GIT_DELTA_COPIED
: code
= 'C'; break;
129 case GIT_DELTA_IGNORED
: code
= 'I'; break;
130 case GIT_DELTA_UNTRACKED
: code
= '?'; break;
131 case GIT_DELTA_UNREADABLE
: code
= 'X'; break;
132 default: code
= ' '; break;
138 static int diff_print_one_name_only(
139 const git_diff_delta
*delta
, float progress
, void *data
)
141 diff_print_info
*pi
= data
;
142 git_buf
*out
= pi
->buf
;
144 GIT_UNUSED(progress
);
146 if ((pi
->flags
& GIT_DIFF_SHOW_UNMODIFIED
) == 0 &&
147 delta
->status
== GIT_DELTA_UNMODIFIED
)
151 git_buf_puts(out
, delta
->new_file
.path
);
152 git_buf_putc(out
, '\n');
153 if (git_buf_oom(out
))
156 pi
->line
.origin
= GIT_DIFF_LINE_FILE_HDR
;
157 pi
->line
.content
= git_buf_cstr(out
);
158 pi
->line
.content_len
= git_buf_len(out
);
160 return pi
->print_cb(delta
, NULL
, &pi
->line
, pi
->payload
);
163 static int diff_print_one_name_status(
164 const git_diff_delta
*delta
, float progress
, void *data
)
166 diff_print_info
*pi
= data
;
167 git_buf
*out
= pi
->buf
;
168 char old_suffix
, new_suffix
, code
= git_diff_status_char(delta
->status
);
169 int(*strcomp
)(const char *, const char *) = pi
->strcomp
?
170 pi
->strcomp
: git__strcmp
;
172 GIT_UNUSED(progress
);
174 if ((pi
->flags
& GIT_DIFF_SHOW_UNMODIFIED
) == 0 && code
== ' ')
177 old_suffix
= diff_pick_suffix(delta
->old_file
.mode
);
178 new_suffix
= diff_pick_suffix(delta
->new_file
.mode
);
182 if (delta
->old_file
.path
!= delta
->new_file
.path
&&
183 strcomp(delta
->old_file
.path
,delta
->new_file
.path
) != 0)
184 git_buf_printf(out
, "%c\t%s%c %s%c\n", code
,
185 delta
->old_file
.path
, old_suffix
, delta
->new_file
.path
, new_suffix
);
186 else if (delta
->old_file
.mode
!= delta
->new_file
.mode
&&
187 delta
->old_file
.mode
!= 0 && delta
->new_file
.mode
!= 0)
188 git_buf_printf(out
, "%c\t%s%c %s%c\n", code
,
189 delta
->old_file
.path
, old_suffix
, delta
->new_file
.path
, new_suffix
);
190 else if (old_suffix
!= ' ')
191 git_buf_printf(out
, "%c\t%s%c\n", code
, delta
->old_file
.path
, old_suffix
);
193 git_buf_printf(out
, "%c\t%s\n", code
, delta
->old_file
.path
);
194 if (git_buf_oom(out
))
197 pi
->line
.origin
= GIT_DIFF_LINE_FILE_HDR
;
198 pi
->line
.content
= git_buf_cstr(out
);
199 pi
->line
.content_len
= git_buf_len(out
);
201 return pi
->print_cb(delta
, NULL
, &pi
->line
, pi
->payload
);
204 static int diff_print_one_raw(
205 const git_diff_delta
*delta
, float progress
, void *data
)
207 diff_print_info
*pi
= data
;
208 git_buf
*out
= pi
->buf
;
210 char code
= git_diff_status_char(delta
->status
);
211 char start_oid
[GIT_OID_HEXSZ
+1], end_oid
[GIT_OID_HEXSZ
+1];
213 GIT_UNUSED(progress
);
215 if ((pi
->flags
& GIT_DIFF_SHOW_UNMODIFIED
) == 0 && code
== ' ')
220 id_abbrev
= delta
->old_file
.mode
? delta
->old_file
.id_abbrev
:
221 delta
->new_file
.id_abbrev
;
223 if (pi
->id_strlen
> id_abbrev
) {
224 giterr_set(GITERR_PATCH
,
225 "the patch input contains %d id characters (cannot print %d)",
226 id_abbrev
, pi
->id_strlen
);
230 git_oid_tostr(start_oid
, pi
->id_strlen
+ 1, &delta
->old_file
.id
);
231 git_oid_tostr(end_oid
, pi
->id_strlen
+ 1, &delta
->new_file
.id
);
234 out
, (pi
->id_strlen
<= GIT_OID_HEXSZ
) ?
235 ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
236 delta
->old_file
.mode
, delta
->new_file
.mode
, start_oid
, end_oid
, code
);
238 if (delta
->similarity
> 0)
239 git_buf_printf(out
, "%03u", delta
->similarity
);
241 if (delta
->old_file
.path
!= delta
->new_file
.path
)
243 out
, "\t%s %s\n", delta
->old_file
.path
, delta
->new_file
.path
);
246 out
, "\t%s\n", delta
->old_file
.path
?
247 delta
->old_file
.path
: delta
->new_file
.path
);
249 if (git_buf_oom(out
))
252 pi
->line
.origin
= GIT_DIFF_LINE_FILE_HDR
;
253 pi
->line
.content
= git_buf_cstr(out
);
254 pi
->line
.content_len
= git_buf_len(out
);
256 return pi
->print_cb(delta
, NULL
, &pi
->line
, pi
->payload
);
259 static int diff_print_modes(
260 git_buf
*out
, const git_diff_delta
*delta
)
262 git_buf_printf(out
, "old mode %o\n", delta
->old_file
.mode
);
263 git_buf_printf(out
, "new mode %o\n", delta
->new_file
.mode
);
265 return git_buf_oom(out
) ? -1 : 0;
268 static int diff_print_oid_range(
269 git_buf
*out
, const git_diff_delta
*delta
, int id_strlen
)
271 char start_oid
[GIT_OID_HEXSZ
+1], end_oid
[GIT_OID_HEXSZ
+1];
273 if (delta
->old_file
.mode
&&
274 id_strlen
> delta
->old_file
.id_abbrev
) {
275 giterr_set(GITERR_PATCH
,
276 "the patch input contains %d id characters (cannot print %d)",
277 delta
->old_file
.id_abbrev
, id_strlen
);
281 if ((delta
->new_file
.mode
&&
282 id_strlen
> delta
->new_file
.id_abbrev
)) {
283 giterr_set(GITERR_PATCH
,
284 "the patch input contains %d id characters (cannot print %d)",
285 delta
->new_file
.id_abbrev
, id_strlen
);
289 git_oid_tostr(start_oid
, id_strlen
+ 1, &delta
->old_file
.id
);
290 git_oid_tostr(end_oid
, id_strlen
+ 1, &delta
->new_file
.id
);
292 if (delta
->old_file
.mode
== delta
->new_file
.mode
) {
293 git_buf_printf(out
, "index %s..%s %o\n",
294 start_oid
, end_oid
, delta
->old_file
.mode
);
296 if (delta
->old_file
.mode
== 0)
297 git_buf_printf(out
, "new file mode %o\n", delta
->new_file
.mode
);
298 else if (delta
->new_file
.mode
== 0)
299 git_buf_printf(out
, "deleted file mode %o\n", delta
->old_file
.mode
);
301 diff_print_modes(out
, delta
);
303 git_buf_printf(out
, "index %s..%s\n", start_oid
, end_oid
);
306 return git_buf_oom(out
) ? -1 : 0;
309 static int diff_delta_format_path(
310 git_buf
*out
, const char *prefix
, const char *filename
)
312 if (git_buf_joinpath(out
, prefix
, filename
) < 0)
315 return git_buf_quote(out
);
318 static int diff_delta_format_with_paths(
320 const git_diff_delta
*delta
,
321 const char *template,
325 if (git_oid_iszero(&delta
->old_file
.id
))
326 oldpath
= "/dev/null";
328 if (git_oid_iszero(&delta
->new_file
.id
))
329 newpath
= "/dev/null";
331 return git_buf_printf(out
, template, oldpath
, newpath
);
334 int diff_delta_format_similarity_header(
336 const git_diff_delta
*delta
)
338 git_buf old_path
= GIT_BUF_INIT
, new_path
= GIT_BUF_INIT
;
342 if (delta
->similarity
> 100) {
343 giterr_set(GITERR_PATCH
, "invalid similarity %d", delta
->similarity
);
348 if (delta
->status
== GIT_DELTA_RENAMED
)
350 else if (delta
->status
== GIT_DELTA_COPIED
)
355 if ((error
= git_buf_puts(&old_path
, delta
->old_file
.path
)) < 0 ||
356 (error
= git_buf_puts(&new_path
, delta
->new_file
.path
)) < 0 ||
357 (error
= git_buf_quote(&old_path
)) < 0 ||
358 (error
= git_buf_quote(&new_path
)) < 0)
362 "similarity index %d%%\n"
369 if (git_buf_oom(out
))
373 git_buf_free(&old_path
);
374 git_buf_free(&new_path
);
379 static bool delta_is_unchanged(const git_diff_delta
*delta
)
381 if (git_oid_iszero(&delta
->old_file
.id
) &&
382 git_oid_iszero(&delta
->new_file
.id
))
385 if (delta
->old_file
.mode
== GIT_FILEMODE_COMMIT
||
386 delta
->new_file
.mode
== GIT_FILEMODE_COMMIT
)
389 if (git_oid_equal(&delta
->old_file
.id
, &delta
->new_file
.id
))
395 int git_diff_delta__format_file_header(
397 const git_diff_delta
*delta
,
402 git_buf old_path
= GIT_BUF_INIT
, new_path
= GIT_BUF_INIT
;
403 bool unchanged
= delta_is_unchanged(delta
);
407 oldpfx
= DIFF_OLD_PREFIX_DEFAULT
;
409 newpfx
= DIFF_NEW_PREFIX_DEFAULT
;
411 id_strlen
= GIT_ABBREV_DEFAULT
;
413 if ((error
= diff_delta_format_path(
414 &old_path
, oldpfx
, delta
->old_file
.path
)) < 0 ||
415 (error
= diff_delta_format_path(
416 &new_path
, newpfx
, delta
->new_file
.path
)) < 0)
421 git_buf_printf(out
, "diff --git %s %s\n",
422 old_path
.ptr
, new_path
.ptr
);
424 if (delta
->status
== GIT_DELTA_RENAMED
||
425 (delta
->status
== GIT_DELTA_COPIED
&& unchanged
)) {
426 if ((error
= diff_delta_format_similarity_header(out
, delta
)) < 0)
431 if ((error
= diff_print_oid_range(out
, delta
, id_strlen
)) < 0)
434 if ((delta
->flags
& GIT_DIFF_FLAG_BINARY
) == 0)
435 diff_delta_format_with_paths(out
, delta
,
436 "--- %s\n+++ %s\n", old_path
.ptr
, new_path
.ptr
);
439 if (unchanged
&& delta
->old_file
.mode
!= delta
->new_file
.mode
)
440 diff_print_modes(out
, delta
);
442 if (git_buf_oom(out
))
446 git_buf_free(&old_path
);
447 git_buf_free(&new_path
);
452 static int format_binary(
454 git_diff_binary_t type
,
459 const char *typename
= type
== GIT_DIFF_BINARY_DELTA
?
461 const char *scan
, *end
;
463 git_buf_printf(pi
->buf
, "%s %" PRIuZ
"\n", typename
, inflatedlen
);
464 pi
->line
.num_lines
++;
466 for (scan
= data
, end
= data
+ datalen
; scan
< end
; ) {
467 size_t chunk_len
= end
- scan
;
472 git_buf_putc(pi
->buf
, (char)chunk_len
+ 'A' - 1);
474 git_buf_putc(pi
->buf
, (char)chunk_len
- 26 + 'a' - 1);
476 git_buf_encode_base85(pi
->buf
, scan
, chunk_len
);
477 git_buf_putc(pi
->buf
, '\n');
479 if (git_buf_oom(pi
->buf
))
483 pi
->line
.num_lines
++;
485 git_buf_putc(pi
->buf
, '\n');
490 static int diff_print_patch_file_binary_noshow(
491 diff_print_info
*pi
, git_diff_delta
*delta
,
492 const char *old_pfx
, const char *new_pfx
)
494 git_buf old_path
= GIT_BUF_INIT
, new_path
= GIT_BUF_INIT
;
497 if ((error
= diff_delta_format_path(
498 &old_path
, old_pfx
, delta
->old_file
.path
)) < 0 ||
499 (error
= diff_delta_format_path(
500 &new_path
, new_pfx
, delta
->new_file
.path
)) < 0)
503 pi
->line
.num_lines
= 1;
504 error
= diff_delta_format_with_paths(
505 pi
->buf
, delta
, "Binary files %s and %s differ\n",
506 old_path
.ptr
, new_path
.ptr
);
509 git_buf_free(&old_path
);
510 git_buf_free(&new_path
);
515 static int diff_print_patch_file_binary(
516 diff_print_info
*pi
, git_diff_delta
*delta
,
517 const char *old_pfx
, const char *new_pfx
,
518 const git_diff_binary
*binary
)
520 size_t pre_binary_size
;
523 if (delta
->status
== GIT_DELTA_UNMODIFIED
)
526 if ((pi
->flags
& GIT_DIFF_SHOW_BINARY
) == 0 || !binary
->contains_data
)
527 return diff_print_patch_file_binary_noshow(
528 pi
, delta
, old_pfx
, new_pfx
);
530 pre_binary_size
= pi
->buf
->size
;
531 git_buf_printf(pi
->buf
, "GIT binary patch\n");
532 pi
->line
.num_lines
++;
534 if ((error
= format_binary(pi
, binary
->new_file
.type
, binary
->new_file
.data
,
535 binary
->new_file
.datalen
, binary
->new_file
.inflatedlen
)) < 0 ||
536 (error
= format_binary(pi
, binary
->old_file
.type
, binary
->old_file
.data
,
537 binary
->old_file
.datalen
, binary
->old_file
.inflatedlen
)) < 0) {
539 if (error
== GIT_EBUFS
) {
541 git_buf_truncate(pi
->buf
, pre_binary_size
);
543 return diff_print_patch_file_binary_noshow(
544 pi
, delta
, old_pfx
, new_pfx
);
548 pi
->line
.num_lines
++;
552 static int diff_print_patch_file(
553 const git_diff_delta
*delta
, float progress
, void *data
)
556 diff_print_info
*pi
= data
;
558 pi
->old_prefix
? pi
->old_prefix
: DIFF_OLD_PREFIX_DEFAULT
;
560 pi
->new_prefix
? pi
->new_prefix
: DIFF_NEW_PREFIX_DEFAULT
;
562 bool binary
= (delta
->flags
& GIT_DIFF_FLAG_BINARY
) ||
563 (pi
->flags
& GIT_DIFF_FORCE_BINARY
);
564 bool show_binary
= !!(pi
->flags
& GIT_DIFF_SHOW_BINARY
);
565 int id_strlen
= pi
->id_strlen
;
567 if (binary
&& show_binary
)
568 id_strlen
= delta
->old_file
.id_abbrev
? delta
->old_file
.id_abbrev
:
569 delta
->new_file
.id_abbrev
;
571 GIT_UNUSED(progress
);
573 if (S_ISDIR(delta
->new_file
.mode
) ||
574 delta
->status
== GIT_DELTA_UNMODIFIED
||
575 delta
->status
== GIT_DELTA_IGNORED
||
576 delta
->status
== GIT_DELTA_UNREADABLE
||
577 (delta
->status
== GIT_DELTA_UNTRACKED
&&
578 (pi
->flags
& GIT_DIFF_SHOW_UNTRACKED_CONTENT
) == 0))
581 if ((error
= git_diff_delta__format_file_header(
582 pi
->buf
, delta
, oldpfx
, newpfx
, id_strlen
)) < 0)
585 pi
->line
.origin
= GIT_DIFF_LINE_FILE_HDR
;
586 pi
->line
.content
= git_buf_cstr(pi
->buf
);
587 pi
->line
.content_len
= git_buf_len(pi
->buf
);
589 return pi
->print_cb(delta
, NULL
, &pi
->line
, pi
->payload
);
592 static int diff_print_patch_binary(
593 const git_diff_delta
*delta
,
594 const git_diff_binary
*binary
,
597 diff_print_info
*pi
= data
;
598 const char *old_pfx
=
599 pi
->old_prefix
? pi
->old_prefix
: DIFF_OLD_PREFIX_DEFAULT
;
600 const char *new_pfx
=
601 pi
->new_prefix
? pi
->new_prefix
: DIFF_NEW_PREFIX_DEFAULT
;
604 git_buf_clear(pi
->buf
);
606 if ((error
= diff_print_patch_file_binary(
607 pi
, (git_diff_delta
*)delta
, old_pfx
, new_pfx
, binary
)) < 0)
610 pi
->line
.origin
= GIT_DIFF_LINE_BINARY
;
611 pi
->line
.content
= git_buf_cstr(pi
->buf
);
612 pi
->line
.content_len
= git_buf_len(pi
->buf
);
614 return pi
->print_cb(delta
, NULL
, &pi
->line
, pi
->payload
);
617 static int diff_print_patch_hunk(
618 const git_diff_delta
*d
,
619 const git_diff_hunk
*h
,
622 diff_print_info
*pi
= data
;
624 if (S_ISDIR(d
->new_file
.mode
))
627 pi
->line
.origin
= GIT_DIFF_LINE_HUNK_HDR
;
628 pi
->line
.content
= h
->header
;
629 pi
->line
.content_len
= h
->header_len
;
631 return pi
->print_cb(d
, h
, &pi
->line
, pi
->payload
);
634 static int diff_print_patch_line(
635 const git_diff_delta
*delta
,
636 const git_diff_hunk
*hunk
,
637 const git_diff_line
*line
,
640 diff_print_info
*pi
= data
;
642 if (S_ISDIR(delta
->new_file
.mode
))
645 return pi
->print_cb(delta
, hunk
, line
, pi
->payload
);
648 /* print a git_diff to an output callback */
651 git_diff_format_t format
,
652 git_diff_line_cb print_cb
,
656 git_buf buf
= GIT_BUF_INIT
;
658 git_diff_file_cb print_file
= NULL
;
659 git_diff_binary_cb print_binary
= NULL
;
660 git_diff_hunk_cb print_hunk
= NULL
;
661 git_diff_line_cb print_line
= NULL
;
664 case GIT_DIFF_FORMAT_PATCH
:
665 print_file
= diff_print_patch_file
;
666 print_binary
= diff_print_patch_binary
;
667 print_hunk
= diff_print_patch_hunk
;
668 print_line
= diff_print_patch_line
;
670 case GIT_DIFF_FORMAT_PATCH_HEADER
:
671 print_file
= diff_print_patch_file
;
673 case GIT_DIFF_FORMAT_RAW
:
674 print_file
= diff_print_one_raw
;
676 case GIT_DIFF_FORMAT_NAME_ONLY
:
677 print_file
= diff_print_one_name_only
;
679 case GIT_DIFF_FORMAT_NAME_STATUS
:
680 print_file
= diff_print_one_name_status
;
683 giterr_set(GITERR_INVALID
, "unknown diff output format (%d)", format
);
687 if (!(error
= diff_print_info_init_fromdiff(
688 &pi
, &buf
, diff
, format
, print_cb
, payload
))) {
689 error
= git_diff_foreach(
690 diff
, print_file
, print_binary
, print_hunk
, print_line
, &pi
);
692 if (error
) /* make sure error message is set */
693 giterr_set_after_callback_function(error
, "git_diff_print");
701 int git_diff_print_callback__to_buf(
702 const git_diff_delta
*delta
,
703 const git_diff_hunk
*hunk
,
704 const git_diff_line
*line
,
707 git_buf
*output
= payload
;
708 GIT_UNUSED(delta
); GIT_UNUSED(hunk
);
711 giterr_set(GITERR_INVALID
, "buffer pointer must be provided");
715 if (line
->origin
== GIT_DIFF_LINE_ADDITION
||
716 line
->origin
== GIT_DIFF_LINE_DELETION
||
717 line
->origin
== GIT_DIFF_LINE_CONTEXT
)
718 git_buf_putc(output
, line
->origin
);
720 return git_buf_put(output
, line
->content
, line
->content_len
);
723 int git_diff_print_callback__to_file_handle(
724 const git_diff_delta
*delta
,
725 const git_diff_hunk
*hunk
,
726 const git_diff_line
*line
,
729 FILE *fp
= payload
? payload
: stdout
;
731 GIT_UNUSED(delta
); GIT_UNUSED(hunk
);
733 if (line
->origin
== GIT_DIFF_LINE_CONTEXT
||
734 line
->origin
== GIT_DIFF_LINE_ADDITION
||
735 line
->origin
== GIT_DIFF_LINE_DELETION
)
736 fputc(line
->origin
, fp
);
737 fwrite(line
->content
, 1, line
->content_len
, fp
);
741 /* print a git_diff to a git_buf */
742 int git_diff_to_buf(git_buf
*out
, git_diff
*diff
, git_diff_format_t format
)
745 git_buf_sanitize(out
);
746 return git_diff_print(
747 diff
, format
, git_diff_print_callback__to_buf
, out
);
750 /* print a git_patch to an output callback */
753 git_diff_line_cb print_cb
,
757 git_buf temp
= GIT_BUF_INIT
;
760 assert(patch
&& print_cb
);
762 if (!(error
= diff_print_info_init_frompatch(
764 GIT_DIFF_FORMAT_PATCH
, print_cb
, payload
)))
766 error
= git_patch__invoke_callbacks(
768 diff_print_patch_file
, diff_print_patch_binary
,
769 diff_print_patch_hunk
, diff_print_patch_line
,
772 if (error
) /* make sure error message is set */
773 giterr_set_after_callback_function(error
, "git_patch_print");
781 /* print a git_patch to a git_buf */
782 int git_patch_to_buf(git_buf
*out
, git_patch
*patch
)
784 assert(out
&& patch
);
785 git_buf_sanitize(out
);
786 return git_patch_print(patch
, git_diff_print_callback__to_buf
, out
);