summaryrefslogtreecommitdiff
path: root/tests/libgit2/diff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-07 15:28:58 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-10 14:21:16 +0100
commitdb2a794dda2b6f92291b3758507f863f39314c72 (patch)
tree53c5b2d77c6c38cf26fecc90e91809df0397fa46 /tests/libgit2/diff
parent7f70484799df14dbc666b3c395ded690d1a5a402 (diff)
downloadlibgit2-db2a794dda2b6f92291b3758507f863f39314c72.tar.gz
diff: parse patches with sha256
Diffstat (limited to 'tests/libgit2/diff')
-rw-r--r--tests/libgit2/diff/diff_helpers.c17
-rw-r--r--tests/libgit2/diff/diff_helpers.h4
-rw-r--r--tests/libgit2/diff/parse.c40
-rw-r--r--tests/libgit2/diff/patchid.c3
-rw-r--r--tests/libgit2/diff/stats.c3
5 files changed, 45 insertions, 22 deletions
diff --git a/tests/libgit2/diff/diff_helpers.c b/tests/libgit2/diff/diff_helpers.c
index 341b0a448..5daebffeb 100644
--- a/tests/libgit2/diff/diff_helpers.c
+++ b/tests/libgit2/diff/diff_helpers.c
@@ -314,3 +314,20 @@ void diff_assert_equal(git_diff *a, git_diff *b)
}
}
+#ifdef GIT_EXPERIMENTAL_SHA256
+int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len)
+{
+ return git_diff_from_buffer(out, content, content_len, NULL);
+}
+#else
+int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len)
+{
+ return git_diff_from_buffer(out, content, content_len);
+}
+#endif
diff --git a/tests/libgit2/diff/diff_helpers.h b/tests/libgit2/diff/diff_helpers.h
index af855ce68..1be4b4780 100644
--- a/tests/libgit2/diff/diff_helpers.h
+++ b/tests/libgit2/diff/diff_helpers.h
@@ -71,3 +71,7 @@ extern void diff_print_raw(FILE *fp, git_diff *diff);
extern void diff_assert_equal(git_diff *a, git_diff *b);
+extern int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len);
diff --git a/tests/libgit2/diff/parse.c b/tests/libgit2/diff/parse.c
index cae843cc8..79745b995 100644
--- a/tests/libgit2/diff/parse.c
+++ b/tests/libgit2/diff/parse.c
@@ -19,19 +19,19 @@ void test_diff_parse__nonpatches_fail_with_notfound(void)
const char *not_with_both = "Lead.\n" PATCH_NOT_A_PATCH "Trail.\n";
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not,
strlen(not)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_leading,
strlen(not_with_leading)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_trailing,
strlen(not_with_trailing)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_both,
strlen(not_with_both)));
}
@@ -51,7 +51,7 @@ static void test_parse_invalid_diff(const char *invalid_diff)
git_str_puts(&buf, PATCH_BINARY_LITERAL);
cl_git_fail_with(GIT_ERROR,
- git_diff_from_buffer(&diff, buf.ptr, buf.size));
+ diff_from_buffer(&diff, buf.ptr, buf.size));
git_str_dispose(&buf);
}
@@ -72,7 +72,7 @@ void test_diff_parse__exact_rename(void)
"2.9.3\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -92,7 +92,7 @@ void test_diff_parse__empty_file(void)
"2.20.1\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -102,7 +102,7 @@ void test_diff_parse__no_extended_headers(void)
const char *content = PATCH_NO_EXTENDED_HEADERS;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -125,7 +125,7 @@ void test_diff_parse__add_delete_no_index(void)
"-three\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -166,7 +166,7 @@ static void test_tree_to_tree_computed_to_parsed(
cl_git_pass(git_diff_to_buf(&computed_buf,
computed, GIT_DIFF_FORMAT_PATCH));
- cl_git_pass(git_diff_from_buffer(&parsed,
+ cl_git_pass(diff_from_buffer(&parsed,
computed_buf.ptr, computed_buf.size));
diff_assert_equal(computed, parsed);
@@ -248,7 +248,7 @@ void test_diff_parse__get_patch_from_diff(void)
computed, GIT_DIFF_FORMAT_PATCH));
cl_git_pass(git_patch_from_diff(&patch_computed, computed, 0));
- cl_git_pass(git_diff_from_buffer(&parsed,
+ cl_git_pass(diff_from_buffer(&parsed,
computed_buf.ptr, computed_buf.size));
cl_git_pass(git_patch_from_diff(&patch_parsed, parsed, 0));
@@ -292,7 +292,7 @@ void test_diff_parse__foreach_works_with_parsed_patch(void)
int called = 0;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch)));
+ cl_git_pass(diff_from_buffer(&diff, patch, strlen(patch)));
cl_git_pass(git_diff_foreach(diff, file_cb, NULL, NULL, NULL, &called));
cl_assert_equal_i(called, 1);
@@ -312,7 +312,7 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void)
git_buf buf = GIT_BUF_INIT;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch)));
+ cl_git_pass(diff_from_buffer(&diff, patch, strlen(patch)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
cl_assert_equal_s(patch, buf.ptr);
@@ -330,7 +330,7 @@ void test_diff_parse__patch_roundtrip_succeeds(void)
cl_git_pass(git_patch_from_buffers(&patch, buf1, strlen(buf1), "obj1", buf2, strlen(buf2), "obj2", NULL));
cl_git_pass(git_patch_to_buf(&patchbuf, patch));
- cl_git_pass(git_diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size));
+ cl_git_pass(diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size));
cl_git_pass(git_diff_to_buf(&diffbuf, diff, GIT_DIFF_FORMAT_PATCH));
cl_assert_equal_s(patchbuf.ptr, diffbuf.ptr);
@@ -372,7 +372,7 @@ void test_diff_parse__issue4672(void)
const git_diff_hunk *hunk;
size_t n, l = 0;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_get_hunk(&hunk, &n, patch, 0));
@@ -393,7 +393,7 @@ void test_diff_parse__lineinfo(void)
const git_diff_hunk *hunk;
size_t n, l = 0;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_get_hunk(&hunk, &n, patch, 0));
@@ -419,7 +419,7 @@ void test_diff_parse__new_file_with_space(void)
git_patch *patch;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_patch_from_diff((git_patch **) &patch, diff, 0));
cl_assert_equal_p(patch->diff_opts.old_prefix, NULL);
@@ -437,7 +437,7 @@ void test_diff_parse__new_file_with_space_and_regenerate_patch(void)
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
@@ -450,7 +450,7 @@ void test_diff_parse__delete_file_with_space_and_regenerate_patch(void)
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
@@ -464,7 +464,7 @@ void test_diff_parse__crlf(void)
git_patch *patch;
const git_diff_delta *delta;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
delta = git_patch_get_delta(patch);
diff --git a/tests/libgit2/diff/patchid.c b/tests/libgit2/diff/patchid.c
index 1cc368e21..91807e7b7 100644
--- a/tests/libgit2/diff/patchid.c
+++ b/tests/libgit2/diff/patchid.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "patch/patch_common.h"
+#include "diff_helpers.h"
static void verify_patch_id(const char *diff_content, const char *expected_id)
{
@@ -7,7 +8,7 @@ static void verify_patch_id(const char *diff_content, const char *expected_id)
git_diff *diff;
cl_git_pass(git_oid__fromstr(&expected_oid, expected_id, GIT_OID_SHA1));
- cl_git_pass(git_diff_from_buffer(&diff, diff_content, strlen(diff_content)));
+ cl_git_pass(diff_from_buffer(&diff, diff_content, strlen(diff_content)));
cl_git_pass(git_diff_patchid(&actual_oid, diff, NULL));
cl_assert_equal_oid(&expected_oid, &actual_oid);
diff --git a/tests/libgit2/diff/stats.c b/tests/libgit2/diff/stats.c
index b076ad5a9..7af891550 100644
--- a/tests/libgit2/diff/stats.c
+++ b/tests/libgit2/diff/stats.c
@@ -4,6 +4,7 @@
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
+#include "diff_helpers.h"
static git_repository *_repo;
static git_diff_stats *_stats;
@@ -368,7 +369,7 @@ void test_diff_stats__new_file(void)
" 1 file changed, 1 insertion(+)\n"
" create mode 100644 Gurjeet Singh\n";
- cl_git_pass(git_diff_from_buffer(&diff, input, strlen(input)));
+ cl_git_pass(diff_from_buffer(&diff, input, strlen(input)));
cl_git_pass(git_diff_get_stats(&_stats, diff));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
cl_assert_equal_s(stat, buf.ptr);