Commit 82175084 by Edward Thomson Committed by Edward Thomson

Introduce git_patch_options, handle prefixes

Handle prefixes (in terms of number of path components) for patch
parsing.
parent 19e46645
......@@ -267,18 +267,31 @@ 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);
size_t patchfile_len,
git_patch_options *opts);
GIT_END_DECL
......
......@@ -8,19 +8,21 @@ 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(&patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE, strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE)));
cl_git_pass(git_patch_from_patchfile(
&patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE,
strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE), NULL));
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
cl_assert_equal_i(2, delta->nfiles);
cl_assert_equal_s(delta->old_file.path, "a/file.txt");
cl_assert_equal_s(delta->old_file.path, "file.txt");
cl_assert(delta->old_file.mode == GIT_FILEMODE_BLOB);
cl_assert_equal_i(7, delta->old_file.id_abbrev);
git_oid_nfmt(idstr, delta->old_file.id_abbrev, &delta->old_file.id);
cl_assert_equal_s(idstr, "9432026");
cl_assert_equal_i(0, delta->old_file.size);
cl_assert_equal_s(delta->new_file.path, "b/file.txt");
cl_assert_equal_s(delta->new_file.path, "file.txt");
cl_assert(delta->new_file.mode == GIT_FILEMODE_BLOB);
cl_assert_equal_i(7, delta->new_file.id_abbrev);
git_oid_nfmt(idstr, delta->new_file.id_abbrev, &delta->new_file.id);
......
......@@ -12,7 +12,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));
cl_git_pass(git_patch_from_patchfile(&patch, data, len, NULL));
cl_git_pass(git_patch_to_buf(&buf, patch));
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