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
5942bd18
Commit
5942bd18
authored
Sep 25, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #947 from arrbee/public-error-set
Make giterr_set_str() and giterr_set_oom() public APIs
parents
31d22037
1a628100
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
4 deletions
+79
-4
include/git2/errors.h
+34
-0
src/common.h
+13
-3
src/errors.c
+5
-1
tests-clar/core/errors.c
+27
-0
No files found.
include/git2/errors.h
View file @
5942bd18
...
...
@@ -71,6 +71,40 @@ GIT_EXTERN(const git_error *) giterr_last(void);
*/
GIT_EXTERN
(
void
)
giterr_clear
(
void
);
/**
* Set the error message string for this thread.
*
* This function is public so that custom ODB backends and the like can
* relay an error message through libgit2. Most regular users of libgit2
* will never need to call this function -- actually, calling it in most
* circumstances (for example, calling from within a callback function)
* will just end up having the value overwritten by libgit2 internals.
*
* This error message is stored in thread-local storage and only applies
* to the particular thread that this libgit2 call is made from.
*
* NOTE: Passing the `error_class` as GITERR_OS has a special behavior: we
* attempt to append the system default error message for the last OS error
* that occurred and then clear the last error. The specific implementation
* of looking up and clearing this last OS error will vary by platform.
*
* @param error_class One of the `git_error_t` enum above describing the
* general subsystem that is responsible for the error.
* @param message The formatted error message to keep
*/
GIT_EXTERN
(
void
)
giterr_set_str
(
int
error_class
,
const
char
*
string
);
/**
* Set the error message to a special value for memory allocation failure.
*
* The normal `giterr_set_str()` function attempts to `strdup()` the string
* that is passed in. This is not a good idea when the error in question
* is a memory allocation failure. That circumstance has a special setter
* function that sets the error string to a known and statically allocated
* internal value.
*/
GIT_EXTERN
(
void
)
giterr_set_oom
(
void
);
/** @} */
GIT_END_DECL
#endif
src/common.h
View file @
5942bd18
...
...
@@ -49,14 +49,24 @@
#include <regex.h>
/**
* Check a pointer allocation result, returning -1 if it failed.
*/
#define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
void
giterr_set_oom
(
void
);
/**
* Set the error message for this thread, formatting as needed.
*/
void
giterr_set
(
int
error_class
,
const
char
*
string
,
...);
void
giterr_clear
(
void
);
void
giterr_set_str
(
int
error_class
,
const
char
*
string
);
/**
* Set the error message for a regex failure, using the internal regex
* error code lookup.
*/
void
giterr_set_regex
(
const
regex_t
*
regex
,
int
error_code
);
/* NOTE: other giterr functions are in the public errors.h header file */
#include "util.h"
typedef
struct
git_transport
git_transport
;
...
...
src/errors.c
View file @
5942bd18
...
...
@@ -94,7 +94,11 @@ void giterr_set(int error_class, const char *string, ...)
void
giterr_set_str
(
int
error_class
,
const
char
*
string
)
{
char
*
message
=
git__strdup
(
string
);
char
*
message
;
assert
(
string
);
message
=
git__strdup
(
string
);
if
(
message
)
set_error
(
error_class
,
message
);
...
...
tests-clar/core/errors.c
View file @
5942bd18
#include "clar_libgit2.h"
void
test_core_errors__public_api
(
void
)
{
char
*
str_in_error
;
giterr_clear
();
cl_assert
(
giterr_last
()
==
NULL
);
giterr_set_oom
();
cl_assert
(
giterr_last
()
!=
NULL
);
cl_assert
(
giterr_last
()
->
klass
==
GITERR_NOMEMORY
);
str_in_error
=
strstr
(
giterr_last
()
->
message
,
"memory"
);
cl_assert
(
str_in_error
!=
NULL
);
giterr_clear
();
giterr_set_str
(
GITERR_REPOSITORY
,
"This is a test"
);
cl_assert
(
giterr_last
()
!=
NULL
);
str_in_error
=
strstr
(
giterr_last
()
->
message
,
"This is a test"
);
cl_assert
(
str_in_error
!=
NULL
);
giterr_clear
();
cl_assert
(
giterr_last
()
==
NULL
);
}
#include "common.h"
#include "util.h"
#include "posix.h"
...
...
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