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
aa4bfb32
Commit
aa4bfb32
authored
9 years ago
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse: introduce parse_ctx_contains_s
parent
8d44f8b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
src/patch_parse.c
+25
-18
No files found.
src/patch_parse.c
View file @
aa4bfb32
...
...
@@ -42,6 +42,15 @@ typedef struct {
}
patch_parse_ctx
;
GIT_INLINE
(
bool
)
parse_ctx_contains
(
patch_parse_ctx
*
ctx
,
const
char
*
str
,
size_t
len
)
{
return
(
ctx
->
line_len
>=
len
&&
memcmp
(
ctx
->
line
,
str
,
len
)
==
0
);
}
#define parse_ctx_contains_s(ctx, str) \
parse_ctx_contains(ctx, str, sizeof(str) - 1)
static
void
parse_advance_line
(
patch_parse_ctx
*
ctx
)
{
ctx
->
line
+=
ctx
->
line_len
;
...
...
@@ -589,11 +598,11 @@ static int parse_hunk_body(
}
/* Handle "\ No newline at end of file". Only expect the leading
* backslash, though, because the rest of the string could be
* localized. Because `diff` optimizes for the case where you
* want to apply the patch by hand.
*/
if
(
ctx
->
line_len
>=
2
&&
memcmp
(
ctx
->
line
,
"
\\
"
,
2
)
==
0
&&
* backslash, though, because the rest of the string could be
* localized. Because `diff` optimizes for the case where you
* want to apply the patch by hand.
*/
if
(
parse_ctx_contains_s
(
ctx
,
"
\\
"
)
&&
git_array_size
(
patch
->
base
.
lines
)
>
0
)
{
line
=
git_array_get
(
patch
->
base
.
lines
,
git_array_size
(
patch
->
base
.
lines
)
-
1
);
...
...
@@ -624,8 +633,8 @@ static int parsed_patch_header(
continue
;
/* This might be a hunk header without a patch header, provide a
* sensible error message. */
if
(
memcmp
(
ctx
->
line
,
"@@ -"
,
4
)
==
0
)
{
* sensible error message. */
if
(
parse_ctx_contains_s
(
ctx
,
"@@ -"
)
)
{
size_t
line_num
=
ctx
->
line_num
;
git_patch_hunk
hunk
;
...
...
@@ -647,7 +656,7 @@ static int parsed_patch_header(
break
;
/* A proper git patch */
if
(
ctx
->
line_len
>=
11
&&
memcmp
(
ctx
->
line
,
"diff --git "
,
11
)
==
0
)
{
if
(
parse_ctx_contains_s
(
ctx
,
"diff --git "
)
)
{
error
=
parse_header_git
(
patch
,
ctx
);
goto
done
;
}
...
...
@@ -671,16 +680,15 @@ static int parsed_patch_binary_side(
git_off_t
len
;
int
error
=
0
;
if
(
ctx
->
line_len
>=
8
&&
memcmp
(
ctx
->
line
,
"literal "
,
8
)
==
0
)
{
if
(
parse_ctx_contains_s
(
ctx
,
"literal "
)
)
{
type
=
GIT_DIFF_BINARY_LITERAL
;
parse_advance_chars
(
ctx
,
8
);
}
else
if
(
ctx
->
line_len
>=
6
&&
memcmp
(
ctx
->
line
,
"delta "
,
6
)
==
0
)
{
}
else
if
(
parse_ctx_contains_s
(
ctx
,
"delta "
))
{
type
=
GIT_DIFF_BINARY_DELTA
;
parse_advance_chars
(
ctx
,
6
);
}
else
{
error
=
parse_err
(
"unknown binary delta type at line %d"
,
ctx
->
line_num
);
}
else
{
error
=
parse_err
(
"unknown binary delta type at line %d"
,
ctx
->
line_num
);
goto
done
;
}
...
...
@@ -777,8 +785,7 @@ static int parsed_patch_hunks(
git_patch_hunk
*
hunk
;
int
error
=
0
;
for
(;
ctx
->
line_len
>
4
&&
memcmp
(
ctx
->
line
,
"@@ -"
,
4
)
==
0
;
)
{
while
(
parse_ctx_contains_s
(
ctx
,
"@@ -"
))
{
hunk
=
git_array_alloc
(
patch
->
base
.
hunks
);
GITERR_CHECK_ALLOC
(
hunk
);
...
...
@@ -799,10 +806,10 @@ done:
static
int
parsed_patch_body
(
git_patch_parsed
*
patch
,
patch_parse_ctx
*
ctx
)
{
if
(
ctx
->
line_len
>=
16
&&
memcmp
(
ctx
->
line
,
"GIT binary patch"
,
16
)
==
0
)
if
(
parse_ctx_contains_s
(
ctx
,
"GIT binary patch"
)
)
return
parsed_patch_binary
(
patch
,
ctx
);
else
if
(
ctx
->
line_len
>=
4
&&
memcmp
(
ctx
->
line
,
"@@ -"
,
4
)
==
0
)
else
if
(
parse_ctx_contains_s
(
ctx
,
"@@ -"
)
)
return
parsed_patch_hunks
(
patch
,
ctx
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
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