Commit 440e3bae by Edward Thomson Committed by Edward Thomson

patch: `git_patch_from_patchfile` -> `git_patch_from_buffer`

parent 00e63b36
...@@ -267,32 +267,6 @@ GIT_EXTERN(int) git_patch_to_buf( ...@@ -267,32 +267,6 @@ GIT_EXTERN(int) git_patch_to_buf(
git_buf *out, git_buf *out,
git_patch *patch); 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 GIT_END_DECL
/**@}*/ /**@}*/
......
...@@ -50,6 +50,32 @@ extern int git_patch_line_stats( ...@@ -50,6 +50,32 @@ extern int git_patch_line_stats(
size_t *total_dels, size_t *total_dels,
const git_patch *patch); 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); extern void git_patch_free(git_patch *patch);
#endif #endif
...@@ -956,7 +956,7 @@ static void patch_parsed__free(git_patch *p) ...@@ -956,7 +956,7 @@ static void patch_parsed__free(git_patch *p)
git__free(patch); git__free(patch);
} }
int git_patch_from_patchfile( int git_patch_from_buffer(
git_patch **out, git_patch **out,
const char *content, const char *content,
size_t content_len, size_t content_len,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "git2/sys/repository.h" #include "git2/sys/repository.h"
#include "apply.h" #include "apply.h"
#include "patch.h"
#include "repository.h" #include "repository.h"
#include "buf_text.h" #include "buf_text.h"
...@@ -35,7 +36,7 @@ static int apply_patchfile( ...@@ -35,7 +36,7 @@ static int apply_patchfile(
unsigned int mode; unsigned int mode;
int error; 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); error = git_apply__patch(&result, &filename, &mode, old, old_len, patch);
...@@ -308,28 +309,28 @@ void test_apply_fromfile__noisy_nocontext(void) ...@@ -308,28 +309,28 @@ void test_apply_fromfile__noisy_nocontext(void)
void test_apply_fromfile__fail_truncated_1(void) void test_apply_fromfile__fail_truncated_1(void)
{ {
git_patch *patch; 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)); strlen(PATCH_TRUNCATED_1), NULL));
} }
void test_apply_fromfile__fail_truncated_2(void) void test_apply_fromfile__fail_truncated_2(void)
{ {
git_patch *patch; 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)); strlen(PATCH_TRUNCATED_2), NULL));
} }
void test_apply_fromfile__fail_truncated_3(void) void test_apply_fromfile__fail_truncated_3(void)
{ {
git_patch *patch; 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)); strlen(PATCH_TRUNCATED_3), NULL));
} }
void test_apply_fromfile__fail_corrupt_githeader(void) void test_apply_fromfile__fail_corrupt_githeader(void)
{ {
git_patch *patch; 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)); strlen(PATCH_CORRUPT_GIT_HEADER), NULL));
} }
...@@ -353,7 +354,7 @@ void test_apply_fromfile__append_no_nl(void) ...@@ -353,7 +354,7 @@ void test_apply_fromfile__append_no_nl(void)
void test_apply_fromfile__fail_missing_new_file(void) void test_apply_fromfile__fail_missing_new_file(void)
{ {
git_patch *patch; git_patch *patch;
cl_git_fail(git_patch_from_patchfile(&patch, cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_NEW_FILE, PATCH_CORRUPT_MISSING_NEW_FILE,
strlen(PATCH_CORRUPT_MISSING_NEW_FILE), NULL)); strlen(PATCH_CORRUPT_MISSING_NEW_FILE), NULL));
} }
...@@ -361,7 +362,7 @@ void test_apply_fromfile__fail_missing_new_file(void) ...@@ -361,7 +362,7 @@ void test_apply_fromfile__fail_missing_new_file(void)
void test_apply_fromfile__fail_missing_old_file(void) void test_apply_fromfile__fail_missing_old_file(void)
{ {
git_patch *patch; git_patch *patch;
cl_git_fail(git_patch_from_patchfile(&patch, cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_OLD_FILE, PATCH_CORRUPT_MISSING_OLD_FILE,
strlen(PATCH_CORRUPT_MISSING_OLD_FILE), NULL)); strlen(PATCH_CORRUPT_MISSING_OLD_FILE), NULL));
} }
...@@ -369,7 +370,7 @@ void test_apply_fromfile__fail_missing_old_file(void) ...@@ -369,7 +370,7 @@ void test_apply_fromfile__fail_missing_old_file(void)
void test_apply_fromfile__fail_no_changes(void) void test_apply_fromfile__fail_no_changes(void)
{ {
git_patch *patch; git_patch *patch;
cl_git_fail(git_patch_from_patchfile(&patch, cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_NO_CHANGES, PATCH_CORRUPT_NO_CHANGES,
strlen(PATCH_CORRUPT_NO_CHANGES), NULL)); strlen(PATCH_CORRUPT_NO_CHANGES), NULL));
} }
...@@ -377,7 +378,7 @@ void test_apply_fromfile__fail_no_changes(void) ...@@ -377,7 +378,7 @@ void test_apply_fromfile__fail_no_changes(void)
void test_apply_fromfile__fail_missing_hunk_header(void) void test_apply_fromfile__fail_missing_hunk_header(void)
{ {
git_patch *patch; git_patch *patch;
cl_git_fail(git_patch_from_patchfile(&patch, cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_HUNK_HEADER, PATCH_CORRUPT_MISSING_HUNK_HEADER,
strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL)); strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL));
} }
...@@ -385,7 +386,7 @@ void test_apply_fromfile__fail_missing_hunk_header(void) ...@@ -385,7 +386,7 @@ void test_apply_fromfile__fail_missing_hunk_header(void)
void test_apply_fromfile__fail_not_a_patch(void) void test_apply_fromfile__fail_not_a_patch(void)
{ {
git_patch *patch; 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)); strlen(PATCH_NOT_A_PATCH), NULL));
} }
...@@ -442,6 +443,6 @@ void test_apply_fromfile__empty_file_not_allowed(void) ...@@ -442,6 +443,6 @@ void test_apply_fromfile__empty_file_not_allowed(void)
{ {
git_patch *patch; git_patch *patch;
cl_git_fail(git_patch_from_patchfile(&patch, "", 0, NULL)); cl_git_fail(git_patch_from_buffer(&patch, "", 0, NULL));
cl_git_fail(git_patch_from_patchfile(&patch, NULL, 0, NULL)); cl_git_fail(git_patch_from_buffer(&patch, NULL, 0, NULL));
} }
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "patch.h"
#include "patch_common.h" #include "patch_common.h"
...@@ -8,7 +9,7 @@ void test_patch_parse__original_to_change_middle(void) ...@@ -8,7 +9,7 @@ void test_patch_parse__original_to_change_middle(void)
const git_diff_delta *delta; const git_diff_delta *delta;
char idstr[GIT_OID_HEXSZ+1] = {0}; 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, &patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE,
strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE), NULL)); strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE), NULL));
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "patch.h"
#include "patch_common.h" #include "patch_common.h"
...@@ -12,7 +13,7 @@ void patch_print_from_patchfile(const char *data, size_t len) ...@@ -12,7 +13,7 @@ void patch_print_from_patchfile(const char *data, size_t len)
git_patch *patch; git_patch *patch;
git_buf buf = GIT_BUF_INIT; 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_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_equal_s(data, buf.ptr); cl_assert_equal_s(data, buf.ptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment