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
69592bde
Commit
69592bde
authored
Apr 24, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grafts: use `git_parse` to parse object IDs
Don't mix parsing by hand and using `git_parse` to parse.
parent
6a02b459
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
9 deletions
+7
-9
src/libgit2/grafts.c
+7
-9
No files found.
src/libgit2/grafts.c
View file @
69592bde
...
@@ -119,7 +119,7 @@ cleanup:
...
@@ -119,7 +119,7 @@ cleanup:
return
error
;
return
error
;
}
}
int
git_grafts_parse
(
git_grafts
*
grafts
,
const
char
*
content
,
size_t
content
len
)
int
git_grafts_parse
(
git_grafts
*
grafts
,
const
char
*
buf
,
size_t
len
)
{
{
git_array_oid_t
parents
=
GIT_ARRAY_INIT
;
git_array_oid_t
parents
=
GIT_ARRAY_INIT
;
git_parse_ctx
parser
;
git_parse_ctx
parser
;
...
@@ -127,29 +127,26 @@ int git_grafts_parse(git_grafts *grafts, const char *content, size_t contentlen)
...
@@ -127,29 +127,26 @@ int git_grafts_parse(git_grafts *grafts, const char *content, size_t contentlen)
git_grafts_clear
(
grafts
);
git_grafts_clear
(
grafts
);
if
((
error
=
git_parse_ctx_init
(
&
parser
,
content
,
content
len
))
<
0
)
if
((
error
=
git_parse_ctx_init
(
&
parser
,
buf
,
len
))
<
0
)
goto
error
;
goto
error
;
for
(;
parser
.
remain_len
;
git_parse_advance_line
(
&
parser
))
{
for
(;
parser
.
remain_len
;
git_parse_advance_line
(
&
parser
))
{
const
char
*
line_start
=
parser
.
line
,
*
line_end
=
parser
.
line
+
parser
.
line_len
;
git_oid
graft_oid
;
git_oid
graft_oid
;
if
((
error
=
git_
oid__fromstrn
(
&
graft_oid
,
line_start
,
GIT_OID_SHA1_HEXSIZE
,
GIT_OID_SHA1
))
<
0
)
{
if
((
error
=
git_
parse_advance_oid
(
&
graft_oid
,
&
parser
,
GIT_OID_SHA1
))
<
0
)
{
git_error_set
(
GIT_ERROR_GRAFTS
,
"invalid graft OID at line %"
PRIuZ
,
parser
.
line_num
);
git_error_set
(
GIT_ERROR_GRAFTS
,
"invalid graft OID at line %"
PRIuZ
,
parser
.
line_num
);
goto
error
;
goto
error
;
}
}
line_start
+=
GIT_OID_SHA1_HEXSIZE
;
while
(
line_start
<
line_end
&&
*
line_start
==
' '
)
{
while
(
parser
.
line_len
&&
git_parse_advance_expected
(
&
parser
,
"
\n
"
,
1
)
!=
0
)
{
git_oid
*
id
=
git_array_alloc
(
parents
);
git_oid
*
id
=
git_array_alloc
(
parents
);
GIT_ERROR_CHECK_ALLOC
(
id
);
GIT_ERROR_CHECK_ALLOC
(
id
);
if
((
error
=
git_oid__fromstrn
(
id
,
++
line_start
,
GIT_OID_SHA1_HEXSIZE
,
GIT_OID_SHA1
))
<
0
)
{
if
((
error
=
git_parse_advance_expected
(
&
parser
,
" "
,
1
))
<
0
||
(
error
=
git_parse_advance_oid
(
id
,
&
parser
,
GIT_OID_SHA1
))
<
0
)
{
git_error_set
(
GIT_ERROR_GRAFTS
,
"invalid parent OID at line %"
PRIuZ
,
parser
.
line_num
);
git_error_set
(
GIT_ERROR_GRAFTS
,
"invalid parent OID at line %"
PRIuZ
,
parser
.
line_num
);
goto
error
;
goto
error
;
}
}
line_start
+=
GIT_OID_SHA1_HEXSIZE
;
}
}
if
((
error
=
git_grafts_add
(
grafts
,
&
graft_oid
,
parents
))
<
0
)
if
((
error
=
git_grafts_add
(
grafts
,
&
graft_oid
,
parents
))
<
0
)
...
@@ -186,6 +183,7 @@ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t paren
...
@@ -186,6 +183,7 @@ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t paren
if
((
error
=
git_grafts_remove
(
grafts
,
&
graft
->
oid
))
<
0
&&
error
!=
GIT_ENOTFOUND
)
if
((
error
=
git_grafts_remove
(
grafts
,
&
graft
->
oid
))
<
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
git_oidmap_set
(
grafts
->
commits
,
&
graft
->
oid
,
graft
))
<
0
)
if
((
error
=
git_oidmap_set
(
grafts
->
commits
,
&
graft
->
oid
,
graft
))
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
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