Skip to content

Commit 635693d

Browse files
authored
Merge pull request libgit2#4917 from libgit2/ethomson/giterr
Move `giterr` to `git_error`
2 parents 6b2cd0e + a27a4de commit 635693d

File tree

204 files changed

+2150
-2040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+2150
-2040
lines changed

docs/conventions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ Check
136136
[`include/git2/errors.h`](https://github.com/libgit2/libgit2/blob/development/include/git2/errors.h)
137137
for the return codes already defined.
138138

139-
In your implementation, use `giterr_set()` to provide extended error
139+
In your implementation, use `git_error_set()` to provide extended error
140140
information to callers.
141141

142142
If a `libgit2` function internally invokes another function that reports an
143-
error, but the error is not propagated up, use `giterr_clear()` to prevent
143+
error, but the error is not propagated up, use `git_error_clear()` to prevent
144144
callers from getting the wrong error message later on.
145145

146146

docs/error-handling.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and a generic error code (-1) for all critical or non-specific failures
99
(e.g. running out of memory or system corruption).
1010

1111
When a negative value is returned, an error message is also set. The
12-
message can be accessed via the `giterr_last` function which will return a
12+
message can be accessed via the `git_error_last` function which will return a
1313
pointer to a `git_error` structure containing the error message text and
1414
the class of error (i.e. what part of the library generated the error).
1515

@@ -51,7 +51,7 @@ look at the error message that was generated.
5151
int error = git_repository_open(&repo, "path/to/repo");
5252

5353
if (error < 0) {
54-
fprintf(stderr, "Could not open repository: %s\n", giterr_last()->message);
54+
fprintf(stderr, "Could not open repository: %s\n", git_error_last()->message);
5555
exit(1);
5656
}
5757

@@ -75,7 +75,7 @@ at the specific error values to decide what to do.
7575
fprintf(stderr, "Could not find repository at path '%s'\n", path);
7676
else
7777
fprintf(stderr, "Unable to open repository: %s\n",
78-
giterr_last()->message);
78+
git_error_last()->message);
7979
exit(1);
8080
}
8181

@@ -86,7 +86,7 @@ at the specific error values to decide what to do.
8686
Some of the higher-level language bindings may use a range of information
8787
from libgit2 to convert error return codes into exceptions, including the
8888
specific error return codes and even the class of error and the error
89-
message returned by `giterr_last`, but the full range of that logic is
89+
message returned by `git_error_last`, but the full range of that logic is
9090
beyond the scope of this document.
9191

9292
Example internal implementation
@@ -102,7 +102,7 @@ int git_repository_open(git_repository **repository, const char *path)
102102
{
103103
/* perform some logic to open the repository */
104104
if (p_exists(path) < 0) {
105-
giterr_set(GITERR_REPOSITORY, "The path '%s' doesn't exist", path);
105+
git_error_set(GIT_ERROR_REPOSITORY, "The path '%s' doesn't exist", path);
106106
return GIT_ENOTFOUND;
107107
}
108108

@@ -113,7 +113,7 @@ int git_repository_open(git_repository **repository, const char *path)
113113
The public error API
114114
--------------------
115115
116-
- `const git_error *giterr_last(void)`: The main function used to look up
116+
- `const git_error *git_error_last(void)`: The main function used to look up
117117
the last error. This may return NULL if no error has occurred.
118118
Otherwise this should return a `git_error` object indicating the class
119119
of error and the error message that was generated by the library.
@@ -133,22 +133,22 @@ The public error API
133133
bugs, but in the meantime, please code defensively and check for NULL
134134
when calling this function.
135135
136-
- `void giterr_clear(void)`: This function clears the last error. The
136+
- `void git_error_clear(void)`: This function clears the last error. The
137137
library will call this when an error is generated by low level function
138138
and the higher level function handles the error.
139139
140140
_Note_ There are some known bugs in the library where a low level
141141
function's error message is not cleared by higher level code that
142142
handles the error and returns zero. Please report these as bugs, but in
143143
the meantime, a zero return value from a libgit2 API does not guarantee
144-
that `giterr_last()` will return NULL.
144+
that `git_error_last()` will return NULL.
145145
146-
- `void giterr_set_str(int error_class, const char *message)`: This
146+
- `void git_error_set(int error_class, const char *message)`: This
147147
function can be used when writing a custom backend module to set the
148148
libgit2 error message. See the documentation on this function for its
149149
use. Normal usage of libgit2 will probably never need to call this API.
150150
151-
- `void giterr_set_oom(void)`: This is a standard function for reporting
151+
- `void git_error_set_oom(void)`: This is a standard function for reporting
152152
an out-of-memory error. It is written in a manner that it doesn't have
153153
to allocate any extra memory in order to record the error, so this is
154154
the best way to report that scenario.
@@ -182,18 +182,18 @@ There are some known bugs in the library where some functions may return a
182182
negative value but not set an error message and some other functions may
183183
return zero (no error) and yet leave an error message set. Please report
184184
these cases as issues and they will be fixed. In the meanwhile, please
185-
code defensively, checking that the return value of `giterr_last` is not
186-
NULL before using it, and not relying on `giterr_last` to return NULL when
185+
code defensively, checking that the return value of `git_error_last` is not
186+
NULL before using it, and not relying on `git_error_last` to return NULL when
187187
a function returns 0 for success.
188188
189189
The internal error API
190190
----------------------
191191
192-
- `void giterr_set(int error_class, const char *fmt, ...)`: This is the
192+
- `void git_error_set(int error_class, const char *fmt, ...)`: This is the
193193
main internal function for setting an error. It works like `printf` to
194-
format the error message. See the notes of `giterr_set_str` for a
194+
format the error message. See the notes of `git_error_set_str` for a
195195
general description of how error messages are stored (and also about
196-
special handling for `error_class` of `GITERR_OS`).
196+
special handling for `error_class` of `GIT_ERROR_OS`).
197197
198198
Writing error messages
199199
----------------------
@@ -248,7 +248,7 @@ General guidelines for error reporting
248248
...
249249
250250
if (git_commit_lookup(parent, repo, parent_id) < 0) {
251-
giterr_set(GITERR_COMMIT, "Overwrite lookup error message");
251+
git_error_set(GIT_ERROR_COMMIT, "Overwrite lookup error message");
252252
return -1; /* mask error code */
253253
}
254254

docs/threading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ snapshots.
2222
Error messages
2323
--------------
2424

25-
The error message is thread-local. The `giterr_last()` call must
25+
The error message is thread-local. The `git_error_last()` call must
2626
happen on the same thread as the error in order to get the
2727
message. Often this will be the case regardless, but if you use
2828
something like the [GCD](http://en.wikipedia.org/wiki/Grand_Central_Dispatch)

examples/checkout.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ
132132
/** Grab the commit we're interested to move to */
133133
err = git_commit_lookup(&target_commit, repo, git_annotated_commit_id(target));
134134
if (err != 0) {
135-
fprintf(stderr, "failed to lookup commit: %s\n", giterr_last()->message);
135+
fprintf(stderr, "failed to lookup commit: %s\n", git_error_last()->message);
136136
goto cleanup;
137137
}
138138

139139
/**
140140
* Perform the checkout so the workdir corresponds to what target_commit
141141
* contains.
142142
*
143-
* Note that it's okay to pass a git_commit here, because it will be
143+
* Note that it's okay to pass a git_commit here, because it will be
144144
* peeled to a tree.
145145
*/
146146
err = git_checkout_tree(repo, (const git_object *)target_commit, &checkout_opts);
147147
if (err != 0) {
148-
fprintf(stderr, "failed to checkout tree: %s\n", giterr_last()->message);
148+
fprintf(stderr, "failed to checkout tree: %s\n", git_error_last()->message);
149149
goto cleanup;
150150
}
151151

@@ -161,7 +161,7 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ
161161
err = git_repository_set_head_detached_from_annotated(repo, target);
162162
}
163163
if (err != 0) {
164-
fprintf(stderr, "failed to update HEAD reference: %s\n", giterr_last()->message);
164+
fprintf(stderr, "failed to update HEAD reference: %s\n", git_error_last()->message);
165165
goto cleanup;
166166
}
167167

@@ -219,7 +219,7 @@ int main(int argc, char **argv)
219219
*/
220220
err = resolve_refish(&checkout_target, repo, args.argv[args.pos]);
221221
if (err != 0) {
222-
fprintf(stderr, "failed to resolve %s: %s\n", args.argv[args.pos], giterr_last()->message);
222+
fprintf(stderr, "failed to resolve %s: %s\n", args.argv[args.pos], git_error_last()->message);
223223
goto cleanup;
224224
}
225225
err = perform_checkout_ref(repo, checkout_target, &opts);

examples/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void check_lg2(int error, const char *message, const char *extra)
2424
if (!error)
2525
return;
2626

27-
if ((lg2err = giterr_last()) != NULL && lg2err->message != NULL) {
27+
if ((lg2err = git_error_last()) != NULL && lg2err->message != NULL) {
2828
lg2msg = lg2err->message;
2929
lg2spacer = " - ";
3030
}

examples/general.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void config_files(const char *repo_path, git_repository *repo);
6666
*/
6767
static void check_error(int error_code, const char *action)
6868
{
69-
const git_error *error = giterr_last();
69+
const git_error *error = git_error_last();
7070
if (!error_code)
7171
return;
7272

examples/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int resolve_heads(git_repository *repo, merge_options *opts)
9696
for (i = 0; i < opts->heads_count; i++) {
9797
err = resolve_refish(&annotated[annotated_count++], repo, opts->heads[i]);
9898
if (err != 0) {
99-
fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], giterr_last()->message);
99+
fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], git_error_last()->message);
100100
annotated_count--;
101101
continue;
102102
}
@@ -229,7 +229,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, merge_opt
229229

230230
/* Maybe that's a ref, so DWIM it */
231231
err = git_reference_dwim(&merge_ref, repo, opts->heads[0]);
232-
check_lg2(err, "failed to DWIM reference", giterr_last()->message);
232+
check_lg2(err, "failed to DWIM reference", git_error_last()->message);
233233

234234
/* Grab a signature */
235235
check_lg2(git_signature_now(&sign, "Me", "me@example.com"), "failed to create signature", NULL);

examples/network/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
104104
error = git_clone(&cloned_repo, url, path, &clone_opts);
105105
printf("\n");
106106
if (error != 0) {
107-
const git_error *err = giterr_last();
107+
const git_error *err = git_error_last();
108108
if (err) printf("ERROR %d: %s\n", err->klass, err->message);
109109
else printf("ERROR %d: no detailed info\n", error);
110110
}

examples/network/git2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ static int run_command(git_cb fn, git_repository *repo, struct args_info args)
2626
/* Run the command. If something goes wrong, print the error message to stderr */
2727
error = fn(repo, args.argc - args.pos, &args.argv[args.pos]);
2828
if (error < 0) {
29-
if (giterr_last() == NULL)
29+
if (git_error_last() == NULL)
3030
fprintf(stderr, "Error without message");
3131
else
32-
fprintf(stderr, "Bad news:\n %s\n", giterr_last()->message);
32+
fprintf(stderr, "Bad news:\n %s\n", git_error_last()->message);
3333
}
3434

3535
return !!error;

fuzzers/download_refs_fuzzer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
158158

159159
void fuzzer_git_abort(const char *op)
160160
{
161-
const git_error *err = giterr_last();
161+
const git_error *err = git_error_last();
162162
fprintf(stderr, "unexpected libgit error: %s: %s\n",
163163
op, err ? err->message : "<none>");
164164
abort();

0 commit comments

Comments
 (0)