Skip to content

Commit c9464bf

Browse files
authored
Merge pull request libgit2#5273 from dlax/parse-diff-without-extended-headers
patch_parse: handle patches without extended headers
2 parents 4c0dea5 + 11de594 commit c9464bf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/patch_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ static const parse_header_transition transitions[] = {
389389
{ "index " , STATE_DIFF, STATE_INDEX, parse_header_git_index },
390390
{ "index " , STATE_END, STATE_INDEX, parse_header_git_index },
391391

392+
{ "--- " , STATE_DIFF, STATE_PATH, parse_header_git_oldpath },
392393
{ "--- " , STATE_INDEX, STATE_PATH, parse_header_git_oldpath },
393394
{ "+++ " , STATE_PATH, STATE_END, parse_header_git_newpath },
394395
{ "GIT binary patch" , STATE_INDEX, STATE_END, NULL },

tests/diff/parse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ void test_diff_parse__empty_file(void)
9898
git_diff_free(diff);
9999
}
100100

101+
void test_diff_parse__no_extended_headers(void)
102+
{
103+
const char *content = PATCH_NO_EXTENDED_HEADERS;
104+
git_diff *diff;
105+
106+
cl_git_pass(git_diff_from_buffer(
107+
&diff, content, strlen(content)));
108+
git_diff_free(diff);
109+
}
110+
101111
void test_diff_parse__invalid_patches_fails(void)
102112
{
103113
test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE);

tests/patch/patch_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,3 +895,13 @@
895895
"+++ b/test-file\r\n" \
896896
"@@ -0,0 +1 @@\r\n" \
897897
"+a contents\r\n"
898+
899+
#define PATCH_NO_EXTENDED_HEADERS \
900+
"diff --git a/file b/file\n" \
901+
"--- a/file\n" \
902+
"+++ b/file\n" \
903+
"@@ -1,3 +1,3 @@\n" \
904+
" a\n" \
905+
"-b\n" \
906+
"+bb\n" \
907+
" c\n"

0 commit comments

Comments
 (0)