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
5988cf34
Commit
5988cf34
authored
Dec 15, 2017
by
Etienne Samson
Committed by
Patrick Steinhardt
Oct 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit_list: unify commit information parsing
parent
1c847a6a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
77 deletions
+23
-77
src/commit_list.c
+23
-77
No files found.
src/commit_list.c
View file @
5988cf34
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "revwalk.h"
#include "revwalk.h"
#include "pool.h"
#include "pool.h"
#include "odb.h"
#include "odb.h"
#include "commit.h"
int
git_commit_list_time_cmp
(
const
void
*
a
,
const
void
*
b
)
int
git_commit_list_time_cmp
(
const
void
*
a
,
const
void
*
b
)
{
{
...
@@ -55,17 +56,6 @@ git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
...
@@ -55,17 +56,6 @@ git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
return
(
git_commit_list_node
*
)
git_pool_mallocz
(
&
walk
->
commit_pool
,
1
);
return
(
git_commit_list_node
*
)
git_pool_mallocz
(
&
walk
->
commit_pool
,
1
);
}
}
static
int
commit_error
(
git_commit_list_node
*
commit
,
const
char
*
msg
)
{
char
commit_oid
[
GIT_OID_HEXSZ
+
1
];
git_oid_fmt
(
commit_oid
,
&
commit
->
oid
);
commit_oid
[
GIT_OID_HEXSZ
]
=
'\0'
;
git_error_set
(
GIT_ERROR_ODB
,
"failed to parse commit %s - %s"
,
commit_oid
,
msg
);
return
-
1
;
}
static
git_commit_list_node
**
alloc_parents
(
static
git_commit_list_node
**
alloc_parents
(
git_revwalk
*
walk
,
git_commit_list_node
*
commit
,
size_t
n_parents
)
git_revwalk
*
walk
,
git_commit_list_node
*
commit
,
size_t
n_parents
)
{
{
...
@@ -107,77 +97,36 @@ git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
...
@@ -107,77 +97,36 @@ git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
static
int
commit_quick_parse
(
static
int
commit_quick_parse
(
git_revwalk
*
walk
,
git_revwalk
*
walk
,
git_commit_list_node
*
commit
,
git_commit_list_node
*
node
,
const
uint8_t
*
buffer
,
git_odb_object
*
obj
)
size_t
buffer_len
)
{
{
const
size_t
parent_len
=
strlen
(
"parent "
)
+
GIT_OID_HEXSZ
+
1
;
git_oid
*
parent_oid
;
const
uint8_t
*
buffer_end
=
buffer
+
buffer_len
;
git_commit
*
commit
;
const
uint8_t
*
parents_start
,
*
committer_start
;
int
error
;
int
i
,
parents
=
0
;
size_t
i
;
int64_t
commit_time
;
buffer
+=
strlen
(
"tree "
)
+
GIT_OID_HEXSZ
+
1
;
parents_start
=
buffer
;
while
(
buffer
+
parent_len
<
buffer_end
&&
memcmp
(
buffer
,
"parent "
,
strlen
(
"parent "
))
==
0
)
{
parents
++
;
buffer
+=
parent_len
;
}
commit
->
parents
=
alloc_parents
(
walk
,
commit
,
parents
);
GIT_ERROR_CHECK_ALLOC
(
commit
->
parents
);
buffer
=
parents_start
;
for
(
i
=
0
;
i
<
parents
;
++
i
)
{
git_oid
oid
;
if
(
git_oid_fromstr
(
&
oid
,
(
const
char
*
)
buffer
+
strlen
(
"parent "
))
<
0
)
return
-
1
;
commit
->
parents
[
i
]
=
git_revwalk__commit_lookup
(
walk
,
&
oid
);
commit
=
git__calloc
(
1
,
sizeof
(
*
commit
)
);
if
(
commit
->
parents
[
i
]
==
NULL
)
GIT_ERROR_CHECK_ALLOC
(
commit
);
return
-
1
;
commit
->
object
.
repo
=
walk
->
repo
;
buffer
+=
parent_len
;
if
((
error
=
git_commit__parse_ext
(
commit
,
obj
,
GIT_COMMIT_PARSE_QUICK
))
<
0
)
{
git__free
(
commit
);
return
error
;
}
}
commit
->
out_degree
=
(
unsigned
short
)
parents
;
node
->
time
=
commit
->
committer
->
when
.
time
;
node
->
out_degree
=
git_array_size
(
commit
->
parent_ids
);
if
((
committer_start
=
buffer
=
memchr
(
buffer
,
'\n'
,
buffer_end
-
buffer
))
==
NULL
)
node
->
parents
=
alloc_parents
(
walk
,
node
,
node
->
out_degree
);
return
commit_error
(
commit
,
"object is corrupted"
);
GIT_ERROR_CHECK_ALLOC
(
node
->
parents
);
buffer
++
;
if
((
buffer
=
memchr
(
buffer
,
'\n'
,
buffer_end
-
buffer
))
==
NULL
)
return
commit_error
(
commit
,
"object is corrupted"
);
/* Skip trailing spaces */
git_array_foreach
(
commit
->
parent_ids
,
i
,
parent_oid
)
{
while
(
buffer
>
committer_start
&&
git__isspace
(
*
buffer
))
node
->
parents
[
i
]
=
git_revwalk__commit_lookup
(
walk
,
parent_oid
);
buffer
--
;
/* Seek for the beginning of the pack of digits */
while
(
buffer
>
committer_start
&&
git__isdigit
(
*
buffer
))
buffer
--
;
/* Skip potential timezone offset */
if
((
buffer
>
committer_start
)
&&
(
*
buffer
==
'+'
||
*
buffer
==
'-'
))
{
buffer
--
;
while
(
buffer
>
committer_start
&&
git__isspace
(
*
buffer
))
buffer
--
;
while
(
buffer
>
committer_start
&&
git__isdigit
(
*
buffer
))
buffer
--
;
}
}
if
((
buffer
==
committer_start
)
||
git_commit__free
(
commit
);
(
git__strntol64
(
&
commit_time
,
(
char
*
)(
buffer
+
1
),
buffer_end
-
buffer
+
1
,
NULL
,
10
)
<
0
))
node
->
parsed
=
1
;
return
commit_error
(
commit
,
"cannot parse commit time"
);
commit
->
time
=
commit_time
;
commit
->
parsed
=
1
;
return
0
;
return
0
;
}
}
...
@@ -196,10 +145,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
...
@@ -196,10 +145,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
git_error_set
(
GIT_ERROR_INVALID
,
"object is no commit object"
);
git_error_set
(
GIT_ERROR_INVALID
,
"object is no commit object"
);
error
=
-
1
;
error
=
-
1
;
}
else
}
else
error
=
commit_quick_parse
(
error
=
commit_quick_parse
(
walk
,
commit
,
obj
);
walk
,
commit
,
(
const
uint8_t
*
)
git_odb_object_data
(
obj
),
git_odb_object_size
(
obj
));
git_odb_object_free
(
obj
);
git_odb_object_free
(
obj
);
return
error
;
return
error
;
...
...
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