mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
diff: print the file header on GIT_DIFF_FORMAT_PATCH_HEADER
In `diff_print_patch_file` we try to avoid printing the file if we're not sure that there will be some content. This works fine if we have any later functions that might get called as part of printing. But when given the format `GIT_DIFF_FORMAT_PATCH_HEADER`, this is the only function to get called. Add the binary and hunk functions to those to be called when given this option and have them exit after printing the header. This takes care of printing the header if we would be issuing a hunk, but we skip that part.
This commit is contained in:
committed by
Carlos Martín Nieto
parent
caa781fc55
commit
6fa78bcabc
@@ -667,6 +667,13 @@ static int diff_print_patch_binary(
|
||||
if ((error = flush_file_header(delta, pi)) < 0)
|
||||
return error;
|
||||
|
||||
/*
|
||||
* If the caller only wants the header, we just needed to make sure to
|
||||
* call flush_file_header
|
||||
*/
|
||||
if (pi->format == GIT_DIFF_FORMAT_PATCH_HEADER)
|
||||
return 0;
|
||||
|
||||
git_str_clear(pi->buf);
|
||||
|
||||
if ((error = diff_print_patch_file_binary(
|
||||
@@ -694,6 +701,13 @@ static int diff_print_patch_hunk(
|
||||
if ((error = flush_file_header(d, pi)) < 0)
|
||||
return error;
|
||||
|
||||
/*
|
||||
* If the caller only wants the header, we just needed to make sure to
|
||||
* call flush_file_header
|
||||
*/
|
||||
if (pi->format == GIT_DIFF_FORMAT_PATCH_HEADER)
|
||||
return 0;
|
||||
|
||||
pi->line.origin = GIT_DIFF_LINE_HUNK_HDR;
|
||||
pi->line.content = h->header;
|
||||
pi->line.content_len = h->header_len;
|
||||
@@ -748,6 +762,8 @@ int git_diff_print(
|
||||
break;
|
||||
case GIT_DIFF_FORMAT_PATCH_HEADER:
|
||||
print_file = diff_print_patch_file;
|
||||
print_binary = diff_print_patch_binary;
|
||||
print_hunk = diff_print_patch_hunk;
|
||||
break;
|
||||
case GIT_DIFF_FORMAT_RAW:
|
||||
print_file = diff_print_one_raw;
|
||||
|
||||
Reference in New Issue
Block a user