mirror of
https://git.proxmox.com/git/libgit2
synced 2026-08-26 20:08:02 +00:00
Add public diff print helpers
The usefulness of these helpers came up for me while debugging some of the iterator changes that I was making, so since they have also been requested (albeit indirectly) I thought I'd include them.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "diff_helpers.h"
|
||||
#include "git2/sys/diff.h"
|
||||
|
||||
git_tree *resolve_commit_oid_to_tree(
|
||||
git_repository *repo,
|
||||
@@ -215,32 +216,16 @@ abort:
|
||||
return GIT_EUSER;
|
||||
}
|
||||
|
||||
static int diff_print_cb(
|
||||
const git_diff_delta *delta,
|
||||
const git_diff_hunk *hunk,
|
||||
const git_diff_line *line,
|
||||
void *payload)
|
||||
{
|
||||
FILE *fp = payload;
|
||||
|
||||
GIT_UNUSED(delta); GIT_UNUSED(hunk);
|
||||
|
||||
if (line->origin == GIT_DIFF_LINE_CONTEXT ||
|
||||
line->origin == GIT_DIFF_LINE_ADDITION ||
|
||||
line->origin == GIT_DIFF_LINE_DELETION)
|
||||
fputc(line->origin, fp);
|
||||
fwrite(line->content, 1, line->content_len, fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void diff_print(FILE *fp, git_diff *diff)
|
||||
{
|
||||
cl_git_pass(git_diff_print(
|
||||
diff, GIT_DIFF_FORMAT_PATCH, diff_print_cb, fp ? fp : stderr));
|
||||
cl_git_pass(
|
||||
git_diff_print(diff, GIT_DIFF_FORMAT_PATCH,
|
||||
git_diff_print_callback__to_file_handle, fp ? fp : stderr));
|
||||
}
|
||||
|
||||
void diff_print_raw(FILE *fp, git_diff *diff)
|
||||
{
|
||||
cl_git_pass(git_diff_print(
|
||||
diff, GIT_DIFF_FORMAT_RAW, diff_print_cb, fp ? fp : stderr));
|
||||
cl_git_pass(
|
||||
git_diff_print(diff, GIT_DIFF_FORMAT_RAW,
|
||||
git_diff_print_callback__to_file_handle, fp ? fp : stderr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user