line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#ifndef INCLUDE_errors_h__ |
9
|
|
|
|
|
|
|
#define INCLUDE_errors_h__ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#include "common.h" |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
/* |
14
|
|
|
|
|
|
|
* Set the error message for this thread, formatting as needed. |
15
|
|
|
|
|
|
|
*/ |
16
|
|
|
|
|
|
|
void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3); |
17
|
|
|
|
|
|
|
void git_error_vset(int error_class, const char *fmt, va_list ap); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
/** |
20
|
|
|
|
|
|
|
* Set error message for user callback if needed. |
21
|
|
|
|
|
|
|
* |
22
|
|
|
|
|
|
|
* If the error code in non-zero and no error message is set, this |
23
|
|
|
|
|
|
|
* sets a generic error message. |
24
|
|
|
|
|
|
|
* |
25
|
|
|
|
|
|
|
* @return This always returns the `error_code` parameter. |
26
|
|
|
|
|
|
|
*/ |
27
|
6
|
|
|
|
|
|
GIT_INLINE(int) git_error_set_after_callback_function( |
28
|
|
|
|
|
|
|
int error_code, const char *action) |
29
|
|
|
|
|
|
|
{ |
30
|
6
|
50
|
|
|
|
|
if (error_code) { |
31
|
6
|
|
|
|
|
|
const git_error *e = git_error_last(); |
32
|
6
|
50
|
|
|
|
|
if (!e || !e->message) |
|
|
0
|
|
|
|
|
|
33
|
6
|
50
|
|
|
|
|
git_error_set(e ? e->klass : GIT_ERROR_CALLBACK, |
34
|
|
|
|
|
|
|
"%s callback returned %d", action, error_code); |
35
|
|
|
|
|
|
|
} |
36
|
6
|
|
|
|
|
|
return error_code; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#ifdef GIT_WIN32 |
40
|
|
|
|
|
|
|
#define git_error_set_after_callback(code) \ |
41
|
|
|
|
|
|
|
git_error_set_after_callback_function((code), __FUNCTION__) |
42
|
|
|
|
|
|
|
#else |
43
|
|
|
|
|
|
|
#define git_error_set_after_callback(code) \ |
44
|
|
|
|
|
|
|
git_error_set_after_callback_function((code), __func__) |
45
|
|
|
|
|
|
|
#endif |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
/** |
48
|
|
|
|
|
|
|
* Gets the system error code for this thread. |
49
|
|
|
|
|
|
|
*/ |
50
|
|
|
|
|
|
|
int git_error_system_last(void); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
/** |
53
|
|
|
|
|
|
|
* Sets the system error code for this thread. |
54
|
|
|
|
|
|
|
*/ |
55
|
|
|
|
|
|
|
void git_error_system_set(int code); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
/** |
58
|
|
|
|
|
|
|
* Structure to preserve libgit2 error state |
59
|
|
|
|
|
|
|
*/ |
60
|
|
|
|
|
|
|
typedef struct { |
61
|
|
|
|
|
|
|
int error_code; |
62
|
|
|
|
|
|
|
unsigned int oom : 1; |
63
|
|
|
|
|
|
|
git_error error_msg; |
64
|
|
|
|
|
|
|
} git_error_state; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
/** |
67
|
|
|
|
|
|
|
* Capture current error state to restore later, returning error code. |
68
|
|
|
|
|
|
|
* If `error_code` is zero, this does not clear the current error state. |
69
|
|
|
|
|
|
|
* You must either restore this error state, or free it. |
70
|
|
|
|
|
|
|
*/ |
71
|
|
|
|
|
|
|
extern int git_error_state_capture(git_error_state *state, int error_code); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
/** |
74
|
|
|
|
|
|
|
* Restore error state to a previous value, returning saved error code. |
75
|
|
|
|
|
|
|
*/ |
76
|
|
|
|
|
|
|
extern int git_error_state_restore(git_error_state *state); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
/** Free an error state. */ |
79
|
|
|
|
|
|
|
extern void git_error_state_free(git_error_state *state); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#endif |