patch: `git_patch_from_patchfile` -> `git_patch_from_buffer`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
diff --git a/include/git2/patch.h b/include/git2/patch.h
index f2e2476..790cb74 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 b818c5c..28fe766 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 46ecae7..9421bb3 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 ec2b889..7eb1af9 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 28f61ff..88cdbf6 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 a07328f..047b48e 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);