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
5e8ba35d
Commit
5e8ba35d
authored
Apr 29, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3763 from libgit2/ethomson/signature_from_buffer
Introduce `git_signature_from_buffer`
parents
1e7fa834
d383c39b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletions
+52
-1
include/git2/signature.h
+13
-0
src/signature.c
+26
-1
tests/commit/signature.c
+13
-0
No files found.
include/git2/signature.h
View file @
5e8ba35d
...
...
@@ -63,6 +63,19 @@ GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const c
GIT_EXTERN
(
int
)
git_signature_default
(
git_signature
**
out
,
git_repository
*
repo
);
/**
* Create a new signature by parsing the given buffer, which is
* expected to be in the format "Real Name <email> timestamp tzoffset",
* where `timestamp` is the number of seconds since the Unix epoch and
* `tzoffset` is the timezone offset in `hhmm` format (note the lack
* of a colon separator).
*
* @param out new signature
* @param buf signature string
* @return 0 on success, or an error code
*/
GIT_EXTERN
(
int
)
git_signature_from_buffer
(
git_signature
**
out
,
const
char
*
buf
);
/**
* Create a copy of an existing signature. All internal strings are also
* duplicated.
*
...
...
src/signature.c
View file @
5e8ba35d
...
...
@@ -200,7 +200,8 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
memset
(
sig
,
0
,
sizeof
(
git_signature
));
if
((
buffer_end
=
memchr
(
buffer
,
ender
,
buffer_end
-
buffer
))
==
NULL
)
if
(
ender
&&
(
buffer_end
=
memchr
(
buffer
,
ender
,
buffer_end
-
buffer
))
==
NULL
)
return
signature_error
(
"no newline given"
);
if
(
header
)
{
...
...
@@ -262,6 +263,30 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
return
0
;
}
int
git_signature_from_buffer
(
git_signature
**
out
,
const
char
*
buf
)
{
git_signature
*
sig
;
const
char
*
buf_end
;
int
error
;
assert
(
out
&&
buf
);
*
out
=
NULL
;
sig
=
git__calloc
(
1
,
sizeof
(
git_signature
));
GITERR_CHECK_ALLOC
(
sig
);
buf_end
=
buf
+
strlen
(
buf
);
error
=
git_signature__parse
(
sig
,
&
buf
,
buf_end
,
NULL
,
'\0'
);
if
(
error
)
git__free
(
sig
);
else
*
out
=
sig
;
return
error
;
}
void
git_signature__writebuf
(
git_buf
*
buf
,
const
char
*
header
,
const
git_signature
*
sig
)
{
int
offset
,
hours
,
mins
;
...
...
tests/commit/signature.c
View file @
5e8ba35d
...
...
@@ -86,3 +86,16 @@ void test_commit_signature__create_zero_char(void)
cl_git_fail
(
git_signature_new
(
&
sign
,
""
,
"x@y.z"
,
1234567890
,
60
));
cl_assert
(
sign
==
NULL
);
}
void
test_commit_signature__from_buf
(
void
)
{
git_signature
*
sign
;
cl_git_pass
(
git_signature_from_buffer
(
&
sign
,
"Test User <test@test.tt> 1461698487 +0200"
));
cl_assert_equal_s
(
"Test User"
,
sign
->
name
);
cl_assert_equal_s
(
"test@test.tt"
,
sign
->
email
);
cl_assert_equal_i
(
1461698487
,
sign
->
when
.
time
);
cl_assert_equal_i
(
120
,
sign
->
when
.
offset
);
git_signature_free
(
sign
);
}
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