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
720d5472
Commit
720d5472
authored
Apr 02, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change `parse` methods to const buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent
d8ad64d3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
47 deletions
+29
-47
src/commit.c
+2
-2
src/oid.c
+2
-2
src/repository.h
+1
-1
src/signature.c
+4
-4
src/signature.h
+1
-1
src/tag.c
+12
-30
src/tree.c
+2
-2
tests/t04-commit.c
+5
-5
No files found.
src/commit.c
View file @
720d5472
...
...
@@ -235,9 +235,9 @@ int git_commit_create(
return
error
;
}
int
commit_parse_buffer
(
git_commit
*
commit
,
void
*
data
,
size_t
len
)
int
commit_parse_buffer
(
git_commit
*
commit
,
const
void
*
data
,
size_t
len
)
{
char
*
buffer
=
(
char
*
)
data
;
c
onst
c
har
*
buffer
=
(
char
*
)
data
;
const
char
*
buffer_end
=
(
char
*
)
data
+
len
;
git_oid
parent_oid
;
...
...
src/oid.c
View file @
720d5472
...
...
@@ -118,13 +118,13 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
return
out
;
}
int
git__parse_oid
(
git_oid
*
oid
,
char
**
buffer_out
,
int
git__parse_oid
(
git_oid
*
oid
,
c
onst
c
har
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
)
{
const
size_t
sha_len
=
GIT_OID_HEXSZ
;
const
size_t
header_len
=
strlen
(
header
);
char
*
buffer
=
*
buffer_out
;
c
onst
c
har
*
buffer
=
*
buffer_out
;
if
(
buffer
+
(
header_len
+
sha_len
+
1
)
>
buffer_end
)
return
GIT_EOBJCORRUPTED
;
...
...
src/repository.h
View file @
720d5472
...
...
@@ -43,7 +43,7 @@ struct git_repository {
* export */
void
git_object__free
(
void
*
object
);
int
git__parse_oid
(
git_oid
*
oid
,
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
int
git__parse_oid
(
git_oid
*
oid
,
c
onst
c
har
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
int
git__write_oid
(
git_odb_stream
*
src
,
const
char
*
header
,
const
git_oid
*
oid
);
#endif
src/signature.c
View file @
720d5472
...
...
@@ -109,14 +109,14 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
}
int
git_signature__parse
(
git_signature
*
sig
,
char
**
buffer_out
,
int
git_signature__parse
(
git_signature
*
sig
,
c
onst
c
har
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
)
{
const
size_t
header_len
=
strlen
(
header
);
int
name_length
,
email_length
;
char
*
buffer
=
*
buffer_out
;
char
*
line_end
,
*
name_end
,
*
email_end
;
c
onst
c
har
*
buffer
=
*
buffer_out
;
c
onst
c
har
*
line_end
,
*
name_end
,
*
email_end
;
int
offset
=
0
;
memset
(
sig
,
0x0
,
sizeof
(
git_signature
));
...
...
@@ -159,7 +159,7 @@ int git_signature__parse(git_signature *sig, char **buffer_out,
if
(
buffer
>=
line_end
)
return
GIT_EOBJCORRUPTED
;
sig
->
when
.
time
=
strtol
(
buffer
,
&
buffer
,
10
);
sig
->
when
.
time
=
strtol
(
buffer
,
(
char
**
)
&
buffer
,
10
);
if
(
sig
->
when
.
time
==
0
)
return
GIT_EOBJCORRUPTED
;
...
...
src/signature.h
View file @
720d5472
...
...
@@ -6,7 +6,7 @@
#include "repository.h"
#include <time.h>
int
git_signature__parse
(
git_signature
*
sig
,
char
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
int
git_signature__parse
(
git_signature
*
sig
,
c
onst
c
har
**
buffer_out
,
const
char
*
buffer_end
,
const
char
*
header
);
int
git_signature__write
(
char
**
signature
,
const
char
*
header
,
const
git_signature
*
sig
);
#endif
src/tag.c
View file @
720d5472
...
...
@@ -79,7 +79,7 @@ const char *git_tag_message(git_tag *t)
return
t
->
message
;
}
static
int
parse_tag_buffer
(
git_tag
*
tag
,
char
*
buffer
,
const
char
*
buffer_end
)
static
int
parse_tag_buffer
(
git_tag
*
tag
,
c
onst
c
har
*
buffer
,
const
char
*
buffer_end
)
{
static
const
char
*
tag_types
[]
=
{
NULL
,
"commit
\n
"
,
"tree
\n
"
,
"blob
\n
"
,
"tag
\n
"
...
...
@@ -130,9 +130,6 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
text_len
=
search
-
buffer
;
if
(
tag
->
tag_name
!=
NULL
)
free
(
tag
->
tag_name
);
tag
->
tag_name
=
git__malloc
(
text_len
+
1
);
memcpy
(
tag
->
tag_name
,
buffer
,
text_len
);
tag
->
tag_name
[
text_len
]
=
'\0'
;
...
...
@@ -141,8 +138,11 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
tag
->
tagger
=
git__malloc
(
sizeof
(
git_signature
));
if
((
error
=
git_signature__parse
(
tag
->
tagger
,
&
buffer
,
buffer_end
,
"tagger "
))
!=
0
)
goto
cleanup
;
if
((
error
=
git_signature__parse
(
tag
->
tagger
,
&
buffer
,
buffer_end
,
"tagger "
))
!=
0
)
{
free
(
tag
->
tag_name
);
git_signature_free
(
tag
->
tagger
);
return
error
;
}
text_len
=
buffer_end
-
++
buffer
;
...
...
@@ -151,14 +151,6 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
tag
->
message
[
text_len
]
=
'\0'
;
return
GIT_SUCCESS
;
cleanup:
if
(
tag
->
tag_name
)
free
(
tag
->
tag_name
);
if
(
tag
->
tagger
)
git_signature_free
(
tag
->
tagger
);
return
error
;
}
int
git_tag_create_o
(
...
...
@@ -194,7 +186,6 @@ int git_tag_create(
int
type_str_len
,
tag_name_len
,
tagger_str_len
,
message_len
;
int
error
;
type_str
=
git_object_type2string
(
target_type
);
tagger_str_len
=
git_signature__write
(
&
tagger_str
,
"tagger"
,
tagger
);
...
...
@@ -245,40 +236,31 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
{
git_tag
tag
;
int
error
;
char
*
buf
;
git_object
*
obj
;
assert
(
oid
&&
buffer
);
memset
(
&
tag
,
0
,
sizeof
(
tag
));
buf
=
strdup
(
buffer
);
if
(
buf
==
NULL
)
return
GIT_ENOMEM
;
if
((
error
=
parse_tag_buffer
(
&
tag
,
buf
,
buf
+
strlen
(
buf
)))
<
0
)
goto
exit_freebuf
;
if
((
error
=
parse_tag_buffer
(
&
tag
,
buffer
,
buffer
+
strlen
(
buffer
)))
<
GIT_SUCCESS
)
return
error
;
error
=
git_object_lookup
(
&
obj
,
repo
,
&
tag
.
target
,
tag
.
type
);
if
(
error
<
0
)
goto
exit_freetag
;
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
error
=
git_tag_create_o
(
oid
,
repo
,
tag
.
tag_name
,
obj
,
tag
.
tagger
,
tag
.
message
);
error
=
git_tag_create_o
(
oid
,
repo
,
tag
.
tag_name
,
obj
,
tag
.
tagger
,
tag
.
message
);
git_object_close
(
obj
);
exit_freetag
:
cleanup
:
git_signature_free
(
tag
.
tagger
);
free
(
tag
.
tag_name
);
free
(
tag
.
message
);
exit_freebuf:
free
(
buf
);
return
error
;
}
int
git_tag__parse
(
git_tag
*
tag
,
git_odb_object
*
obj
)
{
assert
(
tag
);
...
...
src/tree.c
View file @
720d5472
...
...
@@ -127,7 +127,7 @@ size_t git_tree_entrycount(git_tree *tree)
return
tree
->
entries
.
length
;
}
static
int
tree_parse_buffer
(
git_tree
*
tree
,
c
har
*
buffer
,
char
*
buffer_end
)
static
int
tree_parse_buffer
(
git_tree
*
tree
,
c
onst
char
*
buffer
,
const
char
*
buffer_end
)
{
int
error
=
GIT_SUCCESS
;
...
...
@@ -146,7 +146,7 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end)
if
(
git_vector_insert
(
&
tree
->
entries
,
entry
)
<
GIT_SUCCESS
)
return
GIT_ENOMEM
;
entry
->
attr
=
strtol
(
buffer
,
&
buffer
,
8
);
entry
->
attr
=
strtol
(
buffer
,
(
char
**
)
&
buffer
,
8
);
if
(
*
buffer
++
!=
' '
)
{
error
=
GIT_EOBJCORRUPTED
;
...
...
tests/t04-commit.c
View file @
720d5472
...
...
@@ -114,15 +114,15 @@ BEGIN_TEST(parse0, "parse the OID line in a commit")
git_oid
oid
;
#define TEST_OID_PASS(string, header) { \
char *ptr = string;\
char *ptr_original = ptr;\
c
onst c
har *ptr = string;\
c
onst c
har *ptr_original = ptr;\
size_t len = strlen(ptr);\
must_pass(git__parse_oid(&oid, &ptr, ptr + len, header));\
must_be_true(ptr == ptr_original + len);\
}
#define TEST_OID_FAIL(string, header) { \
char *ptr = string;\
c
onst c
har *ptr = string;\
size_t len = strlen(ptr);\
must_fail(git__parse_oid(&oid, &ptr, ptr + len, header));\
}
...
...
@@ -154,7 +154,7 @@ END_TEST
BEGIN_TEST
(
parse1
,
"parse the signature line in a commit"
)
#define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset)
{
\
char
*
ptr
=
_string
;
\
c
onst
c
har
*
ptr
=
_string
;
\
size_t
len
=
strlen
(
_string
);
\
git_signature
person
=
{
NULL
,
NULL
,
{
0
,
0
}};
\
must_pass
(
git_signature__parse
(
&
person
,
&
ptr
,
ptr
+
len
,
_header
));
\
...
...
@@ -166,7 +166,7 @@ BEGIN_TEST(parse1, "parse the signature line in a commit")
}
#define TEST_SIGNATURE_FAIL(_string, _header) { \
char *ptr = _string; \
c
onst c
har *ptr = _string; \
size_t len = strlen(_string);\
git_signature person = {NULL, NULL, {0, 0}}; \
must_fail(git_signature__parse(&person, &ptr, ptr + len, _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