vendor/libgit2/src/errors.c in rugged-0.27.10 vs vendor/libgit2/src/errors.c in rugged-0.27.10.1
- old
+ new
@@ -15,11 +15,11 @@
* New error handling
********************************************/
static git_error g_git_oom_error = {
"Out of memory",
- GIT_ERROR_NOMEMORY
+ GITERR_NOMEMORY
};
static void set_error_from_buffer(int error_class)
{
git_error *error = &GIT_GLOBAL->error_t;
@@ -42,40 +42,35 @@
}
set_error_from_buffer(error_class);
}
-void git_error_set_oom(void)
+void giterr_set_oom(void)
{
GIT_GLOBAL->last_error = &g_git_oom_error;
}
-void git_error_set(int error_class, const char *fmt, ...)
+void giterr_set(int error_class, const char *string, ...)
{
- va_list ap;
-
- va_start(ap, fmt);
- git_error_vset(error_class, fmt, ap);
- va_end(ap);
-}
-
-void git_error_vset(int error_class, const char *fmt, va_list ap)
-{
+ va_list arglist;
#ifdef GIT_WIN32
- DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
+ DWORD win32_error_code = (error_class == GITERR_OS) ? GetLastError() : 0;
#endif
- int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
+ int error_code = (error_class == GITERR_OS) ? errno : 0;
git_buf *buf = &GIT_GLOBAL->error_buf;
git_buf_clear(buf);
- if (fmt) {
- git_buf_vprintf(buf, fmt, ap);
- if (error_class == GIT_ERROR_OS)
+ if (string) {
+ va_start(arglist, string);
+ git_buf_vprintf(buf, string, arglist);
+ va_end(arglist);
+
+ if (error_class == GITERR_OS)
git_buf_PUTS(buf, ": ");
}
- if (error_class == GIT_ERROR_OS) {
+ if (error_class == GITERR_OS) {
#ifdef GIT_WIN32
char * win32_error = git_win32_get_error_message(win32_error_code);
if (win32_error) {
git_buf_puts(buf, win32_error);
git__free(win32_error);
@@ -93,11 +88,11 @@
if (!git_buf_oom(buf))
set_error_from_buffer(error_class);
}
-void git_error_set_str(int error_class, const char *string)
+void giterr_set_str(int error_class, const char *string)
{
git_buf *buf = &GIT_GLOBAL->error_buf;
assert(string);
@@ -108,12 +103,27 @@
git_buf_puts(buf, string);
if (!git_buf_oom(buf))
set_error_from_buffer(error_class);
}
-void git_error_clear(void)
+int giterr_set_regex(const regex_t *regex, int error_code)
{
+ char error_buf[1024];
+
+ assert(error_code);
+
+ regerror(error_code, regex, error_buf, sizeof(error_buf));
+ giterr_set_str(GITERR_REGEX, error_buf);
+
+ if (error_code == REG_NOMATCH)
+ return GIT_ENOTFOUND;
+
+ return GIT_EINVALIDSPEC;
+}
+
+void giterr_clear(void)
+{
if (GIT_GLOBAL->last_error != NULL) {
set_error(0, NULL);
GIT_GLOBAL->last_error = NULL;
}
@@ -121,16 +131,16 @@
#ifdef GIT_WIN32
SetLastError(0);
#endif
}
-const git_error *git_error_last(void)
+const git_error *giterr_last(void)
{
return GIT_GLOBAL->last_error;
}
-int git_error_state_capture(git_error_state *state, int error_code)
+int giterr_state_capture(git_error_state *state, int error_code)
{
git_error *error = GIT_GLOBAL->last_error;
git_buf *error_buf = &GIT_GLOBAL->error_buf;
memset(state, 0, sizeof(git_error_state));
@@ -148,78 +158,56 @@
state->error_msg.message = g_git_oom_error.message;
else
state->error_msg.message = git_buf_detach(error_buf);
}
- git_error_clear();
+ giterr_clear();
return error_code;
}
-int git_error_state_restore(git_error_state *state)
+int giterr_state_restore(git_error_state *state)
{
int ret = 0;
- git_error_clear();
+ giterr_clear();
if (state && state->error_msg.message) {
if (state->oom)
- git_error_set_oom();
+ giterr_set_oom();
else
set_error(state->error_msg.klass, state->error_msg.message);
ret = state->error_code;
memset(state, 0, sizeof(git_error_state));
}
return ret;
}
-void git_error_state_free(git_error_state *state)
+void giterr_state_free(git_error_state *state)
{
if (!state)
return;
if (!state->oom)
git__free(state->error_msg.message);
memset(state, 0, sizeof(git_error_state));
}
-int git_error_system_last(void)
+int giterr_system_last(void)
{
#ifdef GIT_WIN32
return GetLastError();
#else
return errno;
#endif
}
-void git_error_system_set(int code)
+void giterr_system_set(int code)
{
#ifdef GIT_WIN32
SetLastError(code);
#else
errno = code;
#endif
-}
-
-/* Deprecated error values and functions */
-
-const git_error *giterr_last(void)
-{
- return git_error_last();
-}
-
-void giterr_clear(void)
-{
- git_error_clear();
-}
-
-void giterr_set_str(int error_class, const char *string)
-{
- git_error_set_str(error_class, string);
-}
-
-void giterr_set_oom(void)
-{
- git_error_set_oom();
}