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
b7a46fa8
Commit
b7a46fa8
authored
Jan 23, 2022
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
object: move oid header parsing to object
parent
c4360116
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
33 deletions
+44
-33
src/libgit2/commit.c
+5
-3
src/libgit2/object.c
+28
-0
src/libgit2/object.h
+5
-1
src/libgit2/oid.c
+0
-26
src/libgit2/tag.c
+2
-1
tests/libgit2/commit/parse.c
+4
-2
No files found.
src/libgit2/commit.c
View file @
b7a46fa8
...
...
@@ -408,7 +408,8 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig
/* The tree is always the first field */
if
(
!
(
flags
&
GIT_COMMIT_PARSE_QUICK
))
{
if
(
git_oid__parse
(
&
commit
->
tree_id
,
&
buffer
,
buffer_end
,
"tree "
)
<
0
)
if
(
git_object__parse_oid_header
(
&
commit
->
tree_id
,
&
buffer
,
buffer_end
,
"tree "
)
<
0
)
goto
bad_buffer
;
}
else
{
size_t
tree_len
=
strlen
(
"tree "
)
+
GIT_OID_SHA1_HEXSIZE
+
1
;
...
...
@@ -421,7 +422,8 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig
* TODO: commit grafts!
*/
while
(
git_oid__parse
(
&
parent_id
,
&
buffer
,
buffer_end
,
"parent "
)
==
0
)
{
while
(
git_object__parse_oid_header
(
&
parent_id
,
&
buffer
,
buffer_end
,
"parent "
)
==
0
)
{
git_oid
*
new_id
=
git_array_alloc
(
commit
->
parent_ids
);
GIT_ERROR_CHECK_ALLOC
(
new_id
);
...
...
@@ -566,7 +568,7 @@ const char *git_commit_summary(git_commit *commit)
while
(
*
next
&&
git__isspace_nonlf
(
*
next
))
{
++
next
;
}
if
(
!*
next
||
*
next
==
'\n'
)
if
(
!*
next
||
*
next
==
'\n'
)
break
;
}
/* record the beginning of contiguous whitespace runs */
...
...
src/libgit2/object.c
View file @
b7a46fa8
...
...
@@ -600,3 +600,31 @@ int git_object_rawcontent_is_valid(
return
error
;
}
int
git_object__parse_oid_header
(
git_oid
*
oid
,
const
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
)
{
const
size_t
sha_len
=
GIT_OID_SHA1_HEXSIZE
;
const
size_t
header_len
=
strlen
(
header
);
const
char
*
buffer
=
*
buffer_out
;
if
(
buffer
+
(
header_len
+
sha_len
+
1
)
>
buffer_end
)
return
-
1
;
if
(
memcmp
(
buffer
,
header
,
header_len
)
!=
0
)
return
-
1
;
if
(
buffer
[
header_len
+
sha_len
]
!=
'\n'
)
return
-
1
;
if
(
git_oid_fromstr
(
oid
,
buffer
+
header_len
)
<
0
)
return
-
1
;
*
buffer_out
=
buffer
+
(
header_len
+
sha_len
+
1
);
return
0
;
}
src/libgit2/object.h
View file @
b7a46fa8
...
...
@@ -45,7 +45,11 @@ int git_object__resolve_to_type(git_object **obj, git_object_t type);
git_object_t
git_object_stringn2type
(
const
char
*
str
,
size_t
len
);
int
git_oid__parse
(
git_oid
*
oid
,
const
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
int
git_object__parse_oid_header
(
git_oid
*
oid
,
const
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
void
git_oid__writebuf
(
git_str
*
buf
,
const
char
*
header
,
const
git_oid
*
oid
);
...
...
src/libgit2/oid.c
View file @
b7a46fa8
...
...
@@ -143,32 +143,6 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
return
out
;
}
int
git_oid__parse
(
git_oid
*
oid
,
const
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
)
{
const
size_t
sha_len
=
GIT_OID_SHA1_HEXSIZE
;
const
size_t
header_len
=
strlen
(
header
);
const
char
*
buffer
=
*
buffer_out
;
if
(
buffer
+
(
header_len
+
sha_len
+
1
)
>
buffer_end
)
return
-
1
;
if
(
memcmp
(
buffer
,
header
,
header_len
)
!=
0
)
return
-
1
;
if
(
buffer
[
header_len
+
sha_len
]
!=
'\n'
)
return
-
1
;
if
(
git_oid_fromstr
(
oid
,
buffer
+
header_len
)
<
0
)
return
-
1
;
*
buffer_out
=
buffer
+
(
header_len
+
sha_len
+
1
);
return
0
;
}
void
git_oid__writebuf
(
git_str
*
buf
,
const
char
*
header
,
const
git_oid
*
oid
)
{
char
hex_oid
[
GIT_OID_SHA1_HEXSIZE
];
...
...
src/libgit2/tag.c
View file @
b7a46fa8
...
...
@@ -75,7 +75,8 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
unsigned
int
i
;
int
error
;
if
(
git_oid__parse
(
&
tag
->
target
,
&
buffer
,
buffer_end
,
"object "
)
<
0
)
if
(
git_object__parse_oid_header
(
&
tag
->
target
,
&
buffer
,
buffer_end
,
"object "
)
<
0
)
return
tag_error
(
"object field invalid"
);
if
(
buffer
+
5
>=
buffer_end
)
...
...
tests/libgit2/commit/parse.c
View file @
b7a46fa8
...
...
@@ -56,7 +56,8 @@ void test_commit_parse__header(void)
const
char
*
line
=
testcase
->
line
;
const
char
*
line_end
=
line
+
strlen
(
line
);
cl_git_pass
(
git_oid__parse
(
&
oid
,
&
line
,
line_end
,
testcase
->
header
));
cl_git_pass
(
git_object__parse_oid_header
(
&
oid
,
&
line
,
line_end
,
testcase
->
header
));
cl_assert
(
line
==
line_end
);
}
...
...
@@ -65,7 +66,8 @@ void test_commit_parse__header(void)
const
char
*
line
=
testcase
->
line
;
const
char
*
line_end
=
line
+
strlen
(
line
);
cl_git_fail
(
git_oid__parse
(
&
oid
,
&
line
,
line_end
,
testcase
->
header
));
cl_git_fail
(
git_object__parse_oid_header
(
&
oid
,
&
line
,
line_end
,
testcase
->
header
));
}
}
...
...
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