Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libgit2/diff_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ int git_diff_from_buffer_ext(
diff = diff_parsed_alloc(oid_type);
GIT_ERROR_CHECK_ALLOC(diff);

diff->base.opts.flags |= GIT_DIFF_SHOW_BINARY;

ctx = git_patch_parse_ctx_init(content, content_len, &patch_opts);
GIT_ERROR_CHECK_ALLOC(ctx);

Expand Down
16 changes: 16 additions & 0 deletions tests/libgit2/diff/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "delta.h"
#include "filebuf.h"
#include "repository.h"
#include "../patch/patch_common.h"

static git_repository *repo;

Expand Down Expand Up @@ -407,6 +408,21 @@ void test_diff_binary__print_patch_from_diff(void)
git_index_free(index);
}

void test_diff_binary__print_patch_from_diff_from_buffer(void)
{
git_diff *diff;
git_str actual = GIT_STR_INIT;

cl_git_pass(git_diff_from_buffer(&diff, PATCH_BINARY_LITERAL, strlen(PATCH_BINARY_LITERAL)));

cl_git_pass(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, print_cb, &actual));

cl_assert_equal_s(PATCH_BINARY_LITERAL, actual.ptr);

git_str_dispose(&actual);
git_diff_free(diff);
}

struct diff_data {
char *old_path;
git_oid old_id;
Expand Down
14 changes: 14 additions & 0 deletions tests/libgit2/diff/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,20 @@ void test_diff_parse__patch_roundtrip_succeeds(void)
git_buf_dispose(&diffbuf);
}

void test_diff_parse__binary_patch_roundtrip_succeeds(void)
{
git_buf diffbuf = GIT_BUF_INIT;
git_diff *diff;

cl_git_pass(git_diff_from_buffer(&diff, PATCH_BINARY_LITERAL, strlen(PATCH_BINARY_LITERAL)));
cl_git_pass(git_diff_to_buf(&diffbuf, diff, GIT_DIFF_FORMAT_PATCH));

cl_assert_equal_s(PATCH_BINARY_LITERAL, diffbuf.ptr);

git_diff_free(diff);
git_buf_dispose(&diffbuf);
}

#define cl_assert_equal_i_src(i1,i2,file,func,line) clar__assert_equal(file,func,line,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))

static void cl_git_assert_lineinfo_(int old_lineno, int new_lineno, int num_lines, git_patch *patch, size_t hunk_idx, size_t line_idx, const char *file, const char *func, int lineno)
Expand Down