mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-03 02:09:41 +00:00
patch: git_patch_from_patchfile
-> git_patch_from_buffer
This commit is contained in:
parent
00e63b3620
commit
440e3bae10
@ -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
|
||||
|
||||
/**@}*/
|
||||
|
26
src/patch.h
26
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
|
||||
|
@ -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,
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user