vendor/libgit2/src/errors.c in rugged-0.28.4 vs vendor/libgit2/src/errors.c in rugged-0.28.4.1

- old
+ new

@@ -47,30 +47,25 @@ void git_error_set_oom(void) { GIT_GLOBAL->last_error = &g_git_oom_error; } -void git_error_set(int error_class, const char *fmt, ...) +void git_error_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; #endif int error_code = (error_class == GIT_ERROR_OS) ? errno : 0; git_buf *buf = &GIT_GLOBAL->error_buf; git_buf_clear(buf); - if (fmt) { - git_buf_vprintf(buf, fmt, ap); + if (string) { + va_start(arglist, string); + git_buf_vprintf(buf, string, arglist); + va_end(arglist); + if (error_class == GIT_ERROR_OS) git_buf_PUTS(buf, ": "); } if (error_class == GIT_ERROR_OS) { @@ -106,9 +101,24 @@ git_buf_clear(buf); git_buf_puts(buf, string); if (!git_buf_oom(buf)) set_error_from_buffer(error_class); +} + +int git_error_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)); + git_error_set_str(GIT_ERROR_REGEX, error_buf); + + if (error_code == REG_NOMATCH) + return GIT_ENOTFOUND; + + return GIT_EINVALIDSPEC; } void git_error_clear(void) { if (GIT_GLOBAL->last_error != NULL) {