Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
440e3bae
Commit
440e3bae
authored
Nov 21, 2015
by
Edward Thomson
Committed by
Edward Thomson
May 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch: `git_patch_from_patchfile` -> `git_patch_from_buffer`
parent
00e63b36
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
41 deletions
+44
-41
include/git2/patch.h
+0
-26
src/patch.h
+26
-0
src/patch_parse.c
+1
-1
tests/apply/fromfile.c
+13
-12
tests/patch/parse.c
+2
-1
tests/patch/print.c
+2
-1
No files found.
include/git2/patch.h
View file @
440e3bae
...
@@ -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
/**@}*/
/**@}*/
...
...
src/patch.h
View file @
440e3bae
...
@@ -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
src/patch_parse.c
View file @
440e3bae
...
@@ -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
,
...
...
tests/apply/fromfile.c
View file @
440e3bae
...
@@ -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
));
}
}
tests/patch/parse.c
View file @
440e3bae
#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
));
...
...
tests/patch/print.c
View file @
440e3bae
#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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment