summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/git2/patch.h26
-rw-r--r--src/patch.h26
-rw-r--r--src/patch_parse.c2
-rw-r--r--tests/apply/fromfile.c25
-rw-r--r--tests/patch/parse.c3
-rw-r--r--tests/patch/print.c3
6 files changed, 44 insertions, 41 deletions
diff --git a/include/git2/patch.h b/include/git2/patch.h
index f2e2476d9..790cb74fc 100644
--- a/include/git2/patch.h
+++ b/include/git2/patch.h
@@ -267,32 +267,6 @@ GIT_EXTERN(int) git_patch_to_buf(
git_buf *out,
git_patch *patch);
-/** Options for parsing patch files. */
-typedef struct {
- /**
- * The length of the prefix (in path segments) for the filenames.
- * This prefix will be removed when looking for files. The default is 1.
- */
- uint32_t prefix_len;
-} git_patch_options;
-
-#define GIT_PATCH_OPTIONS_INIT { 1 }
-
-/**
- * Create a patch from the contents of a patch file.
- *
- * @param out The patch to be created
- * @param patchfile The contents of a patch file
- * @param patchfile_len The length of the patch file
- * @param opts The git_patch_options
- * @return 0 on success, <0 on failure.
- */
-GIT_EXTERN(int) git_patch_from_patchfile(
- git_patch **out,
- const char *patchfile,
- size_t patchfile_len,
- git_patch_options *opts);
-
GIT_END_DECL
/**@}*/
diff --git a/src/patch.h b/src/patch.h
index b818c5cbe..28fe766da 100644
--- a/src/patch.h
+++ b/src/patch.h
@@ -50,6 +50,32 @@ extern int git_patch_line_stats(
size_t *total_dels,
const git_patch *patch);
+/** Options for parsing patch files. */
+typedef struct {
+ /**
+ * The length of the prefix (in path segments) for the filenames.
+ * This prefix will be removed when looking for files. The default is 1.
+ */
+ uint32_t prefix_len;
+} git_patch_options;
+
+#define GIT_PATCH_OPTIONS_INIT { 1 }
+
+/**
+ * Create a patch for a single file from the contents of a patch buffer.
+ *
+ * @param out The patch to be created
+ * @param contents The contents of a patch file
+ * @param contents_len The length of the patch file
+ * @param opts The git_patch_options
+ * @return 0 on success, <0 on failure.
+ */
+extern int git_patch_from_buffer(
+ git_patch **out,
+ const char *contents,
+ size_t contents_len,
+ git_patch_options *opts);
+
extern void git_patch_free(git_patch *patch);
#endif
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 46ecae73f..9421bb39b 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -956,7 +956,7 @@ static void patch_parsed__free(git_patch *p)
git__free(patch);
}
-int git_patch_from_patchfile(
+int git_patch_from_buffer(
git_patch **out,
const char *content,
size_t content_len,
diff --git a/tests/apply/fromfile.c b/tests/apply/fromfile.c
index ec2b889b3..7eb1af90c 100644
--- a/tests/apply/fromfile.c
+++ b/tests/apply/fromfile.c
@@ -2,6 +2,7 @@
#include "git2/sys/repository.h"
#include "apply.h"
+#include "patch.h"
#include "repository.h"
#include "buf_text.h"
@@ -35,7 +36,7 @@ static int apply_patchfile(
unsigned int mode;
int error;
- cl_git_pass(git_patch_from_patchfile(&patch, patchfile, strlen(patchfile), NULL));
+ cl_git_pass(git_patch_from_buffer(&patch, patchfile, strlen(patchfile), NULL));
error = git_apply__patch(&result, &filename, &mode, old, old_len, patch);
@@ -308,28 +309,28 @@ void test_apply_fromfile__noisy_nocontext(void)
void test_apply_fromfile__fail_truncated_1(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_1,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_1,
strlen(PATCH_TRUNCATED_1), NULL));
}
void test_apply_fromfile__fail_truncated_2(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_2,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_2,
strlen(PATCH_TRUNCATED_2), NULL));
}
void test_apply_fromfile__fail_truncated_3(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_3,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_3,
strlen(PATCH_TRUNCATED_3), NULL));
}
void test_apply_fromfile__fail_corrupt_githeader(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_CORRUPT_GIT_HEADER,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_CORRUPT_GIT_HEADER,
strlen(PATCH_CORRUPT_GIT_HEADER), NULL));
}
@@ -353,7 +354,7 @@ void test_apply_fromfile__append_no_nl(void)
void test_apply_fromfile__fail_missing_new_file(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_NEW_FILE,
strlen(PATCH_CORRUPT_MISSING_NEW_FILE), NULL));
}
@@ -361,7 +362,7 @@ void test_apply_fromfile__fail_missing_new_file(void)
void test_apply_fromfile__fail_missing_old_file(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_OLD_FILE,
strlen(PATCH_CORRUPT_MISSING_OLD_FILE), NULL));
}
@@ -369,7 +370,7 @@ void test_apply_fromfile__fail_missing_old_file(void)
void test_apply_fromfile__fail_no_changes(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_NO_CHANGES,
strlen(PATCH_CORRUPT_NO_CHANGES), NULL));
}
@@ -377,7 +378,7 @@ void test_apply_fromfile__fail_no_changes(void)
void test_apply_fromfile__fail_missing_hunk_header(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_HUNK_HEADER,
strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL));
}
@@ -385,7 +386,7 @@ void test_apply_fromfile__fail_missing_hunk_header(void)
void test_apply_fromfile__fail_not_a_patch(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_NOT_A_PATCH,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_NOT_A_PATCH,
strlen(PATCH_NOT_A_PATCH), NULL));
}
@@ -442,6 +443,6 @@ void test_apply_fromfile__empty_file_not_allowed(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, "", 0, NULL));
- cl_git_fail(git_patch_from_patchfile(&patch, NULL, 0, NULL));
+ cl_git_fail(git_patch_from_buffer(&patch, "", 0, NULL));
+ cl_git_fail(git_patch_from_buffer(&patch, NULL, 0, NULL));
}
diff --git a/tests/patch/parse.c b/tests/patch/parse.c
index 28f61ffcd..88cdbf6d7 100644
--- a/tests/patch/parse.c
+++ b/tests/patch/parse.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "patch.h"
#include "patch_common.h"
@@ -8,7 +9,7 @@ void test_patch_parse__original_to_change_middle(void)
const git_diff_delta *delta;
char idstr[GIT_OID_HEXSZ+1] = {0};
- cl_git_pass(git_patch_from_patchfile(
+ cl_git_pass(git_patch_from_buffer(
&patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE,
strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE), NULL));
diff --git a/tests/patch/print.c b/tests/patch/print.c
index a07328fa8..047b48e8f 100644
--- a/tests/patch/print.c
+++ b/tests/patch/print.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "patch.h"
#include "patch_common.h"
@@ -12,7 +13,7 @@ void patch_print_from_patchfile(const char *data, size_t len)
git_patch *patch;
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_patch_from_patchfile(&patch, data, len, NULL));
+ cl_git_pass(git_patch_from_buffer(&patch, data, len, NULL));
cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(data, buf.ptr);