Unverified Commit 635693d3 by Edward Thomson Committed by GitHub

Merge pull request #4917 from libgit2/ethomson/giterr

Move `giterr` to `git_error`
parents 6b2cd0ed a27a4de6
...@@ -136,11 +136,11 @@ Check ...@@ -136,11 +136,11 @@ Check
[`include/git2/errors.h`](https://github.com/libgit2/libgit2/blob/development/include/git2/errors.h) [`include/git2/errors.h`](https://github.com/libgit2/libgit2/blob/development/include/git2/errors.h)
for the return codes already defined. for the return codes already defined.
In your implementation, use `giterr_set()` to provide extended error In your implementation, use `git_error_set()` to provide extended error
information to callers. information to callers.
If a `libgit2` function internally invokes another function that reports an If a `libgit2` function internally invokes another function that reports an
error, but the error is not propagated up, use `giterr_clear()` to prevent error, but the error is not propagated up, use `git_error_clear()` to prevent
callers from getting the wrong error message later on. callers from getting the wrong error message later on.
......
...@@ -9,7 +9,7 @@ and a generic error code (-1) for all critical or non-specific failures ...@@ -9,7 +9,7 @@ and a generic error code (-1) for all critical or non-specific failures
(e.g. running out of memory or system corruption). (e.g. running out of memory or system corruption).
When a negative value is returned, an error message is also set. The When a negative value is returned, an error message is also set. The
message can be accessed via the `giterr_last` function which will return a message can be accessed via the `git_error_last` function which will return a
pointer to a `git_error` structure containing the error message text and pointer to a `git_error` structure containing the error message text and
the class of error (i.e. what part of the library generated the error). the class of error (i.e. what part of the library generated the error).
...@@ -51,7 +51,7 @@ look at the error message that was generated. ...@@ -51,7 +51,7 @@ look at the error message that was generated.
int error = git_repository_open(&repo, "path/to/repo"); int error = git_repository_open(&repo, "path/to/repo");
if (error < 0) { if (error < 0) {
fprintf(stderr, "Could not open repository: %s\n", giterr_last()->message); fprintf(stderr, "Could not open repository: %s\n", git_error_last()->message);
exit(1); exit(1);
} }
...@@ -75,7 +75,7 @@ at the specific error values to decide what to do. ...@@ -75,7 +75,7 @@ at the specific error values to decide what to do.
fprintf(stderr, "Could not find repository at path '%s'\n", path); fprintf(stderr, "Could not find repository at path '%s'\n", path);
else else
fprintf(stderr, "Unable to open repository: %s\n", fprintf(stderr, "Unable to open repository: %s\n",
giterr_last()->message); git_error_last()->message);
exit(1); exit(1);
} }
...@@ -86,7 +86,7 @@ at the specific error values to decide what to do. ...@@ -86,7 +86,7 @@ at the specific error values to decide what to do.
Some of the higher-level language bindings may use a range of information Some of the higher-level language bindings may use a range of information
from libgit2 to convert error return codes into exceptions, including the from libgit2 to convert error return codes into exceptions, including the
specific error return codes and even the class of error and the error specific error return codes and even the class of error and the error
message returned by `giterr_last`, but the full range of that logic is message returned by `git_error_last`, but the full range of that logic is
beyond the scope of this document. beyond the scope of this document.
Example internal implementation Example internal implementation
...@@ -102,7 +102,7 @@ int git_repository_open(git_repository **repository, const char *path) ...@@ -102,7 +102,7 @@ int git_repository_open(git_repository **repository, const char *path)
{ {
/* perform some logic to open the repository */ /* perform some logic to open the repository */
if (p_exists(path) < 0) { if (p_exists(path) < 0) {
giterr_set(GITERR_REPOSITORY, "The path '%s' doesn't exist", path); git_error_set(GIT_ERROR_REPOSITORY, "The path '%s' doesn't exist", path);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -113,7 +113,7 @@ int git_repository_open(git_repository **repository, const char *path) ...@@ -113,7 +113,7 @@ int git_repository_open(git_repository **repository, const char *path)
The public error API The public error API
-------------------- --------------------
- `const git_error *giterr_last(void)`: The main function used to look up - `const git_error *git_error_last(void)`: The main function used to look up
the last error. This may return NULL if no error has occurred. the last error. This may return NULL if no error has occurred.
Otherwise this should return a `git_error` object indicating the class Otherwise this should return a `git_error` object indicating the class
of error and the error message that was generated by the library. of error and the error message that was generated by the library.
...@@ -133,7 +133,7 @@ The public error API ...@@ -133,7 +133,7 @@ The public error API
bugs, but in the meantime, please code defensively and check for NULL bugs, but in the meantime, please code defensively and check for NULL
when calling this function. when calling this function.
- `void giterr_clear(void)`: This function clears the last error. The - `void git_error_clear(void)`: This function clears the last error. The
library will call this when an error is generated by low level function library will call this when an error is generated by low level function
and the higher level function handles the error. and the higher level function handles the error.
...@@ -141,14 +141,14 @@ The public error API ...@@ -141,14 +141,14 @@ The public error API
function's error message is not cleared by higher level code that function's error message is not cleared by higher level code that
handles the error and returns zero. Please report these as bugs, but in handles the error and returns zero. Please report these as bugs, but in
the meantime, a zero return value from a libgit2 API does not guarantee the meantime, a zero return value from a libgit2 API does not guarantee
that `giterr_last()` will return NULL. that `git_error_last()` will return NULL.
- `void giterr_set_str(int error_class, const char *message)`: This - `void git_error_set(int error_class, const char *message)`: This
function can be used when writing a custom backend module to set the function can be used when writing a custom backend module to set the
libgit2 error message. See the documentation on this function for its libgit2 error message. See the documentation on this function for its
use. Normal usage of libgit2 will probably never need to call this API. use. Normal usage of libgit2 will probably never need to call this API.
- `void giterr_set_oom(void)`: This is a standard function for reporting - `void git_error_set_oom(void)`: This is a standard function for reporting
an out-of-memory error. It is written in a manner that it doesn't have an out-of-memory error. It is written in a manner that it doesn't have
to allocate any extra memory in order to record the error, so this is to allocate any extra memory in order to record the error, so this is
the best way to report that scenario. 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 ...@@ -182,18 +182,18 @@ There are some known bugs in the library where some functions may return a
negative value but not set an error message and some other functions may negative value but not set an error message and some other functions may
return zero (no error) and yet leave an error message set. Please report return zero (no error) and yet leave an error message set. Please report
these cases as issues and they will be fixed. In the meanwhile, please these cases as issues and they will be fixed. In the meanwhile, please
code defensively, checking that the return value of `giterr_last` is not code defensively, checking that the return value of `git_error_last` is not
NULL before using it, and not relying on `giterr_last` to return NULL when NULL before using it, and not relying on `git_error_last` to return NULL when
a function returns 0 for success. a function returns 0 for success.
The internal error API The internal error API
---------------------- ----------------------
- `void giterr_set(int error_class, const char *fmt, ...)`: This is the - `void git_error_set(int error_class, const char *fmt, ...)`: This is the
main internal function for setting an error. It works like `printf` to main internal function for setting an error. It works like `printf` to
format the error message. See the notes of `giterr_set_str` for a format the error message. See the notes of `git_error_set_str` for a
general description of how error messages are stored (and also about general description of how error messages are stored (and also about
special handling for `error_class` of `GITERR_OS`). special handling for `error_class` of `GIT_ERROR_OS`).
Writing error messages Writing error messages
---------------------- ----------------------
...@@ -248,7 +248,7 @@ General guidelines for error reporting ...@@ -248,7 +248,7 @@ General guidelines for error reporting
... ...
if (git_commit_lookup(parent, repo, parent_id) < 0) { if (git_commit_lookup(parent, repo, parent_id) < 0) {
giterr_set(GITERR_COMMIT, "Overwrite lookup error message"); git_error_set(GIT_ERROR_COMMIT, "Overwrite lookup error message");
return -1; /* mask error code */ return -1; /* mask error code */
} }
......
...@@ -22,7 +22,7 @@ snapshots. ...@@ -22,7 +22,7 @@ snapshots.
Error messages Error messages
-------------- --------------
The error message is thread-local. The `giterr_last()` call must The error message is thread-local. The `git_error_last()` call must
happen on the same thread as the error in order to get the happen on the same thread as the error in order to get the
message. Often this will be the case regardless, but if you use message. Often this will be the case regardless, but if you use
something like the [GCD](http://en.wikipedia.org/wiki/Grand_Central_Dispatch) something like the [GCD](http://en.wikipedia.org/wiki/Grand_Central_Dispatch)
......
...@@ -132,7 +132,7 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ ...@@ -132,7 +132,7 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ
/** Grab the commit we're interested to move to */ /** Grab the commit we're interested to move to */
err = git_commit_lookup(&target_commit, repo, git_annotated_commit_id(target)); err = git_commit_lookup(&target_commit, repo, git_annotated_commit_id(target));
if (err != 0) { if (err != 0) {
fprintf(stderr, "failed to lookup commit: %s\n", giterr_last()->message); fprintf(stderr, "failed to lookup commit: %s\n", git_error_last()->message);
goto cleanup; goto cleanup;
} }
...@@ -140,12 +140,12 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ ...@@ -140,12 +140,12 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ
* Perform the checkout so the workdir corresponds to what target_commit * Perform the checkout so the workdir corresponds to what target_commit
* contains. * contains.
* *
* Note that it's okay to pass a git_commit here, because it will be * Note that it's okay to pass a git_commit here, because it will be
* peeled to a tree. * peeled to a tree.
*/ */
err = git_checkout_tree(repo, (const git_object *)target_commit, &checkout_opts); err = git_checkout_tree(repo, (const git_object *)target_commit, &checkout_opts);
if (err != 0) { if (err != 0) {
fprintf(stderr, "failed to checkout tree: %s\n", giterr_last()->message); fprintf(stderr, "failed to checkout tree: %s\n", git_error_last()->message);
goto cleanup; goto cleanup;
} }
...@@ -161,7 +161,7 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ ...@@ -161,7 +161,7 @@ static int perform_checkout_ref(git_repository *repo, git_annotated_commit *targ
err = git_repository_set_head_detached_from_annotated(repo, target); err = git_repository_set_head_detached_from_annotated(repo, target);
} }
if (err != 0) { if (err != 0) {
fprintf(stderr, "failed to update HEAD reference: %s\n", giterr_last()->message); fprintf(stderr, "failed to update HEAD reference: %s\n", git_error_last()->message);
goto cleanup; goto cleanup;
} }
...@@ -219,7 +219,7 @@ int main(int argc, char **argv) ...@@ -219,7 +219,7 @@ int main(int argc, char **argv)
*/ */
err = resolve_refish(&checkout_target, repo, args.argv[args.pos]); err = resolve_refish(&checkout_target, repo, args.argv[args.pos]);
if (err != 0) { if (err != 0) {
fprintf(stderr, "failed to resolve %s: %s\n", args.argv[args.pos], giterr_last()->message); fprintf(stderr, "failed to resolve %s: %s\n", args.argv[args.pos], git_error_last()->message);
goto cleanup; goto cleanup;
} }
err = perform_checkout_ref(repo, checkout_target, &opts); err = perform_checkout_ref(repo, checkout_target, &opts);
......
...@@ -24,7 +24,7 @@ void check_lg2(int error, const char *message, const char *extra) ...@@ -24,7 +24,7 @@ void check_lg2(int error, const char *message, const char *extra)
if (!error) if (!error)
return; return;
if ((lg2err = giterr_last()) != NULL && lg2err->message != NULL) { if ((lg2err = git_error_last()) != NULL && lg2err->message != NULL) {
lg2msg = lg2err->message; lg2msg = lg2err->message;
lg2spacer = " - "; lg2spacer = " - ";
} }
......
...@@ -66,7 +66,7 @@ static void config_files(const char *repo_path, git_repository *repo); ...@@ -66,7 +66,7 @@ static void config_files(const char *repo_path, git_repository *repo);
*/ */
static void check_error(int error_code, const char *action) static void check_error(int error_code, const char *action)
{ {
const git_error *error = giterr_last(); const git_error *error = git_error_last();
if (!error_code) if (!error_code)
return; return;
......
...@@ -96,7 +96,7 @@ static int resolve_heads(git_repository *repo, merge_options *opts) ...@@ -96,7 +96,7 @@ static int resolve_heads(git_repository *repo, merge_options *opts)
for (i = 0; i < opts->heads_count; i++) { for (i = 0; i < opts->heads_count; i++) {
err = resolve_refish(&annotated[annotated_count++], repo, opts->heads[i]); err = resolve_refish(&annotated[annotated_count++], repo, opts->heads[i]);
if (err != 0) { if (err != 0) {
fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], giterr_last()->message); fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], git_error_last()->message);
annotated_count--; annotated_count--;
continue; continue;
} }
...@@ -229,7 +229,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, merge_opt ...@@ -229,7 +229,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, merge_opt
/* Maybe that's a ref, so DWIM it */ /* Maybe that's a ref, so DWIM it */
err = git_reference_dwim(&merge_ref, repo, opts->heads[0]); err = git_reference_dwim(&merge_ref, repo, opts->heads[0]);
check_lg2(err, "failed to DWIM reference", giterr_last()->message); check_lg2(err, "failed to DWIM reference", git_error_last()->message);
/* Grab a signature */ /* Grab a signature */
check_lg2(git_signature_now(&sign, "Me", "me@example.com"), "failed to create signature", NULL); check_lg2(git_signature_now(&sign, "Me", "me@example.com"), "failed to create signature", NULL);
......
...@@ -104,7 +104,7 @@ int do_clone(git_repository *repo, int argc, char **argv) ...@@ -104,7 +104,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
error = git_clone(&cloned_repo, url, path, &clone_opts); error = git_clone(&cloned_repo, url, path, &clone_opts);
printf("\n"); printf("\n");
if (error != 0) { if (error != 0) {
const git_error *err = giterr_last(); const git_error *err = git_error_last();
if (err) printf("ERROR %d: %s\n", err->klass, err->message); if (err) printf("ERROR %d: %s\n", err->klass, err->message);
else printf("ERROR %d: no detailed info\n", error); else printf("ERROR %d: no detailed info\n", error);
} }
......
...@@ -26,10 +26,10 @@ static int run_command(git_cb fn, git_repository *repo, struct args_info args) ...@@ -26,10 +26,10 @@ static int run_command(git_cb fn, git_repository *repo, struct args_info args)
/* Run the command. If something goes wrong, print the error message to stderr */ /* Run the command. If something goes wrong, print the error message to stderr */
error = fn(repo, args.argc - args.pos, &args.argv[args.pos]); error = fn(repo, args.argc - args.pos, &args.argv[args.pos]);
if (error < 0) { if (error < 0) {
if (giterr_last() == NULL) if (git_error_last() == NULL)
fprintf(stderr, "Error without message"); fprintf(stderr, "Error without message");
else else
fprintf(stderr, "Bad news:\n %s\n", giterr_last()->message); fprintf(stderr, "Bad news:\n %s\n", git_error_last()->message);
} }
return !!error; return !!error;
......
...@@ -158,7 +158,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) ...@@ -158,7 +158,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
void fuzzer_git_abort(const char *op) void fuzzer_git_abort(const char *op)
{ {
const git_error *err = giterr_last(); const git_error *err = git_error_last();
fprintf(stderr, "unexpected libgit error: %s: %s\n", fprintf(stderr, "unexpected libgit error: %s: %s\n",
op, err ? err->message : "<none>"); op, err ? err->message : "<none>");
abort(); abort();
......
...@@ -77,7 +77,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -77,7 +77,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_new(&indexer, ".", 0, odb, NULL) < 0) { if (git_indexer_new(&indexer, ".", 0, odb, NULL) < 0) {
fprintf(stderr, "Failed to create the indexer: %s\n", fprintf(stderr, "Failed to create the indexer: %s\n",
giterr_last()->message); git_error_last()->message);
abort(); abort();
} }
......
...@@ -183,7 +183,7 @@ GIT_EXTERN(const git_blame_hunk*) git_blame_get_hunk_byline( ...@@ -183,7 +183,7 @@ GIT_EXTERN(const git_blame_hunk*) git_blame_get_hunk_byline(
* @param path path to file to consider * @param path path to file to consider
* @param options options for the blame operation. If NULL, this is treated as * @param options options for the blame operation. If NULL, this is treated as
* though GIT_BLAME_OPTIONS_INIT were passed. * though GIT_BLAME_OPTIONS_INIT were passed.
* @return 0 on success, or an error code. (use giterr_last for information * @return 0 on success, or an error code. (use git_error_last for information
* about the error.) * about the error.)
*/ */
GIT_EXTERN(int) git_blame_file( GIT_EXTERN(int) git_blame_file(
...@@ -207,7 +207,7 @@ GIT_EXTERN(int) git_blame_file( ...@@ -207,7 +207,7 @@ GIT_EXTERN(int) git_blame_file(
* from git_blame_file) * from git_blame_file)
* @param buffer the (possibly) modified contents of the file * @param buffer the (possibly) modified contents of the file
* @param buffer_len number of valid bytes in the buffer * @param buffer_len number of valid bytes in the buffer
* @return 0 on success, or an error code. (use giterr_last for information * @return 0 on success, or an error code. (use git_error_last for information
* about the error) * about the error)
*/ */
GIT_EXTERN(int) git_blame_buffer( GIT_EXTERN(int) git_blame_buffer(
......
...@@ -325,7 +325,7 @@ GIT_EXTERN(int) git_checkout_init_options( ...@@ -325,7 +325,7 @@ GIT_EXTERN(int) git_checkout_init_options(
* @param opts specifies checkout options (may be NULL) * @param opts specifies checkout options (may be NULL)
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non * @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non
* existing branch, non-zero value returned by `notify_cb`, or * existing branch, non-zero value returned by `notify_cb`, or
* other error code < 0 (use giterr_last for error details) * other error code < 0 (use git_error_last for error details)
*/ */
GIT_EXTERN(int) git_checkout_head( GIT_EXTERN(int) git_checkout_head(
git_repository *repo, git_repository *repo,
...@@ -338,7 +338,7 @@ GIT_EXTERN(int) git_checkout_head( ...@@ -338,7 +338,7 @@ GIT_EXTERN(int) git_checkout_head(
* @param index index to be checked out (or NULL to use repository index) * @param index index to be checked out (or NULL to use repository index)
* @param opts specifies checkout options (may be NULL) * @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error * @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use giterr_last for error details) * code < 0 (use git_error_last for error details)
*/ */
GIT_EXTERN(int) git_checkout_index( GIT_EXTERN(int) git_checkout_index(
git_repository *repo, git_repository *repo,
...@@ -354,7 +354,7 @@ GIT_EXTERN(int) git_checkout_index( ...@@ -354,7 +354,7 @@ GIT_EXTERN(int) git_checkout_index(
* the working directory (or NULL to use HEAD) * the working directory (or NULL to use HEAD)
* @param opts specifies checkout options (may be NULL) * @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error * @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use giterr_last for error details) * code < 0 (use git_error_last for error details)
*/ */
GIT_EXTERN(int) git_checkout_tree( GIT_EXTERN(int) git_checkout_tree(
git_repository *repo, git_repository *repo,
......
...@@ -196,7 +196,7 @@ GIT_EXTERN(int) git_clone_init_options( ...@@ -196,7 +196,7 @@ GIT_EXTERN(int) git_clone_init_options(
* function works as though GIT_OPTIONS_INIT were passed. * function works as though GIT_OPTIONS_INIT were passed.
* @return 0 on success, any non-zero return value from a callback * @return 0 on success, any non-zero return value from a callback
* function, or a negative value to indicate an error (use * function, or a negative value to indicate an error (use
* `giterr_last` for a detailed error message) * `git_error_last` for a detailed error message)
*/ */
GIT_EXTERN(int) git_clone( GIT_EXTERN(int) git_clone(
git_repository **out, git_repository **out,
......
...@@ -296,8 +296,8 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit, ...@@ -296,8 +296,8 @@ GIT_EXTERN(int) git_commit_header_field(git_buf *out, const git_commit *commit,
* Extract the signature from a commit * Extract the signature from a commit
* *
* If the id is not for a commit, the error class will be * If the id is not for a commit, the error class will be
* `GITERR_INVALID`. If the commit does not have a signature, the * `GIT_ERROR_INVALID`. If the commit does not have a signature, the
* error class will be `GITERR_OBJECT`. * error class will be `GIT_ERROR_OBJECT`.
* *
* @param signature the signature block; existing content will be * @param signature the signature block; existing content will be
* overwritten * overwritten
......
...@@ -73,42 +73,48 @@ typedef struct { ...@@ -73,42 +73,48 @@ typedef struct {
/** Error classes */ /** Error classes */
typedef enum { typedef enum {
GITERR_NONE = 0, GIT_ERROR_NONE = 0,
GITERR_NOMEMORY, GIT_ERROR_NOMEMORY,
GITERR_OS, GIT_ERROR_OS,
GITERR_INVALID, GIT_ERROR_INVALID,
GITERR_REFERENCE, GIT_ERROR_REFERENCE,
GITERR_ZLIB, GIT_ERROR_ZLIB,
GITERR_REPOSITORY, GIT_ERROR_REPOSITORY,
GITERR_CONFIG, GIT_ERROR_CONFIG,
GITERR_REGEX, GIT_ERROR_REGEX,
GITERR_ODB, GIT_ERROR_ODB,
GITERR_INDEX, GIT_ERROR_INDEX,
GITERR_OBJECT, GIT_ERROR_OBJECT,
GITERR_NET, GIT_ERROR_NET,
GITERR_TAG, GIT_ERROR_TAG,
GITERR_TREE, GIT_ERROR_TREE,
GITERR_INDEXER, GIT_ERROR_INDEXER,
GITERR_SSL, GIT_ERROR_SSL,
GITERR_SUBMODULE, GIT_ERROR_SUBMODULE,
GITERR_THREAD, GIT_ERROR_THREAD,
GITERR_STASH, GIT_ERROR_STASH,
GITERR_CHECKOUT, GIT_ERROR_CHECKOUT,
GITERR_FETCHHEAD, GIT_ERROR_FETCHHEAD,
GITERR_MERGE, GIT_ERROR_MERGE,
GITERR_SSH, GIT_ERROR_SSH,
GITERR_FILTER, GIT_ERROR_FILTER,
GITERR_REVERT, GIT_ERROR_REVERT,
GITERR_CALLBACK, GIT_ERROR_CALLBACK,
GITERR_CHERRYPICK, GIT_ERROR_CHERRYPICK,
GITERR_DESCRIBE, GIT_ERROR_DESCRIBE,
GITERR_REBASE, GIT_ERROR_REBASE,
GITERR_FILESYSTEM, GIT_ERROR_FILESYSTEM,
GITERR_PATCH, GIT_ERROR_PATCH,
GITERR_WORKTREE, GIT_ERROR_WORKTREE,
GITERR_SHA1 GIT_ERROR_SHA1
} git_error_t; } git_error_t;
/** @name Error Functions
*
* These functions report or set error information.
*/
/**@{*/
/** /**
* Return the last `git_error` object that was generated for the * Return the last `git_error` object that was generated for the
* current thread. * current thread.
...@@ -120,12 +126,12 @@ typedef enum { ...@@ -120,12 +126,12 @@ typedef enum {
* *
* @return A git_error object. * @return A git_error object.
*/ */
GIT_EXTERN(const git_error *) giterr_last(void); GIT_EXTERN(const git_error *) git_error_last(void);
/** /**
* Clear the last library error that occurred for this thread. * Clear the last library error that occurred for this thread.
*/ */
GIT_EXTERN(void) giterr_clear(void); GIT_EXTERN(void) git_error_clear(void);
/** /**
* Set the error message string for this thread. * Set the error message string for this thread.
...@@ -143,18 +149,100 @@ GIT_EXTERN(void) giterr_clear(void); ...@@ -143,18 +149,100 @@ GIT_EXTERN(void) giterr_clear(void);
* general subsystem that is responsible for the error. * general subsystem that is responsible for the error.
* @param string The formatted error message to keep * @param string The formatted error message to keep
*/ */
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string); GIT_EXTERN(void) git_error_set_str(int error_class, const char *string);
/** /**
* Set the error message to a special value for memory allocation failure. * Set the error message to a special value for memory allocation failure.
* *
* The normal `giterr_set_str()` function attempts to `strdup()` the string * The normal `git_error_set_str()` function attempts to `strdup()` the
* that is passed in. This is not a good idea when the error in question * string that is passed in. This is not a good idea when the error in
* is a memory allocation failure. That circumstance has a special setter * question is a memory allocation failure. That circumstance has a
* function that sets the error string to a known and statically allocated * special setter function that sets the error string to a known and
* internal value. * statically allocated internal value.
*/
GIT_EXTERN(void) git_error_set_oom(void);
/**@}*/
/** @name Deprecated Error Functions
*
* These functions and enumeration values are retained for backward
* compatibility. The newer versions of these functions should be
* preferred in all new code.
*/
/**@{*/
GIT_DEPRECATED(static const int) GITERR_NONE = GIT_ERROR_NONE;
GIT_DEPRECATED(static const int) GITERR_NOMEMORY = GIT_ERROR_NOMEMORY;
GIT_DEPRECATED(static const int) GITERR_OS = GIT_ERROR_OS;
GIT_DEPRECATED(static const int) GITERR_INVALID = GIT_ERROR_INVALID;
GIT_DEPRECATED(static const int) GITERR_REFERENCE = GIT_ERROR_REFERENCE;
GIT_DEPRECATED(static const int) GITERR_ZLIB = GIT_ERROR_ZLIB;
GIT_DEPRECATED(static const int) GITERR_REPOSITORY = GIT_ERROR_REPOSITORY;
GIT_DEPRECATED(static const int) GITERR_CONFIG = GIT_ERROR_CONFIG;
GIT_DEPRECATED(static const int) GITERR_REGEX = GIT_ERROR_REGEX;
GIT_DEPRECATED(static const int) GITERR_ODB = GIT_ERROR_ODB;
GIT_DEPRECATED(static const int) GITERR_INDEX = GIT_ERROR_INDEX;
GIT_DEPRECATED(static const int) GITERR_OBJECT = GIT_ERROR_OBJECT;
GIT_DEPRECATED(static const int) GITERR_NET = GIT_ERROR_NET;
GIT_DEPRECATED(static const int) GITERR_TAG = GIT_ERROR_TAG;
GIT_DEPRECATED(static const int) GITERR_TREE = GIT_ERROR_TREE;
GIT_DEPRECATED(static const int) GITERR_INDEXER = GIT_ERROR_INDEXER;
GIT_DEPRECATED(static const int) GITERR_SSL = GIT_ERROR_SSL;
GIT_DEPRECATED(static const int) GITERR_SUBMODULE = GIT_ERROR_SUBMODULE;
GIT_DEPRECATED(static const int) GITERR_THREAD = GIT_ERROR_THREAD;
GIT_DEPRECATED(static const int) GITERR_STASH = GIT_ERROR_STASH;
GIT_DEPRECATED(static const int) GITERR_CHECKOUT = GIT_ERROR_CHECKOUT;
GIT_DEPRECATED(static const int) GITERR_FETCHHEAD = GIT_ERROR_FETCHHEAD;
GIT_DEPRECATED(static const int) GITERR_MERGE = GIT_ERROR_MERGE;
GIT_DEPRECATED(static const int) GITERR_SSH = GIT_ERROR_SSH;
GIT_DEPRECATED(static const int) GITERR_FILTER = GIT_ERROR_FILTER;
GIT_DEPRECATED(static const int) GITERR_REVERT = GIT_ERROR_REVERT;
GIT_DEPRECATED(static const int) GITERR_CALLBACK = GIT_ERROR_CALLBACK;
GIT_DEPRECATED(static const int) GITERR_CHERRYPICK = GIT_ERROR_CHERRYPICK;
GIT_DEPRECATED(static const int) GITERR_DESCRIBE = GIT_ERROR_DESCRIBE;
GIT_DEPRECATED(static const int) GITERR_REBASE = GIT_ERROR_REBASE;
GIT_DEPRECATED(static const int) GITERR_FILESYSTEM = GIT_ERROR_FILESYSTEM;
GIT_DEPRECATED(static const int) GITERR_PATCH = GIT_ERROR_PATCH;
GIT_DEPRECATED(static const int) GITERR_WORKTREE = GIT_ERROR_WORKTREE;
GIT_DEPRECATED(static const int) GITERR_SHA1 = GIT_ERROR_SHA1;
/**
* Return the last `git_error` object that was generated for the
* current thread. This function is deprecated and will be removed
* in a future release; `git_error_last` should be used instead.
*
* @see git_error_last
*/ */
GIT_EXTERN(void) giterr_set_oom(void); GIT_DEPRECATED(GIT_EXTERN(const git_error *)) giterr_last(void);
/**
* Clear the last error. This function is deprecated and will be
* removed in a future release; `giterr_clear` should be used instead.
*
* @see git_error_last
*/
GIT_DEPRECATED(GIT_EXTERN(void)) giterr_clear(void);
/**
* Sets the error message to the given string. This function is
* deprecated and will be removed in a future release; `giterr_clear`
* should be used instead.
*
* @see git_error_set_str
*/
GIT_DEPRECATED(GIT_EXTERN(void)) giterr_set_str(int error_class, const char *string);
/**
* Indicates that an out-of-memory situation occured. This function
* is deprecated and will be removed in a future release; `giterr_clear`
* should be used instead.
*
* @see git_error_set_oom
*/
GIT_DEPRECATED(GIT_EXTERN(void)) giterr_set_oom(void);
/**@}*/
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -246,7 +246,7 @@ GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length); ...@@ -246,7 +246,7 @@ GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
* memory-efficient. * memory-efficient.
* *
* Attempting to add more than those OIDs will result in a * Attempting to add more than those OIDs will result in a
* GITERR_INVALID error * GIT_ERROR_INVALID error
* *
* @param os a `git_oid_shorten` instance * @param os a `git_oid_shorten` instance
* @param text_id an OID in text form * @param text_id an OID in text form
......
...@@ -133,7 +133,7 @@ typedef struct git_submodule_update_options { ...@@ -133,7 +133,7 @@ typedef struct git_submodule_update_options {
* checkout, set the `checkout_strategy` to * checkout, set the `checkout_strategy` to
* `GIT_CHECKOUT_NONE`. Generally you will want the use * `GIT_CHECKOUT_NONE`. Generally you will want the use
* GIT_CHECKOUT_SAFE to update files in the working * GIT_CHECKOUT_SAFE to update files in the working
* directory. * directory.
*/ */
git_checkout_options checkout_opts; git_checkout_options checkout_opts;
...@@ -187,7 +187,7 @@ GIT_EXTERN(int) git_submodule_update_init_options( ...@@ -187,7 +187,7 @@ GIT_EXTERN(int) git_submodule_update_init_options(
* function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed. * function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed.
* @return 0 on success, any non-zero return value from a callback * @return 0 on success, any non-zero return value from a callback
* function, or a negative value to indicate an error (use * function, or a negative value to indicate an error (use
* `giterr_last` for a detailed error message). * `git_error_last` for a detailed error message).
*/ */
GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options); GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options);
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
} }
{ {
ignore-giterr-set-leak ignore-giterror-set-leak
Memcheck:Leak Memcheck:Leak
... ...
fun:giterr_set fun:giterror_set
} }
{ {
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#nodef GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); } #nodef GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); }
#nodef GITERR_CHECK_ALLOC_BUF(buf) if (buf == NULL || git_buf_oom(buf)) { __coverity_panic__(); } #nodef GIT_ERROR_CHECK_ALLOC_BUF(buf) if (buf == NULL || git_buf_oom(buf)) { __coverity_panic__(); }
#nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \ #nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \
if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); } if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#nodef GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \ #nodef GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { __coverity_panic__(); } if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { __coverity_panic__(); }
#nodef GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) { __coverity_panic__(); } #nodef GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) { __coverity_panic__(); }
#nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':') #nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':')
......
...@@ -49,7 +49,7 @@ int git_allocator_setup(git_allocator *allocator) ...@@ -49,7 +49,7 @@ int git_allocator_setup(git_allocator *allocator)
int git_win32_crtdbg_init_allocator(git_allocator *allocator) int git_win32_crtdbg_init_allocator(git_allocator *allocator)
{ {
GIT_UNUSED(allocator); GIT_UNUSED(allocator);
giterr_set(GIT_EINVALID, "crtdbg memory allocator not available"); git_error_set(GIT_EINVALID, "crtdbg memory allocator not available");
return -1; return -1;
} }
#endif #endif
...@@ -31,7 +31,7 @@ static int annotated_commit_init( ...@@ -31,7 +31,7 @@ static int annotated_commit_init(
*out = NULL; *out = NULL;
annotated_commit = git__calloc(1, sizeof(git_annotated_commit)); annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
GITERR_CHECK_ALLOC(annotated_commit); GIT_ERROR_CHECK_ALLOC(annotated_commit);
annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL; annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL;
...@@ -45,7 +45,7 @@ static int annotated_commit_init( ...@@ -45,7 +45,7 @@ static int annotated_commit_init(
description = annotated_commit->id_str; description = annotated_commit->id_str;
annotated_commit->description = git__strdup(description); annotated_commit->description = git__strdup(description);
GITERR_CHECK_ALLOC(annotated_commit->description); GIT_ERROR_CHECK_ALLOC(annotated_commit->description);
done: done:
if (!error) if (!error)
...@@ -140,7 +140,7 @@ int git_annotated_commit_from_ref( ...@@ -140,7 +140,7 @@ int git_annotated_commit_from_ref(
if (!error) { if (!error) {
(*out)->ref_name = git__strdup(git_reference_name(ref)); (*out)->ref_name = git__strdup(git_reference_name(ref));
GITERR_CHECK_ALLOC((*out)->ref_name); GIT_ERROR_CHECK_ALLOC((*out)->ref_name);
} }
git_object_free(peeled); git_object_free(peeled);
...@@ -180,10 +180,10 @@ int git_annotated_commit_from_fetchhead( ...@@ -180,10 +180,10 @@ int git_annotated_commit_from_fetchhead(
return -1; return -1;
(*out)->ref_name = git__strdup(branch_name); (*out)->ref_name = git__strdup(branch_name);
GITERR_CHECK_ALLOC((*out)->ref_name); GIT_ERROR_CHECK_ALLOC((*out)->ref_name);
(*out)->remote_url = git__strdup(remote_url); (*out)->remote_url = git__strdup(remote_url);
GITERR_CHECK_ALLOC((*out)->remote_url); GIT_ERROR_CHECK_ALLOC((*out)->remote_url);
return 0; return 0;
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "index.h" #include "index.h"
#define apply_err(...) \ #define apply_err(...) \
( giterr_set(GITERR_PATCH, __VA_ARGS__), GIT_EAPPLYFAIL ) ( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), GIT_EAPPLYFAIL )
typedef struct { typedef struct {
/* The lines that we allocate ourself are allocated out of the pool. /* The lines that we allocate ourself are allocated out of the pool.
...@@ -68,7 +68,7 @@ static int patch_image_init_fromstr( ...@@ -68,7 +68,7 @@ static int patch_image_init_fromstr(
end++; end++;
line = git_pool_mallocz(&out->pool, 1); line = git_pool_mallocz(&out->pool, 1);
GITERR_CHECK_ALLOC(line); GIT_ERROR_CHECK_ALLOC(line);
if (git_vector_insert(&out->lines, line) < 0) if (git_vector_insert(&out->lines, line) < 0)
return -1; return -1;
...@@ -155,7 +155,7 @@ static int update_hunk( ...@@ -155,7 +155,7 @@ static int update_hunk(
&image->lines, linenum, (prelen - postlen)); &image->lines, linenum, (prelen - postlen));
if (error) { if (error) {
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
} }
...@@ -483,7 +483,7 @@ static int apply_one( ...@@ -483,7 +483,7 @@ static int apply_one(
postimage_reader, delta->old_file.path)) == 0) { postimage_reader, delta->old_file.path)) == 0) {
skip_preimage = true; skip_preimage = true;
} else if (error == GIT_ENOTFOUND) { } else if (error == GIT_ENOTFOUND) {
giterr_clear(); git_error_clear();
error = 0; error = 0;
} else { } else {
goto done; goto done;
...@@ -777,7 +777,7 @@ int git_apply( ...@@ -777,7 +777,7 @@ int git_apply(
assert(repo && diff); assert(repo && diff);
GITERR_CHECK_VERSION( GIT_ERROR_CHECK_VERSION(
given_opts, GIT_APPLY_OPTIONS_VERSION, "git_apply_options"); given_opts, GIT_APPLY_OPTIONS_VERSION, "git_apply_options");
if (given_opts) if (given_opts)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* git_array_t(int) my_ints = GIT_ARRAY_INIT; * git_array_t(int) my_ints = GIT_ARRAY_INIT;
* ... * ...
* int *i = git_array_alloc(my_ints); * int *i = git_array_alloc(my_ints);
* GITERR_CHECK_ALLOC(i); * GIT_ERROR_CHECK_ALLOC(i);
* ... * ...
* git_array_clear(my_ints); * git_array_clear(my_ints);
* *
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#define git_array_clear(a) \ #define git_array_clear(a) \
do { git__free((a).ptr); git_array_init(a); } while (0) do { git__free((a).ptr); git_array_init(a); } while (0)
#define GITERR_CHECK_ARRAY(a) GITERR_CHECK_ALLOC((a).ptr) #define GIT_ERROR_CHECK_ARRAY(a) GIT_ERROR_CHECK_ALLOC((a).ptr)
typedef git_array_t(char) git_array_generic_t; typedef git_array_t(char) git_array_generic_t;
......
...@@ -135,7 +135,7 @@ int git_attr_get_many_with_session( ...@@ -135,7 +135,7 @@ int git_attr_get_many_with_session(
goto cleanup; goto cleanup;
info = git__calloc(num_attr, sizeof(attr_get_many_info)); info = git__calloc(num_attr, sizeof(attr_get_many_info));
GITERR_CHECK_ALLOC(info); GIT_ERROR_CHECK_ALLOC(info);
git_vector_foreach(&files, i, file) { git_vector_foreach(&files, i, file) {
...@@ -233,7 +233,7 @@ int git_attr_foreach( ...@@ -233,7 +233,7 @@ int git_attr_foreach(
error = callback(assign->name, assign->value, payload); error = callback(assign->name, assign->value, payload);
if (error) { if (error) {
giterr_set_after_callback(error); git_error_set_after_callback(error);
goto cleanup; goto cleanup;
} }
} }
...@@ -277,7 +277,7 @@ static int system_attr_file( ...@@ -277,7 +277,7 @@ static int system_attr_file(
error = git_sysdir_find_system_file(out, GIT_ATTR_FILE_SYSTEM); error = git_sysdir_find_system_file(out, GIT_ATTR_FILE_SYSTEM);
if (error == GIT_ENOTFOUND) if (error == GIT_ENOTFOUND)
giterr_clear(); git_error_clear();
return error; return error;
} }
...@@ -286,7 +286,7 @@ static int system_attr_file( ...@@ -286,7 +286,7 @@ static int system_attr_file(
error = git_sysdir_find_system_file(&attr_session->sysdir, GIT_ATTR_FILE_SYSTEM); error = git_sysdir_find_system_file(&attr_session->sysdir, GIT_ATTR_FILE_SYSTEM);
if (error == GIT_ENOTFOUND) if (error == GIT_ENOTFOUND)
giterr_clear(); git_error_clear();
else if (error) else if (error)
return error; return error;
...@@ -377,12 +377,12 @@ int git_attr_add_macro( ...@@ -377,12 +377,12 @@ int git_attr_add_macro(
return error; return error;
macro = git__calloc(1, sizeof(git_attr_rule)); macro = git__calloc(1, sizeof(git_attr_rule));
GITERR_CHECK_ALLOC(macro); GIT_ERROR_CHECK_ALLOC(macro);
pool = &git_repository_attr_cache(repo)->pool; pool = &git_repository_attr_cache(repo)->pool;
macro->match.pattern = git_pool_strdup(pool, name); macro->match.pattern = git_pool_strdup(pool, name);
GITERR_CHECK_ALLOC(macro->match.pattern); GIT_ERROR_CHECK_ALLOC(macro->match.pattern);
macro->match.length = strlen(macro->match.pattern); macro->match.length = strlen(macro->match.pattern);
macro->match.flags = GIT_ATTR_FNMATCH_MACRO; macro->match.flags = GIT_ATTR_FNMATCH_MACRO;
...@@ -532,7 +532,7 @@ static int collect_attr_files( ...@@ -532,7 +532,7 @@ static int collect_attr_files(
info.flags = flags; info.flags = flags;
info.workdir = workdir; info.workdir = workdir;
if (git_repository_index__weakptr(&info.index, repo) < 0) if (git_repository_index__weakptr(&info.index, repo) < 0)
giterr_clear(); /* no error even if there is no index */ git_error_clear(); /* no error even if there is no index */
info.files = files; info.files = files;
if (!strcmp(dir.ptr, ".")) if (!strcmp(dir.ptr, "."))
......
...@@ -34,10 +34,10 @@ int git_attr_file__new( ...@@ -34,10 +34,10 @@ int git_attr_file__new(
git_attr_file_source source) git_attr_file_source source)
{ {
git_attr_file *attrs = git__calloc(1, sizeof(git_attr_file)); git_attr_file *attrs = git__calloc(1, sizeof(git_attr_file));
GITERR_CHECK_ALLOC(attrs); GIT_ERROR_CHECK_ALLOC(attrs);
if (git_mutex_init(&attrs->lock) < 0) { if (git_mutex_init(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "failed to initialize lock"); git_error_set(GIT_ERROR_OS, "failed to initialize lock");
git__free(attrs); git__free(attrs);
return -1; return -1;
} }
...@@ -56,7 +56,7 @@ int git_attr_file__clear_rules(git_attr_file *file, bool need_lock) ...@@ -56,7 +56,7 @@ int git_attr_file__clear_rules(git_attr_file *file, bool need_lock)
git_attr_rule *rule; git_attr_rule *rule;
if (need_lock && git_mutex_lock(&file->lock) < 0) { if (need_lock && git_mutex_lock(&file->lock) < 0) {
giterr_set(GITERR_OS, "failed to lock attribute file"); git_error_set(GIT_ERROR_OS, "failed to lock attribute file");
return -1; return -1;
} }
...@@ -147,7 +147,7 @@ int git_attr_file__load( ...@@ -147,7 +147,7 @@ int git_attr_file__load(
break; break;
} }
default: default:
giterr_set(GITERR_INVALID, "unknown file source %d", source); git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source);
return -1; return -1;
} }
...@@ -219,7 +219,7 @@ int git_attr_file__out_of_date( ...@@ -219,7 +219,7 @@ int git_attr_file__out_of_date(
} }
default: default:
giterr_set(GITERR_INVALID, "invalid file type %d", file->source); git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source);
return -1; return -1;
} }
} }
...@@ -245,7 +245,7 @@ int git_attr_file__parse_buffer( ...@@ -245,7 +245,7 @@ int git_attr_file__parse_buffer(
context = attrs->entry->path; context = attrs->entry->path;
if (git_mutex_lock(&attrs->lock) < 0) { if (git_mutex_lock(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "failed to lock attribute file"); git_error_set(GIT_ERROR_OS, "failed to lock attribute file");
return -1; return -1;
} }
...@@ -751,7 +751,7 @@ int git_attr_assignment__parse( ...@@ -751,7 +751,7 @@ int git_attr_assignment__parse(
/* allocate assign if needed */ /* allocate assign if needed */
if (!assign) { if (!assign) {
assign = git__calloc(1, sizeof(git_attr_assignment)); assign = git__calloc(1, sizeof(git_attr_assignment));
GITERR_CHECK_ALLOC(assign); GIT_ERROR_CHECK_ALLOC(assign);
GIT_REFCOUNT_INC(assign); GIT_REFCOUNT_INC(assign);
} }
...@@ -785,7 +785,7 @@ int git_attr_assignment__parse( ...@@ -785,7 +785,7 @@ int git_attr_assignment__parse(
/* allocate permanent storage for name */ /* allocate permanent storage for name */
assign->name = git_pool_strndup(pool, name_start, scan - name_start); assign->name = git_pool_strndup(pool, name_start, scan - name_start);
GITERR_CHECK_ALLOC(assign->name); GIT_ERROR_CHECK_ALLOC(assign->name);
/* if there is an equals sign, find the value */ /* if there is an equals sign, find the value */
if (*scan == '=') { if (*scan == '=') {
...@@ -794,7 +794,7 @@ int git_attr_assignment__parse( ...@@ -794,7 +794,7 @@ int git_attr_assignment__parse(
/* if we found a value, allocate permanent storage for it */ /* if we found a value, allocate permanent storage for it */
if (scan > value_start) { if (scan > value_start) {
assign->value = git_pool_strndup(pool, value_start, scan - value_start); assign->value = git_pool_strndup(pool, value_start, scan - value_start);
GITERR_CHECK_ALLOC(assign->value); GIT_ERROR_CHECK_ALLOC(assign->value);
} }
} }
......
...@@ -18,7 +18,7 @@ GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) ...@@ -18,7 +18,7 @@ GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
GIT_UNUSED(cache); /* avoid warning if threading is off */ GIT_UNUSED(cache); /* avoid warning if threading is off */
if (git_mutex_lock(&cache->lock) < 0) { if (git_mutex_lock(&cache->lock) < 0) {
giterr_set(GITERR_OS, "unable to get attr cache lock"); git_error_set(GIT_ERROR_OS, "unable to get attr cache lock");
return -1; return -1;
} }
return 0; return 0;
...@@ -60,7 +60,7 @@ int git_attr_cache__alloc_file_entry( ...@@ -60,7 +60,7 @@ int git_attr_cache__alloc_file_entry(
} }
ce = git_pool_mallocz(pool, (uint32_t)cachesize); ce = git_pool_mallocz(pool, (uint32_t)cachesize);
GITERR_CHECK_ALLOC(ce); GIT_ERROR_CHECK_ALLOC(ce);
if (baselen) { if (baselen) {
memcpy(ce->fullpath, base, baselen); memcpy(ce->fullpath, base, baselen);
...@@ -250,7 +250,7 @@ int git_attr_cache__get( ...@@ -250,7 +250,7 @@ int git_attr_cache__get(
} }
/* no error if file simply doesn't exist */ /* no error if file simply doesn't exist */
if (error == GIT_ENOTFOUND) { if (error == GIT_ENOTFOUND) {
giterr_clear(); git_error_clear();
error = 0; error = 0;
} }
} }
...@@ -374,11 +374,11 @@ int git_attr_cache__init(git_repository *repo) ...@@ -374,11 +374,11 @@ int git_attr_cache__init(git_repository *repo)
return 0; return 0;
cache = git__calloc(1, sizeof(git_attr_cache)); cache = git__calloc(1, sizeof(git_attr_cache));
GITERR_CHECK_ALLOC(cache); GIT_ERROR_CHECK_ALLOC(cache);
/* set up lock */ /* set up lock */
if (git_mutex_init(&cache->lock) < 0) { if (git_mutex_init(&cache->lock) < 0) {
giterr_set(GITERR_OS, "unable to initialize lock for attr cache"); git_error_set(GIT_ERROR_OS, "unable to initialize lock for attr cache");
git__free(cache); git__free(cache);
return -1; return -1;
} }
...@@ -443,7 +443,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro) ...@@ -443,7 +443,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
return 0; return 0;
if (attr_cache_lock(cache) < 0) { if (attr_cache_lock(cache) < 0) {
giterr_set(GITERR_OS, "unable to get attr cache lock"); git_error_set(GIT_ERROR_OS, "unable to get attr cache lock");
error = -1; error = -1;
} else { } else {
git_strmap_insert(macros, macro->match.pattern, macro, &error); git_strmap_insert(macros, macro->match.pattern, macro, &error);
......
...@@ -272,7 +272,7 @@ static int index_blob_lines(git_blame *blame) ...@@ -272,7 +272,7 @@ static int index_blob_lines(git_blame *blame)
while (len--) { while (len--) {
if (bol) { if (bol) {
i = git_array_alloc(blame->line_index); i = git_array_alloc(blame->line_index);
GITERR_CHECK_ALLOC(i); GIT_ERROR_CHECK_ALLOC(i);
*i = buf - blame->final_buf; *i = buf - blame->final_buf;
bol = 0; bol = 0;
} }
...@@ -282,7 +282,7 @@ static int index_blob_lines(git_blame *blame) ...@@ -282,7 +282,7 @@ static int index_blob_lines(git_blame *blame)
} }
} }
i = git_array_alloc(blame->line_index); i = git_array_alloc(blame->line_index);
GITERR_CHECK_ALLOC(i); GIT_ERROR_CHECK_ALLOC(i);
*i = buf - blame->final_buf; *i = buf - blame->final_buf;
blame->num_lines = num + incomplete; blame->num_lines = num + incomplete;
return blame->num_lines; return blame->num_lines;
...@@ -334,7 +334,7 @@ static int blame_internal(git_blame *blame) ...@@ -334,7 +334,7 @@ static int blame_internal(git_blame *blame)
blame->final_buf_size = git_blob_rawsize(blame->final_blob); blame->final_buf_size = git_blob_rawsize(blame->final_blob);
ent = git__calloc(1, sizeof(git_blame__entry)); ent = git__calloc(1, sizeof(git_blame__entry));
GITERR_CHECK_ALLOC(ent); GIT_ERROR_CHECK_ALLOC(ent);
ent->num_lines = index_blob_lines(blame); ent->num_lines = index_blob_lines(blame);
ent->lno = blame->options.min_line - 1; ent->lno = blame->options.min_line - 1;
...@@ -381,7 +381,7 @@ int git_blame_file( ...@@ -381,7 +381,7 @@ int git_blame_file(
goto on_error; goto on_error;
blame = git_blame__alloc(repo, normOptions, path); blame = git_blame__alloc(repo, normOptions, path);
GITERR_CHECK_ALLOC(blame); GIT_ERROR_CHECK_ALLOC(blame);
if ((error = load_blob(blame)) < 0) if ((error = load_blob(blame)) < 0)
goto on_error; goto on_error;
...@@ -423,14 +423,14 @@ static int buffer_hunk_cb( ...@@ -423,14 +423,14 @@ static int buffer_hunk_cb(
if (!blame->current_hunk) { if (!blame->current_hunk) {
/* Line added at the end of the file */ /* Line added at the end of the file */
blame->current_hunk = new_hunk(wedge_line, 0, wedge_line, blame->path); blame->current_hunk = new_hunk(wedge_line, 0, wedge_line, blame->path);
GITERR_CHECK_ALLOC(blame->current_hunk); GIT_ERROR_CHECK_ALLOC(blame->current_hunk);
git_vector_insert(&blame->hunks, blame->current_hunk); git_vector_insert(&blame->hunks, blame->current_hunk);
} else if (!hunk_starts_at_or_after_line(blame->current_hunk, wedge_line)){ } else if (!hunk_starts_at_or_after_line(blame->current_hunk, wedge_line)){
/* If this hunk doesn't start between existing hunks, split a hunk up so it does */ /* If this hunk doesn't start between existing hunks, split a hunk up so it does */
blame->current_hunk = split_hunk_in_vector(&blame->hunks, blame->current_hunk, blame->current_hunk = split_hunk_in_vector(&blame->hunks, blame->current_hunk,
wedge_line - blame->current_hunk->orig_start_line_number, true); wedge_line - blame->current_hunk->orig_start_line_number, true);
GITERR_CHECK_ALLOC(blame->current_hunk); GIT_ERROR_CHECK_ALLOC(blame->current_hunk);
} }
return 0; return 0;
...@@ -459,7 +459,7 @@ static int buffer_line_cb( ...@@ -459,7 +459,7 @@ static int buffer_line_cb(
/* Create a new buffer-blame hunk with this line */ /* Create a new buffer-blame hunk with this line */
shift_hunks_by(&blame->hunks, blame->current_diff_line, 1); shift_hunks_by(&blame->hunks, blame->current_diff_line, 1);
blame->current_hunk = new_hunk(blame->current_diff_line, 1, 0, blame->path); blame->current_hunk = new_hunk(blame->current_diff_line, 1, 0, blame->path);
GITERR_CHECK_ALLOC(blame->current_hunk); GIT_ERROR_CHECK_ALLOC(blame->current_hunk);
git_vector_insert_sorted(&blame->hunks, blame->current_hunk, NULL); git_vector_insert_sorted(&blame->hunks, blame->current_hunk, NULL);
} }
...@@ -500,12 +500,12 @@ int git_blame_buffer( ...@@ -500,12 +500,12 @@ int git_blame_buffer(
assert(out && reference && buffer && buffer_len); assert(out && reference && buffer && buffer_len);
blame = git_blame__alloc(reference->repository, reference->options, reference->path); blame = git_blame__alloc(reference->repository, reference->options, reference->path);
GITERR_CHECK_ALLOC(blame); GIT_ERROR_CHECK_ALLOC(blame);
/* Duplicate all of the hunk structures in the reference blame */ /* Duplicate all of the hunk structures in the reference blame */
git_vector_foreach(&reference->hunks, i, hunk) { git_vector_foreach(&reference->hunks, i, hunk) {
git_blame_hunk *h = dup_hunk(hunk); git_blame_hunk *h = dup_hunk(hunk);
GITERR_CHECK_ALLOC(h); GIT_ERROR_CHECK_ALLOC(h);
git_vector_insert(&blame->hunks, h); git_vector_insert(&blame->hunks, h);
} }
......
...@@ -46,10 +46,10 @@ static int make_origin(git_blame__origin **out, git_commit *commit, const char * ...@@ -46,10 +46,10 @@ static int make_origin(git_blame__origin **out, git_commit *commit, const char *
path, GIT_OBJECT_BLOB)) < 0) path, GIT_OBJECT_BLOB)) < 0)
return error; return error;
GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*o), path_len); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*o), path_len);
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
o = git__calloc(1, alloc_len); o = git__calloc(1, alloc_len);
GITERR_CHECK_ALLOC(o); GIT_ERROR_CHECK_ALLOC(o);
o->commit = commit; o->commit = commit;
o->blob = (git_blob *) blob; o->blob = (git_blob *) blob;
...@@ -365,7 +365,7 @@ static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data) ...@@ -365,7 +365,7 @@ static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data)
if (file_a.size > GIT_XDIFF_MAX_SIZE || if (file_a.size > GIT_XDIFF_MAX_SIZE ||
file_b.size > GIT_XDIFF_MAX_SIZE) { file_b.size > GIT_XDIFF_MAX_SIZE) {
giterr_set(GITERR_INVALID, "file too large to blame"); git_error_set(GIT_ERROR_INVALID, "file too large to blame");
return -1; return -1;
} }
...@@ -522,7 +522,7 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt) ...@@ -522,7 +522,7 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
memset(sg_buf, 0, sizeof(sg_buf)); memset(sg_buf, 0, sizeof(sg_buf));
else { else {
sg_origin = git__calloc(num_parents, sizeof(*sg_origin)); sg_origin = git__calloc(num_parents, sizeof(*sg_origin));
GITERR_CHECK_ALLOC(sg_origin); GIT_ERROR_CHECK_ALLOC(sg_origin);
} }
for (i=0; i<num_parents; i++) { for (i=0; i<num_parents; i++) {
......
...@@ -116,7 +116,7 @@ static int write_file_stream( ...@@ -116,7 +116,7 @@ static int write_file_stream(
p_close(fd); p_close(fd);
if (written != file_size || read_len < 0) { if (written != file_size || read_len < 0) {
giterr_set(GITERR_OS, "failed to read file into stream"); git_error_set(GIT_ERROR_OS, "failed to read file into stream");
error = -1; error = -1;
} }
...@@ -158,11 +158,11 @@ static int write_symlink( ...@@ -158,11 +158,11 @@ static int write_symlink(
int error; int error;
link_data = git__malloc(link_size); link_data = git__malloc(link_size);
GITERR_CHECK_ALLOC(link_data); GIT_ERROR_CHECK_ALLOC(link_data);
read_len = p_readlink(path, link_data, link_size); read_len = p_readlink(path, link_data, link_size);
if (read_len != (ssize_t)link_size) { if (read_len != (ssize_t)link_size) {
giterr_set(GITERR_OS, "failed to create blob: cannot read symlink '%s'", path); git_error_set(GIT_ERROR_OS, "failed to create blob: cannot read symlink '%s'", path);
git__free(link_data); git__free(link_data);
return -1; return -1;
} }
...@@ -206,7 +206,7 @@ int git_blob__create_from_paths( ...@@ -206,7 +206,7 @@ int git_blob__create_from_paths(
goto done; goto done;
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
giterr_set(GITERR_ODB, "cannot create blob from '%s': it is a directory", content_path); git_error_set(GIT_ERROR_ODB, "cannot create blob from '%s': it is a directory", content_path);
error = GIT_EDIRECTORY; error = GIT_EDIRECTORY;
goto done; goto done;
} }
...@@ -334,11 +334,11 @@ int git_blob_create_fromstream(git_writestream **out, git_repository *repo, cons ...@@ -334,11 +334,11 @@ int git_blob_create_fromstream(git_writestream **out, git_repository *repo, cons
assert(out && repo); assert(out && repo);
stream = git__calloc(1, sizeof(blob_writestream)); stream = git__calloc(1, sizeof(blob_writestream));
GITERR_CHECK_ALLOC(stream); GIT_ERROR_CHECK_ALLOC(stream);
if (hintpath) { if (hintpath) {
stream->hintpath = git__strdup(hintpath); stream->hintpath = git__strdup(hintpath);
GITERR_CHECK_ALLOC(stream->hintpath); GIT_ERROR_CHECK_ALLOC(stream->hintpath);
} }
stream->repo = repo; stream->repo = repo;
......
...@@ -34,8 +34,8 @@ static int retrieve_branch_reference( ...@@ -34,8 +34,8 @@ static int retrieve_branch_reference(
if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0) if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0)
/* OOM */; /* OOM */;
else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0) else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
giterr_set( git_error_set(
GITERR_REFERENCE, "cannot locate %s branch '%s'", GIT_ERROR_REFERENCE, "cannot locate %s branch '%s'",
is_remote ? "remote-tracking" : "local", branch_name); is_remote ? "remote-tracking" : "local", branch_name);
*branch_reference_out = branch; /* will be NULL on error */ *branch_reference_out = branch; /* will be NULL on error */
...@@ -46,8 +46,8 @@ static int retrieve_branch_reference( ...@@ -46,8 +46,8 @@ static int retrieve_branch_reference(
static int not_a_local_branch(const char *reference_name) static int not_a_local_branch(const char *reference_name)
{ {
giterr_set( git_error_set(
GITERR_INVALID, GIT_ERROR_INVALID,
"reference '%s' is not a local branch.", reference_name); "reference '%s' is not a local branch.", reference_name);
return -1; return -1;
} }
...@@ -71,7 +71,7 @@ static int create_branch( ...@@ -71,7 +71,7 @@ static int create_branch(
assert(git_object_owner((const git_object *)commit) == repository); assert(git_object_owner((const git_object *)commit) == repository);
if (!git__strcmp(branch_name, "HEAD")) { if (!git__strcmp(branch_name, "HEAD")) {
giterr_set(GITERR_REFERENCE, "'HEAD' is not a valid branch name"); git_error_set(GIT_ERROR_REFERENCE, "'HEAD' is not a valid branch name");
error = -1; error = -1;
goto cleanup; goto cleanup;
} }
...@@ -88,7 +88,7 @@ static int create_branch( ...@@ -88,7 +88,7 @@ static int create_branch(
} }
if (is_unmovable_head && force) { if (is_unmovable_head && force) {
giterr_set(GITERR_REFERENCE, "cannot force update branch '%s' as it is " git_error_set(GIT_ERROR_REFERENCE, "cannot force update branch '%s' as it is "
"the current HEAD of the repository.", branch_name); "the current HEAD of the repository.", branch_name);
error = -1; error = -1;
goto cleanup; goto cleanup;
...@@ -168,7 +168,7 @@ int git_branch_delete(git_reference *branch) ...@@ -168,7 +168,7 @@ int git_branch_delete(git_reference *branch)
assert(branch); assert(branch);
if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) { if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) {
giterr_set(GITERR_INVALID, "reference '%s' is not a valid branch.", git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a valid branch.",
git_reference_name(branch)); git_reference_name(branch));
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -177,13 +177,13 @@ int git_branch_delete(git_reference *branch) ...@@ -177,13 +177,13 @@ int git_branch_delete(git_reference *branch)
return is_head; return is_head;
if (is_head) { if (is_head) {
giterr_set(GITERR_REFERENCE, "cannot delete branch '%s' as it is " git_error_set(GIT_ERROR_REFERENCE, "cannot delete branch '%s' as it is "
"the current HEAD of the repository.", git_reference_name(branch)); "the current HEAD of the repository.", git_reference_name(branch));
return -1; return -1;
} }
if (git_reference_is_branch(branch) && git_branch_is_checked_out(branch)) { if (git_reference_is_branch(branch) && git_branch_is_checked_out(branch)) {
giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is " git_error_set(GIT_ERROR_REFERENCE, "Cannot delete branch '%s' as it is "
"the current HEAD of a linked repository.", git_reference_name(branch)); "the current HEAD of a linked repository.", git_reference_name(branch));
return -1; return -1;
} }
...@@ -243,7 +243,7 @@ int git_branch_iterator_new( ...@@ -243,7 +243,7 @@ int git_branch_iterator_new(
branch_iter *iter; branch_iter *iter;
iter = git__calloc(1, sizeof(branch_iter)); iter = git__calloc(1, sizeof(branch_iter));
GITERR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
iter->flags = list_flags; iter->flags = list_flags;
...@@ -344,7 +344,7 @@ int git_branch_name( ...@@ -344,7 +344,7 @@ int git_branch_name(
} else if (git_reference_is_remote(ref)) { } else if (git_reference_is_remote(ref)) {
branch_name += strlen(GIT_REFS_REMOTES_DIR); branch_name += strlen(GIT_REFS_REMOTES_DIR);
} else { } else {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"reference '%s' is neither a local nor a remote branch.", ref->name); "reference '%s' is neither a local nor a remote branch.", ref->name);
return -1; return -1;
} }
...@@ -402,7 +402,7 @@ int git_branch_upstream_name( ...@@ -402,7 +402,7 @@ int git_branch_upstream_name(
goto cleanup; goto cleanup;
if (git_buf_len(&remote_name) == 0 || git_buf_len(&merge_name) == 0) { if (git_buf_len(&remote_name) == 0 || git_buf_len(&merge_name) == 0) {
giterr_set(GITERR_REFERENCE, git_error_set(GIT_ERROR_REFERENCE,
"branch '%s' does not have an upstream", refname); "branch '%s' does not have an upstream", refname);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
...@@ -452,7 +452,7 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r ...@@ -452,7 +452,7 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r
return error; return error;
if (git_buf_len(buf) == 0) { if (git_buf_len(buf) == 0) {
giterr_set(GITERR_REFERENCE, "branch '%s' does not have an upstream remote", refname); git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream remote", refname);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
git_buf_clear(buf); git_buf_clear(buf);
} }
...@@ -475,7 +475,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna ...@@ -475,7 +475,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
/* Verify that this is a remote branch */ /* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) { if (!git_reference__is_remote(refname)) {
giterr_set(GITERR_INVALID, "reference '%s' is not a remote branch.", git_error_set(GIT_ERROR_INVALID, "reference '%s' is not a remote branch.",
refname); refname);
error = GIT_ERROR; error = GIT_ERROR;
goto cleanup; goto cleanup;
...@@ -501,7 +501,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna ...@@ -501,7 +501,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
} else { } else {
git_remote_free(remote); git_remote_free(remote);
giterr_set(GITERR_REFERENCE, git_error_set(GIT_ERROR_REFERENCE,
"reference '%s' is ambiguous", refname); "reference '%s' is ambiguous", refname);
error = GIT_EAMBIGUOUS; error = GIT_EAMBIGUOUS;
goto cleanup; goto cleanup;
...@@ -515,7 +515,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna ...@@ -515,7 +515,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
git_buf_clear(buf); git_buf_clear(buf);
error = git_buf_puts(buf, remote_name); error = git_buf_puts(buf, remote_name);
} else { } else {
giterr_set(GITERR_REFERENCE, git_error_set(GIT_ERROR_REFERENCE,
"could not determine remote for '%s'", refname); "could not determine remote for '%s'", refname);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
} }
...@@ -604,7 +604,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name) ...@@ -604,7 +604,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
else if (git_branch_lookup(&upstream, repo, upstream_name, GIT_BRANCH_REMOTE) == 0) else if (git_branch_lookup(&upstream, repo, upstream_name, GIT_BRANCH_REMOTE) == 0)
local = 0; local = 0;
else { else {
giterr_set(GITERR_REFERENCE, git_error_set(GIT_ERROR_REFERENCE,
"cannot set upstream for branch '%s'", shortname); "cannot set upstream for branch '%s'", shortname);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
......
...@@ -29,7 +29,7 @@ int git_buf_text_puts_escaped( ...@@ -29,7 +29,7 @@ int git_buf_text_puts_escaped(
scan += count; scan += count;
} }
GITERR_CHECK_ALLOC_ADD(&alloclen, total, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, total, 1);
if (git_buf_grow_by(buf, alloclen) < 0) if (git_buf_grow_by(buf, alloclen) < 0)
return -1; return -1;
...@@ -75,7 +75,7 @@ int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src) ...@@ -75,7 +75,7 @@ int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src)
return git_buf_set(tgt, src->ptr, src->size); return git_buf_set(tgt, src->ptr, src->size);
/* reduce reallocs while in the loop */ /* reduce reallocs while in the loop */
GITERR_CHECK_ALLOC_ADD(&new_size, src->size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, src->size, 1);
if (git_buf_grow(tgt, new_size) < 0) if (git_buf_grow(tgt, new_size) < 0)
return -1; return -1;
...@@ -122,8 +122,8 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src) ...@@ -122,8 +122,8 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
return git_buf_set(tgt, src->ptr, src->size); return git_buf_set(tgt, src->ptr, src->size);
/* attempt to reduce reallocs while in the loop */ /* attempt to reduce reallocs while in the loop */
GITERR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, src->size, src->size >> 4);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
if (git_buf_grow(tgt, alloclen) < 0) if (git_buf_grow(tgt, alloclen) < 0)
return -1; return -1;
tgt->size = 0; tgt->size = 0;
...@@ -135,7 +135,7 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src) ...@@ -135,7 +135,7 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
if (copylen && next[-1] == '\r') if (copylen && next[-1] == '\r')
copylen--; copylen--;
GITERR_CHECK_ALLOC_ADD(&alloclen, copylen, 3); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, copylen, 3);
if (git_buf_grow_by(tgt, alloclen) < 0) if (git_buf_grow_by(tgt, alloclen) < 0)
return -1; return -1;
......
...@@ -43,7 +43,7 @@ int git_buf_try_grow( ...@@ -43,7 +43,7 @@ int git_buf_try_grow(
return -1; return -1;
if (buf->asize == 0 && buf->size != 0) { if (buf->asize == 0 && buf->size != 0) {
giterr_set(GITERR_INVALID, "cannot grow a borrowed buffer"); git_error_set(GIT_ERROR_INVALID, "cannot grow a borrowed buffer");
return GIT_EINVALID; return GIT_EINVALID;
} }
...@@ -73,7 +73,7 @@ int git_buf_try_grow( ...@@ -73,7 +73,7 @@ int git_buf_try_grow(
if (mark_oom) if (mark_oom)
buf->ptr = git_buf__oom; buf->ptr = git_buf__oom;
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
} }
...@@ -161,7 +161,7 @@ int git_buf_set(git_buf *buf, const void *data, size_t len) ...@@ -161,7 +161,7 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
git_buf_clear(buf); git_buf_clear(buf);
} else { } else {
if (data != buf->ptr) { if (data != buf->ptr) {
GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, len, 1);
ENSURE_SIZE(buf, alloclen); ENSURE_SIZE(buf, alloclen);
memmove(buf->ptr, data, len); memmove(buf->ptr, data, len);
} }
...@@ -192,7 +192,7 @@ int git_buf_sets(git_buf *buf, const char *string) ...@@ -192,7 +192,7 @@ int git_buf_sets(git_buf *buf, const char *string)
int git_buf_putc(git_buf *buf, char c) int git_buf_putc(git_buf *buf, char c)
{ {
size_t new_size; size_t new_size;
GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, 2); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, 2);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
buf->ptr[buf->size++] = c; buf->ptr[buf->size++] = c;
buf->ptr[buf->size] = '\0'; buf->ptr[buf->size] = '\0';
...@@ -202,8 +202,8 @@ int git_buf_putc(git_buf *buf, char c) ...@@ -202,8 +202,8 @@ int git_buf_putc(git_buf *buf, char c)
int git_buf_putcn(git_buf *buf, char c, size_t len) int git_buf_putcn(git_buf *buf, char c, size_t len)
{ {
size_t new_size; size_t new_size;
GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
memset(buf->ptr + buf->size, c, len); memset(buf->ptr + buf->size, c, len);
buf->size += len; buf->size += len;
...@@ -218,8 +218,8 @@ int git_buf_put(git_buf *buf, const char *data, size_t len) ...@@ -218,8 +218,8 @@ int git_buf_put(git_buf *buf, const char *data, size_t len)
assert(data); assert(data);
GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
memmove(buf->ptr + buf->size, data, len); memmove(buf->ptr + buf->size, data, len);
buf->size += len; buf->size += len;
...@@ -244,9 +244,9 @@ int git_buf_encode_base64(git_buf *buf, const char *data, size_t len) ...@@ -244,9 +244,9 @@ int git_buf_encode_base64(git_buf *buf, const char *data, size_t len)
const uint8_t *read = (const uint8_t *)data; const uint8_t *read = (const uint8_t *)data;
size_t blocks = (len / 3) + !!extra, alloclen; size_t blocks = (len / 3) + !!extra, alloclen;
GITERR_CHECK_ALLOC_ADD(&blocks, blocks, 1); GIT_ERROR_CHECK_ALLOC_ADD(&blocks, blocks, 1);
GITERR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 4);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
ENSURE_SIZE(buf, alloclen); ENSURE_SIZE(buf, alloclen);
write = (uint8_t *)&buf->ptr[buf->size]; write = (uint8_t *)&buf->ptr[buf->size];
...@@ -306,13 +306,13 @@ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len) ...@@ -306,13 +306,13 @@ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
size_t orig_size = buf->size, new_size; size_t orig_size = buf->size, new_size;
if (len % 4) { if (len % 4) {
giterr_set(GITERR_INVALID, "invalid base64 input"); git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
return -1; return -1;
} }
assert(len % 4 == 0); assert(len % 4 == 0);
GITERR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (len / 4 * 3), buf->size);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
for (i = 0; i < len; i += 4) { for (i = 0; i < len; i += 4) {
...@@ -323,7 +323,7 @@ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len) ...@@ -323,7 +323,7 @@ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
buf->size = orig_size; buf->size = orig_size;
buf->ptr[buf->size] = '\0'; buf->ptr[buf->size] = '\0';
giterr_set(GITERR_INVALID, "invalid base64 input"); git_error_set(GIT_ERROR_INVALID, "invalid base64 input");
return -1; return -1;
} }
...@@ -343,9 +343,9 @@ int git_buf_encode_base85(git_buf *buf, const char *data, size_t len) ...@@ -343,9 +343,9 @@ int git_buf_encode_base85(git_buf *buf, const char *data, size_t len)
{ {
size_t blocks = (len / 4) + !!(len % 4), alloclen; size_t blocks = (len / 4) + !!(len % 4), alloclen;
GITERR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloclen, blocks, 5);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, buf->size);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
ENSURE_SIZE(buf, alloclen); ENSURE_SIZE(buf, alloclen);
...@@ -408,12 +408,12 @@ int git_buf_decode_base85( ...@@ -408,12 +408,12 @@ int git_buf_decode_base85(
if (base85_len % 5 || if (base85_len % 5 ||
output_len > base85_len * 4 / 5) { output_len > base85_len * 4 / 5) {
giterr_set(GITERR_INVALID, "invalid base85 input"); git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
return -1; return -1;
} }
GITERR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, output_len, buf->size);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
while (output_len) { while (output_len) {
...@@ -456,7 +456,7 @@ on_error: ...@@ -456,7 +456,7 @@ on_error:
buf->size = orig_size; buf->size = orig_size;
buf->ptr[buf->size] = '\0'; buf->ptr[buf->size] = '\0';
giterr_set(GITERR_INVALID, "invalid base85 input"); git_error_set(GIT_ERROR_INVALID, "invalid base85 input");
return -1; return -1;
} }
...@@ -469,8 +469,8 @@ int git_buf_decode_percent( ...@@ -469,8 +469,8 @@ int git_buf_decode_percent(
{ {
size_t str_pos, new_size; size_t str_pos, new_size;
GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, str_len);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) { for (str_pos = 0; str_pos < str_len; buf->size++, str_pos++) {
...@@ -495,8 +495,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) ...@@ -495,8 +495,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
size_t expected_size, new_size; size_t expected_size, new_size;
int len; int len;
GITERR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&expected_size, strlen(format), 2);
GITERR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size); GIT_ERROR_CHECK_ALLOC_ADD(&expected_size, expected_size, buf->size);
ENSURE_SIZE(buf, expected_size); ENSURE_SIZE(buf, expected_size);
while (1) { while (1) {
...@@ -522,8 +522,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) ...@@ -522,8 +522,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
break; break;
} }
GITERR_CHECK_ALLOC_ADD(&new_size, buf->size, len); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
GITERR_CHECK_ALLOC_ADD(&new_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
ENSURE_SIZE(buf, new_size); ENSURE_SIZE(buf, new_size);
} }
...@@ -667,10 +667,10 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) ...@@ -667,10 +667,10 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
segment_len = strlen(segment); segment_len = strlen(segment);
GITERR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len); GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, segment_len);
if (segment_len == 0 || segment[segment_len - 1] != separator) if (segment_len == 0 || segment[segment_len - 1] != separator)
GITERR_CHECK_ALLOC_ADD(&total_size, total_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
} }
va_end(ap); va_end(ap);
...@@ -678,7 +678,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) ...@@ -678,7 +678,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
if (total_size == 0) if (total_size == 0)
return 0; return 0;
GITERR_CHECK_ALLOC_ADD(&total_size, total_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&total_size, total_size, 1);
if (git_buf_grow_by(buf, total_size) < 0) if (git_buf_grow_by(buf, total_size) < 0)
return -1; return -1;
...@@ -758,9 +758,9 @@ int git_buf_join( ...@@ -758,9 +758,9 @@ int git_buf_join(
if (str_a >= buf->ptr && str_a < buf->ptr + buf->size) if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
offset_a = str_a - buf->ptr; offset_a = str_a - buf->ptr;
GITERR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
ENSURE_SIZE(buf, alloc_len); ENSURE_SIZE(buf, alloc_len);
/* fix up internal pointers */ /* fix up internal pointers */
...@@ -810,11 +810,11 @@ int git_buf_join3( ...@@ -810,11 +810,11 @@ int git_buf_join3(
sep_b = (str_b[len_b - 1] != separator); sep_b = (str_b[len_b - 1] != separator);
} }
GITERR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a); GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_a, sep_a);
GITERR_CHECK_ALLOC_ADD(&len_total, len_total, len_b); GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_b);
GITERR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b); GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
GITERR_CHECK_ALLOC_ADD(&len_total, len_total, len_c); GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
GITERR_CHECK_ALLOC_ADD(&len_total, len_total, 1); GIT_ERROR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
ENSURE_SIZE(buf, len_total); ENSURE_SIZE(buf, len_total);
tgt = buf->ptr; tgt = buf->ptr;
...@@ -877,8 +877,8 @@ int git_buf_splice( ...@@ -877,8 +877,8 @@ int git_buf_splice(
/* Ported from git.git /* Ported from git.git
* https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176 * https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176
*/ */
GITERR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert); GIT_ERROR_CHECK_ALLOC_ADD(&new_size, (buf->size - nb_to_remove), nb_to_insert);
GITERR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, new_size, 1);
ENSURE_SIZE(buf, alloc_size); ENSURE_SIZE(buf, alloc_size);
memmove(splice_loc + nb_to_insert, memmove(splice_loc + nb_to_insert,
...@@ -995,14 +995,14 @@ int git_buf_unquote(git_buf *buf) ...@@ -995,14 +995,14 @@ int git_buf_unquote(git_buf *buf)
/* \xyz digits convert to the char*/ /* \xyz digits convert to the char*/
case '0': case '1': case '2': case '3': case '0': case '1': case '2': case '3':
if (j == buf->size-3) { if (j == buf->size-3) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"truncated quoted character \\%c", ch); "truncated quoted character \\%c", ch);
return -1; return -1;
} }
if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' || if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') { buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"truncated quoted character \\%c%c%c", "truncated quoted character \\%c%c%c",
buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]); buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]);
return -1; return -1;
...@@ -1015,7 +1015,7 @@ int git_buf_unquote(git_buf *buf) ...@@ -1015,7 +1015,7 @@ int git_buf_unquote(git_buf *buf)
break; break;
default: default:
giterr_set(GITERR_INVALID, "invalid quoted character \\%c", ch); git_error_set(GIT_ERROR_INVALID, "invalid quoted character \\%c", ch);
return -1; return -1;
} }
} }
...@@ -1029,6 +1029,6 @@ int git_buf_unquote(git_buf *buf) ...@@ -1029,6 +1029,6 @@ int git_buf_unquote(git_buf *buf)
return 0; return 0;
invalid: invalid:
giterr_set(GITERR_INVALID, "invalid quoted line"); git_error_set(GIT_ERROR_INVALID, "invalid quoted line");
return -1; return -1;
} }
...@@ -33,7 +33,7 @@ static size_t git_cache__max_object_size[8] = { ...@@ -33,7 +33,7 @@ static size_t git_cache__max_object_size[8] = {
int git_cache_set_max_object_size(git_object_t type, size_t size) int git_cache_set_max_object_size(git_object_t type, size_t size)
{ {
if (type < 0 || (size_t)type >= ARRAY_SIZE(git_cache__max_object_size)) { if (type < 0 || (size_t)type >= ARRAY_SIZE(git_cache__max_object_size)) {
giterr_set(GITERR_INVALID, "type out of range"); git_error_set(GIT_ERROR_INVALID, "type out of range");
return -1; return -1;
} }
...@@ -66,9 +66,9 @@ int git_cache_init(git_cache *cache) ...@@ -66,9 +66,9 @@ int git_cache_init(git_cache *cache)
{ {
memset(cache, 0, sizeof(*cache)); memset(cache, 0, sizeof(*cache));
cache->map = git_oidmap_alloc(); cache->map = git_oidmap_alloc();
GITERR_CHECK_ALLOC(cache->map); GIT_ERROR_CHECK_ALLOC(cache->map);
if (git_rwlock_init(&cache->lock)) { if (git_rwlock_init(&cache->lock)) {
giterr_set(GITERR_OS, "failed to initialize cache rwlock"); git_error_set(GIT_ERROR_OS, "failed to initialize cache rwlock");
return -1; return -1;
} }
return 0; return 0;
......
...@@ -108,7 +108,7 @@ static int cherrypick_seterr(git_commit *commit, const char *fmt) ...@@ -108,7 +108,7 @@ static int cherrypick_seterr(git_commit *commit, const char *fmt)
{ {
char commit_oidstr[GIT_OID_HEXSZ + 1]; char commit_oidstr[GIT_OID_HEXSZ + 1];
giterr_set(GITERR_CHERRYPICK, fmt, git_error_set(GIT_ERROR_CHERRYPICK, fmt,
git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
return -1; return -1;
...@@ -179,7 +179,7 @@ int git_cherrypick( ...@@ -179,7 +179,7 @@ int git_cherrypick(
assert(repo && commit); assert(repo && commit);
GITERR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options"); GIT_ERROR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options");
if ((error = git_repository__ensure_not_bare(repo, "cherry-pick")) < 0) if ((error = git_repository__ensure_not_bare(repo, "cherry-pick")) < 0)
return error; return error;
......
...@@ -176,7 +176,7 @@ static int update_head_to_remote( ...@@ -176,7 +176,7 @@ static int update_head_to_remote(
refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch)); refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch));
if (refspec == NULL) { if (refspec == NULL) {
giterr_set(GITERR_NET, "the remote's default branch does not fit the refspec configuration"); git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration");
error = GIT_EINVALIDSPEC; error = GIT_EINVALIDSPEC;
goto cleanup; goto cleanup;
} }
...@@ -332,7 +332,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch ...@@ -332,7 +332,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
assert(repo && _remote); assert(repo && _remote);
if (!git_repository_is_empty(repo)) { if (!git_repository_is_empty(repo)) {
giterr_set(GITERR_INVALID, "the repository is not empty"); git_error_set(GIT_ERROR_INVALID, "the repository is not empty");
return -1; return -1;
} }
...@@ -400,11 +400,11 @@ int git_clone( ...@@ -400,11 +400,11 @@ int git_clone(
if (_options) if (_options)
memcpy(&options, _options, sizeof(git_clone_options)); memcpy(&options, _options, sizeof(git_clone_options));
GITERR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); GIT_ERROR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options");
/* Only clone to a new directory or an empty directory */ /* Only clone to a new directory or an empty directory */
if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) { if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"'%s' exists and is not an empty directory", local_path); "'%s' exists and is not an empty directory", local_path);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
...@@ -441,14 +441,14 @@ int git_clone( ...@@ -441,14 +441,14 @@ int git_clone(
if (error != 0) { if (error != 0) {
git_error_state last_error = {0}; git_error_state last_error = {0};
giterr_state_capture(&last_error, error); git_error_state_capture(&last_error, error);
git_repository_free(repo); git_repository_free(repo);
repo = NULL; repo = NULL;
(void)git_futils_rmdir_r(local_path, NULL, rmdir_flags); (void)git_futils_rmdir_r(local_path, NULL, rmdir_flags);
giterr_state_restore(&last_error); git_error_state_restore(&last_error);
} }
*out = repo; *out = repo;
...@@ -496,7 +496,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_ ...@@ -496,7 +496,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
assert(repo && remote); assert(repo && remote);
if (!git_repository_is_empty(repo)) { if (!git_repository_is_empty(repo)) {
giterr_set(GITERR_INVALID, "the repository is not empty"); git_error_set(GIT_ERROR_INVALID, "the repository is not empty");
return -1; return -1;
} }
......
...@@ -99,14 +99,14 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r ...@@ -99,14 +99,14 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r
} }
parent_cpy = git_array_alloc(*parents); parent_cpy = git_array_alloc(*parents);
GITERR_CHECK_ALLOC(parent_cpy); GIT_ERROR_CHECK_ALLOC(parent_cpy);
git_oid_cpy(parent_cpy, parent); git_oid_cpy(parent_cpy, parent);
i++; i++;
} }
if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) { if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) {
giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent"); git_error_set(GIT_ERROR_OBJECT, "failed to create commit: current tip is not the first parent");
error = GIT_EMODIFIED; error = GIT_EMODIFIED;
goto on_error; goto on_error;
} }
...@@ -143,7 +143,7 @@ static int git_commit__create_internal( ...@@ -143,7 +143,7 @@ static int git_commit__create_internal(
if (error < 0 && error != GIT_ENOTFOUND) if (error < 0 && error != GIT_ENOTFOUND)
return error; return error;
} }
giterr_clear(); git_error_clear();
if (ref) if (ref)
current_id = git_reference_target(ref); current_id = git_reference_target(ref);
...@@ -351,7 +351,7 @@ int git_commit_amend( ...@@ -351,7 +351,7 @@ int git_commit_amend(
if (!tree) { if (!tree) {
git_tree *old_tree; git_tree *old_tree;
GITERR_CHECK_ERROR( git_commit_tree(&old_tree, commit_to_amend) ); GIT_ERROR_CHECK_ERROR( git_commit_tree(&old_tree, commit_to_amend) );
git_oid_cpy(&tree_id, git_tree_id(old_tree)); git_oid_cpy(&tree_id, git_tree_id(old_tree));
git_tree_free(old_tree); git_tree_free(old_tree);
} else { } else {
...@@ -365,7 +365,7 @@ int git_commit_amend( ...@@ -365,7 +365,7 @@ int git_commit_amend(
if (git_oid_cmp(git_commit_id(commit_to_amend), git_reference_target(ref))) { if (git_oid_cmp(git_commit_id(commit_to_amend), git_reference_target(ref))) {
git_reference_free(ref); git_reference_free(ref);
giterr_set(GITERR_REFERENCE, "commit to amend is not the tip of the given branch"); git_error_set(GIT_ERROR_REFERENCE, "commit to amend is not the tip of the given branch");
return -1; return -1;
} }
} }
...@@ -396,7 +396,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -396,7 +396,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
/* Allocate for one, which will allow not to realloc 90% of the time */ /* Allocate for one, which will allow not to realloc 90% of the time */
git_array_init_to_size(commit->parent_ids, 1); git_array_init_to_size(commit->parent_ids, 1);
GITERR_CHECK_ARRAY(commit->parent_ids); GIT_ERROR_CHECK_ARRAY(commit->parent_ids);
/* The tree is always the first field */ /* The tree is always the first field */
if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0) if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0)
...@@ -408,13 +408,13 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -408,13 +408,13 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) { while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) {
git_oid *new_id = git_array_alloc(commit->parent_ids); git_oid *new_id = git_array_alloc(commit->parent_ids);
GITERR_CHECK_ALLOC(new_id); GIT_ERROR_CHECK_ALLOC(new_id);
git_oid_cpy(new_id, &parent_id); git_oid_cpy(new_id, &parent_id);
} }
commit->author = git__malloc(sizeof(git_signature)); commit->author = git__malloc(sizeof(git_signature));
GITERR_CHECK_ALLOC(commit->author); GIT_ERROR_CHECK_ALLOC(commit->author);
if (git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n') < 0) if (git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n') < 0)
return -1; return -1;
...@@ -430,7 +430,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -430,7 +430,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
/* Always parse the committer; we need the commit time */ /* Always parse the committer; we need the commit time */
commit->committer = git__malloc(sizeof(git_signature)); commit->committer = git__malloc(sizeof(git_signature));
GITERR_CHECK_ALLOC(commit->committer); GIT_ERROR_CHECK_ALLOC(commit->committer);
if (git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n') < 0) if (git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n') < 0)
return -1; return -1;
...@@ -448,7 +448,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -448,7 +448,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
buffer += strlen("encoding "); buffer += strlen("encoding ");
commit->message_encoding = git__strndup(buffer, eoln - buffer); commit->message_encoding = git__strndup(buffer, eoln - buffer);
GITERR_CHECK_ALLOC(commit->message_encoding); GIT_ERROR_CHECK_ALLOC(commit->message_encoding);
} }
if (eoln < buffer_end && *eoln == '\n') if (eoln < buffer_end && *eoln == '\n')
...@@ -458,7 +458,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -458,7 +458,7 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
header_len = buffer - buffer_start; header_len = buffer - buffer_start;
commit->raw_header = git__strndup(buffer_start, header_len); commit->raw_header = git__strndup(buffer_start, header_len);
GITERR_CHECK_ALLOC(commit->raw_header); GIT_ERROR_CHECK_ALLOC(commit->raw_header);
/* point "buffer" to data after header, +1 for the final LF */ /* point "buffer" to data after header, +1 for the final LF */
buffer = buffer_start + header_len + 1; buffer = buffer_start + header_len + 1;
...@@ -468,12 +468,12 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size) ...@@ -468,12 +468,12 @@ int git_commit__parse_raw(void *_commit, const char *data, size_t size)
commit->raw_message = git__strndup(buffer, buffer_end - buffer); commit->raw_message = git__strndup(buffer, buffer_end - buffer);
else else
commit->raw_message = git__strdup(""); commit->raw_message = git__strdup("");
GITERR_CHECK_ALLOC(commit->raw_message); GIT_ERROR_CHECK_ALLOC(commit->raw_message);
return 0; return 0;
bad_buffer: bad_buffer:
giterr_set(GITERR_OBJECT, "failed to parse bad commit object"); git_error_set(GIT_ERROR_OBJECT, "failed to parse bad commit object");
return -1; return -1;
} }
...@@ -610,7 +610,7 @@ int git_commit_parent( ...@@ -610,7 +610,7 @@ int git_commit_parent(
parent_id = git_commit_parent_id(commit, n); parent_id = git_commit_parent_id(commit, n);
if (parent_id == NULL) { if (parent_id == NULL) {
giterr_set(GITERR_INVALID, "parent %u does not exist", n); git_error_set(GIT_ERROR_INVALID, "parent %u does not exist", n);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -699,14 +699,14 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char * ...@@ -699,14 +699,14 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
return 0; return 0;
} }
giterr_set(GITERR_OBJECT, "no such field '%s'", field); git_error_set(GIT_ERROR_OBJECT, "no such field '%s'", field);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
malformed: malformed:
giterr_set(GITERR_OBJECT, "malformed header"); git_error_set(GIT_ERROR_OBJECT, "malformed header");
return -1; return -1;
oom: oom:
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
} }
...@@ -731,7 +731,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r ...@@ -731,7 +731,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
return error; return error;
if (obj->cached.type != GIT_OBJECT_COMMIT) { if (obj->cached.type != GIT_OBJECT_COMMIT) {
giterr_set(GITERR_INVALID, "the requested type does not match the type in ODB"); git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in ODB");
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
} }
...@@ -783,16 +783,16 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r ...@@ -783,16 +783,16 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
return error; return error;
} }
giterr_set(GITERR_OBJECT, "this commit is not signed"); git_error_set(GIT_ERROR_OBJECT, "this commit is not signed");
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
malformed: malformed:
giterr_set(GITERR_OBJECT, "malformed header"); git_error_set(GIT_ERROR_OBJECT, "malformed header");
error = -1; error = -1;
goto cleanup; goto cleanup;
oom: oom:
giterr_set_oom(); git_error_set_oom();
error = -1; error = -1;
goto cleanup; goto cleanup;
...@@ -872,7 +872,7 @@ int git_commit_create_with_signature( ...@@ -872,7 +872,7 @@ int git_commit_create_with_signature(
/* We start by identifying the end of the commit header */ /* We start by identifying the end of the commit header */
header_end = strstr(commit_content, "\n\n"); header_end = strstr(commit_content, "\n\n");
if (!header_end) { if (!header_end) {
giterr_set(GITERR_INVALID, "malformed commit contents"); git_error_set(GIT_ERROR_INVALID, "malformed commit contents");
return -1; return -1;
} }
......
...@@ -61,7 +61,7 @@ static int commit_error(git_commit_list_node *commit, const char *msg) ...@@ -61,7 +61,7 @@ static int commit_error(git_commit_list_node *commit, const char *msg)
git_oid_fmt(commit_oid, &commit->oid); git_oid_fmt(commit_oid, &commit->oid);
commit_oid[GIT_OID_HEXSZ] = '\0'; commit_oid[GIT_OID_HEXSZ] = '\0';
giterr_set(GITERR_ODB, "failed to parse commit %s - %s", commit_oid, msg); git_error_set(GIT_ERROR_ODB, "failed to parse commit %s - %s", commit_oid, msg);
return -1; return -1;
} }
...@@ -126,7 +126,7 @@ static int commit_quick_parse( ...@@ -126,7 +126,7 @@ static int commit_quick_parse(
} }
commit->parents = alloc_parents(walk, commit, parents); commit->parents = alloc_parents(walk, commit, parents);
GITERR_CHECK_ALLOC(commit->parents); GIT_ERROR_CHECK_ALLOC(commit->parents);
buffer = parents_start; buffer = parents_start;
for (i = 0; i < parents; ++i) { for (i = 0; i < parents; ++i) {
...@@ -193,7 +193,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) ...@@ -193,7 +193,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
return error; return error;
if (obj->cached.type != GIT_OBJECT_COMMIT) { if (obj->cached.type != GIT_OBJECT_COMMIT) {
giterr_set(GITERR_INVALID, "object is no commit object"); git_error_set(GIT_ERROR_INVALID, "object is no commit object");
error = -1; error = -1;
} else } else
error = commit_quick_parse( error = commit_quick_parse(
......
...@@ -89,30 +89,30 @@ ...@@ -89,30 +89,30 @@
/** /**
* Check a pointer allocation result, returning -1 if it failed. * Check a pointer allocation result, returning -1 if it failed.
*/ */
#define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; } #define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
/** /**
* Check a buffer allocation result, returning -1 if it failed. * Check a buffer allocation result, returning -1 if it failed.
*/ */
#define GITERR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; } #define GIT_ERROR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
/** /**
* Check a return value and propagate result if non-zero. * Check a return value and propagate result if non-zero.
*/ */
#define GITERR_CHECK_ERROR(code) \ #define GIT_ERROR_CHECK_ERROR(code) \
do { int _err = (code); if (_err) return _err; } while (0) do { int _err = (code); if (_err) return _err; } while (0)
/** /**
* Set the error message for this thread, formatting as needed. * Set the error message for this thread, formatting as needed.
*/ */
void giterr_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3); void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
/** /**
* Set the error message for a regex failure, using the internal regex * Set the error message for a regex failure, using the internal regex
* error code lookup and return a libgit error code. * error code lookup and return a libgit error code.
*/ */
int giterr_set_regex(const regex_t *regex, int error_code); int git_error_set_regex(const regex_t *regex, int error_code);
/** /**
* Set error message for user callback if needed. * Set error message for user callback if needed.
...@@ -122,35 +122,35 @@ int giterr_set_regex(const regex_t *regex, int error_code); ...@@ -122,35 +122,35 @@ int giterr_set_regex(const regex_t *regex, int error_code);
* *
* @return This always returns the `error_code` parameter. * @return This always returns the `error_code` parameter.
*/ */
GIT_INLINE(int) giterr_set_after_callback_function( GIT_INLINE(int) git_error_set_after_callback_function(
int error_code, const char *action) int error_code, const char *action)
{ {
if (error_code) { if (error_code) {
const git_error *e = giterr_last(); const git_error *e = git_error_last();
if (!e || !e->message) if (!e || !e->message)
giterr_set(e ? e->klass : GITERR_CALLBACK, git_error_set(e ? e->klass : GIT_ERROR_CALLBACK,
"%s callback returned %d", action, error_code); "%s callback returned %d", action, error_code);
} }
return error_code; return error_code;
} }
#ifdef GIT_WIN32 #ifdef GIT_WIN32
#define giterr_set_after_callback(code) \ #define git_error_set_after_callback(code) \
giterr_set_after_callback_function((code), __FUNCTION__) git_error_set_after_callback_function((code), __FUNCTION__)
#else #else
#define giterr_set_after_callback(code) \ #define git_error_set_after_callback(code) \
giterr_set_after_callback_function((code), __func__) git_error_set_after_callback_function((code), __func__)
#endif #endif
/** /**
* Gets the system error code for this thread. * Gets the system error code for this thread.
*/ */
int giterr_system_last(void); int git_error_system_last(void);
/** /**
* Sets the system error code for this thread. * Sets the system error code for this thread.
*/ */
void giterr_system_set(int code); void git_error_system_set(int code);
/** /**
* Structure to preserve libgit2 error state * Structure to preserve libgit2 error state
...@@ -166,20 +166,20 @@ typedef struct { ...@@ -166,20 +166,20 @@ typedef struct {
* If `error_code` is zero, this does not clear the current error state. * If `error_code` is zero, this does not clear the current error state.
* You must either restore this error state, or free it. * You must either restore this error state, or free it.
*/ */
extern int giterr_state_capture(git_error_state *state, int error_code); extern int git_error_state_capture(git_error_state *state, int error_code);
/** /**
* Restore error state to a previous value, returning saved error code. * Restore error state to a previous value, returning saved error code.
*/ */
extern int giterr_state_restore(git_error_state *state); extern int git_error_state_restore(git_error_state *state);
/** Free an error state. */ /** Free an error state. */
extern void giterr_state_free(git_error_state *state); extern void git_error_state_free(git_error_state *state);
/** /**
* Check a versioned structure for validity * Check a versioned structure for validity
*/ */
GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expected_max, const char *name) GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name)
{ {
unsigned int actual; unsigned int actual;
...@@ -190,10 +190,10 @@ GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expect ...@@ -190,10 +190,10 @@ GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expect
if (actual > 0 && actual <= expected_max) if (actual > 0 && actual <= expected_max)
return 0; return 0;
giterr_set(GITERR_INVALID, "invalid version %d on %s", actual, name); git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name);
return -1; return -1;
} }
#define GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) return -1 #define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1
/** /**
* Initialize a structure with a version. * Initialize a structure with a version.
...@@ -207,42 +207,42 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v ...@@ -207,42 +207,42 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v
#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \ #define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \
TYPE _tmpl = TPL; \ TYPE _tmpl = TPL; \
GITERR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \ GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0) memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0)
/** Check for additive overflow, setting an error if would occur. */ /** Check for additive overflow, setting an error if would occur. */
#define GIT_ADD_SIZET_OVERFLOW(out, one, two) \ #define GIT_ADD_SIZET_OVERFLOW(out, one, two) \
(git__add_sizet_overflow(out, one, two) ? (giterr_set_oom(), 1) : 0) (git__add_sizet_overflow(out, one, two) ? (git_error_set_oom(), 1) : 0)
/** Check for additive overflow, setting an error if would occur. */ /** Check for additive overflow, setting an error if would occur. */
#define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \ #define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \
(git__multiply_sizet_overflow(out, nelem, elsize) ? (giterr_set_oom(), 1) : 0) (git__multiply_sizet_overflow(out, nelem, elsize) ? (git_error_set_oom(), 1) : 0)
/** Check for additive overflow, failing if it would occur. */ /** Check for additive overflow, failing if it would occur. */
#define GITERR_CHECK_ALLOC_ADD(out, one, two) \ #define GIT_ERROR_CHECK_ALLOC_ADD(out, one, two) \
if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; } if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; }
#define GITERR_CHECK_ALLOC_ADD3(out, one, two, three) \ #define GIT_ERROR_CHECK_ALLOC_ADD3(out, one, two, three) \
if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; } GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; }
#define GITERR_CHECK_ALLOC_ADD4(out, one, two, three, four) \ #define GIT_ERROR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; } GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; }
#define GITERR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \ #define GIT_ERROR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \
if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \ GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \
GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; } GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; }
/** Check for multiplicative overflow, failing if it would occur. */ /** Check for multiplicative overflow, failing if it would occur. */
#define GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \ #define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; } if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; }
/* NOTE: other giterr functions are in the public errors.h header file */ /* NOTE: other git_error functions are in the public errors.h header file */
#include "util.h" #include "util.h"
......
...@@ -81,7 +81,7 @@ int git_config_new(git_config **out) ...@@ -81,7 +81,7 @@ int git_config_new(git_config **out)
git_config *cfg; git_config *cfg;
cfg = git__malloc(sizeof(git_config)); cfg = git__malloc(sizeof(git_config));
GITERR_CHECK_ALLOC(cfg); GIT_ERROR_CHECK_ALLOC(cfg);
memset(cfg, 0x0, sizeof(git_config)); memset(cfg, 0x0, sizeof(git_config));
...@@ -110,7 +110,7 @@ int git_config_add_file_ondisk( ...@@ -110,7 +110,7 @@ int git_config_add_file_ondisk(
res = p_stat(path, &st); res = p_stat(path, &st);
if (res < 0 && errno != ENOENT && errno != ENOTDIR) { if (res < 0 && errno != ENOENT && errno != ENOTDIR) {
giterr_set(GITERR_CONFIG, "failed to stat '%s'", path); git_error_set(GIT_ERROR_CONFIG, "failed to stat '%s'", path);
return -1; return -1;
} }
...@@ -203,7 +203,7 @@ static int find_backend_by_level( ...@@ -203,7 +203,7 @@ static int find_backend_by_level(
} }
if (pos == -1) { if (pos == -1) {
giterr_set(GITERR_CONFIG, git_error_set(GIT_ERROR_CONFIG,
"no configuration exists for the given level '%i'", (int)level); "no configuration exists for the given level '%i'", (int)level);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -219,7 +219,7 @@ static int duplicate_level(void **old_raw, void *new_raw) ...@@ -219,7 +219,7 @@ static int duplicate_level(void **old_raw, void *new_raw)
GIT_UNUSED(new_raw); GIT_UNUSED(new_raw);
giterr_set(GITERR_CONFIG, "there already exists a configuration for the given level (%i)", (int)(*old)->level); git_error_set(GIT_ERROR_CONFIG, "there already exists a configuration for the given level (%i)", (int)(*old)->level);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
...@@ -316,13 +316,13 @@ int git_config_add_backend( ...@@ -316,13 +316,13 @@ int git_config_add_backend(
assert(cfg && backend); assert(cfg && backend);
GITERR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend"); GIT_ERROR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
if ((result = backend->open(backend, level, repo)) < 0) if ((result = backend->open(backend, level, repo)) < 0)
return result; return result;
internal = git__malloc(sizeof(backend_internal)); internal = git__malloc(sizeof(backend_internal));
GITERR_CHECK_ALLOC(internal); GIT_ERROR_CHECK_ALLOC(internal);
memset(internal, 0x0, sizeof(backend_internal)); memset(internal, 0x0, sizeof(backend_internal));
...@@ -456,7 +456,7 @@ int git_config_iterator_new(git_config_iterator **out, const git_config *cfg) ...@@ -456,7 +456,7 @@ int git_config_iterator_new(git_config_iterator **out, const git_config *cfg)
all_iter *iter; all_iter *iter;
iter = git__calloc(1, sizeof(all_iter)); iter = git__calloc(1, sizeof(all_iter));
GITERR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
iter->parent.free = all_iter_free; iter->parent.free = all_iter_free;
iter->parent.next = all_iter_next; iter->parent.next = all_iter_next;
...@@ -478,10 +478,10 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -478,10 +478,10 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
return git_config_iterator_new(out, cfg); return git_config_iterator_new(out, cfg);
iter = git__calloc(1, sizeof(all_iter)); iter = git__calloc(1, sizeof(all_iter));
GITERR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
if ((result = p_regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) { if ((result = p_regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(&iter->regex, result); git_error_set_regex(&iter->regex, result);
git__free(iter); git__free(iter);
return -1; return -1;
} }
...@@ -517,7 +517,7 @@ int git_config_backend_foreach_match( ...@@ -517,7 +517,7 @@ int git_config_backend_foreach_match(
if (regexp != NULL) { if (regexp != NULL) {
if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) { if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(&regex, error); git_error_set_regex(&regex, error);
regfree(&regex); regfree(&regex);
return -1; return -1;
} }
...@@ -535,7 +535,7 @@ int git_config_backend_foreach_match( ...@@ -535,7 +535,7 @@ int git_config_backend_foreach_match(
/* abort iterator on non-zero return value */ /* abort iterator on non-zero return value */
if ((error = cb(entry, payload)) != 0) { if ((error = cb(entry, payload)) != 0) {
giterr_set_after_callback(error); git_error_set_after_callback(error);
break; break;
} }
} }
...@@ -563,7 +563,7 @@ int git_config_foreach_match( ...@@ -563,7 +563,7 @@ int git_config_foreach_match(
while (!(error = git_config_next(&entry, iter))) { while (!(error = git_config_next(&entry, iter))) {
if ((error = cb(entry, payload)) != 0) { if ((error = cb(entry, payload)) != 0) {
giterr_set_after_callback(error); git_error_set_after_callback(error);
break; break;
} }
} }
...@@ -599,7 +599,7 @@ static int get_backend_for_use(git_config_backend **out, ...@@ -599,7 +599,7 @@ static int get_backend_for_use(git_config_backend **out,
*out = NULL; *out = NULL;
if (git_vector_length(&cfg->backends) == 0) { if (git_vector_length(&cfg->backends) == 0) {
giterr_set(GITERR_CONFIG, git_error_set(GIT_ERROR_CONFIG,
"cannot %s value for '%s' when no config backends exist", "cannot %s value for '%s' when no config backends exist",
uses[use], name); uses[use], name);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -612,7 +612,7 @@ static int get_backend_for_use(git_config_backend **out, ...@@ -612,7 +612,7 @@ static int get_backend_for_use(git_config_backend **out,
} }
} }
giterr_set(GITERR_CONFIG, git_error_set(GIT_ERROR_CONFIG,
"cannot %s value for '%s' when all config backends are readonly", "cannot %s value for '%s' when all config backends are readonly",
uses[use], name); uses[use], name);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -651,7 +651,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value) ...@@ -651,7 +651,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
git_config_backend *backend; git_config_backend *backend;
if (!value) { if (!value) {
giterr_set(GITERR_CONFIG, "the value to set cannot be NULL"); git_error_set(GIT_ERROR_CONFIG, "the value to set cannot be NULL");
return -1; return -1;
} }
...@@ -703,7 +703,7 @@ int git_config__update_entry( ...@@ -703,7 +703,7 @@ int git_config__update_entry(
static int config_error_notfound(const char *name) static int config_error_notfound(const char *name)
{ {
giterr_set(GITERR_CONFIG, "config value '%s' was not found", name); git_error_set(GIT_ERROR_CONFIG, "config value '%s' was not found", name);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -750,7 +750,7 @@ cleanup: ...@@ -750,7 +750,7 @@ cleanup:
if (res == GIT_ENOTFOUND) if (res == GIT_ENOTFOUND)
res = (want_errors > GET_ALL_ERRORS) ? 0 : config_error_notfound(name); res = (want_errors > GET_ALL_ERRORS) ? 0 : config_error_notfound(name);
else if (res && (want_errors == GET_NO_ERRORS)) { else if (res && (want_errors == GET_NO_ERRORS)) {
giterr_clear(); git_error_clear();
res = 0; res = 0;
} }
...@@ -871,7 +871,7 @@ int git_config_get_string( ...@@ -871,7 +871,7 @@ int git_config_get_string(
int ret; int ret;
if (!is_readonly(cfg)) { if (!is_readonly(cfg)) {
giterr_set(GITERR_CONFIG, "get_string called on a live config object"); git_error_set(GIT_ERROR_CONFIG, "get_string called on a live config object");
return -1; return -1;
} }
...@@ -925,7 +925,7 @@ int git_config__get_bool_force( ...@@ -925,7 +925,7 @@ int git_config__get_bool_force(
get_entry(&entry, cfg, key, false, GET_NO_ERRORS); get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
if (entry && git_config_parse_bool(&val, entry->value) < 0) if (entry && git_config_parse_bool(&val, entry->value) < 0)
giterr_clear(); git_error_clear();
git_config_entry_free(entry); git_config_entry_free(entry);
return val; return val;
...@@ -940,7 +940,7 @@ int git_config__get_int_force( ...@@ -940,7 +940,7 @@ int git_config__get_int_force(
get_entry(&entry, cfg, key, false, GET_NO_ERRORS); get_entry(&entry, cfg, key, false, GET_NO_ERRORS);
if (entry && git_config_parse_int32(&val, entry->value) < 0) if (entry && git_config_parse_int32(&val, entry->value) < 0)
giterr_clear(); git_error_clear();
git_config_entry_free(entry); git_config_entry_free(entry);
return (int)val; return (int)val;
...@@ -962,7 +962,7 @@ int git_config_get_multivar_foreach( ...@@ -962,7 +962,7 @@ int git_config_get_multivar_foreach(
found = 1; found = 1;
if ((err = cb(entry, payload)) != 0) { if ((err = cb(entry, payload)) != 0) {
giterr_set_after_callback(err); git_error_set_after_callback(err);
break; break;
} }
} }
...@@ -1026,7 +1026,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config ...@@ -1026,7 +1026,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
return error; return error;
iter = git__calloc(1, sizeof(multivar_iter)); iter = git__calloc(1, sizeof(multivar_iter));
GITERR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
if ((error = git_config__normalize_name(name, &iter->name)) < 0) if ((error = git_config__normalize_name(name, &iter->name)) < 0)
goto on_error; goto on_error;
...@@ -1034,7 +1034,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config ...@@ -1034,7 +1034,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
if (regexp != NULL) { if (regexp != NULL) {
error = p_regcomp(&iter->regex, regexp, REG_EXTENDED); error = p_regcomp(&iter->regex, regexp, REG_EXTENDED);
if (error != 0) { if (error != 0) {
giterr_set_regex(&iter->regex, error); git_error_set_regex(&iter->regex, error);
error = -1; error = -1;
regfree(&iter->regex); regfree(&iter->regex);
goto on_error; goto on_error;
...@@ -1188,7 +1188,7 @@ int git_config_lock(git_transaction **out, git_config *cfg) ...@@ -1188,7 +1188,7 @@ int git_config_lock(git_transaction **out, git_config *cfg)
internal = git_vector_get(&cfg->backends, 0); internal = git_vector_get(&cfg->backends, 0);
if (!internal || !internal->backend) { if (!internal || !internal->backend) {
giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends"); git_error_set(GIT_ERROR_CONFIG, "cannot lock; the config has no backends");
return -1; return -1;
} }
backend = internal->backend; backend = internal->backend;
...@@ -1208,7 +1208,7 @@ int git_config_unlock(git_config *cfg, int commit) ...@@ -1208,7 +1208,7 @@ int git_config_unlock(git_config *cfg, int commit)
internal = git_vector_get(&cfg->backends, 0); internal = git_vector_get(&cfg->backends, 0);
if (!internal || !internal->backend) { if (!internal || !internal->backend) {
giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends"); git_error_set(GIT_ERROR_CONFIG, "cannot lock; the config has no backends");
return -1; return -1;
} }
...@@ -1263,7 +1263,7 @@ int git_config_lookup_map_value( ...@@ -1263,7 +1263,7 @@ int git_config_lookup_map_value(
} }
fail_parse: fail_parse:
giterr_set(GITERR_CONFIG, "failed to map '%s'", value); git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value);
return -1; return -1;
} }
...@@ -1283,7 +1283,7 @@ int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out, ...@@ -1283,7 +1283,7 @@ int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
return 0; return 0;
} }
giterr_set(GITERR_CONFIG, "invalid enum value"); git_error_set(GIT_ERROR_CONFIG, "invalid enum value");
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -1297,7 +1297,7 @@ int git_config_parse_bool(int *out, const char *value) ...@@ -1297,7 +1297,7 @@ int git_config_parse_bool(int *out, const char *value)
return 0; return 0;
} }
giterr_set(GITERR_CONFIG, "failed to parse '%s' as a boolean value", value); git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a boolean value", value);
return -1; return -1;
} }
...@@ -1340,7 +1340,7 @@ int git_config_parse_int64(int64_t *out, const char *value) ...@@ -1340,7 +1340,7 @@ int git_config_parse_int64(int64_t *out, const char *value)
} }
fail_parse: fail_parse:
giterr_set(GITERR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)"); git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)");
return -1; return -1;
} }
...@@ -1360,7 +1360,7 @@ int git_config_parse_int32(int32_t *out, const char *value) ...@@ -1360,7 +1360,7 @@ int git_config_parse_int32(int32_t *out, const char *value)
return 0; return 0;
fail_parse: fail_parse:
giterr_set(GITERR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)"); git_error_set(GIT_ERROR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)");
return -1; return -1;
} }
...@@ -1372,7 +1372,7 @@ int git_config_parse_path(git_buf *out, const char *value) ...@@ -1372,7 +1372,7 @@ int git_config_parse_path(git_buf *out, const char *value)
if (value[0] == '~') { if (value[0] == '~') {
if (value[1] != '\0' && value[1] != '/') { if (value[1] != '\0' && value[1] != '/') {
giterr_set(GITERR_CONFIG, "retrieving a homedir by name is not supported"); git_error_set(GIT_ERROR_CONFIG, "retrieving a homedir by name is not supported");
return -1; return -1;
} }
...@@ -1414,7 +1414,7 @@ int git_config__normalize_name(const char *in, char **out) ...@@ -1414,7 +1414,7 @@ int git_config__normalize_name(const char *in, char **out)
assert(in && out); assert(in && out);
name = git__strdup(in); name = git__strdup(in);
GITERR_CHECK_ALLOC(name); GIT_ERROR_CHECK_ALLOC(name);
fdot = strchr(name, '.'); fdot = strchr(name, '.');
ldot = strrchr(name, '.'); ldot = strrchr(name, '.');
...@@ -1437,7 +1437,7 @@ int git_config__normalize_name(const char *in, char **out) ...@@ -1437,7 +1437,7 @@ int git_config__normalize_name(const char *in, char **out)
invalid: invalid:
git__free(name); git__free(name);
giterr_set(GITERR_CONFIG, "invalid config item name '%s'", in); git_error_set(GIT_ERROR_CONFIG, "invalid config item name '%s'", in);
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
...@@ -1498,8 +1498,8 @@ int git_config_rename_section( ...@@ -1498,8 +1498,8 @@ int git_config_rename_section(
if (new_section_name != NULL && if (new_section_name != NULL &&
(error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0) (error = normalize_section(replace.ptr, strchr(replace.ptr, '.'))) < 0)
{ {
giterr_set( git_error_set(
GITERR_CONFIG, "invalid config section '%s'", new_section_name); GIT_ERROR_CONFIG, "invalid config section '%s'", new_section_name);
goto cleanup; goto cleanup;
} }
......
...@@ -56,7 +56,7 @@ int git_config_entries_new(git_config_entries **out) ...@@ -56,7 +56,7 @@ int git_config_entries_new(git_config_entries **out)
int error; int error;
entries = git__calloc(1, sizeof(git_config_entries)); entries = git__calloc(1, sizeof(git_config_entries));
GITERR_CHECK_ALLOC(entries); GIT_ERROR_CHECK_ALLOC(entries);
GIT_REFCOUNT_INC(entries); GIT_REFCOUNT_INC(entries);
if ((error = git_strmap_alloc(&entries->map)) < 0) if ((error = git_strmap_alloc(&entries->map)) < 0)
...@@ -81,10 +81,10 @@ int git_config_entries_dup(git_config_entries **out, git_config_entries *entries ...@@ -81,10 +81,10 @@ int git_config_entries_dup(git_config_entries **out, git_config_entries *entries
dup = git__calloc(1, sizeof(git_config_entry)); dup = git__calloc(1, sizeof(git_config_entry));
dup->name = git__strdup(head->entry->name); dup->name = git__strdup(head->entry->name);
GITERR_CHECK_ALLOC(dup->name); GIT_ERROR_CHECK_ALLOC(dup->name);
if (head->entry->value) { if (head->entry->value) {
dup->value = git__strdup(head->entry->value); dup->value = git__strdup(head->entry->value);
GITERR_CHECK_ALLOC(dup->value); GIT_ERROR_CHECK_ALLOC(dup->value);
} }
dup->level = head->entry->level; dup->level = head->entry->level;
dup->include_depth = head->entry->include_depth; dup->include_depth = head->entry->include_depth;
...@@ -136,7 +136,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent ...@@ -136,7 +136,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
size_t pos; size_t pos;
var = git__calloc(1, sizeof(config_entry_list)); var = git__calloc(1, sizeof(config_entry_list));
GITERR_CHECK_ALLOC(var); GIT_ERROR_CHECK_ALLOC(var);
var->entry = entry; var->entry = entry;
pos = git_strmap_lookup_index(entries->map, entry->name); pos = git_strmap_lookup_index(entries->map, entry->name);
...@@ -162,7 +162,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent ...@@ -162,7 +162,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
} }
var = git__calloc(1, sizeof(config_entry_list)); var = git__calloc(1, sizeof(config_entry_list));
GITERR_CHECK_ALLOC(var); GIT_ERROR_CHECK_ALLOC(var);
var->entry = entry; var->entry = entry;
config_entry_list_append(&entries->list, var); config_entry_list_append(&entries->list, var);
...@@ -205,12 +205,12 @@ int git_config_entries_get_unique(git_config_entry **out, git_config_entries *en ...@@ -205,12 +205,12 @@ int git_config_entries_get_unique(git_config_entry **out, git_config_entries *en
return error; return error;
if (entry->next != NULL) { if (entry->next != NULL) {
giterr_set(GITERR_CONFIG, "entry is not unique due to being a multivar"); git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being a multivar");
return -1; return -1;
} }
if (entry->entry->include_depth) { if (entry->entry->include_depth) {
giterr_set(GITERR_CONFIG, "entry is not unique due to being included"); git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being included");
return -1; return -1;
} }
...@@ -246,7 +246,7 @@ int git_config_entries_iterator_new(git_config_iterator **out, git_config_entrie ...@@ -246,7 +246,7 @@ int git_config_entries_iterator_new(git_config_iterator **out, git_config_entrie
config_entries_iterator *it; config_entries_iterator *it;
it = git__calloc(1, sizeof(config_entries_iterator)); it = git__calloc(1, sizeof(config_entries_iterator));
GITERR_CHECK_ALLOC(it); GIT_ERROR_CHECK_ALLOC(it);
it->parent.next = config_iterator_next; it->parent.next = config_iterator_next;
it->parent.free = config_iterator_free; it->parent.free = config_iterator_free;
it->head = entries->list; it->head = entries->list;
......
...@@ -69,7 +69,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in); ...@@ -69,7 +69,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in);
static int config_error_readonly(void) static int config_error_readonly(void)
{ {
giterr_set(GITERR_CONFIG, "this backend is read-only"); git_error_set(GIT_ERROR_CONFIG, "this backend is read-only");
return -1; return -1;
} }
...@@ -83,7 +83,7 @@ static git_config_entries *diskfile_entries_take(diskfile_header *h) ...@@ -83,7 +83,7 @@ static git_config_entries *diskfile_entries_take(diskfile_header *h)
git_config_entries *entries; git_config_entries *entries;
if (git_mutex_lock(&h->values_mutex) < 0) { if (git_mutex_lock(&h->values_mutex) < 0) {
giterr_set(GITERR_OS, "failed to lock config backend"); git_error_set(GIT_ERROR_OS, "failed to lock config backend");
return NULL; return NULL;
} }
...@@ -196,7 +196,7 @@ static int config_refresh(git_config_backend *cfg) ...@@ -196,7 +196,7 @@ static int config_refresh(git_config_backend *cfg)
goto out; goto out;
if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) { if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) {
giterr_set(GITERR_OS, "failed to lock config backend"); git_error_set(GIT_ERROR_OS, "failed to lock config backend");
goto out; goto out;
} }
...@@ -274,7 +274,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val ...@@ -274,7 +274,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
/* No early returns due to sanity checks, let's write it out and refresh */ /* No early returns due to sanity checks, let's write it out and refresh */
if (value) { if (value) {
esc_value = escape_value(value); esc_value = escape_value(value);
GITERR_CHECK_ALLOC(esc_value); GIT_ERROR_CHECK_ALLOC(esc_value);
} }
if ((error = config_write(b, name, key, NULL, esc_value)) < 0) if ((error = config_write(b, name, key, NULL, esc_value)) < 0)
...@@ -339,7 +339,7 @@ static int config_set_multivar( ...@@ -339,7 +339,7 @@ static int config_set_multivar(
result = p_regcomp(&preg, regexp, REG_EXTENDED); result = p_regcomp(&preg, regexp, REG_EXTENDED);
if (result != 0) { if (result != 0) {
giterr_set_regex(&preg, result); git_error_set_regex(&preg, result);
result = -1; result = -1;
goto out; goto out;
} }
...@@ -374,7 +374,7 @@ static int config_delete(git_config_backend *cfg, const char *name) ...@@ -374,7 +374,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
/* Check whether we'd be modifying an included or multivar key */ /* Check whether we'd be modifying an included or multivar key */
if ((error = git_config_entries_get_unique(&entry, entries, key)) < 0) { if ((error = git_config_entries_get_unique(&entry, entries, key)) < 0) {
if (error == GIT_ENOTFOUND) if (error == GIT_ENOTFOUND)
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name); git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name);
goto out; goto out;
} }
...@@ -409,12 +409,12 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -409,12 +409,12 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
if ((result = git_config_entries_get(&entry, entries, key)) < 0) { if ((result = git_config_entries_get(&entry, entries, key)) < 0) {
if (result == GIT_ENOTFOUND) if (result == GIT_ENOTFOUND)
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name); git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name);
goto out; goto out;
} }
if ((result = p_regcomp(&preg, regexp, REG_EXTENDED)) != 0) { if ((result = p_regcomp(&preg, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(&preg, result); git_error_set_regex(&preg, result);
result = -1; result = -1;
goto out; goto out;
} }
...@@ -473,13 +473,13 @@ int git_config_backend_from_file(git_config_backend **out, const char *path) ...@@ -473,13 +473,13 @@ int git_config_backend_from_file(git_config_backend **out, const char *path)
diskfile_backend *backend; diskfile_backend *backend;
backend = git__calloc(1, sizeof(diskfile_backend)); backend = git__calloc(1, sizeof(diskfile_backend));
GITERR_CHECK_ALLOC(backend); GIT_ERROR_CHECK_ALLOC(backend);
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION; backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
git_mutex_init(&backend->header.values_mutex); git_mutex_init(&backend->header.values_mutex);
backend->file.path = git__strdup(path); backend->file.path = git__strdup(path);
GITERR_CHECK_ALLOC(backend->file.path); GIT_ERROR_CHECK_ALLOC(backend->file.path);
git_array_init(backend->file.includes); git_array_init(backend->file.includes);
backend->header.parent.open = config_open; backend->header.parent.open = config_open;
...@@ -590,7 +590,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in) ...@@ -590,7 +590,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in)
diskfile_readonly_backend *backend; diskfile_readonly_backend *backend;
backend = git__calloc(1, sizeof(diskfile_readonly_backend)); backend = git__calloc(1, sizeof(diskfile_readonly_backend));
GITERR_CHECK_ALLOC(backend); GIT_ERROR_CHECK_ALLOC(backend);
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION; backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
git_mutex_init(&backend->header.values_mutex); git_mutex_init(&backend->header.values_mutex);
...@@ -686,7 +686,7 @@ static int parse_include(git_config_parser *reader, ...@@ -686,7 +686,7 @@ static int parse_include(git_config_parser *reader,
include, parse_data->level, parse_data->depth+1); include, parse_data->level, parse_data->depth+1);
if (result == GIT_ENOTFOUND) { if (result == GIT_ENOTFOUND) {
giterr_clear(); git_error_clear();
result = 0; result = 0;
} }
...@@ -828,7 +828,7 @@ static int read_on_variable( ...@@ -828,7 +828,7 @@ static int read_on_variable(
return -1; return -1;
entry = git__calloc(1, sizeof(git_config_entry)); entry = git__calloc(1, sizeof(git_config_entry));
GITERR_CHECK_ALLOC(entry); GIT_ERROR_CHECK_ALLOC(entry);
entry->name = git_buf_detach(&buf); entry->name = git_buf_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL; entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level; entry->level = parse_data->level;
...@@ -863,7 +863,7 @@ static int config_read( ...@@ -863,7 +863,7 @@ static int config_read(
int error; int error;
if (depth >= MAX_INCLUDE_DEPTH) { if (depth >= MAX_INCLUDE_DEPTH) {
giterr_set(GITERR_CONFIG, "maximum config include depth reached"); git_error_set(GIT_ERROR_CONFIG, "maximum config include depth reached");
return -1; return -1;
} }
...@@ -911,7 +911,7 @@ static int write_section(git_buf *fbuf, const char *key) ...@@ -911,7 +911,7 @@ static int write_section(git_buf *fbuf, const char *key)
char *escaped; char *escaped;
git_buf_put(&buf, key, dot - key); git_buf_put(&buf, key, dot - key);
escaped = escape_value(dot + 1); escaped = escape_value(dot + 1);
GITERR_CHECK_ALLOC(escaped); GIT_ERROR_CHECK_ALLOC(escaped);
git_buf_printf(&buf, " \"%s\"", escaped); git_buf_printf(&buf, " \"%s\"", escaped);
git__free(escaped); git__free(escaped);
} }
...@@ -1156,12 +1156,12 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char ...@@ -1156,12 +1156,12 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
ldot = strrchr(key, '.'); ldot = strrchr(key, '.');
name = ldot + 1; name = ldot + 1;
section = git__strndup(key, ldot - key); section = git__strndup(key, ldot - key);
GITERR_CHECK_ALLOC(section); GIT_ERROR_CHECK_ALLOC(section);
ldot = strrchr(orig_key, '.'); ldot = strrchr(orig_key, '.');
orig_name = ldot + 1; orig_name = ldot + 1;
orig_section = git__strndup(orig_key, ldot - orig_key); orig_section = git__strndup(orig_key, ldot - orig_key);
GITERR_CHECK_ALLOC(orig_section); GIT_ERROR_CHECK_ALLOC(orig_section);
write_data.buf = &buf; write_data.buf = &buf;
git_buf_init(&write_data.buffered_comment, 0); git_buf_init(&write_data.buffered_comment, 0);
......
...@@ -24,7 +24,7 @@ typedef struct { ...@@ -24,7 +24,7 @@ typedef struct {
static int config_error_readonly(void) static int config_error_readonly(void)
{ {
giterr_set(GITERR_CONFIG, "this backend is read-only"); git_error_set(GIT_ERROR_CONFIG, "this backend is read-only");
return -1; return -1;
} }
...@@ -63,7 +63,7 @@ static int read_variable_cb( ...@@ -63,7 +63,7 @@ static int read_variable_cb(
return -1; return -1;
entry = git__calloc(1, sizeof(git_config_entry)); entry = git__calloc(1, sizeof(git_config_entry));
GITERR_CHECK_ALLOC(entry); GIT_ERROR_CHECK_ALLOC(entry);
entry->name = git_buf_detach(&buf); entry->name = git_buf_detach(&buf);
entry->value = var_value ? git__strdup(var_value) : NULL; entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level; entry->level = parse_data->level;
...@@ -170,7 +170,7 @@ static int config_memory_snapshot(git_config_backend **out, git_config_backend * ...@@ -170,7 +170,7 @@ static int config_memory_snapshot(git_config_backend **out, git_config_backend *
{ {
GIT_UNUSED(out); GIT_UNUSED(out);
GIT_UNUSED(backend); GIT_UNUSED(backend);
giterr_set(GITERR_CONFIG, "this backend does not support snapshots"); git_error_set(GIT_ERROR_CONFIG, "this backend does not support snapshots");
return -1; return -1;
} }
...@@ -191,7 +191,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si ...@@ -191,7 +191,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si
config_memory_backend *backend; config_memory_backend *backend;
backend = git__calloc(1, sizeof(config_memory_backend)); backend = git__calloc(1, sizeof(config_memory_backend));
GITERR_CHECK_ALLOC(backend); GIT_ERROR_CHECK_ALLOC(backend);
if (git_config_entries_new(&backend->entries) < 0) { if (git_config_entries_new(&backend->entries) < 0) {
git__free(backend); git__free(backend);
......
...@@ -17,7 +17,7 @@ const char *git_config_escaped = "\n\t\b\"\\"; ...@@ -17,7 +17,7 @@ const char *git_config_escaped = "\n\t\b\"\\";
static void set_parse_error(git_config_parser *reader, int col, const char *error_str) static void set_parse_error(git_config_parser *reader, int col, const char *error_str)
{ {
const char *file = reader->file ? reader->file->path : "in-memory"; const char *file = reader->file ? reader->file->path : "in-memory";
giterr_set(GITERR_CONFIG, "failed to parse config file: %s (in %s:%"PRIuZ", column %d)", git_error_set(GIT_ERROR_CONFIG, "failed to parse config file: %s (in %s:%"PRIuZ", column %d)",
error_str, file, reader->ctx.line_num, col); error_str, file, reader->ctx.line_num, col);
} }
...@@ -87,8 +87,8 @@ static int parse_section_header_ext(git_config_parser *reader, const char *line, ...@@ -87,8 +87,8 @@ static int parse_section_header_ext(git_config_parser *reader, const char *line,
goto end_error; goto end_error;
} }
GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
if (git_buf_grow(&buf, alloc_len) < 0 || if (git_buf_grow(&buf, alloc_len) < 0 ||
git_buf_printf(&buf, "%s.", base_name) < 0) git_buf_printf(&buf, "%s.", base_name) < 0)
...@@ -169,9 +169,9 @@ static int parse_section_header(git_config_parser *reader, char **section_out) ...@@ -169,9 +169,9 @@ static int parse_section_header(git_config_parser *reader, char **section_out)
return -1; return -1;
} }
GITERR_CHECK_ALLOC_ADD(&line_len, (size_t)(name_end - line), 1); GIT_ERROR_CHECK_ALLOC_ADD(&line_len, (size_t)(name_end - line), 1);
name = git__malloc(line_len); name = git__malloc(line_len);
GITERR_CHECK_ALLOC(name); GIT_ERROR_CHECK_ALLOC(name);
name_length = 0; name_length = 0;
pos = 0; pos = 0;
...@@ -304,7 +304,7 @@ static int unescape_line( ...@@ -304,7 +304,7 @@ static int unescape_line(
*fixed++ = git_config_escaped[esc - git_config_escapes]; *fixed++ = git_config_escaped[esc - git_config_escapes];
} else { } else {
git__free(str); git__free(str);
giterr_set(GITERR_CONFIG, "invalid escape at %s", ptr); git_error_set(GIT_ERROR_CONFIG, "invalid escape at %s", ptr);
return -1; return -1;
} }
} }
...@@ -330,7 +330,7 @@ static int parse_multiline_variable(git_config_parser *reader, git_buf *value, i ...@@ -330,7 +330,7 @@ static int parse_multiline_variable(git_config_parser *reader, git_buf *value, i
/* Check that the next line exists */ /* Check that the next line exists */
git_parse_advance_line(&reader->ctx); git_parse_advance_line(&reader->ctx);
line = git__strndup(reader->ctx.line, reader->ctx.line_len); line = git__strndup(reader->ctx.line, reader->ctx.line_len);
GITERR_CHECK_ALLOC(line); GIT_ERROR_CHECK_ALLOC(line);
/* /*
* We've reached the end of the file, there is no continuation. * We've reached the end of the file, there is no continuation.
...@@ -420,7 +420,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var ...@@ -420,7 +420,7 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
git_parse_advance_ws(&reader->ctx); git_parse_advance_ws(&reader->ctx);
line = git__strndup(reader->ctx.line, reader->ctx.line_len); line = git__strndup(reader->ctx.line, reader->ctx.line_len);
GITERR_CHECK_ALLOC(line); GIT_ERROR_CHECK_ALLOC(line);
quote_count = strip_comments(line, 0); quote_count = strip_comments(line, 0);
......
...@@ -85,7 +85,7 @@ static int has_cr_in_index(const git_filter_source *src) ...@@ -85,7 +85,7 @@ static int has_cr_in_index(const git_filter_source *src)
return false; return false;
if (git_repository_index__weakptr(&index, repo) < 0) { if (git_repository_index__weakptr(&index, repo) < 0) {
giterr_clear(); git_error_clear();
return false; return false;
} }
...@@ -170,12 +170,12 @@ GIT_INLINE(int) check_safecrlf( ...@@ -170,12 +170,12 @@ GIT_INLINE(int) check_safecrlf(
/* TODO: issue a warning when available */ /* TODO: issue a warning when available */
} else { } else {
if (filename && *filename) if (filename && *filename)
giterr_set( git_error_set(
GITERR_FILTER, "CRLF would be replaced by LF in '%s'", GIT_ERROR_FILTER, "CRLF would be replaced by LF in '%s'",
filename); filename);
else else
giterr_set( git_error_set(
GITERR_FILTER, "CRLF would be replaced by LF"); GIT_ERROR_FILTER, "CRLF would be replaced by LF");
return -1; return -1;
} }
...@@ -190,12 +190,12 @@ GIT_INLINE(int) check_safecrlf( ...@@ -190,12 +190,12 @@ GIT_INLINE(int) check_safecrlf(
/* TODO: issue a warning when available */ /* TODO: issue a warning when available */
} else { } else {
if (filename && *filename) if (filename && *filename)
giterr_set( git_error_set(
GITERR_FILTER, "LF would be replaced by CRLF in '%s'", GIT_ERROR_FILTER, "LF would be replaced by CRLF in '%s'",
filename); filename);
else else
giterr_set( git_error_set(
GITERR_FILTER, "LF would be replaced by CRLF"); GIT_ERROR_FILTER, "LF would be replaced by CRLF");
return -1; return -1;
} }
...@@ -360,7 +360,7 @@ static int crlf_check( ...@@ -360,7 +360,7 @@ static int crlf_check(
return GIT_PASSTHROUGH; return GIT_PASSTHROUGH;
*payload = git__malloc(sizeof(ca)); *payload = git__malloc(sizeof(ca));
GITERR_CHECK_ALLOC(*payload); GIT_ERROR_CHECK_ALLOC(*payload);
memcpy(*payload, &ca, sizeof(ca)); memcpy(*payload, &ca, sizeof(ca));
return 0; return 0;
......
...@@ -124,19 +124,19 @@ static int lookup_index_alloc( ...@@ -124,19 +124,19 @@ static int lookup_index_alloc(
{ {
size_t entries_len, hash_len, index_len; size_t entries_len, hash_len, index_len;
GITERR_CHECK_ALLOC_MULTIPLY(&entries_len, entries, sizeof(struct index_entry)); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&entries_len, entries, sizeof(struct index_entry));
GITERR_CHECK_ALLOC_MULTIPLY(&hash_len, hash_count, sizeof(struct index_entry *)); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&hash_len, hash_count, sizeof(struct index_entry *));
GITERR_CHECK_ALLOC_ADD(&index_len, sizeof(struct git_delta_index), entries_len); GIT_ERROR_CHECK_ALLOC_ADD(&index_len, sizeof(struct git_delta_index), entries_len);
GITERR_CHECK_ALLOC_ADD(&index_len, index_len, hash_len); GIT_ERROR_CHECK_ALLOC_ADD(&index_len, index_len, hash_len);
if (!git__is_ulong(index_len)) { if (!git__is_ulong(index_len)) {
giterr_set(GITERR_NOMEMORY, "overly large delta"); git_error_set(GIT_ERROR_NOMEMORY, "overly large delta");
return -1; return -1;
} }
*out = git__malloc(index_len); *out = git__malloc(index_len);
GITERR_CHECK_ALLOC(*out); GIT_ERROR_CHECK_ALLOC(*out);
*out_len = index_len; *out_len = index_len;
return 0; return 0;
...@@ -291,7 +291,7 @@ int git_delta_create_from_index( ...@@ -291,7 +291,7 @@ int git_delta_create_from_index(
if (max_size && bufsize >= max_size) if (max_size && bufsize >= max_size)
bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1); bufsize = (unsigned int)(max_size + MAX_OP_SIZE + 1);
buf = git__malloc(bufsize); buf = git__malloc(bufsize);
GITERR_CHECK_ALLOC(buf); GIT_ERROR_CHECK_ALLOC(buf);
/* store reference buffer size */ /* store reference buffer size */
i = index->src_size; i = index->src_size;
...@@ -438,7 +438,7 @@ int git_delta_create_from_index( ...@@ -438,7 +438,7 @@ int git_delta_create_from_index(
buf[bufpos - inscnt - 1] = inscnt; buf[bufpos - inscnt - 1] = inscnt;
if (max_size && bufpos > max_size) { if (max_size && bufpos > max_size) {
giterr_set(GITERR_NOMEMORY, "delta would be larger than maximum size"); git_error_set(GIT_ERROR_NOMEMORY, "delta would be larger than maximum size");
git__free(buf); git__free(buf);
return GIT_EBUFS; return GIT_EBUFS;
} }
...@@ -466,7 +466,7 @@ static int hdr_sz( ...@@ -466,7 +466,7 @@ static int hdr_sz(
do { do {
if (d == end) { if (d == end) {
giterr_set(GITERR_INVALID, "truncated delta"); git_error_set(GIT_ERROR_INVALID, "truncated delta");
return -1; return -1;
} }
...@@ -545,18 +545,18 @@ int git_delta_apply( ...@@ -545,18 +545,18 @@ int git_delta_apply(
* base object, resulting in data corruption or segfault. * base object, resulting in data corruption or segfault.
*/ */
if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) { if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) {
giterr_set(GITERR_INVALID, "failed to apply delta: base size does not match given data"); git_error_set(GIT_ERROR_INVALID, "failed to apply delta: base size does not match given data");
return -1; return -1;
} }
if (hdr_sz(&res_sz, &delta, delta_end) < 0) { if (hdr_sz(&res_sz, &delta, delta_end) < 0) {
giterr_set(GITERR_INVALID, "failed to apply delta: base size does not match given data"); git_error_set(GIT_ERROR_INVALID, "failed to apply delta: base size does not match given data");
return -1; return -1;
} }
GITERR_CHECK_ALLOC_ADD(&alloc_sz, res_sz, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_sz, res_sz, 1);
res_dp = git__malloc(alloc_sz); res_dp = git__malloc(alloc_sz);
GITERR_CHECK_ALLOC(res_dp); GIT_ERROR_CHECK_ALLOC(res_dp);
res_dp[res_sz] = '\0'; res_dp[res_sz] = '\0';
*out = res_dp; *out = res_dp;
...@@ -616,6 +616,6 @@ fail: ...@@ -616,6 +616,6 @@ fail:
*out = NULL; *out = NULL;
*out_len = 0; *out_len = 0;
giterr_set(GITERR_INVALID, "failed to apply delta"); git_error_set(GIT_ERROR_INVALID, "failed to apply delta");
return -1; return -1;
} }
...@@ -108,7 +108,7 @@ static int add_to_known_names( ...@@ -108,7 +108,7 @@ static int add_to_known_names(
if (replace_name(&tag, repo, e, prio, sha1)) { if (replace_name(&tag, repo, e, prio, sha1)) {
if (!found) { if (!found) {
e = git__malloc(sizeof(struct commit_name)); e = git__malloc(sizeof(struct commit_name));
GITERR_CHECK_ALLOC(e); GIT_ERROR_CHECK_ALLOC(e);
e->path = NULL; e->path = NULL;
e->tag = NULL; e->tag = NULL;
...@@ -191,7 +191,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in) ...@@ -191,7 +191,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in)
struct commit_name *name; struct commit_name *name;
name = git__malloc(sizeof(struct commit_name)); name = git__malloc(sizeof(struct commit_name));
GITERR_CHECK_ALLOC(name); GIT_ERROR_CHECK_ALLOC(name);
memcpy(name, in, sizeof(struct commit_name)); memcpy(name, in, sizeof(struct commit_name));
name->tag = NULL; name->tag = NULL;
...@@ -201,7 +201,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in) ...@@ -201,7 +201,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in)
return -1; return -1;
name->path = git__strdup(in->path); name->path = git__strdup(in->path);
GITERR_CHECK_ALLOC(name->path); GIT_ERROR_CHECK_ALLOC(name->path);
*out = name; *out = name;
return 0; return 0;
...@@ -267,7 +267,7 @@ static int possible_tag_dup(struct possible_tag **out, struct possible_tag *in) ...@@ -267,7 +267,7 @@ static int possible_tag_dup(struct possible_tag **out, struct possible_tag *in)
int error; int error;
tag = git__malloc(sizeof(struct possible_tag)); tag = git__malloc(sizeof(struct possible_tag));
GITERR_CHECK_ALLOC(tag); GIT_ERROR_CHECK_ALLOC(tag);
memcpy(tag, in, sizeof(struct possible_tag)); memcpy(tag, in, sizeof(struct possible_tag));
tag->name = NULL; tag->name = NULL;
...@@ -335,14 +335,14 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name * ...@@ -335,14 +335,14 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name *
{ {
if (n->prio == 2 && !n->tag) { if (n->prio == 2 && !n->tag) {
if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) { if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) {
giterr_set(GITERR_TAG, "annotated tag '%s' not available", n->path); git_error_set(GIT_ERROR_TAG, "annotated tag '%s' not available", n->path);
return -1; return -1;
} }
} }
if (n->tag && !n->name_checked) { if (n->tag && !n->name_checked) {
if (!git_tag_name(n->tag)) { if (!git_tag_name(n->tag)) {
giterr_set(GITERR_TAG, "annotated tag '%s' has no embedded name", n->path); git_error_set(GIT_ERROR_TAG, "annotated tag '%s' has no embedded name", n->path);
return -1; return -1;
} }
...@@ -425,7 +425,7 @@ static int describe_not_found(const git_oid *oid, const char *message_format) { ...@@ -425,7 +425,7 @@ static int describe_not_found(const git_oid *oid, const char *message_format) {
char oid_str[GIT_OID_HEXSZ + 1]; char oid_str[GIT_OID_HEXSZ + 1];
git_oid_tostr(oid_str, sizeof(oid_str), oid); git_oid_tostr(oid_str, sizeof(oid_str), oid);
giterr_set(GITERR_DESCRIBE, message_format, oid_str); git_error_set(GIT_ERROR_DESCRIBE, message_format, oid_str);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -504,7 +504,7 @@ static int describe( ...@@ -504,7 +504,7 @@ static int describe(
unannotated_cnt++; unannotated_cnt++;
} else if (match_cnt < data->opts->max_candidates_tags) { } else if (match_cnt < data->opts->max_candidates_tags) {
struct possible_tag *t = git__malloc(sizeof(struct commit_name)); struct possible_tag *t = git__malloc(sizeof(struct commit_name));
GITERR_CHECK_ALLOC(t); GIT_ERROR_CHECK_ALLOC(t);
if ((error = git_vector_insert(&all_matches, t)) < 0) if ((error = git_vector_insert(&all_matches, t)) < 0)
goto cleanup; goto cleanup;
...@@ -667,7 +667,7 @@ int git_describe_commit( ...@@ -667,7 +667,7 @@ int git_describe_commit(
assert(committish); assert(committish);
data.result = git__calloc(1, sizeof(git_describe_result)); data.result = git__calloc(1, sizeof(git_describe_result));
GITERR_CHECK_ALLOC(data.result); GIT_ERROR_CHECK_ALLOC(data.result);
data.result->repo = git_object_owner(committish); data.result->repo = git_object_owner(committish);
data.repo = git_object_owner(committish); data.repo = git_object_owner(committish);
...@@ -675,14 +675,14 @@ int git_describe_commit( ...@@ -675,14 +675,14 @@ int git_describe_commit(
if ((error = normalize_options(&normalized, opts)) < 0) if ((error = normalize_options(&normalized, opts)) < 0)
return error; return error;
GITERR_CHECK_VERSION( GIT_ERROR_CHECK_VERSION(
&normalized, &normalized,
GIT_DESCRIBE_OPTIONS_VERSION, GIT_DESCRIBE_OPTIONS_VERSION,
"git_describe_options"); "git_describe_options");
data.opts = &normalized; data.opts = &normalized;
data.names = git_oidmap_alloc(); data.names = git_oidmap_alloc();
GITERR_CHECK_ALLOC(data.names); GIT_ERROR_CHECK_ALLOC(data.names);
/** TODO: contains to be implemented */ /** TODO: contains to be implemented */
...@@ -695,7 +695,7 @@ int git_describe_commit( ...@@ -695,7 +695,7 @@ int git_describe_commit(
goto cleanup; goto cleanup;
if (git_oidmap_size(data.names) == 0 && !opts->show_commit_oid_as_fallback) { if (git_oidmap_size(data.names) == 0 && !opts->show_commit_oid_as_fallback) {
giterr_set(GITERR_DESCRIBE, "cannot describe - " git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - "
"no reference found, cannot describe anything."); "no reference found, cannot describe anything.");
error = -1; error = -1;
goto cleanup; goto cleanup;
...@@ -786,14 +786,14 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g ...@@ -786,14 +786,14 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
assert(out && result); assert(out && result);
GITERR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options"); GIT_ERROR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options");
normalize_format_options(&opts, given); normalize_format_options(&opts, given);
git_buf_sanitize(out); git_buf_sanitize(out);
if (opts.always_use_long_format && opts.abbreviated_size == 0) { if (opts.always_use_long_format && opts.abbreviated_size == 0) {
giterr_set(GITERR_DESCRIBE, "cannot describe - " git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - "
"'always_use_long_format' is incompatible with a zero" "'always_use_long_format' is incompatible with a zero"
"'abbreviated_size'"); "'abbreviated_size'");
return -1; return -1;
......
...@@ -114,7 +114,7 @@ int git_diff_is_sorted_icase(const git_diff *diff) ...@@ -114,7 +114,7 @@ int git_diff_is_sorted_icase(const git_diff *diff)
int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff) int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
{ {
assert(out); assert(out);
GITERR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata"); GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
out->stat_calls = diff->perf.stat_calls; out->stat_calls = diff->perf.stat_calls;
out->oid_calculations = diff->perf.oid_calculations; out->oid_calculations = diff->perf.oid_calculations;
return 0; return 0;
...@@ -251,7 +251,7 @@ int git_diff_format_email( ...@@ -251,7 +251,7 @@ int git_diff_format_email(
assert(out && diff && opts); assert(out && diff && opts);
assert(opts->summary && opts->id && opts->author); assert(opts->summary && opts->id && opts->author);
GITERR_CHECK_VERSION(opts, GIT_ERROR_CHECK_VERSION(opts,
GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
"git_format_email_options"); "git_format_email_options");
...@@ -260,14 +260,14 @@ int git_diff_format_email( ...@@ -260,14 +260,14 @@ int git_diff_format_email(
if (!ignore_marker) { if (!ignore_marker) {
if (opts->patch_no > opts->total_patches) { if (opts->patch_no > opts->total_patches) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"patch %"PRIuZ" out of range. max %"PRIuZ, "patch %"PRIuZ" out of range. max %"PRIuZ,
opts->patch_no, opts->total_patches); opts->patch_no, opts->total_patches);
return -1; return -1;
} }
if (opts->patch_no == 0) { if (opts->patch_no == 0) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"invalid patch no %"PRIuZ". should be >0", opts->patch_no); "invalid patch no %"PRIuZ". should be >0", opts->patch_no);
return -1; return -1;
} }
...@@ -280,14 +280,14 @@ int git_diff_format_email( ...@@ -280,14 +280,14 @@ int git_diff_format_email(
size_t offset = 0; size_t offset = 0;
if ((offset = (loc - opts->summary)) == 0) { if ((offset = (loc - opts->summary)) == 0) {
giterr_set(GITERR_INVALID, "summary is empty"); git_error_set(GIT_ERROR_INVALID, "summary is empty");
error = -1; error = -1;
goto on_error; goto on_error;
} }
GITERR_CHECK_ALLOC_ADD(&allocsize, offset, 1); GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, offset, 1);
summary = git__calloc(allocsize, sizeof(char)); summary = git__calloc(allocsize, sizeof(char));
GITERR_CHECK_ALLOC(summary); GIT_ERROR_CHECK_ALLOC(summary);
strncpy(summary, opts->summary, offset); strncpy(summary, opts->summary, offset);
} }
...@@ -466,7 +466,7 @@ static int line_cb( ...@@ -466,7 +466,7 @@ static int line_cb(
case GIT_DIFF_LINE_CONTEXT: case GIT_DIFF_LINE_CONTEXT:
break; break;
default: default:
giterr_set(GITERR_PATCH, "invalid line origin for patch"); git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch");
return -1; return -1;
} }
...@@ -493,7 +493,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt ...@@ -493,7 +493,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt
struct patch_id_args args; struct patch_id_args args;
int error; int error;
GITERR_CHECK_VERSION( GIT_ERROR_CHECK_VERSION(
opts, GIT_DIFF_PATCHID_OPTIONS_VERSION, "git_diff_patchid_options"); opts, GIT_DIFF_PATCHID_OPTIONS_VERSION, "git_diff_patchid_options");
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
......
...@@ -149,7 +149,7 @@ static git_diff_driver_registry *git_repository_driver_registry( ...@@ -149,7 +149,7 @@ static git_diff_driver_registry *git_repository_driver_registry(
} }
if (!repo->diff_drivers) if (!repo->diff_drivers)
giterr_set(GITERR_REPOSITORY, "unable to create diff driver registry"); git_error_set(GIT_ERROR_REPOSITORY, "unable to create diff driver registry");
return repo->diff_drivers; return repo->diff_drivers;
} }
...@@ -162,11 +162,11 @@ static int diff_driver_alloc( ...@@ -162,11 +162,11 @@ static int diff_driver_alloc(
namelen = strlen(name), namelen = strlen(name),
alloclen; alloclen;
GITERR_CHECK_ALLOC_ADD(&alloclen, driverlen, namelen); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, driverlen, namelen);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
driver = git__calloc(1, alloclen); driver = git__calloc(1, alloclen);
GITERR_CHECK_ALLOC(driver); GIT_ERROR_CHECK_ALLOC(driver);
memcpy(driver->name, name, namelen); memcpy(driver->name, name, namelen);
...@@ -211,7 +211,7 @@ static int git_diff_driver_builtin( ...@@ -211,7 +211,7 @@ static int git_diff_driver_builtin(
(error = p_regcomp( (error = p_regcomp(
&drv->word_pattern, ddef->words, ddef->flags | REG_EXTENDED))) &drv->word_pattern, ddef->words, ddef->flags | REG_EXTENDED)))
{ {
error = giterr_set_regex(&drv->word_pattern, error); error = git_error_set_regex(&drv->word_pattern, error);
goto done; goto done;
} }
...@@ -256,7 +256,7 @@ static int git_diff_driver_load( ...@@ -256,7 +256,7 @@ static int git_diff_driver_load(
/* if you can't read config for repo, just use default driver */ /* if you can't read config for repo, just use default driver */
if (git_repository_config_snapshot(&cfg, repo) < 0) { if (git_repository_config_snapshot(&cfg, repo) < 0) {
giterr_clear(); git_error_clear();
goto done; goto done;
} }
...@@ -287,7 +287,7 @@ static int git_diff_driver_load( ...@@ -287,7 +287,7 @@ static int git_diff_driver_load(
cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) { cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) {
if (error != GIT_ENOTFOUND) if (error != GIT_ENOTFOUND)
goto done; goto done;
giterr_clear(); /* no diff.<driver>.xfuncname, so just continue */ git_error_clear(); /* no diff.<driver>.xfuncname, so just continue */
} }
git_buf_truncate(&name, namelen + strlen("diff..")); git_buf_truncate(&name, namelen + strlen("diff.."));
...@@ -296,7 +296,7 @@ static int git_diff_driver_load( ...@@ -296,7 +296,7 @@ static int git_diff_driver_load(
cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) { cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) {
if (error != GIT_ENOTFOUND) if (error != GIT_ENOTFOUND)
goto done; goto done;
giterr_clear(); /* no diff.<driver>.funcname, so just continue */ git_error_clear(); /* no diff.<driver>.funcname, so just continue */
} }
/* if we found any patterns, set driver type to use correct callback */ /* if we found any patterns, set driver type to use correct callback */
...@@ -315,7 +315,7 @@ static int git_diff_driver_load( ...@@ -315,7 +315,7 @@ static int git_diff_driver_load(
found_driver = true; found_driver = true;
else { else {
/* TODO: warn about bad regex instead of failure */ /* TODO: warn about bad regex instead of failure */
error = giterr_set_regex(&drv->word_pattern, error); error = git_error_set_regex(&drv->word_pattern, error);
goto done; goto done;
} }
...@@ -379,7 +379,7 @@ int git_diff_driver_lookup( ...@@ -379,7 +379,7 @@ int git_diff_driver_lookup(
else if ((error = git_diff_driver_load(out, repo, values[0])) < 0) { else if ((error = git_diff_driver_load(out, repo, values[0])) < 0) {
if (error == GIT_ENOTFOUND) { if (error == GIT_ENOTFOUND) {
error = 0; error = 0;
giterr_clear(); git_error_clear();
} }
} }
......
...@@ -188,7 +188,7 @@ static int diff_file_content_commit_to_str( ...@@ -188,7 +188,7 @@ static int diff_file_content_commit_to_str(
if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) { if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) {
/* GIT_EEXISTS means a "submodule" that has not been git added */ /* GIT_EEXISTS means a "submodule" that has not been git added */
if (error == GIT_EEXISTS) { if (error == GIT_EEXISTS) {
giterr_clear(); git_error_clear();
error = 0; error = 0;
} }
return error; return error;
...@@ -303,13 +303,13 @@ static int diff_file_content_load_workdir_symlink( ...@@ -303,13 +303,13 @@ static int diff_file_content_load_workdir_symlink(
alloc_len = (ssize_t)(fc->file->size * 2) + 1; alloc_len = (ssize_t)(fc->file->size * 2) + 1;
fc->map.data = git__calloc(alloc_len, sizeof(char)); fc->map.data = git__calloc(alloc_len, sizeof(char));
GITERR_CHECK_ALLOC(fc->map.data); GIT_ERROR_CHECK_ALLOC(fc->map.data);
fc->flags |= GIT_DIFF_FLAG__FREE_DATA; fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len); read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len);
if (read_len < 0) { if (read_len < 0) {
giterr_set(GITERR_OS, "failed to read symlink '%s'", fc->file->path); git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", fc->file->path);
return -1; return -1;
} }
...@@ -352,7 +352,7 @@ static int diff_file_content_load_workdir_file( ...@@ -352,7 +352,7 @@ static int diff_file_content_load_workdir_file(
} }
/* if mmap failed, fall through to try readbuffer below */ /* if mmap failed, fall through to try readbuffer below */
giterr_clear(); git_error_clear();
} }
if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) { if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) {
......
...@@ -81,7 +81,7 @@ static int diff_insert_delta( ...@@ -81,7 +81,7 @@ static int diff_insert_delta(
if (error > 0) /* positive value means to skip this delta */ if (error > 0) /* positive value means to skip this delta */
return 0; return 0;
else /* negative value means to cancel diff */ else /* negative value means to cancel diff */
return giterr_set_after_callback_function(error, "git_diff"); return git_error_set_after_callback_function(error, "git_diff");
} }
} }
...@@ -157,7 +157,7 @@ static int diff_delta__from_one( ...@@ -157,7 +157,7 @@ static int diff_delta__from_one(
return 0; return 0;
delta = diff_delta__alloc(diff, status, entry->path); delta = diff_delta__alloc(diff, status, entry->path);
GITERR_CHECK_ALLOC(delta); GIT_ERROR_CHECK_ALLOC(delta);
/* This fn is just for single-sided diffs */ /* This fn is just for single-sided diffs */
assert(status != GIT_DELTA_MODIFIED); assert(status != GIT_DELTA_MODIFIED);
...@@ -220,7 +220,7 @@ static int diff_delta__from_two( ...@@ -220,7 +220,7 @@ static int diff_delta__from_two(
} }
delta = diff_delta__alloc(diff, status, canonical_path); delta = diff_delta__alloc(diff, status, canonical_path);
GITERR_CHECK_ALLOC(delta); GIT_ERROR_CHECK_ALLOC(delta);
delta->nfiles = 2; delta->nfiles = 2;
if (!git_index_entry_is_conflict(old_entry)) { if (!git_index_entry_is_conflict(old_entry)) {
...@@ -517,7 +517,7 @@ static int diff_generated_apply_options( ...@@ -517,7 +517,7 @@ static int diff_generated_apply_options(
if (entry && git_submodule_parse_ignore( if (entry && git_submodule_parse_ignore(
&diff->base.opts.ignore_submodules, entry->value) < 0) &diff->base.opts.ignore_submodules, entry->value) < 0)
giterr_clear(); git_error_clear();
git_config_entry_free(entry); git_config_entry_free(entry);
} }
...@@ -622,13 +622,13 @@ int git_diff__oid_for_entry( ...@@ -622,13 +622,13 @@ int git_diff__oid_for_entry(
/* if submodule lookup failed probably just in an intermediate /* if submodule lookup failed probably just in an intermediate
* state where some init hasn't happened, so ignore the error * state where some init hasn't happened, so ignore the error
*/ */
giterr_clear(); git_error_clear();
} }
} else if (S_ISLNK(mode)) { } else if (S_ISLNK(mode)) {
error = git_odb__hashlink(out, full_path.ptr); error = git_odb__hashlink(out, full_path.ptr);
diff->base.perf.oid_calculations++; diff->base.perf.oid_calculations++;
} else if (!git__is_sizet(entry.file_size)) { } else if (!git__is_sizet(entry.file_size)) {
giterr_set(GITERR_OS, "file size overflow (for 32-bits) on '%s'", git_error_set(GIT_ERROR_OS, "file size overflow (for 32-bits) on '%s'",
entry.path); entry.path);
error = -1; error = -1;
} else if (!(error = git_filter_list_load(&fl, } else if (!(error = git_filter_list_load(&fl,
...@@ -700,7 +700,7 @@ static int maybe_modified_submodule( ...@@ -700,7 +700,7 @@ static int maybe_modified_submodule(
/* GIT_EEXISTS means dir with .git in it was found - ignore it */ /* GIT_EEXISTS means dir with .git in it was found - ignore it */
if (error == GIT_EEXISTS) { if (error == GIT_EEXISTS) {
giterr_clear(); git_error_clear();
error = 0; error = 0;
} }
return error; return error;
...@@ -1060,7 +1060,7 @@ static int handle_unmatched_new_item( ...@@ -1060,7 +1060,7 @@ static int handle_unmatched_new_item(
/* if directory is empty, can't advance into it, so skip it */ /* if directory is empty, can't advance into it, so skip it */
if (error == GIT_ENOTFOUND) { if (error == GIT_ENOTFOUND) {
giterr_clear(); git_error_clear();
error = iterator_advance(&info->nitem, info->new_iter); error = iterator_advance(&info->nitem, info->new_iter);
} }
...@@ -1082,7 +1082,7 @@ static int handle_unmatched_new_item( ...@@ -1082,7 +1082,7 @@ static int handle_unmatched_new_item(
else if (nitem->mode == GIT_FILEMODE_COMMIT) { else if (nitem->mode == GIT_FILEMODE_COMMIT) {
/* ignore things that are not actual submodules */ /* ignore things that are not actual submodules */
if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) { if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) {
giterr_clear(); git_error_clear();
delta_type = GIT_DELTA_IGNORED; delta_type = GIT_DELTA_IGNORED;
/* if this contains a tracked item, treat as normal TREE */ /* if this contains a tracked item, treat as normal TREE */
...@@ -1091,7 +1091,7 @@ static int handle_unmatched_new_item( ...@@ -1091,7 +1091,7 @@ static int handle_unmatched_new_item(
if (error != GIT_ENOTFOUND) if (error != GIT_ENOTFOUND)
return error; return error;
giterr_clear(); git_error_clear();
return iterator_advance(&info->nitem, info->new_iter); return iterator_advance(&info->nitem, info->new_iter);
} }
} }
...@@ -1192,7 +1192,7 @@ int git_diff__from_iterators( ...@@ -1192,7 +1192,7 @@ int git_diff__from_iterators(
*out = NULL; *out = NULL;
diff = diff_generated_alloc(repo, old_iter, new_iter); diff = diff_generated_alloc(repo, old_iter, new_iter);
GITERR_CHECK_ALLOC(diff); GIT_ERROR_CHECK_ALLOC(diff);
info.repo = repo; info.repo = repo;
info.old_iter = old_iter; info.old_iter = old_iter;
...@@ -1269,7 +1269,7 @@ cleanup: ...@@ -1269,7 +1269,7 @@ cleanup:
b_opts.flags = FLAGS_SECOND; \ b_opts.flags = FLAGS_SECOND; \
b_opts.start = pfx; \ b_opts.start = pfx; \
b_opts.end = pfx; \ b_opts.end = pfx; \
GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \ GIT_ERROR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \
if (opts && (opts->flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH)) { \ if (opts && (opts->flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH)) { \
a_opts.pathlist.strings = opts->pathspec.strings; \ a_opts.pathlist.strings = opts->pathspec.strings; \
a_opts.pathlist.count = opts->pathspec.count; \ a_opts.pathlist.count = opts->pathspec.count; \
...@@ -1320,7 +1320,7 @@ static int diff_load_index(git_index **index, git_repository *repo) ...@@ -1320,7 +1320,7 @@ static int diff_load_index(git_index **index, git_repository *repo)
/* reload the repository index when user did not pass one in */ /* reload the repository index when user did not pass one in */
if (!error && git_index_read(*index, false) < 0) if (!error && git_index_read(*index, false) < 0)
giterr_clear(); git_error_clear();
return error; return error;
} }
...@@ -1552,7 +1552,7 @@ int git_diff__paired_foreach( ...@@ -1552,7 +1552,7 @@ int git_diff__paired_foreach(
} }
if ((error = cb(h2i, i2w, payload)) != 0) { if ((error = cb(h2i, i2w, payload)) != 0) {
giterr_set_after_callback(error); git_error_set_after_callback(error);
break; break;
} }
} }
...@@ -1591,7 +1591,7 @@ int git_diff__commit( ...@@ -1591,7 +1591,7 @@ int git_diff__commit(
char commit_oidstr[GIT_OID_HEXSZ + 1]; char commit_oidstr[GIT_OID_HEXSZ + 1];
error = -1; error = -1;
giterr_set(GITERR_INVALID, "commit %s is a merge commit", git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
goto on_error; goto on_error;
} }
......
...@@ -78,10 +78,10 @@ int git_diff_from_buffer( ...@@ -78,10 +78,10 @@ int git_diff_from_buffer(
*out = NULL; *out = NULL;
diff = diff_parsed_alloc(); diff = diff_parsed_alloc();
GITERR_CHECK_ALLOC(diff); GIT_ERROR_CHECK_ALLOC(diff);
ctx = git_patch_parse_ctx_init(content, content_len, NULL); ctx = git_patch_parse_ctx_init(content, content_len, NULL);
GITERR_CHECK_ALLOC(ctx); GIT_ERROR_CHECK_ALLOC(ctx);
while (ctx->parse_ctx.remain_len) { while (ctx->parse_ctx.remain_len) {
if ((error = git_patch_parse(&patch, ctx)) < 0) if ((error = git_patch_parse(&patch, ctx)) < 0)
...@@ -92,7 +92,7 @@ int git_diff_from_buffer( ...@@ -92,7 +92,7 @@ int git_diff_from_buffer(
} }
if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) { if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) {
giterr_clear(); git_error_clear();
error = 0; error = 0;
} }
......
...@@ -224,7 +224,7 @@ static int diff_print_one_raw( ...@@ -224,7 +224,7 @@ static int diff_print_one_raw(
delta->new_file.id_abbrev; delta->new_file.id_abbrev;
if (pi->id_strlen > id_abbrev) { if (pi->id_strlen > id_abbrev) {
giterr_set(GITERR_PATCH, git_error_set(GIT_ERROR_PATCH,
"the patch input contains %d id characters (cannot print %d)", "the patch input contains %d id characters (cannot print %d)",
id_abbrev, pi->id_strlen); id_abbrev, pi->id_strlen);
return -1; return -1;
...@@ -275,7 +275,7 @@ static int diff_print_oid_range( ...@@ -275,7 +275,7 @@ static int diff_print_oid_range(
if (delta->old_file.mode && if (delta->old_file.mode &&
id_strlen > delta->old_file.id_abbrev) { id_strlen > delta->old_file.id_abbrev) {
giterr_set(GITERR_PATCH, git_error_set(GIT_ERROR_PATCH,
"the patch input contains %d id characters (cannot print %d)", "the patch input contains %d id characters (cannot print %d)",
delta->old_file.id_abbrev, id_strlen); delta->old_file.id_abbrev, id_strlen);
return -1; return -1;
...@@ -283,7 +283,7 @@ static int diff_print_oid_range( ...@@ -283,7 +283,7 @@ static int diff_print_oid_range(
if ((delta->new_file.mode && if ((delta->new_file.mode &&
id_strlen > delta->new_file.id_abbrev)) { id_strlen > delta->new_file.id_abbrev)) {
giterr_set(GITERR_PATCH, git_error_set(GIT_ERROR_PATCH,
"the patch input contains %d id characters (cannot print %d)", "the patch input contains %d id characters (cannot print %d)",
delta->new_file.id_abbrev, id_strlen); delta->new_file.id_abbrev, id_strlen);
return -1; return -1;
...@@ -343,7 +343,7 @@ int diff_delta_format_similarity_header( ...@@ -343,7 +343,7 @@ int diff_delta_format_similarity_header(
int error = 0; int error = 0;
if (delta->similarity > 100) { if (delta->similarity > 100) {
giterr_set(GITERR_PATCH, "invalid similarity %d", delta->similarity); git_error_set(GIT_ERROR_PATCH, "invalid similarity %d", delta->similarity);
error = -1; error = -1;
goto done; goto done;
} }
...@@ -540,7 +540,7 @@ static int diff_print_patch_file_binary( ...@@ -540,7 +540,7 @@ static int diff_print_patch_file_binary(
binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) { binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) {
if (error == GIT_EBUFS) { if (error == GIT_EBUFS) {
giterr_clear(); git_error_clear();
git_buf_truncate(pi->buf, pre_binary_size); git_buf_truncate(pi->buf, pre_binary_size);
return diff_print_patch_file_binary_noshow( return diff_print_patch_file_binary_noshow(
...@@ -683,7 +683,7 @@ int git_diff_print( ...@@ -683,7 +683,7 @@ int git_diff_print(
print_file = diff_print_one_name_status; print_file = diff_print_one_name_status;
break; break;
default: default:
giterr_set(GITERR_INVALID, "unknown diff output format (%d)", format); git_error_set(GIT_ERROR_INVALID, "unknown diff output format (%d)", format);
return -1; return -1;
} }
...@@ -693,7 +693,7 @@ int git_diff_print( ...@@ -693,7 +693,7 @@ int git_diff_print(
diff, print_file, print_binary, print_hunk, print_line, &pi); diff, print_file, print_binary, print_hunk, print_line, &pi);
if (error) /* make sure error message is set */ if (error) /* make sure error message is set */
giterr_set_after_callback_function(error, "git_diff_print"); git_error_set_after_callback_function(error, "git_diff_print");
} }
git_buf_dispose(&buf); git_buf_dispose(&buf);
...@@ -711,7 +711,7 @@ int git_diff_print_callback__to_buf( ...@@ -711,7 +711,7 @@ int git_diff_print_callback__to_buf(
GIT_UNUSED(delta); GIT_UNUSED(hunk); GIT_UNUSED(delta); GIT_UNUSED(hunk);
if (!output) { if (!output) {
giterr_set(GITERR_INVALID, "buffer pointer must be provided"); git_error_set(GIT_ERROR_INVALID, "buffer pointer must be provided");
return -1; return -1;
} }
...@@ -773,7 +773,7 @@ int git_patch_print( ...@@ -773,7 +773,7 @@ int git_patch_print(
&pi); &pi);
if (error) /* make sure error message is set */ if (error) /* make sure error message is set */
giterr_set_after_callback_function(error, "git_patch_print"); git_error_set_after_callback_function(error, "git_patch_print");
} }
git_buf_dispose(&temp); git_buf_dispose(&temp);
......
...@@ -184,7 +184,7 @@ int git_diff_get_stats( ...@@ -184,7 +184,7 @@ int git_diff_get_stats(
assert(out && diff); assert(out && diff);
stats = git__calloc(1, sizeof(git_diff_stats)); stats = git__calloc(1, sizeof(git_diff_stats));
GITERR_CHECK_ALLOC(stats); GIT_ERROR_CHECK_ALLOC(stats);
deltas = git_diff_num_deltas(diff); deltas = git_diff_num_deltas(diff);
......
...@@ -131,7 +131,7 @@ int git_diff__merge( ...@@ -131,7 +131,7 @@ int git_diff__merge(
if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0) || if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0) ||
reversed != ((from->opts.flags & GIT_DIFF_REVERSE) != 0)) { reversed != ((from->opts.flags & GIT_DIFF_REVERSE) != 0)) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"attempt to merge diffs created with conflicting options"); "attempt to merge diffs created with conflicting options");
return -1; return -1;
} }
...@@ -251,7 +251,7 @@ static int normalize_find_opts( ...@@ -251,7 +251,7 @@ static int normalize_find_opts(
git_config *cfg = NULL; git_config *cfg = NULL;
git_hashsig_option_t hashsig_opts; git_hashsig_option_t hashsig_opts;
GITERR_CHECK_VERSION(given, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options"); GIT_ERROR_CHECK_VERSION(given, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options");
if (diff->repo != NULL && if (diff->repo != NULL &&
git_repository_config__weakptr(&cfg, diff->repo) < 0) git_repository_config__weakptr(&cfg, diff->repo) < 0)
...@@ -332,7 +332,7 @@ static int normalize_find_opts( ...@@ -332,7 +332,7 @@ static int normalize_find_opts(
/* assign the internal metric with whitespace flag as payload */ /* assign the internal metric with whitespace flag as payload */
if (!opts->metric) { if (!opts->metric) {
opts->metric = git__malloc(sizeof(git_diff_similarity_metric)); opts->metric = git__malloc(sizeof(git_diff_similarity_metric));
GITERR_CHECK_ALLOC(opts->metric); GIT_ERROR_CHECK_ALLOC(opts->metric);
opts->metric->file_signature = git_diff_find_similar__hashsig_for_file; opts->metric->file_signature = git_diff_find_similar__hashsig_for_file;
opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf; opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf;
...@@ -357,7 +357,7 @@ static int insert_delete_side_of_split( ...@@ -357,7 +357,7 @@ static int insert_delete_side_of_split(
{ {
/* make new record for DELETED side of split */ /* make new record for DELETED side of split */
git_diff_delta *deleted = git_diff__delta_dup(delta, &diff->pool); git_diff_delta *deleted = git_diff__delta_dup(delta, &diff->pool);
GITERR_CHECK_ALLOC(deleted); GIT_ERROR_CHECK_ALLOC(deleted);
deleted->status = GIT_DELTA_DELETED; deleted->status = GIT_DELTA_DELETED;
deleted->nfiles = 1; deleted->nfiles = 1;
...@@ -502,7 +502,7 @@ static int similarity_sig( ...@@ -502,7 +502,7 @@ static int similarity_sig(
if (error < 0) { if (error < 0) {
/* if lookup fails, just skip this item in similarity calc */ /* if lookup fails, just skip this item in similarity calc */
giterr_clear(); git_error_clear();
} else { } else {
size_t sz; size_t sz;
...@@ -831,9 +831,9 @@ int git_diff_find_similar( ...@@ -831,9 +831,9 @@ int git_diff_find_similar(
if ((opts.flags & GIT_DIFF_FIND_ALL) == 0) if ((opts.flags & GIT_DIFF_FIND_ALL) == 0)
goto cleanup; goto cleanup;
GITERR_CHECK_ALLOC_MULTIPLY(&sigcache_size, num_deltas, 2); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&sigcache_size, num_deltas, 2);
sigcache = git__calloc(sigcache_size, sizeof(void *)); sigcache = git__calloc(sigcache_size, sizeof(void *));
GITERR_CHECK_ALLOC(sigcache); GIT_ERROR_CHECK_ALLOC(sigcache);
/* Label rename sources and targets /* Label rename sources and targets
* *
...@@ -856,13 +856,13 @@ int git_diff_find_similar( ...@@ -856,13 +856,13 @@ int git_diff_find_similar(
goto cleanup; goto cleanup;
src2tgt = git__calloc(num_deltas, sizeof(diff_find_match)); src2tgt = git__calloc(num_deltas, sizeof(diff_find_match));
GITERR_CHECK_ALLOC(src2tgt); GIT_ERROR_CHECK_ALLOC(src2tgt);
tgt2src = git__calloc(num_deltas, sizeof(diff_find_match)); tgt2src = git__calloc(num_deltas, sizeof(diff_find_match));
GITERR_CHECK_ALLOC(tgt2src); GIT_ERROR_CHECK_ALLOC(tgt2src);
if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) { if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) {
tgt2src_copy = git__calloc(num_deltas, sizeof(diff_find_match)); tgt2src_copy = git__calloc(num_deltas, sizeof(diff_find_match));
GITERR_CHECK_ALLOC(tgt2src_copy); GIT_ERROR_CHECK_ALLOC(tgt2src_copy);
} }
/* /*
......
...@@ -52,7 +52,7 @@ static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header) ...@@ -52,7 +52,7 @@ static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header)
return 0; return 0;
fail: fail:
giterr_set(GITERR_INVALID, "malformed hunk header from xdiff"); git_error_set(GIT_ERROR_INVALID, "malformed hunk header from xdiff");
return -1; return -1;
} }
...@@ -101,7 +101,7 @@ static int diff_update_lines( ...@@ -101,7 +101,7 @@ static int diff_update_lines(
info->new_lineno += (int)line->num_lines; info->new_lineno += (int)line->num_lines;
break; break;
default: default:
giterr_set(GITERR_INVALID, "unknown diff line origin %02x", git_error_set(GIT_ERROR_INVALID, "unknown diff line origin %02x",
(unsigned int)line->origin); (unsigned int)line->origin);
return -1; return -1;
} }
...@@ -224,7 +224,7 @@ static int git_xdiff(git_patch_generated_output *output, git_patch_generated *pa ...@@ -224,7 +224,7 @@ static int git_xdiff(git_patch_generated_output *output, git_patch_generated *pa
if (info.xd_old_data.size > GIT_XDIFF_MAX_SIZE || if (info.xd_old_data.size > GIT_XDIFF_MAX_SIZE ||
info.xd_new_data.size > GIT_XDIFF_MAX_SIZE) { info.xd_new_data.size > GIT_XDIFF_MAX_SIZE) {
giterr_set(GITERR_INVALID, "files too large for diff"); git_error_set(GIT_ERROR_INVALID, "files too large for diff");
return -1; return -1;
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
static git_error g_git_oom_error = { static git_error g_git_oom_error = {
"Out of memory", "Out of memory",
GITERR_NOMEMORY GIT_ERROR_NOMEMORY
}; };
static void set_error_from_buffer(int error_class) static void set_error_from_buffer(int error_class)
...@@ -44,18 +44,18 @@ static void set_error(int error_class, char *string) ...@@ -44,18 +44,18 @@ static void set_error(int error_class, char *string)
set_error_from_buffer(error_class); set_error_from_buffer(error_class);
} }
void giterr_set_oom(void) void git_error_set_oom(void)
{ {
GIT_GLOBAL->last_error = &g_git_oom_error; GIT_GLOBAL->last_error = &g_git_oom_error;
} }
void giterr_set(int error_class, const char *string, ...) void git_error_set(int error_class, const char *string, ...)
{ {
va_list arglist; va_list arglist;
#ifdef GIT_WIN32 #ifdef GIT_WIN32
DWORD win32_error_code = (error_class == GITERR_OS) ? GetLastError() : 0; DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif #endif
int error_code = (error_class == GITERR_OS) ? errno : 0; int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
git_buf *buf = &GIT_GLOBAL->error_buf; git_buf *buf = &GIT_GLOBAL->error_buf;
git_buf_clear(buf); git_buf_clear(buf);
...@@ -64,11 +64,11 @@ void giterr_set(int error_class, const char *string, ...) ...@@ -64,11 +64,11 @@ void giterr_set(int error_class, const char *string, ...)
git_buf_vprintf(buf, string, arglist); git_buf_vprintf(buf, string, arglist);
va_end(arglist); va_end(arglist);
if (error_class == GITERR_OS) if (error_class == GIT_ERROR_OS)
git_buf_PUTS(buf, ": "); git_buf_PUTS(buf, ": ");
} }
if (error_class == GITERR_OS) { if (error_class == GIT_ERROR_OS) {
#ifdef GIT_WIN32 #ifdef GIT_WIN32
char * win32_error = git_win32_get_error_message(win32_error_code); char * win32_error = git_win32_get_error_message(win32_error_code);
if (win32_error) { if (win32_error) {
...@@ -90,7 +90,7 @@ void giterr_set(int error_class, const char *string, ...) ...@@ -90,7 +90,7 @@ void giterr_set(int error_class, const char *string, ...)
set_error_from_buffer(error_class); set_error_from_buffer(error_class);
} }
void giterr_set_str(int error_class, const char *string) void git_error_set_str(int error_class, const char *string)
{ {
git_buf *buf = &GIT_GLOBAL->error_buf; git_buf *buf = &GIT_GLOBAL->error_buf;
...@@ -105,14 +105,14 @@ void giterr_set_str(int error_class, const char *string) ...@@ -105,14 +105,14 @@ void giterr_set_str(int error_class, const char *string)
set_error_from_buffer(error_class); set_error_from_buffer(error_class);
} }
int giterr_set_regex(const regex_t *regex, int error_code) int git_error_set_regex(const regex_t *regex, int error_code)
{ {
char error_buf[1024]; char error_buf[1024];
assert(error_code); assert(error_code);
regerror(error_code, regex, error_buf, sizeof(error_buf)); regerror(error_code, regex, error_buf, sizeof(error_buf));
giterr_set_str(GITERR_REGEX, error_buf); git_error_set_str(GIT_ERROR_REGEX, error_buf);
if (error_code == REG_NOMATCH) if (error_code == REG_NOMATCH)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -120,7 +120,7 @@ int giterr_set_regex(const regex_t *regex, int error_code) ...@@ -120,7 +120,7 @@ int giterr_set_regex(const regex_t *regex, int error_code)
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
void giterr_clear(void) void git_error_clear(void)
{ {
if (GIT_GLOBAL->last_error != NULL) { if (GIT_GLOBAL->last_error != NULL) {
set_error(0, NULL); set_error(0, NULL);
...@@ -133,12 +133,12 @@ void giterr_clear(void) ...@@ -133,12 +133,12 @@ void giterr_clear(void)
#endif #endif
} }
const git_error *giterr_last(void) const git_error *git_error_last(void)
{ {
return GIT_GLOBAL->last_error; return GIT_GLOBAL->last_error;
} }
int giterr_state_capture(git_error_state *state, int error_code) int git_error_state_capture(git_error_state *state, int error_code)
{ {
git_error *error = GIT_GLOBAL->last_error; git_error *error = GIT_GLOBAL->last_error;
git_buf *error_buf = &GIT_GLOBAL->error_buf; git_buf *error_buf = &GIT_GLOBAL->error_buf;
...@@ -160,19 +160,19 @@ int giterr_state_capture(git_error_state *state, int error_code) ...@@ -160,19 +160,19 @@ int giterr_state_capture(git_error_state *state, int error_code)
state->error_msg.message = git_buf_detach(error_buf); state->error_msg.message = git_buf_detach(error_buf);
} }
giterr_clear(); git_error_clear();
return error_code; return error_code;
} }
int giterr_state_restore(git_error_state *state) int git_error_state_restore(git_error_state *state)
{ {
int ret = 0; int ret = 0;
giterr_clear(); git_error_clear();
if (state && state->error_msg.message) { if (state && state->error_msg.message) {
if (state->oom) if (state->oom)
giterr_set_oom(); git_error_set_oom();
else else
set_error(state->error_msg.klass, state->error_msg.message); set_error(state->error_msg.klass, state->error_msg.message);
...@@ -183,7 +183,7 @@ int giterr_state_restore(git_error_state *state) ...@@ -183,7 +183,7 @@ int giterr_state_restore(git_error_state *state)
return ret; return ret;
} }
void giterr_state_free(git_error_state *state) void git_error_state_free(git_error_state *state)
{ {
if (!state) if (!state)
return; return;
...@@ -194,7 +194,7 @@ void giterr_state_free(git_error_state *state) ...@@ -194,7 +194,7 @@ void giterr_state_free(git_error_state *state)
memset(state, 0, sizeof(git_error_state)); memset(state, 0, sizeof(git_error_state));
} }
int giterr_system_last(void) int git_error_system_last(void)
{ {
#ifdef GIT_WIN32 #ifdef GIT_WIN32
return GetLastError(); return GetLastError();
...@@ -203,7 +203,7 @@ int giterr_system_last(void) ...@@ -203,7 +203,7 @@ int giterr_system_last(void)
#endif #endif
} }
void giterr_system_set(int code) void git_error_system_set(int code)
{ {
#ifdef GIT_WIN32 #ifdef GIT_WIN32
SetLastError(code); SetLastError(code);
...@@ -211,3 +211,25 @@ void giterr_system_set(int code) ...@@ -211,3 +211,25 @@ void giterr_system_set(int code)
errno = code; errno = code;
#endif #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)
{
return git_error_set_str(error_class, string);
}
void giterr_set_oom(void)
{
git_error_set_oom();
}
...@@ -113,7 +113,7 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) ...@@ -113,7 +113,7 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
remote->need_pack = 0; remote->need_pack = 0;
if (filter_wants(remote, opts) < 0) { if (filter_wants(remote, opts) < 0) {
giterr_set(GITERR_NET, "failed to filter the reference list for wants"); git_error_set(GIT_ERROR_NET, "failed to filter the reference list for wants");
return -1; return -1;
} }
......
...@@ -50,7 +50,7 @@ int git_fetchhead_ref_create( ...@@ -50,7 +50,7 @@ int git_fetchhead_ref_create(
*out = NULL; *out = NULL;
fetchhead_ref = git__malloc(sizeof(git_fetchhead_ref)); fetchhead_ref = git__malloc(sizeof(git_fetchhead_ref));
GITERR_CHECK_ALLOC(fetchhead_ref); GIT_ERROR_CHECK_ALLOC(fetchhead_ref);
memset(fetchhead_ref, 0x0, sizeof(git_fetchhead_ref)); memset(fetchhead_ref, 0x0, sizeof(git_fetchhead_ref));
...@@ -148,7 +148,7 @@ static int fetchhead_ref_parse( ...@@ -148,7 +148,7 @@ static int fetchhead_ref_parse(
*remote_url = NULL; *remote_url = NULL;
if (!*line) { if (!*line) {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"empty line in FETCH_HEAD line %"PRIuZ, line_num); "empty line in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
...@@ -162,16 +162,16 @@ static int fetchhead_ref_parse( ...@@ -162,16 +162,16 @@ static int fetchhead_ref_parse(
} }
if (strlen(oid_str) != GIT_OID_HEXSZ) { if (strlen(oid_str) != GIT_OID_HEXSZ) {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"invalid object ID in FETCH_HEAD line %"PRIuZ, line_num); "invalid object ID in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
if (git_oid_fromstr(oid, oid_str) < 0) { if (git_oid_fromstr(oid, oid_str) < 0) {
const git_error *oid_err = giterr_last(); const git_error *oid_err = git_error_last();
const char *err_msg = oid_err ? oid_err->message : "invalid object ID"; const char *err_msg = oid_err ? oid_err->message : "invalid object ID";
giterr_set(GITERR_FETCHHEAD, "%s in FETCH_HEAD line %"PRIuZ, git_error_set(GIT_ERROR_FETCHHEAD, "%s in FETCH_HEAD line %"PRIuZ,
err_msg, line_num); err_msg, line_num);
return -1; return -1;
} }
...@@ -179,7 +179,7 @@ static int fetchhead_ref_parse( ...@@ -179,7 +179,7 @@ static int fetchhead_ref_parse(
/* Parse new data from newer git clients */ /* Parse new data from newer git clients */
if (*line) { if (*line) {
if ((is_merge_str = git__strsep(&line, "\t")) == NULL) { if ((is_merge_str = git__strsep(&line, "\t")) == NULL) {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"invalid description data in FETCH_HEAD line %"PRIuZ, line_num); "invalid description data in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
...@@ -189,13 +189,13 @@ static int fetchhead_ref_parse( ...@@ -189,13 +189,13 @@ static int fetchhead_ref_parse(
else if (strcmp(is_merge_str, "not-for-merge") == 0) else if (strcmp(is_merge_str, "not-for-merge") == 0)
*is_merge = 0; *is_merge = 0;
else { else {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num); "invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
if ((desc = line) == NULL) { if ((desc = line) == NULL) {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"invalid description in FETCH_HEAD line %"PRIuZ, line_num); "invalid description in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
...@@ -212,7 +212,7 @@ static int fetchhead_ref_parse( ...@@ -212,7 +212,7 @@ static int fetchhead_ref_parse(
if (name) { if (name) {
if ((desc = strstr(name, "' ")) == NULL || if ((desc = strstr(name, "' ")) == NULL ||
git__prefixcmp(desc, "' of ") != 0) { git__prefixcmp(desc, "' of ") != 0) {
giterr_set(GITERR_FETCHHEAD, git_error_set(GIT_ERROR_FETCHHEAD,
"invalid description in FETCH_HEAD line %"PRIuZ, line_num); "invalid description in FETCH_HEAD line %"PRIuZ, line_num);
return -1; return -1;
} }
...@@ -271,13 +271,13 @@ int git_repository_fetchhead_foreach(git_repository *repo, ...@@ -271,13 +271,13 @@ int git_repository_fetchhead_foreach(git_repository *repo,
error = cb(ref_name, remote_url, &oid, is_merge, payload); error = cb(ref_name, remote_url, &oid, is_merge, payload);
if (error) { if (error) {
giterr_set_after_callback(error); git_error_set_after_callback(error);
goto done; goto done;
} }
} }
if (*buffer) { if (*buffer) {
giterr_set(GITERR_FETCHHEAD, "no EOL at line %"PRIuZ, line_num+1); git_error_set(GIT_ERROR_FETCHHEAD, "no EOL at line %"PRIuZ, line_num+1);
error = -1; error = -1;
goto done; goto done;
} }
......
...@@ -24,15 +24,15 @@ static int verify_last_error(git_filebuf *file) ...@@ -24,15 +24,15 @@ static int verify_last_error(git_filebuf *file)
{ {
switch (file->last_error) { switch (file->last_error) {
case BUFERR_WRITE: case BUFERR_WRITE:
giterr_set(GITERR_OS, "failed to write out file"); git_error_set(GIT_ERROR_OS, "failed to write out file");
return -1; return -1;
case BUFERR_MEM: case BUFERR_MEM:
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
case BUFERR_ZLIB: case BUFERR_ZLIB:
giterr_set(GITERR_ZLIB, git_error_set(GIT_ERROR_ZLIB,
"Buffer error when writing out ZLib data"); "Buffer error when writing out ZLib data");
return -1; return -1;
...@@ -47,8 +47,8 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) ...@@ -47,8 +47,8 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
if (flags & GIT_FILEBUF_FORCE) if (flags & GIT_FILEBUF_FORCE)
p_unlink(file->path_lock); p_unlink(file->path_lock);
else { else {
giterr_clear(); /* actual OS error code just confuses */ git_error_clear(); /* actual OS error code just confuses */
giterr_set(GITERR_OS, git_error_set(GIT_ERROR_OS,
"failed to lock file '%s' for writing", file->path_lock); "failed to lock file '%s' for writing", file->path_lock);
return GIT_ELOCKED; return GIT_ELOCKED;
} }
...@@ -75,7 +75,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) ...@@ -75,7 +75,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
source = p_open(file->path_original, O_RDONLY); source = p_open(file->path_original, O_RDONLY);
if (source < 0) { if (source < 0) {
giterr_set(GITERR_OS, git_error_set(GIT_ERROR_OS,
"failed to open file '%s' for reading", "failed to open file '%s' for reading",
file->path_original); file->path_original);
return -1; return -1;
...@@ -91,10 +91,10 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) ...@@ -91,10 +91,10 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
p_close(source); p_close(source);
if (read_bytes < 0) { if (read_bytes < 0) {
giterr_set(GITERR_OS, "failed to read file '%s'", file->path_original); git_error_set(GIT_ERROR_OS, "failed to read file '%s'", file->path_original);
return -1; return -1;
} else if (error < 0) { } else if (error < 0) {
giterr_set(GITERR_OS, "failed to write file '%s'", file->path_lock); git_error_set(GIT_ERROR_OS, "failed to write file '%s'", file->path_lock);
return -1; return -1;
} }
} }
...@@ -218,7 +218,7 @@ static int resolve_symlink(git_buf *out, const char *path) ...@@ -218,7 +218,7 @@ static int resolve_symlink(git_buf *out, const char *path)
} }
if (error < 0) { if (error < 0) {
giterr_set(GITERR_OS, "failed to stat '%s'", curpath.ptr); git_error_set(GIT_ERROR_OS, "failed to stat '%s'", curpath.ptr);
error = -1; error = -1;
goto cleanup; goto cleanup;
} }
...@@ -230,13 +230,13 @@ static int resolve_symlink(git_buf *out, const char *path) ...@@ -230,13 +230,13 @@ static int resolve_symlink(git_buf *out, const char *path)
ret = p_readlink(curpath.ptr, target.ptr, GIT_PATH_MAX); ret = p_readlink(curpath.ptr, target.ptr, GIT_PATH_MAX);
if (ret < 0) { if (ret < 0) {
giterr_set(GITERR_OS, "failed to read symlink '%s'", curpath.ptr); git_error_set(GIT_ERROR_OS, "failed to read symlink '%s'", curpath.ptr);
error = -1; error = -1;
goto cleanup; goto cleanup;
} }
if (ret == GIT_PATH_MAX) { if (ret == GIT_PATH_MAX) {
giterr_set(GITERR_INVALID, "symlink target too long"); git_error_set(GIT_ERROR_INVALID, "symlink target too long");
error = -1; error = -1;
goto cleanup; goto cleanup;
} }
...@@ -263,7 +263,7 @@ static int resolve_symlink(git_buf *out, const char *path) ...@@ -263,7 +263,7 @@ static int resolve_symlink(git_buf *out, const char *path)
} }
} }
giterr_set(GITERR_INVALID, "maximum symlink depth reached"); git_error_set(GIT_ERROR_INVALID, "maximum symlink depth reached");
error = -1; error = -1;
cleanup: cleanup:
...@@ -303,7 +303,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo ...@@ -303,7 +303,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* Allocate the main cache buffer */ /* Allocate the main cache buffer */
if (!file->do_not_buffer) { if (!file->do_not_buffer) {
file->buffer = git__malloc(file->buf_size); file->buffer = git__malloc(file->buf_size);
GITERR_CHECK_ALLOC(file->buffer); GIT_ERROR_CHECK_ALLOC(file->buffer);
} }
/* If we are hashing on-write, allocate a new hash context */ /* If we are hashing on-write, allocate a new hash context */
...@@ -320,13 +320,13 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo ...@@ -320,13 +320,13 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
if (compression != 0) { if (compression != 0) {
/* Initialize the ZLib stream */ /* Initialize the ZLib stream */
if (deflateInit(&file->zs, compression) != Z_OK) { if (deflateInit(&file->zs, compression) != Z_OK) {
giterr_set(GITERR_ZLIB, "failed to initialize zlib"); git_error_set(GIT_ERROR_ZLIB, "failed to initialize zlib");
goto cleanup; goto cleanup;
} }
/* Allocate the Zlib cache buffer */ /* Allocate the Zlib cache buffer */
file->z_buf = git__malloc(file->buf_size); file->z_buf = git__malloc(file->buf_size);
GITERR_CHECK_ALLOC(file->z_buf); GIT_ERROR_CHECK_ALLOC(file->z_buf);
/* Never flush */ /* Never flush */
file->flush_mode = Z_NO_FLUSH; file->flush_mode = Z_NO_FLUSH;
...@@ -352,7 +352,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo ...@@ -352,7 +352,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
/* No original path */ /* No original path */
file->path_original = NULL; file->path_original = NULL;
file->path_lock = git_buf_detach(&tmp_path); file->path_lock = git_buf_detach(&tmp_path);
GITERR_CHECK_ALLOC(file->path_lock); GIT_ERROR_CHECK_ALLOC(file->path_lock);
} else { } else {
git_buf resolved_path = GIT_BUF_INIT; git_buf resolved_path = GIT_BUF_INIT;
...@@ -364,15 +364,15 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo ...@@ -364,15 +364,15 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
file->path_original = git_buf_detach(&resolved_path); file->path_original = git_buf_detach(&resolved_path);
/* create the locking path by appending ".lock" to the original */ /* create the locking path by appending ".lock" to the original */
GITERR_CHECK_ALLOC_ADD(&alloc_len, path_len, GIT_FILELOCK_EXTLENGTH); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, path_len, GIT_FILELOCK_EXTLENGTH);
file->path_lock = git__malloc(alloc_len); file->path_lock = git__malloc(alloc_len);
GITERR_CHECK_ALLOC(file->path_lock); GIT_ERROR_CHECK_ALLOC(file->path_lock);
memcpy(file->path_lock, file->path_original, path_len); memcpy(file->path_lock, file->path_original, path_len);
memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH); memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH);
if (git_path_isdir(file->path_original)) { if (git_path_isdir(file->path_original)) {
giterr_set(GITERR_FILESYSTEM, "path '%s' is a directory", file->path_original); git_error_set(GIT_ERROR_FILESYSTEM, "path '%s' is a directory", file->path_original);
error = GIT_EDIRECTORY; error = GIT_EDIRECTORY;
goto cleanup; goto cleanup;
} }
...@@ -411,7 +411,7 @@ int git_filebuf_commit_at(git_filebuf *file, const char *path) ...@@ -411,7 +411,7 @@ int git_filebuf_commit_at(git_filebuf *file, const char *path)
{ {
git__free(file->path_original); git__free(file->path_original);
file->path_original = git__strdup(path); file->path_original = git__strdup(path);
GITERR_CHECK_ALLOC(file->path_original); GIT_ERROR_CHECK_ALLOC(file->path_original);
return git_filebuf_commit(file); return git_filebuf_commit(file);
} }
...@@ -430,19 +430,19 @@ int git_filebuf_commit(git_filebuf *file) ...@@ -430,19 +430,19 @@ int git_filebuf_commit(git_filebuf *file)
file->fd_is_open = false; file->fd_is_open = false;
if (file->do_fsync && p_fsync(file->fd) < 0) { if (file->do_fsync && p_fsync(file->fd) < 0) {
giterr_set(GITERR_OS, "failed to fsync '%s'", file->path_lock); git_error_set(GIT_ERROR_OS, "failed to fsync '%s'", file->path_lock);
goto on_error; goto on_error;
} }
if (p_close(file->fd) < 0) { if (p_close(file->fd) < 0) {
giterr_set(GITERR_OS, "failed to close file at '%s'", file->path_lock); git_error_set(GIT_ERROR_OS, "failed to close file at '%s'", file->path_lock);
goto on_error; goto on_error;
} }
file->fd = -1; file->fd = -1;
if (p_rename(file->path_lock, file->path_original) < 0) { if (p_rename(file->path_lock, file->path_original) < 0) {
giterr_set(GITERR_OS, "failed to rename lockfile to '%s'", file->path_original); git_error_set(GIT_ERROR_OS, "failed to rename lockfile to '%s'", file->path_original);
goto on_error; goto on_error;
} }
...@@ -583,7 +583,7 @@ int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file) ...@@ -583,7 +583,7 @@ int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file)
res = p_stat(file->path_original, &st); res = p_stat(file->path_original, &st);
if (res < 0) { if (res < 0) {
giterr_set(GITERR_OS, "could not get stat info for '%s'", git_error_set(GIT_ERROR_OS, "could not get stat info for '%s'",
file->path_original); file->path_original);
return res; return res;
} }
......
...@@ -340,7 +340,7 @@ typedef struct { ...@@ -340,7 +340,7 @@ typedef struct {
* This function updates the file stamp to current data for the given path * This function updates the file stamp to current data for the given path
* and returns 0 if the file is up-to-date relative to the prior setting, * and returns 0 if the file is up-to-date relative to the prior setting,
* 1 if the file has been changed, or GIT_ENOTFOUND if the file doesn't * 1 if the file has been changed, or GIT_ENOTFOUND if the file doesn't
* exist. This will not call giterr_set, so you must set the error if you * exist. This will not call git_error_set, so you must set the error if you
* plan to return an error. * plan to return an error.
* *
* @param stamp File stamp to be checked * @param stamp File stamp to be checked
......
...@@ -157,15 +157,15 @@ static int filter_registry_insert( ...@@ -157,15 +157,15 @@ static int filter_registry_insert(
if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0) if (filter_def_scan_attrs(&attrs, &nattr, &nmatch, filter->attributes) < 0)
return -1; return -1;
GITERR_CHECK_ALLOC_MULTIPLY(&alloc_len, nattr, 2); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_len, nattr, 2);
GITERR_CHECK_ALLOC_MULTIPLY(&alloc_len, alloc_len, sizeof(char *)); GIT_ERROR_CHECK_ALLOC_MULTIPLY(&alloc_len, alloc_len, sizeof(char *));
GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, sizeof(git_filter_def)); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, sizeof(git_filter_def));
fdef = git__calloc(1, alloc_len); fdef = git__calloc(1, alloc_len);
GITERR_CHECK_ALLOC(fdef); GIT_ERROR_CHECK_ALLOC(fdef);
fdef->filter_name = git__strdup(name); fdef->filter_name = git__strdup(name);
GITERR_CHECK_ALLOC(fdef->filter_name); GIT_ERROR_CHECK_ALLOC(fdef->filter_name);
fdef->filter = filter; fdef->filter = filter;
fdef->priority = priority; fdef->priority = priority;
...@@ -269,13 +269,13 @@ int git_filter_register( ...@@ -269,13 +269,13 @@ int git_filter_register(
assert(name && filter); assert(name && filter);
if (git_rwlock_wrlock(&filter_registry.lock) < 0) { if (git_rwlock_wrlock(&filter_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock filter registry"); git_error_set(GIT_ERROR_OS, "failed to lock filter registry");
return -1; return -1;
} }
if (!filter_registry_find(NULL, name)) { if (!filter_registry_find(NULL, name)) {
giterr_set( git_error_set(
GITERR_FILTER, "attempt to reregister existing filter '%s'", name); GIT_ERROR_FILTER, "attempt to reregister existing filter '%s'", name);
error = GIT_EEXISTS; error = GIT_EEXISTS;
goto done; goto done;
} }
...@@ -297,17 +297,17 @@ int git_filter_unregister(const char *name) ...@@ -297,17 +297,17 @@ int git_filter_unregister(const char *name)
/* cannot unregister default filters */ /* cannot unregister default filters */
if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) { if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) {
giterr_set(GITERR_FILTER, "cannot unregister filter '%s'", name); git_error_set(GIT_ERROR_FILTER, "cannot unregister filter '%s'", name);
return -1; return -1;
} }
if (git_rwlock_wrlock(&filter_registry.lock) < 0) { if (git_rwlock_wrlock(&filter_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock filter registry"); git_error_set(GIT_ERROR_OS, "failed to lock filter registry");
return -1; return -1;
} }
if ((fdef = filter_registry_lookup(&pos, name)) == NULL) { if ((fdef = filter_registry_lookup(&pos, name)) == NULL) {
giterr_set(GITERR_FILTER, "cannot find filter '%s' to unregister", name); git_error_set(GIT_ERROR_FILTER, "cannot find filter '%s' to unregister", name);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto done; goto done;
} }
...@@ -348,7 +348,7 @@ git_filter *git_filter_lookup(const char *name) ...@@ -348,7 +348,7 @@ git_filter *git_filter_lookup(const char *name)
git_filter *filter = NULL; git_filter *filter = NULL;
if (git_rwlock_rdlock(&filter_registry.lock) < 0) { if (git_rwlock_rdlock(&filter_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock filter registry"); git_error_set(GIT_ERROR_OS, "failed to lock filter registry");
return NULL; return NULL;
} }
...@@ -404,11 +404,11 @@ static int filter_list_new( ...@@ -404,11 +404,11 @@ static int filter_list_new(
git_filter_list *fl = NULL; git_filter_list *fl = NULL;
size_t pathlen = src->path ? strlen(src->path) : 0, alloclen; size_t pathlen = src->path ? strlen(src->path) : 0, alloclen;
GITERR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_filter_list), pathlen); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(git_filter_list), pathlen);
GITERR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1); GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
fl = git__calloc(1, alloclen); fl = git__calloc(1, alloclen);
GITERR_CHECK_ALLOC(fl); GIT_ERROR_CHECK_ALLOC(fl);
if (src->path) if (src->path)
memcpy(fl->path, src->path, pathlen); memcpy(fl->path, src->path, pathlen);
...@@ -431,14 +431,14 @@ static int filter_list_check_attributes( ...@@ -431,14 +431,14 @@ static int filter_list_check_attributes(
int error; int error;
size_t i; size_t i;
const char **strs = git__calloc(fdef->nattrs, sizeof(const char *)); const char **strs = git__calloc(fdef->nattrs, sizeof(const char *));
GITERR_CHECK_ALLOC(strs); GIT_ERROR_CHECK_ALLOC(strs);
error = git_attr_get_many_with_session( error = git_attr_get_many_with_session(
strs, repo, attr_session, 0, src->path, fdef->nattrs, fdef->attrs); strs, repo, attr_session, 0, src->path, fdef->nattrs, fdef->attrs);
/* if no values were found but no matches are needed, it's okay! */ /* if no values were found but no matches are needed, it's okay! */
if (error == GIT_ENOTFOUND && !fdef->nmatches) { if (error == GIT_ENOTFOUND && !fdef->nmatches) {
giterr_clear(); git_error_clear();
git__free((void *)strs); git__free((void *)strs);
return 0; return 0;
} }
...@@ -499,7 +499,7 @@ int git_filter_list__load_ext( ...@@ -499,7 +499,7 @@ int git_filter_list__load_ext(
git_filter_def *fdef; git_filter_def *fdef;
if (git_rwlock_rdlock(&filter_registry.lock) < 0) { if (git_rwlock_rdlock(&filter_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock filter registry"); git_error_set(GIT_ERROR_OS, "failed to lock filter registry");
return -1; return -1;
} }
...@@ -551,7 +551,7 @@ int git_filter_list__load_ext( ...@@ -551,7 +551,7 @@ int git_filter_list__load_ext(
} }
fe = git_array_alloc(fl->filters); fe = git_array_alloc(fl->filters);
GITERR_CHECK_ALLOC(fe); GIT_ERROR_CHECK_ALLOC(fe);
fe->filter = fdef->filter; fe->filter = fdef->filter;
fe->filter_name = fdef->filter_name; fe->filter_name = fdef->filter_name;
...@@ -634,7 +634,7 @@ int git_filter_list_push( ...@@ -634,7 +634,7 @@ int git_filter_list_push(
assert(fl && filter); assert(fl && filter);
if (git_rwlock_rdlock(&filter_registry.lock) < 0) { if (git_rwlock_rdlock(&filter_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock filter registry"); git_error_set(GIT_ERROR_OS, "failed to lock filter registry");
return -1; return -1;
} }
...@@ -646,7 +646,7 @@ int git_filter_list_push( ...@@ -646,7 +646,7 @@ int git_filter_list_push(
git_rwlock_rdunlock(&filter_registry.lock); git_rwlock_rdunlock(&filter_registry.lock);
if (fdef == NULL) { if (fdef == NULL) {
giterr_set(GITERR_FILTER, "cannot use an unregistered filter"); git_error_set(GIT_ERROR_FILTER, "cannot use an unregistered filter");
return -1; return -1;
} }
...@@ -654,7 +654,7 @@ int git_filter_list_push( ...@@ -654,7 +654,7 @@ int git_filter_list_push(
return error; return error;
fe = git_array_alloc(fl->filters); fe = git_array_alloc(fl->filters);
GITERR_CHECK_ALLOC(fe); GIT_ERROR_CHECK_ALLOC(fe);
fe->filter = filter; fe->filter = filter;
fe->payload = payload; fe->payload = payload;
...@@ -759,7 +759,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob) ...@@ -759,7 +759,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob)
git_off_t rawsize = git_blob_rawsize(blob); git_off_t rawsize = git_blob_rawsize(blob);
if (!git__is_sizet(rawsize)) { if (!git__is_sizet(rawsize)) {
giterr_set(GITERR_OS, "blob is too large to filter"); git_error_set(GIT_ERROR_OS, "blob is too large to filter");
return -1; return -1;
} }
...@@ -829,9 +829,9 @@ static int proxy_stream_close(git_writestream *s) ...@@ -829,9 +829,9 @@ static int proxy_stream_close(git_writestream *s)
} else { } else {
/* close stream before erroring out taking care /* close stream before erroring out taking care
* to preserve the original error */ * to preserve the original error */
giterr_state_capture(&error_state, error); git_error_state_capture(&error_state, error);
proxy_stream->target->close(proxy_stream->target); proxy_stream->target->close(proxy_stream->target);
giterr_state_restore(&error_state); git_error_state_restore(&error_state);
return error; return error;
} }
...@@ -861,7 +861,7 @@ static int proxy_stream_init( ...@@ -861,7 +861,7 @@ static int proxy_stream_init(
git_writestream *target) git_writestream *target)
{ {
struct proxy_stream *proxy_stream = git__calloc(1, sizeof(struct proxy_stream)); struct proxy_stream *proxy_stream = git__calloc(1, sizeof(struct proxy_stream));
GITERR_CHECK_ALLOC(proxy_stream); GIT_ERROR_CHECK_ALLOC(proxy_stream);
proxy_stream->parent.write = proxy_stream_write; proxy_stream->parent.write = proxy_stream_write;
proxy_stream->parent.close = proxy_stream_close; proxy_stream->parent.close = proxy_stream_close;
......
...@@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) ...@@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
{ {
assert(ctx); assert(ctx);
if (SHA1DCFinal(out->id, &ctx->c)) { if (SHA1DCFinal(out->id, &ctx->c)) {
giterr_set(GITERR_SHA1, "SHA1 collision attack detected"); git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected");
return -1; return -1;
} }
......
...@@ -29,7 +29,7 @@ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) ...@@ -29,7 +29,7 @@ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
assert(ctx); assert(ctx);
if (SHA1_Init(&ctx->c) != 1) { if (SHA1_Init(&ctx->c) != 1) {
giterr_set(GITERR_SHA1, "hash_openssl: failed to initialize hash context"); git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to initialize hash context");
return -1; return -1;
} }
...@@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) ...@@ -41,7 +41,7 @@ GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
assert(ctx); assert(ctx);
if (SHA1_Update(&ctx->c, data, len) != 1) { if (SHA1_Update(&ctx->c, data, len) != 1) {
giterr_set(GITERR_SHA1, "hash_openssl: failed to update hash"); git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to update hash");
return -1; return -1;
} }
...@@ -53,7 +53,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) ...@@ -53,7 +53,7 @@ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
assert(ctx); assert(ctx);
if (SHA1_Final(out->id, &ctx->c) != 1) { if (SHA1_Final(out->id, &ctx->c) != 1) {
giterr_set(GITERR_SHA1, "hash_openssl: failed to finalize hash"); git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash");
return -1; return -1;
} }
......
...@@ -25,7 +25,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) ...@@ -25,7 +25,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
/* Only use CNG on Windows 2008 / Vista SP1 or better (Windows 6.0 SP1) */ /* Only use CNG on Windows 2008 / Vista SP1 or better (Windows 6.0 SP1) */
if (!git_has_win32_version(6, 0, 1)) { if (!git_has_win32_version(6, 0, 1)) {
giterr_set(GITERR_SHA1, "CryptoNG is not supported on this platform"); git_error_set(GIT_ERROR_SHA1, "CryptoNG is not supported on this platform");
return -1; return -1;
} }
...@@ -35,7 +35,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) ...@@ -35,7 +35,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
StringCchCat(dll_path, MAX_PATH, "\\") < 0 || StringCchCat(dll_path, MAX_PATH, "\\") < 0 ||
StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 || StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 ||
(hash_prov.prov.cng.dll = LoadLibrary(dll_path)) == NULL) { (hash_prov.prov.cng.dll = LoadLibrary(dll_path)) == NULL) {
giterr_set(GITERR_SHA1, "CryptoNG library could not be loaded"); git_error_set(GIT_ERROR_SHA1, "CryptoNG library could not be loaded");
return -1; return -1;
} }
...@@ -49,7 +49,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) ...@@ -49,7 +49,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
(hash_prov.prov.cng.close_algorithm_provider = (hash_win32_cng_close_algorithm_provider_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptCloseAlgorithmProvider")) == NULL) { (hash_prov.prov.cng.close_algorithm_provider = (hash_win32_cng_close_algorithm_provider_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptCloseAlgorithmProvider")) == NULL) {
FreeLibrary(hash_prov.prov.cng.dll); FreeLibrary(hash_prov.prov.cng.dll);
giterr_set(GITERR_OS, "CryptoNG functions could not be loaded"); git_error_set(GIT_ERROR_OS, "CryptoNG functions could not be loaded");
return -1; return -1;
} }
...@@ -57,7 +57,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) ...@@ -57,7 +57,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
if (hash_prov.prov.cng.open_algorithm_provider(&hash_prov.prov.cng.handle, GIT_HASH_CNG_HASH_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0) { if (hash_prov.prov.cng.open_algorithm_provider(&hash_prov.prov.cng.handle, GIT_HASH_CNG_HASH_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0) {
FreeLibrary(hash_prov.prov.cng.dll); FreeLibrary(hash_prov.prov.cng.dll);
giterr_set(GITERR_OS, "algorithm provider could not be initialized"); git_error_set(GIT_ERROR_OS, "algorithm provider could not be initialized");
return -1; return -1;
} }
...@@ -66,7 +66,7 @@ GIT_INLINE(int) hash_cng_prov_init(void) ...@@ -66,7 +66,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
hash_prov.prov.cng.close_algorithm_provider(hash_prov.prov.cng.handle, 0); hash_prov.prov.cng.close_algorithm_provider(hash_prov.prov.cng.handle, 0);
FreeLibrary(hash_prov.prov.cng.dll); FreeLibrary(hash_prov.prov.cng.dll);
giterr_set(GITERR_OS, "algorithm handle could not be found"); git_error_set(GIT_ERROR_OS, "algorithm handle could not be found");
return -1; return -1;
} }
...@@ -86,7 +86,7 @@ GIT_INLINE(void) hash_cng_prov_shutdown(void) ...@@ -86,7 +86,7 @@ GIT_INLINE(void) hash_cng_prov_shutdown(void)
GIT_INLINE(int) hash_cryptoapi_prov_init() GIT_INLINE(int) hash_cryptoapi_prov_init()
{ {
if (!CryptAcquireContext(&hash_prov.prov.cryptoapi.handle, NULL, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { if (!CryptAcquireContext(&hash_prov.prov.cryptoapi.handle, NULL, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
giterr_set(GITERR_OS, "legacy hash context could not be started"); git_error_set(GIT_ERROR_OS, "legacy hash context could not be started");
return -1; return -1;
} }
...@@ -141,7 +141,7 @@ GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx) ...@@ -141,7 +141,7 @@ GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
if (!CryptCreateHash(ctx->prov->prov.cryptoapi.handle, CALG_SHA1, 0, 0, &ctx->ctx.cryptoapi.hash_handle)) { if (!CryptCreateHash(ctx->prov->prov.cryptoapi.handle, CALG_SHA1, 0, 0, &ctx->ctx.cryptoapi.hash_handle)) {
ctx->ctx.cryptoapi.valid = 0; ctx->ctx.cryptoapi.valid = 0;
giterr_set(GITERR_OS, "legacy hash implementation could not be created"); git_error_set(GIT_ERROR_OS, "legacy hash implementation could not be created");
return -1; return -1;
} }
...@@ -159,7 +159,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size ...@@ -159,7 +159,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *_data, size
DWORD chunk = (len > MAXDWORD) ? MAXDWORD : (DWORD)len; DWORD chunk = (len > MAXDWORD) ? MAXDWORD : (DWORD)len;
if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, data, chunk, 0)) { if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, data, chunk, 0)) {
giterr_set(GITERR_OS, "legacy hash data could not be updated"); git_error_set(GIT_ERROR_OS, "legacy hash data could not be updated");
return -1; return -1;
} }
...@@ -178,7 +178,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx) ...@@ -178,7 +178,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
assert(ctx->ctx.cryptoapi.valid); assert(ctx->ctx.cryptoapi.valid);
if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0)) { if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0)) {
giterr_set(GITERR_OS, "legacy hash data could not be finished"); git_error_set(GIT_ERROR_OS, "legacy hash data could not be finished");
error = -1; error = -1;
} }
...@@ -204,7 +204,7 @@ GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx) ...@@ -204,7 +204,7 @@ GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx)
if (hash_prov.prov.cng.create_hash(hash_prov.prov.cng.handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, hash_prov.prov.cng.hash_object_size, NULL, 0, 0) < 0) { if (hash_prov.prov.cng.create_hash(hash_prov.prov.cng.handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, hash_prov.prov.cng.hash_object_size, NULL, 0, 0) < 0) {
git__free(ctx->ctx.cng.hash_object); git__free(ctx->ctx.cng.hash_object);
giterr_set(GITERR_OS, "hash implementation could not be created"); git_error_set(GIT_ERROR_OS, "hash implementation could not be created");
return -1; return -1;
} }
...@@ -223,7 +223,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx) ...@@ -223,7 +223,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
/* CNG needs to be finished to restart */ /* CNG needs to be finished to restart */
if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, hash, GIT_OID_RAWSZ, 0) < 0) { if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, hash, GIT_OID_RAWSZ, 0) < 0) {
giterr_set(GITERR_OS, "hash implementation could not be finished"); git_error_set(GIT_ERROR_OS, "hash implementation could not be finished");
return -1; return -1;
} }
...@@ -240,7 +240,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len ...@@ -240,7 +240,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len
ULONG chunk = (len > ULONG_MAX) ? ULONG_MAX : (ULONG)len; ULONG chunk = (len > ULONG_MAX) ? ULONG_MAX : (ULONG)len;
if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, data, chunk, 0) < 0) { if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, data, chunk, 0) < 0) {
giterr_set(GITERR_OS, "hash could not be updated"); git_error_set(GIT_ERROR_OS, "hash could not be updated");
return -1; return -1;
} }
...@@ -254,7 +254,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len ...@@ -254,7 +254,7 @@ GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *_data, size_t len
GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx) GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
{ {
if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, out->id, GIT_OID_RAWSZ, 0) < 0) { if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, out->id, GIT_OID_RAWSZ, 0) < 0) {
giterr_set(GITERR_OS, "hash could not be finished"); git_error_set(GIT_ERROR_OS, "hash could not be finished");
return -1; return -1;
} }
......
...@@ -216,7 +216,7 @@ static int hashsig_finalize_hashes(git_hashsig *sig) ...@@ -216,7 +216,7 @@ static int hashsig_finalize_hashes(git_hashsig *sig)
{ {
if (sig->mins.size < HASHSIG_HEAP_MIN_SIZE && if (sig->mins.size < HASHSIG_HEAP_MIN_SIZE &&
!(sig->opt & GIT_HASHSIG_ALLOW_SMALL_FILES)) { !(sig->opt & GIT_HASHSIG_ALLOW_SMALL_FILES)) {
giterr_set(GITERR_INVALID, git_error_set(GIT_ERROR_INVALID,
"file too small for similarity signature calculation"); "file too small for similarity signature calculation");
return GIT_EBUFS; return GIT_EBUFS;
} }
...@@ -249,7 +249,7 @@ int git_hashsig_create( ...@@ -249,7 +249,7 @@ int git_hashsig_create(
int error; int error;
hashsig_in_progress prog; hashsig_in_progress prog;
git_hashsig *sig = hashsig_alloc(opts); git_hashsig *sig = hashsig_alloc(opts);
GITERR_CHECK_ALLOC(sig); GIT_ERROR_CHECK_ALLOC(sig);
hashsig_in_progress_init(&prog, sig); hashsig_in_progress_init(&prog, sig);
...@@ -276,7 +276,7 @@ int git_hashsig_create_fromfile( ...@@ -276,7 +276,7 @@ int git_hashsig_create_fromfile(
int error = 0, fd; int error = 0, fd;
hashsig_in_progress prog; hashsig_in_progress prog;
git_hashsig *sig = hashsig_alloc(opts); git_hashsig *sig = hashsig_alloc(opts);
GITERR_CHECK_ALLOC(sig); GIT_ERROR_CHECK_ALLOC(sig);
if ((fd = git_futils_open_ro(path)) < 0) { if ((fd = git_futils_open_ro(path)) < 0) {
git__free(sig); git__free(sig);
...@@ -288,7 +288,7 @@ int git_hashsig_create_fromfile( ...@@ -288,7 +288,7 @@ int git_hashsig_create_fromfile(
while (!error) { while (!error) {
if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) { if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) {
if ((error = (int)buflen) < 0) if ((error = (int)buflen) < 0)
giterr_set(GITERR_OS, git_error_set(GIT_ERROR_OS,
"read error on '%s' calculating similarity hashes", path); "read error on '%s' calculating similarity hashes", path);
break; break;
} }
......
...@@ -35,7 +35,7 @@ __KHASH_IMPL(idxicase, static kh_inline, const git_index_entry *, git_index_entr ...@@ -35,7 +35,7 @@ __KHASH_IMPL(idxicase, static kh_inline, const git_index_entry *, git_index_entr
int git_idxmap_alloc(git_idxmap **map) int git_idxmap_alloc(git_idxmap **map)
{ {
if ((*map = kh_init(idx)) == NULL) { if ((*map = kh_init(idx)) == NULL) {
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
} }
...@@ -45,7 +45,7 @@ int git_idxmap_alloc(git_idxmap **map) ...@@ -45,7 +45,7 @@ int git_idxmap_alloc(git_idxmap **map)
int git_idxmap_icase_alloc(git_idxmap_icase **map) int git_idxmap_icase_alloc(git_idxmap_icase **map)
{ {
if ((*map = kh_init(idxicase)) == NULL) { if ((*map = kh_init(idxicase)) == NULL) {
giterr_set_oom(); git_error_set_oom();
return -1; return -1;
} }
......
...@@ -142,7 +142,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match ...@@ -142,7 +142,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
goto out; goto out;
if ((error = p_fnmatch(git_buf_cstr(&buf), path, fnflags)) < 0) { if ((error = p_fnmatch(git_buf_cstr(&buf), path, fnflags)) < 0) {
giterr_set(GITERR_INVALID, "error matching pattern"); git_error_set(GIT_ERROR_INVALID, "error matching pattern");
goto out; goto out;
} }
...@@ -171,7 +171,7 @@ static int parse_ignore_file( ...@@ -171,7 +171,7 @@ static int parse_ignore_file(
git_attr_fnmatch *match = NULL; git_attr_fnmatch *match = NULL;
if (git_repository__cvar(&ignore_case, repo, GIT_CVAR_IGNORECASE) < 0) if (git_repository__cvar(&ignore_case, repo, GIT_CVAR_IGNORECASE) < 0)
giterr_clear(); git_error_clear();
/* if subdir file path, convert context for file paths */ /* if subdir file path, convert context for file paths */
if (attrs->entry && if (attrs->entry &&
...@@ -180,7 +180,7 @@ static int parse_ignore_file( ...@@ -180,7 +180,7 @@ static int parse_ignore_file(
context = attrs->entry->path; context = attrs->entry->path;
if (git_mutex_lock(&attrs->lock) < 0) { if (git_mutex_lock(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "failed to lock ignore file"); git_error_set(GIT_ERROR_OS, "failed to lock ignore file");
return -1; return -1;
} }
...@@ -624,7 +624,7 @@ int git_ignore__check_pathspec_for_exact_ignores( ...@@ -624,7 +624,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
break; break;
if (ignored) { if (ignored) {
giterr_set(GITERR_INVALID, "pathspec contains ignored file '%s'", git_error_set(GIT_ERROR_INVALID, "pathspec contains ignored file '%s'",
filename); filename);
error = GIT_EINVALIDSPEC; error = GIT_EINVALIDSPEC;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment