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
c3a7892f
Unverified
Commit
c3a7892f
authored
Sep 09, 2019
by
Edward Thomson
Committed by
GitHub
Sep 09, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5209 from mkostyuk/apply-wrong-patch
apply: Fix a patch corruption related to EOFNL handling
parents
17d6cd45
585fbd74
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
1 deletions
+38
-1
src/apply.c
+1
-1
tests/apply/fromdiff.c
+11
-0
tests/patch/patch_common.h
+26
-0
No files found.
src/apply.c
View file @
c3a7892f
...
...
@@ -219,7 +219,7 @@ static int apply_hunk(
case
GIT_DIFF_LINE_CONTEXT_EOFNL
:
case
GIT_DIFF_LINE_DEL_EOFNL
:
case
GIT_DIFF_LINE_ADD_EOFNL
:
prev
=
i
?
git_array_get
(
patch
->
lines
,
i
-
1
)
:
NULL
;
prev
=
i
?
git_array_get
(
patch
->
lines
,
linenum
-
1
)
:
NULL
;
if
(
prev
&&
prev
->
content
[
prev
->
content_len
-
1
]
==
'\n'
)
prev
->
content_len
-=
1
;
break
;
...
...
tests/apply/fromdiff.c
View file @
c3a7892f
...
...
@@ -131,6 +131,17 @@ void test_apply_fromdiff__lastline(void)
PATCH_ORIGINAL_TO_CHANGE_LASTLINE
,
NULL
));
}
void
test_apply_fromdiff__change_middle_and_lastline_nocontext
(
void
)
{
git_diff_options
diff_opts
=
GIT_DIFF_OPTIONS_INIT
;
diff_opts
.
context_lines
=
0
;
cl_git_pass
(
apply_buf
(
FILE_ORIGINAL
,
"file.txt"
,
FILE_CHANGE_MIDDLE_AND_LASTLINE
,
"file.txt"
,
PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT
,
&
diff_opts
));
}
void
test_apply_fromdiff__prepend
(
void
)
{
cl_git_pass
(
apply_buf
(
...
...
tests/patch/patch_common.h
View file @
c3a7892f
...
...
@@ -263,6 +263,32 @@
"-(this line is changed)\n" \
"+(THIS line is changed!)\n"
/* A change in the middle and a deletion of the newline at the end of the file */
#define FILE_CHANGE_MIDDLE_AND_LASTLINE \
"hey!\n" \
"this is some context!\n" \
"around some lines\n" \
"that will change\n" \
"yes it is!\n" \
"(THIS line is changed!)\n" \
"and this\n" \
"is additional context\n" \
"BELOW it! - (THIS line is changed!)"
#define PATCH_ORIGINAL_TO_CHANGE_MIDDLE_AND_LASTLINE_NOCONTEXT \
"diff --git a/file.txt b/file.txt\n" \
"index 9432026..e05d36c 100644\n" \
"--- a/file.txt\n" \
"+++ b/file.txt\n" \
"@@ -6 +6 @@ yes it is!\n" \
"-(this line is changed)\n" \
"+(THIS line is changed!)\n" \
"@@ -9 +9 @@ is additional context\n" \
"-below it!\n" \
"+BELOW it! - (THIS line is changed!)\n" \
"\\ No newline at end of file\n"
/* A deletion at the beginning of the file and a change in the middle */
#define FILE_DELETE_AND_CHANGE \
...
...
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