diff options
author | Russell Belfer <rb@github.com> | 2013-11-04 15:45:31 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-11-04 15:45:31 -0800 |
commit | d6c6016966cff46d874a8d85b38704a6ef2150e5 (patch) | |
tree | ee7bd8d462e5dcfd9ed6caba7aa0531c0d44ede3 /src/errors.c | |
parent | 0e1115d2872fcb8f13fd28a52f1f14d52792623e (diff) | |
download | libgit2-d6c6016966cff46d874a8d85b38704a6ef2150e5.tar.gz |
Add giterr_detach API to get and clear error
There are a number of cases where it is convenient to be able to
fetch and "claim" the current error string, clearing the error.
This is helpful when you need to call some code that may alter
the error and you want to restore it later on and/or report it via
some other mechanism.
Diffstat (limited to 'src/errors.c')
-rw-r--r-- | src/errors.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/errors.c b/src/errors.c index c9d9e4e37..70b5f2668 100644 --- a/src/errors.c +++ b/src/errors.c @@ -112,6 +112,29 @@ void giterr_clear(void) #endif } +git_error_t giterr_detach(git_buf *message) +{ + git_error_t rval; + git_error *error = GIT_GLOBAL->last_error; + + assert(message); + + git_buf_free(message); + + if (!error) + return GITERR_NONE; + + rval = error->klass; + + if (error != &g_git_oom_error) + git_buf_attach(message, error->message, 0); + + error->message = NULL; + giterr_clear(); + + return rval; +} + const git_error *giterr_last(void) { return GIT_GLOBAL->last_error; |