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:
Russell Belfer
2014-04-17 14:43:45 -07:00
parent 3dbee45656
commit 27e54bcf82
3 changed files with 96 additions and 24 deletions
+7 -22
View File
@@ -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));
}