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
474bd2c1
Commit
474bd2c1
authored
Feb 16, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3617 from libgit2/cmn/extract-sig-errors
commit: expose the different kinds of errors
parents
1aa14921
eadd0f05
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
1 deletions
+24
-1
include/git2/commit.h
+6
-0
src/commit.c
+7
-1
tests/commit/parse.c
+11
-0
No files found.
include/git2/commit.h
View file @
474bd2c1
...
@@ -266,12 +266,18 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit,
...
@@ -266,12 +266,18 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit,
/**
/**
* Extract the signature from a commit
* Extract the signature from a commit
*
*
* If the id is not for a commit, the error class will be
* `GITERR_INVALID`. If the commit does not have a signature, the
* error class will be `GITERR_OBJECT`.
*
* @param signature the signature block
* @param signature the signature block
* @param signed_data signed data; this is the commit contents minus the signature block
* @param signed_data signed data; this is the commit contents minus the signature block
* @param repo the repository in which the commit exists
* @param repo the repository in which the commit exists
* @param commit_id the commit from which to extract the data
* @param commit_id the commit from which to extract the data
* @param field the name of the header field containing the signature
* @param field the name of the header field containing the signature
* block; pass `NULL` to extract the default 'gpgsig'
* block; pass `NULL` to extract the default 'gpgsig'
* @return 0 on success, GIT_ENOTFOUND if the id is not for a commit
* or the commit does not have a signature.
*/
*/
GIT_EXTERN
(
int
)
git_commit_extract_signature
(
git_buf
*
signature
,
git_buf
*
signed_data
,
git_repository
*
repo
,
git_oid
*
commit_id
,
const
char
*
field
);
GIT_EXTERN
(
int
)
git_commit_extract_signature
(
git_buf
*
signature
,
git_buf
*
signed_data
,
git_repository
*
repo
,
git_oid
*
commit_id
,
const
char
*
field
);
...
...
src/commit.c
View file @
474bd2c1
...
@@ -642,6 +642,12 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
...
@@ -642,6 +642,12 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
if
((
error
=
git_odb_read
(
&
obj
,
odb
,
commit_id
))
<
0
)
if
((
error
=
git_odb_read
(
&
obj
,
odb
,
commit_id
))
<
0
)
return
error
;
return
error
;
if
(
obj
->
cached
.
type
!=
GIT_OBJ_COMMIT
)
{
giterr_set
(
GITERR_INVALID
,
"the requested type does not match the type in ODB"
);
error
=
GIT_ENOTFOUND
;
goto
cleanup
;
}
buf
=
git_odb_object_data
(
obj
);
buf
=
git_odb_object_data
(
obj
);
while
((
h
=
strchr
(
buf
,
'\n'
))
&&
h
[
1
]
!=
'\0'
&&
h
[
1
]
!=
'\n'
)
{
while
((
h
=
strchr
(
buf
,
'\n'
))
&&
h
[
1
]
!=
'\0'
&&
h
[
1
]
!=
'\n'
)
{
...
@@ -688,7 +694,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
...
@@ -688,7 +694,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
return
git_buf_puts
(
signed_data
,
eol
+
1
);
return
git_buf_puts
(
signed_data
,
eol
+
1
);
}
}
giterr_set
(
GITERR_
INVALID
,
"this commit is not signed"
);
giterr_set
(
GITERR_
OBJECT
,
"this commit is not signed"
);
error
=
GIT_ENOTFOUND
;
error
=
GIT_ENOTFOUND
;
goto
cleanup
;
goto
cleanup
;
...
...
tests/commit/parse.c
View file @
474bd2c1
...
@@ -513,6 +513,17 @@ a simple commit which works\n";
...
@@ -513,6 +513,17 @@ a simple commit which works\n";
cl_assert_equal_s
(
gpgsig
,
signature
.
ptr
);
cl_assert_equal_s
(
gpgsig
,
signature
.
ptr
);
cl_assert_equal_s
(
data
,
signed_data
.
ptr
);
cl_assert_equal_s
(
data
,
signed_data
.
ptr
);
/* Try to parse a tree */
cl_git_pass
(
git_oid_fromstr
(
&
commit_id
,
"45dd856fdd4d89b884c340ba0e047752d9b085d6"
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_commit_extract_signature
(
&
signature
,
&
signed_data
,
g_repo
,
&
commit_id
,
NULL
));
cl_assert_equal_i
(
GITERR_INVALID
,
giterr_last
()
->
klass
);
/* Try to parse an unsigned commit */
cl_git_pass
(
git_odb_write
(
&
commit_id
,
odb
,
passing_commit_cases
[
1
],
strlen
(
passing_commit_cases
[
1
]),
GIT_OBJ_COMMIT
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_commit_extract_signature
(
&
signature
,
&
signed_data
,
g_repo
,
&
commit_id
,
NULL
));
cl_assert_equal_i
(
GITERR_OBJECT
,
giterr_last
()
->
klass
);
git_buf_free
(
&
signature
);
git_buf_free
(
&
signature
);
git_buf_free
(
&
signed_data
);
git_buf_free
(
&
signed_data
);
}
}
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